Closed djc closed 2 years ago
To clarify, the assumption might be valid, or is at least reasonable given that it works fine in rustc
. It's just that we don't really unload the proc macro libraries, and use a single process per Cargo workspace, IIRC. We could probably spawn a new process for each proc macro, but I wouldn't be surprised if users started complaining about RA being a resource hog with dozens of processes.
A quick workaround on your side might be to store that value in a thread-local variable. We currently expand each macro call in a new thread (because the bridge now requires that), so we wouldn't get the benefits of the cache, but at least it would work.
This should be easy to fix / work around in proc-macro-crate so I'll work on a PR. I'm also very interested in what others think about this assumption though. I guess this is the wrong place for that discussion, maybe https://github.com/rust-lang/rust-analyzer/issues/12969 is right.
Turning the CACHE
static at https://github.com/bkchr/proc-macro-crate/blob/66213a5d49a46f4986a5b2d9cee0cbefab5e917b/src/lib.rs#L118 into a thread local should fix this as thread locals are cleared between invocations in rust-analyzer as it puts every invocation in it's own thread. It shouldn't regress performance in rustc as rustc uses a single thread right now. This will probably change in the future though. Another option would be to make it a map from CARGO_MANIFEST_DIR
to crate name. This will keep using the old name if the crate name gets changed in Cargo.toml
though.
Another option would be to make it a map from
CARGO_MANIFEST_DIR
to crate name. This will keep using the old name if the crate name gets changed inCargo.toml
though.
This is what I'm doing, and I'm also adding a timestamp based on fs metadata so changing the Cargo.toml
file and re-running the proc macro from the same process won't use outdated information from the cache.
After my weekly dependency updates this morning, I'm having async-graphql macros failing in my crates with this assertion:
It looks like #20 is making assumptions it should not be making. Rust-Analyzer issue: https://github.com/rust-lang/rust-analyzer/issues/12969.
cc @jplatte