-
-
Notifications
You must be signed in to change notification settings - Fork 157
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
Replace tuple implementation macros with typle #614
base: main
Are you sure you want to change the base?
Conversation
Interesting! I was a little suspicious at first (in a 'does it really help?' way rather than a 'assuming ill intent' way), but I definitely agree that the resultant code is simpler to read and most likely will be simpler to maintain. That said, I do have a few questions:
|
You are right about the compilation times. I ran |
Thanks for the in-depth explanation. It's good to know that As you say, the compilation times are a bit unfortunate: I'm in two minds about this PR, since it's clearly a win from a maintainability standpoint. That said, I'm unconvinced that it adds enough (or rather, removes enough complexity-wise) to justify the compilation time footprint, at least today. Chumsky is already quite a complicated crate internally, so a recursive macro like in the original code doesn't really pose much of an additional barrier for maintainers, at least compared to what's already there. Out of interest, when you ran Assuming that there's a similar cost associated with rebuilds, I would like to keep this PR open pending further compile-time optimisations to |
This generates almost identical code to the existing macros while being more readable. The only semantic difference is for `Choice`, where the final option does not rewind the input.
All timings are on a fresh build (and specific to my laptop). As the generated code is very similar to the macro version, I do not expect any difference in compilation or runtime for crates that use The overall time for a fresh build is 5.3 s, still much longer than the 3.3 s of |
I've been working on the
typle
crate to make tuple implementations look more like typical Rust code. I foundchumsky
had some complex macro-based tuple implementations, so I've been testingtyple
with these.I thought you might like to see the results. This generates very similar code to the existing macro-base tuple implementations. The only intentional semantic difference is in
Choice
, where the input rewind is avoided after an error on the final choice for all tuple sizes. It is currently only avoided for a 1-tuple.As well as being more readable than the macros, using
typle
allows rust-analyzer to parse the code to provide type insets: