rename ModuleId -> CrateModuleId

This commit is contained in:
Aleksey Kladov 2019-03-16 18:57:53 +03:00
parent c51a6a7bdd
commit ee3cf6172b
8 changed files with 40 additions and 39 deletions

View File

@ -8,7 +8,7 @@ use crate::{
Name, ScopesWithSourceMap, Ty, HirFileId,
HirDatabase, PersistentHirDatabase,
type_ref::TypeRef,
nameres::{ModuleScope, Namespace, ImportId, ModuleId},
nameres::{ModuleScope, Namespace, ImportId, CrateModuleId},
expr::{Body, BodySourceMap},
ty::InferenceResult,
adt::{EnumVariantId, StructFieldId, VariantDef},
@ -64,7 +64,7 @@ impl Crate {
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct Module {
pub(crate) krate: Crate,
pub(crate) module_id: ModuleId,
pub(crate) module_id: CrateModuleId,
}
/// The defs which can be visible in the module.

View File

@ -3,7 +3,7 @@ use ra_syntax::{ast, SyntaxNode, TreeArc, AstNode};
use crate::{
Module, ModuleSource, Problem, Name,
nameres::{ModuleId, ImportId},
nameres::{CrateModuleId, ImportId},
HirDatabase, PersistentHirDatabase,
HirFileId, SourceItemId,
};
@ -31,7 +31,7 @@ impl ModuleSource {
}
impl Module {
fn with_module_id(&self, module_id: ModuleId) -> Module {
fn with_module_id(&self, module_id: CrateModuleId) -> Module {
Module { module_id, krate: self.krate }
}

View File

@ -373,6 +373,7 @@ impl SourceFileItems {
impl std::ops::Index<SourceFileItemId> for SourceFileItems {
type Output = SyntaxNodePtr;
fn index(&self, idx: SourceFileItemId) -> &SyntaxNodePtr {
eprintln!("invalid SourceFileItemId({:?}) for file({:?})", idx, self.file_id);
&self.arena[idx]
}
}

View File

@ -74,28 +74,28 @@ pub struct CrateDefMap {
/// a dependency (`std` or `core`).
prelude: Option<Module>,
extern_prelude: FxHashMap<Name, ModuleDef>,
root: ModuleId,
modules: Arena<ModuleId, ModuleData>,
root: CrateModuleId,
modules: Arena<CrateModuleId, ModuleData>,
public_macros: FxHashMap<Name, mbe::MacroRules>,
problems: CrateDefMapProblems,
}
impl std::ops::Index<ModuleId> for CrateDefMap {
impl std::ops::Index<CrateModuleId> for CrateDefMap {
type Output = ModuleData;
fn index(&self, id: ModuleId) -> &ModuleData {
fn index(&self, id: CrateModuleId) -> &ModuleData {
&self.modules[id]
}
}
/// An ID of a module, **local** to a specific crate
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub(crate) struct ModuleId(RawId);
impl_arena_id!(ModuleId);
struct CrateModuleId(RawId);
impl_arena_id!(CrateModuleId);
#[derive(Default, Debug, PartialEq, Eq)]
pub(crate) struct ModuleData {
pub(crate) parent: Option<ModuleId>,
pub(crate) children: FxHashMap<Name, ModuleId>,
pub(crate) parent: Option<CrateModuleId>,
pub(crate) children: FxHashMap<Name, CrateModuleId>,
pub(crate) scope: ModuleScope,
/// None for root
pub(crate) declaration: Option<SourceItemId>,
@ -183,7 +183,7 @@ impl CrateDefMap {
let start = std::time::Instant::now();
let def_map = {
let edition = krate.edition(db);
let mut modules: Arena<ModuleId, ModuleData> = Arena::default();
let mut modules: Arena<CrateModuleId, ModuleData> = Arena::default();
let root = modules.alloc(ModuleData::default());
CrateDefMap {
krate,
@ -201,7 +201,7 @@ impl CrateDefMap {
Arc::new(def_map)
}
pub(crate) fn root(&self) -> ModuleId {
pub(crate) fn root(&self) -> CrateModuleId {
self.root
}
@ -209,7 +209,7 @@ impl CrateDefMap {
&self.problems
}
pub(crate) fn mk_module(&self, module_id: ModuleId) -> Module {
pub(crate) fn mk_module(&self, module_id: CrateModuleId) -> Module {
Module { krate: self.krate, module_id }
}
@ -225,7 +225,7 @@ impl CrateDefMap {
&self,
file_id: HirFileId,
decl_id: Option<SourceFileItemId>,
) -> Option<ModuleId> {
) -> Option<CrateModuleId> {
let decl_id = decl_id.map(|it| it.with_file_id(file_id));
let (module_id, _module_data) = self.modules.iter().find(|(_module_id, module_data)| {
if decl_id.is_some() {
@ -240,7 +240,7 @@ impl CrateDefMap {
pub(crate) fn resolve_path(
&self,
db: &impl PersistentHirDatabase,
original_module: ModuleId,
original_module: CrateModuleId,
path: &Path,
) -> (PerNs<ModuleDef>, Option<usize>) {
let res = self.resolve_path_fp(db, ResolveMode::Other, original_module, path);
@ -253,7 +253,7 @@ impl CrateDefMap {
&self,
db: &impl PersistentHirDatabase,
mode: ResolveMode,
original_module: ModuleId,
original_module: CrateModuleId,
path: &Path,
) -> ResolvePathResult {
let mut segments = path.segments.iter().enumerate();
@ -394,7 +394,7 @@ impl CrateDefMap {
pub(crate) fn resolve_name_in_module(
&self,
db: &impl PersistentHirDatabase,
module: ModuleId,
module: CrateModuleId,
name: &Name,
) -> PerNs<ModuleDef> {
// Resolve in:

View File

@ -12,7 +12,7 @@ use crate::{
ids::{AstItemDef, LocationCtx, MacroCallLoc, SourceItemId, MacroCallId},
};
use super::{CrateDefMap, ModuleId, ModuleData};
use super::{CrateDefMap, CrateModuleId, ModuleData};
pub(super) fn collect_defs(
db: &impl PersistentHirDatabase,
@ -49,9 +49,9 @@ pub(super) fn collect_defs(
struct DefCollector<DB> {
db: DB,
def_map: CrateDefMap,
glob_imports: FxHashMap<ModuleId, Vec<(ModuleId, raw::ImportId)>>,
unresolved_imports: Vec<(ModuleId, raw::ImportId, raw::ImportData)>,
unexpanded_macros: Vec<(ModuleId, MacroCallId, Path, tt::Subtree)>,
glob_imports: FxHashMap<CrateModuleId, Vec<(CrateModuleId, raw::ImportId)>>,
unresolved_imports: Vec<(CrateModuleId, raw::ImportId, raw::ImportData)>,
unexpanded_macros: Vec<(CrateModuleId, MacroCallId, Path, tt::Subtree)>,
global_macro_scope: FxHashMap<Name, mbe::MacroRules>,
}
@ -124,7 +124,7 @@ where
fn resolve_import(
&mut self,
module_id: ModuleId,
module_id: CrateModuleId,
import: &raw::ImportData,
) -> (PerNs<ModuleDef>, ReachedFixedPoint) {
log::debug!("resolving import: {:?} ({:?})", import, self.def_map.edition);
@ -147,7 +147,7 @@ where
fn record_resolved_import(
&mut self,
module_id: ModuleId,
module_id: CrateModuleId,
def: PerNs<ModuleDef>,
import_id: raw::ImportId,
import: &raw::ImportData,
@ -234,7 +234,7 @@ where
fn update(
&mut self,
module_id: ModuleId,
module_id: CrateModuleId,
import: Option<raw::ImportId>,
resolutions: &[(Name, Resolution)],
) {
@ -243,7 +243,7 @@ where
fn update_recursive(
&mut self,
module_id: ModuleId,
module_id: CrateModuleId,
import: Option<raw::ImportId>,
resolutions: &[(Name, Resolution)],
depth: usize,
@ -327,7 +327,7 @@ where
fn collect_macro_expansion(
&mut self,
module_id: ModuleId,
module_id: CrateModuleId,
macro_call_id: MacroCallId,
expansion: tt::Subtree,
) {
@ -353,7 +353,7 @@ where
/// Walks a single module, populating defs, imports and macros
struct ModCollector<'a, D> {
def_collector: D,
module_id: ModuleId,
module_id: CrateModuleId,
file_id: HirFileId,
raw_items: &'a raw::RawItems,
}
@ -426,7 +426,7 @@ where
name: Name,
declaration: SourceItemId,
definition: Option<FileId>,
) -> ModuleId {
) -> CrateModuleId {
let modules = &mut self.def_collector.def_map.modules;
let res = modules.alloc(ModuleData::default());
modules[res].parent = Some(self.module_id);

View File

@ -27,7 +27,7 @@ fn render_crate_def_map(map: &CrateDefMap) -> String {
go(&mut buf, map, "\ncrate", map.root);
return buf;
fn go(buf: &mut String, map: &CrateDefMap, path: &str, module: ModuleId) {
fn go(buf: &mut String, map: &CrateDefMap, path: &str, module: CrateModuleId) {
*buf += path;
*buf += "\n";
for (name, res) in map.modules[module].scope.items.iter() {

View File

@ -7,7 +7,7 @@ use crate::{
ModuleDef,
db::HirDatabase,
name::{Name, KnownName},
nameres::{PerNs, CrateDefMap, ModuleId},
nameres::{PerNs, CrateDefMap, CrateModuleId},
generics::GenericParams,
expr::{scope::{ExprScopes, ScopeId}, PatId, Body},
impl_block::ImplBlock,
@ -23,7 +23,7 @@ pub struct Resolver {
#[derive(Debug, Clone)]
pub(crate) struct ModuleItemMap {
crate_def_map: Arc<CrateDefMap>,
module_id: ModuleId,
module_id: CrateModuleId,
}
#[derive(Debug, Clone)]
@ -175,7 +175,7 @@ impl Resolver {
names
}
fn module(&self) -> Option<(&CrateDefMap, ModuleId)> {
fn module(&self) -> Option<(&CrateDefMap, CrateModuleId)> {
self.scopes.iter().rev().find_map(|scope| match scope {
Scope::ModuleScope(m) => Some((&*m.crate_def_map, m.module_id)),
@ -209,7 +209,7 @@ impl Resolver {
pub(crate) fn push_module_scope(
self,
crate_def_map: Arc<CrateDefMap>,
module_id: ModuleId,
module_id: CrateModuleId,
) -> Resolver {
self.push_scope(Scope::ModuleScope(ModuleItemMap { crate_def_map, module_id }))
}

View File

@ -11,7 +11,7 @@ use crate::{
ids::TraitId,
impl_block::{ImplId, ImplBlock, ImplItem},
ty::{AdtDef, Ty},
nameres::ModuleId,
nameres::CrateModuleId,
};
@ -35,10 +35,10 @@ impl TyFingerprint {
#[derive(Debug, PartialEq, Eq)]
pub struct CrateImplBlocks {
/// To make sense of the ModuleIds, we need the source root.
/// To make sense of the CrateModuleIds, we need the source root.
krate: Crate,
impls: FxHashMap<TyFingerprint, Vec<(ModuleId, ImplId)>>,
impls_by_trait: FxHashMap<TraitId, Vec<(ModuleId, ImplId)>>,
impls: FxHashMap<TyFingerprint, Vec<(CrateModuleId, ImplId)>>,
impls_by_trait: FxHashMap<TraitId, Vec<(CrateModuleId, ImplId)>>,
}
impl CrateImplBlocks {