Auto merge of #15070 - Veykril:analysis-stat-stuff, r=Veykril

internal: Report metric timings for file item trees and crate def map creation
This commit is contained in:
bors 2023-06-21 05:58:13 +00:00
commit bc26e81cd5
7 changed files with 67 additions and 16 deletions

View file

@ -1,12 +1,13 @@
//! Provides set of implementation for hir's objects that allows get back location in file.
use base_db::FileId;
use either::Either;
use hir_def::{
nameres::{ModuleOrigin, ModuleSource},
src::{HasChildSource, HasSource as _},
Lookup, MacroId, VariantId,
};
use hir_expand::InFile;
use hir_expand::{HirFileId, InFile};
use syntax::ast;
use crate::{
@ -32,6 +33,11 @@ impl Module {
def_map[self.id.local_id].definition_source(db.upcast())
}
pub fn definition_source_file_id(self, db: &dyn HirDatabase) -> HirFileId {
let def_map = self.id.def_map(db.upcast());
def_map[self.id.local_id].definition_source_file_id()
}
pub fn is_mod_rs(self, db: &dyn HirDatabase) -> bool {
let def_map = self.id.def_map(db.upcast());
match def_map[self.id.local_id].origin {
@ -40,6 +46,16 @@ impl Module {
}
}
pub fn as_source_file_id(self, db: &dyn HirDatabase) -> Option<FileId> {
let def_map = self.id.def_map(db.upcast());
match def_map[self.id.local_id].origin {
ModuleOrigin::File { definition, .. } | ModuleOrigin::CrateRoot { definition, .. } => {
Some(definition)
}
_ => None,
}
}
pub fn is_inline(self, db: &dyn HirDatabase) -> bool {
let def_map = self.id.def_map(db.upcast());
def_map[self.id.local_id].origin.is_inline()