-
Notifications
You must be signed in to change notification settings - Fork 10.6k
SE-0492: Metatypes and existential metatypes #85139
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,8 +28,14 @@ func bar(x: Int) -> String { return "test" } | |
| @section("mysection") let funcRef1 = foo // ok | ||
| @section("mysection") let funcRef2 = bar // ok | ||
|
|
||
| // metatypes - TODO | ||
| //@section("mysection") let metatype1 = Int.self | ||
| struct S: Hashable, Sendable {} | ||
|
|
||
| // metatypes | ||
| @section("mysection") let metatype1 = Int.self | ||
| @section("mysection") let metatype2: Any.Type = Int.self | ||
| @section("mysection") let metatype3: Any.Type = S.self | ||
| @section("mysection") let metatype4: any (Hashable & Sendable).Type = Int.self | ||
| @section("mysection") let metatype5: any (Hashable & Sendable).Type = S.self | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you add tests for bound generic types, e.g. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We're rejecting that case syntactically: https://github.com/swiftlang/swift/pull/85139/files#diff-ea7de05f211d676ea604c35f0e6b253fb4a454efbfcc84928a931bab113e7bdcR82 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ...but I did add that as a SIL test into |
||
|
|
||
| // tuples | ||
| @section("mysection") let tuple1 = (1, 2, 3, 2.718, true) // ok | ||
|
|
@@ -56,6 +62,12 @@ func bar(x: Int) -> String { return "test" } | |
| // CHECK: @"$s9SectionIR12boolLiteral2Sbvp" = {{.*}}constant %TSb zeroinitializer, section "mysection" | ||
| // CHECK: @"$s9SectionIR8funcRef1Siycvp" = {{.*}}constant %swift.function { ptr @"$s9SectionIR3fooSiyF{{.*}}", ptr null }, section "mysection" | ||
| // CHECK: @"$s9SectionIR8funcRef2ySSSicvp" = {{.*}}constant %swift.function { ptr @"$s9SectionIR3bar1xSSSi_tF{{.*}}", ptr null }, section "mysection" | ||
|
|
||
| // CHECK: @"$s9SectionIR9metatype2ypXpvp" = {{.*}}constant ptr @"$sSiN", section "mysection" | ||
| // CHECK: @"$s9SectionIR9metatype3ypXpvp" = {{.*}}constant ptr getelementptr inbounds (<{ ptr, ptr, {{i64|i32}}, ptr }>, ptr @"$s9SectionIR1SVMf", i32 0, i32 2), section "mysection" | ||
| // CHECK: @"$s9SectionIR9metatype4SH_s8SendablepXpvp" = {{.*}}constant <{ ptr, ptr }> <{ ptr @"$sSiN", ptr @"$sSiSHsWP" }>, section "mysection" | ||
| // CHECK: @"$s9SectionIR9metatype5SH_s8SendablepXpvp" = {{.*}}constant <{ ptr, ptr }> <{ ptr getelementptr inbounds (<{ ptr, ptr, {{i64|i32}}, ptr }>, ptr @"$s9SectionIR1SVMf", i32 0, i32 2), ptr @"$s9SectionIR1SVSHAAWP" }>, section "mysection" | ||
|
|
||
| // CHECK: @"$s9SectionIR6tuple1Si_S2iSdSbtvp" = {{.*}}constant <{ %TSi, %TSi, %TSi, {{.*}} }> <{ %TSi <{ {{i64|i32}} 1 }>, %TSi <{ {{i64|i32}} 2 }>, %TSi <{ {{i64|i32}} 3 }>, {{.*}} }>, section "mysection" | ||
| // CHECK: @"$s9SectionIR6tuple2Si_SfSbtvp" = {{.*}}constant <{ %TSi, %TSf, %TSb }> <{ %TSi <{ {{i64|i32}} 42 }>, %TSf <{ float 0x40091EB860000000 }>, %TSb zeroinitializer }>, section "mysection" | ||
| // CHECK: @"$s9SectionIR6tuple3Siyc_SSSictvp" = {{.*}}constant <{ %swift.function, %swift.function }> <{ %swift.function { ptr @"$s9SectionIR3fooSiyF{{.*}}", ptr null }, %swift.function { ptr @"$s9SectionIR3bar1xSSSi_tF{{.*}}", ptr null } }>, section "mysection" | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| // RUN: %target-swift-frontend %s -parse-as-library -module-name=test -emit-sil | %FileCheck %s | ||
| // RUN: %target-swift-frontend %s -parse-as-library -O -module-name=test -emit-sil | %FileCheck %s | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please also add a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Yes, that should be fine. As long as IRGen can handle those SIL initializer instructions. |
||
|
|
||
| struct S: Hashable, Sendable {} | ||
|
|
||
| public let metatype1 = Int.self | ||
| public let metatype2: Any.Type = Int.self | ||
| public let metatype3: Any.Type = S.self | ||
| public let metatype4: any (Hashable & Sendable).Type = Int.self | ||
| public let metatype5: any (Hashable & Sendable).Type = S.self | ||
| public let metatype6: Any.Type = Array<Int>.self | ||
| public let metatype7: any (Hashable & Sendable).Type = Array<Int>.self | ||
|
|
||
| // CHECK: sil_global [let] @$s4test9metatype1Simvp : $@thin Int.Type = { | ||
| // CHECK-NEXT: %initval = metatype $@thin Int.Type | ||
| // CHECK-NEXT: } | ||
|
|
||
| // CHECK: sil_global [let] @$s4test9metatype2ypXpvp : $@thick any Any.Type = { | ||
| // CHECK-NEXT: %0 = metatype $@thick Int.Type | ||
| // CHECK-NEXT: %initval = init_existential_metatype %0, $@thick any Any.Type | ||
| // CHECK-NEXT: } | ||
|
|
||
| // CHECK: sil_global [let] @$s4test9metatype3ypXpvp : $@thick any Any.Type = { | ||
| // CHECK-NEXT: %0 = metatype $@thick S.Type | ||
| // CHECK-NEXT: %initval = init_existential_metatype %0, $@thick any Any.Type | ||
| // CHECK-NEXT: } | ||
|
|
||
| // CHECK: sil_global [let] @$s4test9metatype4SH_s8SendablepXpvp : $@thick any (Hashable & Sendable).Type = { | ||
| // CHECK-NEXT: %0 = metatype $@thick Int.Type | ||
| // CHECK-NEXT: %initval = init_existential_metatype %0, $@thick any (Hashable & Sendable).Type | ||
| // CHECK-NEXT: } | ||
|
|
||
| // CHECK: sil_global [let] @$s4test9metatype5SH_s8SendablepXpvp : $@thick any (Hashable & Sendable).Type = { | ||
| // CHECK-NEXT: %0 = metatype $@thick S.Type | ||
| // CHECK-NEXT: %initval = init_existential_metatype %0, $@thick any (Hashable & Sendable).Type | ||
| // CHECK-NEXT: } | ||
|
|
||
| // CHECK: sil_global [let] @$s4test9metatype6ypXpvp : $@thick any Any.Type = { | ||
| // CHECK-NEXT: %0 = metatype $@thick Array<Int>.Type | ||
| // CHECK-NEXT: %initval = init_existential_metatype %0, $@thick any Any.Type | ||
| // CHECK-NEXT: } | ||
|
|
||
| // CHECK: sil_global [let] @$s4test9metatype7SH_s8SendablepXpvp : $@thick any (Hashable & Sendable).Type = { | ||
| // CHECK-NEXT: %0 = metatype $@thick Array<Int>.Type | ||
| // CHECK-NEXT: %initval = init_existential_metatype %0, $@thick any (Hashable & Sendable).Type | ||
| // CHECK-NEXT: } | ||
|
|
||
| // These are not constant folded and stay as lazily-initialized | ||
| public let metatypeA: Any.Type = (Bool.random() ? Array<Int>.self : Array<Bool>.self).self | ||
| public let metatypeB: Any.Type = Mirror.self // resilient | ||
|
|
||
| // CHECK: sil_global private @$s4test9metatypeA_Wz : $Builtin.Word | ||
| // CHECK: sil_global [let] @$s4test9metatypeAypXpvp : $@thick any Any.Type | ||
| // CHECK: sil_global private @$s4test9metatypeB_Wz : $Builtin.Word | ||
| // CHECK: sil_global [let] @$s4test9metatypeBypXpvp : $@thick any Any.Type | ||
| // CHECK: sil private [global_init_once_fn] @$s4test9metatypeA_WZ : $@convention(c) (Builtin.RawPointer) -> () { | ||
| // CHECK: sil private [global_init_once_fn] @$s4test9metatypeB_WZ : $@convention(c) (Builtin.RawPointer) -> () { | ||
Uh oh!
There was an error while loading. Please reload this page.