Replace crossbeam with std's scoped threads

This commit is contained in:
Lukas Wirth 2022-08-11 17:12:25 +02:00
parent dea163970a
commit f9d1b26a96
3 changed files with 6 additions and 37 deletions

25
Cargo.lock generated
View File

@ -247,20 +247,6 @@ dependencies = [
"cfg-if", "cfg-if",
] ]
[[package]]
name = "crossbeam"
version = "0.8.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2801af0d36612ae591caa9568261fddce32ce6e08a7275ea334a06a4ad021a2c"
dependencies = [
"cfg-if",
"crossbeam-channel",
"crossbeam-deque",
"crossbeam-epoch",
"crossbeam-queue",
"crossbeam-utils",
]
[[package]] [[package]]
name = "crossbeam-channel" name = "crossbeam-channel"
version = "0.5.6" version = "0.5.6"
@ -296,16 +282,6 @@ dependencies = [
"scopeguard", "scopeguard",
] ]
[[package]]
name = "crossbeam-queue"
version = "0.3.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1cd42583b04998a5363558e5f9291ee5a5ff6b49944332103f251e7479a82aa7"
dependencies = [
"cfg-if",
"crossbeam-utils",
]
[[package]] [[package]]
name = "crossbeam-utils" name = "crossbeam-utils"
version = "0.8.11" version = "0.8.11"
@ -1178,7 +1154,6 @@ dependencies = [
name = "proc-macro-srv" name = "proc-macro-srv"
version = "0.0.0" version = "0.0.0"
dependencies = [ dependencies = [
"crossbeam",
"expect-test", "expect-test",
"libloading", "libloading",
"mbe", "mbe",

View File

@ -24,7 +24,6 @@ tt = { path = "../tt", version = "0.0.0" }
mbe = { path = "../mbe", version = "0.0.0" } mbe = { path = "../mbe", version = "0.0.0" }
paths = { path = "../paths", version = "0.0.0" } paths = { path = "../paths", version = "0.0.0" }
proc-macro-api = { path = "../proc-macro-api", version = "0.0.0" } proc-macro-api = { path = "../proc-macro-api", version = "0.0.0" }
crossbeam = "0.8.1"
[dev-dependencies] [dev-dependencies]
expect-test = "1.4.0" expect-test = "1.4.0"

View File

@ -26,6 +26,7 @@ use std::{
ffi::OsString, ffi::OsString,
fs, fs,
path::{Path, PathBuf}, path::{Path, PathBuf},
thread,
time::SystemTime, time::SystemTime,
}; };
@ -65,18 +66,16 @@ impl ProcMacroSrv {
let macro_body = task.macro_body.to_subtree(); let macro_body = task.macro_body.to_subtree();
let attributes = task.attributes.map(|it| it.to_subtree()); let attributes = task.attributes.map(|it| it.to_subtree());
// FIXME: replace this with std's scoped threads once they stabilize let result = thread::scope(|s| {
// (then remove dependency on crossbeam) let thread = thread::Builder::new()
let result = crossbeam::scope(|s| {
let res = match s
.builder()
.stack_size(EXPANDER_STACK_SIZE) .stack_size(EXPANDER_STACK_SIZE)
.name(task.macro_name.clone()) .name(task.macro_name.clone())
.spawn(|_| { .spawn_scoped(s, || {
expander expander
.expand(&task.macro_name, &macro_body, attributes.as_ref()) .expand(&task.macro_name, &macro_body, attributes.as_ref())
.map(|it| FlatTree::new(&it)) .map(|it| FlatTree::new(&it))
}) { });
let res = match thread {
Ok(handle) => handle.join(), Ok(handle) => handle.join(),
Err(e) => std::panic::resume_unwind(Box::new(e)), Err(e) => std::panic::resume_unwind(Box::new(e)),
}; };
@ -86,10 +85,6 @@ impl ProcMacroSrv {
Err(e) => std::panic::resume_unwind(e), Err(e) => std::panic::resume_unwind(e),
} }
}); });
let result = match result {
Ok(result) => result,
Err(e) => std::panic::resume_unwind(e),
};
prev_env.rollback(); prev_env.rollback();