lukaslueg / macro_railroad

A library to generate syntax diagrams for Rust macros.
MIT License
529 stars 11 forks source link

Missed optimization opportunities #2

Closed lukaslueg closed 5 years ago

lukaslueg commented 5 years ago

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

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.

lukaslueg commented 5 years ago

Should be good for now