Skip to content

Commit 33db2af

Browse files
committed
[TBDGen] Walk accessors as part of their parent storage, not the main AST.
Sometimes, inconsistently, an accessor appears as a member of a parent DeclContext, but other times it can seemingly only be accessed through the storage decl. Instead of trying to conditionalise on this, just use the storage decl as the canonical source, and ignore direct visits to accessors (i.e. the membership route to ones that are members of other things). Fixes rdar://problem/40476839.
1 parent 250eb97 commit 33db2af

File tree

4 files changed

+66
-0
lines changed

4 files changed

+66
-0
lines changed

lib/TBDGen/TBDGen.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,22 @@ void TBDGenVisitor::visitAbstractFunctionDecl(AbstractFunctionDecl *AFD) {
150150
}
151151
}
152152

153+
void TBDGenVisitor::visitAccessorDecl(AccessorDecl *AD) {
154+
// Do nothing: accessors are always nested within the storage decl, but
155+
// sometimes appear outside it too. To avoid double-walking them, we
156+
// explicitly visit them as members of the storage and ignore them when we
157+
// visit them as part of the main walk, here.
158+
}
159+
160+
void TBDGenVisitor::visitAbstractStorageDecl(AbstractStorageDecl *ASD) {
161+
// Explicitly look at each accessor here: see visitAccessorDecl.
162+
SmallVector<Decl *, 8> accessors;
163+
ASD->getAllAccessorFunctions(accessors);
164+
for (auto accessor : accessors) {
165+
visitAbstractFunctionDecl(cast<AbstractFunctionDecl>(accessor));
166+
}
167+
}
168+
153169
void TBDGenVisitor::visitVarDecl(VarDecl *VD) {
154170
// statically/globally stored variables have some special handling.
155171
if (VD->hasStorage() && isGlobalOrStaticVar(VD)) {
@@ -162,6 +178,8 @@ void TBDGenVisitor::visitVarDecl(VarDecl *VD) {
162178
if (!FileHasEntryPoint || VD->isStatic())
163179
addSymbol(SILDeclRef(VD, SILDeclRef::Kind::GlobalAccessor));
164180
}
181+
182+
visitAbstractStorageDecl(VD);
165183
}
166184

167185
void TBDGenVisitor::visitNominalTypeDecl(NominalTypeDecl *NTD) {

lib/TBDGen/TBDGenVisitor.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ class TBDGenVisitor : public ASTVisitor<TBDGenVisitor> {
9494

9595
void visitAbstractFunctionDecl(AbstractFunctionDecl *AFD);
9696

97+
void visitAccessorDecl(AccessorDecl *AD);
98+
9799
void visitNominalTypeDecl(NominalTypeDecl *NTD);
98100

99101
void visitClassDecl(ClassDecl *CD);
@@ -104,6 +106,8 @@ class TBDGenVisitor : public ASTVisitor<TBDGenVisitor> {
104106

105107
void visitProtocolDecl(ProtocolDecl *PD);
106108

109+
void visitAbstractStorageDecl(AbstractStorageDecl *ASD);
110+
107111
void visitVarDecl(VarDecl *VD);
108112

109113
void visitEnumDecl(EnumDecl *ED);

test/TBD/global.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// RUN: %target-swift-frontend -emit-ir -o- -parse-as-library -module-name test -validate-tbd-against-ir=missing %s
2+
// RUN: %target-swift-frontend -emit-ir -o- -parse-as-library -module-name test -validate-tbd-against-ir=missing -enable-resilience %s
23

34
public let publicLet: Int = 0
45
internal let internalLet: Int = 0

test/TBD/struct.swift

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// RUN: %target-swift-frontend -emit-ir -o- -parse-as-library -module-name test -validate-tbd-against-ir=missing %s
2+
// RUN: %target-swift-frontend -emit-ir -o- -parse-as-library -module-name test -validate-tbd-against-ir=missing %s -enable-resilience
23

34
public struct PublicNothing {}
45

@@ -44,6 +45,25 @@ public struct PublicProperties {
4445
}
4546
}
4647

48+
public struct PublicSubscripts {
49+
public subscript(publicGet _: Int) -> Int { return 0 }
50+
internal subscript(internalGet _: Int) -> Int { return 0 }
51+
private subscript(privateGet _: Int) -> Int { return 0 }
52+
53+
public subscript(publicGetSet _: Int) -> Int {
54+
get {return 0 }
55+
set {}
56+
}
57+
internal subscript(internalGetSet _: Int) -> Int {
58+
get {return 0 }
59+
set {}
60+
}
61+
private subscript(privateGetSet _: Int) -> Int {
62+
get {return 0 }
63+
set {}
64+
}
65+
}
66+
4767
public struct PublicStatics {
4868
public static func publicStaticFunc() {}
4969
internal static func internalStaticFunc() {}
@@ -135,6 +155,20 @@ internal struct InternalProperties {
135155
}
136156
}
137157

158+
internal struct InternalSubscripts {
159+
internal subscript(internalGet _: Int) -> Int { return 0 }
160+
private subscript(privateGet _: Int) -> Int { return 0 }
161+
162+
internal subscript(internalGetSet _: Int) -> Int {
163+
get {return 0 }
164+
set {}
165+
}
166+
private subscript(privateGetSet _: Int) -> Int {
167+
get {return 0 }
168+
set {}
169+
}
170+
}
171+
138172
internal struct InternalStatics {
139173
internal static func internalStaticFunc() {}
140174
private static func privateStaticFunc() {}
@@ -203,6 +237,15 @@ private struct PrivateProperties {
203237
}
204238
}
205239

240+
private struct PrivateSubscripts {
241+
private subscript(privateGet _: Int) -> Int { return 0 }
242+
243+
private subscript(privateGetSet _: Int) -> Int {
244+
get {return 0 }
245+
set {}
246+
}
247+
}
248+
206249
private struct PrivateStatics {
207250
private static func privateStaticFunc() {}
208251

0 commit comments

Comments
 (0)