Auto merge of #14302 - Veykril:db-memory-usage, r=Veykril

internal: Add missing queries to per_query_memory_usage
This commit is contained in:
bors 2023-03-09 16:02:43 +00:00
commit 8ce5a53934
5 changed files with 59 additions and 68 deletions

View file

@ -271,7 +271,6 @@ pub struct Body {
pub exprs: Arena<Expr>,
pub pats: Arena<Pat>,
pub bindings: Arena<Binding>,
pub or_pats: FxHashMap<PatId, Arc<[PatId]>>,
pub labels: Arena<Label>,
/// The patterns for the function's parameters. While the parameter types are
/// part of the function signature, the patterns are not (they don't change
@ -410,18 +409,6 @@ impl Body {
.map(move |&block| (block, db.block_def_map(block).expect("block ID without DefMap")))
}
pub fn pattern_representative(&self, pat: PatId) -> PatId {
self.or_pats.get(&pat).and_then(|pats| pats.first().copied()).unwrap_or(pat)
}
/// Retrieves all ident patterns this pattern shares the ident with.
pub fn ident_patterns_for<'slf>(&'slf self, pat: &'slf PatId) -> &'slf [PatId] {
match self.or_pats.get(pat) {
Some(pats) => pats,
None => std::slice::from_ref(pat),
}
}
pub fn pretty_print(&self, db: &dyn DefDatabase, owner: DefWithBodyId) -> String {
pretty::print_body_hir(db, self, owner)
}
@ -436,19 +423,9 @@ impl Body {
}
fn shrink_to_fit(&mut self) {
let Self {
_c: _,
body_expr: _,
block_scopes,
or_pats,
exprs,
labels,
params,
pats,
bindings,
} = self;
let Self { _c: _, body_expr: _, block_scopes, exprs, labels, params, pats, bindings } =
self;
block_scopes.shrink_to_fit();
or_pats.shrink_to_fit();
exprs.shrink_to_fit();
labels.shrink_to_fit();
params.shrink_to_fit();
@ -464,7 +441,6 @@ impl Default for Body {
exprs: Default::default(),
pats: Default::default(),
bindings: Default::default(),
or_pats: Default::default(),
labels: Default::default(),
params: Default::default(),
block_scopes: Default::default(),

View file

@ -94,11 +94,8 @@ pub(super) fn lower(
body_expr: dummy_expr_id(),
block_scopes: Vec::new(),
_c: Count::new(),
or_pats: Default::default(),
},
expander,
name_to_pat_grouping: Default::default(),
is_lowering_inside_or_pat: false,
is_lowering_assignee_expr: false,
is_lowering_generator: false,
}
@ -111,9 +108,6 @@ struct ExprCollector<'a> {
ast_id_map: Arc<AstIdMap>,
body: Body,
source_map: BodySourceMap,
// a poor-mans union-find?
name_to_pat_grouping: FxHashMap<Name, Vec<PatId>>,
is_lowering_inside_or_pat: bool,
is_lowering_assignee_expr: bool,
is_lowering_generator: bool,
}
@ -824,13 +818,7 @@ impl ExprCollector<'_> {
}
fn collect_pat(&mut self, pat: ast::Pat) -> PatId {
let pat_id = self.collect_pat_(pat, &mut BindingList::default());
for (_, pats) in self.name_to_pat_grouping.drain() {
let pats = Arc::<[_]>::from(pats);
self.body.or_pats.extend(pats.iter().map(|&pat| (pat, pats.clone())));
}
self.is_lowering_inside_or_pat = false;
pat_id
self.collect_pat_(pat, &mut BindingList::default())
}
fn collect_pat_opt(&mut self, pat: Option<ast::Pat>) -> PatId {
@ -845,13 +833,13 @@ impl ExprCollector<'_> {
ast::Pat::IdentPat(bp) => {
let name = bp.name().map(|nr| nr.as_name()).unwrap_or_else(Name::missing);
let key = self.is_lowering_inside_or_pat.then(|| name.clone());
let annotation =
BindingAnnotation::new(bp.mut_token().is_some(), bp.ref_token().is_some());
let subpat = bp.pat().map(|subpat| self.collect_pat_(subpat, binding_list));
let (binding, pattern) = if annotation == BindingAnnotation::Unannotated
&& subpat.is_none()
{
let is_simple_ident_pat =
annotation == BindingAnnotation::Unannotated && subpat.is_none();
let (binding, pattern) = if is_simple_ident_pat {
// This could also be a single-segment path pattern. To
// decide that, we need to try resolving the name.
let (resolved, _) = self.expander.def_map.resolve_path(
@ -892,9 +880,6 @@ impl ExprCollector<'_> {
if let Some(binding_id) = binding {
self.add_definition_to_binding(binding_id, pat);
}
if let Some(key) = key {
self.name_to_pat_grouping.entry(key).or_default().push(pat);
}
return pat;
}
ast::Pat::TupleStructPat(p) => {
@ -914,7 +899,6 @@ impl ExprCollector<'_> {
path.map(Pat::Path).unwrap_or(Pat::Missing)
}
ast::Pat::OrPat(p) => {
self.is_lowering_inside_or_pat = true;
let pats = p.pats().map(|p| self.collect_pat_(p, binding_list)).collect();
Pat::Or(pats)
}

View file

@ -5,8 +5,9 @@
//! But we need this for at least LRU caching at the query level.
pub use hir_def::db::*;
pub use hir_expand::db::{
AstDatabase, AstDatabaseStorage, AstIdMapQuery, HygieneFrameQuery, InternMacroCallQuery,
MacroArgTextQuery, MacroDefQuery, MacroExpandQuery, ParseMacroExpansionQuery,
AstDatabase, AstDatabaseStorage, AstIdMapQuery, ExpandProcMacroQuery, HygieneFrameQuery,
InternMacroCallQuery, MacroArgTextQuery, MacroDefQuery, MacroExpandErrorQuery,
MacroExpandQuery, ParseMacroExpansionQuery,
};
pub use hir_ty::db::*;

View file

@ -2501,10 +2501,6 @@ impl GenericDef {
}
/// A single local definition.
///
/// If the definition of this is part of a "MultiLocal", that is a local that has multiple declarations due to or-patterns
/// then this only references a single one of those.
/// To retrieve the other locals you should use [`Local::associated_locals`]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub struct Local {
pub(crate) parent: DefWithBodyId,

View file

@ -73,68 +73,96 @@ impl RootDatabase {
// AstDatabase
hir::db::AstIdMapQuery
hir::db::ParseMacroExpansionQuery
hir::db::InternMacroCallQuery
hir::db::MacroArgTextQuery
hir::db::MacroDefQuery
hir::db::ParseMacroExpansionQuery
hir::db::MacroExpandQuery
hir::db::ExpandProcMacroQuery
hir::db::MacroExpandErrorQuery
hir::db::HygieneFrameQuery
hir::db::InternMacroCallQuery
// DefDatabase
hir::db::FileItemTreeQuery
hir::db::BlockDefMapQuery
hir::db::CrateDefMapQueryQuery
hir::db::FieldsAttrsQuery
hir::db::VariantsAttrsQuery
hir::db::FieldsAttrsSourceMapQuery
hir::db::VariantsAttrsSourceMapQuery
hir::db::BlockDefMapQuery
hir::db::StructDataQuery
hir::db::StructDataWithDiagnosticsQuery
hir::db::UnionDataQuery
hir::db::UnionDataWithDiagnosticsQuery
hir::db::EnumDataQuery
hir::db::EnumDataWithDiagnosticsQuery
hir::db::ImplDataQuery
hir::db::ImplDataWithDiagnosticsQuery
hir::db::TraitDataQuery
hir::db::TraitDataWithDiagnosticsQuery
hir::db::TraitAliasDataQuery
hir::db::TypeAliasDataQuery
hir::db::FunctionDataQuery
hir::db::ConstDataQuery
hir::db::StaticDataQuery
hir::db::Macro2DataQuery
hir::db::MacroRulesDataQuery
hir::db::ProcMacroDataQuery
hir::db::BodyWithSourceMapQuery
hir::db::BodyQuery
hir::db::ExprScopesQuery
hir::db::GenericParamsQuery
hir::db::VariantsAttrsQuery
hir::db::FieldsAttrsQuery
hir::db::VariantsAttrsSourceMapQuery
hir::db::FieldsAttrsSourceMapQuery
hir::db::AttrsQuery
hir::db::CrateLangItemsQuery
hir::db::LangItemQuery
hir::db::ImportMapQuery
hir::db::FieldVisibilitiesQuery
hir::db::FunctionVisibilityQuery
hir::db::ConstVisibilityQuery
hir::db::CrateSupportsNoStdQuery
// HirDatabase
hir::db::InferQueryQuery
hir::db::MirBodyQuery
hir::db::BorrowckQuery
hir::db::TyQuery
hir::db::ValueTyQuery
hir::db::ImplSelfTyQuery
hir::db::ConstParamTyQuery
hir::db::ConstEvalQuery
hir::db::ConstEvalDiscriminantQuery
hir::db::ImplTraitQuery
hir::db::FieldTypesQuery
hir::db::LayoutOfAdtQuery
hir::db::TargetDataLayoutQuery
hir::db::CallableItemSignatureQuery
hir::db::ReturnTypeImplTraitsQuery
hir::db::GenericPredicatesForParamQuery
hir::db::GenericPredicatesQuery
hir::db::TraitEnvironmentQuery
hir::db::GenericDefaultsQuery
hir::db::InherentImplsInCrateQuery
hir::db::TraitEnvironmentQuery
hir::db::InherentImplsInBlockQuery
hir::db::IncoherentInherentImplCratesQuery
hir::db::TraitImplsInCrateQuery
hir::db::TraitImplsInBlockQuery
hir::db::TraitImplsInDepsQuery
hir::db::AssociatedTyDataQuery
hir::db::InternCallableDefQuery
hir::db::InternLifetimeParamIdQuery
hir::db::InternImplTraitIdQuery
hir::db::InternTypeOrConstParamIdQuery
hir::db::InternClosureQuery
hir::db::InternGeneratorQuery
hir::db::AssociatedTyDataQuery
hir::db::TraitDatumQuery
hir::db::StructDatumQuery
hir::db::ImplDatumQuery
hir::db::FnDefDatumQuery
hir::db::ReturnTypeImplTraitsQuery
hir::db::InternCallableDefQuery
hir::db::InternTypeOrConstParamIdQuery
hir::db::InternImplTraitIdQuery
hir::db::InternClosureQuery
hir::db::FnDefVarianceQuery
hir::db::AdtVarianceQuery
hir::db::AssociatedTyValueQuery
hir::db::TraitSolveQueryQuery
hir::db::InternTypeOrConstParamIdQuery
hir::db::ProgramClausesForChalkEnvQuery
// SymbolsDatabase
crate::symbol_index::ModuleSymbolsQuery
@ -153,8 +181,14 @@ impl RootDatabase {
hir::db::InternConstQuery
hir::db::InternStaticQuery
hir::db::InternTraitQuery
hir::db::InternTraitAliasQuery
hir::db::InternTypeAliasQuery
hir::db::InternImplQuery
hir::db::InternExternBlockQuery
hir::db::InternBlockQuery
hir::db::InternMacro2Query
hir::db::InternProcMacroQuery
hir::db::InternMacroRulesQuery
];
acc.sort_by_key(|it| std::cmp::Reverse(it.1));