Skip to content

Commit

Permalink
Simplify
Browse files Browse the repository at this point in the history
  • Loading branch information
Veykril committed Aug 10, 2023
1 parent bfad781 commit 9adff00
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 30 deletions.
4 changes: 2 additions & 2 deletions crates/hir-def/src/item_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ use crate::{
path::{path, AssociatedTypeBinding, GenericArgs, ImportAlias, ModPath, Path, PathKind},
type_ref::{Mutability, TraitRef, TypeBound, TypeRef},
visibility::RawVisibility,
BlockId,
BlockId, Lookup,
};

#[derive(Copy, Clone, Eq, PartialEq)]
Expand Down Expand Up @@ -144,7 +144,7 @@ impl ItemTree {
}

pub(crate) fn block_item_tree_query(db: &dyn DefDatabase, block: BlockId) -> Arc<ItemTree> {
let loc = db.lookup_intern_block(block);
let loc = block.lookup(db);
let block = loc.ast_id.to_node(db.upcast());

let ctx = lower::Ctx::new(db, loc.ast_id.file_id);
Expand Down
7 changes: 3 additions & 4 deletions crates/hir-def/src/nameres.rs
Original file line number Diff line number Diff line change
Expand Up @@ -320,9 +320,7 @@ impl DefMap {
}

pub(crate) fn block_def_map_query(db: &dyn DefDatabase, block_id: BlockId) -> Arc<DefMap> {
let block: BlockLoc = db.lookup_intern_block(block_id);

let tree_id = TreeId::new(block.ast_id.file_id, Some(block_id));
let block: BlockLoc = block_id.lookup(db);

let parent_map = block.module.def_map(db);
let krate = block.module.krate;
Expand All @@ -346,7 +344,8 @@ impl DefMap {
},
});

let def_map = collector::collect_defs(db, def_map, tree_id);
let def_map =
collector::collect_defs(db, def_map, TreeId::new(block.ast_id.file_id, Some(block_id)));
Arc::new(def_map)
}

Expand Down
10 changes: 5 additions & 5 deletions crates/hir-def/src/nameres/collector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ use crate::{
visibility::{RawVisibility, Visibility},
AdtId, AstId, AstIdWithPath, ConstLoc, CrateRootModuleId, EnumLoc, EnumVariantId,
ExternBlockLoc, ExternCrateId, ExternCrateLoc, FunctionId, FunctionLoc, ImplLoc, Intern,
ItemContainerId, LocalModuleId, Macro2Id, Macro2Loc, MacroExpander, MacroId, MacroRulesId,
MacroRulesLoc, ModuleDefId, ModuleId, ProcMacroId, ProcMacroLoc, StaticLoc, StructLoc,
TraitAliasLoc, TraitLoc, TypeAliasLoc, UnionLoc, UnresolvedMacro, UseId, UseLoc,
ItemContainerId, LocalModuleId, Lookup, Macro2Id, Macro2Loc, MacroExpander, MacroId,
MacroRulesId, MacroRulesLoc, ModuleDefId, ModuleId, ProcMacroId, ProcMacroLoc, StaticLoc,
StructLoc, TraitAliasLoc, TraitLoc, TypeAliasLoc, UnionLoc, UnresolvedMacro, UseId, UseLoc,
};

