Move LocalImportId

This commit is contained in:
Aleksey Kladov 2019-12-21 17:34:28 +01:00
parent 02f79e37ca
commit 1a8f2aa024
4 changed files with 20 additions and 28 deletions

View file

@ -5,7 +5,7 @@ use hir_expand::name::Name;
use once_cell::sync::Lazy;
use rustc_hash::FxHashMap;
use crate::{per_ns::PerNs, BuiltinType, ImplId, LocalImportId, MacroDefId, ModuleDefId, TraitId};
use crate::{per_ns::PerNs, BuiltinType, ImplId, MacroDefId, ModuleDefId, TraitId};
#[derive(Debug, Default, PartialEq, Eq)]
pub struct ItemScope {
@ -112,28 +112,23 @@ impl ItemScope {
self.legacy_macros.insert(name, mac);
}
pub(crate) fn push_res(
&mut self,
name: Name,
res: &Resolution,
import: Option<LocalImportId>,
) -> bool {
pub(crate) fn push_res(&mut self, name: Name, res: &Resolution, import: bool) -> bool {
let mut changed = false;
let existing = self.items.entry(name.clone()).or_default();
if existing.def.types.is_none() && res.def.types.is_some() {
existing.def.types = res.def.types;
existing.import = import.is_some() || res.import;
existing.import = import || res.import;
changed = true;
}
if existing.def.values.is_none() && res.def.values.is_some() {
existing.def.values = res.def.values;
existing.import = import.is_some() || res.import;
existing.import = import || res.import;
changed = true;
}
if existing.def.macros.is_none() && res.def.macros.is_some() {
existing.def.macros = res.def.macros;
existing.import = import.is_some() || res.import;
existing.import = import || res.import;
changed = true;
}

View file

@ -51,10 +51,6 @@ use ra_syntax::{ast, AstNode};
use crate::body::Expander;
use crate::builtin_type::BuiltinType;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub(crate) struct LocalImportId(RawId);
impl_arena_id!(LocalImportId);
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct ModuleId {
pub krate: CrateId,

View file

@ -26,8 +26,7 @@ use crate::{
path::{ModPath, PathKind},
per_ns::PerNs,
AdtId, AstId, ConstLoc, ContainerId, EnumLoc, EnumVariantId, FunctionLoc, ImplLoc, Intern,
LocalImportId, LocalModuleId, ModuleDefId, ModuleId, StaticLoc, StructLoc, TraitLoc,
TypeAliasLoc, UnionLoc,
LocalModuleId, ModuleDefId, ModuleId, StaticLoc, StructLoc, TraitLoc, TypeAliasLoc, UnionLoc,
};
pub(super) fn collect_defs(db: &impl DefDatabase, mut def_map: CrateDefMap) -> CrateDefMap {
@ -93,7 +92,7 @@ impl PartialResolvedImport {
#[derive(Clone, Debug, Eq, PartialEq)]
struct ImportDirective {
module_id: LocalModuleId,
import_id: LocalImportId,
import_id: raw::Import,
import: raw::ImportData,
status: PartialResolvedImport,
}
@ -110,7 +109,7 @@ struct MacroDirective {
struct DefCollector<'a, DB> {
db: &'a DB,
def_map: CrateDefMap,
glob_imports: FxHashMap<LocalModuleId, Vec<(LocalModuleId, LocalImportId)>>,
glob_imports: FxHashMap<LocalModuleId, Vec<(LocalModuleId, raw::Import)>>,
unresolved_imports: Vec<ImportDirective>,
resolved_imports: Vec<ImportDirective>,
unexpanded_macros: Vec<MacroDirective>,
@ -442,7 +441,7 @@ where
fn update(
&mut self,
module_id: LocalModuleId,
import: Option<LocalImportId>,
import: Option<raw::Import>,
resolutions: &[(Name, Resolution)],
) {
self.update_recursive(module_id, import, resolutions, 0)
@ -451,7 +450,7 @@ where
fn update_recursive(
&mut self,
module_id: LocalModuleId,
import: Option<LocalImportId>,
import: Option<raw::Import>,
resolutions: &[(Name, Resolution)],
depth: usize,
) {
@ -462,7 +461,7 @@ where
let scope = &mut self.def_map.modules[module_id].scope;
let mut changed = false;
for (name, res) in resolutions {
changed |= scope.push_res(name.clone(), res, import);
changed |= scope.push_res(name.clone(), res, import.is_some());
}
if !changed {

View file

@ -20,9 +20,7 @@ use ra_syntax::{
};
use test_utils::tested_by;
use crate::{
attr::Attrs, db::DefDatabase, path::ModPath, FileAstId, HirFileId, InFile, LocalImportId,
};
use crate::{attr::Attrs, db::DefDatabase, path::ModPath, FileAstId, HirFileId, InFile};
/// `RawItems` is a set of top-level items in a file (except for impls).
///
@ -31,7 +29,7 @@ use crate::{
#[derive(Debug, Default, PartialEq, Eq)]
pub struct RawItems {
modules: Arena<Module, ModuleData>,
imports: Arena<LocalImportId, ImportData>,
imports: Arena<Import, ImportData>,
defs: Arena<Def, DefData>,
macros: Arena<Macro, MacroData>,
impls: Arena<Impl, ImplData>,
@ -73,9 +71,9 @@ impl Index<Module> for RawItems {
}
}
impl Index<LocalImportId> for RawItems {
impl Index<Import> for RawItems {
type Output = ImportData;
fn index(&self, idx: LocalImportId) -> &ImportData {
fn index(&self, idx: Import) -> &ImportData {
&self.imports[idx]
}
}
@ -110,7 +108,7 @@ pub(super) struct RawItem {
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
pub(super) enum RawItemKind {
Module(Module),
Import(LocalImportId),
Import(Import),
Def(Def),
Macro(Macro),
Impl(Impl),
@ -126,6 +124,10 @@ pub(super) enum ModuleData {
Definition { name: Name, ast_id: FileAstId<ast::Module>, items: Vec<RawItem> },
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub(crate) struct Import(RawId);
impl_arena_id!(Import);
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ImportData {
pub(super) path: ModPath,