From a65025604da0a3f43b668c60a4a2f97a70b71363 Mon Sep 17 00:00:00 2001 From: Edwin Cheng Date: Fri, 1 Jan 2021 15:09:27 +0800 Subject: [PATCH] Fix deep syntax tree bug generated by proc-macro --- Cargo.lock | 33 ++++++++++++++++++++++++++++ crates/proc_macro_api/Cargo.toml | 1 + crates/proc_macro_api/src/msg.rs | 9 +++++++- crates/proc_macro_api/src/process.rs | 7 +++--- 4 files changed, 46 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 9ddbeac477d..d724d8962a1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1182,6 +1182,7 @@ dependencies = [ "log", "serde", "serde_json", + "serde_stacker", "tt", ] @@ -1239,6 +1240,15 @@ dependencies = [ "toolchain", ] +[[package]] +name = "psm" +version = "0.1.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3abf49e5417290756acfd26501536358560c4a5cc4a0934d390939acb3e7083a" +dependencies = [ + "cc", +] + [[package]] name = "pulldown-cmark" version = "0.8.0" @@ -1557,6 +1567,16 @@ dependencies = [ "syn", ] +[[package]] +name = "serde_stacker" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f4c92391a63e3b83f77334d8beaaf11bac4c900f3769483e543bf76a81bf8ee2" +dependencies = [ + "serde", + "stacker", +] + [[package]] name = "sharded-slab" version = "0.1.0" @@ -1602,6 +1622,19 @@ dependencies = [ "text_edit", ] +[[package]] +name = "stacker" +version = "0.1.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "21ccb4c06ec57bc82d0f610f1a2963d7648700e43a6f513e564b9c89f7991786" +dependencies = [ + "cc", + "cfg-if 0.1.10", + "libc", + "psm", + "winapi 0.3.9", +] + [[package]] name = "stdx" version = "0.0.0" diff --git a/crates/proc_macro_api/Cargo.toml b/crates/proc_macro_api/Cargo.toml index 1af2bbca782..a8e128d5571 100644 --- a/crates/proc_macro_api/Cargo.toml +++ b/crates/proc_macro_api/Cargo.toml @@ -12,6 +12,7 @@ doctest = false [dependencies] serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" +serde_stacker = "0.1" log = "0.4.8" crossbeam-channel = "0.5.0" jod-thread = "0.1.1" diff --git a/crates/proc_macro_api/src/msg.rs b/crates/proc_macro_api/src/msg.rs index f84ebdbc574..43d13a764c1 100644 --- a/crates/proc_macro_api/src/msg.rs +++ b/crates/proc_macro_api/src/msg.rs @@ -58,7 +58,14 @@ pub trait Message: Serialize + DeserializeOwned { fn read(inp: &mut impl BufRead) -> io::Result> { Ok(match read_json(inp)? { None => None, - Some(text) => Some(serde_json::from_str(&text)?), + Some(text) => { + let mut deserializer = serde_json::Deserializer::from_str(&text); + // Note that some proc-macro generate very deep syntax tree + // We have to disable the current limit of serde here + deserializer.disable_recursion_limit(); + let deserializer = serde_stacker::Deserializer::new(&mut deserializer); + Some(Self::deserialize(deserializer)?) + } }) } fn write(self, out: &mut impl Write) -> io::Result<()> { diff --git a/crates/proc_macro_api/src/process.rs b/crates/proc_macro_api/src/process.rs index d68723ada36..6d6ab888868 100644 --- a/crates/proc_macro_api/src/process.rs +++ b/crates/proc_macro_api/src/process.rs @@ -92,10 +92,11 @@ fn client_loop(task_rx: Receiver, mut process: Process) { for Task { req, result_tx } in task_rx { match send_request(&mut stdin, &mut stdout, req) { Ok(res) => result_tx.send(res).unwrap(), - Err(_err) => { + Err(err) => { log::error!( - "proc macro server crashed, server process state: {:?}", - process.child.try_wait() + "proc macro server crashed, server process state: {:?}, server request error: {:?}", + process.child.try_wait(), + err ); let res = Response::Error(ResponseError { code: ErrorCode::ServerErrorEnd,