From f44e01e3d0c4e8f1b8792019a11a2c082ffbd563 Mon Sep 17 00:00:00 2001 From: Chayim Refael Friedman Date: Fri, 25 Apr 2025 12:57:13 +0300 Subject: [PATCH] Switch `AstIdMap` to `hashbrown::HashTable` from the raw API It's the intended use. --- crates/span/src/ast_id.rs | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/crates/span/src/ast_id.rs b/crates/span/src/ast_id.rs index abde8855b5..228fba1fa0 100644 --- a/crates/span/src/ast_id.rs +++ b/crates/span/src/ast_id.rs @@ -132,7 +132,7 @@ pub struct AstIdMap { /// Maps stable id to unstable ptr. arena: Arena, /// Reverse: map ptr to id. - map: hashbrown::HashMap, (), ()>, + map: hashbrown::HashTable>, } impl fmt::Debug for AstIdMap { @@ -169,13 +169,13 @@ impl AstIdMap { TreeOrder::DepthFirst } }); - res.map = hashbrown::HashMap::with_capacity_and_hasher(res.arena.len(), ()); + res.map = hashbrown::HashTable::with_capacity(res.arena.len()); for (idx, ptr) in res.arena.iter() { let hash = hash_ptr(ptr); - match res.map.raw_entry_mut().from_hash(hash, |idx2| *idx2 == idx) { - hashbrown::hash_map::RawEntryMut::Occupied(_) => unreachable!(), - hashbrown::hash_map::RawEntryMut::Vacant(entry) => { - entry.insert_with_hasher(hash, idx, (), |&idx| hash_ptr(&res.arena[idx])); + match res.map.entry(hash, |&idx2| idx2 == idx, |&idx| hash_ptr(&res.arena[idx])) { + hashbrown::hash_table::Entry::Occupied(_) => unreachable!(), + hashbrown::hash_table::Entry::Vacant(entry) => { + entry.insert(idx); } } } @@ -196,8 +196,8 @@ impl AstIdMap { pub fn ast_id_for_ptr(&self, ptr: AstPtr) -> FileAstId { 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 { + match self.map.find(hash, |&idx| self.arena[idx] == ptr) { + Some(&raw) => FileAstId { raw: ErasedFileAstId(raw.into_raw().into_u32()), covariant: PhantomData, }, @@ -221,8 +221,8 @@ impl AstIdMap { 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, &())) => ErasedFileAstId(idx.into_raw().into_u32()), + match self.map.find(hash, |&idx| self.arena[idx] == ptr) { + Some(&idx) => ErasedFileAstId(idx.into_raw().into_u32()), None => panic!( "Can't find {:?} in AstIdMap:\n{:?}\n source text: {}", item,