mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-25 12:33:33 +00:00
Remove salsa from proc-macro server dep tree
This commit is contained in:
parent
2780dfd80c
commit
3d63140758
9 changed files with 88 additions and 15 deletions
2
Cargo.lock
generated
2
Cargo.lock
generated
|
@ -1352,7 +1352,6 @@ dependencies = [
|
||||||
name = "proc-macro-api"
|
name = "proc-macro-api"
|
||||||
version = "0.0.0"
|
version = "0.0.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"base-db",
|
|
||||||
"indexmap",
|
"indexmap",
|
||||||
"intern",
|
"intern",
|
||||||
"paths",
|
"paths",
|
||||||
|
@ -1369,7 +1368,6 @@ dependencies = [
|
||||||
name = "proc-macro-srv"
|
name = "proc-macro-srv"
|
||||||
version = "0.0.0"
|
version = "0.0.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"base-db",
|
|
||||||
"expect-test",
|
"expect-test",
|
||||||
"intern",
|
"intern",
|
||||||
"libloading",
|
"libloading",
|
||||||
|
|
|
@ -487,7 +487,7 @@ impl ProcMacroExpander for Expander {
|
||||||
match self.0.expand(
|
match self.0.expand(
|
||||||
subtree,
|
subtree,
|
||||||
attrs,
|
attrs,
|
||||||
env.clone(),
|
env.clone().into(),
|
||||||
def_site,
|
def_site,
|
||||||
call_site,
|
call_site,
|
||||||
mixed_site,
|
mixed_site,
|
||||||
|
|
|
@ -23,11 +23,9 @@ indexmap.workspace = true
|
||||||
paths = { workspace = true, features = ["serde1"] }
|
paths = { workspace = true, features = ["serde1"] }
|
||||||
tt.workspace = true
|
tt.workspace = true
|
||||||
stdx.workspace = true
|
stdx.workspace = true
|
||||||
# Ideally this crate would not depend on salsa things, but we need span information here which wraps
|
# span = {workspace = true, default-features = false} does not work
|
||||||
# InternIds for the syntax context
|
span = { path = "../span", version = "0.0.0", default-features = false}
|
||||||
span.workspace = true
|
|
||||||
# only here due to the `Env` newtype :/
|
|
||||||
base-db.workspace = true
|
|
||||||
intern.workspace = true
|
intern.workspace = true
|
||||||
|
|
||||||
[lints]
|
[lints]
|
||||||
|
|
|
@ -9,7 +9,6 @@ pub mod json;
|
||||||
pub mod msg;
|
pub mod msg;
|
||||||
mod process;
|
mod process;
|
||||||
|
|
||||||
use base_db::Env;
|
|
||||||
use paths::{AbsPath, AbsPathBuf};
|
use paths::{AbsPath, AbsPathBuf};
|
||||||
use span::Span;
|
use span::Span;
|
||||||
use std::{fmt, io, sync::Arc};
|
use std::{fmt, io, sync::Arc};
|
||||||
|
@ -148,7 +147,7 @@ impl ProcMacro {
|
||||||
&self,
|
&self,
|
||||||
subtree: &tt::Subtree<Span>,
|
subtree: &tt::Subtree<Span>,
|
||||||
attr: Option<&tt::Subtree<Span>>,
|
attr: Option<&tt::Subtree<Span>>,
|
||||||
env: Env,
|
env: Vec<(String, String)>,
|
||||||
def_site: Span,
|
def_site: Span,
|
||||||
call_site: Span,
|
call_site: Span,
|
||||||
mixed_site: Span,
|
mixed_site: Span,
|
||||||
|
@ -179,7 +178,7 @@ impl ProcMacro {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
lib: self.dylib_path.to_path_buf().into(),
|
lib: self.dylib_path.to_path_buf().into(),
|
||||||
env: env.into(),
|
env,
|
||||||
current_dir,
|
current_dir,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -21,8 +21,8 @@ stdx.workspace = true
|
||||||
tt.workspace = true
|
tt.workspace = true
|
||||||
syntax-bridge.workspace = true
|
syntax-bridge.workspace = true
|
||||||
paths.workspace = true
|
paths.workspace = true
|
||||||
base-db.workspace = true
|
# span = {workspace = true, default-features = false} does not work
|
||||||
span.workspace = true
|
span = { path = "../span", version = "0.0.0", default-features = false}
|
||||||
proc-macro-api.workspace = true
|
proc-macro-api.workspace = true
|
||||||
intern.workspace = true
|
intern.workspace = true
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,7 @@ authors.workspace = true
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
la-arena.workspace = true
|
la-arena.workspace = true
|
||||||
ra-salsa.workspace = true
|
ra-salsa = { workspace = true, optional = true }
|
||||||
rustc-hash.workspace = true
|
rustc-hash.workspace = true
|
||||||
hashbrown.workspace = true
|
hashbrown.workspace = true
|
||||||
text-size.workspace = true
|
text-size.workspace = true
|
||||||
|
@ -22,5 +22,8 @@ vfs.workspace = true
|
||||||
syntax.workspace = true
|
syntax.workspace = true
|
||||||
stdx.workspace = true
|
stdx.workspace = true
|
||||||
|
|
||||||
|
[features]
|
||||||
|
default = ["ra-salsa"]
|
||||||
|
|
||||||
[lints]
|
[lints]
|
||||||
workspace = true
|
workspace = true
|
||||||
|
|
|
@ -21,6 +21,9 @@
|
||||||
//! `ExpnData::call_site` in rustc, [`MacroCallLoc::call_site`] in rust-analyzer.
|
//! `ExpnData::call_site` in rustc, [`MacroCallLoc::call_site`] in rust-analyzer.
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
|
|
||||||
|
#[cfg(not(feature = "ra-salsa"))]
|
||||||
|
use crate::InternId;
|
||||||
|
#[cfg(feature = "ra-salsa")]
|
||||||
use ra_salsa::{InternId, InternValue};
|
use ra_salsa::{InternId, InternValue};
|
||||||
|
|
||||||
use crate::MacroCallId;
|
use crate::MacroCallId;
|
||||||
|
@ -39,6 +42,7 @@ impl fmt::Debug for SyntaxContextId {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "ra-salsa")]
|
||||||
impl ra_salsa::InternKey for SyntaxContextId {
|
impl ra_salsa::InternKey for SyntaxContextId {
|
||||||
fn from_intern_id(v: ra_salsa::InternId) -> Self {
|
fn from_intern_id(v: ra_salsa::InternId) -> Self {
|
||||||
SyntaxContextId(v)
|
SyntaxContextId(v)
|
||||||
|
@ -92,6 +96,7 @@ pub struct SyntaxContextData {
|
||||||
pub opaque_and_semitransparent: SyntaxContextId,
|
pub opaque_and_semitransparent: SyntaxContextId,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "ra-salsa")]
|
||||||
impl InternValue for SyntaxContextData {
|
impl InternValue for SyntaxContextData {
|
||||||
type Key = (SyntaxContextId, Option<MacroCallId>, Transparency);
|
type Key = (SyntaxContextId, Option<MacroCallId>, Transparency);
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
//! File and span related types.
|
//! File and span related types.
|
||||||
use std::fmt::{self, Write};
|
use std::fmt::{self, Write};
|
||||||
|
|
||||||
|
#[cfg(feature = "ra-salsa")]
|
||||||
use ra_salsa::InternId;
|
use ra_salsa::InternId;
|
||||||
|
|
||||||
mod ast_id;
|
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;
|
||||||
|
|
|
@ -21,7 +21,8 @@ syntax.workspace = true
|
||||||
parser.workspace = true
|
parser.workspace = true
|
||||||
tt.workspace = true
|
tt.workspace = true
|
||||||
stdx.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
|
intern.workspace = true
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
|
|
Loading…
Reference in a new issue