aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir_def/src/trace.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir_def/src/trace.rs')
-rw-r--r--crates/ra_hir_def/src/trace.rs22
1 files changed, 11 insertions, 11 deletions
diff --git a/crates/ra_hir_def/src/trace.rs b/crates/ra_hir_def/src/trace.rs
index 9769e88df..ced07577d 100644
--- a/crates/ra_hir_def/src/trace.rs
+++ b/crates/ra_hir_def/src/trace.rs
@@ -9,28 +9,28 @@
9//! absolute offsets. The `Trace` structure (inspired, at least in name, by 9//! absolute offsets. The `Trace` structure (inspired, at least in name, by
10//! Kotlin's `BindingTrace`) allows use the same code to compute both 10//! Kotlin's `BindingTrace`) allows use the same code to compute both
11//! projections. 11//! projections.
12use ra_arena::{map::ArenaMap, Arena, ArenaId, RawId}; 12use ra_arena::{map::ArenaMap, Arena, Idx, RawId};
13 13
14pub(crate) struct Trace<ID: ArenaId, T, V> { 14pub(crate) struct Trace<T, V> {
15 arena: Option<Arena<ID, T>>, 15 arena: Option<Arena<T>>,
16 map: Option<ArenaMap<ID, V>>, 16 map: Option<ArenaMap<Idx<T>, V>>,
17 len: u32, 17 len: u32,
18} 18}
19 19
20impl<ID: ra_arena::ArenaId + Copy, T, V> Trace<ID, T, V> { 20impl<T, V> Trace<T, V> {
21 pub(crate) fn new_for_arena() -> Trace<ID, T, V> { 21 pub(crate) fn new_for_arena() -> Trace<T, V> {
22 Trace { arena: Some(Arena::default()), map: None, len: 0 } 22 Trace { arena: Some(Arena::default()), map: None, len: 0 }
23 } 23 }
24 24
25 pub(crate) fn new_for_map() -> Trace<ID, T, V> { 25 pub(crate) fn new_for_map() -> Trace<T, V> {
26 Trace { arena: None, map: Some(ArenaMap::default()), len: 0 } 26 Trace { arena: None, map: Some(ArenaMap::default()), len: 0 }
27 } 27 }
28 28
29 pub(crate) fn alloc(&mut self, value: impl FnOnce() -> V, data: impl FnOnce() -> T) -> ID { 29 pub(crate) fn alloc(&mut self, value: impl FnOnce() -> V, data: impl FnOnce() -> T) -> Idx<T> {
30 let id = if let Some(arena) = &mut self.arena { 30 let id = if let Some(arena) = &mut self.arena {
31 arena.alloc(data()) 31 arena.alloc(data())
32 } else { 32 } else {
33 let id = ID::from_raw(RawId::from(self.len)); 33 let id = Idx::<T>::from_raw(RawId::from(self.len));
34 self.len += 1; 34 self.len += 1;
35 id 35 id
36 }; 36 };
@@ -41,11 +41,11 @@ impl<ID: ra_arena::ArenaId + Copy, T, V> Trace<ID, T, V> {
41 id 41 id
42 } 42 }
43 43
44 pub(crate) fn into_arena(mut self) -> Arena<ID, T> { 44 pub(crate) fn into_arena(mut self) -> Arena<T> {
45 self.arena.take().unwrap() 45 self.arena.take().unwrap()
46 } 46 }
47 47
48 pub(crate) fn into_map(mut self) -> ArenaMap<ID, V> { 48 pub(crate) fn into_map(mut self) -> ArenaMap<Idx<T>, V> {
49 self.map.take().unwrap() 49 self.map.take().unwrap()
50 } 50 }
51} 51}