|
| 1 | +// RUN: %empty-directory(%t) |
| 2 | +// RUN: %swift-frontend %s -swift-version 6 -module-name main -emit-ir -o %t/new.ir |
| 3 | +// RUN: %FileCheck %s --check-prefix=NEW < %t/new.ir |
| 4 | +// RUN: %target-swift-frontend %s -target %target-cpu-apple-macosx11 -module-name main -emit-ir -o %t/old.ir |
| 5 | +// RUN: %FileCheck %s --check-prefix=OLD < %t/old.ir |
| 6 | + |
| 7 | +// Check that we add extra type metadata accessors for types with generic |
| 8 | +// parameters that have an inverse. These are used instead of using demangling |
| 9 | +// cache variables since old runtimes cannot synthesize type metadata based on |
| 10 | +// the new mangling. |
| 11 | + |
| 12 | +// RUN: %target-build-swift -target %target-cpu-apple-macosx11 %s -o %t/test_mangling |
| 13 | +// RUN: %target-run %t/test_mangling | %FileCheck %s |
| 14 | + |
| 15 | +// REQUIRES: OS=macosx |
| 16 | +// REQUIRES: executable_test |
| 17 | + |
| 18 | + |
| 19 | +// This type's generic parameter is noncopyable, so older runtimes can't |
| 20 | +// demangle the type's name to build the metadata. |
| 21 | +struct Foo<T: ~Copyable>: ~Copyable { |
| 22 | + mutating func bar(_ i: Int) { print("Foo.bar(\(i))") } |
| 23 | +} |
| 24 | + |
| 25 | +func test() { |
| 26 | + var foo = Foo<Int>() |
| 27 | + foo.bar(1) |
| 28 | +} |
| 29 | +test() |
| 30 | +// CHECK: Foo.bar(1) |
| 31 | + |
| 32 | +// NEW: define hidden swiftcc void @"$s4main4testyyF"() |
| 33 | +// NEW: call ptr @__swift_instantiateConcreteTypeFromMangledName(ptr @"$s4main3FooVySiGMD") |
| 34 | +// NEW: } |
| 35 | + |
| 36 | +// OLD: define hidden swiftcc void @"$s4main4testyyF"() |
| 37 | +// OLD: call swiftcc %swift.metadata_response @"$s4main3FooVySiGMa"(i64 0) |
| 38 | +// OLD: } |
| 39 | + |
| 40 | +struct NC: ~Copyable {} |
| 41 | + |
| 42 | +// NEW: define hidden swiftcc void @"$s4main10testWithNCyyF"() |
| 43 | +// NEW: call ptr @__swift_instantiateConcreteTypeFromMangledName(ptr @"$s4main3FooVyAA2NCVGMD") |
| 44 | +// NEW: } |
| 45 | + |
| 46 | +// OLD: define hidden swiftcc void @"$s4main10testWithNCyyF"() |
| 47 | +// OLD: call swiftcc %swift.metadata_response @"$s4main3FooVyAA2NCVGMa" |
| 48 | +// OLD: } |
| 49 | +func testWithNC() { |
| 50 | + var foo = Foo<NC>() |
| 51 | + foo.bar(2) |
| 52 | +} |
| 53 | +testWithNC() |
| 54 | +// CHECK: Foo.bar(2) |
| 55 | + |
| 56 | + |
| 57 | +// NEW: define hidden swiftcc void @"$s4main17testWithNCGenericyyxnRi_zlF" |
| 58 | +// NEW: call swiftcc %swift.metadata_response @"$s4main3FooVMa" |
| 59 | +// NEW: } |
| 60 | + |
| 61 | +// OLD: define hidden swiftcc void @"$s4main17testWithNCGenericyyxnRi_zlF" |
| 62 | +// OLD: call swiftcc %swift.metadata_response @"$s4main3FooVMa" |
| 63 | +// OLD: } |
| 64 | +func testWithNCGeneric<T: ~Copyable>(_ t: consuming T) { |
| 65 | + var foo = Foo<T>() |
| 66 | + foo.bar(3) |
| 67 | +} |
| 68 | +testWithNCGeneric(Foo<NC>()) |
| 69 | +// CHECK: Foo.bar(3) |
| 70 | + |
| 71 | + |
| 72 | +// This type does not need a Swift 6.0 runtime, despite being noncopyable, |
| 73 | +// because it doesn't have a noncopyable generic parameter. |
| 74 | +struct JustNoncopyable<T>: ~Copyable { |
| 75 | + mutating func bar() { print("JustNoncopyable.bar") } |
| 76 | +} |
| 77 | + |
| 78 | +func testNonGeneric() { |
| 79 | + var ng = JustNoncopyable<Int>() |
| 80 | + ng.bar() |
| 81 | +} |
| 82 | +testNonGeneric() |
| 83 | +// CHECK: JustNoncopyable.bar |
| 84 | + |
| 85 | +// NEW: define hidden swiftcc void @"$s4main14testNonGenericyyF"() |
| 86 | +// NEW: call ptr @__swift_instantiateConcreteTypeFromMangledName(ptr @"$s4main15JustNoncopyableVySiGMD") |
| 87 | +// NEW: } |
| 88 | + |
| 89 | +// OLD: define hidden swiftcc void @"$s4main14testNonGenericyyF"() |
| 90 | +// OLD: call ptr @__swift_instantiateConcreteTypeFromMangledName(ptr @"$s4main15JustNoncopyableVySiGMD") |
| 91 | +// OLD: } |
| 92 | + |
| 93 | + |
| 94 | +/// Check that Optional still uses `__swift_instantiateConcreteTypeFromMangledName` |
| 95 | +/// even when calling a method available to a noncopyable Optional. |
| 96 | +extension Optional where Wrapped: ~Copyable { |
| 97 | + mutating func bar(_ i: Int) { print("Optional.bar(\(i))") } |
| 98 | +} |
| 99 | + |
| 100 | +// NEW: define hidden swiftcc void @"$s4main20testCopyableOptionalyyF"() |
| 101 | +// NEW: call ptr @__swift_instantiateConcreteTypeFromMangledName(ptr @"$sSiSgMD") |
| 102 | +// NEW: } |
| 103 | + |
| 104 | +// OLD: define hidden swiftcc void @"$s4main20testCopyableOptionalyyF"() |
| 105 | +// OLD: call ptr @__swift_instantiateConcreteTypeFromMangledName(ptr @"$sSiSgMD") |
| 106 | +// OLD: } |
| 107 | +func testCopyableOptional() { |
| 108 | + var opt = Optional<Int>(94103) |
| 109 | + opt.bar(1) |
| 110 | +} |
| 111 | +testCopyableOptional() |
| 112 | +// CHECK: Optional.bar(1) |
| 113 | + |
| 114 | + |
| 115 | +// NEW: define hidden swiftcc void @"$s4main23testNOTCopyableOptionalyyF"() |
| 116 | +// NEW: call ptr @__swift_instantiateConcreteTypeFromMangledName(ptr @"$s4main2NCVSgMD") |
| 117 | +// NEW: } |
| 118 | + |
| 119 | +// OLD: define hidden swiftcc void @"$s4main23testNOTCopyableOptionalyyF"() |
| 120 | +// OLD: call ptr @__swift_instantiateConcreteTypeFromMangledName(ptr @"$s4main2NCVSgMD") |
| 121 | +// OLD: } |
| 122 | +func testNOTCopyableOptional() { |
| 123 | + var opt = Optional<NC>(NC()) |
| 124 | + opt.bar(2) |
| 125 | +} |
| 126 | +testNOTCopyableOptional() |
| 127 | +// CHECK: Optional.bar(2) |
0 commit comments