Skip to content

Commit c4a77e1

Browse files
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 @thepowersgang
2 parents 75af15e + 6e63e8d commit c4a77e1

File tree

139 files changed

+1537
-682
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

139 files changed

+1537
-682
lines changed

src/Cargo.lock

+2-8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/bootstrap/builder.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ impl<'a> Builder<'a> {
306306
test::CompileFail, test::ParseFail, test::RunFail, test::RunPassValgrind,
307307
test::MirOpt, test::Codegen, test::CodegenUnits, test::Incremental, test::Debuginfo,
308308
test::UiFullDeps, test::RunPassFullDeps, test::RunFailFullDeps,
309-
test::CompileFailFullDeps, test::IncrementalFullDeps, test::Rustdoc, test::Pretty,
309+
test::CompileFailFullDeps, test::Rustdoc, test::Pretty,
310310
test::RunPassPretty, test::RunFailPretty, test::RunPassValgrindPretty,
311311
test::RunPassFullDepsPretty, test::RunFailFullDepsPretty, test::RunMake,
312312
test::Crate, test::CrateLibrustc, test::CrateRustdoc, test::Linkcheck,

src/bootstrap/test.rs

-6
Original file line numberDiff line numberDiff line change
@@ -704,12 +704,6 @@ host_test!(CompileFailFullDeps {
704704
suite: "compile-fail-fulldeps"
705705
});
706706

707-
host_test!(IncrementalFullDeps {
708-
path: "src/test/incremental-fulldeps",
709-
mode: "incremental",
710-
suite: "incremental-fulldeps"
711-
});
712-
713707
host_test!(Rustdoc {
714708
path: "src/test/rustdoc",
715709
mode: "rustdoc",

src/libproc_macro/Cargo.toml

+1-4
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,4 @@ path = "lib.rs"
88
crate-type = ["dylib"]
99

1010
[dependencies]
11-
syntax = { path = "../libsyntax" }
12-
syntax_pos = { path = "../libsyntax_pos" }
13-
rustc_errors = { path = "../librustc_errors" }
14-
rustc_data_structures = { path = "../librustc_data_structures" }
11+
lazy_static = "1.0.0"

0 commit comments

Comments
 (0)