Skip to content

Commit 1bd2a9b

Browse files
committed
[Parse] Allow skipping member bodies following #sourceLocation
If the bodies themselves don't have a `#sourceLocation` in them, there should be no harm in skipping; the parsed virtual files get recorded on the SourceManager, so will be accessible when doing delayed parsing. The `InPoundLineEnvironment` flag will be inaccurate, but that's only needed for the parsing of `#sourceLocation` itself.
1 parent 4efb210 commit 1bd2a9b

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

include/swift/Parse/Parser.h

+6
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,13 @@ class Parser {
156156
/// Whether this context has an async attribute.
157157
bool InPatternWithAsyncAttribute = false;
158158

159+
/// Whether a '#sourceLocation' is currently active.
160+
/// NOTE: Do not use this outside of `parseLineDirective`, it doesn't have
161+
/// its state restored when parsing delayed bodies (we avoid skipping bodies
162+
/// if we see a `#sourceLocation` in them though). Instead, query the
163+
/// SourceManager.
159164
bool InPoundLineEnvironment = false;
165+
160166
bool InPoundIfEnvironment = false;
161167
/// ASTScopes are not created in inactive clauses and lookups to decls will fail.
162168
bool InInactiveClauseEnvironment = false;

lib/Parse/ParseDecl.cpp

-4
Original file line numberDiff line numberDiff line change
@@ -7080,10 +7080,6 @@ bool Parser::canDelayMemberDeclParsing(bool &HasOperatorDeclarations,
70807080
// If explicitly disabled, respect the flag.
70817081
if (!isDelayedParsingEnabled())
70827082
return false;
7083-
// Recovering parser status later for #sourceLocation is not-trivial and
7084-
// it may not worth it.
7085-
if (InPoundLineEnvironment)
7086-
return false;
70877083

70887084
// Skip until the matching right curly bracket; if we find a pound directive,
70897085
// we can't lazily parse.

0 commit comments

Comments
 (0)