diff options
author | bors[bot] <bors[bot]@users.noreply.github.com> | 2018-11-27 11:23:29 +0000 |
---|---|---|
committer | bors[bot] <bors[bot]@users.noreply.github.com> | 2018-11-27 11:23:29 +0000 |
commit | 8e37208040a456d4e481472f69b3b584655ee90f (patch) | |
tree | d7c7674e657443a104cc06a24c1254e8396ca286 | |
parent | 7adbea9c425847ee7193d3eaba2bef5ba4f0d4bd (diff) | |
parent | ed023929d5f3a53a3989371452291176d3ce543c (diff) |
Merge #244
244: Switch to id-arena r=matklad a=matklad
Co-authored-by: Aleksey Kladov <[email protected]>
-rw-r--r-- | Cargo.lock | 7 | ||||
-rw-r--r-- | crates/ra_analysis/Cargo.toml | 1 | ||||
-rw-r--r-- | crates/ra_analysis/src/arena.rs | 56 | ||||
-rw-r--r-- | crates/ra_analysis/src/descriptors/function/scope.rs | 4 | ||||
-rw-r--r-- | crates/ra_analysis/src/descriptors/module/mod.rs | 8 |
5 files changed, 27 insertions, 49 deletions
diff --git a/Cargo.lock b/Cargo.lock index c6ed5107c..b4d466fb6 100644 --- a/Cargo.lock +++ b/Cargo.lock | |||
@@ -351,6 +351,11 @@ version = "1.1.0" | |||
351 | source = "registry+https://github.com/rust-lang/crates.io-index" | 351 | source = "registry+https://github.com/rust-lang/crates.io-index" |
352 | 352 | ||
353 | [[package]] | 353 | [[package]] |
354 | name = "id-arena" | ||
355 | version = "1.0.2" | ||
356 | source = "git+https://github.com/fitzgen/id-arena/?rev=43ecd67#43ecd67d81f707dfdc1b0d067b96c17f7a7ef9b8" | ||
357 | |||
358 | [[package]] | ||
354 | name = "idna" | 359 | name = "idna" |
355 | version = "0.1.5" | 360 | version = "0.1.5" |
356 | source = "registry+https://github.com/rust-lang/crates.io-index" | 361 | source = "registry+https://github.com/rust-lang/crates.io-index" |
@@ -599,6 +604,7 @@ name = "ra_analysis" | |||
599 | version = "0.1.0" | 604 | version = "0.1.0" |
600 | dependencies = [ | 605 | dependencies = [ |
601 | "fst 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", | 606 | "fst 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", |
607 | "id-arena 1.0.2 (git+https://github.com/fitzgen/id-arena/?rev=43ecd67)", | ||
602 | "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", | 608 | "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", |
603 | "parking_lot 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)", | 609 | "parking_lot 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)", |
604 | "ra_editor 0.1.0", | 610 | "ra_editor 0.1.0", |
@@ -1301,6 +1307,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" | |||
1301 | "checksum glob 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "8be18de09a56b60ed0edf84bc9df007e30040691af7acd1c41874faac5895bfb" | 1307 | "checksum glob 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "8be18de09a56b60ed0edf84bc9df007e30040691af7acd1c41874faac5895bfb" |
1302 | "checksum heck 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ea04fa3ead4e05e51a7c806fc07271fdbde4e246a6c6d1efd52e72230b771b82" | 1308 | "checksum heck 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ea04fa3ead4e05e51a7c806fc07271fdbde4e246a6c6d1efd52e72230b771b82" |
1303 | "checksum humansize 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b6cab2627acfc432780848602f3f558f7e9dd427352224b0d9324025796d2a5e" | 1309 | "checksum humansize 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b6cab2627acfc432780848602f3f558f7e9dd427352224b0d9324025796d2a5e" |
1310 | "checksum id-arena 1.0.2 (git+https://github.com/fitzgen/id-arena/?rev=43ecd67)" = "<none>" | ||
1304 | "checksum idna 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "38f09e0f0b1fb55fdee1f17470ad800da77af5186a1a76c026b679358b7e844e" | 1311 | "checksum idna 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "38f09e0f0b1fb55fdee1f17470ad800da77af5186a1a76c026b679358b7e844e" |
1305 | "checksum im 12.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ae9c7f9bb8aee47fc16d535a705f7867a9fc83bb822e5e1043bb98e77ffeed3c" | 1312 | "checksum im 12.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ae9c7f9bb8aee47fc16d535a705f7867a9fc83bb822e5e1043bb98e77ffeed3c" |
1306 | "checksum indexmap 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7e81a7c05f79578dbc15793d8b619db9ba32b4577003ef3af1a91c416798c58d" | 1313 | "checksum indexmap 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7e81a7c05f79578dbc15793d8b619db9ba32b4577003ef3af1a91c416798c58d" |
diff --git a/crates/ra_analysis/Cargo.toml b/crates/ra_analysis/Cargo.toml index b4a1a09b5..5dae45857 100644 --- a/crates/ra_analysis/Cargo.toml +++ b/crates/ra_analysis/Cargo.toml | |||
@@ -12,6 +12,7 @@ fst = "0.3.1" | |||
12 | salsa = "0.8.0" | 12 | salsa = "0.8.0" |
13 | rustc-hash = "1.0" | 13 | rustc-hash = "1.0" |
14 | parking_lot = "0.6.4" | 14 | parking_lot = "0.6.4" |
15 | id-arena = { git = "https://github.com/fitzgen/id-arena/", rev = "43ecd67" } | ||
15 | ra_syntax = { path = "../ra_syntax" } | 16 | ra_syntax = { path = "../ra_syntax" } |
16 | ra_editor = { path = "../ra_editor" } | 17 | ra_editor = { path = "../ra_editor" } |
17 | test_utils = { path = "../test_utils" } | 18 | test_utils = { path = "../test_utils" } |
diff --git a/crates/ra_analysis/src/arena.rs b/crates/ra_analysis/src/arena.rs index 98ed89274..a752ec0c1 100644 --- a/crates/ra_analysis/src/arena.rs +++ b/crates/ra_analysis/src/arena.rs | |||
@@ -4,7 +4,6 @@ | |||
4 | 4 | ||
5 | use std::{ | 5 | use std::{ |
6 | fmt, | 6 | fmt, |
7 | ops::{Index, IndexMut}, | ||
8 | hash::{Hash, Hasher}, | 7 | hash::{Hash, Hasher}, |
9 | marker::PhantomData, | 8 | marker::PhantomData, |
10 | }; | 9 | }; |
@@ -41,56 +40,27 @@ impl<T> Hash for Id<T> { | |||
41 | } | 40 | } |
42 | 41 | ||
43 | #[derive(Debug, PartialEq, Eq)] | 42 | #[derive(Debug, PartialEq, Eq)] |
44 | pub(crate) struct Arena<T> { | 43 | pub(crate) struct ArenaBehavior<T> { |
45 | data: Vec<T>, | 44 | _ty: PhantomData<T>, |
46 | } | 45 | } |
47 | 46 | ||
48 | impl<T> Default for Arena<T> { | 47 | impl<T> id_arena::ArenaBehavior for ArenaBehavior<T> { |
49 | fn default() -> Arena<T> { | 48 | type Id = Id<T>; |
50 | Arena { data: Vec::new() } | 49 | fn new_arena_id() -> usize { |
50 | 0 | ||
51 | } | 51 | } |
52 | } | 52 | fn new_id(_arena_id: usize, index: usize) -> Id<T> { |
53 | |||
54 | impl<T> Arena<T> { | ||
55 | pub(crate) fn push(&mut self, value: T) -> Id<T> { | ||
56 | let id = self.data.len() as u32; | ||
57 | self.data.push(value); | ||
58 | Id { | 53 | Id { |
59 | idx: id as u32, | 54 | idx: index as u32, |
60 | _ty: PhantomData, | 55 | _ty: PhantomData, |
61 | } | 56 | } |
62 | } | 57 | } |
63 | 58 | fn index(id: Id<T>) -> usize { | |
64 | pub(crate) fn keys<'a>(&'a self) -> impl Iterator<Item = Id<T>> + 'a { | 59 | id.idx as usize |
65 | (0..(self.data.len() as u32)).into_iter().map(|idx| Id { | ||
66 | idx, | ||
67 | _ty: PhantomData, | ||
68 | }) | ||
69 | } | ||
70 | |||
71 | pub(crate) fn items<'a>(&'a self) -> impl Iterator<Item = (Id<T>, &T)> + 'a { | ||
72 | self.data.iter().enumerate().map(|(idx, item)| { | ||
73 | let idx = idx as u32; | ||
74 | ( | ||
75 | Id { | ||
76 | idx, | ||
77 | _ty: PhantomData, | ||
78 | }, | ||
79 | item, | ||
80 | ) | ||
81 | }) | ||
82 | } | 60 | } |
83 | } | 61 | fn arena_id(_id: Id<T>) -> usize { |
84 | 62 | 0 | |
85 | impl<T> Index<Id<T>> for Arena<T> { | ||
86 | type Output = T; | ||
87 | fn index(&self, id: Id<T>) -> &T { | ||
88 | &self.data[id.idx as usize] | ||
89 | } | 63 | } |
90 | } | 64 | } |
91 | 65 | ||
92 | impl<T> IndexMut<Id<T>> for Arena<T> { | 66 | pub(crate) type Arena<T> = id_arena::Arena<T, ArenaBehavior<T>>; |
93 | fn index_mut(&mut self, id: Id<T>) -> &mut T { | ||
94 | &mut self.data[id.idx as usize] | ||
95 | } | ||
96 | } | ||
diff --git a/crates/ra_analysis/src/descriptors/function/scope.rs b/crates/ra_analysis/src/descriptors/function/scope.rs index 54d7fa456..5307a0a8e 100644 --- a/crates/ra_analysis/src/descriptors/function/scope.rs +++ b/crates/ra_analysis/src/descriptors/function/scope.rs | |||
@@ -58,13 +58,13 @@ impl FnScopes { | |||
58 | }) | 58 | }) |
59 | } | 59 | } |
60 | fn root_scope(&mut self) -> ScopeId { | 60 | fn root_scope(&mut self) -> ScopeId { |
61 | self.scopes.push(ScopeData { | 61 | self.scopes.alloc(ScopeData { |
62 | parent: None, | 62 | parent: None, |
63 | entries: vec![], | 63 | entries: vec![], |
64 | }) | 64 | }) |
65 | } | 65 | } |
66 | fn new_scope(&mut self, parent: ScopeId) -> ScopeId { | 66 | fn new_scope(&mut self, parent: ScopeId) -> ScopeId { |
67 | self.scopes.push(ScopeData { | 67 | self.scopes.alloc(ScopeData { |
68 | parent: Some(parent), | 68 | parent: Some(parent), |
69 | entries: vec![], | 69 | entries: vec![], |
70 | }) | 70 | }) |
diff --git a/crates/ra_analysis/src/descriptors/module/mod.rs b/crates/ra_analysis/src/descriptors/module/mod.rs index 54ff95b66..a6eaec178 100644 --- a/crates/ra_analysis/src/descriptors/module/mod.rs +++ b/crates/ra_analysis/src/descriptors/module/mod.rs | |||
@@ -166,12 +166,12 @@ pub(crate) struct ModuleTree { | |||
166 | 166 | ||
167 | impl ModuleTree { | 167 | impl ModuleTree { |
168 | fn modules<'a>(&'a self) -> impl Iterator<Item = ModuleId> + 'a { | 168 | fn modules<'a>(&'a self) -> impl Iterator<Item = ModuleId> + 'a { |
169 | self.mods.keys() | 169 | self.mods.iter().map(|(id, _)| id) |
170 | } | 170 | } |
171 | 171 | ||
172 | fn modules_for_source(&self, source: ModuleSource) -> Vec<ModuleId> { | 172 | fn modules_for_source(&self, source: ModuleSource) -> Vec<ModuleId> { |
173 | self.mods | 173 | self.mods |
174 | .items() | 174 | .iter() |
175 | .filter(|(_idx, it)| it.source == source) | 175 | .filter(|(_idx, it)| it.source == source) |
176 | .map(|(idx, _)| idx) | 176 | .map(|(idx, _)| idx) |
177 | .collect() | 177 | .collect() |
@@ -333,11 +333,11 @@ struct LinkData { | |||
333 | 333 | ||
334 | impl ModuleTree { | 334 | impl ModuleTree { |
335 | fn push_mod(&mut self, data: ModuleData) -> ModuleId { | 335 | fn push_mod(&mut self, data: ModuleData) -> ModuleId { |
336 | self.mods.push(data) | 336 | self.mods.alloc(data) |
337 | } | 337 | } |
338 | fn push_link(&mut self, data: LinkData) -> LinkId { | 338 | fn push_link(&mut self, data: LinkData) -> LinkId { |
339 | let owner = data.owner; | 339 | let owner = data.owner; |
340 | let id = self.links.push(data); | 340 | let id = self.links.alloc(data); |
341 | self.mods[owner].children.push(id); | 341 | self.mods[owner].children.push(id); |
342 | id | 342 | id |
343 | } | 343 | } |