Skip to content

Commit 7913091

Browse files
committed
[Parse] Fix issue with incremental re-parsing for SwiftSyntax emitting bogus parsing error
rdar://60232712
1 parent 1882b50 commit 7913091

File tree

5 files changed

+18
-1
lines changed

5 files changed

+18
-1
lines changed

include/swift/Basic/LangOptions.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,11 @@ namespace swift {
296296
/// incrementals parsing.
297297
bool BuildSyntaxTree = false;
298298

299+
/// Whether parsing is occurring for creation of syntax tree only, and no typechecking will occur after
300+
/// parsing e.g. when parsing for SwiftSyntax. This is intended to affect parsing, e.g. disable
301+
/// unnecessary name lookups that are not useful for pure syntactic parsing.
302+
bool ParseForSyntaxTreeOnly = false;
303+
299304
/// Whether to verify the parsed syntax tree and emit related diagnostics.
300305
bool VerifySyntaxTree = false;
301306

lib/Parse/ParseExpr.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2264,7 +2264,10 @@ Expr *Parser::parseExprIdentifier() {
22642264
}
22652265

22662266
ValueDecl *D = nullptr;
2267-
if (!InPoundIfEnvironment) {
2267+
// When doing incremental re-parsing for SwiftSyntax this check may emit bogus
2268+
// diagnostic. Also really the syntactic parser should not be doing name
2269+
// lookups, so disable this check when parsing for SwiftSyntax.
2270+
if (!InPoundIfEnvironment && !Context.LangOpts.ParseForSyntaxTreeOnly) {
22682271
D = lookupInScope(name);
22692272
// FIXME: We want this to work: "var x = { x() }", but for now it's better
22702273
// to disallow it than to crash.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %validate-incrparse %s --test-case REPLACE
3+
4+
let myFont: Font = {
5+
let myFont = Font.body
6+
return myFont.weight(.<<REPLACE<bold|||light>>>)
7+
}()

tools/libSwiftSyntaxParser/libSwiftSyntaxParser.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,7 @@ swiftparse_client_node_t SynParser::parse(const char *source) {
277277
TypeCheckerOptions tyckOpts;
278278
LangOptions langOpts;
279279
langOpts.BuildSyntaxTree = true;
280+
langOpts.ParseForSyntaxTreeOnly = true;
280281
langOpts.CollectParsedToken = false;
281282
// Disable name lookups during parsing.
282283
// Not ready yet:

tools/swift-syntax-test/swift-syntax-test.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -606,6 +606,7 @@ int parseFile(
606606
// Set up the compiler invocation
607607
CompilerInvocation Invocation;
608608
Invocation.getLangOptions().BuildSyntaxTree = true;
609+
Invocation.getLangOptions().ParseForSyntaxTreeOnly = true;
609610
Invocation.getLangOptions().VerifySyntaxTree = options::VerifySyntaxTree;
610611
Invocation.getLangOptions().RequestEvaluatorGraphVizPath = options::GraphVisPath;
611612
Invocation.getFrontendOptions().InputsAndOutputs.addInputFile(InputFileName);

0 commit comments

Comments
 (0)