diff options
author | Edwin Cheng <[email protected]> | 2021-01-01 07:09:27 +0000 |
---|---|---|
committer | Edwin Cheng <[email protected]> | 2021-01-01 07:09:27 +0000 |
commit | a65025604da0a3f43b668c60a4a2f97a70b71363 (patch) | |
tree | 4c6af6d0b9ab4fa148b05c70e8f15aa9699ab229 | |
parent | a9814fa9c037b0fafd30580a6e7682ed032d77e6 (diff) |
Fix deep syntax tree bug generated by proc-macro
-rw-r--r-- | Cargo.lock | 33 | ||||
-rw-r--r-- | crates/proc_macro_api/Cargo.toml | 1 | ||||
-rw-r--r-- | crates/proc_macro_api/src/msg.rs | 9 | ||||
-rw-r--r-- | crates/proc_macro_api/src/process.rs | 7 |
4 files changed, 46 insertions, 4 deletions
diff --git a/Cargo.lock b/Cargo.lock index 9ddbeac47..d724d8962 100644 --- a/Cargo.lock +++ b/Cargo.lock | |||
@@ -1182,6 +1182,7 @@ dependencies = [ | |||
1182 | "log", | 1182 | "log", |
1183 | "serde", | 1183 | "serde", |
1184 | "serde_json", | 1184 | "serde_json", |
1185 | "serde_stacker", | ||
1185 | "tt", | 1186 | "tt", |
1186 | ] | 1187 | ] |
1187 | 1188 | ||
@@ -1240,6 +1241,15 @@ dependencies = [ | |||
1240 | ] | 1241 | ] |
1241 | 1242 | ||
1242 | [[package]] | 1243 | [[package]] |
1244 | name = "psm" | ||
1245 | version = "0.1.12" | ||
1246 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
1247 | checksum = "3abf49e5417290756acfd26501536358560c4a5cc4a0934d390939acb3e7083a" | ||
1248 | dependencies = [ | ||
1249 | "cc", | ||
1250 | ] | ||
1251 | |||
1252 | [[package]] | ||
1243 | name = "pulldown-cmark" | 1253 | name = "pulldown-cmark" |
1244 | version = "0.8.0" | 1254 | version = "0.8.0" |
1245 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1255 | source = "registry+https://github.com/rust-lang/crates.io-index" |
@@ -1558,6 +1568,16 @@ dependencies = [ | |||
1558 | ] | 1568 | ] |
1559 | 1569 | ||
1560 | [[package]] | 1570 | [[package]] |
1571 | name = "serde_stacker" | ||
1572 | version = "0.1.4" | ||
1573 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
1574 | checksum = "f4c92391a63e3b83f77334d8beaaf11bac4c900f3769483e543bf76a81bf8ee2" | ||
1575 | dependencies = [ | ||
1576 | "serde", | ||
1577 | "stacker", | ||
1578 | ] | ||
1579 | |||
1580 | [[package]] | ||
1561 | name = "sharded-slab" | 1581 | name = "sharded-slab" |
1562 | version = "0.1.0" | 1582 | version = "0.1.0" |
1563 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1583 | source = "registry+https://github.com/rust-lang/crates.io-index" |
@@ -1603,6 +1623,19 @@ dependencies = [ | |||
1603 | ] | 1623 | ] |
1604 | 1624 | ||
1605 | [[package]] | 1625 | [[package]] |
1626 | name = "stacker" | ||
1627 | version = "0.1.12" | ||
1628 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
1629 | checksum = "21ccb4c06ec57bc82d0f610f1a2963d7648700e43a6f513e564b9c89f7991786" | ||
1630 | dependencies = [ | ||
1631 | "cc", | ||
1632 | "cfg-if 0.1.10", | ||
1633 | "libc", | ||
1634 | "psm", | ||
1635 | "winapi 0.3.9", | ||
1636 | ] | ||
1637 | |||
1638 | [[package]] | ||
1606 | name = "stdx" | 1639 | name = "stdx" |
1607 | version = "0.0.0" | 1640 | version = "0.0.0" |
1608 | 1641 | ||
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 | |||
12 | [dependencies] | 12 | [dependencies] |
13 | serde = { version = "1.0", features = ["derive"] } | 13 | serde = { version = "1.0", features = ["derive"] } |
14 | serde_json = "1.0" | 14 | serde_json = "1.0" |
15 | serde_stacker = "0.1" | ||
15 | log = "0.4.8" | 16 | log = "0.4.8" |
16 | crossbeam-channel = "0.5.0" | 17 | crossbeam-channel = "0.5.0" |
17 | jod-thread = "0.1.1" | 18 | 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 { | |||
58 | fn read(inp: &mut impl BufRead) -> io::Result<Option<Self>> { | 58 | fn read(inp: &mut impl BufRead) -> io::Result<Option<Self>> { |
59 | Ok(match read_json(inp)? { | 59 | Ok(match read_json(inp)? { |
60 | None => None, | 60 | None => None, |
61 | Some(text) => Some(serde_json::from_str(&text)?), | 61 | Some(text) => { |
62 | let mut deserializer = serde_json::Deserializer::from_str(&text); | ||
63 | // Note that some proc-macro generate very deep syntax tree | ||
64 | // We have to disable the current limit of serde here | ||
65 | deserializer.disable_recursion_limit(); | ||
66 | let deserializer = serde_stacker::Deserializer::new(&mut deserializer); | ||
67 | Some(Self::deserialize(deserializer)?) | ||
68 | } | ||
62 | }) | 69 | }) |
63 | } | 70 | } |
64 | fn write(self, out: &mut impl Write) -> io::Result<()> { | 71 | 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<Task>, mut process: Process) { | |||
92 | for Task { req, result_tx } in task_rx { | 92 | for Task { req, result_tx } in task_rx { |
93 | match send_request(&mut stdin, &mut stdout, req) { | 93 | match send_request(&mut stdin, &mut stdout, req) { |
94 | Ok(res) => result_tx.send(res).unwrap(), | 94 | Ok(res) => result_tx.send(res).unwrap(), |
95 | Err(_err) => { | 95 | Err(err) => { |
96 | log::error!( | 96 | log::error!( |
97 | "proc macro server crashed, server process state: {:?}", | 97 | "proc macro server crashed, server process state: {:?}, server request error: {:?}", |
98 | process.child.try_wait() | 98 | process.child.try_wait(), |
99 | err | ||
99 | ); | 100 | ); |
100 | let res = Response::Error(ResponseError { | 101 | let res = Response::Error(ResponseError { |
101 | code: ErrorCode::ServerErrorEnd, | 102 | code: ErrorCode::ServerErrorEnd, |