From c639fe333f81f23a2a79eb650ef8a7bc0c5f9cd2 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 28 Aug 2021 22:03:06 +0300 Subject: [PATCH] internal: improve compilation critical path a bit --- Cargo.lock | 3 --- crates/paths/Cargo.toml | 5 ++++- crates/paths/src/lib.rs | 21 --------------------- crates/proc_macro_api/src/lib.rs | 2 +- crates/proc_macro_api/src/process.rs | 2 +- crates/proc_macro_api/src/rpc.rs | 9 +++++---- crates/proc_macro_srv/src/tests/utils.rs | 4 +--- 7 files changed, 12 insertions(+), 34 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 72ea4446d48..61e62ee82fe 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1062,9 +1062,6 @@ checksum = "acbf547ad0c65e31259204bd90935776d1c693cec2f4ff7abb7a1bbbd40dfe58" [[package]] name = "paths" version = "0.0.0" -dependencies = [ - "serde", -] [[package]] name = "percent-encoding" diff --git a/crates/paths/Cargo.toml b/crates/paths/Cargo.toml index cf44b7a0d2a..cc062ebb7cb 100644 --- a/crates/paths/Cargo.toml +++ b/crates/paths/Cargo.toml @@ -9,4 +9,7 @@ edition = "2018" doctest = false [dependencies] -serde = "1" +# Adding this dep sadly puts a lot of rust-analyzer crates after the +# serde-derive crate. Even though we don't activate the derive feature here, +# someone else in the crate graph certainly does! +# serde = "1" diff --git a/crates/paths/src/lib.rs b/crates/paths/src/lib.rs index 14747cc72f9..90909f4e8ea 100644 --- a/crates/paths/src/lib.rs +++ b/crates/paths/src/lib.rs @@ -66,27 +66,6 @@ impl PartialEq for AbsPathBuf { } } -impl serde::Serialize for AbsPathBuf { - fn serialize(&self, serializer: S) -> Result - where - S: serde::Serializer, - { - self.0.serialize(serializer) - } -} - -impl<'de> serde::Deserialize<'de> for AbsPathBuf { - fn deserialize(deserializer: D) -> Result - where - D: serde::Deserializer<'de>, - { - let path = PathBuf::deserialize(deserializer)?; - AbsPathBuf::try_from(path).map_err(|path| { - serde::de::Error::custom(format!("expected absolute path, got {}", path.display())) - }) - } -} - impl AbsPathBuf { /// Wrap the given absolute path in `AbsPathBuf` /// diff --git a/crates/proc_macro_api/src/lib.rs b/crates/proc_macro_api/src/lib.rs index 41dfcc541a8..159af94cca3 100644 --- a/crates/proc_macro_api/src/lib.rs +++ b/crates/proc_macro_api/src/lib.rs @@ -63,7 +63,7 @@ impl ProcMacroProcessExpander { macro_body: FlatTree::new(subtree), macro_name: self.name.to_string(), attributes: attr.map(FlatTree::new), - lib: self.dylib_path.to_path_buf(), + lib: self.dylib_path.to_path_buf().into(), env, }; diff --git a/crates/proc_macro_api/src/process.rs b/crates/proc_macro_api/src/process.rs index 466ac962f97..79c749d55ad 100644 --- a/crates/proc_macro_api/src/process.rs +++ b/crates/proc_macro_api/src/process.rs @@ -39,7 +39,7 @@ impl ProcMacroProcessSrv { &mut self, dylib_path: &AbsPath, ) -> Result, tt::ExpansionError> { - let task = ListMacrosTask { lib: dylib_path.to_path_buf() }; + let task = ListMacrosTask { lib: dylib_path.to_path_buf().into() }; let result: ListMacrosResult = self.send_task(Request::ListMacro(task))?; Ok(result.macros) diff --git a/crates/proc_macro_api/src/rpc.rs b/crates/proc_macro_api/src/rpc.rs index 10aa24d00c2..9fdbf045765 100644 --- a/crates/proc_macro_api/src/rpc.rs +++ b/crates/proc_macro_api/src/rpc.rs @@ -7,14 +7,15 @@ //! for separation of code responsibility. pub(crate) mod flat; -use paths::AbsPathBuf; +use std::path::PathBuf; + use serde::{Deserialize, Serialize}; use crate::rpc::flat::FlatTree; #[derive(Clone, Eq, PartialEq, Debug, Serialize, Deserialize)] pub struct ListMacrosTask { - pub lib: AbsPathBuf, + pub lib: PathBuf, } #[derive(Copy, Clone, Eq, PartialEq, Debug, Serialize, Deserialize)] @@ -46,7 +47,7 @@ pub struct ExpansionTask { /// Possible attributes for the attribute-like macros. pub attributes: Option, - pub lib: AbsPathBuf, + pub lib: PathBuf, /// Environment variables to set during macro expansion. pub env: Vec<(String, String)>, @@ -93,7 +94,7 @@ mod tests { macro_body: FlatTree::new(&tt), macro_name: Default::default(), attributes: None, - lib: AbsPathBuf::assert(std::env::current_dir().unwrap()), + lib: std::env::current_dir().unwrap(), env: Default::default(), }; diff --git a/crates/proc_macro_srv/src/tests/utils.rs b/crates/proc_macro_srv/src/tests/utils.rs index d78e14a2dda..e5520174488 100644 --- a/crates/proc_macro_srv/src/tests/utils.rs +++ b/crates/proc_macro_srv/src/tests/utils.rs @@ -3,7 +3,6 @@ use crate::dylib; use crate::ProcMacroSrv; use expect_test::Expect; -use paths::AbsPathBuf; use proc_macro_api::ListMacrosTask; use std::str::FromStr; @@ -42,8 +41,7 @@ fn assert_expand_impl(macro_name: &str, input: &str, attr: Option<&str>, expect: } pub fn list() -> Vec { - let path = AbsPathBuf::assert(fixtures::proc_macro_test_dylib_path()); - let task = ListMacrosTask { lib: path }; + let task = ListMacrosTask { lib: fixtures::proc_macro_test_dylib_path() }; let mut srv = ProcMacroSrv::default(); let res = srv.list_macros(&task).unwrap(); res.macros.into_iter().map(|(name, kind)| format!("{} [{:?}]", name, kind)).collect()