aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir_def/src/trace.rs
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2020-03-19 17:47:43 +0000
committerGitHub <[email protected]>2020-03-19 17:47:43 +0000
commit1ba03c6995015b3143a417ed07437f0c9028a97d (patch)
treece3eb047dd9fe9005750a3b1417d95b1aa8fe01e /crates/ra_hir_def/src/trace.rs
parent988f1dda6bde576ec2457dd97a7525014609c771 (diff)
parentf840fcb2f525c13809d6a736e434155edf075a06 (diff)
Merge #3656
3656: Simplify arenas r=matklad a=matklad At the moment, Arena is paranetrized by two types: index and data. The original motivation was to allow index to be defined in the downstream crate, so that you can add inherent impls to the index. However, it seems like we've never actually used that capability, so perhaps we should switch to a generic Index impl? This PR tries this out, switching only `raw.rs` and parts of `hir_def`. wdyt? Co-authored-by: Aleksey Kladov <[email protected]>
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}