aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Cargo.lock8
-rw-r--r--crates/ra_arena/src/lib.rs2
-rw-r--r--crates/ra_hir/Cargo.toml2
-rw-r--r--crates/ra_hir/src/arena.rs66
-rw-r--r--crates/ra_hir/src/function/scope.rs12
-rw-r--r--crates/ra_hir/src/ids.rs12
-rw-r--r--crates/ra_hir/src/lib.rs1
-rw-r--r--crates/ra_hir/src/module.rs17
8 files changed, 26 insertions, 94 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 4666347f8..b06058688 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -371,11 +371,6 @@ version = "1.1.0"
371source = "registry+https://github.com/rust-lang/crates.io-index" 371source = "registry+https://github.com/rust-lang/crates.io-index"
372 372
373[[package]] 373[[package]]
374name = "id-arena"
375version = "2.0.0"
376source = "registry+https://github.com/rust-lang/crates.io-index"
377
378[[package]]
379name = "idna" 374name = "idna"
380version = "0.1.5" 375version = "0.1.5"
381source = "registry+https://github.com/rust-lang/crates.io-index" 376source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -733,9 +728,9 @@ dependencies = [
733 "arrayvec 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)", 728 "arrayvec 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)",
734 "ena 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", 729 "ena 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)",
735 "flexi_logger 0.10.3 (registry+https://github.com/rust-lang/crates.io-index)", 730 "flexi_logger 0.10.3 (registry+https://github.com/rust-lang/crates.io-index)",
736 "id-arena 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
737 "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", 731 "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
738 "parking_lot 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", 732 "parking_lot 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
733 "ra_arena 0.1.0",
739 "ra_db 0.1.0", 734 "ra_db 0.1.0",
740 "ra_editor 0.1.0", 735 "ra_editor 0.1.0",
741 "ra_syntax 0.1.0", 736 "ra_syntax 0.1.0",
@@ -1534,7 +1529,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
1534"checksum glob 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "8be18de09a56b60ed0edf84bc9df007e30040691af7acd1c41874faac5895bfb" 1529"checksum glob 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "8be18de09a56b60ed0edf84bc9df007e30040691af7acd1c41874faac5895bfb"
1535"checksum heck 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "20564e78d53d2bb135c343b3f47714a56af2061f1c928fdb541dc7b9fdd94205" 1530"checksum heck 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "20564e78d53d2bb135c343b3f47714a56af2061f1c928fdb541dc7b9fdd94205"
1536"checksum humansize 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b6cab2627acfc432780848602f3f558f7e9dd427352224b0d9324025796d2a5e" 1531"checksum humansize 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b6cab2627acfc432780848602f3f558f7e9dd427352224b0d9324025796d2a5e"
1537"checksum id-arena 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3a7250033feafee46a1cecd2c2616a64aec1d064f38c9ae2bdd297728542843e"
1538"checksum idna 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "38f09e0f0b1fb55fdee1f17470ad800da77af5186a1a76c026b679358b7e844e" 1532"checksum idna 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "38f09e0f0b1fb55fdee1f17470ad800da77af5186a1a76c026b679358b7e844e"
1539"checksum im 12.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ae9c7f9bb8aee47fc16d535a705f7867a9fc83bb822e5e1043bb98e77ffeed3c" 1533"checksum im 12.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ae9c7f9bb8aee47fc16d535a705f7867a9fc83bb822e5e1043bb98e77ffeed3c"
1540"checksum indexmap 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7e81a7c05f79578dbc15793d8b619db9ba32b4577003ef3af1a91c416798c58d" 1534"checksum indexmap 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7e81a7c05f79578dbc15793d8b619db9ba32b4577003ef3af1a91c416798c58d"
diff --git a/crates/ra_arena/src/lib.rs b/crates/ra_arena/src/lib.rs
index 44d9e826b..a5eeb4118 100644
--- a/crates/ra_arena/src/lib.rs
+++ b/crates/ra_arena/src/lib.rs
@@ -33,7 +33,7 @@ impl fmt::Display for RawId {
33 } 33 }
34} 34}
35 35
36#[derive(Clone, Debug)] 36#[derive(Clone, Debug, PartialEq, Eq)]
37pub struct Arena<ID: ArenaId, T> { 37pub struct Arena<ID: ArenaId, T> {
38 data: Vec<T>, 38 data: Vec<T>,
39 _ty: PhantomData<ID>, 39 _ty: PhantomData<ID>,
diff --git a/crates/ra_hir/Cargo.toml b/crates/ra_hir/Cargo.toml
index c3fbd327d..8c0cf4b86 100644
--- a/crates/ra_hir/Cargo.toml
+++ b/crates/ra_hir/Cargo.toml
@@ -11,9 +11,9 @@ relative-path = "0.4.0"
11salsa = "0.9.0" 11salsa = "0.9.0"
12rustc-hash = "1.0" 12rustc-hash = "1.0"
13parking_lot = "0.7.0" 13parking_lot = "0.7.0"
14id-arena = "2.0"
15ena = "0.11" 14ena = "0.11"
16ra_syntax = { path = "../ra_syntax" } 15ra_syntax = { path = "../ra_syntax" }
16ra_arena = { path = "../ra_arena" }
17ra_editor = { path = "../ra_editor" } 17ra_editor = { path = "../ra_editor" }
18ra_db = { path = "../ra_db" } 18ra_db = { path = "../ra_db" }
19test_utils = { path = "../test_utils" } 19test_utils = { path = "../test_utils" }
diff --git a/crates/ra_hir/src/arena.rs b/crates/ra_hir/src/arena.rs
deleted file mode 100644
index d4f9d9cb9..000000000
--- a/crates/ra_hir/src/arena.rs
+++ /dev/null
@@ -1,66 +0,0 @@
1//! A simple id-based arena, similar to https://github.com/fitzgen/id-arena.
2//! We use our own version for more compact id's and to allow inherent impls
3//! on Ids.
4
5use std::{
6 fmt,
7 hash::{Hash, Hasher},
8 marker::PhantomData,
9};
10
11pub struct Id<T> {
12 idx: u32,
13 _ty: PhantomData<fn() -> T>,
14}
15
16impl<T> fmt::Debug for Id<T> {
17 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
18 f.debug_tuple("Id").field(&self.idx).finish()
19 }
20}
21impl<T> Copy for Id<T> {}
22impl<T> Clone for Id<T> {
23 fn clone(&self) -> Id<T> {
24 *self
25 }
26}
27
28impl<T> PartialEq for Id<T> {
29 fn eq(&self, other: &Id<T>) -> bool {
30 self.idx == other.idx
31 }
32}
33
34impl<T> Eq for Id<T> {}
35
36impl<T> Hash for Id<T> {
37 fn hash<H: Hasher>(&self, h: &mut H) {
38 self.idx.hash(h);
39 }
40}
41
42#[derive(Debug, PartialEq, Eq)]
43pub(crate) struct ArenaBehavior<T> {
44 _ty: PhantomData<T>,
45}
46
47impl<T> id_arena::ArenaBehavior for ArenaBehavior<T> {
48 type Id = Id<T>;
49 fn new_arena_id() -> u32 {
50 0
51 }
52 fn new_id(_arena_id: u32, index: usize) -> Id<T> {
53 Id {
54 idx: index as u32,
55 _ty: PhantomData,
56 }
57 }
58 fn index(id: Id<T>) -> usize {
59 id.idx as usize
60 }
61 fn arena_id(_id: Id<T>) -> u32 {
62 0
63 }
64}
65
66pub(crate) type Arena<T> = id_arena::Arena<T, ArenaBehavior<T>>;
diff --git a/crates/ra_hir/src/function/scope.rs b/crates/ra_hir/src/function/scope.rs
index 3e4cfad0c..42bfe4f32 100644
--- a/crates/ra_hir/src/function/scope.rs
+++ b/crates/ra_hir/src/function/scope.rs
@@ -5,19 +5,19 @@ use ra_syntax::{
5 algo::generate, 5 algo::generate,
6 ast::{self, ArgListOwner, LoopBodyOwner, NameOwner}, 6 ast::{self, ArgListOwner, LoopBodyOwner, NameOwner},
7}; 7};
8use ra_arena::{Arena, RawId, impl_arena_id};
8use ra_db::LocalSyntaxPtr; 9use ra_db::LocalSyntaxPtr;
9 10
10use crate::{ 11use crate::{Name, AsName};
11 arena::{Arena, Id},
12 Name, AsName,
13};
14 12
15pub(crate) type ScopeId = Id<ScopeData>; 13#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
14pub struct ScopeId(RawId);
15impl_arena_id!(ScopeId);
16 16
17#[derive(Debug, PartialEq, Eq)] 17#[derive(Debug, PartialEq, Eq)]
18pub struct FnScopes { 18pub struct FnScopes {
19 pub self_param: Option<LocalSyntaxPtr>, 19 pub self_param: Option<LocalSyntaxPtr>,
20 scopes: Arena<ScopeData>, 20 scopes: Arena<ScopeId, ScopeData>,
21 scope_for: FxHashMap<LocalSyntaxPtr, ScopeId>, 21 scope_for: FxHashMap<LocalSyntaxPtr, ScopeId>,
22} 22}
23 23
diff --git a/crates/ra_hir/src/ids.rs b/crates/ra_hir/src/ids.rs
index 4c7ebe3ea..66adacc7d 100644
--- a/crates/ra_hir/src/ids.rs
+++ b/crates/ra_hir/src/ids.rs
@@ -1,10 +1,8 @@
1use ra_db::{SourceRootId, LocationIntener, Cancelable, FileId}; 1use ra_db::{SourceRootId, LocationIntener, Cancelable, FileId};
2use ra_syntax::{SourceFileNode, SyntaxKind, SyntaxNode, SyntaxNodeRef, SourceFile, AstNode, ast}; 2use ra_syntax::{SourceFileNode, SyntaxKind, SyntaxNode, SyntaxNodeRef, SourceFile, AstNode, ast};
3use ra_arena::{Arena, RawId, impl_arena_id};
3 4
4use crate::{ 5use crate::{HirDatabase, PerNs, ModuleId, Module, Def, Function, Struct, Enum};
5 HirDatabase, PerNs, ModuleId, Module, Def, Function, Struct, Enum,
6 arena::{Arena, Id},
7};
8 6
9/// hir makes a heavy use of ids: integer (u32) handlers to various things. You 7/// hir makes a heavy use of ids: integer (u32) handlers to various things. You
10/// can think of id as a pointer (but without a lifetime) or a file descriptor 8/// can think of id as a pointer (but without a lifetime) or a file descriptor
@@ -206,7 +204,9 @@ impl DefKind {
206 204
207/// Identifier of item within a specific file. This is stable over reparses, so 205/// Identifier of item within a specific file. This is stable over reparses, so
208/// it's OK to use it as a salsa key/value. 206/// it's OK to use it as a salsa key/value.
209pub(crate) type SourceFileItemId = Id<SyntaxNode>; 207#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
208pub struct SourceFileItemId(RawId);
209impl_arena_id!(SourceFileItemId);
210 210
211#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] 211#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
212pub struct SourceItemId { 212pub struct SourceItemId {
@@ -219,7 +219,7 @@ pub struct SourceItemId {
219#[derive(Debug, PartialEq, Eq)] 219#[derive(Debug, PartialEq, Eq)]
220pub struct SourceFileItems { 220pub struct SourceFileItems {
221 file_id: HirFileId, 221 file_id: HirFileId,
222 arena: Arena<SyntaxNode>, 222 arena: Arena<SourceFileItemId, SyntaxNode>,
223} 223}
224 224
225impl SourceFileItems { 225impl SourceFileItems {
diff --git a/crates/ra_hir/src/lib.rs b/crates/ra_hir/src/lib.rs
index 8ee52a466..344b543b6 100644
--- a/crates/ra_hir/src/lib.rs
+++ b/crates/ra_hir/src/lib.rs
@@ -19,7 +19,6 @@ pub mod db;
19mod mock; 19mod mock;
20mod query_definitions; 20mod query_definitions;
21mod path; 21mod path;
22mod arena;
23pub mod source_binder; 22pub mod source_binder;
24 23
25mod ids; 24mod ids;
diff --git a/crates/ra_hir/src/module.rs b/crates/ra_hir/src/module.rs
index a53b69d20..c70dc54dd 100644
--- a/crates/ra_hir/src/module.rs
+++ b/crates/ra_hir/src/module.rs
@@ -9,6 +9,7 @@ use ra_syntax::{
9 ast::{self, AstNode, NameOwner}, 9 ast::{self, AstNode, NameOwner},
10 SyntaxNode, 10 SyntaxNode,
11}; 11};
12use ra_arena::{Arena, RawId, impl_arena_id};
12use ra_db::{SourceRootId, FileId, Cancelable}; 13use ra_db::{SourceRootId, FileId, Cancelable};
13use relative_path::RelativePathBuf; 14use relative_path::RelativePathBuf;
14 15
@@ -16,7 +17,6 @@ use crate::{
16 Def, DefKind, DefLoc, DefId, 17 Def, DefKind, DefLoc, DefId,
17 Name, Path, PathKind, HirDatabase, SourceItemId, SourceFileItemId, Crate, 18 Name, Path, PathKind, HirDatabase, SourceItemId, SourceFileItemId, Crate,
18 HirFileId, 19 HirFileId,
19 arena::{Arena, Id},
20}; 20};
21 21
22pub use self::nameres::{ModuleScope, Resolution, Namespace, PerNs}; 22pub use self::nameres::{ModuleScope, Resolution, Namespace, PerNs};
@@ -173,6 +173,14 @@ impl Module {
173 } 173 }
174} 174}
175 175
176#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
177pub struct ModuleId(RawId);
178impl_arena_id!(ModuleId);
179
180#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
181pub struct LinkId(RawId);
182impl_arena_id!(LinkId);
183
176/// Physically, rust source is organized as a set of files, but logically it is 184/// Physically, rust source is organized as a set of files, but logically it is
177/// organized as a tree of modules. Usually, a single file corresponds to a 185/// organized as a tree of modules. Usually, a single file corresponds to a
178/// single module, but it is not nessary the case. 186/// single module, but it is not nessary the case.
@@ -182,8 +190,8 @@ impl Module {
182/// always have one parent). 190/// always have one parent).
183#[derive(Default, Debug, PartialEq, Eq)] 191#[derive(Default, Debug, PartialEq, Eq)]
184pub struct ModuleTree { 192pub struct ModuleTree {
185 mods: Arena<ModuleData>, 193 mods: Arena<ModuleId, ModuleData>,
186 links: Arena<LinkData>, 194 links: Arena<LinkId, LinkData>,
187} 195}
188 196
189impl ModuleTree { 197impl ModuleTree {
@@ -210,9 +218,6 @@ pub(crate) enum ModuleSourceNode {
210 Module(ast::ModuleNode), 218 Module(ast::ModuleNode),
211} 219}
212 220
213pub type ModuleId = Id<ModuleData>;
214type LinkId = Id<LinkData>;
215
216#[derive(Clone, Debug, Hash, PartialEq, Eq)] 221#[derive(Clone, Debug, Hash, PartialEq, Eq)]
217pub enum Problem { 222pub enum Problem {
218 UnresolvedModule { 223 UnresolvedModule {