mirror of
https://github.com/rust-lang/rust.git
synced 2024-12-11 08:05:12 +00:00
remove Cancelable from nameres
This commit is contained in:
parent
18e9a710cd
commit
490112dea1
@ -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<ModuleScope> {
|
||||
pub fn scope(&self, db: &impl HirDatabase) -> ModuleScope {
|
||||
self.scope_impl(db)
|
||||
}
|
||||
|
||||
pub fn resolve_path(&self, db: &impl HirDatabase, path: &Path) -> Cancelable<PerNs<DefId>> {
|
||||
pub fn resolve_path(&self, db: &impl HirDatabase, path: &Path) -> PerNs<DefId> {
|
||||
self.resolve_path_impl(db, path)
|
||||
}
|
||||
|
||||
|
@ -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<ModuleScope> {
|
||||
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<PerNs<DefId>> {
|
||||
pub fn resolve_path_impl(&self, db: &impl HirDatabase, path: &Path) -> PerNs<DefId> {
|
||||
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(
|
||||
|
@ -87,7 +87,7 @@ pub trait HirDatabase: SyntaxDatabase
|
||||
use fn query_definitions::input_module_items;
|
||||
}
|
||||
|
||||
fn item_map(source_root_id: SourceRootId) -> Cancelable<Arc<ItemMap>> {
|
||||
fn item_map(source_root_id: SourceRootId) -> Arc<ItemMap> {
|
||||
type ItemMapQuery;
|
||||
use fn query_definitions::item_map;
|
||||
}
|
||||
|
@ -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<ItemMap> {
|
||||
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<InputModuleItems>,
|
||||
) -> Cancelable<()> {
|
||||
fn populate_module(&mut self, module_id: ModuleId, input: Arc<InputModuleItems>) {
|
||||
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<DefId>) {
|
||||
@ -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<bool> {
|
||||
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)) {
|
||||
|
@ -17,7 +17,7 @@ fn item_map(fixture: &str) -> (Arc<ItemMap>, 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"),
|
||||
|
@ -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<Arc<ItemMap>> {
|
||||
pub(super) fn item_map(db: &impl HirDatabase, source_root: SourceRootId) -> Arc<ItemMap> {
|
||||
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::<FxHashMap<_, _>>();
|
||||
|
||||
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)
|
||||
}
|
||||
|
@ -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));
|
||||
|
@ -8,13 +8,13 @@ pub(super) fn complete_path(acc: &mut Completions, ctx: &CompletionContext) -> C
|
||||
(Some(path), Some(module)) => (path.clone(), module),
|
||||
_ => return Ok(()),
|
||||
};
|
||||
let def_id = match module.resolve_path(ctx.db, &path)?.take_types() {
|
||||
let def_id = match module.resolve_path(ctx.db, &path).take_types() {
|
||||
Some(it) => it,
|
||||
None => return Ok(()),
|
||||
};
|
||||
match def_id.resolve(ctx.db) {
|
||||
hir::Def::Module(module) => {
|
||||
let module_scope = module.scope(ctx.db)?;
|
||||
let module_scope = module.scope(ctx.db);
|
||||
for (name, res) in module_scope.entries() {
|
||||
CompletionItem::new(CompletionKind::Reference, name.to_string())
|
||||
.from_resolution(ctx, res)
|
||||
|
@ -19,7 +19,7 @@ pub(super) fn complete_scope(acc: &mut Completions, ctx: &CompletionContext) ->
|
||||
complete_fn(acc, &scopes, ctx.offset);
|
||||
}
|
||||
|
||||
let module_scope = module.scope(ctx.db)?;
|
||||
let module_scope = module.scope(ctx.db);
|
||||
let (file_id, _) = module.definition_source(ctx.db);
|
||||
module_scope
|
||||
.entries()
|
||||
|
@ -85,7 +85,7 @@ pub(crate) fn reference_definition(
|
||||
.find_map(ast::Path::cast)
|
||||
.and_then(hir::Path::from_ast)
|
||||
{
|
||||
let resolved = module.resolve_path(db, &path)?;
|
||||
let resolved = module.resolve_path(db, &path);
|
||||
if let Some(def_id) = resolved.take_types().or(resolved.take_values()) {
|
||||
if let Some(target) = NavigationTarget::from_def(db, def_id.resolve(db)) {
|
||||
return Ok(Exact(target));
|
||||
|
Loading…
Reference in New Issue
Block a user