-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Support error recovery in check
for invalid parse trees
#4689
Comments
Stepping back a moment, we currently expect that (a) parse can create (subtly) invalid parse trees, and (b) check will crash on these. We do not fuzz test invalid parse trees as a consequence. So broadly speaking, I think it's fair to say crashes like this are probably common. Similarly, I think we should be cautious about trying to chase down all the issues like this unless we're ready to really commit to error recovery -- my leaning has been that we benefit from prioritizing language features first. Regarding just bumping out, my expectation has been that we'd try to check invalid parse trees as best as possible. At a minimum, we should be okay checking a parse tree until the first invalid node. However, you might have something like:
My own expectation is that this should print a diagnostic for the invalid In this specific case, I think the right choice is to recover in parse. For now, I believe that's creating Short-term, we could exit with a TODO in ProcessNodeIds when node_has_error. |
Thanks for the discussion/details - I'll work on the short-term fix for now, after that don't mind leaving this bug open or closing for now since we aren't planning to work on this feature (check recovery from parse failures) at this time. |
Maybe re-title the issue to reflect the broader scope of it, or I could create a new issue that captures the high-level problem/plan? |
extend base
check
for invalid parse trees
Retitling sounds good - I could edit the main post at the top to discuss this/focus on this broader issue? |
Short term solution/block for #4689
Description of the bug:
No response
What did you do, or what's a simple way to reproduce the bug?
What did you expect to happen?
In this particular case, it could've recovered with an assumed
:
, but I'd also (or perhaps initially/first) like to fix the more general case, where a recovery might not be feasible/correct/helpful.What actually happened?
CHECK-fail/crash:
Any other information, logs, or outputs that you want to share?
I know we (myself, @zygoloid and @jonmeow ) have had some conversations about this, but some was in person/un-recorded, or the records are hard for me to find/synthesize.
Currently, the failure in
carbon-lang/toolchain/parse/handle_base.cpp
Lines 14 to 25 in f922988
Specifically, this does not match the "shape" a
BaseDecl
expects, which is this:And so the above crash/check-fail occurs.
I know we had talked about different representations for the failure and recovery.
But I'd like to focus on the case where recovery isn't feasible.
What should we do in that case? (eg: if the name (
Foo
) is missing entirely)I thought we could, in check, skip any error nodes in Check's
carbon-lang/toolchain/check/check_unit.cpp
Lines 345 to 347 in f922988
But judging by the code in https://github.com/carbon-language/carbon-lang/blob/f922988c8ccaaf68e703e3126a4a26709efb460f/toolchain/check/handle_noop.cpp that's not the intent (the intent seems to be that we do walk through even the error nodes) - but perhaps the proposed skip ^ is the way to address these TODOs? (or perhaps some more general "we shouldn't check a parse tree with any invalid nodes at all" might be even more general/failing earlier?)
After this discussion, I wouldn't mind discussing how to improve the error recovery - I know we talked about some kind of "synthetic token" we could use to put the colon into the parse tree?
The text was updated successfully, but these errors were encountered: