dtolnay / watt

Runtime for executing procedural macros as WebAssembly
Apache License 2.0
1.29k stars 29 forks source link

Pure Macros #55

Open rzvxa opened 5 months ago

rzvxa commented 5 months ago

Hello,

I hope you having a wonderful day, First off let me thank you for your awesome projects; I'm a fan of your work.

I was wondering have you ever tried to cache the TokenStream based on the input? So maybe we can mark a procedural macro as #[pure] and get the results cached based on the input?

I have recently forked proc-macro2 and serde (to remove its dependency on proc-macro2) and bootstrapped a simple serializable TokenStream, But It means that I would still spend a lot of time compiling and running a noop macro that just reads the cache and returns it.

Then I came around to this article a few days ago https://www.coderemote.dev/blog/faster-rust-compiler-macro-expansion-caching/

It sounded promising to me, So that's when I started thinking about using Watt as both the runtime and cache server to prevent the redundant time spent on the macro execution by short-circuiting from the cache auto-magically.

So what I want to ask you is, Have you ever tried this? What are your thoughts? Do you think Watt can be a good place to do this kind of caching? Or do you prefer me to not submit such a PR and instead work on a standalone solution?

I also would like to know about the current situation with the Compiler and Fallback variants of the token stream and whether are they going to both be kept in or one is a temporary transition period solution. But I think that's another question for another repo.

Note: while this text is written with @dtolnay as the recipient the question remains open for everyone to discuss. Sorry if it felt more like an email than an issue, I just noticed the tone as I'm about to submit😅