softdevteam / lrpar

Rust LR parser
Other
1 stars 0 forks source link

Add a recovery timeout #57

Closed ltratt closed 6 years ago

ltratt commented 6 years ago

Corchuelo have heuristics to know "when to stop" -- unfortunately they don't work well in edge cases as they're based on the number of tokens examined. For example, on the Java grammar, it's possible to construct inputs that have massive search spaces, even with only a few tokens involved, and that take tens of minutes to complete.

This PR adds a simple timeout facility to recoverers: after a fixed amount of time (0.5s) the recoverer simply gives up. This is, in one way, very dumb, but it deals well with the user expectation that recovery won't continue indefinitely. The check is put into the "neighbours" function, which is expected to regularly check the timeout. This means that we check pretty often, but not so often as to be ridiculous. It also keeps the API fairly simple.

A note of warning: on some platforms, there appears to be a codegen bug. In debug mode, this PR works fine. In release mode (on 2 of the 3 machines I have access to), the timeout doesn't work. I don't really know why. It is, of course, quite possible that I've made a crass mistake, so please check to see if I've done something obviously stupid. But, because the problem only occurs in release mode, I suspect it's a buggy optimisation somewhere in rustc or LLVM...