Skip to content

Downgrade placeholder error to warning for swiftparser #64382

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
9 changes: 6 additions & 3 deletions lib/ASTGen/Sources/ASTGen/Diagnostics.swift
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,15 @@ func emitDiagnostic(
diagEnginePtr: UnsafeMutablePointer<UInt8>,
sourceFileBuffer: UnsafeMutableBufferPointer<UInt8>,
diagnostic: Diagnostic,
diagnosticSeverity: DiagnosticSeverity,
messageSuffix: String? = nil
) {
// Emit the main diagnostic
emitDiagnosticParts(
diagEnginePtr: diagEnginePtr,
sourceFileBuffer: sourceFileBuffer,
message: diagnostic.diagMessage.message + (messageSuffix ?? ""),
severity: diagnostic.diagMessage.severity,
severity: diagnosticSeverity,
position: diagnostic.position,
highlights: diagnostic.highlights
)
Expand All @@ -107,7 +108,8 @@ func emitDiagnostic(
diagEnginePtr: diagEnginePtr,
sourceFileBuffer: sourceFileBuffer,
message: fixIt.message.message,
severity: .note, position: diagnostic.position,
severity: .note,
position: diagnostic.position,
fixItChanges: fixIt.changes.changes
)
}
Expand All @@ -118,7 +120,8 @@ func emitDiagnostic(
diagEnginePtr: diagEnginePtr,
sourceFileBuffer: sourceFileBuffer,
message: note.message,
severity: .note, position: note.position
severity: .note,
position: note.position
)
}
}
Expand Down
17 changes: 14 additions & 3 deletions lib/ASTGen/Sources/ASTGen/SourceFile.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import SwiftDiagnostics
import SwiftParser
import SwiftSyntax
import SwiftParserDiagnostics
Expand Down Expand Up @@ -77,7 +78,8 @@ extension Syntax {
public func emitParserDiagnostics(
diagEnginePtr: UnsafeMutablePointer<UInt8>,
sourceFilePtr: UnsafeMutablePointer<UInt8>,
emitOnlyErrors: CInt
emitOnlyErrors: CInt,
downgradePlaceholderErrorsToWarnings: CInt
) -> CInt {
return sourceFilePtr.withMemoryRebound(
to: ExportedSourceFile.self, capacity: 1
Expand All @@ -94,15 +96,24 @@ public func emitParserDiagnostics(
if diag.node.isInIfConfig {
continue
}
if emitOnlyErrors != 0, diag.diagMessage.severity != .error {

let diagnosticSeverity: DiagnosticSeverity
if downgradePlaceholderErrorsToWarnings == 1 && diag.diagMessage.diagnosticID == StaticTokenError.editorPlaceholder.diagnosticID {
diagnosticSeverity = .warning
} else {
diagnosticSeverity = diag.diagMessage.severity
}

if emitOnlyErrors != 0, diagnosticSeverity != .error {
continue
}

emitDiagnostic(
diagEnginePtr: diagEnginePtr,
sourceFileBuffer: UnsafeMutableBufferPointer(
mutating: sourceFile.pointee.buffer),
diagnostic: diag
diagnostic: diag,
diagnosticSeverity: diagnosticSeverity
)
anyDiags = true
}
Expand Down
21 changes: 14 additions & 7 deletions lib/Parse/ParseDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,9 +186,10 @@ extern "C" int swift_ASTGen_roundTripCheck(void *sourceFile);

/// Emit parser diagnostics for given source file.. Returns non-zero if any
/// diagnostics were emitted.
extern "C" int swift_ASTGen_emitParserDiagnostics(void *diagEngine,
void *sourceFile,
int emitOnlyErrors);
extern "C" int
swift_ASTGen_emitParserDiagnostics(void *diagEngine, void *sourceFile,
int emitOnlyErrors,
int downgradePlaceholderErrorsToWarnings);

// Build AST nodes for the top-level entities in the syntax.
extern "C" void swift_ASTGen_buildTopLevelASTNodes(void *sourceFile,
Expand Down Expand Up @@ -274,9 +275,12 @@ void Parser::parseTopLevelItems(SmallVectorImpl<ASTNode> &items) {
diagnose(loc, diag::parser_round_trip_error);
} else if (Context.LangOpts.hasFeature(Feature::ParserValidation) &&
!Context.Diags.hadAnyError() &&
swift_ASTGen_emitParserDiagnostics(&Context.Diags,
SF.exportedSourceFile,
/*emitOnlyErrors=*/true)) {
swift_ASTGen_emitParserDiagnostics(
&Context.Diags, SF.exportedSourceFile,
/*emitOnlyErrors=*/true,
/*downgradePlaceholderErrorsToWarnings=*/
Context.LangOpts.Playground ||
Context.LangOpts.WarnOnEditorPlaceholder)) {
// We might have emitted warnings in the C++ parser but no errors, in
// which case we still have `hadAnyError() == false`. To avoid emitting
// the same warnings from SwiftParser, only emit errors from SwiftParser
Expand Down Expand Up @@ -316,7 +320,10 @@ Parser::parseSourceFileViaASTGen(SmallVectorImpl<ASTNode> &items,
Context.LangOpts.hasFeature(Feature::ParserASTGen)) &&
!suppressDiagnostics &&
swift_ASTGen_emitParserDiagnostics(
&Context.Diags, SF.exportedSourceFile, /*emitOnlyErrors=*/false) &&
&Context.Diags, SF.exportedSourceFile, /*emitOnlyErrors=*/false,
/*downgradePlaceholderErrorsToWarnings=*/
Context.LangOpts.Playground ||
Context.LangOpts.WarnOnEditorPlaceholder) &&
Context.Diags.hadAnyError() &&
!Context.LangOpts.hasFeature(Feature::ParserASTGen)) {
// Errors were emitted, and we're still using the C++ parser, so
Expand Down