about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorLukas Wirth <lukastw97@gmail.com>2024-08-03 19:16:56 +0200
committerLukas Wirth <lukastw97@gmail.com>2024-08-05 13:46:47 +0200
commitcdee65f5ea9bfb20d2a0c8d44f805dd42c845938 (patch)
treef4e2f38aee50600ec79985f38188871599c031f0 /src
parent2e7db9c69ffeb58cb512e84a88ab5dced33abcf2 (diff)
downloadrust-cdee65f5ea9bfb20d2a0c8d44f805dd42c845938.tar.gz
rust-cdee65f5ea9bfb20d2a0c8d44f805dd42c845938.zip
Newtype ErasedFileAstId
Diffstat (limited to 'src')
-rw-r--r--src/tools/rust-analyzer/Cargo.lock3
-rw-r--r--src/tools/rust-analyzer/crates/base-db/src/lib.rs2
-rw-r--r--src/tools/rust-analyzer/crates/paths/Cargo.toml7
-rw-r--r--src/tools/rust-analyzer/crates/proc-macro-api/Cargo.toml5
-rw-r--r--src/tools/rust-analyzer/crates/proc-macro-api/src/msg.rs6
-rw-r--r--src/tools/rust-analyzer/crates/proc-macro-api/src/msg/flat.rs8
-rw-r--r--src/tools/rust-analyzer/crates/proc-macro-srv/src/server_impl/rust_analyzer_span.rs4
-rw-r--r--src/tools/rust-analyzer/crates/proc-macro-srv/src/tests/utils.rs4
-rw-r--r--src/tools/rust-analyzer/crates/rust-analyzer/tests/slow-tests/main.rs2
-rw-r--r--src/tools/rust-analyzer/crates/span/src/ast_id.rs39
-rw-r--r--src/tools/rust-analyzer/crates/span/src/lib.rs7
-rw-r--r--src/tools/rust-analyzer/crates/span/src/map.rs2
-rw-r--r--src/tools/rust-analyzer/crates/test-fixture/src/lib.rs2
13 files changed, 52 insertions, 39 deletions
diff --git a/src/tools/rust-analyzer/Cargo.lock b/src/tools/rust-analyzer/Cargo.lock
index e4f6ad28c1e..b89bab1a6b9 100644
--- a/src/tools/rust-analyzer/Cargo.lock
+++ b/src/tools/rust-analyzer/Cargo.lock
@@ -1268,6 +1268,7 @@ name = "paths"
 version = "0.0.0"
 dependencies = [
  "camino",
+ "serde",
 ]
 
 [[package]]
@@ -1330,14 +1331,12 @@ dependencies = [
  "base-db",
  "indexmap",
  "intern",
- "la-arena 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
  "paths",
  "rustc-hash",
  "serde",
  "serde_json",
  "span",
  "stdx",
- "text-size",
  "tracing",
  "tt",
 ]
diff --git a/src/tools/rust-analyzer/crates/base-db/src/lib.rs b/src/tools/rust-analyzer/crates/base-db/src/lib.rs
index 35b51f22c56..20ef45d0b37 100644
--- a/src/tools/rust-analyzer/crates/base-db/src/lib.rs
+++ b/src/tools/rust-analyzer/crates/base-db/src/lib.rs
@@ -1,5 +1,5 @@
 //! base_db defines basic database traits. The concrete DB is defined by ide.
-
+// FIXME: Rename this crate, base db is non descriptive
 mod change;
 mod input;
 
diff --git a/src/tools/rust-analyzer/crates/paths/Cargo.toml b/src/tools/rust-analyzer/crates/paths/Cargo.toml
index 59a4ad9a255..b51892c2655 100644
--- a/src/tools/rust-analyzer/crates/paths/Cargo.toml
+++ b/src/tools/rust-analyzer/crates/paths/Cargo.toml
@@ -13,13 +13,10 @@ doctest = false
 
 [dependencies]
 camino.workspace = true
