Skip to content

Experimentally emit diagnostics from the new Swift parser #62629

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 4 commits into from
Dec 16, 2022

Conversation

DougGregor
Copy link
Member

Introduce the experimental feature ParserDiagnostics, which emits
diagnostics from the new Swift parser first for a source file. If
that produces any errors, we suppress any diagnostics emitted from the
C++ parser.

While here, move diagnostic validation checking into ASTGen, so we
can drop our dependency on SwiftCompilerSupport... which will go away.

@DougGregor
Copy link
Member Author

@swift-ci please smoke test

Comment on lines 94 to 97
// Determine the set of note IDs.
let knownNoteIDs: Set<MessageID> = .init(
diagnostic.notes.map { $0.noteMessage.fixItID }
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Swift parser models diagnostics a little differently. Each diagnostic has both notes + fix-it's. A note has no fix-it attached (I think fixItID is actually misnamed here, it's just the note ID). A fix-it has both a message (or "note" if you like :P) and a set of changes.

We can talk about whether that's how we want to model that or not later, but IMO the way these should be emitted right now is that each of the fix-it's just become a note with an attached fix-it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't match the model used by the compiler, and is somewhat lossy. But I'll embrace the model here (see my latest commit) and we can iterate on the swift-syntax diagnostic model more.

@@ -118,5 +128,10 @@ func emitDiagnostic(
severity: .note, position: note.position,
fixItChanges: fixItChangesByID[note.noteMessage.fixItID] ?? []
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can drop this - notes never have fix-its.

@@ -109,6 +117,8 @@ func emitDiagnostic(
fixItChanges: fixItChangesByID[diagnostic.diagnosticID] ?? []
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can drop this - a diagnostic never has a fix-it directly attached (in the current parser model)

@@ -109,6 +117,8 @@ func emitDiagnostic(
fixItChanges: fixItChangesByID[diagnostic.diagnosticID] ?? []
)

fixItChangesByID.removeValue(forKey: diagnostic.diagnosticID)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then you can just add:

for fixIt in diagnostic.fixIts {
     emitDiagnosticParts(
      diagEnginePtr: diagEnginePtr,
      sourceFileBuffer: sourceFileBuffer,
      message: fixIt.message,
       severity: .note, position: note.position,
       fixItChanges: fixIt.changes.changes)
}

Replace the use of the "consistency check" vended by swift-syntax with
an ASTGen-implemented operation that emits diagnostics from the new parser
via the normal diagnostic engine. This eliminates our last dependency
on SwiftCompilerSupport, so stop linking it.
Introduce the experimental feature `ParserDiagnostics`, which emits
diagnostics from the new Swift parser *first* for a source file. If
that produces any errors, we suppress any diagnostics emitted from the
C++ parser.
Any Fix-Its not associated with a note are automatically associated
with the main diagnostic.
The swift-syntax diagnostic system always treats Fix-Its as separate
notes, which are never attached to the primary diagnostic. Embrace this
module in the mapping over to the existing C++ diagnostic engine.
@DougGregor DougGregor force-pushed the new-parser-diagnostics branch from 69f0873 to 4ef35c5 Compare December 16, 2022 05:25
@DougGregor
Copy link
Member Author

@swift-ci please smoke test and merge

@DougGregor
Copy link
Member Author

@swift-ci please smoke test

@@ -2021,6 +2015,9 @@ ERROR(macro_expansion_decl_expected_macro_identifier,none,

ERROR(parser_round_trip_error,none,
"source file did not round-trip through the Swift Swift parser", ())
ERROR(parser_new_parser_errors,none,
"Swift Swift parser generated errors for code that C++ parser accepted",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar to my comment on another PR, I think Swift Swift parser is confusing. What about SwiftParser or SwiftParser implemented in Swift?

@swift-ci swift-ci merged commit dfe6fd9 into swiftlang:main Dec 16, 2022
@DougGregor DougGregor deleted the new-parser-diagnostics branch December 16, 2022 17:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants