mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-01 11:31:15 +00:00
Merge pull request #19457 from Veykril/push-xpmluxlzprpy
chore: Remove salsa dependency from proc-macro server again
This commit is contained in:
commit
d6b9261fed
3
.github/workflows/ci.yaml
vendored
3
.github/workflows/ci.yaml
vendored
@ -70,6 +70,9 @@ jobs:
|
|||||||
- name: Test
|
- name: Test
|
||||||
run: cargo test --features sysroot-abi -p proc-macro-srv -p proc-macro-srv-cli -p proc-macro-api -- --quiet
|
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:
|
rust:
|
||||||
if: github.repository == 'rust-lang/rust-analyzer'
|
if: github.repository == 'rust-lang/rust-analyzer'
|
||||||
name: Rust
|
name: Rust
|
||||||
|
@ -8,6 +8,7 @@ authors.workspace = true
|
|||||||
edition.workspace = true
|
edition.workspace = true
|
||||||
license.workspace = true
|
license.workspace = true
|
||||||
rust-version.workspace = true
|
rust-version.workspace = true
|
||||||
|
publish = false
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
proc-macro-srv.workspace = true
|
proc-macro-srv.workspace = true
|
||||||
|
@ -12,7 +12,7 @@ authors.workspace = true
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
la-arena.workspace = true
|
la-arena.workspace = true
|
||||||
salsa.workspace = true
|
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 = ["salsa"]
|
||||||
|
|
||||||
[lints]
|
[lints]
|
||||||
workspace = true
|
workspace = true
|
||||||
|
@ -21,16 +21,19 @@
|
|||||||
//! `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;
|
||||||
|
|
||||||
use crate::{Edition, MacroCallId};
|
use crate::Edition;
|
||||||
|
|
||||||
/// A syntax context describes a hierarchy tracking order of macro definitions.
|
/// A syntax context describes a hierarchy tracking order of macro definitions.
|
||||||
|
#[cfg(feature = "salsa")]
|
||||||
#[derive(Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
|
#[derive(Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
|
||||||
pub struct SyntaxContext(
|
pub struct SyntaxContext(
|
||||||
salsa::Id,
|
salsa::Id,
|
||||||
std::marker::PhantomData<&'static salsa::plumbing::interned::Value<SyntaxContext>>,
|
std::marker::PhantomData<&'static salsa::plumbing::interned::Value<SyntaxContext>>,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
#[cfg(feature = "salsa")]
|
||||||
const _: () = {
|
const _: () = {
|
||||||
|
use crate::MacroCallId;
|
||||||
use salsa::plumbing as zalsa_;
|
use salsa::plumbing as zalsa_;
|
||||||
use salsa::plumbing::interned as zalsa_struct_;
|
use salsa::plumbing::interned as zalsa_struct_;
|
||||||
|
|
||||||
@ -291,8 +294,6 @@ const _: () = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
impl SyntaxContext {
|
impl SyntaxContext {
|
||||||
const MAX_ID: u32 = salsa::Id::MAX_U32 - 1;
|
|
||||||
|
|
||||||
pub fn is_root(self) -> bool {
|
pub fn is_root(self) -> bool {
|
||||||
(SyntaxContext::MAX_ID - Edition::LATEST as u32) <= self.into_u32()
|
(SyntaxContext::MAX_ID - Edition::LATEST as u32) <= self.into_u32()
|
||||||
&& self.into_u32() <= (SyntaxContext::MAX_ID - Edition::Edition2015 as u32)
|
&& self.into_u32() <= (SyntaxContext::MAX_ID - Edition::Edition2015 as u32)
|
||||||
@ -308,20 +309,43 @@ impl SyntaxContext {
|
|||||||
/// The root context, which is the parent of all other contexts. All [`FileId`]s have this context.
|
/// The root context, which is the parent of all other contexts. All [`FileId`]s have this context.
|
||||||
pub const fn root(edition: Edition) -> Self {
|
pub const fn root(edition: Edition) -> Self {
|
||||||
let edition = edition as u32;
|
let edition = edition as u32;
|
||||||
SyntaxContext(
|
SyntaxContext::from_u32(SyntaxContext::MAX_ID - edition)
|
||||||
salsa::Id::from_u32(SyntaxContext::MAX_ID - edition),
|
|
||||||
std::marker::PhantomData,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
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()
|
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)
|
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
|
/// A property of a macro expansion that determines how identifiers
|
||||||
/// produced by that expansion are resolved.
|
/// produced by that expansion are resolved.
|
||||||
@ -354,9 +378,9 @@ impl Transparency {
|
|||||||
impl fmt::Display for SyntaxContext {
|
impl fmt::Display for SyntaxContext {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
if self.is_root() {
|
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 {
|
} else {
|
||||||
write!(f, "{}", self.0.as_u32())
|
write!(f, "{}", self.into_u32())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -180,6 +180,22 @@ impl EditionedFileId {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[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
|
/// 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
|
/// `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
|
/// Rust are macros: each macro can be thought of as producing a "temporary
|
||||||
@ -201,12 +217,14 @@ impl EditionedFileId {
|
|||||||
#[derive(Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)]
|
#[derive(Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)]
|
||||||
pub struct HirFileId(salsa::Id);
|
pub struct HirFileId(salsa::Id);
|
||||||
|
|
||||||
|
#[cfg(feature = "salsa")]
|
||||||
impl salsa::plumbing::AsId for HirFileId {
|
impl salsa::plumbing::AsId for HirFileId {
|
||||||
fn as_id(&self) -> salsa::Id {
|
fn as_id(&self) -> salsa::Id {
|
||||||
self.0
|
self.0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "salsa")]
|
||||||
impl salsa::plumbing::FromId for HirFileId {
|
impl salsa::plumbing::FromId for HirFileId {
|
||||||
fn from_id(id: salsa::Id) -> Self {
|
fn from_id(id: salsa::Id) -> Self {
|
||||||
HirFileId(id)
|
HirFileId(id)
|
||||||
@ -273,12 +291,14 @@ pub struct MacroFileId {
|
|||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||||
pub struct MacroCallId(salsa::Id);
|
pub struct MacroCallId(salsa::Id);
|
||||||
|
|
||||||
|
#[cfg(feature = "salsa")]
|
||||||
impl salsa::plumbing::AsId for MacroCallId {
|
impl salsa::plumbing::AsId for MacroCallId {
|
||||||
fn as_id(&self) -> salsa::Id {
|
fn as_id(&self) -> salsa::Id {
|
||||||
self.0
|
self.0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "salsa")]
|
||||||
impl salsa::plumbing::FromId for MacroCallId {
|
impl salsa::plumbing::FromId for MacroCallId {
|
||||||
fn from_id(id: salsa::Id) -> Self {
|
fn from_id(id: salsa::Id) -> Self {
|
||||||
MacroCallId(id)
|
MacroCallId(id)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user