Skip to content
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

CHECK that PreCheck and GetCheckUnit are not called twice #4608

Merged
merged 2 commits into from
Dec 2, 2024

Conversation

danakj
Copy link
Contributor

@danakj danakj commented Nov 29, 2024

If they were called twice for a CompilationUnit, they would destroy objects that they created and returned a pointer to, leaving a dangling pointer somewhere else.

@danakj danakj requested a review from jonmeow November 29, 2024 18:21
@github-actions github-actions bot requested a review from zygoloid November 29, 2024 18:21
@@ -420,6 +420,8 @@ class CompilationUnit {

auto PreCheck() -> Parse::NodeLocConverter& {
CARBON_CHECK(parse_tree_, "Must call RunParse first");
CARBON_CHECK(!node_converter_.has_value(), "Called PreCheck twice");
Copy link
Contributor

@jonmeow jonmeow Dec 2, 2024

Choose a reason for hiding this comment

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

In other calls (RunLex, RunParse, PostCheck, etc) we only verify that we're moving forward. They would share this problem. I'm fine with adding more checks to help document the progressive call structure, but I think it's implying the wrong thing to only check in some calls: can you please add them in the other spots too?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right, these functions do not emplace any optionals, so it's not clear how to CHECK that without adding a bool for the purpose of checking, or maybe an enum tracking the progress through them all if it's linear. WDYT?

Copy link
Contributor

@jonmeow jonmeow Dec 2, 2024

Choose a reason for hiding this comment

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

Note, we typically don't write .has_value() for optionals. parse_tree_ is an optional [for example]. You could use the same CHECKs we're using to ensure things are called in order, to make sure they're not called again.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, thanks, will do. The lack of has_value() and use of operator= had me miss that. There's a couple functions that are still missed, but this covers most of them (and all the ones that set optionals).

If they were called twice for a snigle CompilationUnit, they would
destroy objects that they created and returned a pointer to,
leaving a dangling pointer somewhere else.
@danakj danakj force-pushed the precheck-checkunit-twice branch from eab4d30 to 9f16edd Compare December 2, 2024 20:26
@danakj danakj requested a review from jonmeow December 2, 2024 20:27
Copy link
Contributor

@jonmeow jonmeow left a comment

Choose a reason for hiding this comment

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

LG

@jonmeow jonmeow added this pull request to the merge queue Dec 2, 2024
Merged via the queue into carbon-language:trunk with commit 74dcd1f Dec 2, 2024
8 checks passed
@danakj danakj deleted the precheck-checkunit-twice branch December 3, 2024 19:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants