Skip to content

Commit 17f6f4e

Browse files
committed
SILGen: Introduce and adopt SILGenModule::shouldSkipDecl().
This method centralizes the logic for determining whether to skip emission of SIL associated with a Decl.
1 parent 9dbe72a commit 17f6f4e

File tree

8 files changed

+40
-20
lines changed

8 files changed

+40
-20
lines changed

include/swift/AST/DeclContext.h

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -877,15 +877,6 @@ class IterableDeclContext {
877877
/// The resulting list of members will be stable across translation units.
878878
ArrayRef<Decl *> getABIMembers() const;
879879

880-
using DeclsForLowering =
881-
OptionalTransformRange<ArrayRef<Decl *>,
882-
AvailableDuringLoweringDeclFilter<Decl>>;
883-
884-
/// Get all of the members within this context that should be included when
885-
/// lowering to SIL/IR, including any implicitly-synthesized members. The
886-
/// decls returned by \c getABIMembers() are a superset of these decls.
887-
DeclsForLowering getMembersForLowering() const;
888-
889880
/// Get all of the members within this context, including any
890881
/// implicitly-synthesized members.
891882
///

include/swift/SIL/SILVTableVisitor.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,9 @@ template <class T> class SILVTableVisitor {
105105
}
106106

107107
void maybeAddMember(Decl *member) {
108+
if (!member->isAvailableDuringLowering())
109+
return;
110+
108111
if (isa<AccessorDecl>(member))
109112
/* handled as part of its storage */;
110113
else if (auto *fd = dyn_cast<FuncDecl>(member))
@@ -141,7 +144,7 @@ template <class T> class SILVTableVisitor {
141144
if (!theClass->hasKnownSwiftImplementation())
142145
return;
143146

144-
for (Decl *member : theClass->getMembersForLowering()) {
147+
for (Decl *member : theClass->getABIMembers()) {
145148
maybeAddMember(member);
146149
}
147150
}

lib/AST/DeclContext.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -914,12 +914,6 @@ ArrayRef<Decl *> IterableDeclContext::getABIMembers() const {
914914
ArrayRef<Decl *>());
915915
}
916916

917-
IterableDeclContext::DeclsForLowering
918-
IterableDeclContext::getMembersForLowering() const {
919-
return DeclsForLowering(getABIMembers(),
920-
AvailableDuringLoweringDeclFilter<Decl>());
921-
}
922-
923917
ArrayRef<Decl *> IterableDeclContext::getAllMembers() const {
924918
ASTContext &ctx = getASTContext();
925919
return evaluateOrDefault(

lib/SILGen/SILGen.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -797,8 +797,15 @@ bool SILGenModule::hasFunction(SILDeclRef constant) {
797797
return emittedFunctions.count(constant);
798798
}
799799

800-
void SILGenModule::visit(Decl *D) {
800+
bool SILGenModule::shouldSkipDecl(Decl *D) {
801801
if (!D->isAvailableDuringLowering())
802+
return true;
803+
804+
return false;
805+
}
806+
807+
void SILGenModule::visit(Decl *D) {
808+
if (shouldSkipDecl(D))
802809
return;
803810

804811
ASTVisitor::visit(D);

lib/SILGen/SILGen.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,9 @@ class LLVM_LIBRARY_VISIBILITY SILGenModule : public ASTVisitor<SILGenModule> {
264264
// Visitors for top-level forms
265265
//===--------------------------------------------------------------------===//
266266

267+
/// Returns true if SILGen should be skipped for the given decl.
268+
bool shouldSkipDecl(Decl *d);
269+
267270
void visit(Decl *D);
268271

269272
// These are either not allowed at global scope or don't require

lib/SILGen/SILGenTopLevel.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,11 +294,18 @@ void SILGenTopLevel::visitTopLevelCodeDecl(TopLevelCodeDecl *TD) {
294294
SILGenTopLevel::TypeVisitor::TypeVisitor(SILGenFunction &SGF) : SGF(SGF) {}
295295

296296
void SILGenTopLevel::TypeVisitor::emit(IterableDeclContext *Ctx) {
297-
for (auto *Member : Ctx->getMembersForLowering()) {
297+
for (auto *Member : Ctx->getABIMembers()) {
298298
visit(Member);
299299
}
300300
}
301301

302+
void SILGenTopLevel::TypeVisitor::visit(Decl *D) {
303+
if (SGF.SGM.shouldSkipDecl(D))
304+
return;
305+
306+
TypeMemberVisitor::visit(D);
307+
}
308+
302309
void SILGenTopLevel::TypeVisitor::visitPatternBindingDecl(
303310
PatternBindingDecl *PD) {
304311
for (auto i : range(PD->getNumPatternEntries())) {

lib/SILGen/SILGenTopLevel.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ class SILGenTopLevel : public ASTVisitor<SILGenTopLevel> {
4949
/// Emit `mark_function_escape` SIL instructions into `SGF` for encountered
5050
/// escape points.
5151
TypeVisitor(SILGenFunction &SGF);
52+
void visit(Decl *D);
5253
void visitDecl(Decl *D) {}
5354
void emit(IterableDeclContext *Ctx);
5455
virtual void visitPatternBindingDecl(PatternBindingDecl *PD);

lib/SILGen/SILGenType.cpp

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1098,7 +1098,7 @@ class SILGenType : public TypeMemberVisitor<SILGenType> {
10981098
void emitType() {
10991099
SGM.emitLazyConformancesForType(theType);
11001100

1101-
for (Decl *member : theType->getMembersForLowering()) {
1101+
for (Decl *member : theType->getABIMembers()) {
11021102
visit(member);
11031103
}
11041104

@@ -1141,6 +1141,13 @@ class SILGenType : public TypeMemberVisitor<SILGenType> {
11411141
//===--------------------------------------------------------------------===//
11421142
// Visitors for subdeclarations
11431143
//===--------------------------------------------------------------------===//
1144+
void visit(Decl *D) {
1145+
if (SGM.shouldSkipDecl(D))
1146+
return;
1147+
1148+
TypeMemberVisitor::visit(D);
1149+
}
1150+
11441151
void visitTypeAliasDecl(TypeAliasDecl *tad) {}
11451152
void visitOpaqueTypeDecl(OpaqueTypeDecl *otd) {}
11461153
void visitGenericTypeParamDecl(GenericTypeParamDecl *d) {}
@@ -1273,7 +1280,7 @@ class SILGenExtension : public TypeMemberVisitor<SILGenExtension> {
12731280
// @_objcImplementation extension, but we don't actually need to do any of
12741281
// the stuff that it currently does.
12751282

1276-
for (Decl *member : e->getMembersForLowering()) {
1283+
for (Decl *member : e->getABIMembers()) {
12771284
visit(member);
12781285
}
12791286

@@ -1300,6 +1307,13 @@ class SILGenExtension : public TypeMemberVisitor<SILGenExtension> {
13001307
//===--------------------------------------------------------------------===//
13011308
// Visitors for subdeclarations
13021309
//===--------------------------------------------------------------------===//
1310+
void visit(Decl *D) {
1311+
if (SGM.shouldSkipDecl(D))
1312+
return;
1313+
1314+
TypeMemberVisitor::visit(D);
1315+
}
1316+
13031317
void visitTypeAliasDecl(TypeAliasDecl *tad) {}
13041318
void visitOpaqueTypeDecl(OpaqueTypeDecl *tad) {}
13051319
void visitGenericTypeParamDecl(GenericTypeParamDecl *d) {}

0 commit comments

Comments
 (0)