Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Combine DiagnosticConverter into DiagnosticEmitter #4878

Merged
merged 8 commits into from
Feb 6, 2025

Conversation

jonmeow
Copy link
Contributor

@jonmeow jonmeow commented Jan 31, 2025

At present, we typically define a DiagnosticConverter, then store an instance of it and a DiagnosticEmitter that wraps it. This is relatively minor in general, but I've been trying to create more self-contained DiagnosticEmitter classes (which hold their own DiagnosticConverter, similar to NullDiagnosticEmitter), and there it just gets in the way.

Since we don't reuse DiagnosticConverter instances, this combines the definition into DiagnosticEmitter. Mainly this means we don't have a separate object in play, and less to carry around.

The most impact is probably to SemIRDiagnosticConverter, which was also the most complex. Now SemIRLocDiagnosticEmitter, this gets some different construction flow. Note in the PR I've split the file rename to its own commit, to try to help delta views. However, the most substantial parts of the refactoring are split into #4876, which this depends upon.

@github-actions github-actions bot requested a review from josh11b January 31, 2025 22:49
@jonmeow jonmeow requested review from chandlerc and removed request for josh11b January 31, 2025 22:50
Copy link
Contributor

@chandlerc chandlerc left a comment

Choose a reason for hiding this comment

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

Nice, I like how this sifted out. Minor stuff inline.

@@ -320,9 +320,12 @@ auto CheckParseTrees(llvm::MutableArrayRef<Unit> units, bool prelude_import,
// UnitAndImports is big due to its SmallVectors, so we default to 0 on the
// stack.
llvm::SmallVector<UnitAndImports, 0> unit_infos;
llvm::SmallVector<Parse::GetTreeAndSubtreesFn> all_trees_and_subtrees;
Copy link
Contributor

Choose a reason for hiding this comment

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

WDYT about naming this all_tree_getters or something to indicate these are callable things, not the trees themselves?

(And maybe can just mention tree here given its just a local variable?)

Copy link
Contributor Author

@jonmeow jonmeow Feb 5, 2025

Choose a reason for hiding this comment

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

Renamed to tree_and_subtrees_getters. I prefer to include the "and subtree" given we typically say "tree" for Parse::Tree. I'm assuming you suggested "all" because I had it before, but I was just trying to emphasize the plural there.


private:
const TokenizedBuffer* tokens_;
Lex::TokenizedBuffer* tokens_;
Copy link
Contributor

Choose a reason for hiding this comment

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

const doesn't work here any more? Not a huge deal, just a bit surprising.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed (also the unnecessary namespace)

Copy link
Contributor

@chandlerc chandlerc left a comment

Choose a reason for hiding this comment

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

LGTM!

@jonmeow jonmeow force-pushed the remove-diagnostic-converter branch from 2c33d7e to d6351d5 Compare February 6, 2025 19:03
@jonmeow jonmeow enabled auto-merge February 6, 2025 19:08
@jonmeow jonmeow added this pull request to the merge queue Feb 6, 2025
Merged via the queue into carbon-language:trunk with commit e79d3be Feb 6, 2025
8 checks passed
@jonmeow jonmeow deleted the remove-diagnostic-converter branch February 6, 2025 21:49
# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants