about summary refs log tree commit diff
diff options
context:
space:
mode:
authorLukas Wirth <lukastw97@gmail.com>2024-06-30 16:41:52 +0200
committerLukas Wirth <lukastw97@gmail.com>2024-06-30 16:43:22 +0200
commitb1518b262e177b23362a72adf5d3e3ba23cf44fe (patch)
tree8ad79bf9686b77c8da532df4920a5233a9e5f8a7
parent58286ccbd1760d83c7e2e47a7dfe6604219d29d0 (diff)
downloadrust-b1518b262e177b23362a72adf5d3e3ba23cf44fe.tar.gz
rust-b1518b262e177b23362a72adf5d3e3ba23cf44fe.zip
Simplify
-rw-r--r--src/tools/rust-analyzer/Cargo.lock1
-rw-r--r--src/tools/rust-analyzer/crates/proc-macro-api/Cargo.toml1
-rw-r--r--src/tools/rust-analyzer/crates/proc-macro-api/src/lib.rs10
-rw-r--r--src/tools/rust-analyzer/crates/proc-macro-api/src/msg/flat.rs6
-rw-r--r--src/tools/rust-analyzer/crates/proc-macro-api/src/process.rs10
-rw-r--r--src/tools/rust-analyzer/crates/proc-macro-srv-cli/src/main.rs6
-rw-r--r--src/tools/rust-analyzer/crates/rust-analyzer/src/reload.rs2
7 files changed, 17 insertions, 19 deletions
diff --git a/src/tools/rust-analyzer/Cargo.lock b/src/tools/rust-analyzer/Cargo.lock
index 790bccea196..56deb1b7a19 100644
--- a/src/tools/rust-analyzer/Cargo.lock
+++ b/src/tools/rust-analyzer/Cargo.lock
@@ -1337,7 +1337,6 @@ dependencies = [
  "stdx",
  "text-size",
  "tracing",
- "triomphe",
  "tt",
 ]
 
diff --git a/src/tools/rust-analyzer/crates/proc-macro-api/Cargo.toml b/src/tools/rust-analyzer/crates/proc-macro-api/Cargo.toml
index 11fd076a6f6..7f633d91ecc 100644
--- a/src/tools/rust-analyzer/crates/proc-macro-api/Cargo.toml
+++ b/src/tools/rust-analyzer/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/src/tools/rust-analyzer/crates/proc-macro-api/src/lib.rs b/src/tools/rust-analyzer/crates/proc-macro-api/src/lib.rs
index 9ba6a09cb73..f21411bc814 100644
--- a/src/tools/rust-analyzer/crates/proc-macro-api/src/lib.rs
+++ b/src/tools/rust-analyzer/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/src/tools/rust-analyzer/crates/proc-macro-api/src/msg/flat.rs b/src/tools/rust-analyzer/crates/proc-macro-api/src/msg/flat.rs
index 99cdbd930e1..11fd7596f2b 100644
--- a/src/tools/rust-analyzer/crates/proc-macro-api/src/msg/flat.rs
+++ b/src/tools/rust-analyzer/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/src/tools/rust-analyzer/crates/proc-macro-api/src/process.rs b/src/tools/rust-analyzer/crates/proc-macro-api/src/process.rs
index 1c37082bb29..3a1a4cfa131 100644
--- a/src/tools/rust-analyzer/crates/proc-macro-api/src/process.rs
+++ b/src/tools/rust-analyzer/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/src/tools/rust-analyzer/crates/proc-macro-srv-cli/src/main.rs b/src/tools/rust-analyzer/crates/proc-macro-srv-cli/src/main.rs
index f6f6fdc864b..407c1969cbd 100644
--- a/src/tools/rust-analyzer/crates/proc-macro-srv-cli/src/main.rs
+++ b/src/tools/rust-analyzer/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/src/tools/rust-analyzer/crates/rust-analyzer/src/reload.rs b/src/tools/rust-analyzer/crates/rust-analyzer/src/reload.rs
index bd0f733ef39..7b9a10fdb8c 100644
--- a/src/tools/rust-analyzer/crates/rust-analyzer/src/reload.rs
+++ b/src/tools/rust-analyzer/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(_),