mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-25 08:13:41 +00:00
remove id arena
This commit is contained in:
parent
291d578938
commit
3fe6f422f9
8
Cargo.lock
generated
8
Cargo.lock
generated
@ -370,11 +370,6 @@ name = "humansize"
|
||||
version = "1.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "id-arena"
|
||||
version = "2.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "idna"
|
||||
version = "0.1.5"
|
||||
@ -733,9 +728,9 @@ dependencies = [
|
||||
"arrayvec 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"ena 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"flexi_logger 0.10.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"id-arena 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"parking_lot 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"ra_arena 0.1.0",
|
||||
"ra_db 0.1.0",
|
||||
"ra_editor 0.1.0",
|
||||
"ra_syntax 0.1.0",
|
||||
@ -1534,7 +1529,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
"checksum glob 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "8be18de09a56b60ed0edf84bc9df007e30040691af7acd1c41874faac5895bfb"
|
||||
"checksum heck 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "20564e78d53d2bb135c343b3f47714a56af2061f1c928fdb541dc7b9fdd94205"
|
||||
"checksum humansize 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b6cab2627acfc432780848602f3f558f7e9dd427352224b0d9324025796d2a5e"
|
||||
"checksum id-arena 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3a7250033feafee46a1cecd2c2616a64aec1d064f38c9ae2bdd297728542843e"
|
||||
"checksum idna 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "38f09e0f0b1fb55fdee1f17470ad800da77af5186a1a76c026b679358b7e844e"
|
||||
"checksum im 12.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ae9c7f9bb8aee47fc16d535a705f7867a9fc83bb822e5e1043bb98e77ffeed3c"
|
||||
"checksum indexmap 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7e81a7c05f79578dbc15793d8b619db9ba32b4577003ef3af1a91c416798c58d"
|
||||
|
@ -33,7 +33,7 @@ impl fmt::Display for RawId {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub struct Arena<ID: ArenaId, T> {
|
||||
data: Vec<T>,
|
||||
_ty: PhantomData<ID>,
|
||||
|
@ -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" }
|
||||
|
@ -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<T> {
|
||||
idx: u32,
|
||||
_ty: PhantomData<fn() -> T>,
|
||||
}
|
||||
|
||||
impl<T> fmt::Debug for Id<T> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
f.debug_tuple("Id").field(&self.idx).finish()
|
||||
}
|
||||
}
|
||||
impl<T> Copy for Id<T> {}
|
||||
impl<T> Clone for Id<T> {
|
||||
fn clone(&self) -> Id<T> {
|
||||
*self
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> PartialEq for Id<T> {
|
||||
fn eq(&self, other: &Id<T>) -> bool {
|
||||
self.idx == other.idx
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Eq for Id<T> {}
|
||||
|
||||
impl<T> Hash for Id<T> {
|
||||
fn hash<H: Hasher>(&self, h: &mut H) {
|
||||
self.idx.hash(h);
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Eq)]
|
||||
pub(crate) struct ArenaBehavior<T> {
|
||||
_ty: PhantomData<T>,
|
||||
}
|
||||
|
||||
impl<T> id_arena::ArenaBehavior for ArenaBehavior<T> {
|
||||
type Id = Id<T>;
|
||||
fn new_arena_id() -> u32 {
|
||||
0
|
||||
}
|
||||
fn new_id(_arena_id: u32, index: usize) -> Id<T> {
|
||||
Id {
|
||||
idx: index as u32,
|
||||
_ty: PhantomData,
|
||||
}
|
||||
}
|
||||
fn index(id: Id<T>) -> usize {
|
||||
id.idx as usize
|
||||
}
|
||||
fn arena_id(_id: Id<T>) -> u32 {
|
||||
0
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) type Arena<T> = id_arena::Arena<T, ArenaBehavior<T>>;
|
@ -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<ScopeData>;
|
||||
#[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<LocalSyntaxPtr>,
|
||||
scopes: Arena<ScopeData>,
|
||||
scopes: Arena<ScopeId, ScopeData>,
|
||||
scope_for: FxHashMap<LocalSyntaxPtr, ScopeId>,
|
||||
}
|
||||
|
||||
|
@ -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<SyntaxNode>;
|
||||
#[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<SyntaxNode>,
|
||||
arena: Arena<SourceFileItemId, SyntaxNode>,
|
||||
}
|
||||
|
||||
impl SourceFileItems {
|
||||
|
@ -19,7 +19,6 @@ pub mod db;
|
||||
mod mock;
|
||||
mod query_definitions;
|
||||
mod path;
|
||||
mod arena;
|
||||
pub mod source_binder;
|
||||
|
||||
mod ids;
|
||||
|
@ -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<ModuleData>,
|
||||
links: Arena<LinkData>,
|
||||
mods: Arena<ModuleId, ModuleData>,
|
||||
links: Arena<LinkId, LinkData>,
|
||||
}
|
||||
|
||||
impl ModuleTree {
|
||||
@ -210,9 +218,6 @@ pub(crate) enum ModuleSourceNode {
|
||||
Module(ast::ModuleNode),
|
||||
}
|
||||
|
||||
pub type ModuleId = Id<ModuleData>;
|
||||
type LinkId = Id<LinkData>;
|
||||
|
||||
#[derive(Clone, Debug, Hash, PartialEq, Eq)]
|
||||
pub enum Problem {
|
||||
UnresolvedModule {
|
||||
|
Loading…
Reference in New Issue
Block a user