News for hackers. Stuff that matters.
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.
Re:Why is my Rust build so slow? by Cu3PO42 on Friday December 31, 2021 @09:16AM (#29748228)
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.
Re:Why is my Rust build so slow? by jhgg on Friday December 31, 2021 @07:53AM (#29747570)
It allows for things like https://docs.rs/typed-html/latest/typed_html/ to exist.
Re:Why is my Rust build so slow? by dom96 on Friday December 31, 2021 @08:32AM (#29747842)
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.

Re:Why is my Rust build so slow? by varajelle on Friday December 31, 2021 @08:53AM (#29748039)
it's a completely separate implementation of the parser

I wish that the proc_macro API from the compiler would do that instead.

Re:Why is my Rust build so slow? by estebank on Friday December 31, 2021 @12:48PM (#29750463)
syn also let's you define your own parsers for non-Rust syntax, way beyond what rustc could provide.