Skip to content

Commit 033732b

Browse files
committed
ASTVerifier: avoid verifying IterableDeclContext if it has unparsed members.
1 parent c0d52fd commit 033732b

File tree

6 files changed

+18
-4
lines changed

6 files changed

+18
-4
lines changed

include/swift/AST/ASTContext.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -791,6 +791,10 @@ class ASTContext final {
791791
/// \param IDC The context whose member decls should be lazily parsed.
792792
void parseMembers(IterableDeclContext *IDC);
793793

794+
/// Use the lazy parsers associated with the context to check whether the decl
795+
/// context has been parsed.
796+
bool hasUnparsedMembers(const IterableDeclContext *IDC) const;
797+
794798
/// Get the lazy function data for the given generic context.
795799
///
796800
/// \param lazyLoader If non-null, the lazy loader to use when creating the

include/swift/AST/LazyResolver.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,9 @@ class LazyMemberParser {
101101
///
102102
/// The implementation should add the members to IDC.
103103
virtual void parseMembers(IterableDeclContext *IDC) = 0;
104+
105+
/// Return whether the iterable decl context needs parsing.
106+
virtual bool hasUnparsedMembers(const IterableDeclContext *IDC) = 0;
104107
};
105108

106109
/// Context data for generic contexts.

include/swift/Parse/PersistentParserState.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ class PersistentParserState: public LazyMemberParser {
174174
std::unique_ptr<DelayedDeclListState>
175175
takeDelayedDeclListState(IterableDeclContext *IDC);
176176

177-
bool hasDelayedDeclList(IterableDeclContext *IDC) {
177+
bool hasUnparsedMembers(const IterableDeclContext *IDC) override {
178178
return DelayedDeclListStates.find(IDC) != DelayedDeclListStates.end();
179179
}
180180

lib/AST/ASTContext.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1903,9 +1903,16 @@ LazyContextData *ASTContext::getOrCreateLazyContextData(
19031903
return contextData;
19041904
}
19051905

1906+
bool ASTContext::hasUnparsedMembers(const IterableDeclContext *IDC) const {
1907+
auto parsers = getImpl().lazyParsers;
1908+
return std::any_of(parsers.begin(), parsers.end(),
1909+
[IDC](LazyMemberParser *p) { return p->hasUnparsedMembers(IDC); });
1910+
}
1911+
19061912
void ASTContext::parseMembers(IterableDeclContext *IDC) {
19071913
for (auto *p: getImpl().lazyParsers) {
1908-
p->parseMembers(IDC);
1914+
if (p->hasUnparsedMembers(IDC))
1915+
p->parseMembers(IDC);
19091916
}
19101917
}
19111918

lib/AST/ASTVerifier.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -709,6 +709,8 @@ class Verifier : public ASTWalker {
709709
pushScope(fn); \
710710
if (fn->hasLazyMembers()) \
711711
return false; \
712+
if (fn->getASTContext().hasUnparsedMembers(fn)) \
713+
return false; \
712714
return shouldVerify(cast<ASTNodeBase<NODE*>::BaseTy>(fn));\
713715
} \
714716
void cleanup(NODE *fn) { \

lib/Parse/ParseDecl.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,6 @@ namespace {
181181
} // end anonymous namespace
182182

183183
void PersistentParserState::parseMembers(IterableDeclContext *IDC) {
184-
if (!hasDelayedDeclList(IDC))
185-
return;
186184
SourceFile &SF = *IDC->getDecl()->getDeclContext()->getParentSourceFile();
187185
assert(!SF.hasInterfaceHash() &&
188186
"Cannot delay parsing if we care about the interface hash.");

0 commit comments

Comments
 (0)