Skip to content

Refactor main executable into a frontend architecture. #178

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
Apr 6, 2020

Conversation

allevato
Copy link
Member

@allevato allevato commented Apr 6, 2020

Instead of a bunch of free functions that pass their arguments
around, this change now refactors the core format and lint file
handling functionality into a set of "frontend" classes so that
the diagnostic engine and related state can be created in one
place and shared.

This also significantly improves error handling. Whereas we
were previously killing the process on the first sign of a
source file or configuration file being invalid, we now emit
an error and skip the file, allowing any remaining inputs to
still be processed.

Lastly, this introduces a configuration cache so that we're
not re-reading the configuration from the file system for
every source file we process. In most cases, when we're
processing a recursive directory structure, they'll all
share a configuration file at a common root, so we cache
that based on its file URL and return it when requested.

@allevato
Copy link
Member Author

allevato commented Apr 6, 2020

cc @dylansturg

private func processPaths(_ paths: [String]) {
precondition(
!paths.isEmpty,
"processFiles() should only be called when paths is non-empty.")
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this be processPaths?

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 should be processPaths(_:) 😛 That's what I get for trying to have a helpful sanity check.

Instead of a bunch of free functions that pass their arguments
around, this change now refactors the core format and lint file
handling functionality into a set of "frontend" classes so that
the diagnostic engine and related state can be created in one
place and shared.

This also significantly improves error handling. Whereas we
were previously killing the process on the first sign of a
source file or configuration file being invalid, we now emit
an error and skip the file, allowing any remaining inputs to
still be processed.

Lastly, this introduces a configuration cache so that we're
not re-reading the configuration from the file system for
every source file we process. In most cases, when we're
processing a recursive directory structure, they'll all
share a configuration file at a common root, so we cache
that based on its file URL and return it when requested.
@allevato allevato force-pushed the better-error-handling branch from 45c8c96 to 3d859da Compare April 6, 2020 22:18
@allevato allevato merged commit 634a112 into swiftlang:master Apr 6, 2020
@allevato allevato deleted the better-error-handling branch April 6, 2020 22:18
aaditya-chandrasekhar pushed a commit to val-verde/swift-format that referenced this pull request May 20, 2021
swiftlang#178)

* Don't render href on unknown symbols for child relationships

* Add changelog entry for swiftlang#178

Co-authored-by: Mattt <[email protected]>
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