diff options
| author | Amos Wenger <amoswenger@gmail.com> | 2022-07-21 18:11:50 +0200 |
|---|---|---|
| committer | Amos Wenger <amoswenger@gmail.com> | 2022-07-21 18:11:50 +0200 |
| commit | 32ee097580fe473bcdbae5f422c93e99dec348a3 (patch) | |
| tree | 1ffb3acd8ddd6e7c14923e99c47198bf71cf113a | |
| parent | 05d8f5fee7ceacb68e18a6c9c7fc4d15adc75b22 (diff) | |
| download | rust-32ee097580fe473bcdbae5f422c93e99dec348a3.tar.gz rust-32ee097580fe473bcdbae5f422c93e99dec348a3.zip | |
Run proc macro expansion in a separate thread (for the thread-local interner)
| -rw-r--r-- | Cargo.lock | 25 | ||||
| -rw-r--r-- | crates/proc-macro-srv/Cargo.toml | 1 | ||||
| -rw-r--r-- | crates/proc-macro-srv/src/lib.rs | 13 |
3 files changed, 36 insertions, 3 deletions
diff --git a/Cargo.lock b/Cargo.lock index 0204617d5df..67bfbf01096 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -248,6 +248,20 @@ dependencies = [ ] [[package]] +name = "crossbeam" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ae5588f6b3c3cb05239e90bd110f257254aecd01e4635400391aeae07497845" +dependencies = [ + "cfg-if", + "crossbeam-channel", + "crossbeam-deque", + "crossbeam-epoch", + "crossbeam-queue", + "crossbeam-utils", +] + +[[package]] name = "crossbeam-channel" version = "0.5.5" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -283,6 +297,16 @@ dependencies = [ ] [[package]] +name = "crossbeam-queue" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f25d8400f4a7a5778f0e4e52384a48cbd9b5c495d110786187fc750075277a2" +dependencies = [ + "cfg-if", + "crossbeam-utils", +] + +[[package]] name = "crossbeam-utils" version = "0.8.10" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1162,6 +1186,7 @@ dependencies = [ name = "proc-macro-srv" version = "0.0.0" dependencies = [ + "crossbeam", "expect-test", "libloading", "mbe", diff --git a/crates/proc-macro-srv/Cargo.toml b/crates/proc-macro-srv/Cargo.toml index e39026ac70b..5746eac0b37 100644 --- a/crates/proc-macro-srv/Cargo.toml +++ b/crates/proc-macro-srv/Cargo.toml @@ -24,6 +24,7 @@ tt = { path = "../tt", version = "0.0.0" } mbe = { path = "../mbe", version = "0.0.0" } paths = { path = "../paths", version = "0.0.0" } proc-macro-api = { path = "../proc-macro-api", version = "0.0.0" } +crossbeam = "0.8.1" [dev-dependencies] expect-test = "1.4.0" diff --git a/crates/proc-macro-srv/src/lib.rs b/crates/proc-macro-srv/src/lib.rs index 2ab6eba6f42..98a79f5be33 100644 --- a/crates/proc-macro-srv/src/lib.rs +++ b/crates/proc-macro-srv/src/lib.rs @@ -63,9 +63,16 @@ impl ProcMacroSrv { let macro_body = task.macro_body.to_subtree(); let attributes = task.attributes.map(|it| it.to_subtree()); - let result = expander - .expand(&task.macro_name, ¯o_body, attributes.as_ref()) - .map(|it| FlatTree::new(&it)); + let result = crossbeam::scope(|s| { + s.spawn(|_| { + expander + .expand(&task.macro_name, ¯o_body, attributes.as_ref()) + .map(|it| FlatTree::new(&it)) + }) + .join() + .unwrap() + }) + .unwrap(); prev_env.rollback(); |
