Skip to content

Commit dda37ce

Browse files
authored
Merge pull request rust-lang#19457 from Veykril/push-xpmluxlzprpy
chore: Remove salsa dependency from proc-macro server again
2 parents 085b4d5 + ad913a4 commit dda37ce

File tree

5 files changed

+63
-12
lines changed

5 files changed

+63
-12
lines changed

src/tools/rust-analyzer/.github/workflows/ci.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ jobs:
7070
- name: Test
7171
run: cargo test --features sysroot-abi -p proc-macro-srv -p proc-macro-srv-cli -p proc-macro-api -- --quiet
7272

73+
- name: Check salsa dependency
74+
run: "! (cargo tree -p proc-macro-srv-cli | grep -q salsa)"
75+
7376
rust:
7477
if: github.repository == 'rust-lang/rust-analyzer'
7578
name: Rust

src/tools/rust-analyzer/crates/proc-macro-srv-cli/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ authors.workspace = true
88
edition.workspace = true
99
license.workspace = true
1010
rust-version.workspace = true
11+
publish = false
1112

1213
[dependencies]
1314
proc-macro-srv.workspace = true

src/tools/rust-analyzer/crates/span/Cargo.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ authors.workspace = true
1212

1313
[dependencies]
1414
la-arena.workspace = true
15-
salsa.workspace = true
15+
salsa = { workspace = true, optional = true }
1616
rustc-hash.workspace = true
1717
hashbrown.workspace = true
1818
text-size.workspace = true
@@ -22,5 +22,8 @@ vfs.workspace = true
2222
syntax.workspace = true
2323
stdx.workspace = true
2424

25+
[features]
26+
default = ["salsa"]
27+
2528
[lints]
2629
workspace = true

src/tools/rust-analyzer/crates/span/src/hygiene.rs

Lines changed: 35 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,19 @@
2121
//! `ExpnData::call_site` in rustc, [`MacroCallLoc::call_site`] in rust-analyzer.
2222
use std::fmt;
2323

24-
use crate::{Edition, MacroCallId};
24+
use crate::Edition;
2525

2626
/// A syntax context describes a hierarchy tracking order of macro definitions.
27+
#[cfg(feature = "salsa")]
2728
#[derive(Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
2829
pub struct SyntaxContext(
2930
salsa::Id,
3031
std::marker::PhantomData<&'static salsa::plumbing::interned::Value<SyntaxContext>>,
3132
);
3233

34+
#[cfg(feature = "salsa")]
3335
const _: () = {
36+
use crate::MacroCallId;
3437
use salsa::plumbing as zalsa_;
3538
use salsa::plumbing::interned as zalsa_struct_;
3639

@@ -291,8 +294,6 @@ const _: () = {
291294
};
292295

293296
impl SyntaxContext {
294-
const MAX_ID: u32 = salsa::Id::MAX_U32 - 1;
295-
296297
pub fn is_root(self) -> bool {
297298
(SyntaxContext::MAX_ID - Edition::LATEST as u32) <= self.into_u32()
298299
&& self.into_u32() <= (SyntaxContext::MAX_ID - Edition::Edition2015 as u32)
@@ -308,20 +309,43 @@ impl SyntaxContext {
308309
/// The root context, which is the parent of all other contexts. All [`FileId`]s have this context.
309310
pub const fn root(edition: Edition) -> Self {
310311
let edition = edition as u32;
311-
SyntaxContext(
312-
salsa::Id::from_u32(SyntaxContext::MAX_ID - edition),
313-
std::marker::PhantomData,
314-
)
312+
SyntaxContext::from_u32(SyntaxContext::MAX_ID - edition)
315313
}
314+
}
315+
316+
#[cfg(feature = "salsa")]
317+
impl SyntaxContext {
318+
const MAX_ID: u32 = salsa::Id::MAX_U32 - 1;
316319

317-
pub fn into_u32(self) -> u32 {
320+
pub const fn into_u32(self) -> u32 {
318321
self.0.as_u32()
319322
}
320323

321-
pub fn from_u32(u32: u32) -> Self {
324+
pub const fn from_u32(u32: u32) -> Self {
322325
Self(salsa::Id::from_u32(u32), std::marker::PhantomData)
323326
}
324327
}
328+
#[cfg(not(feature = "salsa"))]
329+
#[derive(Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
330+
pub struct SyntaxContext(u32);
331+
332+
#[allow(dead_code)]
333+
const SALSA_MAX_ID_MIRROR: u32 = u32::MAX - 0xFF;
334+
#[cfg(feature = "salsa")]
335+
const _: () = assert!(salsa::Id::MAX_U32 == SALSA_MAX_ID_MIRROR);
336+
337+
#[cfg(not(feature = "salsa"))]
338+
impl SyntaxContext {
339+
const MAX_ID: u32 = SALSA_MAX_ID_MIRROR - 1;
340+
341+
pub const fn into_u32(self) -> u32 {
342+
self.0
343+
}
344+
345+
pub const fn from_u32(u32: u32) -> Self {
346+
Self(u32)
347+
}
348+
}
325349

326350
/// A property of a macro expansion that determines how identifiers
327351
/// produced by that expansion are resolved.
@@ -354,9 +378,9 @@ impl Transparency {
354378
impl fmt::Display for SyntaxContext {
355379
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
356380
if self.is_root() {
357-
write!(f, "ROOT{}", Edition::from_u32(SyntaxContext::MAX_ID - self.0.as_u32()).number())
381+
write!(f, "ROOT{}", Edition::from_u32(SyntaxContext::MAX_ID - self.into_u32()).number())
358382
} else {
359-
write!(f, "{}", self.0.as_u32())
383+
write!(f, "{}", self.into_u32())
360384
}
361385
}
362386
}

src/tools/rust-analyzer/crates/span/src/lib.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,22 @@ impl EditionedFileId {
180180
}
181181
}
182182

183+
#[cfg(not(feature = "salsa"))]
184+
mod salsa {
185+
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
186+
pub(crate) struct Id(u32);
187+
188+
impl Id {
189+
pub(crate) const fn from_u32(u32: u32) -> Self {
190+
Self(u32)
191+
}
192+
193+
pub(crate) const fn as_u32(self) -> u32 {
194+
self.0
195+
}
196+
}
197+
}
198+
183199
/// Input to the analyzer is a set of files, where each file is identified by
184200
/// `FileId` and contains source code. However, another source of source code in
185201
/// Rust are macros: each macro can be thought of as producing a "temporary
@@ -201,12 +217,14 @@ impl EditionedFileId {
201217
#[derive(Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)]
202218
pub struct HirFileId(salsa::Id);
203219

220+
#[cfg(feature = "salsa")]
204221
impl salsa::plumbing::AsId for HirFileId {
205222
fn as_id(&self) -> salsa::Id {
206223
self.0
207224
}
208225
}
209226

227+
#[cfg(feature = "salsa")]
210228
impl salsa::plumbing::FromId for HirFileId {
211229
fn from_id(id: salsa::Id) -> Self {
212230
HirFileId(id)
@@ -273,12 +291,14 @@ pub struct MacroFileId {
273291
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
274292
pub struct MacroCallId(salsa::Id);
275293

294+
#[cfg(feature = "salsa")]
276295
impl salsa::plumbing::AsId for MacroCallId {
277296
fn as_id(&self) -> salsa::Id {
278297
self.0
279298
}
280299
}
281300

301+
#[cfg(feature = "salsa")]
282302
impl salsa::plumbing::FromId for MacroCallId {
283303
fn from_id(id: salsa::Id) -> Self {
284304
MacroCallId(id)

0 commit comments

Comments
 (0)