From a65025604da0a3f43b668c60a4a2f97a70b71363 Mon Sep 17 00:00:00 2001 From: Edwin Cheng Date: Fri, 1 Jan 2021 15:09:27 +0800 Subject: Fix deep syntax tree bug generated by proc-macro --- crates/proc_macro_api/Cargo.toml | 1 + crates/proc_macro_api/src/msg.rs | 9 ++++++++- crates/proc_macro_api/src/process.rs | 7 ++++--- 3 files changed, 13 insertions(+), 4 deletions(-) (limited to 'crates') diff --git a/crates/proc_macro_api/Cargo.toml b/crates/proc_macro_api/Cargo.toml index 1af2bbca7..a8e128d55 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 f84ebdbc5..43d13a764 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 d68723ada..6d6ab8888 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, -- cgit v1.2.3 From ae92baba6a3f70a5234dc4fcf15660c2c01deeee Mon Sep 17 00:00:00 2001 From: Edwin Cheng Date: Fri, 1 Jan 2021 15:26:55 +0800 Subject: Remove serde_stacker which depends on cc --- crates/proc_macro_api/Cargo.toml | 1 - crates/proc_macro_api/src/msg.rs | 3 +-- 2 files changed, 1 insertion(+), 3 deletions(-) (limited to 'crates') diff --git a/crates/proc_macro_api/Cargo.toml b/crates/proc_macro_api/Cargo.toml index a8e128d55..1af2bbca7 100644 --- a/crates/proc_macro_api/Cargo.toml +++ b/crates/proc_macro_api/Cargo.toml @@ -12,7 +12,6 @@ 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 43d13a764..4cd572101 100644 --- a/crates/proc_macro_api/src/msg.rs +++ b/crates/proc_macro_api/src/msg.rs @@ -63,8 +63,7 @@ pub trait Message: Serialize + DeserializeOwned { // 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)?) + Some(Self::deserialize(&mut deserializer)?) } }) } -- cgit v1.2.3