mirror of
				https://github.com/rust-lang/rust-analyzer.git
				synced 2025-10-30 19:49:36 +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
					
				
					 5 changed files with 63 additions and 12 deletions
				
			
		
							
								
								
									
										3
									
								
								.github/workflows/ci.yaml
									
										
									
									
										vendored
									
									
								
							
							
						
						
									
										3
									
								
								.github/workflows/ci.yaml
									
										
									
									
										vendored
									
									
								
							|  | @ -70,6 +70,9 @@ jobs: | |||
|       - 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 | ||||
|  |  | |||
|  | @ -8,6 +8,7 @@ authors.workspace = true | |||
| edition.workspace = true | ||||
| license.workspace = true | ||||
| rust-version.workspace = true | ||||
| publish = false | ||||
| 
 | ||||
| [dependencies] | ||||
| proc-macro-srv.workspace = true | ||||
|  |  | |||
|  | @ -12,7 +12,7 @@ authors.workspace = true | |||
| 
 | ||||
| [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 @@ vfs.workspace = true | |||
| syntax.workspace = true | ||||
| stdx.workspace = true | ||||
| 
 | ||||
| [features] | ||||
| default = ["salsa"] | ||||
| 
 | ||||
| [lints] | ||||
| workspace = true | ||||
|  |  | |||
|  | @ -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 @@ const _: () = { | |||
| }; | ||||
| 
 | ||||
| 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 @@ impl SyntaxContext { | |||
|     /// 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 Transparency { | |||
| 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()) | ||||
|         } | ||||
|     } | ||||
| } | ||||
|  |  | |||
|  | @ -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
 | ||||
| /// `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 @@ impl EditionedFileId { | |||
| #[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 @@ pub struct MacroFileId { | |||
| #[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) | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Lukas Wirth
						Lukas Wirth