Skip to content

Diagnostics: teach the parser API to listen to diagnostics emitted from the compiler(parser). #102

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 5 commits into from
Mar 6, 2019

Conversation

nkcsgexi
Copy link
Contributor

@nkcsgexi nkcsgexi commented Mar 5, 2019

This patch adds a parameter of DiagnosticConsumer to the parser entry point
to capture any diagnostics emitted from the compiler(parser). We also convert the
c structures collected from the compiler side to an existing Diagnostic type
in SwiftSyntax to unify the API.

To avoid unnecessarily calculating line/column from a utf8 offset, a property
is added to DiagnosticConsumer to indicate whether the users want line/column;
by default they are calculated.

rdar://48439271

…om the compiler(parser).

This patch adds a parameter of DiagnosticConsumer to the parser entry point
to capture any diagnostics emitted from the compiler(parser). We also convert the
c structures collected from the compiler side to an existing Diagnostic type
in SwiftSyntax to unify the API.

To avoid unnecessarily calculating line/column from a utf8 offset, a property
is added to DiagnosticConsumer to indicate whether the users want line/column;
by default they are calculated.

rdar://48439271
@nkcsgexi
Copy link
Contributor Author

nkcsgexi commented Mar 5, 2019

@swift-ci please test

parseTransition: IncrementalParseTransition? = nil
file: String = "",
parseTransition: IncrementalParseTransition? = nil,
diagConsumer: DiagnosticConsumer? = nil
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you make this take a DiagnosticEngine instead? An engine might have several consumers that would want to receive diagnostics. You'd probably want to check if any of the consumers requested line and column, and compute it once if so. IMO that would make the parser API a little nicer -- 'parse and push the diagnostics into this diagnostic engine' rather than 'deliver them to this one consumer, of multiple which I might have'.

Also, please name it 'diagnosticEngine' over 'diagEngine'.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

hmm, we usually need DiagnosticEngine for issuing new diagnostics. In here, the clients just want to hear diagnostics so adding DiagnosticEngine to the parameter seems to me to complicate the caller site (setting up engine and adding consumers to it). Also, the usefulness of multiple consumers for these diagnostics isn't so clear to me yet.

Copy link
Contributor

Choose a reason for hiding this comment

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

In practice, tools that use SwiftSyntax and deal with diagnostics will create a DiagnosticEngine as part of their initial start-up. If we make this method take a single consumer, that removes the ability for a client to use multiple consumers (say, a linter that wants to print diagnostics in CI and also send them to a web service).

The way this reads now (which I still think is valid) is 'parse this file, and if there are diagnostics, tell this consumer'. I don't think it's unreasonable or more difficult for clients to change that to 'parse this file, and if there are diagnostics, use this engine to diagnose them'.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's fair. I've updated the function signature to use DiagnosticEngine instead of DiagnosticConsumer.

Copy link
Contributor

Choose a reason for hiding this comment

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

Thank you!

@nkcsgexi
Copy link
Contributor Author

nkcsgexi commented Mar 5, 2019

@swift-ci please test

@akyrtzi akyrtzi self-requested a review March 5, 2019 23:36
@nkcsgexi
Copy link
Contributor Author

nkcsgexi commented Mar 6, 2019

@swift-ci please test

@swift-ci
Copy link
Contributor

swift-ci commented Mar 6, 2019

Build failed
Swift Test OS X Platform
Git Sha - fab4998

@nkcsgexi
Copy link
Contributor Author

nkcsgexi commented Mar 6, 2019

@swift-ci please test

@swift-ci
Copy link
Contributor

swift-ci commented Mar 6, 2019

Build failed
Swift Test OS X Platform
Git Sha - aac93ed

@nkcsgexi nkcsgexi merged commit 4e09ab4 into swiftlang:master Mar 6, 2019
@nkcsgexi nkcsgexi deleted the diag-parser branch March 6, 2019 03:52
adevress pushed a commit to adevress/swift-syntax that referenced this pull request Jan 14, 2024
Add open breaks around type annotations in optional condition exprs.
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