Skip to content

Commit 22c8ea6

Browse files
committed
Add experimental feature flag EmbeddedExistentials
This flag can be used to gradually add the functionility that will allow use of protocol values in embedded mode.
1 parent a867ff8 commit 22c8ea6

File tree

5 files changed

+34
-1
lines changed

5 files changed

+34
-1
lines changed

SwiftCompilerSources/Sources/Optimizer/ModulePasses/EmbeddedSwiftDiagnostics.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,9 @@ private struct FunctionChecker {
8888
is InitExistentialAddrInst,
8989
is InitExistentialValueInst,
9090
is ExistentialMetatypeInst:
91-
throw Diagnostic(.embedded_swift_existential_type, instruction.operands[0].value.type, at: instruction.location)
91+
if !context.options.enableEmbeddedSwiftExistentials {
92+
throw Diagnostic(.embedded_swift_existential_type, instruction.operands[0].value.type, at: instruction.location)
93+
}
9294

9395
case let aeb as AllocExistentialBoxInst:
9496
throw Diagnostic(.embedded_swift_existential_type, aeb.type, at: instruction.location)

SwiftCompilerSources/Sources/Optimizer/PassManager/Options.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ struct Options {
4444
hasFeature(.Embedded)
4545
}
4646

47+
var enableEmbeddedSwiftExistentials: Bool {
48+
hasFeature(.EmbeddedExistentials)
49+
}
50+
4751
var enableMergeableTraps: Bool {
4852
_bridged.enableMergeableTraps()
4953
}

include/swift/Basic/Features.def

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -558,6 +558,9 @@ EXPERIMENTAL_FEATURE(SwiftRuntimeAvailability, true)
558558
/// Allow use of `~Sendable`.
559559
SUPPRESSIBLE_EXPERIMENTAL_FEATURE(TildeSendable, false)
560560

561+
/// Allow use of protocol typed values in Embedded mode (`Any` and friends)
562+
EXPERIMENTAL_FEATURE(EmbeddedExistentials, false)
563+
561564
#undef EXPERIMENTAL_FEATURE_EXCLUDED_FROM_MODULE_INTERFACE
562565
#undef EXPERIMENTAL_FEATURE
563566
#undef UPCOMING_FEATURE

lib/AST/FeatureSet.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ UNINTERESTING_FEATURE(NonisolatedNonsendingByDefault)
128128
UNINTERESTING_FEATURE(KeyPathWithMethodMembers)
129129
UNINTERESTING_FEATURE(ImportMacroAliases)
130130
UNINTERESTING_FEATURE(NoExplicitNonIsolated)
131+
UNINTERESTING_FEATURE(EmbeddedExistentials)
131132

132133
// TODO: Return true for inlinable function bodies with module selectors in them
133134
UNINTERESTING_FEATURE(ModuleSelector)

test/embedded/existential.swift

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// RUN: %target-swift-frontend -enable-experimental-feature EmbeddedExistentials -enable-experimental-feature Embedded -parse-as-library -wmo -emit-sil %s | %FileCheck %s
2+
3+
// REQUIRES: swift_in_compiler
4+
// REQUIRES: optimized_stdlib
5+
// REQUIRES: swift_feature_Embedded
6+
// REQUIRES: swift_feature_EmbeddedExistentials
7+
8+
class C {}
9+
10+
// CHECK: sil @$e11existential4testyyF
11+
// CHECK: init_existential_addr
12+
// CHECK: } // end sil function '$e11existential4testyyF'
13+
14+
func test() {
15+
let any: any Any = C()
16+
}
17+
18+
@main
19+
struct Main {
20+
static func main() {
21+
test()
22+
}
23+
}

0 commit comments

Comments
 (0)