Skip to content

[IDE] Skip walking serialized internal top level decls in SemaAnnotator #42406

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions include/swift/AST/ASTWalker.h
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,11 @@ class ASTWalker {
/// until eventually we can remove this altogether.
virtual bool shouldWalkAccessorsTheOldWay() { return false; }

/// Whether to walk internal top level decls in serialized modules.
///
/// TODO: Consider changing this to false by default.
virtual bool shouldWalkSerializedTopLevelInternalDecls() { return true; }

/// walkToParameterListPre - This method is called when first visiting a
/// ParameterList, before walking into its parameters. If it returns false,
/// the subtree is skipped.
Expand Down
10 changes: 10 additions & 0 deletions lib/AST/Module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2916,7 +2916,17 @@ bool FileUnit::walk(ASTWalker &walker) {
getTopLevelDecls(Decls);
llvm::SaveAndRestore<ASTWalker::ParentTy> SAR(walker.Parent,
getParentModule());

bool SkipInternal = getKind() == FileUnitKind::SerializedAST &&
!walker.shouldWalkSerializedTopLevelInternalDecls();
for (Decl *D : Decls) {
if (SkipInternal) {
if (auto *VD = dyn_cast<ValueDecl>(D)) {
if (!VD->isAccessibleFrom(nullptr))
continue;
}
}

#ifndef NDEBUG
PrettyStackTraceDecl debugStack("walking into decl", D);
#endif
Expand Down
5 changes: 5 additions & 0 deletions lib/IDE/SourceEntityWalker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ class SemaAnnotator : public ASTWalker {
bool shouldWalkIntoGenericParams() override {
return SEWalker.shouldWalkIntoGenericParams();
}

bool shouldWalkSerializedTopLevelInternalDecls() override {
return false;
}

bool walkToDeclPre(Decl *D) override;
bool walkToDeclPreProper(Decl *D);
std::pair<bool, Expr *> walkToExprPre(Expr *E) override;
Expand Down