From 490112dea10d476e9b5829499bc6670f03f7d138 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 15 Jan 2019 19:15:01 +0300 Subject: remove Cancelable from nameres --- crates/ra_hir/src/code_model_api.rs | 4 +-- crates/ra_hir/src/code_model_impl/module.rs | 33 ++++++++++------------- crates/ra_hir/src/db.rs | 2 +- crates/ra_hir/src/nameres.rs | 42 +++++++++++++---------------- crates/ra_hir/src/nameres/tests.rs | 12 ++++----- crates/ra_hir/src/query_definitions.rs | 11 +++----- crates/ra_hir/src/ty.rs | 6 ++--- 7 files changed, 48 insertions(+), 62 deletions(-) (limited to 'crates/ra_hir') diff --git a/crates/ra_hir/src/code_model_api.rs b/crates/ra_hir/src/code_model_api.rs index 4d7925ac4..7ccd29e2f 100644 --- a/crates/ra_hir/src/code_model_api.rs +++ b/crates/ra_hir/src/code_model_api.rs @@ -134,11 +134,11 @@ impl Module { } /// Returns a `ModuleScope`: a set of items, visible in this module. - pub fn scope(&self, db: &impl HirDatabase) -> Cancelable { + pub fn scope(&self, db: &impl HirDatabase) -> ModuleScope { self.scope_impl(db) } - pub fn resolve_path(&self, db: &impl HirDatabase, path: &Path) -> Cancelable> { + pub fn resolve_path(&self, db: &impl HirDatabase, path: &Path) -> PerNs { self.resolve_path_impl(db, path) } diff --git a/crates/ra_hir/src/code_model_impl/module.rs b/crates/ra_hir/src/code_model_impl/module.rs index 331b0500e..04301ae53 100644 --- a/crates/ra_hir/src/code_model_impl/module.rs +++ b/crates/ra_hir/src/code_model_impl/module.rs @@ -114,18 +114,13 @@ impl Module { } /// Returns a `ModuleScope`: a set of items, visible in this module. - pub fn scope_impl(&self, db: &impl HirDatabase) -> Cancelable { + pub fn scope_impl(&self, db: &impl HirDatabase) -> ModuleScope { let loc = self.def_id.loc(db); - let item_map = db.item_map(loc.source_root_id)?; - let res = item_map.per_module[&loc.module_id].clone(); - Ok(res) + let item_map = db.item_map(loc.source_root_id); + item_map.per_module[&loc.module_id].clone() } - pub fn resolve_path_impl( - &self, - db: &impl HirDatabase, - path: &Path, - ) -> Cancelable> { + pub fn resolve_path_impl(&self, db: &impl HirDatabase, path: &Path) -> PerNs { let mut curr_per_ns = PerNs::types( match path.kind { PathKind::Crate => self.crate_root(db), @@ -134,7 +129,7 @@ impl Module { if let Some(p) = self.parent(db) { p } else { - return Ok(PerNs::none()); + return PerNs::none(); } } } @@ -146,7 +141,7 @@ impl Module { let curr = if let Some(r) = curr_per_ns.as_ref().take_types() { r } else { - return Ok(PerNs::none()); + return PerNs::none(); }; let module = match curr.resolve(db) { Def::Module(it) => it, @@ -157,28 +152,28 @@ impl Module { e.variants(db).into_iter().find(|(n, _variant)| n == name); if let Some((_n, variant)) = matching_variant { - return Ok(PerNs::both(variant.def_id(), e.def_id())); + return PerNs::both(variant.def_id(), e.def_id()); } else { - return Ok(PerNs::none()); + return PerNs::none(); } } else if segments.len() == idx { // enum - return Ok(PerNs::types(e.def_id())); + return PerNs::types(e.def_id()); } else { // malformed enum? - return Ok(PerNs::none()); + return PerNs::none(); } } - _ => return Ok(PerNs::none()), + _ => return PerNs::none(), }; - let scope = module.scope(db)?; + let scope = module.scope(db); curr_per_ns = if let Some(r) = scope.get(&name) { r.def_id } else { - return Ok(PerNs::none()); + return PerNs::none(); }; } - Ok(curr_per_ns) + curr_per_ns } pub fn problems_impl( diff --git a/crates/ra_hir/src/db.rs b/crates/ra_hir/src/db.rs index d20c03f43..1466c3438 100644 --- a/crates/ra_hir/src/db.rs +++ b/crates/ra_hir/src/db.rs @@ -87,7 +87,7 @@ pub trait HirDatabase: SyntaxDatabase use fn query_definitions::input_module_items; } - fn item_map(source_root_id: SourceRootId) -> Cancelable> { + fn item_map(source_root_id: SourceRootId) -> Arc { type ItemMapQuery; use fn query_definitions::item_map; } diff --git a/crates/ra_hir/src/nameres.rs b/crates/ra_hir/src/nameres.rs index e51cbe786..484f668d0 100644 --- a/crates/ra_hir/src/nameres.rs +++ b/crates/ra_hir/src/nameres.rs @@ -22,7 +22,7 @@ use ra_syntax::{ SyntaxKind::{self, *}, ast::{self, AstNode} }; -use ra_db::{SourceRootId, Cancelable, FileId}; +use ra_db::{SourceRootId, FileId}; use crate::{ HirFileId, @@ -319,30 +319,26 @@ where } } - pub(crate) fn resolve(mut self) -> Cancelable { + pub(crate) fn resolve(mut self) -> ItemMap { for (&module_id, items) in self.input.iter() { - self.populate_module(module_id, Arc::clone(items))?; + self.populate_module(module_id, Arc::clone(items)); } loop { let processed_imports_count = self.processed_imports.len(); for &module_id in self.input.keys() { self.db.check_canceled(); - self.resolve_imports(module_id)?; + self.resolve_imports(module_id); } if processed_imports_count == self.processed_imports.len() { // no new imports resolved break; } } - Ok(self.result) + self.result } - fn populate_module( - &mut self, - module_id: ModuleId, - input: Arc, - ) -> Cancelable<()> { + fn populate_module(&mut self, module_id: ModuleId, input: Arc) { let mut module_items = ModuleScope::default(); // Populate extern crates prelude @@ -415,7 +411,6 @@ where } self.result.per_module.insert(module_id, module_items); - Ok(()) } fn add_module_item(&self, module_items: &mut ModuleScope, name: Name, def_id: PerNs) { @@ -426,24 +421,23 @@ where module_items.items.insert(name, resolution); } - fn resolve_imports(&mut self, module_id: ModuleId) -> Cancelable<()> { + fn resolve_imports(&mut self, module_id: ModuleId) { for (i, import) in self.input[&module_id].imports.iter().enumerate() { if self.processed_imports.contains(&(module_id, i)) { // already done continue; } - if self.resolve_import(module_id, import)? { + if self.resolve_import(module_id, import) { log::debug!("import {:?} resolved (or definite error)", import); self.processed_imports.insert((module_id, i)); } } - Ok(()) } - fn resolve_import(&mut self, module_id: ModuleId, import: &Import) -> Cancelable { + fn resolve_import(&mut self, module_id: ModuleId, import: &Import) -> bool { log::debug!("resolving import: {:?}", import); let ptr = match import.kind { - ImportKind::Glob => return Ok(false), + ImportKind::Glob => return false, ImportKind::Named(ptr) => ptr, }; @@ -455,7 +449,7 @@ where None => { // TODO: error log::debug!("super path in root module"); - return Ok(true); // this can't suddenly resolve if we just resolve some other imports + return true; // this can't suddenly resolve if we just resolve some other imports } } } @@ -469,7 +463,7 @@ where Some(res) if !res.def_id.is_none() => res.def_id, _ => { log::debug!("path segment {:?} not found", name); - return Ok(false); + return false; } }; @@ -481,7 +475,7 @@ where "path segment {:?} resolved to value only, but is not last", name ); - return Ok(false); + return false; }; curr = match type_def_id.loc(self.db) { DefLoc { @@ -499,7 +493,7 @@ where kind: PathKind::Crate, }; log::debug!("resolving {:?} in other source root", path); - let def_id = module.resolve_path(self.db, &path)?; + let def_id = module.resolve_path(self.db, &path); if !def_id.is_none() { let name = path.segments.last().unwrap(); self.update(module_id, |items| { @@ -515,10 +509,10 @@ where import, def_id.map(|did| did.loc(self.db)) ); - return Ok(true); + return true; } else { log::debug!("rest of path did not resolve in other source root"); - return Ok(true); + return true; } } } @@ -528,7 +522,7 @@ where name, type_def_id.loc(self.db) ); - return Ok(true); // this resolved to a non-module, so the path won't ever resolve + return true; // this resolved to a non-module, so the path won't ever resolve } } } else { @@ -547,7 +541,7 @@ where }) } } - Ok(true) + true } fn update(&mut self, module_id: ModuleId, f: impl FnOnce(&mut ModuleScope)) { diff --git a/crates/ra_hir/src/nameres/tests.rs b/crates/ra_hir/src/nameres/tests.rs index ea8ab4c83..9a0474045 100644 --- a/crates/ra_hir/src/nameres/tests.rs +++ b/crates/ra_hir/src/nameres/tests.rs @@ -17,7 +17,7 @@ fn item_map(fixture: &str) -> (Arc, ModuleId) { let source_root = db.file_source_root(pos.file_id); let module = crate::source_binder::module_from_position(&db, pos).unwrap(); let module_id = module.def_id.loc(&db).module_id; - (db.item_map(source_root).unwrap(), module_id) + (db.item_map(source_root), module_id) } fn check_module_item_map(map: &ItemMap, module_id: ModuleId, expected: &str) { @@ -242,7 +242,7 @@ fn item_map_across_crates() { let source_root = db.file_source_root(main_id); let module = crate::source_binder::module_from_file_id(&db, main_id).unwrap(); let module_id = module.def_id.loc(&db).module_id; - let item_map = db.item_map(source_root).unwrap(); + let item_map = db.item_map(source_root); check_module_item_map( &item_map, @@ -294,7 +294,7 @@ fn import_across_source_roots() { let module = crate::source_binder::module_from_file_id(&db, main_id).unwrap(); let module_id = module.def_id.loc(&db).module_id; - let item_map = db.item_map(source_root).unwrap(); + let item_map = db.item_map(source_root); check_module_item_map( &item_map, @@ -337,7 +337,7 @@ fn reexport_across_crates() { let source_root = db.file_source_root(main_id); let module = crate::source_binder::module_from_file_id(&db, main_id).unwrap(); let module_id = module.def_id.loc(&db).module_id; - let item_map = db.item_map(source_root).unwrap(); + let item_map = db.item_map(source_root); check_module_item_map( &item_map, @@ -354,7 +354,7 @@ fn check_item_map_is_not_recomputed(initial: &str, file_change: &str) { let source_root = db.file_source_root(pos.file_id); { let events = db.log_executed(|| { - db.item_map(source_root).unwrap(); + db.item_map(source_root); }); assert!(format!("{:?}", events).contains("item_map")) } @@ -363,7 +363,7 @@ fn check_item_map_is_not_recomputed(initial: &str, file_change: &str) { { let events = db.log_executed(|| { - db.item_map(source_root).unwrap(); + db.item_map(source_root); }); assert!( !format!("{:?}", events).contains("item_map"), diff --git a/crates/ra_hir/src/query_definitions.rs b/crates/ra_hir/src/query_definitions.rs index 8f33ec707..24cb5c752 100644 --- a/crates/ra_hir/src/query_definitions.rs +++ b/crates/ra_hir/src/query_definitions.rs @@ -8,7 +8,7 @@ use ra_syntax::{ AstNode, SyntaxNode, TreeArc, ast::{self, ModuleItemOwner} }; -use ra_db::{SourceRootId, Cancelable,}; +use ra_db::SourceRootId; use crate::{ SourceFileItems, SourceItemId, DefId, HirFileId, ModuleSource, @@ -93,10 +93,7 @@ pub(super) fn input_module_items( Arc::new(res) } -pub(super) fn item_map( - db: &impl HirDatabase, - source_root: SourceRootId, -) -> Cancelable> { +pub(super) fn item_map(db: &impl HirDatabase, source_root: SourceRootId) -> Arc { let start = Instant::now(); let module_tree = db.module_tree(source_root); let input = module_tree @@ -105,8 +102,8 @@ pub(super) fn item_map( .collect::>(); let resolver = Resolver::new(db, &input, source_root, module_tree); - let res = resolver.resolve()?; + let res = resolver.resolve(); let elapsed = start.elapsed(); log::info!("item_map: {:?}", elapsed); - Ok(Arc::new(res)) + Arc::new(res) } diff --git a/crates/ra_hir/src/ty.rs b/crates/ra_hir/src/ty.rs index 54eece165..6df7820ea 100644 --- a/crates/ra_hir/src/ty.rs +++ b/crates/ra_hir/src/ty.rs @@ -349,7 +349,7 @@ impl Ty { } // Resolve in module (in type namespace) - let resolved = if let Some(r) = module.resolve_path(db, path)?.take_types() { + let resolved = if let Some(r) = module.resolve_path(db, path).take_types() { r } else { return Ok(Ty::Unknown); @@ -860,7 +860,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { }; // resolve in module - let resolved = ctry!(self.module.resolve_path(self.db, &path)?.take_values()); + let resolved = ctry!(self.module.resolve_path(self.db, &path).take_values()); let ty = self.db.type_for_def(resolved)?; let ty = self.insert_type_vars(ty); Ok(Some(ty)) @@ -872,7 +872,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { } else { return Ok((Ty::Unknown, None)); }; - let def_id = if let Some(def_id) = self.module.resolve_path(self.db, &path)?.take_types() { + let def_id = if let Some(def_id) = self.module.resolve_path(self.db, &path).take_types() { def_id } else { return Ok((Ty::Unknown, None)); -- cgit v1.2.3 From fafcd103d26821a8408572514201a40765bb2d2b Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 15 Jan 2019 19:18:52 +0300 Subject: remove Cancelable from ids --- crates/ra_hir/src/code_model_impl/function.rs | 5 ++--- crates/ra_hir/src/db.rs | 2 +- crates/ra_hir/src/ids.rs | 20 ++++++++------------ crates/ra_hir/src/impl_block.rs | 12 +++++------- crates/ra_hir/src/ty.rs | 12 ++++++------ crates/ra_hir/src/ty/method_resolution.rs | 10 +++++----- 6 files changed, 27 insertions(+), 34 deletions(-) (limited to 'crates/ra_hir') diff --git a/crates/ra_hir/src/code_model_impl/function.rs b/crates/ra_hir/src/code_model_impl/function.rs index d34803e32..66d7e1713 100644 --- a/crates/ra_hir/src/code_model_impl/function.rs +++ b/crates/ra_hir/src/code_model_impl/function.rs @@ -2,7 +2,6 @@ mod scope; use std::sync::Arc; -use ra_db::Cancelable; use ra_syntax::{TreeArc, ast::{self, NameOwner}}; use crate::{ @@ -24,12 +23,12 @@ impl Function { db.body_hir(self.def_id) } - pub(crate) fn module(&self, db: &impl HirDatabase) -> Cancelable { + pub(crate) fn module(&self, db: &impl HirDatabase) -> Module { self.def_id.module(db) } /// The containing impl block, if this is a method. - pub(crate) fn impl_block(&self, db: &impl HirDatabase) -> Cancelable> { + pub(crate) fn impl_block(&self, db: &impl HirDatabase) -> Option { self.def_id.impl_block(db) } } diff --git a/crates/ra_hir/src/db.rs b/crates/ra_hir/src/db.rs index 1466c3438..161a5e714 100644 --- a/crates/ra_hir/src/db.rs +++ b/crates/ra_hir/src/db.rs @@ -97,7 +97,7 @@ pub trait HirDatabase: SyntaxDatabase use fn crate::module_tree::ModuleTree::module_tree_query; } - fn impls_in_module(source_root_id: SourceRootId, module_id: ModuleId) -> Cancelable> { + fn impls_in_module(source_root_id: SourceRootId, module_id: ModuleId) -> Arc { type ImplsInModuleQuery; use fn crate::impl_block::impls_in_module; } diff --git a/crates/ra_hir/src/ids.rs b/crates/ra_hir/src/ids.rs index 3cbf8070f..0d8e67547 100644 --- a/crates/ra_hir/src/ids.rs +++ b/crates/ra_hir/src/ids.rs @@ -1,4 +1,4 @@ -use ra_db::{SourceRootId, LocationIntener, Cancelable, FileId}; +use ra_db::{SourceRootId, LocationIntener, FileId}; use ra_syntax::{TreeArc, SyntaxKind, SyntaxNode, SourceFile, AstNode, ast}; use ra_arena::{Arena, RawId, impl_arena_id}; @@ -205,25 +205,21 @@ impl DefId { } /// For a module, returns that module; for any other def, returns the containing module. - pub fn module(self, db: &impl HirDatabase) -> Cancelable { + pub fn module(self, db: &impl HirDatabase) -> Module { let loc = self.loc(db); - Ok(Module::from_module_id( - db, - loc.source_root_id, - loc.module_id, - )) + Module::from_module_id(db, loc.source_root_id, loc.module_id) } /// Returns the containing crate. - pub fn krate(&self, db: &impl HirDatabase) -> Cancelable> { - Ok(self.module(db)?.krate(db)) + pub fn krate(&self, db: &impl HirDatabase) -> Option { + self.module(db).krate(db) } /// Returns the containing impl block, if this is an impl item. - pub fn impl_block(self, db: &impl HirDatabase) -> Cancelable> { + pub fn impl_block(self, db: &impl HirDatabase) -> Option { let loc = self.loc(db); - let module_impls = db.impls_in_module(loc.source_root_id, loc.module_id)?; - Ok(ImplBlock::containing(module_impls, self)) + let module_impls = db.impls_in_module(loc.source_root_id, loc.module_id); + ImplBlock::containing(module_impls, self) } } diff --git a/crates/ra_hir/src/impl_block.rs b/crates/ra_hir/src/impl_block.rs index ce9087b49..ab996a12c 100644 --- a/crates/ra_hir/src/impl_block.rs +++ b/crates/ra_hir/src/impl_block.rs @@ -3,7 +3,7 @@ use rustc_hash::FxHashMap; use ra_arena::{Arena, RawId, impl_arena_id}; use ra_syntax::ast::{self, AstNode}; -use ra_db::{LocationIntener, Cancelable, SourceRootId}; +use ra_db::{LocationIntener, SourceRootId}; use crate::{ DefId, DefLoc, DefKind, SourceItemId, SourceFileItems, @@ -166,7 +166,7 @@ impl ModuleImplBlocks { } } - fn collect(&mut self, db: &impl HirDatabase, module: Module) -> Cancelable<()> { + fn collect(&mut self, db: &impl HirDatabase, module: Module) { let (file_id, module_source) = module.definition_source(db); let node = match &module_source { ModuleSource::SourceFile(node) => node.syntax(), @@ -185,8 +185,6 @@ impl ModuleImplBlocks { self.impls_by_def.insert(impl_item.def_id(), id); } } - - Ok(()) } } @@ -194,9 +192,9 @@ pub(crate) fn impls_in_module( db: &impl HirDatabase, source_root_id: SourceRootId, module_id: ModuleId, -) -> Cancelable> { +) -> Arc { let mut result = ModuleImplBlocks::new(); let module = Module::from_module_id(db, source_root_id, module_id); - result.collect(db, module)?; - Ok(Arc::new(result)) + result.collect(db, module); + Arc::new(result) } diff --git a/crates/ra_hir/src/ty.rs b/crates/ra_hir/src/ty.rs index 6df7820ea..e5f8ffc2e 100644 --- a/crates/ra_hir/src/ty.rs +++ b/crates/ra_hir/src/ty.rs @@ -447,8 +447,8 @@ impl fmt::Display for Ty { /// function body. fn type_for_fn(db: &impl HirDatabase, f: Function) -> Cancelable { let signature = f.signature(db); - let module = f.module(db)?; - let impl_block = f.impl_block(db)?; + let module = f.module(db); + let impl_block = f.impl_block(db); // TODO we ignore type parameters for now let input = signature .params() @@ -517,8 +517,8 @@ pub(super) fn type_for_field( def_id ), }; - let module = def_id.module(db)?; - let impl_block = def_id.impl_block(db)?; + let module = def_id.module(db); + let impl_block = def_id.impl_block(db); let type_ref = ctry!(variant_data.get_field_type_ref(&field)); Ok(Some(Ty::from_hir( db, @@ -1207,8 +1207,8 @@ pub fn infer(db: &impl HirDatabase, def_id: DefId) -> Cancelable Cancelable<()> { let module_id = module.def_id.loc(db).module_id; - let module_impl_blocks = db.impls_in_module(self.source_root_id, module_id)?; + let module_impl_blocks = db.impls_in_module(self.source_root_id, module_id); for (impl_id, impl_data) in module_impl_blocks.impls.iter() { let impl_block = ImplBlock::from_id(Arc::clone(&module_impl_blocks), impl_id); @@ -100,10 +100,10 @@ impl CrateImplBlocks { } } -fn def_crate(db: &impl HirDatabase, ty: &Ty) -> Cancelable> { +fn def_crate(db: &impl HirDatabase, ty: &Ty) -> Option { match ty { Ty::Adt { def_id, .. } => def_id.krate(db), - _ => Ok(None), + _ => None, } } @@ -139,7 +139,7 @@ impl Ty { // rustc does an autoderef and then autoref again). for derefed_ty in self.autoderef(db) { - let krate = match def_crate(db, &derefed_ty)? { + let krate = match def_crate(db, &derefed_ty) { Some(krate) => krate, None => continue, }; -- cgit v1.2.3