Skip to content

Commit 04d7938

Browse files
authored
Merge pull request swiftlang#63372 from ahoppen/ahoppen/swiftparser-errors-only-verification
[Parser] When performing parser validation, suppress warnings from SwiftParser
2 parents 89625c0 + d54af66 commit 04d7938

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

lib/ASTGen/Sources/ASTGen/SourceFile.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@ extension Syntax {
7676
@_cdecl("swift_ASTGen_emitParserDiagnostics")
7777
public func emitParserDiagnostics(
7878
diagEnginePtr: UnsafeMutablePointer<UInt8>,
79-
sourceFilePtr: UnsafeMutablePointer<UInt8>
79+
sourceFilePtr: UnsafeMutablePointer<UInt8>,
80+
emitOnlyErrors: CInt
8081
) -> CInt {
8182
return sourceFilePtr.withMemoryRebound(
8283
to: ExportedSourceFile.self, capacity: 1
@@ -93,6 +94,9 @@ public func emitParserDiagnostics(
9394
if diag.node.isInIfConfig {
9495
continue
9596
}
97+
if emitOnlyErrors != 0, diag.diagMessage.severity != .error {
98+
continue
99+
}
96100

97101
emitDiagnostic(
98102
diagEnginePtr: diagEnginePtr,

lib/Parse/ParseDecl.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -186,9 +186,9 @@ extern "C" int swift_ASTGen_roundTripCheck(void *sourceFile);
186186

187187
/// Emit parser diagnostics for given source file.. Returns non-zero if any
188188
/// diagnostics were emitted.
189-
extern "C" int swift_ASTGen_emitParserDiagnostics(
190-
void *diagEngine, void *sourceFile
191-
);
189+
extern "C" int swift_ASTGen_emitParserDiagnostics(void *diagEngine,
190+
void *sourceFile,
191+
int emitOnlyErrors);
192192

193193
// Build AST nodes for the top-level entities in the syntax.
194194
extern "C" void swift_ASTGen_buildTopLevelASTNodes(void *sourceFile,
@@ -274,8 +274,12 @@ void Parser::parseTopLevelItems(SmallVectorImpl<ASTNode> &items) {
274274
diagnose(loc, diag::parser_round_trip_error);
275275
} else if (Context.LangOpts.hasFeature(Feature::ParserValidation) &&
276276
!Context.Diags.hadAnyError() &&
277-
swift_ASTGen_emitParserDiagnostics(
278-
&Context.Diags, SF.exportedSourceFile)) {
277+
swift_ASTGen_emitParserDiagnostics(&Context.Diags,
278+
SF.exportedSourceFile,
279+
/*emitOnlyErrors=*/true)) {
280+
// We might have emitted warnings in the C++ parser but no errors, in
281+
// which case we still have `hadAnyError() == false`. To avoid emitting
282+
// the same warnings from SwiftParser, only emit errors from SwiftParser
279283
SourceLoc loc;
280284
if (auto bufferID = SF.getBufferID()) {
281285
loc = Context.SourceMgr.getLocForBufferStart(*bufferID);
@@ -318,7 +322,7 @@ Parser::parseSourceFileViaASTGen(SmallVectorImpl<ASTNode> &items,
318322
Context.LangOpts.hasFeature(Feature::ParserASTGen)) &&
319323
!suppressDiagnostics &&
320324
swift_ASTGen_emitParserDiagnostics(
321-
&Context.Diags, SF.exportedSourceFile) &&
325+
&Context.Diags, SF.exportedSourceFile, /*emitOnlyErrors=*/false) &&
322326
Context.Diags.hadAnyError() &&
323327
!Context.LangOpts.hasFeature(Feature::ParserASTGen)) {
324328
// Errors were emitted, and we're still using the C++ parser, so

0 commit comments

Comments
 (0)