Merge pull request #85948 from aschwaighofer/embedded_enable_existential_support

[embedded] Enable support for existentials/boxed protocol types per default
This commit is contained in:
Arnold Schwaighofer
2025-12-11 07:16:26 -08:00
committed by GitHub
13 changed files with 137 additions and 10 deletions

View File

@@ -1,8 +1,10 @@
// RUN: %target-swift-frontend -emit-ir -verify %s -parse-stdlib -enable-experimental-feature Embedded -wmo
// RUN: %target-swift-frontend -emit-ir -verify %s -parse-stdlib -enable-experimental-feature Embedded -wmo -disable-embedded-existentials
// REQUIRES: swift_in_compiler
// REQUIRES: swift_feature_Embedded
// This is only an error if we disable support for existentials in embedded.
public protocol Player {}
struct Concrete: Player {}

View File

@@ -1,5 +1,6 @@
// RUN: %target-swift-emit-sil %s -parse-stdlib -enable-experimental-feature Embedded -target arm64e-apple-none -wmo | %FileCheck %s --check-prefix CHECK-SIL
// RUN: %target-swift-emit-ir %s -parse-stdlib -enable-experimental-feature Embedded -target arm64e-apple-none -wmo | %FileCheck %s --check-prefix CHECK-IR
// RUN: %target-swift-emit-ir %s -parse-stdlib -enable-experimental-feature Embedded -target arm64e-apple-none -wmo -disable-embedded-existentials | %FileCheck %s --check-prefix CHECK-IR
// RUN: %target-swift-emit-ir %s -parse-stdlib -enable-experimental-feature Embedded -target arm64e-apple-none -wmo | %FileCheck %s --check-prefix CHECK-IR-EXIST
// UNSUPPORTED: CPU=wasm32
// REQUIRES: swift_in_compiler
@@ -69,3 +70,11 @@ public func bar(t: T2) -> MyClass<T2> {
// CHECK-IR-DAG: define {{.*}}void @"$e4main7MyClassCfDAA2T2V_Tg5"(ptr swiftself %0)
// CHECK-IR-DAG: define {{.*}}ptr @"$e4main3foo1tAA7MyClassCyAA2T1VGAG_tF"()
// CHECK-IR-DAG: define {{.*}}ptr @"$e4main3bar1tAA7MyClassCyAA2T2VGAG_tF"(i1 %0)
// CHECK-IR-EXIST-DAG: @"$e4main7MyClassCyAA2T1VGMf" = {{.*}} <{ ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }> <{ ptr @"$eBoWV", ptr null, ptr @"$e4main7MyClassCfDAA2T1V_Tg5", ptr null, ptr @"$e4main7MyClassC1txvgAA2T1V_Tg5", ptr @"$e4main7MyClassC1txvsAA2T1V_Tg5", ptr @"$e4main7MyClassC1txvMAA2T1V_Tg5", ptr @"$e4main7MyClassC1tACyxGx_tcfCAA2T1V_Tg5" }>
// CHECK-IR-EXIST-DAG: @"$e4main7MyClassCyAA2T2VGMf" = {{.*}} <{ ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }> <{ ptr @"$eBoWV", ptr null, ptr @"$e4main7MyClassCfDAA2T2V_Tg5", ptr null, ptr @"$e4main7MyClassC1txvgAA2T2V_Tg5", ptr @"$e4main7MyClassC1txvsAA2T2V_Tg5", ptr @"$e4main7MyClassC1txvMAA2T2V_Tg5", ptr @"$e4main7MyClassC1tACyxGx_tcfCAA2T2V_Tg5" }>
// CHECK-IR-EXIST-DAG: @"$e4main7MyClassCyAA2T1VGN" = {{.*}} alias {{.*}} ptr @"$e4main7MyClassCyAA2T1VGMf", i32 0, i32 1)
// CHECK-IR-EXIST-DAG: @"$e4main7MyClassCyAA2T2VGN" = {{.*}} alias {{.*}} ptr @"$e4main7MyClassCyAA2T2VGMf", i32 0, i32 1)

View File

@@ -1,4 +1,5 @@
// RUN: %target-swift-emit-ir %s -parse-stdlib -enable-experimental-feature Embedded -target arm64e-apple-none -wmo | %FileCheck %s
// RUN: %target-swift-emit-ir %s -parse-stdlib -enable-experimental-feature Embedded -target arm64e-apple-none -wmo -disable-embedded-existentials | %FileCheck %s
// RUN: %target-swift-emit-ir %s -parse-stdlib -enable-experimental-feature Embedded -target arm64e-apple-none -wmo | %FileCheck %s --check-prefix=EXIST
// REQUIRES: swift_in_compiler
// REQUIRES: swift_feature_Embedded
@@ -37,3 +38,38 @@ public func test(x: MyClass) {
// CHECK: call swiftcc void @"$e4main7MyClassC3baryyF"
}
// EXIST: @"$e4main10MySubClassCMf" = {{.*}} <{ ptr @"$eBoWV", ptr getelementptr inbounds (<{ ptr, ptr, ptr, ptr, ptr, ptr, ptr }>, ptr @"$e4main7MyClassCMf", i32 0, i32 1), ptr @"$e4main10MySubClassCfD", ptr null, ptr @"$e4main10MySubClassC3fooyyF", ptr @"$e4main7MyClassC3baryyF", ptr @"$e4main10MySubClassCACycfC" }>
// EXIST: @"$e4main7MyClassCMf" = {{.*}} <{ ptr @"$eBoWV", ptr null, ptr @"$e4main7MyClassCfD", ptr null, ptr @"$e4main7MyClassC3fooyyF", ptr @"$e4main7MyClassC3baryyF", ptr @swift_deletedMethodError }>
// EXIST: @"$e4main10MySubClassCN" = {{.*}}alias{{.*}} ptr @"$e4main10MySubClassCMf", i32 0, i32 1)
// EXIST: @"$e4main7MyClassCN" = {{.*}}alias{{.*}} ptr @"$e4main7MyClassCMf", i32 0, i32 1)
// EXIST: define {{.*}}void @"$e4main4test1xyAA7MyClassC_tF"(ptr %0)
// public func test(x: MyClass) {
// x.foo() // goes through the vtable
// EXIST: %1 = load ptr, ptr %0
// EXIST: %2 = getelementptr inbounds ptr, ptr %1, i64 3
// EXIST: %3 = load ptr, ptr %2
// EXIST: call swiftcc void %3(ptr swiftself %0)
// x.bar() // does not go through the vtable
// EXIST: call swiftcc void @"$e4main7MyClassC3baryyF"
// let y = MySubClass()
// EXIST: call swiftcc ptr @"$e4main10MySubClassCACycfC"
// y.foo() // does not go through the vtable
// EXIST: call swiftcc void @"$e4main10MySubClassC3fooyyF"
// y.bar() // does not go through the vtable
// EXIST: call swiftcc void @"$e4main7MyClassC3baryyF"

View File

@@ -1,4 +1,6 @@
// RUN: %target-swift-emit-ir %s -parse-stdlib -enable-experimental-feature Embedded -target arm64e-apple-none -wmo | %FileCheck %s
// RUN: %target-swift-emit-ir %s -parse-stdlib -enable-experimental-feature Embedded -target arm64e-apple-none -wmo -disable-embedded-existentials | %FileCheck %s
// RUN: %target-swift-emit-ir %s -parse-stdlib -enable-experimental-feature Embedded -target arm64e-apple-none -wmo | %FileCheck %s --check-prefix=EXIST
// REQUIRES: swift_in_compiler
// REQUIRES: swift_feature_Embedded
@@ -28,3 +30,27 @@ public func bar() -> MyClass {
return MySubClass()
}
// CHECK-DAG: define {{.*}}ptr @"$e4main3barAA7MyClassCyF"
// EXIST-DAG: @"$e4main10MySubClassCMf" = {{.*}} <{ ptr @"$eBoWV", ptr getelementptr inbounds (<{ ptr, ptr, ptr, ptr, ptr }>, ptr @"$e4main7MyClassCMf", i32 0, i32 1), ptr @"$e4main10MySubClassCfD", ptr null, ptr @"$e4main10MySubClassCACycfC" }>
// EXIST-DAG: @"$e4main7MyClassCMf" = {{.*}} <{ ptr @"$eBoWV", ptr null, ptr @"$e4main7MyClassCfD", ptr null, ptr @"$e4main7MyClassCACycfC" }>
// EXIST-DAG: @"$e4main10MySubClassCN" = {{.*}} ptr @"$e4main10MySubClassCMf", i32 0, i32 1)
// EXIST-DAG: @"$e4main7MyClassCN" = {{.*}} ptr @"$e4main7MyClassCMf", i32 0, i32 1)
// EXIST-DAG: define {{.*}}ptr @"$e4main3barAA7MyClassCyF"
// EXIST-DAG: define {{.*}}ptr @"$e4main7MyClassCfd"
// EXIST-DAG: define {{.*}}void @"$e4main7MyClassCfD"
// EXIST-DAG: define {{.*}}ptr @"$e4main7MyClassCACycfC"
// EXIST-DAG: define {{.*}}ptr @"$e4main7MyClassCACycfc"
// EXIST-DAG: define {{.*}}ptr @"$e4main3fooAA7MyClassCyF"
// EXIST-DAG: define {{.*}}ptr @"$e4main10MySubClassCACycfC"
// EXIST-DAG: define {{.*}}ptr @"$e4main10MySubClassCACycfc"
// EXIST-DAG: define {{.*}}ptr @"$e4main10MySubClassCfd"
// EXIST-DAG: define {{.*}}void @"$e4main10MySubClassCfD"

View File

@@ -1,9 +1,16 @@
// RUN: %empty-directory(%t)
// RUN: %target-swift-frontend -enable-experimental-feature Embedded -parse-as-library -module-name main %s -emit-ir | %FileCheck --check-prefix=CHECK-IR %s
// RUN: %target-swift-frontend -disable-embedded-existentials -enable-experimental-feature Embedded -parse-as-library -module-name main %s -emit-ir | %FileCheck --check-prefix=CHECK-IR %s
// RUN: %target-swift-frontend -disable-embedded-existentials -enable-experimental-feature Embedded -parse-as-library -module-name main %s -c -o %t/a.o
// RUN: %target-clang %t/a.o -o %t/a.out -L%swift_obj_root/lib/swift/embedded/%module-target-triple %target-clang-resource-dir-opt -lswift_Concurrency %target-swift-default-executor-opt -dead_strip
// RUN: %target-run %t/a.out | %FileCheck %s
// RUN: %empty-directory(%t)
// RUN: %target-swift-frontend -enable-experimental-feature Embedded -parse-as-library -module-name main %s -emit-ir | %FileCheck --check-prefix=EXIST-IR %s
// RUN: %target-swift-frontend -enable-experimental-feature Embedded -parse-as-library -module-name main %s -c -o %t/a.o
// RUN: %target-clang %t/a.o -o %t/a.out -L%swift_obj_root/lib/swift/embedded/%module-target-triple %target-clang-resource-dir-opt -lswift_Concurrency %target-swift-default-executor-opt -dead_strip
// RUN: %target-run %t/a.out | %FileCheck %s
// REQUIRES: executable_test
// REQUIRES: swift_in_compiler
// REQUIRES: optimized_stdlib
@@ -48,3 +55,21 @@ actor MyActor {
// CHECK-IR: define weak_odr {{swifttailcc|swiftcc}} void @swift_deletedAsyncMethodError(ptr swiftasync %0)
// CHECK: value: 42
// EXIST-IR: @swift_deletedAsyncMethodErrorTu =
// EXIST-IR: @"$e4main7MyActorCMf" = {{.*}} <{ ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }> <{
// EXIST-IR-SAME: ptr @"$eBoWV",
// EXIST-IR-SAME: ptr null,
// EXIST-IR-SAME: ptr @"$e4main7MyActorCfD",
// EXIST-IR-SAME: ptr null,
// EXIST-IR-SAME: ptr @swift_deletedMethodError,
// EXIST-IR-SAME: ptr @swift_deletedMethodError,
// EXIST-IR-SAME: ptr @swift_deletedMethodError,
// EXIST-IR-SAME: ptr @"$e4main7MyActorC3fooyyYaFTu",
// EXIST-IR-SAME: ptr @got.swift_deletedAsyncMethodErrorTu,
// EXIST-IR-SAME: ptr @"$e4main7MyActorCACycfC" }>
// EXIST-IR-DAG: @"$e4main7MyActorCN" = {{.*}}alias{{.*}} ptr @"$e4main7MyActorCMf", i32 0, i32 1)
// EXIST-IR-NOT: $e4main7MyActorC12thisIsUnusedyyYaF

View File

@@ -1,4 +1,4 @@
// RUN: %target-swift-emit-ir -parse-as-library -module-name main -verify %s -enable-experimental-feature Embedded -wmo
// RUN: %target-swift-emit-ir -parse-as-library -module-name main -verify %s -enable-experimental-feature Embedded -wmo -disable-embedded-existentials
// REQUIRES: swift_in_compiler
// REQUIRES: optimized_stdlib

View File

@@ -1,4 +1,4 @@
// RUN: %target-swift-emit-ir -parse-as-library -module-name main -verify %s -enable-experimental-feature Embedded -wmo
// RUN: %target-swift-emit-ir -parse-as-library -module-name main -verify %s -enable-experimental-feature Embedded -wmo -disable-embedded-existentials
// REQUIRES: swift_feature_Embedded

View File

@@ -4,6 +4,12 @@
// RUN: not %target-swift-frontend -enable-experimental-feature EmbeddedExistentials -parse-as-library -wmo -emit-sil %s 2>&1 | %FileCheck --check-prefix=ERRMSG %s
// EmbeddedExistentials is the default.
// RUN: %target-run-simple-swift( -enable-experimental-feature Embedded -parse-as-library -wmo) | %FileCheck %s --check-prefix=OUTPUT
// Test -disable-embedded-existentials
// RUN: not %target-swift-frontend -disable-embedded-existentials -enable-experimental-feature Embedded -parse-as-library -wmo -emit-sil %s 2>&1 | %FileCheck --check-prefix=ERRMSG2 %s
// REQUIRES: swift_in_compiler
// REQUIRES: executable_test
// REQUIRES: optimized_stdlib
@@ -13,6 +19,9 @@
// EmbeddedExistentials requires Embedded
// ERRMSG: error: EmbeddedExistentials requires enabling embedded Swift.
// Test -disable-embedded-existentials
// ERRMSG2: error: cannot use a value of protocol type 'Any' in embedded Swift
class CP {
}

View File

@@ -7,12 +7,14 @@
// RUN: %target-swift-frontend %t/Library.swift -parse-as-library -entry-point-function-name Library_main -enable-experimental-feature Embedded -enable-experimental-feature DeferredCodeGen -emit-sil -emit-module-path %t/Modules/Library.swiftmodule -o - | %FileCheck -check-prefix LIBRARY-SIL %s
// IR checking to ensure we get the right weak symbols.
// RUN: %target-swift-frontend %t/Library.swift -parse-as-library -entry-point-function-name Library_main -enable-experimental-feature Embedded -enable-experimental-feature DeferredCodeGen -emit-ir -o - | %FileCheck -check-prefix LIBRARY-IR --dump-input-filter all %s
// RUN: %target-swift-frontend %t/Library.swift -disable-embedded-existentials -parse-as-library -entry-point-function-name Library_main -enable-experimental-feature Embedded -enable-experimental-feature DeferredCodeGen -emit-ir -o - | %FileCheck -check-prefix LIBRARY-IR --dump-input-filter all %s
// RUN: %target-swift-frontend %t/Library.swift -parse-as-library -entry-point-function-name Library_main -enable-experimental-feature Embedded -enable-experimental-feature DeferredCodeGen -emit-ir -o - | %FileCheck -check-prefix LIBRARY-EXIST-IR --dump-input-filter all %s
// Application module
// RUN: %target-swift-frontend %t/Application.swift -I %t/Modules -parse-as-library -entry-point-function-name Application_main -enable-experimental-feature Embedded -emit-sil -o - | %FileCheck -check-prefix APPLICATION-SIL %s
// RUN: %target-swift-frontend %t/Application.swift -disable-embedded-existentials -I %t/Modules -parse-as-library -entry-point-function-name Application_main -enable-experimental-feature Embedded -emit-ir -o - | %FileCheck -check-prefix APPLICATION-IR --dump-input-filter all %s
// RUN: %target-swift-frontend %t/Application.swift -I %t/Modules -parse-as-library -entry-point-function-name Application_main -enable-experimental-feature Embedded -emit-ir -o - | %FileCheck -check-prefix APPLICATION-IR --dump-input-filter all %s
// REQUIRES: swift_in_compiler
@@ -22,6 +24,7 @@
//--- Library.swift
// LIBRARY-IR: @"$e7Library10PointClassCN" = linkonce_odr {{.*}}global
// LIBRARY-EXIST-IR: @"$e7Library10PointClassCMf" = {{.*}}linkonce_odr {{.*}}global
// Never referenced.
// LIBRARY-IR-NOT: @"$es23_swiftEmptyArrayStorageSi_S3itvp" = linkonce_odr {{(protected |dllexport )?}}global

View File

@@ -1,10 +1,18 @@
// RUN: %target-swift-emit-ir %s -module-name=main -enable-experimental-feature Embedded | %FileCheck %s
// RUN: %target-swift-emit-ir -disable-embedded-existentials %s -module-name=main -enable-experimental-feature Embedded | %FileCheck %s
// RUN: %target-swift-emit-ir %s -module-name=main -enable-experimental-feature Embedded | %FileCheck %s --check-prefix=EXIST
// REQUIRES: swift_in_compiler
// REQUIRES: swift_feature_Embedded
// CHECK: @"$e4main8MyBufferCN" = {{.*global.*}} <{ ptr @"$es13ManagedBufferCySis5UInt8VGN", ptr @"$e4main8MyBufferCfD{{[^"]*}}", ptr null, ptr @"$e4main8MyBufferC12_doNotCallMeACyt_tcfC{{[^"]*}}" }>
// CHECK: @"$es13ManagedBufferCySis5UInt8VGN" = {{.*global.*}} <{ ptr null, ptr @"$es13ManagedBufferCfDSi_s5UInt8VTgq5{{[^"]*}}", ptr null, ptr @"$es13ManagedBufferC12_doNotCallMeAByxq_Gyt_tcfCSi_s5UInt8VTgq5{{[^"]*}}" }>
// EXIST: @"$e4main8MyBufferCMf" = {{.*}} <{ ptr @"$eBoWV", {{.*}} ptr @"$es13ManagedBufferCySis5UInt8VGMf", i32 0, i32 1), ptr @"$e4main8MyBufferCfD{{[^"]*}}", ptr null, ptr @"$e4main8MyBufferC12_doNotCallMeACyt_tcfC{{[^"]*}}" }>
// EXIST: @"$es13ManagedBufferCySis5UInt8VGMf" = {{.*}} <{ ptr @"$eBoWV", ptr null, ptr @"$es13ManagedBufferCfDSi_s5UInt8VTgq5{{[^"]*}}", ptr null, ptr @"$es13ManagedBufferC12_doNotCallMeAByxq_Gyt_tcfCSi_s5UInt8VTgq5{{[^"]*}}" }>
// EXIST: @"$e4main8MyBufferCN" = {{.*}}alias
// EXIST: @"$es13ManagedBufferCySis5UInt8VGN" = {{.*}}alias
final public class MyBuffer: ManagedBuffer<Int, UInt8> {
}