mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-11-10 07:04:22 +00:00
internal: improve compilation critical path a bit
This commit is contained in:
parent
0dabcf0044
commit
c639fe333f
7 changed files with 12 additions and 34 deletions
3
Cargo.lock
generated
3
Cargo.lock
generated
|
@ -1062,9 +1062,6 @@ checksum = "acbf547ad0c65e31259204bd90935776d1c693cec2f4ff7abb7a1bbbd40dfe58"
|
|||
[[package]]
|
||||
name = "paths"
|
||||
version = "0.0.0"
|
||||
dependencies = [
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "percent-encoding"
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -66,27 +66,6 @@ impl PartialEq<AbsPath> for AbsPathBuf {
|
|||
}
|
||||
}
|
||||
|
||||
impl serde::Serialize for AbsPathBuf {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: serde::Serializer,
|
||||
{
|
||||
self.0.serialize(serializer)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'de> serde::Deserialize<'de> for AbsPathBuf {
|
||||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
||||
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`
|
||||
///
|
||||
|
|
|
@ -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,
|
||||
};
|
||||
|
||||
|
|
|
@ -39,7 +39,7 @@ impl ProcMacroProcessSrv {
|
|||
&mut self,
|
||||
dylib_path: &AbsPath,
|
||||
) -> Result<Vec<(String, ProcMacroKind)>, 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)
|
||||
|
|
|
@ -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<FlatTree>,
|
||||
|
||||
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(),
|
||||
};
|
||||
|
||||
|
|
|
@ -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<String> {
|
||||
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()
|
||||
|
|
Loading…
Reference in a new issue