Skip to content

Commit 73b4b43

Browse files
committed
SILGen: Implement if #_hasSymbol() conditions.
Emit a call to a helper function that determines whether the symbols associated with the declaration referenced in the `#_hasSymbol(...)` condition are non-null at runtime. An upcoming change will emit a definition for this function during IRGen. Resolves rdar://100130015
1 parent 1d473d1 commit 73b4b43

File tree

7 files changed

+314
-4
lines changed

7 files changed

+314
-4
lines changed

include/swift/AST/Decl.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2733,6 +2733,11 @@ class ValueDecl : public Decl {
27332733
/// 'func foo(Int) -> () -> Self?'.
27342734
GenericParameterReferenceInfo findExistentialSelfReferences(
27352735
Type baseTy, bool treatNonResultCovariantSelfAsInvariant) const;
2736+
2737+
/// Returns a synthesized declaration for a query function that provides
2738+
/// the boolean value for a `if #_hasSymbol(...)` condition. The interface
2739+
/// type of the function is `() -> Builtin.Int1`.
2740+
FuncDecl *getHasSymbolQueryDecl() const;
27362741
};
27372742

27382743
/// This is a common base class for declarations which declare a type.

include/swift/AST/TypeCheckRequests.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3736,6 +3736,24 @@ class GetTypeWrapperInitializer
37363736
bool isCached() const { return true; }
37373737
};
37383738

3739+
/// Synthesizes and returns a `#_hasSymbol` query function for the given
3740+
/// `ValueDecl`. The function has an interface type of `() -> Builtin.Int1`.
3741+
class SynthesizeHasSymbolQueryRequest
3742+
: public SimpleRequest<SynthesizeHasSymbolQueryRequest,
3743+
FuncDecl *(const ValueDecl *),
3744+
RequestFlags::Cached> {
3745+
public:
3746+
using SimpleRequest::SimpleRequest;
3747+
3748+
private:
3749+
friend SimpleRequest;
3750+
3751+
FuncDecl *evaluate(Evaluator &evaluator, const ValueDecl *decl) const;
3752+
3753+
public:
3754+
bool isCached() const { return true; }
3755+
};
3756+
37393757
void simple_display(llvm::raw_ostream &out, ASTNode node);
37403758
void simple_display(llvm::raw_ostream &out, Type value);
37413759
void simple_display(llvm::raw_ostream &out, const TypeRepr *TyR);

include/swift/AST/TypeCheckerTypeIDZone.def

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,3 +440,6 @@ SWIFT_REQUEST(TypeChecker, SynthesizeLocalVariableForTypeWrapperStorage,
440440
SWIFT_REQUEST(TypeChecker, GetTypeWrapperInitializer,
441441
ConstructorDecl *(NominalTypeDecl *),
442442
Cached, NoLocationInfo)
443+
SWIFT_REQUEST(TypeChecker, SynthesizeHasSymbolQueryRequest,
444+
FuncDecl *(ValueDecl *),
445+
Cached, NoLocationInfo)

lib/SILGen/SILGenDecl.cpp

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1522,7 +1522,26 @@ void SILGenFunction::emitStmtCondition(StmtCondition Cond, JumpDest FalseDest,
15221522
}
15231523

15241524
case StmtConditionElement::CK_HasSymbol: {
1525-
llvm::report_fatal_error("Can't SILGen #_hasSymbol yet!");
1525+
auto info = elt.getHasSymbolInfo();
1526+
if (info->isInvalid()) {
1527+
SILType i1 = SILType::getBuiltinIntegerType(1, getASTContext());
1528+
booleanTestValue = B.createIntegerLiteral(loc, i1, 1);
1529+
} else {
1530+
auto expr = info->getSymbolExpr();
1531+
auto declRef = info->getReferencedDecl();
1532+
assert(declRef);
1533+
1534+
auto queryFunc = declRef.getDecl()->getHasSymbolQueryDecl();
1535+
SILFunction *silFn = SGM.getFunction(
1536+
SILDeclRef(queryFunc, SILDeclRef::Kind::Func), NotForDefinition);
1537+
SILValue fnRef = B.createFunctionRefFor(loc, silFn);
1538+
booleanTestValue = B.createApply(loc, fnRef, {}, {});
1539+
booleanTestValue = emitUnwrapIntegerResult(expr, booleanTestValue);
1540+
booleanTestLoc = expr;
1541+
1542+
// FIXME: Add decl to list of decls that need a has symbol query
1543+
// function to be emitted during IRGen.
1544+
}
15261545
break;
15271546
}
15281547
}

