Skip to content

Commit aa6f99a

Browse files
authored
Merge pull request #61283 from DougGregor/enable-round-trip-testing
[New parser] Enable round-trip testing of the new parser in +Asserts builds
2 parents 08b5c5c + 3708c66 commit aa6f99a

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed

lib/Basic/LangOptions.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ using namespace swift;
3131

3232
LangOptions::LangOptions() {
3333
// Note: Introduce default-on language options here.
34+
#ifndef NDEBUG
35+
Features.insert(Feature::ParserRoundTrip);
36+
#endif
3437
}
3538

3639
struct SupportedConditionalValue {

lib/Parse/ParseRequests.cpp

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -201,24 +201,28 @@ SourceFileParsingResult ParseSourceFileRequest::evaluate(Evaluator &evaluator,
201201
auto bufferRange = ctx.SourceMgr.getRangeForBuffer(*bufferID);
202202
unsigned int flags = 0;
203203

204-
if (ctx.LangOpts.hasFeature(Feature::ParserRoundTrip))
204+
if (ctx.LangOpts.hasFeature(Feature::ParserRoundTrip) &&
205+
!parser.L->lexingCutOffOffset()) {
205206
flags |= SCC_RoundTrip;
207+
}
206208

207209
if (!ctx.Diags.hadAnyError() &&
208210
ctx.LangOpts.hasFeature(Feature::ParserValidation))
209211
flags |= SCC_ParseDiagnostics;
210212

211-
if (ctx.LangOpts.hasFeature(Feature::ParserSequenceFolding))
213+
if (ctx.LangOpts.hasFeature(Feature::ParserSequenceFolding) &&
214+
!parser.L->lexingCutOffOffset())
212215
flags |= SCC_FoldSequences;
213216

214-
int roundTripResult =
215-
swift_parser_consistencyCheck(
216-
bufferRange.str().data(), bufferRange.getByteLength(),
217-
SF->getFilename().str().c_str(), flags);
217+
if (flags) {
218+
int roundTripResult = swift_parser_consistencyCheck(
219+
bufferRange.str().data(), bufferRange.getByteLength(),
220+
SF->getFilename().str().c_str(), flags);
218221

219-
// FIXME: Produce an error on round-trip failure.
220-
if (roundTripResult)
221-
abort();
222+
// FIXME: Produce an error on round-trip failure.
223+
if (roundTripResult)
224+
abort();
225+
}
222226
}
223227
#endif
224228

0 commit comments

Comments
 (0)