about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--src/tools/rust-analyzer/Cargo.lock2
-rw-r--r--src/tools/rust-analyzer/crates/load-cargo/src/lib.rs2
-rw-r--r--src/tools/rust-analyzer/crates/proc-macro-api/Cargo.toml8
-rw-r--r--src/tools/rust-analyzer/crates/proc-macro-api/src/lib.rs5
-rw-r--r--src/tools/rust-analyzer/crates/proc-macro-srv/Cargo.toml4
-rw-r--r--src/tools/rust-analyzer/crates/span/Cargo.toml5
-rw-r--r--src/tools/rust-analyzer/crates/span/src/hygiene.rs5
-rw-r--r--src/tools/rust-analyzer/crates/span/src/lib.rs69
-rw-r--r--src/tools/rust-analyzer/crates/syntax-bridge/Cargo.toml3
9 files changed, 88 insertions, 15 deletions
diff --git a/src/tools/rust-analyzer/Cargo.lock b/src/tools/rust-analyzer/Cargo.lock
index ab6580a97a7..2628c9a9d16 100644
--- a/src/tools/rust-analyzer/Cargo.lock
+++ b/src/tools/rust-analyzer/Cargo.lock
@@ -1352,7 +1352,6 @@ dependencies = [
 name = "proc-macro-api"
 version = "0.0.0"
 dependencies = [
- "base-db",
  "indexmap",
  "intern",
  "paths",
@@ -1369,7 +1368,6 @@ dependencies = [
 name = "proc-macro-srv"
 version = "0.0.0"
 dependencies = [
- "base-db",
  "expect-test",
  "intern",
  "libloading",
diff --git a/src/tools/rust-analyzer/crates/load-cargo/src/lib.rs b/src/tools/rust-analyzer/crates/load-cargo/src/lib.rs
index aa64f570ed5..1b2162dad0f 100644
--- a/src/tools/rust-analyzer/crates/load-cargo/src/lib.rs
+++ b/src/tools/rust-analyzer/crates/load-cargo/src/lib.rs
@@ -487,7 +487,7 @@ impl ProcMacroExpander for Expander {
         match self.0.expand(
             subtree,
             attrs,
-            env.clone(),
+            env.clone().into(),
             def_site,
             call_site,
             mixed_site,
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 84b877f026b..911301e22b4 100644
--- a/src/tools/rust-analyzer/crates/proc-macro-api/Cargo.toml
+++ b/src/tools/rust-analyzer/crates/proc-macro-api/Cargo.toml
@@ -23,11 +23,9 @@ indexmap.workspace = true
 paths = { workspace = true, features = ["serde1"] }
 tt.workspace = true
 stdx.workspace = true
-# Ideally this crate would not depend on salsa things, but we need span information here which wraps
-# InternIds for the syntax context
-span.workspace = true
-# only here due to the `Env` newtype :/
-base-db.workspace = true
+# span = {workspace = true, default-features = false} does not work
+span = { path = "../span", version = "0.0.0", default-features = false}
+
 intern.workspace = true
 
 [lints]
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 011baad65f7..e54d501b94c 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,7 +9,6 @@ pub mod json;
 pub mod msg;
 mod process;
 
-use base_db::Env;
 use paths::{AbsPath, AbsPathBuf};
 use span::Span;
 use std::{fmt, io, sync::Arc};
@@ -148,7 +147,7 @@ impl ProcMacro {
         &self,
         subtree: &tt::Subtree<Span>,
         attr: Option<&tt::Subtree<Span>>,
-        env: Env,
+        env: Vec<(String, String)>,
         def_site: Span,
         call_site: Span,
         mixed_site: Span,
@@ -179,7 +178,7 @@ impl ProcMacro {
                 },
             },
             lib: self.dylib_path.to_path_buf().into(),
-            env: env.into(),
+            env,
             current_dir,
         };
 
diff --git a/src/tools/rust-analyzer/crates/proc-macro-srv/Cargo.toml b/src/tools/rust-analyzer/crates/proc-macro-srv/Cargo.toml
index 4fabcc90067..98385969459 100644
--- a/src/tools/rust-analyzer/crates/proc-macro-srv/Cargo.toml
+++ b/src/tools/rust-analyzer/crates/proc-macro-srv/Cargo.toml
@@ -21,8 +21,8 @@ stdx.workspace = true
 tt.workspace = true
 syntax-bridge.workspace = true
 paths.workspace = true
-base-db.workspace = true
-span.workspace = true
+# span = {workspace = true, default-features = false} does not work
+span = { path = "../span", version = "0.0.0", default-features = false}
 proc-macro-api.workspace = true
 intern.workspace = true
 
diff --git a/src/tools/rust-analyzer/crates/span/Cargo.toml b/src/tools/rust-analyzer/crates/span/Cargo.toml
index 569da8082a8..097a056c99a 100644
--- a/src/tools/rust-analyzer/crates/span/Cargo.toml
+++ b/src/tools/rust-analyzer/crates/span/Cargo.toml
@@ -12,7 +12,7 @@ authors.workspace = true
 
 [dependencies]
 la-arena.workspace = true
-ra-salsa.workspace = true
+ra-salsa = { workspace = true, optional = true }
 rustc-hash.workspace = true
 hashbrown.workspace = true
 text-size.workspace = true
@@ -22,5 +22,8 @@ vfs.workspace = true
 syntax.workspace = true
 stdx.workspace = true
 
+[features]
+default = ["ra-salsa"]
+
 [lints]
 workspace = true
diff --git a/src/tools/rust-analyzer/crates/span/src/hygiene.rs b/src/tools/rust-analyzer/crates/span/src/hygiene.rs
index 67d7bb9a0de..87a948df550 100644
--- a/src/tools/rust-analyzer/crates/span/src/hygiene.rs
+++ b/src/tools/rust-analyzer/crates/span/src/hygiene.rs
@@ -21,6 +21,9 @@
 //! `ExpnData::call_site` in rustc, [`MacroCallLoc::call_site`] in rust-analyzer.
 use std::fmt;
 
+#[cfg(not(feature = "ra-salsa"))]
+use crate::InternId;
+#[cfg(feature = "ra-salsa")]
 use ra_salsa::{InternId, InternValue};
 
 use crate::MacroCallId;
@@ -39,6 +42,7 @@ impl fmt::Debug for SyntaxContextId {
     }
 }
 
+#[cfg(feature = "ra-salsa")]
 impl ra_salsa::InternKey for SyntaxContextId {
     fn from_intern_id(v: ra_salsa::InternId) -> Self {
         SyntaxContextId(v)
@@ -92,6 +96,7 @@ pub struct SyntaxContextData {
     pub opaque_and_semitransparent: SyntaxContextId,
 }
 
+#[cfg(feature = "ra-salsa")]
 impl InternValue for SyntaxContextData {
     type Key = (SyntaxContextId, Option<MacroCallId>, Transparency);
 
diff --git a/src/tools/rust-analyzer/crates/span/src/lib.rs b/src/tools/rust-analyzer/crates/span/src/lib.rs
index bd270bfe2b1..e12575b9b15 100644
--- a/src/tools/rust-analyzer/crates/span/src/lib.rs
+++ b/src/tools/rust-analyzer/crates/span/src/lib.rs
@@ -1,6 +1,7 @@
 //! File and span related types.
 use std::fmt::{self, Write};
 
+#[cfg(feature = "ra-salsa")]
 use ra_salsa::InternId;
 
 mod ast_id;
@@ -355,3 +356,71 @@ impl HirFileId {
         }
     }
 }
+
+#[cfg(not(feature = "ra-salsa"))]
+mod intern_id_proxy {
+    use std::fmt;
+    use std::num::NonZeroU32;
+
+    pub(super) struct InternId {
+        value: NonZeroU32,
+    }
+
+    impl InternId {
+        pub(super) const MAX: u32 = 0xFFFF_FF00;
+
+        pub(super) const unsafe fn new_unchecked(value: u32) -> Self {
+            debug_assert!(value < InternId::MAX);
+            let value = unsafe { NonZeroU32::new_unchecked(value + 1) };
+            InternId { value }
+        }
+
+        pub(super) fn as_u32(self) -> u32 {
+            self.value.get() - 1
+        }
+
+        pub(super) fn as_usize(self) -> usize {
+            self.as_u32() as usize
+        }
+    }
+
+    impl From<InternId> for u32 {
+        fn from(raw: InternId) -> u32 {
+            raw.as_u32()
+        }
+    }
+
+    impl From<InternId> for usize {
+        fn from(raw: InternId) -> usize {
+            raw.as_usize()
+        }
+    }
+
+    impl From<u32> for InternId {
+        fn from(id: u32) -> InternId {
+            assert!(id < InternId::MAX);
+            unsafe { InternId::new_unchecked(id) }
+        }
+    }
+
+    impl From<usize> for InternId {
+        fn from(id: usize) -> InternId {
+            assert!(id < (InternId::MAX as usize));
+            unsafe { InternId::new_unchecked(id as u32) }
+        }
+    }
+
+    impl fmt::Debug for InternId {
+        fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+            self.as_usize().fmt(f)
+        }
+    }
+
+    impl fmt::Display for InternId {
+        fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+            self.as_usize().fmt(f)
+        }
+    }
+}
+#[cfg(not(feature = "ra-salsa"))]
+use intern_id_proxy::InternId;
diff --git a/src/tools/rust-analyzer/crates/syntax-bridge/Cargo.toml b/src/tools/rust-analyzer/crates/syntax-bridge/Cargo.toml
index e995ff3b55b..f9a9f40541d 100644
--- a/src/tools/rust-analyzer/crates/syntax-bridge/Cargo.toml
+++ b/src/tools/rust-analyzer/crates/syntax-bridge/Cargo.toml
@@ -21,7 +21,8 @@ syntax.workspace = true
 parser.workspace = true
 tt.workspace = true
 stdx.workspace = true
-span.workspace = true
+# span = {workspace = true, default-features = false} does not work
+span = { path = "../span", version = "0.0.0", default-features = false}
 intern.workspace = true
 
 [dev-dependencies]