Commit c4a77e1
committed
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 @thepowersgang139 files changed
Lines changed: 1537 additions & 682 deletions
File tree
- src
- bootstrap
- libproc_macro
- librustc_errors
- librustc_metadata
- librustc
- util
- libsyntax_ext
- deriving
- libtest
- test
- compile-fail/proc-macro
- auxiliary
- incremental
- auxiliary
- run-pass-fulldeps
- run-pass
- auxiliary
- proc-macro
- auxiliary
- ui-fulldeps/proc-macro
- ui
- custom-derive
- auxiliary
- proc-macro
- auxiliary
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
306 | 306 | | |
307 | 307 | | |
308 | 308 | | |
309 | | - | |
| 309 | + | |
310 | 310 | | |
311 | 311 | | |
312 | 312 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
704 | 704 | | |
705 | 705 | | |
706 | 706 | | |
707 | | - | |
708 | | - | |
709 | | - | |
710 | | - | |
711 | | - | |
712 | | - | |
713 | 707 | | |
714 | 708 | | |
715 | 709 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
11 | | - | |
12 | | - | |
13 | | - | |
14 | | - | |
| 11 | + | |
0 commit comments