Skip to content

Commit 7902c6e

Browse files
committed
Add an experimental feature to do validation of the Swift Swift parser.
1 parent f52f0a5 commit 7902c6e

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
@@ -129,6 +129,10 @@ EXPERIMENTAL_FEATURE(TypeWrappers)
129129
/// Whether to perform round-trip testing of the Swift Swift parser.
130130
EXPERIMENTAL_FEATURE(ParserRoundTrip)
131131

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

lib/AST/ASTPrinter.cpp

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

2942+
static bool usesFeatureParserValidation(Decl *decl) {
2943+
return false;
2944+
}
2945+
29422946
static void suppressingFeatureSpecializeAttributeWithAvailability(
29432947
PrintOptions &options,
29442948
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)