jsinger67 / parol

LL(k) and LALR(1) parser generator for Rust
https://jsinger67.github.io/
Apache License 2.0
190 stars 19 forks source link

Randomly infinite loop #354

Closed dalance closed 5 months ago

dalance commented 5 months ago

I found a strange issue which a broken source code causes infinite loop randomly. The reproduce way is below:

The expected behaviour is parse failure like below. Actually, infinite loop frequently occuers instead of it.

Error: ParserError::SyntaxError

  × Unexpected token: '}'
   ╭─[/home/hatta/temp/veryl/test.veryl:2:1]
 2 │     always_ff (i_clk)
 3 │ }
   · ┬
   · ╰── Error location
 4 │
   ╰────
  help:

I thought the parsing by parol is deterministic. Is there any issue which causes the randomness?

jsinger67 commented 5 months ago

@dalance, I will have a look at it later today. Parol should in deed be deterministic. Maybe you found a bug. Infinite loops actually can only occur when the tokenizer can't make any progress in the input. Another scenario could be related to the recovery process that starts with the first error seen. If you have time you could have a look at the Q&A page of the parol book. There's a question https://jsinger67.github.io/QnA.html#q-i-get-strange-errors-while-commissioning-my-new-grammar-and-cant-figure-out-what-the-problem-is You can activate some traces to help pin down the problem.

jsinger67 commented 5 months ago

I can reproduce this scenario.

If I enable trace logs I get a panic in main.rs: image I'll try to circumvent this here locally.

jsinger67 commented 5 months ago

The problem is related to the termination behavior of the recovery process. The reason for the non-deterministic behavior is not clear yet and I'll have to take a deeper investigation for this scenario. Thank you for reporting this issue, @dalance! I'll change the label to bug and try to provide a fix soon.

jsinger67 commented 5 months ago

@dalance, in the meamwhile I have a fix. The reason for the unsettling non-deterministic behavior was due to my use of petgraph in recovery calculations. The graph data was obviously internally randomly sorted. Moreover there was a problem with the termination of recovery process which only occurred in certain scenarios. I will test this thoroughly and provide a new release for the parol_runtime crate at the weekend.

jsinger67 commented 5 months ago

Fixed with commit 9e9a534 @dalance, please update to parol_runtime@0.24 and parol@0.31 Again, thanks for reporting and keep up your good work 👌