Unnamed repository; edit this file 'description' to name the repository.
Simplify
Lukas Wirth 2024-06-30
parent 9d09bc0 · commit 7c7c0cb
-rw-r--r--Cargo.lock1
-rw-r--r--crates/proc-macro-api/Cargo.toml1
-rw-r--r--crates/proc-macro-api/src/lib.rs10
-rw-r--r--crates/proc-macro-api/src/msg/flat.rs6
-rw-r--r--crates/proc-macro-api/src/process.rs10
-rw-r--r--crates/proc-macro-srv-cli/src/main.rs6
-rw-r--r--crates/rust-analyzer/src/reload.rs2
7 files changed, 17 insertions, 19 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 790bccea19..56deb1b7a1 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -1337,7 +1337,6 @@ dependencies = [
"stdx",
"text-size",
"tracing",
- "triomphe",
"tt",
]
diff --git a/crates/proc-macro-api/Cargo.toml b/crates/proc-macro-api/Cargo.toml
index 11fd076a6f..7f633d91ec 100644
--- a/crates/proc-macro-api/Cargo.toml
+++ b/crates/proc-macro-api/Cargo.toml
@@ -15,7 +15,6 @@ doctest = false
serde.workspace = true
serde_json = { workspace = true, features = ["unbounded_depth"] }
tracing.workspace = true
-triomphe.workspace = true
rustc-hash.workspace = true
indexmap.workspace = true
diff --git a/crates/proc-macro-api/src/lib.rs b/crates/proc-macro-api/src/lib.rs
index 9ba6a09cb7..f21411bc81 100644
--- a/crates/proc-macro-api/src/lib.rs
+++ b/crates/proc-macro-api/src/lib.rs
@@ -9,9 +9,7 @@ pub mod msg;
mod process;
use base_db::Env;
-use indexmap::IndexSet;
use paths::{AbsPath, AbsPathBuf};
-use rustc_hash::FxHashMap;
use span::Span;
use std::{fmt, io, sync::Arc};
use tt::SmolStr;
@@ -21,7 +19,8 @@ use serde::{Deserialize, Serialize};
use crate::{
msg::{
deserialize_span_data_index_map, flat::serialize_span_data_index_map, ExpandMacro,
- ExpnGlobals, FlatTree, PanicMessage, HAS_GLOBAL_SPANS, RUST_ANALYZER_SPAN_SUPPORT,
+ ExpnGlobals, FlatTree, PanicMessage, SpanDataIndexMap, HAS_GLOBAL_SPANS,
+ RUST_ANALYZER_SPAN_SUPPORT,
},
process::ProcMacroProcessSrv,
};
@@ -101,7 +100,8 @@ impl ProcMacroServer {
/// Spawns an external process as the proc macro server and returns a client connected to it.
pub fn spawn(
process_path: &AbsPath,
- env: &FxHashMap<String, String>,
+ env: impl IntoIterator<Item = (impl AsRef<std::ffi::OsStr>, impl AsRef<std::ffi::OsStr>)>
+ + Clone,
) -> io::Result<ProcMacroServer> {
let process = ProcMacroProcessSrv::run(process_path, env)?;
Ok(ProcMacroServer { process: Arc::new(process), path: process_path.to_owned() })
@@ -151,7 +151,7 @@ impl ProcMacro {
let version = self.process.version();
let current_dir = env.get("CARGO_MANIFEST_DIR");
- let mut span_data_table = IndexSet::default();
+ let mut span_data_table = SpanDataIndexMap::default();
let def_site = span_data_table.insert_full(def_site).0;
let call_site = span_data_table.insert_full(call_site).0;
let mixed_site = span_data_table.insert_full(mixed_site).0;
diff --git a/crates/proc-macro-api/src/msg/flat.rs b/crates/proc-macro-api/src/msg/flat.rs
index 99cdbd930e..11fd7596f2 100644
--- a/crates/proc-macro-api/src/msg/flat.rs
+++ b/crates/proc-macro-api/src/msg/flat.rs
@@ -37,7 +37,6 @@
use std::collections::VecDeque;
-use indexmap::IndexSet;
use la_arena::RawIdx;
use rustc_hash::FxHashMap;
use serde::{Deserialize, Serialize};
@@ -46,7 +45,8 @@ use text_size::TextRange;
use crate::msg::ENCODE_CLOSE_SPAN_VERSION;
-pub type SpanDataIndexMap = IndexSet<Span>;
+pub type SpanDataIndexMap =
+ indexmap::IndexSet<Span, std::hash::BuildHasherDefault<rustc_hash::FxHasher>>;
pub fn serialize_span_data_index_map(map: &SpanDataIndexMap) -> Vec<u32> {
map.iter()
@@ -328,7 +328,7 @@ impl InternableSpan for TokenId {
}
}
impl InternableSpan for Span {
- type Table = IndexSet<Span>;
+ type Table = SpanDataIndexMap;
fn token_id_of(table: &mut Self::Table, span: Self) -> TokenId {
TokenId(table.insert_full(span).0 as u32)
}
diff --git a/crates/proc-macro-api/src/process.rs b/crates/proc-macro-api/src/process.rs
index 1c37082bb2..3a1a4cfa13 100644
--- a/crates/proc-macro-api/src/process.rs
+++ b/crates/proc-macro-api/src/process.rs
@@ -7,7 +7,6 @@ use std::{
};
use paths::AbsPath;
-use rustc_hash::FxHashMap;
use stdx::JodChild;
use crate::{
@@ -36,10 +35,11 @@ struct ProcessSrvState {
impl ProcMacroProcessSrv {
pub(crate) fn run(
process_path: &AbsPath,
- env: &FxHashMap<String, String>,
+ env: impl IntoIterator<Item = (impl AsRef<std::ffi::OsStr>, impl AsRef<std::ffi::OsStr>)>
+ + Clone,
) -> io::Result<ProcMacroProcessSrv> {
let create_srv = |null_stderr| {
- let mut process = Process::run(process_path, env, null_stderr)?;
+ let mut process = Process::run(process_path, env.clone(), null_stderr)?;
let (stdin, stdout) = process.stdio().expect("couldn't access child stdio");
io::Result::Ok(ProcMacroProcessSrv {
@@ -158,7 +158,7 @@ struct Process {
impl Process {
fn run(
path: &AbsPath,
- env: &FxHashMap<String, String>,
+ env: impl IntoIterator<Item = (impl AsRef<std::ffi::OsStr>, impl AsRef<std::ffi::OsStr>)>,
null_stderr: bool,
) -> io::Result<Process> {
let child = JodChild(mk_child(path, env, null_stderr)?);
@@ -176,7 +176,7 @@ impl Process {
fn mk_child(
path: &AbsPath,
- env: &FxHashMap<String, String>,
+ env: impl IntoIterator<Item = (impl AsRef<std::ffi::OsStr>, impl AsRef<std::ffi::OsStr>)>,
null_stderr: bool,
) -> io::Result<Child> {
let mut cmd = Command::new(path);
diff --git a/crates/proc-macro-srv-cli/src/main.rs b/crates/proc-macro-srv-cli/src/main.rs
index f6f6fdc864..407c1969cb 100644
--- a/crates/proc-macro-srv-cli/src/main.rs
+++ b/crates/proc-macro-srv-cli/src/main.rs
@@ -8,8 +8,6 @@ extern crate rustc_driver as _;
use std::io;
-use proc_macro_api::msg::ServerConfig;
-
fn main() -> std::io::Result<()> {
let v = std::env::var("RUST_ANALYZER_INTERNALS_DO_NOT_USE");
match v.as_deref() {
@@ -48,7 +46,9 @@ fn run() -> io::Result<()> {
msg::Response::ApiVersionCheck(proc_macro_api::msg::CURRENT_API_VERSION)
}
msg::Request::SetConfig(_) => {
- msg::Response::SetConfig(ServerConfig { span_mode: msg::SpanMode::Id })
+ msg::Response::SetConfig(proc_macro_api::msg::ServerConfig {
+ span_mode: msg::SpanMode::Id,
+ })
}
};
write_response(res)?
diff --git a/crates/rust-analyzer/src/reload.rs b/crates/rust-analyzer/src/reload.rs
index bd0f733ef3..7b9a10fdb8 100644
--- a/crates/rust-analyzer/src/reload.rs
+++ b/crates/rust-analyzer/src/reload.rs
@@ -529,7 +529,7 @@ impl GlobalState {
None => ws.find_sysroot_proc_macro_srv()?,
};
- let env = match &ws.kind {
+ let env: FxHashMap<_, _> = match &ws.kind {
ProjectWorkspaceKind::Cargo { cargo_config_extra_env, .. }
| ProjectWorkspaceKind::DetachedFile {
cargo: Some(_),