Skip to content

Skip new parser validation when skipping function bodies #67352

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
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
18 changes: 15 additions & 3 deletions lib/Frontend/Frontend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1538,10 +1538,22 @@ CompilerInstance::getSourceFileParsingOptions(bool forPrimary) const {
opts |= ParsingFlags::SuppressWarnings;
}

// Turn off round-trip checking for secondary files, and for dependency
// scanning and IDE inspection.
// Turn off new parser round-trip and diagnostics checking for
// - secondary files
// - Only want to verify on primary files, no point checking more than
// once
// - IDE inspection
// - We don't want to pay the cost of verification for simple IDE
// functionality (eg. completion and cursor info)
// - dependency scanning
// - Same as IDE inspection, this is meant to be a very fast operation.
// Don't slow it down
// - skipped function bodies
// - Swift parser doesn't support function body skipping yet, so this
// would result in verification failures when bodies have errors
if (!isEffectivelyPrimary || SourceMgr.hasIDEInspectionTargetBuffer() ||
frontendOpts.RequestedAction == ActionType::ScanDependencies) {
frontendOpts.RequestedAction == ActionType::ScanDependencies ||
typeOpts.SkipFunctionBodies != FunctionBodySkipping::None) {
opts -= ParsingFlags::RoundTrip;
opts -= ParsingFlags::ValidateNewParserDiagnostics;
}
Expand Down
7 changes: 3 additions & 4 deletions test/Parse/new_parser_diagnostics.swift
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
// RUN: %target-typecheck-verify-swift -enable-experimental-feature ParserDiagnostics

// FIXME: Swift parser is not enabled on Linux CI yet.
// REQUIRES: OS=macosx
// REQUIRES: swift_swift_parser
// REQUIRES: asserts

// RUN: %target-typecheck-verify-swift -enable-experimental-feature ParserDiagnostics

_ = [(Int) -> async throws Int]()
// expected-error@-1{{'async throws' must precede '->'}}
// expected-note@-2{{move 'async throws' in front of '->'}}{{15-21=}} {{21-28=}} {{20-21= }} {{12-12=async }} {{12-12=throws }}
17 changes: 17 additions & 0 deletions test/Parse/validate_new_parser_diagnostics.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// REQUIRES: swift_swift_parser
// REQUIRES: asserts

// Checks that skipping function bodies doesn't cause the new parser validation
// to fail. This can currently be the case because the new parser doesn't
// support skipping, causing validation fail as it generates diagnostics when
// the C++ parser would not.

// RUN: %target-typecheck-verify-swift -enable-experimental-feature ParserValidation
// RUN: %target-swift-frontend -typecheck %s -enable-experimental-feature ParserValidation -experimental-skip-all-function-bodies

func bad() {
_ = [(Int) -> async throws Int]()
// expected-error@-1{{'throws' may only occur before '->'}}
// expected-error@-2{{'async' may only occur before '->'}}
}