lib/Sema/CodeSynthesis.cpp

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,15 @@
1616

1717
#include "CodeSynthesis.h"
1818

19-
#include "TypeChecker.h"
2019
#include "TypeCheckDecl.h"
20+
#include "TypeCheckDistributed.h"
2121
#include "TypeCheckObjC.h"
2222
#include "TypeCheckType.h"
23-
#include "TypeCheckDistributed.h"
23+
#include "TypeChecker.h"
24+
#include "swift/AST/ASTMangler.h"
2425
#include "swift/AST/ASTPrinter.h"
2526
#include "swift/AST/Availability.h"
27+
#include "swift/AST/DistributedDecl.h"
2628
#include "swift/AST/Expr.h"
2729
#include "swift/AST/GenericEnvironment.h"
2830
#include "swift/AST/Initializer.h"
@@ -31,7 +33,6 @@
3133
#include "swift/AST/ProtocolConformance.h"
3234
#include "swift/AST/SourceFile.h"
3335
#include "swift/AST/TypeCheckRequests.h"
34-
#include "swift/AST/DistributedDecl.h"
3536
#include "swift/Basic/Defer.h"
3637
#include "swift/ClangImporter/ClangModule.h"
3738
#include "swift/Sema/ConstraintSystem.h"
@@ -1608,3 +1609,32 @@ ConstructorDecl *SynthesizeTypeWrappedTypeMemberwiseInitializer::evaluate(
16081609
ctor->setBody(body, AbstractFunctionDecl::BodyKind::Parsed);
16091610
return ctor;
16101611
}
1612+
1613+
FuncDecl *ValueDecl::getHasSymbolQueryDecl() const {
1614+
return evaluateOrDefault(getASTContext().evaluator,
1615+
SynthesizeHasSymbolQueryRequest{this}, nullptr);
1616+
}
1617+
1618+
FuncDecl *
1619+
SynthesizeHasSymbolQueryRequest::evaluate(Evaluator &evaluator,
1620+
const ValueDecl *decl) const {
1621+
auto &ctx = decl->getASTContext();
1622+
auto dc = decl->getModuleContext();
1623+
1624+
Mangle::ASTMangler mangler;
1625+
auto mangledName = ctx.AllocateCopy(mangler.mangleHasSymbolQuery(decl));
1626+
1627+
ParameterList *params = ParameterList::createEmpty(ctx);
1628+
1629+
DeclName funcName =
1630+
DeclName(ctx, DeclBaseName(ctx.getIdentifier(mangledName)),
1631+
/*argumentNames=*/ArrayRef<Identifier>());
1632+
1633+
auto i1 = BuiltinIntegerType::get(1, ctx);
1634+
FuncDecl *func = FuncDecl::createImplicit(
1635+
ctx, swift::StaticSpellingKind::None, funcName, SourceLoc(),
1636+
/*async=*/false, /*throws=*/false, nullptr, params, i1, dc);
1637+
1638+
func->getAttrs().add(new (ctx) SILGenNameAttr(mangledName, IsImplicit));
1639+
return func;
1640+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
2+
public let global: Int = 0
3+
4+
public func function(with argument: Int) {}
5+
public func genericFunc<T: P>(_ t: T) {}
6+
@_cdecl("cdecl_func") public func cdeclFunc() {}
7+
@_silgen_name("forward_declared_func") public func forwardDeclaredFunc()
8+
9+
public protocol P {
10+
func requirement()
11+
}
12+
13+
public struct S {
14+
public static var staticMember: Int = 0
15+
public static func staticFunc() {}
16+
17+
public var member: Int
18+
19+
public init(member: Int) {
20+
self.member = member
21+
}
22+
public func method(with argument: Int) {}
23+
public func genericFunc<T: P>(_ t: T) {}
24+
}
25+
26+
extension S: P {
27+
public func requirement() {}
28+
}
29+
30+
public struct GenericS<T: P> {
31+
public var member: T
32+
33+
public init(member: T) {
34+
self.member = member
35+
}
36+
public func method(with argument: T) {}
37+
}
38+
39+
public class C {
40+
public static var staticMember: Int = 0
41+
public class func classFunc() {}
42+
43+
public var member: Int
44+
45+
public init(member: Int) {
46+
self.member = member
47+
}
48+
public func method(with argument: Int) {}
49+
}
50+
51+
public enum E {
52+
case basicCase
53+
case payloadCase(_: S)
54+
55+
public func method() {}
56+
}

test/SILGen/has_symbol.swift

Lines changed: 179 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,179 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %target-swift-frontend -emit-module -emit-module-path %t/has_symbol_helper.swiftmodule -parse-as-library %S/Inputs/has_symbol_helper.swift -enable-library-evolution
3+
// RUN: %target-swift-frontend -emit-silgen %s -I %t -module-name test | %FileCheck %s
4+
5+
// REQUIRES: VENDOR=apple
6+
7+
@_weakLinked import has_symbol_helper
8+
9+
// CHECK: sil hidden [ossa] @$s4test0A15GlobalFunctionsyyF : $@convention(thin) () -> ()
10+
func testGlobalFunctions() {
11+
// CHECK: [[QUERY:%[0-9]+]] = function_ref @$s17has_symbol_helper8function4withySi_tFTwS : $@convention(thin) () -> Builtin.Int1
12+
// CHECK: [[RES:%[0-9]+]] = apply [[QUERY]]() : $@convention(thin) () -> Builtin.Int1
13+
// CHECK: cond_br [[RES]], bb{{[0-9]+}}, bb{{[0-9]+}}
14+
if #_hasSymbol(function(with:)) {}
15+
// CHECK: [[QUERY:%[0-9]+]] = function_ref @$s17has_symbol_helper11genericFuncyyxAA1PRzlFTwS : $@convention(thin) () -> Builtin.Int1
16+
// CHECK: [[RES:%[0-9]+]] = apply [[QUERY]]() : $@convention(thin) () -> Builtin.Int1
17+
// CHECK: cond_br [[RES]], bb{{[0-9]+}}, bb{{[0-9]+}}
18+
if #_hasSymbol(genericFunc(_:) as (S) -> Void) {}
19+
// CHECK: [[QUERY:%[0-9]+]] = function_ref @$s17has_symbol_helper9cdeclFuncyyFTwS : $@convention(thin) () -> Builtin.Int1
20+
// CHECK: [[RES:%[0-9]+]] = apply [[QUERY]]() : $@convention(thin) () -> Builtin.Int1
21+
// CHECK: cond_br [[RES]], bb{{[0-9]+}}, bb{{[0-9]+}}
22+
if #_hasSymbol(cdeclFunc) {}
23+
// CHECK: [[QUERY:%[0-9]+]] = function_ref @$s17has_symbol_helper19forwardDeclaredFuncyyFTwS : $@convention(thin) () -> Builtin.Int1
24+
// CHECK: [[RES:%[0-9]+]] = apply [[QUERY]]() : $@convention(thin) () -> Builtin.Int1
25+
// CHECK: cond_br [[RES]], bb{{[0-9]+}}, bb{{[0-9]+}}
26+
if #_hasSymbol(forwardDeclaredFunc) {}
27+
}
28+
29+
// CHECK: sil hidden_external @$s17has_symbol_helper8function4withySi_tFTwS : $@convention(thin) () -> Builtin.Int1
30+
// CHECK: sil hidden_external @$s17has_symbol_helper11genericFuncyyxAA1PRzlFTwS : $@convention(thin) () -> Builtin.Int1
31+
// CHECK: sil hidden_external @$s17has_symbol_helper9cdeclFuncyyFTwS : $@convention(thin) () -> Builtin.Int1
32+
33+
// CHECK: sil hidden [ossa] @$s4test0A4VarsyyF : $@convention(thin) () -> ()
34+
func testVars() {
35+
// CHECK: [[QUERY:%[0-9]+]] = function_ref @$s17has_symbol_helper6globalSivpTwS : $@convention(thin) () -> Builtin.Int1
36+
// CHECK: [[RES:%[0-9]+]] = apply [[QUERY]]() : $@convention(thin) () -> Builtin.Int1
37+
// CHECK: cond_br [[RES]], bb{{[0-9]+}}, bb{{[0-9]+}}
38+
if #_hasSymbol(global) {}
39+
}
40+
41+
// CHECK: sil hidden_external @$s17has_symbol_helper6globalSivpTwS : $@convention(thin) () -> Builtin.Int1
42+
43+
// CHECK: sil hidden [ossa] @$s4test0A6Structyy17has_symbol_helper1SVF : $@convention(thin) (@in_guaranteed S) -> ()
44+
func testStruct(_ s: S) {
45+
// CHECK: [[QUERY:%[0-9]+]] = function_ref @$s17has_symbol_helper1SV6memberSivpTwS : $@convention(thin) () -> Builtin.Int1
46+
// CHECK: [[RES:%[0-9]+]] = apply [[QUERY]]() : $@convention(thin) () -> Builtin.Int1
47+
// CHECK: cond_br [[RES]], bb{{[0-9]+}}, bb{{[0-9]+}}
48+
if #_hasSymbol(s.member) {}
49+
// CHECK: [[QUERY:%[0-9]+]] = function_ref @$s17has_symbol_helper1SV6method4withySi_tFTwS : $@convention(thin) () -> Builtin.Int1
50+
// CHECK: [[RES:%[0-9]+]] = apply [[QUERY]]() : $@convention(thin) () -> Builtin.Int1
51+
// CHECK: cond_br [[RES]], bb{{[0-9]+}}, bb{{[0-9]+}}
52+
if #_hasSymbol(s.method(with:)) {}
53+
// CHECK: [[QUERY:%[0-9]+]] = function_ref @$s17has_symbol_helper1SV11genericFuncyyxAA1PRzlFTwS : $@convention(thin) () -> Builtin.Int1
54+
// CHECK: [[RES:%[0-9]+]] = apply [[QUERY]]() : $@convention(thin) () -> Builtin.Int1
55+
// CHECK: cond_br [[RES]], bb{{[0-9]+}}, bb{{[0-9]+}}
56+
if #_hasSymbol(s.genericFunc(_:) as (S) -> ()) {}
57+
// CHECK: [[QUERY:%[0-9]+]] = function_ref @$s17has_symbol_helper1SV10staticFuncyyFZTwS : $@convention(thin) () -> Builtin.Int1
58+
// CHECK: [[RES:%[0-9]+]] = apply [[QUERY]]() : $@convention(thin) () -> Builtin.Int1
59+
// CHECK: cond_br [[RES]], bb{{[0-9]+}}, bb{{[0-9]+}}
60+
if #_hasSymbol(S.staticFunc) {}
61+
// CHECK: [[QUERY:%[0-9]+]] = function_ref @$s17has_symbol_helper1SV12staticMemberSivpZTwS : $@convention(thin) () -> Builtin.Int1
62+
// CHECK: [[RES:%[0-9]+]] = apply [[QUERY]]() : $@convention(thin) () -> Builtin.Int1
63+
// CHECK: cond_br [[RES]], bb{{[0-9]+}}, bb{{[0-9]+}}
64+
if #_hasSymbol(S.staticMember) {}
65+
// CHECK: [[QUERY:%[0-9]+]] = function_ref @$s17has_symbol_helper1SV6memberACSi_tcfcTwS : $@convention(thin) () -> Builtin.Int1
66+
// CHECK: [[RES:%[0-9]+]] = apply [[QUERY]]() : $@convention(thin) () -> Builtin.Int1
67+
// CHECK: cond_br [[RES]], bb{{[0-9]+}}, bb{{[0-9]+}}
68+
if #_hasSymbol(S.init(member:)) {}
69+
}
70+
71+
// CHECK: sil hidden_external @$s17has_symbol_helper1SV6memberSivpTwS : $@convention(thin) () -> Builtin.Int1
72+
// CHECK: sil hidden_external @$s17has_symbol_helper1SV6method4withySi_tFTwS : $@convention(thin) () -> Builtin.Int1
73+
// CHECK: sil hidden_external @$s17has_symbol_helper1SV11genericFuncyyxAA1PRzlFTwS : $@convention(thin) () -> Builtin.Int1
74+
// CHECK: sil hidden_external @$s17has_symbol_helper1SV10staticFuncyyFZTwS : $@convention(thin) () -> Builtin.Int1
75+
// CHECK: sil hidden_external @$s17has_symbol_helper1SV12staticMemberSivpZTwS : $@convention(thin) () -> Builtin.Int1
76+
// CHECK: sil hidden_external @$s17has_symbol_helper1SV6memberACSi_tcfcTwS : $@convention(thin) () -> Builtin.Int1
77+
78+
// CHECK: sil hidden [ossa] @$s4test0A13GenericStructyy17has_symbol_helper0B1SVyAC1SVGF : $@convention(thin) (@in_guaranteed GenericS<S>) -> ()
79+
func testGenericStruct(_ s: GenericS<S>) {
80+
// CHECK: [[QUERY:%[0-9]+]] = function_ref @$s17has_symbol_helper8GenericSV6memberxvpTwS : $@convention(thin) () -> Builtin.Int1
81+
// CHECK: [[RES:%[0-9]+]] = apply [[QUERY]]() : $@convention(thin) () -> Builtin.Int1
82+
// CHECK: cond_br [[RES]], bb{{[0-9]+}}, bb{{[0-9]+}}
83+
if #_hasSymbol(s.member) {}
84+
// CHECK: [[QUERY:%[0-9]+]] = function_ref @$s17has_symbol_helper8GenericSV6method4withyx_tFTwS : $@convention(thin) () -> Builtin.Int1
85+
// CHECK: [[RES:%[0-9]+]] = apply [[QUERY]]() : $@convention(thin) () -> Builtin.Int1
86+
// CHECK: cond_br [[RES]], bb{{[0-9]+}}, bb{{[0-9]+}}
87+
if #_hasSymbol(s.method(with:)) {}
88+
}
89+
90+
// CHECK: sil hidden_external @$s17has_symbol_helper8GenericSV6memberxvpTwS : $@convention(thin) () -> Builtin.Int1
91+
// CHECK: sil hidden_external @$s17has_symbol_helper8GenericSV6method4withyx_tFTwS : $@convention(thin) () -> Builtin.Int1
92+
93+
// CHECK: sil hidden [ossa] @$s4test0A5Classyy17has_symbol_helper1CCF : $@convention(thin) (@guaranteed C) -> () {
94+
func testClass(_ c: C) {
95+
// CHECK: [[QUERY:%[0-9]+]] = function_ref @$s17has_symbol_helper1CC6memberSivpTwS : $@convention(thin) () -> Builtin.Int1
96+
// CHECK: [[RES:%[0-9]+]] = apply [[QUERY]]() : $@convention(thin) () -> Builtin.Int1
97+
// CHECK: cond_br [[RES]], bb{{[0-9]+}}, bb{{[0-9]+}}
98+
if #_hasSymbol(c.member) {}
99+
// CHECK: [[QUERY:%[0-9]+]] = function_ref @$s17has_symbol_helper1CC6method4withySi_tFTwS : $@convention(thin) () -> Builtin.Int1
100+
// CHECK: [[RES:%[0-9]+]] = apply [[QUERY]]() : $@convention(thin) () -> Builtin.Int1
101+
// CHECK: cond_br [[RES]], bb{{[0-9]+}}, bb{{[0-9]+}}
102+
if #_hasSymbol(c.method(with:)) {}
103+
// CHECK: [[QUERY:%[0-9]+]] = function_ref @$s17has_symbol_helper1CC9classFuncyyFZTwS : $@convention(thin) () -> Builtin.Int1
104+
// CHECK: [[RES:%[0-9]+]] = apply [[QUERY]]() : $@convention(thin) () -> Builtin.Int1
105+
// CHECK: cond_br [[RES]], bb{{[0-9]+}}, bb{{[0-9]+}}
106+
if #_hasSymbol(C.classFunc) {}
107+
// CHECK: [[QUERY:%[0-9]+]] = function_ref @$s17has_symbol_helper1CC12staticMemberSivpZTwS : $@convention(thin) () -> Builtin.Int1
108+
// CHECK: [[RES:%[0-9]+]] = apply [[QUERY]]() : $@convention(thin) () -> Builtin.Int1
109+
// CHECK: cond_br [[RES]], bb{{[0-9]+}}, bb{{[0-9]+}}
110+
if #_hasSymbol(C.staticMember) {}
111+
// CHECK: [[QUERY:%[0-9]+]] = function_ref @$s17has_symbol_helper1CC6memberACSi_tcfcTwS : $@convention(thin) () -> Builtin.Int1
112+
// CHECK: [[RES:%[0-9]+]] = apply [[QUERY]]() : $@convention(thin) () -> Builtin.Int1
113+
// CHECK: cond_br [[RES]], bb{{[0-9]+}}, bb{{[0-9]+}}
114+
if #_hasSymbol(C.init(member:)) {}
115+
}
116+
117+
// CHECK: sil hidden_external @$s17has_symbol_helper1CC6memberSivpTwS : $@convention(thin) () -> Builtin.Int1
118+
// CHECK: sil hidden_external @$s17has_symbol_helper1CC6method4withySi_tFTwS : $@convention(thin) () -> Builtin.Int1
119+
// CHECK: sil hidden_external @$s17has_symbol_helper1CC9classFuncyyFZTwS : $@convention(thin) () -> Builtin.Int1
120+
// CHECK: sil hidden_external @$s17has_symbol_helper1CC12staticMemberSivpZTwS : $@convention(thin) () -> Builtin.Int1
121+
// CHECK: sil hidden_external @$s17has_symbol_helper1CC6memberACSi_tcfcTwS : $@convention(thin) () -> Builtin.Int1
122+
123+
// CHECK: sil hidden [ossa] @$s4test0A4Enumyy17has_symbol_helper1EOF : $@convention(thin) (@in_guaranteed E) -> ()
124+
func testEnum(_ e: E) {
125+
// CHECK: [[QUERY:%[0-9]+]] = function_ref @$s17has_symbol_helper1EO9basicCaseyA2CmFTwS : $@convention(thin) () -> Builtin.Int1
126+
// CHECK: [[RES:%[0-9]+]] = apply [[QUERY]]() : $@convention(thin) () -> Builtin.Int1
127+
// CHECK: cond_br [[RES]], bb{{[0-9]+}}, bb{{[0-9]+}}
128+
if #_hasSymbol(E.basicCase) {}
129+
// CHECK: [[QUERY:%[0-9]+]] = function_ref @$s17has_symbol_helper1EO11payloadCaseyAcA1SVcACmFTwS : $@convention(thin) () -> Builtin.Int1
130+
// CHECK: [[RES:%[0-9]+]] = apply [[QUERY]]() : $@convention(thin) () -> Builtin.Int1
131+
// CHECK: cond_br [[RES]], bb{{[0-9]+}}, bb{{[0-9]+}}
132+
if #_hasSymbol(E.payloadCase(_:)) {}
133+
// CHECK: [[QUERY:%[0-9]+]] = function_ref @$s17has_symbol_helper1EO6methodyyFTwS : $@convention(thin) () -> Builtin.Int1
134+
// CHECK: [[RES:%[0-9]+]] = apply [[QUERY]]() : $@convention(thin) () -> Builtin.Int1
135+
// CHECK: cond_br [[RES]], bb{{[0-9]+}}, bb{{[0-9]+}}
136+
if #_hasSymbol(e.method) {}
137+
}
138+
139+
// CHECK: sil hidden_external @$s17has_symbol_helper1EO9basicCaseyA2CmFTwS : $@convention(thin) () -> Builtin.Int1
140+
// CHECK: sil hidden_external @$s17has_symbol_helper1EO11payloadCaseyAcA1SVcACmFTwS : $@convention(thin) () -> Builtin.Int1
141+
// CHECK: sil hidden_external @$s17has_symbol_helper1EO6methodyyFTwS : $@convention(thin) () -> Builtin.Int1
142+
143+
// CHECK: sil hidden [ossa] @$s4test0A8Protocolyyx17has_symbol_helper1PRzlF : $@convention(thin) <T where T : P> (@in_guaranteed T) -> ()
144+
func testProtocol<T: P>(_ p: T) {
145+
// CHECK: [[QUERY:%[0-9]+]] = function_ref @$s17has_symbol_helper1PP11requirementyyFTwS : $@convention(thin) () -> Builtin.Int1
146+
// CHECK: [[RES:%[0-9]+]] = apply [[QUERY]]() : $@convention(thin) () -> Builtin.Int1
147+
// CHECK: cond_br [[RES]], bb{{[0-9]+}}, bb{{[0-9]+}}
148+
if #_hasSymbol(p.requirement) {}
149+
}
150+
151+
// CHECK: sil hidden [ossa] @$s4test0A9MetatypesyyF : $@convention(thin) () -> ()
152+
func testMetatypes() {
153+
// CHECK: [[QUERY:%[0-9]+]] = function_ref @$s17has_symbol_helper1PPTwS : $@convention(thin) () -> Builtin.Int1
154+
// CHECK: [[RES:%[0-9]+]] = apply [[QUERY]]() : $@convention(thin) () -> Builtin.Int1
155+
// CHECK: cond_br [[RES]], bb{{[0-9]+}}, bb{{[0-9]+}}
156+
if #_hasSymbol(P.self) {}
157+
// CHECK: [[QUERY:%[0-9]+]] = function_ref @$s17has_symbol_helper1SVTwS : $@convention(thin) () -> Builtin.Int1
158+
// CHECK: [[RES:%[0-9]+]] = apply [[QUERY]]() : $@convention(thin) () -> Builtin.Int1
159+
// CHECK: cond_br [[RES]], bb{{[0-9]+}}, bb{{[0-9]+}}
160+
if #_hasSymbol(S.self) {}
161+
// CHECK: [[QUERY:%[0-9]+]] = function_ref @$s17has_symbol_helper8GenericSVTwS : $@convention(thin) () -> Builtin.Int1
162+
// CHECK: [[RES:%[0-9]+]] = apply [[QUERY]]() : $@convention(thin) () -> Builtin.Int1
163+
// CHECK: cond_br [[RES]], bb{{[0-9]+}}, bb{{[0-9]+}}
164+
if #_hasSymbol(GenericS<S>.self) {}
165+
// CHECK: [[QUERY:%[0-9]+]] = function_ref @$s17has_symbol_helper1CCTwS : $@convention(thin) () -> Builtin.Int1
166+
// CHECK: [[RES:%[0-9]+]] = apply [[QUERY]]() : $@convention(thin) () -> Builtin.Int1
167+
// CHECK: cond_br [[RES]], bb{{[0-9]+}}, bb{{[0-9]+}}
168+
if #_hasSymbol(C.self) {}
169+
// CHECK: [[QUERY:%[0-9]+]] = function_ref @$s17has_symbol_helper1EOTwS : $@convention(thin) () -> Builtin.Int1
170+
// CHECK: [[RES:%[0-9]+]] = apply [[QUERY]]() : $@convention(thin) () -> Builtin.Int1
171+
// CHECK: cond_br [[RES]], bb{{[0-9]+}}, bb{{[0-9]+}}
172+
if #_hasSymbol(E.self) {}
173+
}
174+
175+
// CHECK: sil hidden_external @$s17has_symbol_helper1PPTwS : $@convention(thin) () -> Builtin.Int1
176+
// CHECK: sil hidden_external @$s17has_symbol_helper1SVTwS : $@convention(thin) () -> Builtin.Int1
177+
// CHECK: sil hidden_external @$s17has_symbol_helper8GenericSVTwS : $@convention(thin) () -> Builtin.Int1
178+
// CHECK: sil hidden_external @$s17has_symbol_helper1CCTwS : $@convention(thin) () -> Builtin.Int1
179+
// CHECK: sil hidden_external @$s17has_symbol_helper1EOTwS : $@convention(thin) () -> Builtin.Int1

0 commit comments

Comments
 (0)