From 68ff52566d44e916868de1b52a9688182c26ebde Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 15 Jan 2019 17:55:15 +0300 Subject: remove Cancelable from module_tree_query --- crates/ra_hir/src/code_model_impl/krate.rs | 2 +- crates/ra_hir/src/code_model_impl/module.rs | 16 +++++++-------- crates/ra_hir/src/db.rs | 4 ++-- crates/ra_hir/src/module_tree.rs | 31 +++++++++++++---------------- crates/ra_hir/src/query_definitions.rs | 4 ++-- crates/ra_hir/src/source_binder.rs | 2 +- 6 files changed, 28 insertions(+), 31 deletions(-) (limited to 'crates') diff --git a/crates/ra_hir/src/code_model_impl/krate.rs b/crates/ra_hir/src/code_model_impl/krate.rs index 3275eafed..712c6c86a 100644 --- a/crates/ra_hir/src/code_model_impl/krate.rs +++ b/crates/ra_hir/src/code_model_impl/krate.rs @@ -25,7 +25,7 @@ impl Crate { let file_id = crate_graph.crate_root(self.crate_id); let source_root_id = db.file_source_root(file_id); let file_id = HirFileId::from(file_id); - let module_tree = db.module_tree(source_root_id)?; + let module_tree = db.module_tree(source_root_id); // FIXME: teach module tree about crate roots instead of guessing let source = SourceItemId { file_id, diff --git a/crates/ra_hir/src/code_model_impl/module.rs b/crates/ra_hir/src/code_model_impl/module.rs index 775dd6709..2ec3ab469 100644 --- a/crates/ra_hir/src/code_model_impl/module.rs +++ b/crates/ra_hir/src/code_model_impl/module.rs @@ -19,7 +19,7 @@ impl Module { source_root_id: SourceRootId, module_id: ModuleId, ) -> Cancelable { - let module_tree = db.module_tree(source_root_id)?; + let module_tree = db.module_tree(source_root_id); let def_loc = DefLoc { kind: DefKind::Module, source_root_id, @@ -33,7 +33,7 @@ impl Module { pub(crate) fn name_impl(&self, db: &impl HirDatabase) -> Cancelable> { let loc = self.def_id.loc(db); - let module_tree = db.module_tree(loc.source_root_id)?; + let module_tree = db.module_tree(loc.source_root_id); let link = ctry!(loc.module_id.parent_link(&module_tree)); Ok(Some(link.name(&module_tree).clone())) } @@ -59,7 +59,7 @@ impl Module { db: &impl HirDatabase, ) -> Cancelable)>> { let loc = self.def_id.loc(db); - let module_tree = db.module_tree(loc.source_root_id)?; + let module_tree = db.module_tree(loc.source_root_id); let link = ctry!(loc.module_id.parent_link(&module_tree)); let file_id = link .owner(&module_tree) @@ -82,7 +82,7 @@ impl Module { pub(crate) fn crate_root_impl(&self, db: &impl HirDatabase) -> Cancelable { let loc = self.def_id.loc(db); - let module_tree = db.module_tree(loc.source_root_id)?; + let module_tree = db.module_tree(loc.source_root_id); let module_id = loc.module_id.crate_root(&module_tree); Module::from_module_id(db, loc.source_root_id, module_id) } @@ -90,7 +90,7 @@ impl Module { /// Finds a child module with the specified name. pub fn child_impl(&self, db: &impl HirDatabase, name: &Name) -> Cancelable> { let loc = self.def_id.loc(db); - let module_tree = db.module_tree(loc.source_root_id)?; + let module_tree = db.module_tree(loc.source_root_id); let child_id = ctry!(loc.module_id.child(&module_tree, name)); Module::from_module_id(db, loc.source_root_id, child_id).map(Some) } @@ -101,7 +101,7 @@ impl Module { // it's kind of hard since the iterator needs to keep a reference to the // module tree. let loc = self.def_id.loc(db); - let module_tree = db.module_tree(loc.source_root_id)?; + let module_tree = db.module_tree(loc.source_root_id); let children = loc .module_id .children(&module_tree) @@ -112,7 +112,7 @@ impl Module { pub fn parent_impl(&self, db: &impl HirDatabase) -> Cancelable> { let loc = self.def_id.loc(db); - let module_tree = db.module_tree(loc.source_root_id)?; + let module_tree = db.module_tree(loc.source_root_id); let parent_id = ctry!(loc.module_id.parent(&module_tree)); Module::from_module_id(db, loc.source_root_id, parent_id).map(Some) } @@ -190,7 +190,7 @@ impl Module { db: &impl HirDatabase, ) -> Cancelable, Problem)>> { let loc = self.def_id.loc(db); - let module_tree = db.module_tree(loc.source_root_id)?; + let module_tree = db.module_tree(loc.source_root_id); Ok(loc.module_id.problems(&module_tree, db)) } } diff --git a/crates/ra_hir/src/db.rs b/crates/ra_hir/src/db.rs index fd6336dd8..68c3eb4e4 100644 --- a/crates/ra_hir/src/db.rs +++ b/crates/ra_hir/src/db.rs @@ -77,7 +77,7 @@ pub trait HirDatabase: SyntaxDatabase use fn query_definitions::file_item; } - fn submodules(source: SourceItemId) -> Cancelable>> { + fn submodules(source: SourceItemId) -> Arc> { type SubmodulesQuery; use fn crate::module_tree::Submodule::submodules_query; } @@ -92,7 +92,7 @@ pub trait HirDatabase: SyntaxDatabase use fn query_definitions::item_map; } - fn module_tree(source_root_id: SourceRootId) -> Cancelable> { + fn module_tree(source_root_id: SourceRootId) -> Arc { type ModuleTreeQuery; use fn crate::module_tree::ModuleTree::module_tree_query; } diff --git a/crates/ra_hir/src/module_tree.rs b/crates/ra_hir/src/module_tree.rs index fd5a92c5b..0256d7996 100644 --- a/crates/ra_hir/src/module_tree.rs +++ b/crates/ra_hir/src/module_tree.rs @@ -3,7 +3,7 @@ use std::sync::Arc; use rustc_hash::{FxHashMap, FxHashSet}; use arrayvec::ArrayVec; use relative_path::RelativePathBuf; -use ra_db::{FileId, SourceRootId, Cancelable, SourceRoot}; +use ra_db::{FileId, SourceRootId, SourceRoot}; use ra_syntax::{ SyntaxNode, TreeArc, algo::generate, @@ -41,7 +41,7 @@ impl Submodule { pub(crate) fn submodules_query( db: &impl HirDatabase, source: SourceItemId, - ) -> Cancelable>> { + ) -> Arc> { db.check_canceled(); let file_id = source.file_id; let file_items = db.file_items(file_id); @@ -54,7 +54,7 @@ impl Submodule { collect_submodules(file_id, &file_items, module.item_list().unwrap()) } }; - return Ok(Arc::new(submodules)); + return Arc::new(submodules); fn collect_submodules( file_id: HirFileId, @@ -116,10 +116,10 @@ impl ModuleTree { pub(crate) fn module_tree_query( db: &impl HirDatabase, source_root: SourceRootId, - ) -> Cancelable> { + ) -> Arc { db.check_canceled(); let res = create_module_tree(db, source_root); - Ok(Arc::new(res?)) + Arc::new(res) } pub(crate) fn modules<'a>(&'a self) -> impl Iterator + 'a { @@ -225,10 +225,7 @@ fn modules(root: &impl ast::ModuleItemOwner) -> impl Iterator( - db: &impl HirDatabase, - source_root: SourceRootId, -) -> Cancelable { +fn create_module_tree<'a>(db: &impl HirDatabase, source_root: SourceRootId) -> ModuleTree { let mut tree = ModuleTree::default(); let mut roots = FxHashMap::default(); @@ -252,10 +249,10 @@ fn create_module_tree<'a>( &mut roots, None, source, - )?; + ); roots.insert(file_id, module_id); } - Ok(tree) + tree } fn build_subtree( @@ -266,14 +263,14 @@ fn build_subtree( roots: &mut FxHashMap, parent: Option, source: SourceItemId, -) -> Cancelable { +) -> ModuleId { visited.insert(source); let id = tree.push_mod(ModuleData { source, parent, children: Vec::new(), }); - for sub in db.submodules(source)?.iter() { + for sub in db.submodules(source).iter() { let link = tree.push_link(LinkData { source: sub.source, name: sub.name.clone(), @@ -289,7 +286,7 @@ fn build_subtree( .map(|file_id| match roots.remove(&file_id) { Some(module_id) => { tree.mods[module_id].parent = Some(link); - Ok(module_id) + module_id } None => build_subtree( db, @@ -304,7 +301,7 @@ fn build_subtree( }, ), }) - .collect::>>()?; + .collect::>(); (points_to, problem) } else { let points_to = build_subtree( @@ -315,14 +312,14 @@ fn build_subtree( roots, Some(link), sub.source, - )?; + ); (vec![points_to], None) }; tree.links[link].points_to = points_to; tree.links[link].problem = problem; } - Ok(id) + id } fn resolve_submodule( diff --git a/crates/ra_hir/src/query_definitions.rs b/crates/ra_hir/src/query_definitions.rs index 214a9d68b..d84efbf95 100644 --- a/crates/ra_hir/src/query_definitions.rs +++ b/crates/ra_hir/src/query_definitions.rs @@ -48,7 +48,7 @@ pub(super) fn input_module_items( source_root_id: SourceRootId, module_id: ModuleId, ) -> Cancelable> { - let module_tree = db.module_tree(source_root_id)?; + let module_tree = db.module_tree(source_root_id); let source = module_id.source(&module_tree); let file_id = source.file_id; let source = ModuleSource::from_source_item_id(db, source); @@ -98,7 +98,7 @@ pub(super) fn item_map( source_root: SourceRootId, ) -> Cancelable> { let start = Instant::now(); - let module_tree = db.module_tree(source_root)?; + let module_tree = db.module_tree(source_root); let input = module_tree .modules() .map(|id| { diff --git a/crates/ra_hir/src/source_binder.rs b/crates/ra_hir/src/source_binder.rs index 1f149a366..70dd850d7 100644 --- a/crates/ra_hir/src/source_binder.rs +++ b/crates/ra_hir/src/source_binder.rs @@ -92,7 +92,7 @@ pub fn module_from_child_node( fn module_from_source(db: &impl HirDatabase, source: SourceItemId) -> Cancelable> { let source_root_id = db.file_source_root(source.file_id.as_original_file()); - let module_tree = db.module_tree(source_root_id)?; + let module_tree = db.module_tree(source_root_id); let module_id = ctry!(module_tree.find_module_by_source(source)); Ok(Some(Module::from_module_id(db, source_root_id, module_id)?)) } -- cgit v1.2.3