aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbors[bot] <bors[bot]@users.noreply.github.com>2019-01-15 16:06:52 +0000
committerbors[bot] <bors[bot]@users.noreply.github.com>2019-01-15 16:06:52 +0000
commit72a4951023f11adfdf0eac353c99d8a01a9471fc (patch)
tree8cca098650d989ea58e6bd4aafd44e5ff85fcee5
parent7c977a7dcd2bac3b6148f2428bcb586c6354d775 (diff)
parent18e9a710cd2f2ced84fde19e88d0b967dcb5939e (diff)
Merge #553
553: remove Cancelable from fn_scopes r=matklad a=matklad Co-authored-by: Aleksey Kladov <[email protected]>
-rw-r--r--crates/ra_hir/src/code_model_api.rs12
-rw-r--r--crates/ra_hir/src/code_model_impl/function.rs2
-rw-r--r--crates/ra_hir/src/db.rs6
-rw-r--r--crates/ra_hir/src/expr.rs17
-rw-r--r--crates/ra_hir/src/query_definitions.rs6
-rw-r--r--crates/ra_hir/src/ty.rs4
-rw-r--r--crates/ra_hir/src/ty/tests.rs2
-rw-r--r--crates/ra_ide_api/src/completion/complete_dot.rs2
-rw-r--r--crates/ra_ide_api/src/completion/complete_scope.rs2
-rw-r--r--crates/ra_ide_api/src/goto_definition.rs4
-rw-r--r--crates/ra_ide_api/src/hover.rs2
-rw-r--r--crates/ra_ide_api/src/imp.rs4
12 files changed, 29 insertions, 34 deletions
diff --git a/crates/ra_hir/src/code_model_api.rs b/crates/ra_hir/src/code_model_api.rs
index f28e077c6..4d7925ac4 100644
--- a/crates/ra_hir/src/code_model_api.rs
+++ b/crates/ra_hir/src/code_model_api.rs
@@ -301,17 +301,17 @@ impl Function {
301 def_id_to_ast(db, self.def_id) 301 def_id_to_ast(db, self.def_id)
302 } 302 }
303 303
304 pub fn body_syntax_mapping(&self, db: &impl HirDatabase) -> Cancelable<Arc<BodySyntaxMapping>> { 304 pub fn body_syntax_mapping(&self, db: &impl HirDatabase) -> Arc<BodySyntaxMapping> {
305 db.body_syntax_mapping(self.def_id) 305 db.body_syntax_mapping(self.def_id)
306 } 306 }
307 307
308 pub fn scopes(&self, db: &impl HirDatabase) -> Cancelable<ScopesWithSyntaxMapping> { 308 pub fn scopes(&self, db: &impl HirDatabase) -> ScopesWithSyntaxMapping {
309 let scopes = db.fn_scopes(self.def_id)?; 309 let scopes = db.fn_scopes(self.def_id);
310 let syntax_mapping = db.body_syntax_mapping(self.def_id)?; 310 let syntax_mapping = db.body_syntax_mapping(self.def_id);
311 Ok(ScopesWithSyntaxMapping { 311 ScopesWithSyntaxMapping {
312 scopes, 312 scopes,
313 syntax_mapping, 313 syntax_mapping,
314 }) 314 }
315 } 315 }
316 316
317 pub fn signature(&self, db: &impl HirDatabase) -> Arc<FnSignature> { 317 pub fn signature(&self, db: &impl HirDatabase) -> Arc<FnSignature> {
diff --git a/crates/ra_hir/src/code_model_impl/function.rs b/crates/ra_hir/src/code_model_impl/function.rs
index 8d6b7fc19..d34803e32 100644
--- a/crates/ra_hir/src/code_model_impl/function.rs
+++ b/crates/ra_hir/src/code_model_impl/function.rs
@@ -20,7 +20,7 @@ impl Function {
20 Function { def_id } 20 Function { def_id }
21 } 21 }
22 22
23 pub(crate) fn body(&self, db: &impl HirDatabase) -> Cancelable<Arc<Body>> { 23 pub(crate) fn body(&self, db: &impl HirDatabase) -> Arc<Body> {
24 db.body_hir(self.def_id) 24 db.body_hir(self.def_id)
25 } 25 }
26 26
diff --git a/crates/ra_hir/src/db.rs b/crates/ra_hir/src/db.rs
index 6229f9778..d20c03f43 100644
--- a/crates/ra_hir/src/db.rs
+++ b/crates/ra_hir/src/db.rs
@@ -32,7 +32,7 @@ pub trait HirDatabase: SyntaxDatabase
32 use fn crate::macros::expand_macro_invocation; 32 use fn crate::macros::expand_macro_invocation;
33 } 33 }
34 34
35 fn fn_scopes(def_id: DefId) -> Cancelable<Arc<FnScopes>> { 35 fn fn_scopes(def_id: DefId) -> Arc<FnScopes> {
36 type FnScopesQuery; 36 type FnScopesQuery;
37 use fn query_definitions::fn_scopes; 37 use fn query_definitions::fn_scopes;
38 } 38 }
@@ -107,12 +107,12 @@ pub trait HirDatabase: SyntaxDatabase
107 use fn crate::ty::method_resolution::CrateImplBlocks::impls_in_crate_query; 107 use fn crate::ty::method_resolution::CrateImplBlocks::impls_in_crate_query;
108 } 108 }
109 109
110 fn body_hir(def_id: DefId) -> Cancelable<Arc<crate::expr::Body>> { 110 fn body_hir(def_id: DefId) -> Arc<crate::expr::Body> {
111 type BodyHirQuery; 111 type BodyHirQuery;
112 use fn crate::expr::body_hir; 112 use fn crate::expr::body_hir;
113 } 113 }
114 114
115 fn body_syntax_mapping(def_id: DefId) -> Cancelable<Arc<crate::expr::BodySyntaxMapping>> { 115 fn body_syntax_mapping(def_id: DefId) -> Arc<crate::expr::BodySyntaxMapping> {
116 type BodySyntaxMappingQuery; 116 type BodySyntaxMappingQuery;
117 use fn crate::expr::body_syntax_mapping; 117 use fn crate::expr::body_syntax_mapping;
118 } 118 }
diff --git a/crates/ra_hir/src/expr.rs b/crates/ra_hir/src/expr.rs
index a1e8da348..4e8dc0c54 100644
--- a/crates/ra_hir/src/expr.rs
+++ b/crates/ra_hir/src/expr.rs
@@ -4,10 +4,8 @@ use std::sync::Arc;
4use rustc_hash::FxHashMap; 4use rustc_hash::FxHashMap;
5 5
6use ra_arena::{Arena, RawId, impl_arena_id, map::ArenaMap}; 6use ra_arena::{Arena, RawId, impl_arena_id, map::ArenaMap};
7use ra_db::{LocalSyntaxPtr, Cancelable}; 7use ra_db::LocalSyntaxPtr;
8use ra_syntax::{ 8use ra_syntax::ast::{self, AstNode, LoopBodyOwner, ArgListOwner, NameOwner, LiteralFlavor};
9 ast::{self, AstNode, LoopBodyOwner, ArgListOwner, NameOwner, LiteralFlavor}
10};
11 9
12use crate::{Path, type_ref::{Mutability, TypeRef}, Name, HirDatabase, DefId, Def, name::AsName}; 10use crate::{Path, type_ref::{Mutability, TypeRef}, Name, HirDatabase, DefId, Def, name::AsName};
13use crate::ty::primitive::{UintTy, UncertainIntTy, UncertainFloatTy}; 11use crate::ty::primitive::{UintTy, UncertainIntTy, UncertainFloatTy};
@@ -358,8 +356,8 @@ impl Pat {
358 356
359// Queries 357// Queries
360 358
361pub(crate) fn body_hir(db: &impl HirDatabase, def_id: DefId) -> Cancelable<Arc<Body>> { 359pub(crate) fn body_hir(db: &impl HirDatabase, def_id: DefId) -> Arc<Body> {
362 Ok(Arc::clone(&body_syntax_mapping(db, def_id)?.body)) 360 Arc::clone(&body_syntax_mapping(db, def_id).body)
363} 361}
364 362
365struct ExprCollector { 363struct ExprCollector {
@@ -828,10 +826,7 @@ pub(crate) fn collect_fn_body_syntax(node: &ast::FnDef) -> BodySyntaxMapping {
828 collector.into_body_syntax_mapping(params, body) 826 collector.into_body_syntax_mapping(params, body)
829} 827}
830 828
831pub(crate) fn body_syntax_mapping( 829pub(crate) fn body_syntax_mapping(db: &impl HirDatabase, def_id: DefId) -> Arc<BodySyntaxMapping> {
832 db: &impl HirDatabase,
833 def_id: DefId,
834) -> Cancelable<Arc<BodySyntaxMapping>> {
835 let def = def_id.resolve(db); 830 let def = def_id.resolve(db);
836 831
837 let body_syntax_mapping = match def { 832 let body_syntax_mapping = match def {
@@ -840,5 +835,5 @@ pub(crate) fn body_syntax_mapping(
840 _ => panic!("Trying to get body for item type without body"), 835 _ => panic!("Trying to get body for item type without body"),
841 }; 836 };
842 837
843 Ok(Arc::new(body_syntax_mapping)) 838 Arc::new(body_syntax_mapping)
844} 839}
diff --git a/crates/ra_hir/src/query_definitions.rs b/crates/ra_hir/src/query_definitions.rs
index 7ff942f6a..8f33ec707 100644
--- a/crates/ra_hir/src/query_definitions.rs
+++ b/crates/ra_hir/src/query_definitions.rs
@@ -18,10 +18,10 @@ use crate::{
18 nameres::{InputModuleItems, ItemMap, Resolver}, 18 nameres::{InputModuleItems, ItemMap, Resolver},
19}; 19};
20 20
21pub(super) fn fn_scopes(db: &impl HirDatabase, def_id: DefId) -> Cancelable<Arc<FnScopes>> { 21pub(super) fn fn_scopes(db: &impl HirDatabase, def_id: DefId) -> Arc<FnScopes> {
22 let body = db.body_hir(def_id)?; 22 let body = db.body_hir(def_id);
23 let res = FnScopes::new(body); 23 let res = FnScopes::new(body);
24 Ok(Arc::new(res)) 24 Arc::new(res)
25} 25}
26 26
27pub(super) fn file_items(db: &impl HirDatabase, file_id: HirFileId) -> Arc<SourceFileItems> { 27pub(super) fn file_items(db: &impl HirDatabase, file_id: HirFileId) -> Arc<SourceFileItems> {
diff --git a/crates/ra_hir/src/ty.rs b/crates/ra_hir/src/ty.rs
index 3607969ed..54eece165 100644
--- a/crates/ra_hir/src/ty.rs
+++ b/crates/ra_hir/src/ty.rs
@@ -1205,8 +1205,8 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
1205pub fn infer(db: &impl HirDatabase, def_id: DefId) -> Cancelable<Arc<InferenceResult>> { 1205pub fn infer(db: &impl HirDatabase, def_id: DefId) -> Cancelable<Arc<InferenceResult>> {
1206 db.check_canceled(); 1206 db.check_canceled();
1207 let function = Function::new(def_id); // TODO: consts also need inference 1207 let function = Function::new(def_id); // TODO: consts also need inference
1208 let body = function.body(db)?; 1208 let body = function.body(db);
1209 let scopes = db.fn_scopes(def_id)?; 1209 let scopes = db.fn_scopes(def_id);
1210 let module = function.module(db)?; 1210 let module = function.module(db)?;
1211 let impl_block = function.impl_block(db)?; 1211 let impl_block = function.impl_block(db)?;
1212 let mut ctx = InferenceContext::new(db, body, scopes, module, impl_block); 1212 let mut ctx = InferenceContext::new(db, body, scopes, module, impl_block);
diff --git a/crates/ra_hir/src/ty/tests.rs b/crates/ra_hir/src/ty/tests.rs
index b81d91e80..b44ac9987 100644
--- a/crates/ra_hir/src/ty/tests.rs
+++ b/crates/ra_hir/src/ty/tests.rs
@@ -322,7 +322,7 @@ fn infer(content: &str) -> String {
322 { 322 {
323 let func = source_binder::function_from_source(&db, file_id, fn_def).unwrap(); 323 let func = source_binder::function_from_source(&db, file_id, fn_def).unwrap();
324 let inference_result = func.infer(&db).unwrap(); 324 let inference_result = func.infer(&db).unwrap();
325 let body_syntax_mapping = func.body_syntax_mapping(&db).unwrap(); 325 let body_syntax_mapping = func.body_syntax_mapping(&db);
326 let mut types = Vec::new(); 326 let mut types = Vec::new();
327 for (pat, ty) in inference_result.type_of_pat.iter() { 327 for (pat, ty) in inference_result.type_of_pat.iter() {
328 let syntax_ptr = match body_syntax_mapping.pat_syntax(pat) { 328 let syntax_ptr = match body_syntax_mapping.pat_syntax(pat) {
diff --git a/crates/ra_ide_api/src/completion/complete_dot.rs b/crates/ra_ide_api/src/completion/complete_dot.rs
index 886dc54d4..cb86ba9a3 100644
--- a/crates/ra_ide_api/src/completion/complete_dot.rs
+++ b/crates/ra_ide_api/src/completion/complete_dot.rs
@@ -10,7 +10,7 @@ pub(super) fn complete_dot(acc: &mut Completions, ctx: &CompletionContext) -> Ca
10 _ => return Ok(()), 10 _ => return Ok(()),
11 }; 11 };
12 let infer_result = function.infer(ctx.db)?; 12 let infer_result = function.infer(ctx.db)?;
13 let syntax_mapping = function.body_syntax_mapping(ctx.db)?; 13 let syntax_mapping = function.body_syntax_mapping(ctx.db);
14 let expr = match syntax_mapping.node_expr(receiver) { 14 let expr = match syntax_mapping.node_expr(receiver) {
15 Some(expr) => expr, 15 Some(expr) => expr,
16 None => return Ok(()), 16 None => return Ok(()),
diff --git a/crates/ra_ide_api/src/completion/complete_scope.rs b/crates/ra_ide_api/src/completion/complete_scope.rs
index f422bb9a7..fdb64895e 100644
--- a/crates/ra_ide_api/src/completion/complete_scope.rs
+++ b/crates/ra_ide_api/src/completion/complete_scope.rs
@@ -15,7 +15,7 @@ pub(super) fn complete_scope(acc: &mut Completions, ctx: &CompletionContext) ->
15 None => return Ok(()), 15 None => return Ok(()),
16 }; 16 };
17 if let Some(function) = &ctx.function { 17 if let Some(function) = &ctx.function {
18 let scopes = function.scopes(ctx.db)?; 18 let scopes = function.scopes(ctx.db);
19 complete_fn(acc, &scopes, ctx.offset); 19 complete_fn(acc, &scopes, ctx.offset);
20 } 20 }
21 21
diff --git a/crates/ra_ide_api/src/goto_definition.rs b/crates/ra_ide_api/src/goto_definition.rs
index 7229293a4..5d522181b 100644
--- a/crates/ra_ide_api/src/goto_definition.rs
+++ b/crates/ra_ide_api/src/goto_definition.rs
@@ -50,7 +50,7 @@ pub(crate) fn reference_definition(
50 if let Some(function) = 50 if let Some(function) =
51 hir::source_binder::function_from_child_node(db, file_id, name_ref.syntax()) 51 hir::source_binder::function_from_child_node(db, file_id, name_ref.syntax())
52 { 52 {
53 let scope = function.scopes(db)?; 53 let scope = function.scopes(db);
54 // First try to resolve the symbol locally 54 // First try to resolve the symbol locally
55 if let Some(entry) = scope.resolve_local_name(name_ref) { 55 if let Some(entry) = scope.resolve_local_name(name_ref) {
56 let nav = NavigationTarget::from_scope_entry(file_id, &entry); 56 let nav = NavigationTarget::from_scope_entry(file_id, &entry);
@@ -64,7 +64,7 @@ pub(crate) fn reference_definition(
64 .and_then(ast::MethodCallExpr::cast) 64 .and_then(ast::MethodCallExpr::cast)
65 { 65 {
66 let infer_result = function.infer(db)?; 66 let infer_result = function.infer(db)?;
67 let syntax_mapping = function.body_syntax_mapping(db)?; 67 let syntax_mapping = function.body_syntax_mapping(db);
68 let expr = ast::Expr::cast(method_call.syntax()).unwrap(); 68 let expr = ast::Expr::cast(method_call.syntax()).unwrap();
69 if let Some(def_id) = syntax_mapping 69 if let Some(def_id) = syntax_mapping
70 .node_expr(expr) 70 .node_expr(expr)
diff --git a/crates/ra_ide_api/src/hover.rs b/crates/ra_ide_api/src/hover.rs
index 26f3ced70..0e9c48421 100644
--- a/crates/ra_ide_api/src/hover.rs
+++ b/crates/ra_ide_api/src/hover.rs
@@ -74,7 +74,7 @@ pub(crate) fn type_of(db: &RootDatabase, frange: FileRange) -> Cancelable<Option
74 parent_fn 74 parent_fn
75 )); 75 ));
76 let infer = function.infer(db)?; 76 let infer = function.infer(db)?;
77 let syntax_mapping = function.body_syntax_mapping(db)?; 77 let syntax_mapping = function.body_syntax_mapping(db);
78 if let Some(expr) = ast::Expr::cast(node).and_then(|e| syntax_mapping.node_expr(e)) { 78 if let Some(expr) = ast::Expr::cast(node).and_then(|e| syntax_mapping.node_expr(e)) {
79 Ok(Some(infer[expr].to_string())) 79 Ok(Some(infer[expr].to_string()))
80 } else if let Some(pat) = ast::Pat::cast(node).and_then(|p| syntax_mapping.node_pat(p)) { 80 } else if let Some(pat) = ast::Pat::cast(node).and_then(|p| syntax_mapping.node_pat(p)) {
diff --git a/crates/ra_ide_api/src/imp.rs b/crates/ra_ide_api/src/imp.rs
index 3ef11dfa1..8b2cd6e27 100644
--- a/crates/ra_ide_api/src/imp.rs
+++ b/crates/ra_ide_api/src/imp.rs
@@ -128,7 +128,7 @@ impl db::RootDatabase {
128 .collect::<Vec<_>>(); 128 .collect::<Vec<_>>();
129 ret.extend( 129 ret.extend(
130 descr 130 descr
131 .scopes(self)? 131 .scopes(self)
132 .find_all_refs(binding) 132 .find_all_refs(binding)
133 .into_iter() 133 .into_iter()
134 .map(|ref_desc| (position.file_id, ref_desc.range)), 134 .map(|ref_desc| (position.file_id, ref_desc.range)),
@@ -156,7 +156,7 @@ impl db::RootDatabase {
156 position.file_id, 156 position.file_id,
157 name_ref.syntax(), 157 name_ref.syntax(),
158 )); 158 ));
159 let scope = descr.scopes(db)?; 159 let scope = descr.scopes(db);
160 let resolved = ctry!(scope.resolve_local_name(name_ref)); 160 let resolved = ctry!(scope.resolve_local_name(name_ref));
161 let resolved = resolved.ptr().resolve(source_file); 161 let resolved = resolved.ptr().resolve(source_file);
162 let binding = ctry!(find_node_at_offset::<ast::BindPat>( 162 let binding = ctry!(find_node_at_offset::<ast::BindPat>(