diff --git a/SwiftCompilerSources/Sources/Optimizer/ModulePasses/EmbeddedSwiftDiagnostics.swift b/SwiftCompilerSources/Sources/Optimizer/ModulePasses/EmbeddedSwiftDiagnostics.swift index 4d99ca22ac7ba..b2a3a1e0bd190 100644 --- a/SwiftCompilerSources/Sources/Optimizer/ModulePasses/EmbeddedSwiftDiagnostics.swift +++ b/SwiftCompilerSources/Sources/Optimizer/ModulePasses/EmbeddedSwiftDiagnostics.swift @@ -88,7 +88,9 @@ private struct FunctionChecker { is InitExistentialAddrInst, is InitExistentialValueInst, is ExistentialMetatypeInst: - throw Diagnostic(.embedded_swift_existential_type, instruction.operands[0].value.type, at: instruction.location) + if !context.options.enableEmbeddedSwiftExistentials { + throw Diagnostic(.embedded_swift_existential_type, instruction.operands[0].value.type, at: instruction.location) + } case let aeb as AllocExistentialBoxInst: throw Diagnostic(.embedded_swift_existential_type, aeb.type, at: instruction.location) diff --git a/SwiftCompilerSources/Sources/Optimizer/PassManager/Options.swift b/SwiftCompilerSources/Sources/Optimizer/PassManager/Options.swift index 2c4b9d031f3d2..41da345a569ef 100644 --- a/SwiftCompilerSources/Sources/Optimizer/PassManager/Options.swift +++ b/SwiftCompilerSources/Sources/Optimizer/PassManager/Options.swift @@ -44,6 +44,10 @@ struct Options { hasFeature(.Embedded) } + var enableEmbeddedSwiftExistentials: Bool { + hasFeature(.EmbeddedExistentials) + } + var enableMergeableTraps: Bool { _bridged.enableMergeableTraps() } diff --git a/include/swift/Basic/Features.def b/include/swift/Basic/Features.def index 3797a9a40462d..b1d3e3bb4eaf4 100644 --- a/include/swift/Basic/Features.def +++ b/include/swift/Basic/Features.def @@ -558,6 +558,9 @@ EXPERIMENTAL_FEATURE(SwiftRuntimeAvailability, true) /// Allow use of `~Sendable`. SUPPRESSIBLE_EXPERIMENTAL_FEATURE(TildeSendable, false) +/// Allow use of protocol typed values in Embedded mode (`Any` and friends) +EXPERIMENTAL_FEATURE(EmbeddedExistentials, false) + #undef EXPERIMENTAL_FEATURE_EXCLUDED_FROM_MODULE_INTERFACE #undef EXPERIMENTAL_FEATURE #undef UPCOMING_FEATURE diff --git a/lib/AST/FeatureSet.cpp b/lib/AST/FeatureSet.cpp index 590a15eabfddd..5013c14fe7bda 100644 --- a/lib/AST/FeatureSet.cpp +++ b/lib/AST/FeatureSet.cpp @@ -128,6 +128,7 @@ UNINTERESTING_FEATURE(NonisolatedNonsendingByDefault) UNINTERESTING_FEATURE(KeyPathWithMethodMembers) UNINTERESTING_FEATURE(ImportMacroAliases) UNINTERESTING_FEATURE(NoExplicitNonIsolated) +UNINTERESTING_FEATURE(EmbeddedExistentials) // TODO: Return true for inlinable function bodies with module selectors in them UNINTERESTING_FEATURE(ModuleSelector) diff --git a/test/embedded/existential.swift b/test/embedded/existential.swift new file mode 100644 index 0000000000000..9073258edcc02 --- /dev/null +++ b/test/embedded/existential.swift @@ -0,0 +1,23 @@ +// RUN: %target-swift-frontend -enable-experimental-feature EmbeddedExistentials -enable-experimental-feature Embedded -parse-as-library -wmo -emit-sil %s | %FileCheck %s + +// REQUIRES: swift_in_compiler +// REQUIRES: optimized_stdlib +// REQUIRES: swift_feature_Embedded +// REQUIRES: swift_feature_EmbeddedExistentials + +class C {} + +// CHECK: sil @$e11existential4testyyF +// CHECK: init_existential_addr +// CHECK: } // end sil function '$e11existential4testyyF' + +func test() { + let any: any Any = C() +} + +@main +struct Main { + static func main() { + test() + } +}