Skip to content

Commit ef81785

Browse files
authored
Merge pull request swiftlang#60990 from DougGregor/swift-swift-parser-validation
2 parents 71312fe + 7902c6e commit ef81785

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

include/swift/Basic/Features.def

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,10 @@ EXPERIMENTAL_FEATURE(TypeWrappers)
130130
/// Whether to perform round-trip testing of the Swift Swift parser.
131131
EXPERIMENTAL_FEATURE(ParserRoundTrip)
132132

133+
/// Whether to perform validation of the parse tree produced by the Swift
134+
/// Swift parser.
135+
EXPERIMENTAL_FEATURE(ParserValidation)
136+
133137
#undef EXPERIMENTAL_FEATURE
134138
#undef UPCOMING_FEATURE
135139
#undef SUPPRESSIBLE_LANGUAGE_FEATURE

lib/AST/ASTPrinter.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2941,6 +2941,10 @@ static bool usesFeatureParserRoundTrip(Decl *decl) {
29412941
return false;
29422942
}
29432943

2944+
static bool usesFeatureParserValidation(Decl *decl) {
2945+
return false;
2946+
}
2947+
29442948
static void suppressingFeatureSpecializeAttributeWithAvailability(
29452949
PrintOptions &options,
29462950
llvm::function_ref<void()> action) {

lib/Parse/ParseRequests.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,10 +194,18 @@ SourceFileParsingResult ParseSourceFileRequest::evaluate(Evaluator &evaluator,
194194
tokensRef = ctx.AllocateCopy(*tokens);
195195

196196
#ifdef SWIFT_SWIFT_PARSER
197-
if (ctx.LangOpts.hasFeature(Feature::ParserRoundTrip) &&
197+
if ((ctx.LangOpts.hasFeature(Feature::ParserRoundTrip) ||
198+
ctx.LangOpts.hasFeature(Feature::ParserValidation)) &&
198199
ctx.SourceMgr.getCodeCompletionBufferID() != bufferID) {
199200
auto bufferRange = ctx.SourceMgr.getRangeForBuffer(*bufferID);
200-
unsigned int flags = SPCC_RoundTrip;
201+
unsigned int flags = 0;
202+
203+
if (ctx.LangOpts.hasFeature(Feature::ParserRoundTrip))
204+
flags |= SPCC_RoundTrip;
205+
206+
if (!ctx.Diags.hadAnyError() &&
207+
ctx.LangOpts.hasFeature(Feature::ParserValidation))
208+
flags |= SPCC_ParseDiagnostics;
201209

202210
int roundTripResult =
203211
swift_parser_consistencyCheck(

0 commit comments

Comments
 (0)