Skip to content

Refactor "diagnostics" into "findings". #270

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 1 commit into from
Nov 10, 2021

Conversation

allevato
Copy link
Member

@allevato allevato commented Nov 4, 2021

This change addresses swiftlang/swift-syntax#309 and swiftlang/swift-syntax#325, which split SwiftSyntaxParser into its own module and then removed the DiagnosticEngine APIs (so only the Diagnostic type remains as the way diagnostics from the parser are sent back to the caller).

Rather than remain coupled to swift-syntax's Diagnostic type, this change creates a similar Finding type (and related types) to describe the "lint findings" that tree-based rules, the pretty-printer, and the whitespace linter encounter during
formatting/linting.

This Finding type is the currency type for these kinds of findings/diagnostics emitted by the formatter API layer. The
swift-format frontend tool now adopts DiagnosticsEngine from https://github.com/apple/swift-tools-support-core to manage and print these, but other clients using the API could use something different entirely. Since the usage of TSC is limited to the executable, API users don't have to take on a large and mostly unrelated dependency.

There are still some opportunities for renaming here -- mainly replacing instances of diagnose in the internal code with emitFinding or something similar -- but I'll leave that as future cleanup.

This change addresses swiftlang/swift-syntax#309
and swiftlang/swift-syntax#325, which split
`SwiftSyntaxParser` into its own module and then removed the
`DiagnosticEngine` APIs (so only the `Diagnostic` type remains as
the way diagnostics from the parser are sent back to the caller).

Rather than remain coupled to swift-syntax's `Diagnostic` type,
this change creates a similar `Finding` type (and related types)
to describe the "lint findings" that tree-based rules, the
pretty-printer, and the whitespace linter encounter during
formatting/linting.

This `Finding` type is the currency type for these kinds of
findings/diagnostics emitted by the formatter API layer. The
`swift-format` frontend tool now adopts `DiagnosticsEngine` from
https://github.com/apple/swift-tools-support-core to manage and
print these, but other clients using the API could use something
different entirely. Since the usage of `TSC` is limited to the
executable, API users don't have to take on a large and mostly
unrelated dependency.

There are still some opportunities for renaming here --
mainly replacing instances of `diagnose` in the internal code
with `emitFinding` or something similar -- but I'll leave that
as future cleanup.
@allevato
Copy link
Member Author

allevato commented Nov 4, 2021

Tested against swift-DEVELOPMENT-SNAPSHOT-2021-10-28-a:

Test Suite 'All tests' passed at 2021-11-04 15:53:21.029.
	 Executed 578 tests, with 0 failures (0 unexpected) in 11.055 (11.084) seconds

cc @dylansturg


/// Prints a diagnostic to standard error.
func printDiagnosticToStderr(_ diagnostic: TSCBasic.Diagnostic) {
printQueue.sync {
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if there would be any appreciable performance difference using async here, especially in parallel mode. In the end, we would need to flush the print queue though (so all diagnostics get printed before exiting), which I guess would have to be handled in the Linter and Format frontends. Might not be worth the added complexity.

Copy link
Member Author

Choose a reason for hiding this comment

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

It's certainly worth trying out as follow-up work to see if there's a meaningful difference.

@allevato allevato merged commit 5add2e0 into swiftlang:main Nov 10, 2021
@allevato allevato deleted the refactor-diagnostics branch November 10, 2021 15:48
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.

2 participants