|
| 1 | +// RUN: rm -rf %t && mkdir -p %t |
| 2 | +// RUN: %target-swift-frontend -emit-sil -o - -emit-module-path %t/Lib.swiftmodule -module-name Lib -I %S/Inputs/custom-modules -disable-objc-attr-requires-foundation-module %s | %FileCheck -check-prefix CHECK-WITNESS-TABLE %s |
| 3 | + |
| 4 | +// RUN: %target-swift-ide-test -source-filename=x -print-module -module-to-print Lib -I %t -I %S/Inputs/custom-modules | %FileCheck %s |
| 5 | + |
| 6 | +// RUN: %target-swift-ide-test -source-filename=x -print-module -module-to-print Lib -I %t -I %S/Inputs/custom-modules -Xcc -DBAD -enable-experimental-deserialization-recovery | %FileCheck -check-prefix CHECK-RECOVERY %s |
| 7 | + |
| 8 | +// RUN: %target-swift-frontend -typecheck -I %t -I %S/Inputs/custom-modules -Xcc -DBAD -DTEST -enable-experimental-deserialization-recovery -DVERIFY %s -verify |
| 9 | + |
| 10 | +// RUN: %target-swift-frontend -emit-ir -I %t -I %S/Inputs/custom-modules -DTEST %s | %FileCheck -check-prefix CHECK-IR %s |
| 11 | +// RUN: %target-swift-frontend -emit-ir -I %t -I %S/Inputs/custom-modules -Xcc -DBAD -DTEST -enable-experimental-deserialization-recovery %s | %FileCheck -check-prefix CHECK-IR %s |
| 12 | + |
| 13 | +#if TEST |
| 14 | + |
| 15 | +import Typedefs |
| 16 | +import Lib |
| 17 | + |
| 18 | +// CHECK-IR-LABEL: define{{.*}} void @_T04main19testWitnessDispatch |
| 19 | +public func testWitnessDispatch(user: Proto) { |
| 20 | + // The important thing in this CHECK line is the "i64 11", which is the offset |
| 21 | + // for the witness table slot for 'lastMethod()'. If the layout here |
| 22 | + // changes, please check that offset 11 is still correct. |
| 23 | + // CHECK-IR-NOT: ret |
| 24 | + // CHECK-IR: [[SLOT:%.+]] = getelementptr inbounds i8*, i8** {{%.+}}, i32 11 |
| 25 | + // CHECK-IR-NOT: ret |
| 26 | + // CHECK-IR: [[RAW_METHOD:%.+]] = load i8*, i8** [[SLOT]] |
| 27 | + // CHECK-IR-NOT: ret |
| 28 | + // CHECK-IR: [[METHOD:%.+]] = bitcast i8* [[RAW_METHOD]] to void (%swift.opaque*, %swift.type*, i8**)* |
| 29 | + // CHECK-IR-NOT: ret |
| 30 | + // CHECK-IR: call swiftcc void [[METHOD]]( |
| 31 | + _ = user.lastMethod() |
| 32 | +} // CHECK-IR: ret void |
| 33 | + |
| 34 | +// CHECK-IR-LABEL: define{{.*}} void @_T04main19testGenericDispatch |
| 35 | +public func testGenericDispatch<T: Proto>(user: T) { |
| 36 | + // The important thing in this CHECK line is the "i64 11", which is the offset |
| 37 | + // for the witness table slot for 'lastMethod()'. If the layout here |
| 38 | + // changes, please check that offset 11 is still correct. |
| 39 | + // CHECK-IR-NOT: ret |
| 40 | + // CHECK-IR: [[SLOT:%.+]] = getelementptr inbounds i8*, i8** %T.Proto, i32 11 |
| 41 | + // CHECK-IR-NOT: ret |
| 42 | + // CHECK-IR: [[RAW_METHOD:%.+]] = load i8*, i8** [[SLOT]] |
| 43 | + // CHECK-IR-NOT: ret |
| 44 | + // CHECK-IR: [[METHOD:%.+]] = bitcast i8* [[RAW_METHOD]] to void (%swift.opaque*, %swift.type*, i8**)* |
| 45 | + // CHECK-IR-NOT: ret |
| 46 | + // CHECK-IR: call swiftcc void [[METHOD]]( |
| 47 | + _ = user.lastMethod() |
| 48 | +} // CHECK-IR: ret void |
| 49 | + |
| 50 | +#if VERIFY |
| 51 | + |
| 52 | +public class TestImpl : Proto {} // expected-error {{type 'TestImpl' cannot conform to protocol 'Proto' because it has requirements that cannot be satisfied}} |
| 53 | + |
| 54 | +#endif // VERIFY |
| 55 | + |
| 56 | +#else // TEST |
| 57 | + |
| 58 | +import Typedefs |
| 59 | + |
| 60 | +// CHECK-LABEL: protocol Proto { |
| 61 | +// CHECK-RECOVERY-LABEL: protocol Proto { |
| 62 | +public protocol Proto { |
| 63 | + // CHECK: var unwrappedProp: UnwrappedInt? { get set } |
| 64 | + // CHECK-RECOVERY: var unwrappedProp: Int32? |
| 65 | + var unwrappedProp: UnwrappedInt? { get set } |
| 66 | + // CHECK: var wrappedProp: WrappedInt? { get set } |
| 67 | + // CHECK-RECOVERY: /* placeholder for _ */ |
| 68 | + // CHECK-RECOVERY: /* placeholder for _ */ |
| 69 | + // CHECK-RECOVERY: /* placeholder for _ */ |
| 70 | + var wrappedProp: WrappedInt? { get set } |
| 71 | + |
| 72 | + // CHECK: func returnsUnwrappedMethod() -> UnwrappedInt |
| 73 | + // CHECK-RECOVERY: func returnsUnwrappedMethod() -> Int32 |
| 74 | + func returnsUnwrappedMethod() -> UnwrappedInt |
| 75 | + // CHECK: func returnsWrappedMethod() -> WrappedInt |
| 76 | + // CHECK-RECOVERY: /* placeholder for returnsWrappedMethod() */ |
| 77 | + func returnsWrappedMethod() -> WrappedInt |
| 78 | + |
| 79 | + // CHECK: subscript(_: WrappedInt) -> () { get } |
| 80 | + // CHECK-RECOVERY: /* placeholder for _ */ |
| 81 | + subscript(_: WrappedInt) -> () { get } |
| 82 | + |
| 83 | + // CHECK: init() |
| 84 | + // CHECK-RECOVERY: init() |
| 85 | + init() |
| 86 | + |
| 87 | + // CHECK: init(wrapped: WrappedInt) |
| 88 | + // CHECK-RECOVERY: /* placeholder for init(wrapped:) */ |
| 89 | + init(wrapped: WrappedInt) |
| 90 | + |
| 91 | + func lastMethod() |
| 92 | +} |
| 93 | +// CHECK: {{^}$}} |
| 94 | +// CHECK-RECOVERY: {{^}$}} |
| 95 | + |
| 96 | +// CHECK-LABEL: struct ProtoLibImpl : Proto { |
| 97 | +// CHECK-RECOVERY-LABEL: struct ProtoLibImpl : Proto { |
| 98 | +public struct ProtoLibImpl : Proto { |
| 99 | + public var unwrappedProp: UnwrappedInt? |
| 100 | + public var wrappedProp: WrappedInt? |
| 101 | + |
| 102 | + public func returnsUnwrappedMethod() -> UnwrappedInt { fatalError() } |
| 103 | + public func returnsWrappedMethod() -> WrappedInt { fatalError() } |
| 104 | + |
| 105 | + public subscript(_: WrappedInt) -> () { return () } |
| 106 | + |
| 107 | + public init() {} |
| 108 | + public init(wrapped: WrappedInt) {} |
| 109 | + |
| 110 | + public func lastMethod() {} |
| 111 | +} |
| 112 | +// CHECK: {{^}$}} |
| 113 | +// CHECK-RECOVERY: {{^}$}} |
| 114 | + |
| 115 | +// This is mostly to check when changes are necessary for the CHECK-IR lines |
| 116 | +// above. |
| 117 | +// CHECK-WITNESS-TABLE-LABEL: sil_witness_table{{.*}} ProtoLibImpl: Proto module Lib { |
| 118 | +// 0 CHECK-WITNESS-TABLE-NEXT: #Proto.unwrappedProp!getter.1: |
| 119 | +// 1 CHECK-WITNESS-TABLE-NEXT: #Proto.unwrappedProp!setter.1: |
| 120 | +// 2 CHECK-WITNESS-TABLE-NEXT: #Proto.unwrappedProp!materializeForSet.1: |
| 121 | +// 3 CHECK-WITNESS-TABLE-NEXT: #Proto.wrappedProp!getter.1: |
| 122 | +// 4 CHECK-WITNESS-TABLE-NEXT: #Proto.wrappedProp!setter.1: |
| 123 | +// 5 CHECK-WITNESS-TABLE-NEXT: #Proto.wrappedProp!materializeForSet.1: |
| 124 | +// 6 CHECK-WITNESS-TABLE-NEXT: #Proto.returnsUnwrappedMethod!1: |
| 125 | +// 7 CHECK-WITNESS-TABLE-NEXT: #Proto.returnsWrappedMethod!1: |
| 126 | +// 8 CHECK-WITNESS-TABLE-NEXT: #Proto.subscript!getter.1: |
| 127 | +// 9 CHECK-WITNESS-TABLE-NEXT: #Proto.init!allocator.1: |
| 128 | +// 10 CHECK-WITNESS-TABLE-NEXT: #Proto.init!allocator.1: |
| 129 | +// 11 CHECK-WITNESS-TABLE-NEXT: #Proto.lastMethod!1: |
| 130 | +// CHECK-WITNESS-TABLE: } |
| 131 | + |
| 132 | +#endif // TEST |
0 commit comments