Merge pull request #19457 from Veykril/push-xpmluxlzprpy
chore: Remove salsa dependency from proc-macro server again
diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml
index 8479d00..610f8d0 100644
--- a/.github/workflows/ci.yaml
+++ b/.github/workflows/ci.yaml
@@ -70,6 +70,9 @@
- name: Test
run: cargo test --features sysroot-abi -p proc-macro-srv -p proc-macro-srv-cli -p proc-macro-api -- --quiet
+ - name: Check salsa dependency
+ run: "! (cargo tree -p proc-macro-srv-cli | grep -q salsa)"
+
rust:
if: github.repository == 'rust-lang/rust-analyzer'
name: Rust
diff --git a/crates/proc-macro-srv-cli/Cargo.toml b/crates/proc-macro-srv-cli/Cargo.toml
index 57a28b0..ab42102 100644
--- a/crates/proc-macro-srv-cli/Cargo.toml
+++ b/crates/proc-macro-srv-cli/Cargo.toml
@@ -8,6 +8,7 @@
edition.workspace = true
license.workspace = true
rust-version.workspace = true
+publish = false
[dependencies]
proc-macro-srv.workspace = true
diff --git a/crates/span/Cargo.toml b/crates/span/Cargo.toml
index 3381dac..b3b401c 100644
--- a/crates/span/Cargo.toml
+++ b/crates/span/Cargo.toml
@@ -12,7 +12,7 @@
[dependencies]
la-arena.workspace = true
-salsa.workspace = true
+salsa = { workspace = true, optional = true }
rustc-hash.workspace = true
hashbrown.workspace = true
text-size.workspace = true
@@ -22,5 +22,8 @@
syntax.workspace = true
stdx.workspace = true
+[features]
+default = ["salsa"]
+
[lints]
workspace = true
diff --git a/crates/span/src/hygiene.rs b/crates/span/src/hygiene.rs
index 9ecd188..a2923cd 100644
--- a/crates/span/src/hygiene.rs
+++ b/crates/span/src/hygiene.rs
@@ -21,16 +21,19 @@
//! `ExpnData::call_site` in rustc, [`MacroCallLoc::call_site`] in rust-analyzer.
use std::fmt;
-use crate::{Edition, MacroCallId};
+use crate::Edition;
/// A syntax context describes a hierarchy tracking order of macro definitions.
+#[cfg(feature = "salsa")]
#[derive(Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
pub struct SyntaxContext(
salsa::Id,
std::marker::PhantomData<&'static salsa::plumbing::interned::Value<SyntaxContext>>,
);
+#[cfg(feature = "salsa")]
const _: () = {
+ use crate::MacroCallId;
use salsa::plumbing as zalsa_;
use salsa::plumbing::interned as zalsa_struct_;
@@ -291,8 +294,6 @@
};
impl SyntaxContext {
- const MAX_ID: u32 = salsa::Id::MAX_U32 - 1;
-
pub fn is_root(self) -> bool {
(SyntaxContext::MAX_ID - Edition::LATEST as u32) <= self.into_u32()
&& self.into_u32() <= (SyntaxContext::MAX_ID - Edition::Edition2015 as u32)
@@ -308,20 +309,43 @@
/// The root context, which is the parent of all other contexts. All [`FileId`]s have this context.
pub const fn root(edition: Edition) -> Self {
let edition = edition as u32;
- SyntaxContext(
- salsa::Id::from_u32(SyntaxContext::MAX_ID - edition),
- std::marker::PhantomData,
- )
+ SyntaxContext::from_u32(SyntaxContext::MAX_ID - edition)
}
+}
- pub fn into_u32(self) -> u32 {
+#[cfg(feature = "salsa")]
+impl SyntaxContext {
+ const MAX_ID: u32 = salsa::Id::MAX_U32 - 1;
+
+ pub const fn into_u32(self) -> u32 {
self.0.as_u32()
}
- pub fn from_u32(u32: u32) -> Self {
+ pub const fn from_u32(u32: u32) -> Self {
Self(salsa::Id::from_u32(u32), std::marker::PhantomData)
}
}
+#[cfg(not(feature = "salsa"))]
+#[derive(Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
+pub struct SyntaxContext(u32);
+
+#[allow(dead_code)]
+const SALSA_MAX_ID_MIRROR: u32 = u32::MAX - 0xFF;
+#[cfg(feature = "salsa")]
+const _: () = assert!(salsa::Id::MAX_U32 == SALSA_MAX_ID_MIRROR);
+
+#[cfg(not(feature = "salsa"))]
+impl SyntaxContext {
+ const MAX_ID: u32 = SALSA_MAX_ID_MIRROR - 1;
+
+ pub const fn into_u32(self) -> u32 {
+ self.0
+ }
+
+ pub const fn from_u32(u32: u32) -> Self {
+ Self(u32)
+ }
+}
/// A property of a macro expansion that determines how identifiers
/// produced by that expansion are resolved.
@@ -354,9 +378,9 @@
impl fmt::Display for SyntaxContext {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
if self.is_root() {
- write!(f, "ROOT{}", Edition::from_u32(SyntaxContext::MAX_ID - self.0.as_u32()).number())
+ write!(f, "ROOT{}", Edition::from_u32(SyntaxContext::MAX_ID - self.into_u32()).number())
} else {
- write!(f, "{}", self.0.as_u32())
+ write!(f, "{}", self.into_u32())
}
}
}
diff --git a/crates/span/src/lib.rs b/crates/span/src/lib.rs
index fbd1b25..f3f6d80 100644
--- a/crates/span/src/lib.rs
+++ b/crates/span/src/lib.rs
@@ -180,6 +180,22 @@
}
}
+#[cfg(not(feature = "salsa"))]
+mod salsa {
+ #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
+ pub(crate) struct Id(u32);
+
+ impl Id {
+ pub(crate) const fn from_u32(u32: u32) -> Self {
+ Self(u32)
+ }
+
+ pub(crate) const fn as_u32(self) -> u32 {
+ self.0
+ }
+ }
+}
+
/// Input to the analyzer is a set of files, where each file is identified by
/// `FileId` and contains source code. However, another source of source code in
/// Rust are macros: each macro can be thought of as producing a "temporary
@@ -201,12 +217,14 @@
#[derive(Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct HirFileId(salsa::Id);
+#[cfg(feature = "salsa")]
impl salsa::plumbing::AsId for HirFileId {
fn as_id(&self) -> salsa::Id {
self.0
}
}
+#[cfg(feature = "salsa")]
impl salsa::plumbing::FromId for HirFileId {
fn from_id(id: salsa::Id) -> Self {
HirFileId(id)
@@ -273,12 +291,14 @@
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct MacroCallId(salsa::Id);
+#[cfg(feature = "salsa")]
impl salsa::plumbing::AsId for MacroCallId {
fn as_id(&self) -> salsa::Id {
self.0
}
}
+#[cfg(feature = "salsa")]
impl salsa::plumbing::FromId for MacroCallId {
fn from_id(id: salsa::Id) -> Self {
MacroCallId(id)