Skip to content

Commit 8d455a4

Browse files
committed
[TBDGen] Explicitly walk members of stored static vars.
Unlike some other vars, these members are not also listed at the top level, adjacent to the VarDecl.
1 parent 002e4d5 commit 8d455a4

File tree

3 files changed

+32
-2
lines changed

3 files changed

+32
-2
lines changed

include/swift/AST/Decl.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4099,6 +4099,10 @@ class AbstractStorageDecl : public ValueDecl {
40994099

41004100
FuncDecl *getAccessorFunction(AccessorKind accessor) const;
41014101

4102+
/// \brief Push all of the accessor functions associated with this VarDecl
4103+
/// onto `decls`.
4104+
void getAllAccessorFunctions(SmallVectorImpl<Decl *> &decls) const;
4105+
41024106
/// \brief Turn this into a computed variable, providing a getter and setter.
41034107
void makeComputed(SourceLoc LBraceLoc, FuncDecl *Get, FuncDecl *Set,
41044108
FuncDecl *MaterializeForSet, SourceLoc RBraceLoc);

lib/AST/Decl.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3430,6 +3430,28 @@ FuncDecl *AbstractStorageDecl::getAccessorFunction(AccessorKind kind) const {
34303430
llvm_unreachable("bad accessor kind!");
34313431
}
34323432

3433+
void AbstractStorageDecl::getAllAccessorFunctions(
3434+
SmallVectorImpl<Decl *> &decls) const {
3435+
auto tryPush = [&](Decl *decl) {
3436+
if (decl)
3437+
decls.push_back(decl);
3438+
};
3439+
3440+
tryPush(getGetter());
3441+
tryPush(getSetter());
3442+
tryPush(getMaterializeForSetFunc());
3443+
3444+
if (hasObservers()) {
3445+
tryPush(getDidSetFunc());
3446+
tryPush(getWillSetFunc());
3447+
}
3448+
3449+
if (hasAddressors()) {
3450+
tryPush(getAddressor());
3451+
tryPush(getMutableAddressor());
3452+
}
3453+
}
3454+
34333455
void AbstractStorageDecl::configureGetSetRecord(GetSetRecord *getSetInfo,
34343456
FuncDecl *getter,
34353457
FuncDecl *setter,

lib/TBDGen/TBDGen.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ class TBDGenVisitor : public ASTVisitor<TBDGenVisitor> {
9696
addMembers(ED->getMembers());
9797
else if (auto NTD = dyn_cast<NominalTypeDecl>(D))
9898
addMembers(NTD->getMembers());
99+
else if (auto VD = dyn_cast<VarDecl>(D))
100+
VD->getAllAccessorFunctions(members);
99101

100102
for (auto member : members) {
101103
ASTVisitor::visit(member);
@@ -221,9 +223,11 @@ void TBDGenVisitor::visitVarDecl(VarDecl *VD) {
221223
// like globals.
222224
if (!FileHasEntryPoint)
223225
addSymbol(SILDeclRef(VD, SILDeclRef::Kind::GlobalAccessor));
224-
}
225226

226-
visitMembers(VD);
227+
// In this case, the members of the VarDecl don't also appear as top-level
228+
// decls, so we need to explicitly walk them.
229+
visitMembers(VD);
230+
}
227231
}
228232

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

0 commit comments

Comments
 (0)