-
Notifications
You must be signed in to change notification settings - Fork 286
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
Lalrpop 0.20.2 exception "no entry found for key" #897
Comments
Thanks for the report! I'm looking into this. This part of the code is hit when the grammar is not LALR(1), so the lane table algorithm needs to split states in order to resolve inconsistencies. I checked our existing test coverage, and we have a few tests that hit this path, but all of them resolve shift-reduce conflicts, while this grammar needs to resolve a reduce-reduce conflict (Note that this is not an actual conflict in the grammar, but rather a step in the lane table algorithm, which initially treats the grammar as LR(0), and then resolves conflicts as needed in order to handle full LR(1) in a space efficient way). So I imagine this code path just doesn't have much test coverage. It looks to me as though the problem is that the conflicting state isn't being added to the lane table, leading to the panic reported here, since we attempt to access the state when resolving. I tried simply adding it to the lane table, but that seems to cause a lot of reduce/reduce conflicts in valid grammars - I'm not sure why. That's all pretty tentative. My next step will be to try to come up with a much more minimal reproducer that will be easier to reason about. We'll need that anyways to add test coverage for this case. Hopefully with a smaller reproducer it will be easier to figure out exactly what's going on here. My time over the next few days to work on this will likely be spotty, but I wanted to update that I'm looking at it and slowly narrowing in towards a root cause. |
The minimal example came together quicker than I expected. I can reproduce with this grammar:
This is based on the G1 grammar described here, which we test. The difference is that while the actual conflict in G1 is reduce/reduce, it happens that the conflicting state also has a shift action. This grammar, which I'm calling G2 has a reduce/reduce conflict that can be resolved via the lane table, but no additional shift action. The code adds the original state to the lane table on a shift action, but not a reduce action, so the presence of a consistent shift action ensures that the missing state ends up in the lane table. I'm pretty sure we need to get that state into the table in this case as well, but my naive attempts to do that have broken other things, so I need to investigate exactly why. |
Okay, I think I have it. Some tweaks to exactly how I added the state to the lane table, and things are mostly working. The G2 grammar I posted above builds successfully, and the cubimpl grammar shared in the report no longer panics, but instead produces conflict messages. That grammar is pretty involved, so I have no idea if it should be valid or not, but we're not panicing anymore, so I suspect the conflicts are legitimate, particular since the more understandable G2 works. I need to do some cleanup and put G2 into a unit test, and then I'll submit a PR. |
We need to make sure the state in the conflict is in the lane table. All the existing test cases happened to have a shift case in the conflict state, even if the shift wasn't part of the actual conflict. In the event of a conflicting state with only reduce actions, we'll need the lookahead store, so we can check it as a successor of the predecessors we found. fixes lalrpop#897
…#898) We need to make sure the state in the conflict is in the lane table. All the existing test cases happened to have a shift case in the conflict state, even if the shift wasn't part of the actual conflict. In the event of a conflicting state with only reduce actions, we'll need the lookahead store, so we can check it as a successor of the predecessors we found. fixes #897
Repo: Storyyeller/cubiml-demo@502da7a
run "RUST_BACKTRACE=full lalrpop src/grammar.lalr"
produces the error
lalrpop version is 0.20.2
The text was updated successfully, but these errors were encountered: