Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #49219 - eddyb:proc-macro-decouple, r=<try>
Decouple proc_macro from the rest of the compiler. This PR removes all dependencies of `proc_macro` on compiler crates and allows multiple copies of `proc_macro`, built even by different compilers (but from the same source), to interoperate. On the compiler (aka "frontend") side: * `Registry` is implemented (as until now) * instead of function pointers, the `Expand{1,2}` wrapper types are received * `FrontendInterface` is implemented to provide the concrete type and methods * the concrete types are completely separated from the `proc_macro` public API * the only use of the implementer is to be passed to `Expand{1,2}::run` On the proc macro side (potentially using a different `proc_macro` instance): * `&mut Registry` is passed to the registrar (as until now) * `Expand{1,2}` wrappers are created to be passed to the `Registry` * they encapsulate the `proc_macro` instance used by the macro crate * their `run` method will set up the "current frontend" of that instance `proc_macro` public APIs call into the "current frontend" via the internal `bridge`: * only a currently running proc macro can interact with those APIs * the frontend itself might not be able to (if it uses a different `proc_macro` instance) * the `bridge` uses C ABI to avoid Rust ABI instability and "generation tagging" for safety * each invocation of a proc macro results in a different "generation" * specifically, opaque `proc_macro` types wrapping concrete frontend types are tagged * this prevents using values of those types across invocations (even if they can be kept) * an ABI mismatch between two versions of `proc_macro` is only possible during stage1 * specifically, rustc compiled by stage0 but proc macros compiled by stage1 * can only affect running tests at stage1 or the compiler using proc macros * defficiencies in the `bridge` can be addressed without waiting for a release cycle r? @alexcrichton cc @jseyfried @nikomatsakis @Zoxc @thepowersgang
- Loading branch information