Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ struct Options {
hasFeature(.Embedded)
}

var enableEmbeddedSwiftExistentials: Bool {
hasFeature(.EmbeddedExistentials)
}

var enableMergeableTraps: Bool {
_bridged.enableMergeableTraps()
}
Expand Down
3 changes: 3 additions & 0 deletions include/swift/Basic/Features.def
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions lib/AST/FeatureSet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
23 changes: 23 additions & 0 deletions test/embedded/existential.swift
Original file line number Diff line number Diff line change
@@ -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()
}
}