The foldcommontails-walker currently misses some opportunities as demonstrated here (the optional mut should be folded) and here (the pub should be folded).
The problem most likely is that the optimizer might produce a Choice of just one element, when it effectivly becomes a Sequence. Since it can not "look into" a Choice when evaluating common tails, it misses out.
The fix is probably to implement a simplifying pass that
Turns Choice of exactly one element into Sequence
Turns Sequence of exactly one element into that element
Removes the needless Sequence in a Repeat
and such.
There are situations where we do this manually now; get rid of them.
The result of the folding pass should be simplified before re-evaluating the current Choice for more opportunities. The overall result should also be simplified.
The
foldcommontails
-walker currently misses some opportunities as demonstrated here (the optionalmut
should be folded) and here (thepub
should be folded).The problem most likely is that the optimizer might produce a
Choice
of just one element, when it effectivly becomes aSequence
. Since it can not "look into" aChoice
when evaluating common tails, it misses out.The fix is probably to implement a simplifying pass that
Choice
of exactly one element intoSequence
Sequence
of exactly one element into that elementSequence
in aRepeat
There are situations where we do this manually now; get rid of them.
The result of the folding pass should be simplified before re-evaluating the current
Choice
for more opportunities. The overall result should also be simplified.