-# Adding this dep sadly puts a lot of rust-analyzer crates after the
-# serde-derive crate. Even though we don't activate the derive feature here,
-# someone else in the crate graph certainly does!
-# serde.workspace = true
+serde = { workspace = true, optional = true }
 
 [features]
-serde1 = ["camino/serde1"]
+serde1 = ["camino/serde1", "dep:serde"]
 
 [lints]
 workspace = true
diff --git a/src/tools/rust-analyzer/crates/proc-macro-api/Cargo.toml b/src/tools/rust-analyzer/crates/proc-macro-api/Cargo.toml
index 345fb9f8ae9..3e6f80878bd 100644
--- a/src/tools/rust-analyzer/crates/proc-macro-api/Cargo.toml
+++ b/src/tools/rust-analyzer/crates/proc-macro-api/Cargo.toml
@@ -22,12 +22,11 @@ indexmap.workspace = true
 paths = { workspace = true, features = ["serde1"] }
 tt.workspace = true
 stdx.workspace = true
-text-size.workspace = true
-span.workspace = true
 # Ideally this crate would not depend on salsa things, but we need span information here which wraps
 # InternIds for the syntax context
+span.workspace = true
+# only here due to the `Env` newtype :/
 base-db.workspace = true
-la-arena.workspace = true
 intern.workspace = true
 
 [lints]
