553: remove Cancelable from fn_scopes r=matklad a=matklad



Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
This commit is contained in:
bors[bot] 2019-01-15 16:06:52 +00:00
commit 72a4951023
12 changed files with 29 additions and 34 deletions

View file

@ -301,17 +301,17 @@ impl Function {
def_id_to_ast(db, self.def_id) def_id_to_ast(db, self.def_id)
} }
pub fn body_syntax_mapping(&self, db: &impl HirDatabase) -> Cancelable<Arc<BodySyntaxMapping>> { pub fn body_syntax_mapping(&self, db: &impl HirDatabase) -> Arc<BodySyntaxMapping> {
db.body_syntax_mapping(self.def_id) db.body_syntax_mapping(self.def_id)
} }
pub fn scopes(&self, db: &impl HirDatabase) -> Cancelable<ScopesWithSyntaxMapping> { pub fn scopes(&self, db: &impl HirDatabase) -> ScopesWithSyntaxMapping {
let scopes = db.fn_scopes(self.def_id)?; let scopes = db.fn_scopes(self.def_id);
let syntax_mapping = db.body_syntax_mapping(self.def_id)?; let syntax_mapping = db.body_syntax_mapping(self.def_id);
Ok(ScopesWithSyntaxMapping { ScopesWithSyntaxMapping {
scopes, scopes,
syntax_mapping, syntax_mapping,
}) }
} }
pub fn signature(&self, db: &impl HirDatabase) -> Arc<FnSignature> { pub fn signature(&self, db: &impl HirDatabase) -> Arc<FnSignature> {

View file

@ -20,7 +20,7 @@ impl Function {
Function { def_id } Function { def_id }
} }
pub(crate) fn body(&self, db: &impl HirDatabase) -> Cancelable<Arc<Body>> { pub(crate) fn body(&self, db: &impl HirDatabase) -> Arc<Body> {
db.body_hir(self.def_id) db.body_hir(self.def_id)
} }

View file

@ -32,7 +32,7 @@ pub trait HirDatabase: SyntaxDatabase
use fn crate::macros::expand_macro_invocation; use fn crate::macros::expand_macro_invocation;
} }
fn fn_scopes(def_id: DefId) -> Cancelable<Arc<FnScopes>> { fn fn_scopes(def_id: DefId) -> Arc<FnScopes> {
type FnScopesQuery; type FnScopesQuery;
use fn query_definitions::fn_scopes; use fn query_definitions::fn_scopes;
} }
@ -107,12 +107,12 @@ pub trait HirDatabase: SyntaxDatabase
use fn crate::ty::method_resolution::CrateImplBlocks::impls_in_crate_query; use fn crate::ty::method_resolution::CrateImplBlocks::impls_in_crate_query;
} }
fn body_hir(def_id: DefId) -> Cancelable<Arc<crate::expr::Body>> { fn body_hir(def_id: DefId) -> Arc<crate::expr::Body> {
type BodyHirQuery; type BodyHirQuery;
use fn crate::expr::body_hir; use fn crate::expr::body_hir;
} }
fn body_syntax_mapping(def_id: DefId) -> Cancelable<Arc<crate::expr::BodySyntaxMapping>> { fn body_syntax_mapping(def_id: DefId) -> Arc<crate::expr::BodySyntaxMapping> {
type BodySyntaxMappingQuery; type BodySyntaxMappingQuery;
use fn crate::expr::body_syntax_mapping; use fn crate::expr::body_syntax_mapping;
} }

View file

