Skip to content

Commit 10e9408

Browse files
bors[bot]matklad
andauthored
Merge #10066
10066: internal: improve compile times a bit r=matklad a=matklad I wanted to *quickly* remove `smol_str = {features = "serde"}`, and figured out that the simplest way to do that is to replace our straightforward proc macro serialization with something significantly more obscure. Co-authored-by: Aleksey Kladov <[email protected]>
2 parents 2e3322d + 0d5c671 commit 10e9408

File tree

13 files changed

+379
-257
lines changed

13 files changed

+379
-257
lines changed

Cargo.lock

Lines changed: 0 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/paths/Cargo.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,7 @@ edition = "2018"
99
doctest = false
1010

1111
[dependencies]
12-
serde = "1"
12+
# Adding this dep sadly puts a lot of rust-analyzer crates after the
13+
# serde-derive crate. Even though we don't activate the derive feature here,
14+
# someone else in the crate graph certainly does!
15+
# serde = "1"

crates/paths/src/lib.rs

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -66,27 +66,6 @@ impl PartialEq<AbsPath> for AbsPathBuf {
6666
}
6767
}
6868

69-
impl serde::Serialize for AbsPathBuf {
70-
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
71-
where
72-
S: serde::Serializer,
73-
{
74-
self.0.serialize(serializer)
75-
}
76-
}
77-
78-
impl<'de> serde::Deserialize<'de> for AbsPathBuf {
79-
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
80-
where
81-
D: serde::Deserializer<'de>,
82-
{
83-
let path = PathBuf::deserialize(deserializer)?;
84-
AbsPathBuf::try_from(path).map_err(|path| {
85-
serde::de::Error::custom(format!("expected absolute path, got {}", path.display()))
86-
})
87-
}
88-
}
89-
9069
impl AbsPathBuf {
9170
/// Wrap the given absolute path in `AbsPathBuf`
9271
///

crates/proc_macro_api/src/lib.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ use tt::{SmolStr, Subtree};
2121

2222
use crate::process::ProcMacroProcessSrv;
2323

24-
pub use rpc::{ExpansionResult, ExpansionTask, ListMacrosResult, ListMacrosTask, ProcMacroKind};
24+
pub use rpc::{
25+
flat::FlatTree, ExpansionResult, ExpansionTask, ListMacrosResult, ListMacrosTask, ProcMacroKind,
26+
};
2527
pub use version::{read_dylib_info, RustCInfo};
2628

2729
#[derive(Debug, Clone)]
@@ -58,10 +60,10 @@ impl ProcMacroProcessExpander {
5860
env: Vec<(String, String)>,
5961
) -> Result<Subtree, tt::ExpansionError> {
6062
let task = ExpansionTask {
61-
macro_body: subtree.clone(),
63+
macro_body: FlatTree::new(subtree),
6264
macro_name: self.name.to_string(),
63-
attributes: attr.cloned(),
64-
lib: self.dylib_path.to_path_buf(),
65+
attributes: attr.map(FlatTree::new),
66+
lib: self.dylib_path.to_path_buf().into(),
6567
env,
6668
};
6769

@@ -70,7 +72,7 @@ impl ProcMacroProcessExpander {
7072
.lock()
7173
.unwrap_or_else(|e| e.into_inner())
7274
.send_task(msg::Request::ExpansionMacro(task))?;
73-
Ok(result.expansion)
75+
Ok(result.expansion.to_subtree())
7476
}
7577
}
7678

crates/proc_macro_api/src/msg.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ use crate::{
1212
ExpansionResult, ExpansionTask,
1313
};
1414

15-
#[derive(Debug, Serialize, Deserialize, Clone)]
15+
#[derive(Debug, Serialize, Deserialize)]
1616
pub enum Request {
1717
ListMacro(ListMacrosTask),
1818
ExpansionMacro(ExpansionTask),
1919
}
2020

21-
#[derive(Debug, Serialize, Deserialize, Clone)]
21+
#[derive(Debug, Serialize, Deserialize)]
2222
pub enum Response {
2323
Error(ResponseError),
2424
ListMacro(ListMacrosResult),

crates/proc_macro_api/src/process.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ impl ProcMacroProcessSrv {
3939
&mut self,
4040
dylib_path: &AbsPath,
4141
) -> Result<Vec<(String, ProcMacroKind)>, tt::ExpansionError> {
42-
let task = ListMacrosTask { lib: dylib_path.to_path_buf() };
42+
let task = ListMacrosTask { lib: dylib_path.to_path_buf().into() };
4343

4444
let result: ListMacrosResult = self.send_task(Request::ListMacro(task))?;
4545
Ok(result.macros)

0 commit comments

Comments
 (0)