Skip to content

Commit 466335b

Browse files
committed
Tests: #_hasSymbol support for members of opaque/existential types.
Resolves rdar://101063734
1 parent c2f7452 commit 466335b

File tree

6 files changed

+73
-2
lines changed

6 files changed

+73
-2
lines changed

test/IRGen/Inputs/has_symbol_helper.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ public func asyncFunc() async {}
2121

2222
public protocol P {
2323
func requirement()
24+
func requirementWithDefaultImpl()
25+
}
26+
27+
extension P {
28+
public func requirementWithDefaultImpl() {}
2429
}
2530

2631
public struct S {

test/IRGen/has_symbol.swift

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,30 @@ public func testEnum(_ e: E) {
113113
// CHECK: define linkonce_odr hidden i1 @"$s17has_symbol_helper1EO11payloadCaseyAcA1SVcACmFTwS"()
114114
// CHECK: ret i1 icmp ne (i32* @"$s17has_symbol_helper1EO11payloadCaseyAcA1SVcACmFWC", i32* null)
115115

116+
public func testOpaqueParameter<T: P>(_ p: T) {
117+
// CHECK: %{{[0-9]+}} = call i1 @"$s17has_symbol_helper1PP11requirementyyFTwS"()
118+
if #_hasSymbol(p.requirement) {}
119+
120+
// CHECK: %{{[0-9]+}} = call i1 @"$s17has_symbol_helper1PP26requirementWithDefaultImplyyFTwS"()
121+
if #_hasSymbol(p.requirementWithDefaultImpl) {}
122+
}
123+
124+
// --- P.requirement() ---
125+
// CHECK: define linkonce_odr hidden i1 @"$s17has_symbol_helper1PP11requirementyyFTwS"()
126+
// CHECK: ret i1 icmp ne (void (%swift.opaque*, %swift.type*, i8**)* @"$s17has_symbol_helper1PP11requirementyyF", void (%swift.opaque*, %swift.type*, i8**)* null)
127+
128+
// --- P.requirementWithDefaultImpl() ---
129+
// CHECK: define linkonce_odr hidden i1 @"$s17has_symbol_helper1PP26requirementWithDefaultImplyyFTwS"()
130+
// CHECK: ret i1 icmp ne (void (%swift.opaque*, %swift.type*, i8**)* @"$s17has_symbol_helper1PP26requirementWithDefaultImplyyF", void (%swift.opaque*, %swift.type*, i8**)* null)
131+
132+
public func testExistentialParameter(_ p: any P) {
133+
// CHECK: %{{[0-9]+}} = call i1 @"$s17has_symbol_helper1PP11requirementyyFTwS"()
134+
if #_hasSymbol(p.requirement) {}
135+
136+
// CHECK: %{{[0-9]+}} = call i1 @"$s17has_symbol_helper1PP26requirementWithDefaultImplyyFTwS"()
137+
if #_hasSymbol(p.requirementWithDefaultImpl) {}
138+
}
139+
116140
public func testMetatypes() {
117141
// CHECK: %{{[0-9]+}} = call i1 @"$s17has_symbol_helper1SVTwS"()
118142
if #_hasSymbol(S.self) {}

test/SILGen/Inputs/has_symbol_helper.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ public func genericFunc<T: P>(_ t: T) {}
88

99
public protocol P {
1010
func requirement()
11+
func requirementWithDefaultImpl()
12+
}
13+
14+
extension P {
15+
public func requirementWithDefaultImpl() {}
1116
}
1217

1318
public struct S {

test/SILGen/has_symbol.swift

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,16 +170,31 @@ func testEnum(_ e: E) {
170170
// CHECK: sil @$s17has_symbol_helper1EO6methodyyF : $@convention(method) (@in_guaranteed E) -> ()
171171

172172

173-
// CHECK: sil hidden [ossa] @$s4test0A8Protocolyyx17has_symbol_helper1PRzlF : $@convention(thin) <T where T : P> (@in_guaranteed T) -> ()
174-
func testProtocol<T: P>(_ p: T) {
173+
// CHECK: sil hidden [ossa] @$s4test0A15OpaqueParameteryyx17has_symbol_helper1PRzlF : $@convention(thin) <T where T : P> (@in_guaranteed T) -> ()
174+
func testOpaqueParameter<T: P>(_ p: T) {
175175
// CHECK: [[RES:%[0-9]+]] = has_symbol #P.requirement
176176
// CHECK: cond_br [[RES]], bb{{[0-9]+}}, bb{{[0-9]+}}
177177
if #_hasSymbol(p.requirement) {}
178+
// CHECK: [[RES:%[0-9]+]] = has_symbol #P.requirementWithDefaultImpl
179+
// CHECK: cond_br [[RES]], bb{{[0-9]+}}, bb{{[0-9]+}}
180+
if #_hasSymbol(p.requirementWithDefaultImpl) {}
178181
}
179182

180183
// --- P.requirement() ---
181184
// CHECK: sil @$s17has_symbol_helper1PP11requirementyyF : $@convention(witness_method: P) <τ_0_0 where τ_0_0 : P> (@in_guaranteed τ_0_0) -> ()
182185

186+
// --- P.requirementWithDefaultImpl() ---
187+
// CHECK: sil @$s17has_symbol_helper1PP26requirementWithDefaultImplyyF : $@convention(witness_method: P) <τ_0_0 where τ_0_0 : P> (@in_guaranteed τ_0_0) -> ()
188+
189+
// CHECK: sil hidden [ossa] @$s4test0A20ExistentialParameteryy17has_symbol_helper1P_pF : $@convention(thin) (@in_guaranteed any P) -> ()
190+
func testExistentialParameter(_ p: any P) {
191+
// CHECK: [[RES:%[0-9]+]] = has_symbol #P.requirement
192+
// CHECK: cond_br [[RES]], bb{{[0-9]+}}, bb{{[0-9]+}}
193+
if #_hasSymbol(p.requirement) {}
194+
// CHECK: [[RES:%[0-9]+]] = has_symbol #P.requirementWithDefaultImpl
195+
// CHECK: cond_br [[RES]], bb{{[0-9]+}}, bb{{[0-9]+}}
196+
if #_hasSymbol(p.requirementWithDefaultImpl) {}
197+
}
183198

184199
// CHECK: sil hidden [ossa] @$s4test0A9MetatypesyyF : $@convention(thin) () -> ()
185200
func testMetatypes() {

test/Sema/Inputs/has_symbol_helper.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,16 @@ extension P {
1616
public func requirementWithDefaultImpl() {}
1717
}
1818

19+
public protocol PAT {
20+
associatedtype A
21+
func requirement() -> A
22+
func requirementWithDefaultImpl()
23+
}
24+
25+
extension PAT {
26+
public func requirementWithDefaultImpl() {}
27+
}
28+
1929
public struct S {
2030
public static var staticMember: Int = 0
2131
public static func staticFunc() {}

test/Sema/has_symbol.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,18 @@ func testEnum(_ e: E) {
6060
if #_hasSymbol(e.method) {}
6161
}
6262

63+
func testOpaqueParameter<T: PAT>(_ p: T) {
64+
// FIXME: Improve this diagnostic
65+
if #_hasSymbol(T.A.self) {} // expected-error {{'#_hasSymbol' condition must refer to a declaration}}
66+
if #_hasSymbol(p.requirement) {}
67+
if #_hasSymbol(p.requirementWithDefaultImpl) {}
68+
}
69+
70+
func testExistentialParameter(_ p: any P) {
71+
if #_hasSymbol(p.requirement) {}
72+
if #_hasSymbol(p.requirementWithDefaultImpl) {}
73+
}
74+
6375
func testMetatypes() {
6476
if #_hasSymbol(P.self) {}
6577
if #_hasSymbol(S.self) {}

0 commit comments

Comments
 (0)