Remove old location infra

This commit is contained in:
Aleksey Kladov 2019-12-12 15:13:05 +01:00
parent 56710f119b
commit 7a255a2f93
2 changed files with 6 additions and 63 deletions

View file

@ -8,8 +8,8 @@ use rustc_hash::FxHashMap;
use crate::{
dyn_map::{DynMap, Policy},
ConstId, EnumVariantId, FunctionId, ImplId, StaticId, StructFieldId, StructId, TraitId,
TypeAliasId, TypeParamId, EnumId, UnionId,
ConstId, EnumId, EnumVariantId, FunctionId, ImplId, StaticId, StructFieldId, StructId, TraitId,
TypeAliasId, TypeParamId, UnionId,
};
type Key<K, V> = crate::dyn_map::Key<InFile<K>, V, AstPtrPolicy<K, V>>;

View file

@ -40,14 +40,14 @@ mod test_db;
#[cfg(test)]
mod marks;
use std::hash::{Hash, Hasher};
use std::hash::Hash;
use hir_expand::{ast_id_map::FileAstId, db::AstDatabase, AstId, HirFileId, InFile, MacroDefId};
use hir_expand::{ast_id_map::FileAstId, AstId, HirFileId, InFile, MacroDefId};
use ra_arena::{impl_arena_id, RawId};
use ra_db::{impl_intern_key, salsa, CrateId};
use ra_syntax::{ast, AstNode};
use ra_syntax::ast;
use crate::{builtin_type::BuiltinType, db::InternDatabase};
use crate::builtin_type::BuiltinType;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct LocalImportId(RawId);
@ -65,63 +65,6 @@ pub struct ModuleId {
pub struct LocalModuleId(RawId);
impl_arena_id!(LocalModuleId);
#[derive(Debug)]
pub struct ItemLoc<N: AstNode> {
pub(crate) module: ModuleId,
ast_id: AstId<N>,
}
impl<N: AstNode> PartialEq for ItemLoc<N> {
fn eq(&self, other: &Self) -> bool {
self.module == other.module && self.ast_id == other.ast_id
}
}
impl<N: AstNode> Eq for ItemLoc<N> {}
impl<N: AstNode> Hash for ItemLoc<N> {
fn hash<H: Hasher>(&self, hasher: &mut H) {
self.module.hash(hasher);
self.ast_id.hash(hasher);
}
}
impl<N: AstNode> Clone for ItemLoc<N> {
fn clone(&self) -> ItemLoc<N> {
ItemLoc { module: self.module, ast_id: self.ast_id }
}
}
#[derive(Clone, Copy)]
pub struct LocationCtx<DB> {
db: DB,
module: ModuleId,
file_id: HirFileId,
}
impl<'a, DB> LocationCtx<&'a DB> {
pub fn new(db: &'a DB, module: ModuleId, file_id: HirFileId) -> LocationCtx<&'a DB> {
LocationCtx { db, module, file_id }
}
}
pub trait AstItemDef<N: AstNode>: salsa::InternKey + Clone {
fn intern(db: &impl InternDatabase, loc: ItemLoc<N>) -> Self;
fn lookup_intern(self, db: &impl InternDatabase) -> ItemLoc<N>;
fn from_ast_id(ctx: LocationCtx<&impl InternDatabase>, ast_id: FileAstId<N>) -> Self {
let loc = ItemLoc { module: ctx.module, ast_id: AstId::new(ctx.file_id, ast_id) };
Self::intern(ctx.db, loc)
}
fn source(self, db: &(impl AstDatabase + InternDatabase)) -> InFile<N> {
let loc = self.lookup_intern(db);
let value = loc.ast_id.to_node(db);
InFile { file_id: loc.ast_id.file_id, value }
}
fn module(self, db: &impl InternDatabase) -> ModuleId {
let loc = self.lookup_intern(db);
loc.module
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct FunctionId(salsa::InternId);
impl_intern_key!(FunctionId);