diff options
Diffstat (limited to 'crates/ra_hir_def/src/keys.rs')
-rw-r--r-- | crates/ra_hir_def/src/keys.rs | 58 |
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 | |||
3 | use std::marker::PhantomData; | ||
4 | |||
5 | use hir_expand::{InFile, MacroDefId}; | ||
6 | use rustc_hash::FxHashMap; | ||
7 | use syntax::{ast, AstNode, AstPtr}; | ||
8 | |||
9 | use crate::{ | ||
10 | dyn_map::{DynMap, Policy}, | ||
11 | ConstId, EnumId, EnumVariantId, FieldId, FunctionId, ImplId, StaticId, StructId, TraitId, | ||
12 | TypeAliasId, TypeParamId, UnionId, | ||
13 | }; | ||
14 | |||
15 | pub type Key<K, V> = crate::dyn_map::Key<InFile<K>, V, AstPtrPolicy<K, V>>; | ||
16 | |||
17 | pub const FUNCTION: Key<ast::Fn, FunctionId> = Key::new(); | ||
18 | pub const CONST: Key<ast::Const, ConstId> = Key::new(); | ||
19 | pub const STATIC: Key<ast::Static, StaticId> = Key::new(); | ||
20 | pub const TYPE_ALIAS: Key<ast::TypeAlias, TypeAliasId> = Key::new(); | ||
21 | pub const IMPL: Key<ast::Impl, ImplId> = Key::new(); | ||
22 | pub const TRAIT: Key<ast::Trait, TraitId> = Key::new(); | ||
23 | pub const STRUCT: Key<ast::Struct, StructId> = Key::new(); | ||
24 | pub const UNION: Key<ast::Union, UnionId> = Key::new(); | ||
25 | pub const ENUM: Key<ast::Enum, EnumId> = Key::new(); | ||
26 | |||
27 | pub const VARIANT: Key<ast::Variant, EnumVariantId> = Key::new(); | ||
28 | pub const TUPLE_FIELD: Key<ast::TupleField, FieldId> = Key::new(); | ||
29 | pub const RECORD_FIELD: Key<ast::RecordField, FieldId> = Key::new(); | ||
30 | pub const TYPE_PARAM: Key<ast::TypeParam, TypeParamId> = Key::new(); | ||
31 | |||
32 | pub 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. | ||
40 | pub struct AstPtrPolicy<AST, ID> { | ||
41 | _phantom: PhantomData<(AST, ID)>, | ||
42 | } | ||
43 | |||
44 | impl<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 | } | ||