Skip to content

Commit

Permalink
[Parse] Fix issue with incremental re-parsing for SwiftSyntax emittin…
Browse files Browse the repository at this point in the history
…g bogus parsing error

rdar://60232712
  • Loading branch information
akyrtzi committed Mar 18, 2020
1 parent 1882b50 commit 7913091
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 1 deletion.
5 changes: 5 additions & 0 deletions include/swift/Basic/LangOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,11 @@ namespace swift {
/// incrementals parsing.
bool BuildSyntaxTree = false;

/// Whether parsing is occurring for creation of syntax tree only, and no typechecking will occur after
/// parsing e.g. when parsing for SwiftSyntax. This is intended to affect parsing, e.g. disable
/// unnecessary name lookups that are not useful for pure syntactic parsing.
bool ParseForSyntaxTreeOnly = false;

/// Whether to verify the parsed syntax tree and emit related diagnostics.
bool VerifySyntaxTree = false;

Expand Down
5 changes: 4 additions & 1 deletion lib/Parse/ParseExpr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2264,7 +2264,10 @@ Expr *Parser::parseExprIdentifier() {
}

ValueDecl *D = nullptr;
if (!InPoundIfEnvironment) {
// When doing incremental re-parsing for SwiftSyntax this check may emit bogus
// diagnostic. Also really the syntactic parser should not be doing name
// lookups, so disable this check when parsing for SwiftSyntax.
if (!InPoundIfEnvironment && !Context.LangOpts.ParseForSyntaxTreeOnly) {
D = lookupInScope(name);
// FIXME: We want this to work: "var x = { x() }", but for now it's better
// to disallow it than to crash.
Expand Down
7 changes: 7 additions & 0 deletions test/incrParse/incremental-diagnostic.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// RUN: %empty-directory(%t)
// RUN: %validate-incrparse %s --test-case REPLACE

let myFont: Font = {
let myFont = Font.body
return myFont.weight(.<<REPLACE<bold|||light>>>)
}()
1 change: 1 addition & 0 deletions tools/libSwiftSyntaxParser/libSwiftSyntaxParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,7 @@ swiftparse_client_node_t SynParser::parse(const char *source) {
TypeCheckerOptions tyckOpts;
LangOptions langOpts;
langOpts.BuildSyntaxTree = true;
langOpts.ParseForSyntaxTreeOnly = true;
langOpts.CollectParsedToken = false;
// Disable name lookups during parsing.
// Not ready yet:
Expand Down
1 change: 1 addition & 0 deletions tools/swift-syntax-test/swift-syntax-test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -606,6 +606,7 @@ int parseFile(
// Set up the compiler invocation
CompilerInvocation Invocation;
Invocation.getLangOptions().BuildSyntaxTree = true;
Invocation.getLangOptions().ParseForSyntaxTreeOnly = true;
Invocation.getLangOptions().VerifySyntaxTree = options::VerifySyntaxTree;
Invocation.getLangOptions().RequestEvaluatorGraphVizPath = options::GraphVisPath;
Invocation.getFrontendOptions().InputsAndOutputs.addInputFile(InputFileName);
Expand Down

0 comments on commit 7913091

Please sign in to comment.