Skip to content

Commit cbf3443

Browse files
authored
Merge pull request #18710 from Veykril/push-oywuruktpozm
Remove salsa from proc-macro server dep tree
2 parents 2780dfd + 3d63140 commit cbf3443

File tree

9 files changed

+88
-15
lines changed

9 files changed

+88
-15
lines changed

Cargo.lock

-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/load-cargo/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,7 @@ impl ProcMacroExpander for Expander {
487487
match self.0.expand(
488488
subtree,
489489
attrs,
490-
env.clone(),
490+
env.clone().into(),
491491
def_site,
492492
call_site,
493493
mixed_site,

crates/proc-macro-api/Cargo.toml

+3-5
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,9 @@ indexmap.workspace = true
2323
paths = { workspace = true, features = ["serde1"] }
2424
tt.workspace = true
2525
stdx.workspace = true
26-
# Ideally this crate would not depend on salsa things, but we need span information here which wraps
27-
# InternIds for the syntax context
28-
span.workspace = true
29-
# only here due to the `Env` newtype :/
30-
base-db.workspace = true
26+
# span = {workspace = true, default-features = false} does not work
27+
span = { path = "../span", version = "0.0.0", default-features = false}
28+
3129
intern.workspace = true
3230

3331
[lints]

crates/proc-macro-api/src/lib.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ pub mod json;
99
pub mod msg;
1010
mod process;
1111

12-
use base_db::Env;
1312
use paths::{AbsPath, AbsPathBuf};
1413
use span::Span;
1514
use std::{fmt, io, sync::Arc};
@@ -148,7 +147,7 @@ impl ProcMacro {
148147
&self,
149148
subtree: &tt::Subtree<Span>,
150149
attr: Option<&tt::Subtree<Span>>,
151-
env: Env,
150+
env: Vec<(String, String)>,
152151
def_site: Span,
153152
call_site: Span,
154153
mixed_site: Span,
@@ -179,7 +178,7 @@ impl ProcMacro {
179178
},
180179
},
181180
lib: self.dylib_path.to_path_buf().into(),
182-
env: env.into(),
181+
env,
183182
current_dir,
184183
};
185184

crates/proc-macro-srv/Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ stdx.workspace = true
2121
tt.workspace = true
2222
syntax-bridge.workspace = true
2323
paths.workspace = true
24-
base-db.workspace = true
25-
span.workspace = true
24+
# span = {workspace = true, default-features = false} does not work
25+
span = { path = "../span", version = "0.0.0", default-features = false}
2626
proc-macro-api.workspace = true
2727
intern.workspace = true
2828

crates/span/Cargo.toml

+4-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ authors.workspace = true
1212

1313
[dependencies]
1414
la-arena.workspace = true
15-
ra-salsa.workspace = true
15+
ra-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 = ["ra-salsa"]
27+
2528
[lints]
2629
workspace = true

crates/span/src/hygiene.rs

+5
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@
2121
//! `ExpnData::call_site` in rustc, [`MacroCallLoc::call_site`] in rust-analyzer.
2222
use std::fmt;
2323

24+
#[cfg(not(feature = "ra-salsa"))]
25+
use crate::InternId;
26+
#[cfg(feature = "ra-salsa")]
2427
use ra_salsa::{InternId, InternValue};
2528

2629
use crate::MacroCallId;
@@ -39,6 +42,7 @@ impl fmt::Debug for SyntaxContextId {
3942
}
4043
}
4144

45+
#[cfg(feature = "ra-salsa")]
4246
impl ra_salsa::InternKey for SyntaxContextId {
4347
fn from_intern_id(v: ra_salsa::InternId) -> Self {
4448
SyntaxContextId(v)
@@ -92,6 +96,7 @@ pub struct SyntaxContextData {
9296
pub opaque_and_semitransparent: SyntaxContextId,
9397
}
9498

99+
#[cfg(feature = "ra-salsa")]
95100
impl InternValue for SyntaxContextData {
96101
type Key = (SyntaxContextId, Option<MacroCallId>, Transparency);
97102

crates/span/src/lib.rs

+69
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
//! File and span related types.
22
use std::fmt::{self, Write};
33

4+
#[cfg(feature = "ra-salsa")]
45
use ra_salsa::InternId;
56

67
mod ast_id;
@@ -355,3 +356,71 @@ impl HirFileId {
355356
}
356357
}
357358
}
359+
360+
#[cfg(not(feature = "ra-salsa"))]
361+
mod intern_id_proxy {
362+
use std::fmt;
363+
use std::num::NonZeroU32;
364+
365+
pub(super) struct InternId {
366+
value: NonZeroU32,
367+
}
368+
369+
impl InternId {
370+
pub(super) const MAX: u32 = 0xFFFF_FF00;
371+
372+
pub(super) const unsafe fn new_unchecked(value: u32) -> Self {
373+
debug_assert!(value < InternId::MAX);
374+
let value = unsafe { NonZeroU32::new_unchecked(value + 1) };
375+
InternId { value }
376+
}
377+
378+
pub(super) fn as_u32(self) -> u32 {
379+
self.value.get() - 1
380+
}
381+
382+
pub(super) fn as_usize(self) -> usize {
383+
self.as_u32() as usize
384+
}
385+
}
386+
387+
impl From<InternId> for u32 {
388+
fn from(raw: InternId) -> u32 {
389+
raw.as_u32()
390+
}
391+
}
392+
393+
impl From<InternId> for usize {
394+
fn from(raw: InternId) -> usize {
395+
raw.as_usize()
396+
}
397+
}
398+
399+
impl From<u32> for InternId {
400+
fn from(id: u32) -> InternId {
401+
assert!(id < InternId::MAX);
402+
unsafe { InternId::new_unchecked(id) }
403+
}
404+
}
405+
406+
impl From<usize> for InternId {
407+
fn from(id: usize) -> InternId {
408+
assert!(id < (InternId::MAX as usize));
409+
unsafe { InternId::new_unchecked(id as u32) }
410+
}
411+
}
412+
413+
impl fmt::Debug for InternId {
414+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
415+
self.as_usize().fmt(f)
416+
}
417+
}
418+
419+
impl fmt::Display for InternId {
420+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
421+
self.as_usize().fmt(f)
422+
}
423+
}
424+
}
425+
#[cfg(not(feature = "ra-salsa"))]
426+
use intern_id_proxy::InternId;

crates/syntax-bridge/Cargo.toml

+2-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ syntax.workspace = true
2121
parser.workspace = true
2222
tt.workspace = true
2323
stdx.workspace = true
24-
span.workspace = true
24+
# span = {workspace = true, default-features = false} does not work
25+
span = { path = "../span", version = "0.0.0", default-features = false}
2526
intern.workspace = true
2627

2728
[dev-dependencies]

0 commit comments

Comments
 (0)