Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions crates/hir-def/src/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ use la_arena::ArenaMap;
use triomphe::Arc;

use crate::{
AssocItemId, AttrDefId, ConstId, ConstLoc, DefWithBodyId, EnumId, EnumLoc, EnumVariantId,
EnumVariantLoc, ExternBlockId, ExternBlockLoc, ExternCrateId, ExternCrateLoc, FunctionId,
FunctionLoc, GenericDefId, ImplId, ImplLoc, LocalFieldId, Macro2Id, Macro2Loc, MacroExpander,
MacroId, MacroRulesId, MacroRulesLoc, MacroRulesLocFlags, ProcMacroId, ProcMacroLoc, StaticId,
StaticLoc, StructId, StructLoc, TraitId, TraitLoc, TypeAliasId, TypeAliasLoc, UnionId,
UnionLoc, UseId, UseLoc, VariantId,
AssocItemId, AttrDefId, BlockId, BlockLoc, ConstId, ConstLoc, DefWithBodyId, EnumId, EnumLoc,
EnumVariantId, EnumVariantLoc, ExternBlockId, ExternBlockLoc, ExternCrateId, ExternCrateLoc,
FunctionId, FunctionLoc, GenericDefId, ImplId, ImplLoc, LocalFieldId, Macro2Id, Macro2Loc,
MacroExpander, MacroId, MacroRulesId, MacroRulesLoc, MacroRulesLocFlags, ProcMacroId,
ProcMacroLoc, StaticId, StaticLoc, StructId, StructLoc, TraitId, TraitLoc, TypeAliasId,
TypeAliasLoc, UnionId, UnionLoc, UseId, UseLoc, VariantId,
attrs::AttrFlags,
expr_store::{
Body, BodySourceMap, ExpressionStore, ExpressionStoreSourceMap, scope::ExprScopes,
Expand Down Expand Up @@ -82,6 +82,9 @@ pub trait InternDatabase: RootQueryDb {
#[salsa::interned]
fn intern_macro_rules(&self, loc: MacroRulesLoc) -> MacroRulesId;
// endregion: items

#[salsa::interned]
fn intern_block(&self, loc: BlockLoc) -> BlockId;
}

#[query_group::query_group]
Expand Down
4 changes: 2 additions & 2 deletions crates/hir-def/src/expr_store/lower.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ use triomphe::Arc;
use tt::TextRange;

use crate::{
AdtId, BlockId, BlockIdLt, DefWithBodyId, FunctionId, GenericDefId, ImplId, MacroId,
AdtId, BlockId, BlockLoc, DefWithBodyId, FunctionId, GenericDefId, ImplId, MacroId,
ModuleDefId, ModuleId, TraitId, TypeAliasId, UnresolvedMacro,
attrs::AttrFlags,
builtin_type::BuiltinUint,
Expand Down Expand Up @@ -2114,7 +2114,7 @@ impl<'db> ExprCollector<'db> {
) -> ExprId {
let block_id = self.expander.ast_id_map().ast_id_for_block(&block).map(|file_local_id| {
let ast_id = self.expander.in_file(file_local_id);
unsafe { BlockIdLt::new(self.db, ast_id, self.module).to_static() }
self.db.intern_block(BlockLoc { ast_id, module: self.module })
});

let (module, def_map) =
Expand Down
52 changes: 3 additions & 49 deletions crates/hir-def/src/expr_store/tests/body/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,55 +195,9 @@ fn f() {
Id(1c00),
),
block: Some(
BlockIdLt {
[salsa id]: Id(3c01),
ast_id: InFileWrapper {
file_id: FileId(
EditionedFileIdData {
editioned_file_id: EditionedFileId(
0,
Edition2024,
),
krate: Crate(
Id(1c00),
),
},
),
value: FileAstId::<syntax::ast::generated::nodes::BlockExpr>(ErasedFileAstId { kind: BlockExpr, index: 0, hash: F9BF }),
},
module: ModuleIdLt {
[salsa id]: Id(3002),
krate: Crate(
Id(1c00),
),
block: Some(
BlockIdLt {
[salsa id]: Id(3c00),
ast_id: InFileWrapper {
file_id: FileId(
EditionedFileIdData {
editioned_file_id: EditionedFileId(
0,
Edition2024,
),
krate: Crate(
Id(1c00),
),
},
),
value: FileAstId::<syntax::ast::generated::nodes::BlockExpr>(ErasedFileAstId { kind: BlockExpr, index: 0, hash: C181 }),
},
module: ModuleIdLt {
[salsa id]: Id(3000),
krate: Crate(
Id(1c00),
),
block: None,
},
},
),
},
},
BlockId(
3c01,
),
),
}"#]],
);
Expand Down
66 changes: 33 additions & 33 deletions crates/hir-def/src/find_path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use intern::sym;
use rustc_hash::FxHashSet;

use crate::{
FindPathConfig, ModuleDefId, ModuleIdLt,
FindPathConfig, ModuleDefId, ModuleId,
db::DefDatabase,
item_scope::ItemInNs,
nameres::DefMap,
Expand All @@ -24,7 +24,7 @@ use crate::{
pub fn find_path(
db: &dyn DefDatabase,
item: ItemInNs,
from: ModuleIdLt<'_>,
from: ModuleId,
mut prefix_kind: PrefixKind,
ignore_local_imports: bool,
mut cfg: FindPathConfig,
Expand Down Expand Up @@ -102,14 +102,14 @@ struct FindPathCtx<'db> {
cfg: FindPathConfig,
ignore_local_imports: bool,
is_std_item: bool,
from: ModuleIdLt<'db>,
from: ModuleId,
from_crate: Crate,
crate_root: ModuleIdLt<'db>,
crate_root: ModuleId,
from_def_map: &'db DefMap,
fuel: Cell<usize>,
}

/// Attempts to find a path to refer to the given `item` visible from the `from` ModuleIdLt<'_>
/// Attempts to find a path to refer to the given `item` visible from the `from` ModuleId
fn find_path_inner(ctx: &FindPathCtx<'_>, item: ItemInNs, max_len: usize) -> Option<ModPath> {
// - if the item is a module, jump straight to module search
if !ctx.is_std_item
Expand Down Expand Up @@ -157,10 +157,10 @@ fn find_path_inner(ctx: &FindPathCtx<'_>, item: ItemInNs, max_len: usize) -> Opt
}

#[tracing::instrument(skip_all)]
fn find_path_for_module<'db>(
ctx: &'db FindPathCtx<'db>,
visited_modules: &mut FxHashSet<(ItemInNs, ModuleIdLt<'db>)>,
module_id: ModuleIdLt<'db>,
fn find_path_for_module(
ctx: &FindPathCtx<'_>,
visited_modules: &mut FxHashSet<(ItemInNs, ModuleId)>,
module_id: ModuleId,
maybe_extern: bool,
max_len: usize,
) -> Option<Choice> {
Expand Down Expand Up @@ -217,7 +217,7 @@ fn find_path_for_module<'db>(
ctx.db,
ctx.from_def_map,
ctx.from,
ItemInNs::Types(unsafe { module_id.to_static() }.into()),
ItemInNs::Types(module_id.into()),
ctx.ignore_local_imports,
);
if let Some(scope_name) = scope_name {
Expand All @@ -244,7 +244,7 @@ fn find_path_for_module<'db>(
}

// - if the module is in the prelude, return it by that path
let item = ItemInNs::Types(unsafe { module_id.to_static() }.into());
let item = ItemInNs::Types(module_id.into());
if let Some(choice) = find_in_prelude(ctx.db, ctx.from_def_map, item, ctx.from) {
return Some(choice);
}
Expand All @@ -257,10 +257,10 @@ fn find_path_for_module<'db>(
best_choice
}

fn find_in_scope<'db>(
db: &'db dyn DefDatabase,
fn find_in_scope(
db: &dyn DefDatabase,
def_map: &DefMap,
from: ModuleIdLt<'db>,
from: ModuleId,
item: ItemInNs,
ignore_local_imports: bool,
) -> Option<Name> {
Expand All @@ -278,7 +278,7 @@ fn find_in_prelude(
db: &dyn DefDatabase,
local_def_map: &DefMap,
item: ItemInNs,
from: ModuleIdLt<'_>,
from: ModuleId,
) -> Option<Choice> {
let (prelude_module, _) = local_def_map.prelude()?;
let prelude_def_map = prelude_module.def_map(db);
Expand Down Expand Up @@ -310,8 +310,8 @@ fn find_in_prelude(
fn is_kw_kind_relative_to_from(
db: &dyn DefDatabase,
def_map: &DefMap,
item: ModuleIdLt<'_>,
from: ModuleIdLt<'_>,
item: ModuleId,
from: ModuleId,
) -> Option<PathKind> {
if item.krate(db) != from.krate(db) || item.block(db).is_some() || from.block(db).is_some() {
return None;
Expand All @@ -332,9 +332,9 @@ fn is_kw_kind_relative_to_from(
}

#[tracing::instrument(skip_all)]
fn calculate_best_path<'db>(
ctx: &'db FindPathCtx<'db>,
visited_modules: &mut FxHashSet<(ItemInNs, ModuleIdLt<'db>)>,
fn calculate_best_path(
ctx: &FindPathCtx<'_>,
visited_modules: &mut FxHashSet<(ItemInNs, ModuleId)>,
item: ItemInNs,
max_len: usize,
best_choice: &mut Option<Choice>,
Expand Down Expand Up @@ -372,9 +372,9 @@ fn calculate_best_path<'db>(
}
}

fn find_in_sysroot<'db>(
ctx: &'db FindPathCtx<'db>,
visited_modules: &mut FxHashSet<(ItemInNs, ModuleIdLt<'db>)>,
fn find_in_sysroot(
ctx: &FindPathCtx<'_>,
visited_modules: &mut FxHashSet<(ItemInNs, ModuleId)>,
item: ItemInNs,
max_len: usize,
best_choice: &mut Option<Choice>,
Expand Down Expand Up @@ -418,9 +418,9 @@ fn find_in_sysroot<'db>(
});
}

fn find_in_dep<'db>(
ctx: &'db FindPathCtx<'db>,
visited_modules: &mut FxHashSet<(ItemInNs, ModuleIdLt<'db>)>,
fn find_in_dep(
ctx: &FindPathCtx<'_>,
visited_modules: &mut FxHashSet<(ItemInNs, ModuleId)>,
item: ItemInNs,
max_len: usize,
best_choice: &mut Option<Choice>,
Expand Down Expand Up @@ -461,9 +461,9 @@ fn find_in_dep<'db>(
}
}

fn calculate_best_path_local<'db>(
ctx: &'db FindPathCtx<'db>,
visited_modules: &mut FxHashSet<(ItemInNs, ModuleIdLt<'db>)>,
fn calculate_best_path_local(
ctx: &FindPathCtx<'_>,
visited_modules: &mut FxHashSet<(ItemInNs, ModuleId)>,
item: ItemInNs,
max_len: usize,
best_choice: &mut Option<Choice>,
Expand Down Expand Up @@ -558,11 +558,11 @@ fn path_kind_len(kind: PathKind) -> usize {
}

/// Finds locations in `from.krate` from which `item` can be imported by `from`.
fn find_local_import_locations<'db>(
ctx: &'db FindPathCtx<'db>,
fn find_local_import_locations(
ctx: &FindPathCtx<'_>,
item: ItemInNs,
visited_modules: &mut FxHashSet<(ItemInNs, ModuleIdLt<'db>)>,
mut cb: impl FnMut(&mut FxHashSet<(ItemInNs, ModuleIdLt<'db>)>, &Name, ModuleIdLt<'db>),
visited_modules: &mut FxHashSet<(ItemInNs, ModuleId)>,
mut cb: impl FnMut(&mut FxHashSet<(ItemInNs, ModuleId)>, &Name, ModuleId),
) {
let _p = tracing::info_span!("find_local_import_locations").entered();
let db = ctx.db;
Expand Down
6 changes: 3 additions & 3 deletions crates/hir-def/src/import_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ mod tests {
use expect_test::{Expect, expect};
use test_fixture::WithFixture;

use crate::{ItemContainerId, Lookup, ModuleIdLt, nameres::assoc::TraitItems, test_db::TestDB};
use crate::{ItemContainerId, Lookup, nameres::assoc::TraitItems, test_db::TestDB};

use super::*;

Expand Down Expand Up @@ -628,8 +628,8 @@ mod tests {
expect.assert_eq(&actual)
}

fn render_path<'db>(db: &'db dyn DefDatabase, info: &ImportInfo) -> String {
let mut module: ModuleIdLt<'db> = info.container;
fn render_path(db: &dyn DefDatabase, info: &ImportInfo) -> String {
let mut module = info.container;
let mut segments = vec![&info.name];

let def_map = module.def_map(db);
Expand Down
8 changes: 4 additions & 4 deletions crates/hir-def/src/item_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ use syntax::{SyntaxKind, ast, match_ast};
use thin_vec::ThinVec;
use triomphe::Arc;

use crate::{BlockId, db::DefDatabase};
use crate::{BlockId, Lookup, db::DefDatabase};

pub(crate) use crate::item_tree::{
attrs::*,
Expand Down Expand Up @@ -150,10 +150,10 @@ pub(crate) fn block_item_tree_query(db: &dyn DefDatabase, block: BlockId) -> Arc
let _p = tracing::info_span!("block_item_tree_query", ?block).entered();
static EMPTY: OnceLock<Arc<ItemTree>> = OnceLock::new();

let ast_id = block.ast_id(db);
let block = ast_id.to_node(db);
let loc = block.lookup(db);
let block = loc.ast_id.to_node(db);

let ctx = lower::Ctx::new(db, ast_id.file_id);
let ctx = lower::Ctx::new(db, loc.ast_id.file_id);
let mut item_tree = ctx.lower_block(&block);
let ItemTree { top_level, top_attrs, attrs, vis, big_data, small_data } = &item_tree;
if small_data.is_empty()
Expand Down
Loading