aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir_def/src/keys.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir_def/src/keys.rs')
-rw-r--r--crates/ra_hir_def/src/keys.rs58
1 files changed, 0 insertions, 58 deletions
diff --git a/crates/ra_hir_def/src/keys.rs b/crates/ra_hir_def/src/keys.rs
deleted file mode 100644
index 40a5d92b5..000000000
--- a/crates/ra_hir_def/src/keys.rs
+++ /dev/null
@@ -1,58 +0,0 @@
1//! keys to be used with `DynMap`
2
3use std::marker::PhantomData;
4
5use hir_expand::{InFile, MacroDefId};
6use rustc_hash::FxHashMap;
7use syntax::{ast, AstNode, AstPtr};
8
9use crate::{
10 dyn_map::{DynMap, Policy},
11 ConstId, EnumId, EnumVariantId, FieldId, FunctionId, ImplId, StaticId, StructId, TraitId,
12 TypeAliasId, TypeParamId, UnionId,
13};
14
15pub type Key<K, V> = crate::dyn_map::Key<InFile<K>, V, AstPtrPolicy<K, V>>;
16
17pub const FUNCTION: Key<ast::Fn, FunctionId> = Key::new();
18pub const CONST: Key<ast::Const, ConstId> = Key::new();
19pub const STATIC: Key<ast::Static, StaticId> = Key::new();
20pub const TYPE_ALIAS: Key<ast::TypeAlias, TypeAliasId> = Key::new();
21pub const IMPL: Key<ast::Impl, ImplId> = Key::new();
22pub const TRAIT: Key<ast::Trait, TraitId> = Key::new();
23pub const STRUCT: Key<ast::Struct, StructId> = Key::new();
24pub const UNION: Key<ast::Union, UnionId> = Key::new();
25pub const ENUM: Key<ast::Enum, EnumId> = Key::new();
26
27pub const VARIANT: Key<ast::Variant, EnumVariantId> = Key::new();
28pub const TUPLE_FIELD: Key<ast::TupleField, FieldId> = Key::new();
29pub const RECORD_FIELD: Key<ast::RecordField, FieldId> = Key::new();
30pub const TYPE_PARAM: Key<ast::TypeParam, TypeParamId> = Key::new();
31
32pub const MACRO: Key<ast::MacroCall, MacroDefId> = Key::new();
33
34/// XXX: AST Nodes and SyntaxNodes have identity equality semantics: nodes are
35/// equal if they point to exactly the same object.
36///
37/// In general, we do not guarantee that we have exactly one instance of a
38/// syntax tree for each file. We probably should add such guarantee, but, for
39/// the time being, we will use identity-less AstPtr comparison.
40pub struct AstPtrPolicy<AST, ID> {
41 _phantom: PhantomData<(AST, ID)>,
42}
43
44impl<AST: AstNode + 'static, ID: 'static> Policy for AstPtrPolicy<AST, ID> {
45 type K = InFile<AST>;
46 type V = ID;
47 fn insert(map: &mut DynMap, key: InFile<AST>, value: ID) {
48 let key = key.as_ref().map(AstPtr::new);
49 map.map
50 .entry::<FxHashMap<InFile<AstPtr<AST>>, ID>>()
51 .or_insert_with(Default::default)
52 .insert(key, value);
53 }
54 fn get<'a>(map: &'a DynMap, key: &InFile<AST>) -> Option<&'a ID> {
55 let key = key.as_ref().map(AstPtr::new);
56 map.map.get::<FxHashMap<InFile<AstPtr<AST>>, ID>>()?.get(&key)
57 }
58}