From 3fe6f422f9ef13b9171dbeab0c5c427f729f9983 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 4 Jan 2019 16:15:50 +0300 Subject: remove id arena --- crates/ra_hir/Cargo.toml | 2 +- crates/ra_hir/src/arena.rs | 66 ------------------------------------- crates/ra_hir/src/function/scope.rs | 12 +++---- crates/ra_hir/src/ids.rs | 12 +++---- crates/ra_hir/src/lib.rs | 1 - crates/ra_hir/src/module.rs | 17 ++++++---- 6 files changed, 24 insertions(+), 86 deletions(-) delete mode 100644 crates/ra_hir/src/arena.rs (limited to 'crates/ra_hir') 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" salsa = "0.9.0" rustc-hash = "1.0" parking_lot = "0.7.0" -id-arena = "2.0" ena = "0.11" ra_syntax = { path = "../ra_syntax" } +ra_arena = { path = "../ra_arena" } ra_editor = { path = "../ra_editor" } ra_db = { path = "../ra_db" } test_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 @@ -//! A simple id-based arena, similar to https://github.com/fitzgen/id-arena. -//! We use our own version for more compact id's and to allow inherent impls -//! on Ids. - -use std::{ - fmt, - hash::{Hash, Hasher}, - marker::PhantomData, -}; - -pub struct Id { - idx: u32, - _ty: PhantomData T>, -} - -impl fmt::Debug for Id { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - f.debug_tuple("Id").field(&self.idx).finish() - } -} -impl Copy for Id {} -impl Clone for Id { - fn clone(&self) -> Id { - *self - } -} - -impl PartialEq for Id { - fn eq(&self, other: &Id) -> bool { - self.idx == other.idx - } -} - -impl Eq for Id {} - -impl Hash for Id { - fn hash(&self, h: &mut H) { - self.idx.hash(h); - } -} - -#[derive(Debug, PartialEq, Eq)] -pub(crate) struct ArenaBehavior { - _ty: PhantomData, -} - -impl id_arena::ArenaBehavior for ArenaBehavior { - type Id = Id; - fn new_arena_id() -> u32 { - 0 - } - fn new_id(_arena_id: u32, index: usize) -> Id { - Id { - idx: index as u32, - _ty: PhantomData, - } - } - fn index(id: Id) -> usize { - id.idx as usize - } - fn arena_id(_id: Id) -> u32 { - 0 - } -} - -pub(crate) type Arena = id_arena::Arena>; 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::{ algo::generate, ast::{self, ArgListOwner, LoopBodyOwner, NameOwner}, }; +use ra_arena::{Arena, RawId, impl_arena_id}; use ra_db::LocalSyntaxPtr; -use crate::{ - arena::{Arena, Id}, - Name, AsName, -}; +use crate::{Name, AsName}; -pub(crate) type ScopeId = Id; +#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] +pub struct ScopeId(RawId); +impl_arena_id!(ScopeId); #[derive(Debug, PartialEq, Eq)] pub struct FnScopes { pub self_param: Option, - scopes: Arena, + scopes: Arena, scope_for: FxHashMap, } 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 @@ use ra_db::{SourceRootId, LocationIntener, Cancelable, FileId}; use ra_syntax::{SourceFileNode, SyntaxKind, SyntaxNode, SyntaxNodeRef, SourceFile, AstNode, ast}; +use ra_arena::{Arena, RawId, impl_arena_id}; -use crate::{ - HirDatabase, PerNs, ModuleId, Module, Def, Function, Struct, Enum, - arena::{Arena, Id}, -}; +use crate::{HirDatabase, PerNs, ModuleId, Module, Def, Function, Struct, Enum}; /// hir makes a heavy use of ids: integer (u32) handlers to various things. You /// can think of id as a pointer (but without a lifetime) or a file descriptor @@ -206,7 +204,9 @@ impl DefKind { /// Identifier of item within a specific file. This is stable over reparses, so /// it's OK to use it as a salsa key/value. -pub(crate) type SourceFileItemId = Id; +#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] +pub struct SourceFileItemId(RawId); +impl_arena_id!(SourceFileItemId); #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] pub struct SourceItemId { @@ -219,7 +219,7 @@ pub struct SourceItemId { #[derive(Debug, PartialEq, Eq)] pub struct SourceFileItems { file_id: HirFileId, - arena: Arena, + arena: Arena, } impl 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; mod mock; mod query_definitions; mod path; -mod arena; pub mod source_binder; mod 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::{ ast::{self, AstNode, NameOwner}, SyntaxNode, }; +use ra_arena::{Arena, RawId, impl_arena_id}; use ra_db::{SourceRootId, FileId, Cancelable}; use relative_path::RelativePathBuf; @@ -16,7 +17,6 @@ use crate::{ Def, DefKind, DefLoc, DefId, Name, Path, PathKind, HirDatabase, SourceItemId, SourceFileItemId, Crate, HirFileId, - arena::{Arena, Id}, }; pub use self::nameres::{ModuleScope, Resolution, Namespace, PerNs}; @@ -173,6 +173,14 @@ impl Module { } } +#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] +pub struct ModuleId(RawId); +impl_arena_id!(ModuleId); + +#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] +pub struct LinkId(RawId); +impl_arena_id!(LinkId); + /// Physically, rust source is organized as a set of files, but logically it is /// organized as a tree of modules. Usually, a single file corresponds to a /// single module, but it is not nessary the case. @@ -182,8 +190,8 @@ impl Module { /// always have one parent). #[derive(Default, Debug, PartialEq, Eq)] pub struct ModuleTree { - mods: Arena, - links: Arena, + mods: Arena, + links: Arena, } impl ModuleTree { @@ -210,9 +218,6 @@ pub(crate) enum ModuleSourceNode { Module(ast::ModuleNode), } -pub type ModuleId = Id; -type LinkId = Id; - #[derive(Clone, Debug, Hash, PartialEq, Eq)] pub enum Problem { UnresolvedModule { -- cgit v1.2.3