Re:Why is my Rust build so slow?
by formerly_proven on Friday December 31, 2021 @07:10AM
(#29747303)
So I've read "syn" and "slow rust compiles" in pretty much every discussion of "slow rust compiles" and finally googled it and... syn is a Rust parser? For use in macros? Because procedural macros operate on tokens and not an AST? Hm. I'm sure there are reasons for how it ended up like this, but it does smell kinda funny.
[ Parent
| on HN ]
If I recall the reason is "rustc's representation of the AST is an implementation detail and unstable, thus macro code may not rely on it (and it will not be exposed)". Hence "syn" came along and provided a stable API and format. "quote" is the inverse function, turning an AST back into tokens.
It allows for things like https://docs.rs/typed-html/latest/typed_html/ to exist.
This is quite interesting. Is `syn` just an interface to the Rust compiler's Rust parser or is it a completely separate implementation of the parser that works at compile-time?
Hopefully it's not the latter but then I wonder where the slowness comes from.
it's a completely separate implementation of the parser
I wish that the proc_macro API from the compiler would do that instead.