Skip to content

Commit acb0c5a

Browse files
authored
Merge pull request #77602 from tshortli/has-symbol-static-property
IRGen: Omit property descriptors from #_hasSymbol checks for static properties
2 parents 91d8abb + d70091f commit acb0c5a

File tree

4 files changed

+31
-3
lines changed

4 files changed

+31
-3
lines changed

include/swift/IRGen/Linking.h

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -359,14 +359,14 @@ class LinkEntity {
359359
BaseConformanceDescriptor,
360360

361361
/// A global function pointer for dynamically replaceable functions.
362-
/// The pointer is a AbstractStorageDecl*.
362+
/// The pointer is a AbstractFunctionDecl*.
363363
DynamicallyReplaceableFunctionVariableAST,
364364

365-
/// The pointer is a AbstractStorageDecl*.
365+
/// The pointer is a AbstractFunctionDecl*.
366366
DynamicallyReplaceableFunctionKeyAST,
367367

368368
/// The original implementation of a dynamically replaceable function.
369-
/// The pointer is a AbstractStorageDecl*.
369+
/// The pointer is a AbstractFunctionDecl*.
370370
DynamicallyReplaceableFunctionImpl,
371371

372372
/// The once token used by cacheCanonicalSpecializedMetadata, by way of
@@ -1473,6 +1473,11 @@ class LinkEntity {
14731473
return reinterpret_cast<ExtensionDecl*>(Pointer);
14741474
}
14751475

1476+
const AbstractStorageDecl *getAbstractStorageDecl() const {
1477+
assert(getKind() == Kind::PropertyDescriptor);
1478+
return reinterpret_cast<AbstractStorageDecl *>(Pointer);
1479+
}
1480+
14761481
const PointerUnion<DeclContext *, VarDecl *> getAnonymousDeclContext() const {
14771482
assert(getKind() == Kind::AnonymousDescriptor);
14781483
return PointerUnion<DeclContext *, VarDecl *>
@@ -1632,6 +1637,9 @@ class LinkEntity {
16321637
getKind() == Kind::DispatchThunkAllocator ||
16331638
getKind() == Kind::DispatchThunkDerivative;
16341639
}
1640+
bool isPropertyDescriptor() const {
1641+
return getKind() == Kind::PropertyDescriptor;
1642+
}
16351643
bool isNominalTypeDescriptor() const {
16361644
return getKind() == Kind::NominalTypeDescriptor;
16371645
}

lib/IRGen/GenHasSymbol.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,13 @@ class HasSymbolIRGenVisitor : public IRSymbolVisitor {
109109
}
110110

111111
void addLinkEntity(LinkEntity entity) override {
112+
// Skip property descriptors for static properties, which were only
113+
// introduced with SE-0438 and are therefore not present in all libraries.
114+
if (entity.isPropertyDescriptor()) {
115+
if (entity.getAbstractStorageDecl()->isStatic())
116+
return;
117+
}
118+
112119
if (entity.hasSILFunction()) {
113120
addFunction(entity.getSILFunction());
114121
return;

test/IRGen/Inputs/has_symbol/has_symbol_helper.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ extension P {
3737

3838
public struct S {
3939
public var member: Int
40+
public static var staticMember: Int = 0
4041

4142
public init(member: Int) {
4243
self.member = member

test/IRGen/has_symbol.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,9 @@ public func testStruct(_ s: S) {
159159
// CHECK: %{{[0-9]+}} = call i1 @"$s17has_symbol_helper1SV6memberSivpTwS"()
160160
if #_hasSymbol(s.member) {}
161161

162+
// CHECK: %{{[0-9]+}} = call i1 @"$s17has_symbol_helper1SV12staticMemberSivpZTwS"()
163+
if #_hasSymbol(S.staticMember) {}
164+
162165
// CHECK: %{{[0-9]+}} = call i1 @"$s17has_symbol_helper1SV6method4withySi_tFTwS"()
163166
if #_hasSymbol(s.method(with:)) {}
164167
}
@@ -174,6 +177,15 @@ public func testStruct(_ s: S) {
174177
// CHECK: [[RES:%.*]] = and i1 [[V4]], [[V5]]
175178
// CHECK: ret i1 [[RES]]
176179

180+
// --- S.staticMember ---
181+
// CHECK: define linkonce_odr hidden i1 @"$s17has_symbol_helper1SV12staticMemberSivpZTwS"()
182+
// CHECK: [[V0:%.*]] = icmp ne ptr @"$s17has_symbol_helper1SV12staticMemberSivgZ", null
183+
// CHECK: [[V1:%.*]] = icmp ne ptr @"$s17has_symbol_helper1SV12staticMemberSivsZ", null
184+
// CHECK: [[V2:%.*]] = and i1 [[V0]], [[V1]]
185+
// CHECK: [[V3:%.*]] = icmp ne ptr @"$s17has_symbol_helper1SV12staticMemberSivMZ", null
186+
// CHECK: [[RES:%.*]] = and i1 [[V2]], [[V3]]
187+
// CHECK: ret i1 [[RES]]
188+
177189
// --- S.method(with:) ---
178190
// CHECK: define linkonce_odr hidden i1 @"$s17has_symbol_helper1SV6method4withySi_tFTwS"()
179191
// CHECK: [[RES:%.*]] = icmp ne ptr @"$s17has_symbol_helper1SV6method4withySi_tF", null

0 commit comments

Comments
 (0)