Skip to content

Commit 7f36b58

Browse files
Merge pull request #85009 from aschwaighofer/embedded_existentials_feature_flag
Add experimental feature flag EmbeddedExistentials
2 parents f3d3613 + a59f6c4 commit 7f36b58

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
@@ -562,6 +562,9 @@ EXPERIMENTAL_FEATURE(StandaloneSwiftAvailability, true)
562562
/// Allow use of `~Sendable`.
563563
SUPPRESSIBLE_EXPERIMENTAL_FEATURE(TildeSendable, false)
564564

565+
/// Allow use of protocol typed values in Embedded mode (`Any` and friends)
566+
EXPERIMENTAL_FEATURE(EmbeddedExistentials, false)
567+
565568
#undef EXPERIMENTAL_FEATURE_EXCLUDED_FROM_MODULE_INTERFACE
566569
#undef EXPERIMENTAL_FEATURE
567570
#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)