Skip to main content

ParentMap

Type Alias ParentMap 

Source
pub type ParentMap = HashMap<*const Node, *const Node, FxBuildHasher>;
Expand description

Parent-map from child node to parent node, stored as raw pointers.

§Safety Invariant

Every *const Node in this map (both keys and values) must be a pointer obtained by casting a shared reference (&Node) that was derived from the same Arc<Node> tree that was passed to DeclarationProvider::build_parent_map. The pointed-to nodes must remain alive for the entire duration of any code that inspects the map.

Raw pointers are used as hash keys only for O(1) identity-based lookup. They are never dereferenced directly through this map. Safe references are recovered via the companion node_lookup map (FxHashMap<*const Node, &Node>) that re-derives &Node from the live Arc<Node> tree at call time.

§Ownership and Lifetime

The Arc<Node> that backs the tree must outlive every &ParentMap borrow. In the LSP server this is guaranteed because both the Arc<Node> and the ParentMap are stored together in DocumentState, guarded by a parking_lot::Mutex.

§Thread Safety

*const Node is !Send + !Sync. Consequently ParentMap is !Send + !Sync and must remain on the thread that owns the Arc<Node> tree. LSP request handlers satisfy this requirement because they process each request synchronously within a single thread context.

Aliased Type§

pub struct ParentMap { /* private fields */ }