@ -4,10 +4,8 @@ use std::sync::Arc;
use rustc_hash::FxHashMap; use rustc_hash::FxHashMap;
use ra_arena::{Arena, RawId, impl_arena_id, map::ArenaMap}; use ra_arena::{Arena, RawId, impl_arena_id, map::ArenaMap};
use ra_db::{LocalSyntaxPtr, Cancelable}; use ra_db::LocalSyntaxPtr;
use ra_syntax::{ use ra_syntax::ast::{self, AstNode, LoopBodyOwner, ArgListOwner, NameOwner, LiteralFlavor};
ast::{self, AstNode, LoopBodyOwner, ArgListOwner, NameOwner, LiteralFlavor}
};
use crate::{Path, type_ref::{Mutability, TypeRef}, Name, HirDatabase, DefId, Def, name::AsName}; use crate::{Path, type_ref::{Mutability, TypeRef}, Name, HirDatabase, DefId, Def, name::AsName};
use crate::ty::primitive::{UintTy, UncertainIntTy, UncertainFloatTy}; use crate::ty::primitive::{UintTy, UncertainIntTy, UncertainFloatTy};
@ -358,8 +356,8 @@ impl Pat {
// Queries // Queries
pub(crate) fn body_hir(db: &impl HirDatabase, def_id: DefId) -> Cancelable<Arc<Body>> { pub(crate) fn body_hir(db: &impl HirDatabase, def_id: DefId) -> Arc<Body> {
Ok(Arc::clone(&body_syntax_mapping(db, def_id)?.body)) Arc::clone(&body_syntax_mapping(db, def_id).body)
} }
struct ExprCollector { struct ExprCollector {
@ -828,10 +826,7 @@ pub(crate) fn collect_fn_body_syntax(node: &ast::FnDef) -> BodySyntaxMapping {
collector.into_body_syntax_mapping(params, body) collector.into_body_syntax_mapping(params, body)
} }
pub(crate) fn body_syntax_mapping( pub(crate) fn body_syntax_mapping(db: &impl HirDatabase, def_id: DefId) -> Arc<BodySyntaxMapping> {
db: &impl HirDatabase,
def_id: DefId,
) -> Cancelable<Arc<BodySyntaxMapping>> {
let def = def_id.resolve(db); let def = def_id.resolve(db);
let body_syntax_mapping = match def { let body_syntax_mapping = match def {
@ -840,5 +835,5 @@ pub(crate) fn body_syntax_mapping(
_ => panic!("Trying to get body for item type without body"), _ => panic!("Trying to get body for item type without body"),
}; };
Ok(Arc::new(body_syntax_mapping)) Arc::new(body_syntax_mapping)
} }

View file

@ -18,10 +18,10 @@ use crate::{
nameres::{InputModuleItems, ItemMap, Resolver}, nameres::{InputModuleItems, ItemMap, Resolver},
}; };
pub(super) fn fn_scopes(db: &impl HirDatabase, def_id: DefId) -> Cancelable<Arc<FnScopes>> { pub(super) fn fn_scopes(db: &impl HirDatabase, def_id: DefId) -> Arc<FnScopes> {
let body = db.body_hir(def_id)?; let body = db.body_hir(def_id);
let res = FnScopes::new(body); let res = FnScopes::new(body);
Ok(Arc::new(res)) Arc::new(res)
} }
pub(super) fn file_items(db: &impl HirDatabase, file_id: HirFileId) -> Arc<SourceFileItems> { pub(super) fn file_items(db: &impl HirDatabase, file_id: HirFileId) -> Arc<SourceFileItems> {

View file

@ -1205,8 +1205,8 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
pub fn infer(db: &impl HirDatabase, def_id: DefId) -> Cancelable<Arc<InferenceResult>> { pub fn infer(db: &impl HirDatabase, def_id: DefId) -> Cancelable<Arc<InferenceResult>> {
db.check_canceled(); db.check_canceled();
let function = Function::new(def_id); // TODO: consts also need inference let function = Function::new(def_id); // TODO: consts also need inference
let body = function.body(db)?; let body = function.body(db);
let scopes = db.fn_scopes(def_id)?; let scopes = db.fn_scopes(def_id);
let module = function.module(db)?; let module = function.module(db)?;
let impl_block = function.impl_block(db)?; let impl_block = function.impl_block(db)?;
let mut ctx = InferenceContext::new(db, body, scopes, module, impl_block); let mut ctx = InferenceContext::new(db, body, scopes, module, impl_block);

View file

@ -322,7 +322,7 @@ fn infer(content: &str) -> String {
{ {
let func = source_binder::function_from_source(&db, file_id, fn_def).unwrap(); let func = source_binder::function_from_source(&db, file_id, fn_def).unwrap();
let inference_result = func.infer(&db).unwrap(); let inference_result = func.infer(&db).unwrap();
let body_syntax_mapping = func.body_syntax_mapping(&db).unwrap(); let body_syntax_mapping = func.body_syntax_mapping(&db);
let mut types = Vec::new(); let mut types = Vec::new();
for (pat, ty) in inference_result.type_of_pat.iter() { for (pat, ty) in inference_result.type_of_pat.iter() {
let syntax_ptr = match body_syntax_mapping.pat_syntax(pat) { let syntax_ptr = match body_syntax_mapping.pat_syntax(pat) {

View file

@ -10,7 +10,7 @@ pub(super) fn complete_dot(acc: &mut Completions, ctx: &CompletionContext) -> Ca
_ => return Ok(()), _ => return Ok(()),
}; };
let infer_result = function.infer(ctx.db)?; let infer_result = function.infer(ctx.db)?;
let syntax_mapping = function.body_syntax_mapping(ctx.db)?; let syntax_mapping = function.body_syntax_mapping(ctx.db);
let expr = match syntax_mapping.node_expr(receiver) { let expr = match syntax_mapping.node_expr(receiver) {
Some(expr) => expr, Some(expr) => expr,
None => return Ok(()), None => return Ok(()),

View file

@ -15,7 +15,7 @@ pub(super) fn complete_scope(acc: &mut Completions, ctx: &CompletionContext) ->
None => return Ok(()), None => return Ok(()),
}; };
if let Some(function) = &ctx.function { if let Some(function) = &ctx.function {
let scopes = function.scopes(ctx.db)?; let scopes = function.scopes(ctx.db);
complete_fn(acc, &scopes, ctx.offset); complete_fn(acc, &scopes, ctx.offset);
} }

View file

@ -50,7 +50,7 @@ pub(crate) fn reference_definition(
if let Some(function) = if let Some(function) =
hir::source_binder::function_from_child_node(db, file_id, name_ref.syntax()) hir::source_binder::function_from_child_node(db, file_id, name_ref.syntax())
{ {
let scope = function.scopes(db)?; let scope = function.scopes(db);
// First try to resolve the symbol locally // First try to resolve the symbol locally
if let Some(entry) = scope.resolve_local_name(name_ref) { if let Some(entry) = scope.resolve_local_name(name_ref) {
let nav = NavigationTarget::from_scope_entry(file_id, &entry); let nav = NavigationTarget::from_scope_entry(file_id, &entry);
@ -64,7 +64,7 @@ pub(crate) fn reference_definition(
.and_then(ast::MethodCallExpr::cast) .and_then(ast::MethodCallExpr::cast)
{ {
let infer_result = function.infer(db)?; let infer_result = function.infer(db)?;
let syntax_mapping = function.body_syntax_mapping(db)?; let syntax_mapping = function.body_syntax_mapping(db);
let expr = ast::Expr::cast(method_call.syntax()).unwrap(); let expr = ast::Expr::cast(method_call.syntax()).unwrap();
if let Some(def_id) = syntax_mapping if let Some(def_id) = syntax_mapping
.node_expr(expr) .node_expr(expr)

View file

@ -74,7 +74,7 @@ pub(crate) fn type_of(db: &RootDatabase, frange: FileRange) -> Cancelable<Option
parent_fn parent_fn
)); ));
let infer = function.infer(db)?; let infer = function.infer(db)?;
let syntax_mapping = function.body_syntax_mapping(db)?; let syntax_mapping = function.body_syntax_mapping(db);
if let Some(expr) = ast::Expr::cast(node).and_then(|e| syntax_mapping.node_expr(e)) { if let Some(expr) = ast::Expr::cast(node).and_then(|e| syntax_mapping.node_expr(e)) {
Ok(Some(infer[expr].to_string())) Ok(Some(infer[expr].to_string()))
} else if let Some(pat) = ast::Pat::cast(node).and_then(|p| syntax_mapping.node_pat(p)) { } else if let Some(pat) = ast::Pat::cast(node).and_then(|p| syntax_mapping.node_pat(p)) {

View file

@ -128,7 +128,7 @@ impl db::RootDatabase {
.collect::<Vec<_>>(); .collect::<Vec<_>>();
ret.extend( ret.extend(
descr descr
.scopes(self)? .scopes(self)
.find_all_refs(binding) .find_all_refs(binding)
.into_iter() .into_iter()
.map(|ref_desc| (position.file_id, ref_desc.range)), .map(|ref_desc| (position.file_id, ref_desc.range)),
@ -156,7 +156,7 @@ impl db::RootDatabase {
position.file_id, position.file_id,
name_ref.syntax(), name_ref.syntax(),
)); ));
let scope = descr.scopes(db)?; let scope = descr.scopes(db);
let resolved = ctry!(scope.resolve_local_name(name_ref)); let resolved = ctry!(scope.resolve_local_name(name_ref));
let resolved = resolved.ptr().resolve(source_file); let resolved = resolved.ptr().resolve(source_file);
let binding = ctry!(find_node_at_offset::<ast::BindPat>( let binding = ctry!(find_node_at_offset::<ast::BindPat>(