|
| 1 | +// RUN: %empty-directory(%t) |
| 2 | +// RUN: %target-swift-frontend -emit-module-path=%t/RAD.swiftmodule -module-name=RAD -enable-experimental-feature RuntimeDiscoverableAttrs %S/Inputs/runtime_attrs.swift |
| 3 | +// RUN: %target-swift-frontend -primary-file %s -emit-ir -I %t -swift-version 5 -enable-experimental-feature RuntimeDiscoverableAttrs | %IRGenFileCheck %s |
| 4 | + |
| 5 | +// REQUIES: asserts |
| 6 | + |
| 7 | +// First, make sure that we emit: |
| 8 | +// - accessible function records for each generator |
| 9 | +// - runtime attribute records with correct number of trailing objects |
| 10 | + |
| 11 | +// CHECK: @"$s18runtime_attributes9gloabalFnyycvpfaAA4FlagHF" |
| 12 | +// CHECK: @"$s18runtime_attributes1AV2v1SSvpfaAA4FlagHF" |
| 13 | +// CHECK: @"$s18runtime_attributes1AV4compSivpfaAA4FlagHF" |
| 14 | +// CHECK: @"$s18runtime_attributes1AV5test1SiycvpZfaAA4FlagHF" |
| 15 | +// CHECK: @"$s18runtime_attributes1AV5test2yycvpfaAA4FlagHF" |
| 16 | +// CHECK: @"$s18runtime_attributes1AV1xSaySiGSgvpfaAA4FlagHF" |
| 17 | +// CHECK: @"$s18runtime_attributes1AV1xSaySiGSgvpfaAA13OnlyPropsTestHF" |
| 18 | +// CHECK: @"$s18runtime_attributes1AV5InnerC4testSaySiGSgvpfaAA4FlagHF" |
| 19 | +// CHECK: @"$s18runtime_attributes1AV5InnerC4testSaySiGSgvpfaAA13OnlyPropsTestHF" |
| 20 | +// CHECK: @"$s18runtime_attributes1AV5InnerAcDCmvpfaAA4FlagHF" |
| 21 | +// CHECK: @"$s18runtime_attributes1AAaBVmvpfaAA4FlagHF" |
| 22 | +// CHECK: @"$s18runtime_attributes1AV5InnerC1BV03extC10StaticTestyycvpZfaAA4FlagHF" |
| 23 | +// CHECK: @"$s18runtime_attributes1AV5InnerC1BV03extC4TestyycvpZfaAA4FlagHF" |
| 24 | +// CHECK: @"$s18runtime_attributes1AV5InnerC1BV6storedSivpfaAA13OnlyPropsTestHF" |
| 25 | +// CHECK: @"$s18runtime_attributes1AV5InnerC1BV6storedSivpfaAA4FlagHF" |
| 26 | +// CHECK: @"$s18runtime_attributes1AV5InnerC1BAeFVmvpfaAA4FlagHF" |
| 27 | +// CHECK: @"$s18runtime_attributes1AV5InnerC13extStaticTestyycvpZfaAA4FlagHF" |
| 28 | +// CHECK: @"$s18runtime_attributes1AV5InnerC7extTestyycvpZfaAA4FlagHF" |
| 29 | +// CHECK: @"$s18runtime_attributes1AV5InnerC11extComputedSivpfa3RAD6IgnoreHF" |
| 30 | +// CHECK: @"$s18runtime_attributes1AV5InnerC11extComputedSivpfaAA4FlagHF" |
| 31 | +// CHECK: @"$s18runtime_attributes1AV5InnerC11extComputedSivpfaAA13OnlyPropsTestHF" |
| 32 | +// CHECK: @"$s18runtime_attributes16WithExternalAttrAaBVmvpfa3RAD6IgnoreHF" |
| 33 | +// CHECK: @"$s18runtime_attributes4testyySicvpfa3RAD13TestAmbiguityHF" |
| 34 | +// CHECK: @"$s18runtime_attributes4testyySScvpfa3RAD13TestAmbiguityHF" |
| 35 | +// CHECK: @"$s18runtime_attributes15TestNoAmbiguityV10testStaticSiycvpZfa3RAD0cE0HF" |
| 36 | +// CHECK: @"$s18runtime_attributes15TestNoAmbiguityV10testStaticyycvpZfa3RAD0cE0HF" |
| 37 | +// CHECK: @"$s18runtime_attributes15TestNoAmbiguityV8testInstyySi_SStcvpfa3RAD0cE0HF" |
| 38 | +// CHECK: @"$s18runtime_attributes15TestNoAmbiguityV8testInstyySi_Sitcvpfa3RAD0cE0HF" |
| 39 | + |
| 40 | +// CHECK: @"$s18runtime_attributes4FlagVHa" = internal constant { i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32 } { i32 0, i32 trunc (i64 sub (i64 ptrtoint (<{ i32, i32, i32, i32, i32, i32, i32, i32, i32, i16, i16, i16, i16, i8, i8, i8, i8 }>* @"$s18runtime_attributes4FlagVMn" to i64), i64 ptrtoint (i32* getelementptr inbounds ({ i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32 }, { i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32 }* @"$s18runtime_attributes4FlagVHa", i32 0, i32 1) to i64)) to i32), i32 16, {{.*}} @"$s18runtime_attributes4FlagVHa", i32 0, i32 34) to i64)) to i32) }, section "__TEXT, __swift5_rattrs, regular", align 4 |
| 41 | + |
| 42 | +// CHECK: @"$s18runtime_attributes13OnlyPropsTestVHa" = internal constant { i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32 } { i32 0, i32 trunc (i64 sub (i64 ptrtoint (<{ i32, i32, i32, i32, i32, i32, i32, i32, i32, i16, i16, i16, i16, i8, i8, i8, i8 }>* @"$s18runtime_attributes13OnlyPropsTestVMn" to i64), i64 ptrtoint (i32* getelementptr inbounds ({ i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32 }, { i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32 }* @"$s18runtime_attributes13OnlyPropsTestVHa", i32 0, i32 1) to i64)) to i32), i32 4, {{.*}} @"$s18runtime_attributes13OnlyPropsTestVHa", i32 0, i32 10) to i64)) to i32) }, section "__TEXT, __swift5_rattrs, regular", align 4 |
| 43 | + |
| 44 | +// CHECK: @"$s3RAD6IgnoreVHa" = internal constant { i32, i32, i32, i32, i32, i32, i32 } { i32 0, i32 trunc (i64 sub (i64 ptrtoint (%swift.type_descriptor* @"$s3RAD6IgnoreVMn" to i64), i64 ptrtoint (i32* getelementptr inbounds ({ i32, i32, i32, i32, i32, i32, i32 }, { i32, i32, i32, i32, i32, i32, i32 }* @"$s3RAD6IgnoreVHa", i32 0, i32 1) to i64)) to i32), i32 2, i32 trunc (i64 sub (i64 ptrtoint (<{ [2 x i8], i8 }>* @"symbolic Si" to i64), i64 ptrtoint (i32* getelementptr inbounds ({ i32, i32, i32, i32, i32, i32, i32 }, { i32, i32, i32, i32, i32, i32, i32 }* @"$s3RAD6IgnoreVHa", i32 0, i32 3) to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint (%swift.accessible_function* @"$s18runtime_attributes1AV5InnerC11extComputedSivpfa3RAD6IgnoreHF" to i64), i64 ptrtoint (i32* getelementptr inbounds ({ i32, i32, i32, i32, i32, i32, i32 }, { i32, i32, i32, i32, i32, i32, i32 }* @"$s3RAD6IgnoreVHa", i32 0, i32 4) to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint (<{ i8, i32, [1 x i8], i8 }>* @"symbolic _____m 18runtime_attributes16WithExternalAttrV" to i64), i64 ptrtoint (i32* getelementptr inbounds ({ i32, i32, i32, i32, i32, i32, i32 }, { i32, i32, i32, i32, i32, i32, i32 }* @"$s3RAD6IgnoreVHa", i32 0, i32 5) to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint (%swift.accessible_function* @"$s18runtime_attributes16WithExternalAttrAaBVmvpfa3RAD6IgnoreHF" to i64), i64 ptrtoint (i32* getelementptr inbounds ({ i32, i32, i32, i32, i32, i32, i32 }, { i32, i32, i32, i32, i32, i32, i32 }* @"$s3RAD6IgnoreVHa", i32 0, i32 6) to i64)) to i32) }, section "__TEXT, __swift5_rattrs, regular", align 4 |
| 45 | + |
| 46 | +// CHECK: @"$s3RAD13TestAmbiguityVHa" = internal constant { i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32 } { i32 0, i32 trunc (i64 sub (i64 ptrtoint (%swift.type_descriptor* @"$s3RAD13TestAmbiguityVMn" to i64), i64 ptrtoint (i32* getelementptr inbounds ({ i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32 }, { i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32 }* @"$s3RAD13TestAmbiguityVHa", i32 0, i32 1) to i64)) to i32), i32 6, i32 trunc (i64 sub (i64 ptrtoint (<{ [4 x i8], i8 }>* @"symbolic ySic" to i64), i64 ptrtoint (i32* getelementptr inbounds ({ i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32 }, { i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32 }* @"$s3RAD13TestAmbiguityVHa", i32 0, i32 3) to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint (%swift.accessible_function* @"$s18runtime_attributes4testyySicvpfa3RAD13TestAmbiguityHF" to i64), i64 ptrtoint (i32* getelementptr inbounds ({ i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32 }, { i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32 }* @"$s3RAD13TestAmbiguityVHa", i32 0, i32 4) to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint (<{ [4 x i8], i8 }>* @"symbolic ySSc" to i64), i64 ptrtoint (i32* getelementptr inbounds ({ i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32 }, { i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32 }* @"$s3RAD13TestAmbiguityVHa", i32 0, i32 5) to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint (%swift.accessible_function* @"$s18runtime_attributes4testyySScvpfa3RAD13TestAmbiguityHF" to i64), i64 ptrtoint (i32* getelementptr inbounds ({ i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32 }, { i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32 }* @"$s3RAD13TestAmbiguityVHa", i32 0, i32 6) to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint (<{ [4 x i8], i8, i32, [2 x i8], i8 }>* @"symbolic Siyc_____mc 18runtime_attributes15TestNoAmbiguityV" to i64), i64 ptrtoint (i32* getelementptr inbounds ({ i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32 }, { i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32 }* @"$s3RAD13TestAmbiguityVHa", i32 0, i32 7) to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint (%swift.accessible_function* @"$s18runtime_attributes15TestNoAmbiguityV10testStaticSiycvpZfa3RAD0cE0HF" to i64), i64 ptrtoint (i32* getelementptr inbounds ({ i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32 }, { i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32 }* @"$s3RAD13TestAmbiguityVHa", i32 0, i32 8) to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint (<{ [3 x i8], i8, i32, [2 x i8], i8 }>* @"symbolic yyc_____mc 18runtime_attributes15TestNoAmbiguityV" to i64), i64 ptrtoint (i32* getelementptr inbounds ({ i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32 }, { i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32 }* @"$s3RAD13TestAmbiguityVHa", i32 0, i32 9) to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint (%swift.accessible_function* @"$s18runtime_attributes15TestNoAmbiguityV10testStaticyycvpZfa3RAD0cE0HF" to i64), i64 ptrtoint (i32* getelementptr inbounds ({ i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32 }, { i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32 }* @"$s3RAD13TestAmbiguityVHa", i32 0, i32 10) to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint (<{ [8 x i8], i8, i32, [1 x i8], i8 }>* @"symbolic ySi_SStc_____c 18runtime_attributes15TestNoAmbiguityV" to i64), i64 ptrtoint (i32* getelementptr inbounds ({ i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32 }, { i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32 }* @"$s3RAD13TestAmbiguityVHa", i32 0, i32 11) to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint (%swift.accessible_function* @"$s18runtime_attributes15TestNoAmbiguityV8testInstyySi_SStcvpfa3RAD0cE0HF" to i64), i64 ptrtoint (i32* getelementptr inbounds ({ i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32 }, { i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32 }* @"$s3RAD13TestAmbiguityVHa", i32 0, i32 12) to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint (<{ [8 x i8], i8, i32, [1 x i8], i8 }>* @"symbolic ySi_Sitc_____c 18runtime_attributes15TestNoAmbiguityV" to i64), i64 ptrtoint (i32* getelementptr inbounds ({ i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32 }, { i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32 }* @"$s3RAD13TestAmbiguityVHa", i32 0, i32 13) to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint (%swift.accessible_function* @"$s18runtime_attributes15TestNoAmbiguityV8testInstyySi_Sitcvpfa3RAD0cE0HF" to i64), i64 ptrtoint (i32* getelementptr inbounds ({ i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32 }, { i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32 }* @"$s3RAD13TestAmbiguityVHa", i32 0, i32 14) to i64)) to i32) }, section "__TEXT, __swift5_rattrs, regular", align 4 |
| 47 | + |
| 48 | +import RAD |
| 49 | + |
| 50 | +@runtimeMetadata |
| 51 | +struct Flag<T> { |
| 52 | + init(attachedTo: T.Type, _ description: String = "") {} |
| 53 | + init<Args>(attachedTo: (Args) -> T, _ description: String = "") {} |
| 54 | + init<Base>(attachedTo: KeyPath<Base, T>, _ description: String = "") {} |
| 55 | +} |
| 56 | + |
| 57 | +@runtimeMetadata |
| 58 | +struct OnlyPropsTest<B, V> { |
| 59 | + init(attachedTo: KeyPath<B, V>) {} |
| 60 | +} |
| 61 | + |
| 62 | +// - Check that all of the generator functions have been emitted |
| 63 | + |
| 64 | +// CHECK-LABEL: define hidden swiftcc i8 @"$s18runtime_attributes9gloabalFnyycvpfaAA4Flag"() |
| 65 | +@Flag("global") func gloabalFn() {} |
| 66 | + |
| 67 | +@Flag |
| 68 | +struct A { |
| 69 | + // CHECK-LABEL: define hidden swiftcc i8 @"$s18runtime_attributes1AV2v1SSvpfaAA4Flag"() |
| 70 | + @Flag("v1") var v1: String = "" |
| 71 | + |
| 72 | + // CHECK-LABEL: define hidden swiftcc i8 @"$s18runtime_attributes1AV4compSivpfaAA4Flag"() |
| 73 | + @Flag var comp: Int { |
| 74 | + get { 42 } |
| 75 | + } |
| 76 | + |
| 77 | + // CHECK-LABEL: define hidden swiftcc i8 @"$s18runtime_attributes1AV5test1SiycvpZfaAA4Flag"() |
| 78 | + @Flag static func test1() -> Int { 42 } |
| 79 | + |
| 80 | + // CHECK-LABEL: define hidden swiftcc i8 @"$s18runtime_attributes1AV5test2yycvpfaAA4Flag"() |
| 81 | + @Flag("test2") func test2() {} // Ok |
| 82 | + |
| 83 | + // CHECK-LABEL: define hidden swiftcc i8 @"$s18runtime_attributes1AV1xSaySiGSgvpfaAA4Flag"() |
| 84 | + // CHECK-LABEL: define hidden swiftcc i8 @"$s18runtime_attributes1AV1xSaySiGSgvpfaAA13OnlyPropsTest"() |
| 85 | + @OnlyPropsTest @Flag("x") var x: [Int]? = [] // Ok |
| 86 | + |
| 87 | + @Flag("Inner type") class Inner { |
| 88 | + // CHECK-LABEL: define hidden swiftcc i8 @"$s18runtime_attributes1AV5InnerC4testSaySiGSgvpfaAA4Flag"() |
| 89 | + // CHECK-LABEL: define hidden swiftcc i8 @"$s18runtime_attributes1AV5InnerC4testSaySiGSgvpfaAA13OnlyPropsTest"() |
| 90 | + @OnlyPropsTest @Flag("test property") var test: [Int]? = nil // Ok |
| 91 | + } |
| 92 | +} |
| 93 | + |
| 94 | +// The generator for `struct A` is emitted last. |
| 95 | +// CHECK-LABEL: define hidden swiftcc i8 @"$s18runtime_attributes1AAaBVmvpfaAA4Flag"() |
| 96 | + |
| 97 | +extension A.Inner { |
| 98 | + @Flag("B type") struct B { |
| 99 | + // CHECK-LABEL: define hidden swiftcc i8 @"$s18runtime_attributes1AV5InnerC1BV03extC10StaticTestyycvpZfaAA4Flag"() |
| 100 | + @Flag static func extInnerStaticTest() {} |
| 101 | + // CHECK-LABEL: define hidden swiftcc i8 @"$s18runtime_attributes1AV5InnerC1BV03extC4TestyycvpZfaAA4Flag"() |
| 102 | + @Flag static func extInnerTest() {} |
| 103 | + |
| 104 | + @Flag("stored prop") @OnlyPropsTest let stored: Int = 42 |
| 105 | + } // CHECK-LABEL: define hidden swiftcc i8 @"$s18runtime_attributes1AV5InnerC1BAeFVmvpfaAA4Flag"() |
| 106 | + |
| 107 | + // CHECK-LABEL: define hidden swiftcc i8 @"$s18runtime_attributes1AV5InnerC13extStaticTestyycvpZfaAA4Flag"() |
| 108 | + @Flag static func extStaticTest() {} |
| 109 | + // CHECK-LABEL: define hidden swiftcc i8 @"$s18runtime_attributes1AV5InnerC7extTestyycvpZfaAA4Flag"() |
| 110 | + @Flag static func extTest() {} |
| 111 | + |
| 112 | + @OnlyPropsTest @Flag @Ignore var extComputed: Int { |
| 113 | + get { 42 } |
| 114 | + } |
| 115 | +} |
| 116 | + |
| 117 | +// CHECK-LABEL: define hidden swiftcc i8 @"$s18runtime_attributes16WithExternalAttrAaBVmvpfa3RAD6Ignore"() |
| 118 | +@Ignore struct WithExternalAttr {} |
| 119 | + |
| 120 | +// CHECK-LABEL: define hidden swiftcc i8 @"$s18runtime_attributes4testyySicvpfa3RAD13TestAmbiguity"() |
| 121 | +@TestAmbiguity public func test(_: Int) {} |
| 122 | +// CHECK-LABEL: define hidden swiftcc i8 @"$s18runtime_attributes4testyySScvpfa3RAD13TestAmbiguity"() |
| 123 | +@TestAmbiguity public func test(_: String) {} |
| 124 | + |
| 125 | +public struct TestNoAmbiguity { |
| 126 | + // CHECK-LABEL: define hidden swiftcc i8 @"$s18runtime_attributes15TestNoAmbiguityV10testStaticSiycvpZfa3RAD0cE0"() |
| 127 | + @TestAmbiguity static func testStatic() -> Int { 42 } |
| 128 | + // CHECK-LABEL: define hidden swiftcc i8 @"$s18runtime_attributes15TestNoAmbiguityV10testStaticyycvpZfa3RAD0cE0"() |
| 129 | + @TestAmbiguity static func testStatic() {} |
| 130 | + |
| 131 | + // CHECK-LABEL: define hidden swiftcc i8 @"$s18runtime_attributes15TestNoAmbiguityV8testInstyySi_SStcvpfa3RAD0cE0"() |
| 132 | + @TestAmbiguity func testInst(_: Int, _: String) {} |
| 133 | + // CHECK-LABEL: define hidden swiftcc i8 @"$s18runtime_attributes15TestNoAmbiguityV8testInstyySi_Sitcvpfa3RAD0cE0"() |
| 134 | + @TestAmbiguity func testInst(_: Int, _: Int) {} |
| 135 | +} |
0 commit comments