Skip to content

Commit 5bef4c7

Browse files
committed
[Parse] Optimize syntax parsing: Disable name lookups during parsing
This eliminates the overhead of doing name lookups during parsing (which is unncessary during syntactic parsing) by enabling the `EnableASTScopeLookup` lang option.
1 parent 57c1f72 commit 5bef4c7

File tree

2 files changed

+5
-0
lines changed

2 files changed

+5
-0
lines changed

include/swift/Parse/Parser.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -637,6 +637,9 @@ class Parser {
637637

638638
/// Add the given Decl to the current scope.
639639
void addToScope(ValueDecl *D) {
640+
if (Context.LangOpts.EnableASTScopeLookup)
641+
return;
642+
640643
getScopeInfo().addToScope(D, *this);
641644
}
642645

tools/libSwiftSyntaxParser/libSwiftSyntaxParser.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,8 @@ swiftparse_client_node_t SynParser::parse(const char *source) {
187187
LangOptions langOpts;
188188
langOpts.BuildSyntaxTree = true;
189189
langOpts.CollectParsedToken = false;
190+
// Disable name lookups during parsing.
191+
langOpts.EnableASTScopeLookup = true;
190192

191193
auto parseActions =
192194
std::make_shared<CLibParseActions>(*this, SM, bufID);

0 commit comments

Comments
 (0)