Skip to content

Commit

Permalink
Auto merge of #49219 - eddyb:proc-macro-decouple, r=<try>
Browse files Browse the repository at this point in the history
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
bors committed Mar 20, 2018
2 parents 75af15e + 6e63e8d commit c4a77e1
Show file tree
Hide file tree
Showing 139 changed files with 1,537 additions and 682 deletions.
10 changes: 2 additions & 8 deletions src/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/bootstrap/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ impl<'a> Builder<'a> {
test::CompileFail, test::ParseFail, test::RunFail, test::RunPassValgrind,
test::MirOpt, test::Codegen, test::CodegenUnits, test::Incremental, test::Debuginfo,
test::UiFullDeps, test::RunPassFullDeps, test::RunFailFullDeps,
test::CompileFailFullDeps, test::IncrementalFullDeps, test::Rustdoc, test::Pretty,
test::CompileFailFullDeps, test::Rustdoc, test::Pretty,
test::RunPassPretty, test::RunFailPretty, test::RunPassValgrindPretty,
test::RunPassFullDepsPretty, test::RunFailFullDepsPretty, test::RunMake,
test::Crate, test::CrateLibrustc, test::CrateRustdoc, test::Linkcheck,
Expand Down
6 changes: 0 additions & 6 deletions src/bootstrap/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -704,12 +704,6 @@ host_test!(CompileFailFullDeps {
suite: "compile-fail-fulldeps"
});

host_test!(IncrementalFullDeps {
path: "src/test/incremental-fulldeps",
mode: "incremental",
suite: "incremental-fulldeps"
});

host_test!(Rustdoc {
path: "src/test/rustdoc",
mode: "rustdoc",
Expand Down
5 changes: 1 addition & 4 deletions src/libproc_macro/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,4 @@ path = "lib.rs"
crate-type = ["dylib"]

[dependencies]
syntax = { path = "../libsyntax" }
syntax_pos = { path = "../libsyntax_pos" }
rustc_errors = { path = "../librustc_errors" }
rustc_data_structures = { path = "../librustc_data_structures" }
lazy_static = "1.0.0"
Loading

0 comments on commit c4a77e1

Please sign in to comment.