From ec56f59ac17ad5ae797ce431883be8f31e795d1b Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 21 Dec 2019 17:22:48 +0100 Subject: Remove import from resolution --- crates/ra_hir_def/src/item_scope.rs | 19 +++++++------------ crates/ra_hir_def/src/nameres/collector.rs | 10 +++++----- 2 files changed, 12 insertions(+), 17 deletions(-) (limited to 'crates') diff --git a/crates/ra_hir_def/src/item_scope.rs b/crates/ra_hir_def/src/item_scope.rs index ad104bb3d..8b70e13c4 100644 --- a/crates/ra_hir_def/src/item_scope.rs +++ b/crates/ra_hir_def/src/item_scope.rs @@ -30,7 +30,7 @@ static BUILTIN_SCOPE: Lazy> = Lazy::new(|| { BuiltinType::ALL .iter() .map(|(name, ty)| { - (name.clone(), Resolution { def: PerNs::types(ty.clone().into()), import: None }) + (name.clone(), Resolution { def: PerNs::types(ty.clone().into()), import: false }) }) .collect() }); @@ -54,7 +54,7 @@ impl ItemScope { pub fn declarations(&self) -> impl Iterator + '_ { self.entries() - .filter_map(|(_name, res)| if res.import.is_none() { Some(res.def) } else { None }) + .filter_map(|(_name, res)| if !res.import { Some(res.def) } else { None }) .flat_map(|per_ns| { per_ns.take_types().into_iter().chain(per_ns.take_values().into_iter()) }) @@ -123,25 +123,21 @@ impl ItemScope { if existing.def.types.is_none() && res.def.types.is_some() { existing.def.types = res.def.types; - existing.import = import.or(res.import); + existing.import = import.is_some() || res.import; changed = true; } if existing.def.values.is_none() && res.def.values.is_some() { existing.def.values = res.def.values; - existing.import = import.or(res.import); + existing.import = import.is_some() || res.import; changed = true; } if existing.def.macros.is_none() && res.def.macros.is_some() { existing.def.macros = res.def.macros; - existing.import = import.or(res.import); + existing.import = import.is_some() || res.import; changed = true; } - if existing.def.is_none() - && res.def.is_none() - && existing.import.is_none() - && res.import.is_some() - { + if existing.def.is_none() && res.def.is_none() && !existing.import && res.import { existing.import = res.import; } changed @@ -160,6 +156,5 @@ impl ItemScope { pub struct Resolution { /// None for unresolved pub def: PerNs, - /// ident by which this is imported into local scope. - pub(crate) import: Option, + pub(crate) import: bool, } diff --git a/crates/ra_hir_def/src/nameres/collector.rs b/crates/ra_hir_def/src/nameres/collector.rs index 45199fa11..c2db5472b 100644 --- a/crates/ra_hir_def/src/nameres/collector.rs +++ b/crates/ra_hir_def/src/nameres/collector.rs @@ -219,7 +219,7 @@ where self.update( self.def_map.root, None, - &[(name, Resolution { def: PerNs::macros(macro_), import: None })], + &[(name, Resolution { def: PerNs::macros(macro_), import: false })], ); } } @@ -404,7 +404,7 @@ where let variant = EnumVariantId { parent: e, local_id }; let res = Resolution { def: PerNs::both(variant.into(), variant.into()), - import: Some(import_id), + import: true, }; (name, res) }) @@ -431,7 +431,7 @@ where } } - let resolution = Resolution { def, import: Some(import_id) }; + let resolution = Resolution { def, import: true }; self.update(module_id, Some(import_id), &[(name, resolution)]); } None => tested_by!(bogus_paths), @@ -719,7 +719,7 @@ where def: PerNs::types( ModuleId { krate: self.def_collector.def_map.krate, local_id: res }.into(), ), - import: None, + import: false, }; self.def_collector.update(self.module_id, None, &[(name, resolution)]); res @@ -791,7 +791,7 @@ where PerNs::types(def.into()) } }; - let resolution = Resolution { def, import: None }; + let resolution = Resolution { def, import: false }; self.def_collector.update(self.module_id, None, &[(name, resolution)]) } -- cgit v1.2.3 From 02f79e37ca1c4a617a46b85bf897dffbf4abed9e Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 21 Dec 2019 17:26:05 +0100 Subject: Remove import source map --- crates/ra_hir/src/db.rs | 4 +-- crates/ra_hir_def/src/db.rs | 11 +------ crates/ra_hir_def/src/nameres/raw.rs | 56 ++++++++---------------------------- crates/ra_hir_def/src/trace.rs | 8 ------ crates/ra_ide/src/change.rs | 2 -- 5 files changed, 15 insertions(+), 66 deletions(-) (limited to 'crates') diff --git a/crates/ra_hir/src/db.rs b/crates/ra_hir/src/db.rs index bfae3660b..f5ffd64fa 100644 --- a/crates/ra_hir/src/db.rs +++ b/crates/ra_hir/src/db.rs @@ -4,8 +4,8 @@ pub use hir_def::db::{ BodyQuery, BodyWithSourceMapQuery, ConstDataQuery, CrateDefMapQuery, CrateLangItemsQuery, DefDatabase, DefDatabaseStorage, DocumentationQuery, EnumDataQuery, ExprScopesQuery, FunctionDataQuery, GenericParamsQuery, ImplDataQuery, InternDatabase, InternDatabaseStorage, - LangItemQuery, ModuleLangItemsQuery, RawItemsQuery, RawItemsWithSourceMapQuery, - StaticDataQuery, StructDataQuery, TraitDataQuery, TypeAliasDataQuery, + LangItemQuery, ModuleLangItemsQuery, RawItemsQuery, StaticDataQuery, StructDataQuery, + TraitDataQuery, TypeAliasDataQuery, }; pub use hir_expand::db::{ AstDatabase, AstDatabaseStorage, AstIdMapQuery, MacroArgQuery, MacroDefQuery, MacroExpandQuery, diff --git a/crates/ra_hir_def/src/db.rs b/crates/ra_hir_def/src/db.rs index 98bff6cb7..c55fd4111 100644 --- a/crates/ra_hir_def/src/db.rs +++ b/crates/ra_hir_def/src/db.rs @@ -13,10 +13,7 @@ use crate::{ docs::Documentation, generics::GenericParams, lang_item::{LangItemTarget, LangItems}, - nameres::{ - raw::{ImportSourceMap, RawItems}, - CrateDefMap, - }, + nameres::{raw::RawItems, CrateDefMap}, AttrDefId, ConstId, ConstLoc, DefWithBodyId, EnumId, EnumLoc, FunctionId, FunctionLoc, GenericDefId, ImplId, ImplLoc, ModuleId, StaticId, StaticLoc, StructId, StructLoc, TraitId, TraitLoc, TypeAliasId, TypeAliasLoc, UnionId, UnionLoc, @@ -46,12 +43,6 @@ pub trait InternDatabase: SourceDatabase { #[salsa::query_group(DefDatabaseStorage)] pub trait DefDatabase: InternDatabase + AstDatabase { - #[salsa::invoke(RawItems::raw_items_with_source_map_query)] - fn raw_items_with_source_map( - &self, - file_id: HirFileId, - ) -> (Arc, Arc); - #[salsa::invoke(RawItems::raw_items_query)] fn raw_items(&self, file_id: HirFileId) -> Arc; diff --git a/crates/ra_hir_def/src/nameres/raw.rs b/crates/ra_hir_def/src/nameres/raw.rs index df5dac88a..73e57f1e5 100644 --- a/crates/ra_hir_def/src/nameres/raw.rs +++ b/crates/ra_hir_def/src/nameres/raw.rs @@ -7,23 +7,21 @@ use std::{ops::Index, sync::Arc}; -use either::Either; use hir_expand::{ ast_id_map::AstIdMap, db::AstDatabase, hygiene::Hygiene, name::{AsName, Name}, }; -use ra_arena::{impl_arena_id, map::ArenaMap, Arena, RawId}; +use ra_arena::{impl_arena_id, Arena, RawId}; use ra_syntax::{ ast::{self, AttrsOwner, NameOwner}, - AstNode, AstPtr, + AstNode, }; use test_utils::tested_by; use crate::{ - attr::Attrs, db::DefDatabase, path::ModPath, trace::Trace, FileAstId, HirFileId, InFile, - LocalImportId, + attr::Attrs, db::DefDatabase, path::ModPath, FileAstId, HirFileId, InFile, LocalImportId, }; /// `RawItems` is a set of top-level items in a file (except for impls). @@ -41,29 +39,14 @@ pub struct RawItems { items: Vec, } -#[derive(Debug, Default, PartialEq, Eq)] -pub struct ImportSourceMap { - map: ArenaMap, -} - -type ImportSourcePtr = Either, AstPtr>; - impl RawItems { pub(crate) fn raw_items_query( db: &(impl DefDatabase + AstDatabase), file_id: HirFileId, ) -> Arc { - db.raw_items_with_source_map(file_id).0 - } - - pub(crate) fn raw_items_with_source_map_query( - db: &(impl DefDatabase + AstDatabase), - file_id: HirFileId, - ) -> (Arc, Arc) { let mut collector = RawItemsCollector { raw_items: RawItems::default(), source_ast_id_map: db.ast_id_map(file_id), - imports: Trace::new(), file_id, hygiene: Hygiene::new(db, file_id), }; @@ -74,11 +57,8 @@ impl RawItems { collector.process_module(None, item_list); } } - let mut raw_items = collector.raw_items; - let (arena, map) = collector.imports.into_arena_and_map(); - raw_items.imports = arena; - let source_map = ImportSourceMap { map }; - (Arc::new(raw_items), Arc::new(source_map)) + let raw_items = collector.raw_items; + Arc::new(raw_items) } pub(super) fn items(&self) -> &[RawItem] { @@ -217,7 +197,6 @@ pub(super) struct ImplData { struct RawItemsCollector { raw_items: RawItems, - imports: Trace, source_ast_id_map: Arc, file_id: HirFileId, hygiene: Hygiene, @@ -324,7 +303,7 @@ impl RawItemsCollector { ModPath::expand_use_item( InFile { value: use_item, file_id: self.file_id }, &self.hygiene, - |path, use_tree, is_glob, alias| { + |path, _use_tree, is_glob, alias| { let import_data = ImportData { path, alias, @@ -333,11 +312,11 @@ impl RawItemsCollector { is_extern_crate: false, is_macro_use: false, }; - buf.push((import_data, Either::Left(AstPtr::new(use_tree)))); + buf.push(import_data); }, ); - for (import_data, ptr) in buf { - self.push_import(current_module, attrs.clone(), import_data, ptr); + for import_data in buf { + self.push_import(current_module, attrs.clone(), import_data); } } @@ -360,12 +339,7 @@ impl RawItemsCollector { is_extern_crate: true, is_macro_use, }; - self.push_import( - current_module, - attrs, - import_data, - Either::Right(AstPtr::new(&extern_crate)), - ); + self.push_import(current_module, attrs, import_data); } } @@ -396,14 +370,8 @@ impl RawItemsCollector { self.push_item(current_module, attrs, RawItemKind::Impl(imp)) } - fn push_import( - &mut self, - current_module: Option, - attrs: Attrs, - data: ImportData, - source: ImportSourcePtr, - ) { - let import = self.imports.alloc(|| source, || data); + fn push_import(&mut self, current_module: Option, attrs: Attrs, data: ImportData) { + let import = self.raw_items.imports.alloc(data); self.push_item(current_module, attrs, RawItemKind::Import(import)) } diff --git a/crates/ra_hir_def/src/trace.rs b/crates/ra_hir_def/src/trace.rs index 2bcd707bc..9769e88df 100644 --- a/crates/ra_hir_def/src/trace.rs +++ b/crates/ra_hir_def/src/trace.rs @@ -18,10 +18,6 @@ pub(crate) struct Trace { } impl Trace { - pub(crate) fn new() -> Trace { - Trace { arena: Some(Arena::default()), map: Some(ArenaMap::default()), len: 0 } - } - pub(crate) fn new_for_arena() -> Trace { Trace { arena: Some(Arena::default()), map: None, len: 0 } } @@ -52,8 +48,4 @@ impl Trace { pub(crate) fn into_map(mut self) -> ArenaMap { self.map.take().unwrap() } - - pub(crate) fn into_arena_and_map(mut self) -> (Arena, ArenaMap) { - (self.arena.take().unwrap(), self.map.take().unwrap()) - } } diff --git a/crates/ra_ide/src/change.rs b/crates/ra_ide/src/change.rs index 4a76d1dd8..387a9cafb 100644 --- a/crates/ra_ide/src/change.rs +++ b/crates/ra_ide/src/change.rs @@ -270,7 +270,6 @@ impl RootDatabase { self.query(hir::db::AstIdMapQuery).sweep(sweep); - self.query(hir::db::RawItemsWithSourceMapQuery).sweep(sweep); self.query(hir::db::BodyWithSourceMapQuery).sweep(sweep); self.query(hir::db::ExprScopesQuery).sweep(sweep); @@ -309,7 +308,6 @@ impl RootDatabase { hir::db::StructDataQuery hir::db::EnumDataQuery hir::db::TraitDataQuery - hir::db::RawItemsWithSourceMapQuery hir::db::RawItemsQuery hir::db::CrateDefMapQuery hir::db::GenericParamsQuery -- cgit v1.2.3 From 1a8f2aa024c6f1a5e9704c9cbd2e5a020debe2c2 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 21 Dec 2019 17:34:28 +0100 Subject: Move LocalImportId --- crates/ra_hir_def/src/item_scope.rs | 15 +++++---------- crates/ra_hir_def/src/lib.rs | 4 ---- crates/ra_hir_def/src/nameres/collector.rs | 13 ++++++------- crates/ra_hir_def/src/nameres/raw.rs | 16 +++++++++------- 4 files changed, 20 insertions(+), 28 deletions(-) (limited to 'crates') diff --git a/crates/ra_hir_def/src/item_scope.rs b/crates/ra_hir_def/src/item_scope.rs index 8b70e13c4..9e082c5f7 100644 --- a/crates/ra_hir_def/src/item_scope.rs +++ b/crates/ra_hir_def/src/item_scope.rs @@ -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, - ) -> 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; } diff --git a/crates/ra_hir_def/src/lib.rs b/crates/ra_hir_def/src/lib.rs index 8cb5ab8d0..f6c7f38d1 100644 --- a/crates/ra_hir_def/src/lib.rs +++ b/crates/ra_hir_def/src/lib.rs @@ -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, diff --git a/crates/ra_hir_def/src/nameres/collector.rs b/crates/ra_hir_def/src/nameres/collector.rs index c2db5472b..2b194f488 100644 --- a/crates/ra_hir_def/src/nameres/collector.rs +++ b/crates/ra_hir_def/src/nameres/collector.rs @@ -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>, + glob_imports: FxHashMap>, unresolved_imports: Vec, resolved_imports: Vec, unexpanded_macros: Vec, @@ -442,7 +441,7 @@ where fn update( &mut self, module_id: LocalModuleId, - import: Option, + import: Option, 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, + import: Option, 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 { diff --git a/crates/ra_hir_def/src/nameres/raw.rs b/crates/ra_hir_def/src/nameres/raw.rs index 73e57f1e5..1b83b2247 100644 --- a/crates/ra_hir_def/src/nameres/raw.rs +++ b/crates/ra_hir_def/src/nameres/raw.rs @@ -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, - imports: Arena, + imports: Arena, defs: Arena, macros: Arena, impls: Arena, @@ -73,9 +71,9 @@ impl Index for RawItems { } } -impl Index for RawItems { +impl Index 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, items: Vec }, } +#[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, -- cgit v1.2.3