static GLOB_RECURSION_LIMIT: Limit = Limit::new(100);
Expand Down Expand Up @@ -1461,7 +1461,7 @@ impl DefCollector<'_> {
let mut diagnosed_extern_crates = FxHashSet::default();
for directive in &self.unresolved_imports {
if let ImportSource::ExternCrate { id } = directive.import.source {
let item_tree_id = self.db.lookup_intern_extern_crate(id).id;
let item_tree_id = id.lookup(self.db).id;
let item_tree = item_tree_id.item_tree(self.db);
let extern_crate = &item_tree[item_tree_id.value];

Expand All @@ -1482,7 +1482,7 @@ impl DefCollector<'_> {
) {
continue;
}
let item_tree_id = self.db.lookup_intern_use(id).id;
let item_tree_id = id.lookup(self.db).id;
self.def_map.diagnostics.push(DefDiagnostic::unresolved_import(
directive.module_id,
item_tree_id,
Expand Down
5 changes: 1 addition & 4 deletions crates/hir-expand/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,7 @@ impl MacroCallKind {
};

let range = match kind {
MacroCallKind::FnLike { ast_id, .. } => ast_id.to_node(db).syntax().text_range(),
MacroCallKind::FnLike { ast_id, .. } => ast_id.to_ptr(db).text_range(),
MacroCallKind::Derive { ast_id, derive_attr_index, .. } => {
// FIXME: should be the range of the macro name, not the whole derive
// FIXME: handle `cfg_attr`
Expand Down Expand Up @@ -840,9 +840,6 @@ impl<N: AstIdNode> AstId<N> {
pub type ErasedAstId = InFile<ErasedFileAstId>;

impl ErasedAstId {
pub fn to_node(&self, db: &dyn db::ExpandDatabase) -> SyntaxNode {
self.to_ptr(db).to_node(&db.parse_or_expand(self.file_id))
}
pub fn to_ptr(&self, db: &dyn db::ExpandDatabase) -> SyntaxNodePtr {
db.ast_id_map(self.file_id).get_raw(self.value)
}
Expand Down
4 changes: 2 additions & 2 deletions crates/hir-ty/src/mir/lower.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use hir_def::{
path::Path,
resolver::{resolver_for_expr, HasResolver, ResolveValueResult, ValueNs},
AdtId, DefWithBodyId, EnumVariantId, GeneralConstId, HasModule, ItemContainerId, LocalFieldId,
TraitId, TypeOrConstParamId,
Lookup, TraitId, TypeOrConstParamId,
};
use hir_expand::name::Name;
use la_arena::ArenaMap;
Expand Down Expand Up @@ -372,7 +372,7 @@ impl<'ctx> MirLowerCtx<'ctx> {
match &self.body.exprs[expr_id] {
Expr::Missing => {
if let DefWithBodyId::FunctionId(f) = self.owner {
let assoc = self.db.lookup_intern_function(f);
let assoc = f.lookup(self.db.upcast());
if let ItemContainerId::TraitId(t) = assoc.container {
let name = &self.db.function_data(f).name;
return Err(MirLowerError::TraitFunctionDefinition(t, name.clone()));
Expand Down
20 changes: 7 additions & 13 deletions crates/hir/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -719,20 +719,18 @@ fn emit_def_diagnostic_(
) {
match diag {
DefDiagnosticKind::UnresolvedModule { ast: declaration, candidates } => {
let decl = declaration.to_node(db.upcast());
let decl = declaration.to_ptr(db.upcast());
acc.push(
UnresolvedModule {
decl: InFile::new(declaration.file_id, AstPtr::new(&decl)),
decl: InFile::new(declaration.file_id, decl),
candidates: candidates.clone(),
}
.into(),
)
}
DefDiagnosticKind::UnresolvedExternCrate { ast } => {
let item = ast.to_node(db.upcast());
acc.push(
UnresolvedExternCrate { decl: InFile::new(ast.file_id, AstPtr::new(&item)) }.into(),
);
let item = ast.to_ptr(db.upcast());
acc.push(UnresolvedExternCrate { decl: InFile::new(ast.file_id, item) }.into());
}

DefDiagnosticKind::UnresolvedImport { id, index } => {
Expand All @@ -747,14 +745,10 @@ fn emit_def_diagnostic_(
}

DefDiagnosticKind::UnconfiguredCode { ast, cfg, opts } => {
let item = ast.to_node(db.upcast());
let item = ast.to_ptr(db.upcast());
acc.push(
InactiveCode {
node: ast.with_value(SyntaxNodePtr::new(&item).into()),
cfg: cfg.clone(),
opts: opts.clone(),
}
.into(),
InactiveCode { node: ast.with_value(item), cfg: cfg.clone(), opts: opts.clone() }
.into(),
);
}
DefDiagnosticKind::UnresolvedProcMacro { ast, krate } => {
Expand Down

0 comments on commit 9adff00

Please sign in to comment.