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

ValueStack not properly reset during application of "reduction rules" #207

Open
sirthias opened this issue Jun 25, 2019 · 0 comments

Comments

Projects
None yet
1 participant
@sirthias
Copy link
Owner

commented Jun 25, 2019

When a rule transforms the value stack (rather than simply pushing values onto it) then these transformations are not always rolled back (as one would expect) when an optional or repetition rules fails further up in the rule structure.

The tests added with the referenced commit below demonstrate the problem.

Due to the mutable nature of the value stack (which is mutable in order to avoid an allocation with every push) fixing this problem is not entirely trivial. Switching to an immutable stack implementation would provide an easy, immediate solution but come with a quite severe performance penalty.

One way could be to switch to a hybrid mutable/immutable value stack implementation, which mutates in place for the large majority of cases and only allocates when optional, zeroOrMore or oneOrMore is applied to rules that actually consume values (i.e. whose I type parameter is not HNil).

Another solution would be to completely disallow reduction rules for optional, zeroOrMore or oneOrMore combinators, which would be an unfortunate restriction, since they can be quite handy in many cases.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.