diff --git a/src/tools/rust-analyzer/crates/proc-macro-api/src/msg.rs b/src/tools/rust-analyzer/crates/proc-macro-api/src/msg.rs
index 6a99b5ed1cc..883528558d9 100644
--- a/src/tools/rust-analyzer/crates/proc-macro-api/src/msg.rs
+++ b/src/tools/rust-analyzer/crates/proc-macro-api/src/msg.rs
@@ -158,9 +158,7 @@ type ProtocolWrite<W: Write> = for<'o, 'msg> fn(out: &'o mut W, msg: &'msg str)
 #[cfg(test)]
 mod tests {
     use intern::{sym, Symbol};
-    use la_arena::RawIdx;
-    use span::{ErasedFileAstId, Span, SpanAnchor, SyntaxContextId};
-    use text_size::{TextRange, TextSize};
+    use span::{ErasedFileAstId, Span, SpanAnchor, SyntaxContextId, TextRange, TextSize};
     use tt::{Delimiter, DelimiterKind, Ident, Leaf, Literal, Punct, Spacing, Subtree, TokenTree};
 
     use super::*;
@@ -171,7 +169,7 @@ mod tests {
                 span::FileId::from_raw(0xe4e4e),
                 span::Edition::CURRENT,
             ),
-            ast_id: ErasedFileAstId::from_raw(RawIdx::from(0)),
+            ast_id: ErasedFileAstId::from_raw(0),
         };
 
         let token_trees = Box::new([
diff --git a/src/tools/rust-analyzer/crates/proc-macro-api/src/msg/flat.rs b/src/tools/rust-analyzer/crates/proc-macro-api/src/msg/flat.rs
index a8661f59b28..88256e98b58 100644
--- a/src/tools/rust-analyzer/crates/proc-macro-api/src/msg/flat.rs
+++ b/src/tools/rust-analyzer/crates/proc-macro-api/src/msg/flat.rs
@@ -38,11 +38,9 @@
 use std::collections::VecDeque;
 
 use intern::Symbol;
-use la_arena::RawIdx;
 use rustc_hash::FxHashMap;
 use serde::{Deserialize, Serialize};
-use span::{EditionedFileId, ErasedFileAstId, Span, SpanAnchor, SyntaxContextId};
-use text_size::TextRange;
+use span::{EditionedFileId, ErasedFileAstId, Span, SpanAnchor, SyntaxContextId, TextRange};
 
 use crate::msg::{ENCODE_CLOSE_SPAN_VERSION, EXTENDED_LEAF_DATA};
 
@@ -54,7 +52,7 @@ pub fn serialize_span_data_index_map(map: &SpanDataIndexMap) -> Vec<u32> {
         .flat_map(|span| {
             [
                 span.anchor.file_id.as_u32(),
-                span.anchor.ast_id.into_raw().into_u32(),
+                span.anchor.ast_id.into_raw(),
                 span.range.start().into(),
                 span.range.end().into(),
                 span.ctx.into_u32(),
@@ -71,7 +69,7 @@ pub fn deserialize_span_data_index_map(map: &[u32]) -> SpanDataIndexMap {
             Span {
                 anchor: SpanAnchor {
                     file_id: EditionedFileId::from_raw(file_id),
-                    ast_id: ErasedFileAstId::from_raw(RawIdx::from_u32(ast_id)),
+                    ast_id: ErasedFileAstId::from_raw(ast_id),
                 },
                 range: TextRange::new(start.into(), end.into()),
                 ctx: SyntaxContextId::from_u32(e),
diff --git a/src/tools/rust-analyzer/crates/proc-macro-srv/src/server_impl/rust_analyzer_span.rs b/src/tools/rust-analyzer/crates/proc-macro-srv/src/server_impl/rust_analyzer_span.rs
index 8b9eb3beb6e..552d99f51ba 100644
--- a/src/tools/rust-analyzer/crates/proc-macro-srv/src/server_impl/rust_analyzer_span.rs
+++ b/src/tools/rust-analyzer/crates/proc-macro-srv/src/server_impl/rust_analyzer_span.rs
@@ -479,7 +479,7 @@ mod tests {
             range: TextRange::empty(TextSize::new(0)),
             anchor: span::SpanAnchor {
                 file_id: EditionedFileId::current_edition(FileId::from_raw(0)),
-                ast_id: span::ErasedFileAstId::from_raw(0.into()),
+                ast_id: span::ErasedFileAstId::from_raw(0),
             },
             ctx: SyntaxContextId::ROOT,
         };
@@ -515,7 +515,7 @@ mod tests {
             range: TextRange::empty(TextSize::new(0)),
             anchor: span::SpanAnchor {
                 file_id: EditionedFileId::current_edition(FileId::from_raw(0)),
-                ast_id: span::ErasedFileAstId::from_raw(0.into()),
+                ast_id: span::ErasedFileAstId::from_raw(0),
             },
             ctx: SyntaxContextId::ROOT,
         };
diff --git a/src/tools/rust-analyzer/crates/proc-macro-srv/src/tests/utils.rs b/src/tools/rust-analyzer/crates/proc-macro-srv/src/tests/utils.rs
index 70eff51cade..ded985877cf 100644
--- a/src/tools/rust-analyzer/crates/proc-macro-srv/src/tests/utils.rs
+++ b/src/tools/rust-analyzer/crates/proc-macro-srv/src/tests/utils.rs
@@ -69,7 +69,7 @@ fn assert_expand_impl(
         range: TextRange::new(0.into(), 150.into()),
         anchor: SpanAnchor {
             file_id: EditionedFileId::current_edition(FileId::from_raw(41)),
-            ast_id: ErasedFileAstId::from_raw(From::from(1)),
+            ast_id: ErasedFileAstId::from_raw(1),
         },
         ctx: SyntaxContextId::ROOT,
     };
@@ -77,7 +77,7 @@ fn assert_expand_impl(
         range: TextRange::new(0.into(), 100.into()),
         anchor: SpanAnchor {
             file_id: EditionedFileId::current_edition(FileId::from_raw(42)),
-            ast_id: ErasedFileAstId::from_raw(From::from(2)),
+            ast_id: ErasedFileAstId::from_raw(2),
         },
         ctx: SyntaxContextId::ROOT,
     };
diff --git a/src/tools/rust-analyzer/crates/rust-analyzer/tests/slow-tests/main.rs b/src/tools/rust-analyzer/crates/rust-analyzer/tests/slow-tests/main.rs
index b1ef4837717..c5b9fee6b16 100644
--- a/src/tools/rust-analyzer/crates/rust-analyzer/tests/slow-tests/main.rs
+++ b/src/tools/rust-analyzer/crates/rust-analyzer/tests/slow-tests/main.rs
@@ -1084,7 +1084,6 @@ fn resolve_proc_macro() {
     let sysroot = project_model::Sysroot::discover(
         &AbsPathBuf::assert_utf8(std::env::current_dir().unwrap()),
         &Default::default(),
-        false,
     );
 
     let proc_macro_server_path = sysroot.discover_proc_macro_srv().unwrap();
@@ -1125,7 +1124,6 @@ edition = "2021"
 proc-macro = true
 
 //- /bar/src/lib.rs
-extern crate proc_macro;
 use proc_macro::{Delimiter, Group, Ident, Span, TokenStream, TokenTree};
 macro_rules! t {
     ($n:literal) => {
diff --git a/src/tools/rust-analyzer/crates/span/src/ast_id.rs b/src/tools/rust-analyzer/crates/span/src/ast_id.rs
index b61baa22446..0ebd72e1514 100644
--- a/src/tools/rust-analyzer/crates/span/src/ast_id.rs
+++ b/src/tools/rust-analyzer/crates/span/src/ast_id.rs
@@ -18,7 +18,28 @@ use syntax::{ast, AstNode, AstPtr, SyntaxNode, SyntaxNodePtr};
 
 /// See crates\hir-expand\src\ast_id_map.rs
 /// This is a type erased FileAstId.
-pub type ErasedFileAstId = la_arena::Idx<syntax::SyntaxNodePtr>;
+#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
+pub struct ErasedFileAstId(u32);
+
+impl ErasedFileAstId {
+    pub const fn into_raw(self) -> u32 {
+        self.0
+    }
+    pub const fn from_raw(u32: u32) -> Self {
+        Self(u32)
+    }
+}
+
+impl fmt::Display for ErasedFileAstId {
+    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+        self.0.fmt(f)
+    }
+}
+impl fmt::Debug for ErasedFileAstId {
+    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+        self.0.fmt(f)
+    }
+}
 
 /// `AstId` points to an AST node in a specific file.
 pub struct FileAstId<N: AstIdNode> {
@@ -47,7 +68,7 @@ impl<N: AstIdNode> Hash for FileAstId<N> {
 
 impl<N: AstIdNode> fmt::Debug for FileAstId<N> {
     fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
-        write!(f, "FileAstId::<{}>({})", type_name::<N>(), self.raw.into_raw())
+        write!(f, "FileAstId::<{}>({})", type_name::<N>(), self.raw)
     }
 }
 
@@ -176,7 +197,10 @@ impl AstIdMap {
         let ptr = ptr.syntax_node_ptr();
         let hash = hash_ptr(&ptr);
         match self.map.raw_entry().from_hash(hash, |&idx| self.arena[idx] == ptr) {
-            Some((&raw, &())) => FileAstId { raw, covariant: PhantomData },
+            Some((&raw, &())) => FileAstId {
+                raw: ErasedFileAstId(raw.into_raw().into_u32()),
+                covariant: PhantomData,
+            },
             None => panic!(
                 "Can't find {:?} in AstIdMap:\n{:?}",
                 ptr,
@@ -186,18 +210,19 @@ impl AstIdMap {
     }
 
     pub fn get<N: AstIdNode>(&self, id: FileAstId<N>) -> AstPtr<N> {
-        AstPtr::try_from_raw(self.arena[id.raw]).unwrap()
+        AstPtr::try_from_raw(self.arena[Idx::from_raw(RawIdx::from_u32(id.raw.into_raw()))])
+            .unwrap()
     }
 
     pub fn get_erased(&self, id: ErasedFileAstId) -> SyntaxNodePtr {
-        self.arena[id]
+        self.arena[Idx::from_raw(RawIdx::from_u32(id.into_raw()))]
     }
 
     fn erased_ast_id(&self, item: &SyntaxNode) -> ErasedFileAstId {
         let ptr = SyntaxNodePtr::new(item);
         let hash = hash_ptr(&ptr);
         match self.map.raw_entry().from_hash(hash, |&idx| self.arena[idx] == ptr) {
-            Some((&idx, &())) => idx,
+            Some((&idx, &())) => ErasedFileAstId(idx.into_raw().into_u32()),
             None => panic!(
                 "Can't find {:?} in AstIdMap:\n{:?}",
                 item,
@@ -207,7 +232,7 @@ impl AstIdMap {
     }
 
     fn alloc(&mut self, item: &SyntaxNode) -> ErasedFileAstId {
-        self.arena.alloc(SyntaxNodePtr::new(item))
+        ErasedFileAstId(self.arena.alloc(SyntaxNodePtr::new(item)).into_raw().into_u32())
     }
 }
 
diff --git a/src/tools/rust-analyzer/crates/span/src/lib.rs b/src/tools/rust-analyzer/crates/span/src/lib.rs
index b4e21d64f81..61e4c98128a 100644
--- a/src/tools/rust-analyzer/crates/span/src/lib.rs
+++ b/src/tools/rust-analyzer/crates/span/src/lib.rs
@@ -21,15 +21,14 @@ pub use vfs::FileId;
 /// The root ast id always points to the encompassing file, using this in spans is discouraged as
 /// any range relative to it will be effectively absolute, ruining the entire point of anchored
 /// relative text ranges.
-pub const ROOT_ERASED_FILE_AST_ID: ErasedFileAstId =
-    la_arena::Idx::from_raw(la_arena::RawIdx::from_u32(0));
+pub const ROOT_ERASED_FILE_AST_ID: ErasedFileAstId = ErasedFileAstId::from_raw(0);
 
 /// FileId used as the span for syntax node fixups. Any Span containing this file id is to be
 /// considered fake.
 pub const FIXUP_ERASED_FILE_AST_ID_MARKER: ErasedFileAstId =
-    // we pick the second to last for this in case we every consider making this a NonMaxU32, this
+    // we pick the second to last for this in case we ever consider making this a NonMaxU32, this
     // is required to be stable for the proc-macro-server
-    la_arena::Idx::from_raw(la_arena::RawIdx::from_u32(!0 - 1));
+    ErasedFileAstId::from_raw(!0 - 1);
 
 pub type Span = SpanData<SyntaxContextId>;
 
diff --git a/src/tools/rust-analyzer/crates/span/src/map.rs b/src/tools/rust-analyzer/crates/span/src/map.rs
index 6269f4c30c7..c539754979d 100644
--- a/src/tools/rust-analyzer/crates/span/src/map.rs
+++ b/src/tools/rust-analyzer/crates/span/src/map.rs
@@ -119,7 +119,7 @@ impl fmt::Display for RealSpanMap {
     fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
         writeln!(f, "RealSpanMap({:?}):", self.file_id)?;
         for span in self.pairs.iter() {
-            writeln!(f, "{}: {}", u32::from(span.0), span.1.into_raw().into_u32())?;
+            writeln!(f, "{}: {}", u32::from(span.0), span.1.into_raw())?;
         }
         Ok(())
     }
diff --git a/src/tools/rust-analyzer/crates/test-fixture/src/lib.rs b/src/tools/rust-analyzer/crates/test-fixture/src/lib.rs
index 0c90127a5f4..03e85a898ab 100644
--- a/src/tools/rust-analyzer/crates/test-fixture/src/lib.rs
+++ b/src/tools/rust-analyzer/crates/test-fixture/src/lib.rs
@@ -3,7 +3,7 @@ use std::{iter, mem, str::FromStr, sync};
 
 use base_db::{
     CrateDisplayName, CrateGraph, CrateId, CrateName, CrateOrigin, Dependency, Env, FileChange,
-    FileSet, LangCrateOrigin, SourceRootDatabase, SourceRoot, Version, VfsPath,
+    FileSet, LangCrateOrigin, SourceRoot, SourceRootDatabase, Version, VfsPath,
 };
 use cfg::CfgOptions;
 use hir_expand::{