Skip to content

Commit 8ce5a53

Browse files
committed
Auto merge of rust-lang#14302 - Veykril:db-memory-usage, r=Veykril
internal: Add missing queries to per_query_memory_usage
2 parents 10a652a + c49f753 commit 8ce5a53

File tree

5 files changed

+59
-68
lines changed

5 files changed

+59
-68
lines changed

crates/hir-def/src/body.rs

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,6 @@ pub struct Body {
271271
pub exprs: Arena<Expr>,
272272
pub pats: Arena<Pat>,
273273
pub bindings: Arena<Binding>,
274-
pub or_pats: FxHashMap<PatId, Arc<[PatId]>>,
275274
pub labels: Arena<Label>,
276275
/// The patterns for the function's parameters. While the parameter types are
277276
/// part of the function signature, the patterns are not (they don't change
@@ -410,18 +409,6 @@ impl Body {
410409
.map(move |&block| (block, db.block_def_map(block).expect("block ID without DefMap")))
411410
}
412411

413-
pub fn pattern_representative(&self, pat: PatId) -> PatId {
414-
self.or_pats.get(&pat).and_then(|pats| pats.first().copied()).unwrap_or(pat)
415-
}
416-
417-
/// Retrieves all ident patterns this pattern shares the ident with.
418-
pub fn ident_patterns_for<'slf>(&'slf self, pat: &'slf PatId) -> &'slf [PatId] {
419-
match self.or_pats.get(pat) {
420-
Some(pats) => pats,
421-
None => std::slice::from_ref(pat),
422-
}
423-
}
424-
425412
pub fn pretty_print(&self, db: &dyn DefDatabase, owner: DefWithBodyId) -> String {
426413
pretty::print_body_hir(db, self, owner)
427414
}
@@ -436,19 +423,9 @@ impl Body {
436423
}
437424

438425
fn shrink_to_fit(&mut self) {
439-
let Self {
440-
_c: _,
441-
body_expr: _,
442-
block_scopes,
443-
or_pats,
444-
exprs,
445-
labels,
446-
params,
447-
pats,
448-
bindings,
449-
} = self;
426+
let Self { _c: _, body_expr: _, block_scopes, exprs, labels, params, pats, bindings } =
427+
self;
450428
block_scopes.shrink_to_fit();
451-
or_pats.shrink_to_fit();
452429
exprs.shrink_to_fit();
453430
labels.shrink_to_fit();
454431
params.shrink_to_fit();
@@ -464,7 +441,6 @@ impl Default for Body {
464441
exprs: Default::default(),
465442
pats: Default::default(),
466443
bindings: Default::default(),
467-
or_pats: Default::default(),
468444
labels: Default::default(),
469445
params: Default::default(),
470446
block_scopes: Default::default(),

crates/hir-def/src/body/lower.rs

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,8 @@ pub(super) fn lower(
9494
body_expr: dummy_expr_id(),
9595
block_scopes: Vec::new(),
9696
_c: Count::new(),
97-
or_pats: Default::default(),
9897
},
9998
expander,
100-
name_to_pat_grouping: Default::default(),
101-
is_lowering_inside_or_pat: false,
10299
is_lowering_assignee_expr: false,
103100
is_lowering_generator: false,
104101
}
@@ -111,9 +108,6 @@ struct ExprCollector<'a> {
111108
ast_id_map: Arc<AstIdMap>,
112109
body: Body,
113110
source_map: BodySourceMap,
114-
// a poor-mans union-find?
115-
name_to_pat_grouping: FxHashMap<Name, Vec<PatId>>,
116-
is_lowering_inside_or_pat: bool,
117111
is_lowering_assignee_expr: bool,
118112
is_lowering_generator: bool,
119113
}
@@ -824,13 +818,7 @@ impl ExprCollector<'_> {
824818
}
825819

826820
fn collect_pat(&mut self, pat: ast::Pat) -> PatId {
827-
let pat_id = self.collect_pat_(pat, &mut BindingList::default());
828-
for (_, pats) in self.name_to_pat_grouping.drain() {
829-
let pats = Arc::<[_]>::from(pats);
830-
self.body.or_pats.extend(pats.iter().map(|&pat| (pat, pats.clone())));
831-
}
832-
self.is_lowering_inside_or_pat = false;
833-
pat_id
821+
self.collect_pat_(pat, &mut BindingList::default())
834822
}
835823

836824
fn collect_pat_opt(&mut self, pat: Option<ast::Pat>) -> PatId {
@@ -845,13 +833,13 @@ impl ExprCollector<'_> {
845833
ast::Pat::IdentPat(bp) => {
846834
let name = bp.name().map(|nr| nr.as_name()).unwrap_or_else(Name::missing);
847835

848-
let key = self.is_lowering_inside_or_pat.then(|| name.clone());
849836
let annotation =
850837
BindingAnnotation::new(bp.mut_token().is_some(), bp.ref_token().is_some());
851838
let subpat = bp.pat().map(|subpat| self.collect_pat_(subpat, binding_list));
852-
let (binding, pattern) = if annotation == BindingAnnotation::Unannotated
853-
&& subpat.is_none()
854-
{
839+
840+
let is_simple_ident_pat =
841+
annotation == BindingAnnotation::Unannotated && subpat.is_none();
842+
let (binding, pattern) = if is_simple_ident_pat {
855843
// This could also be a single-segment path pattern. To
856844
// decide that, we need to try resolving the name.
857845
let (resolved, _) = self.expander.def_map.resolve_path(
@@ -892,9 +880,6 @@ impl ExprCollector<'_> {
892880
if let Some(binding_id) = binding {
893881
self.add_definition_to_binding(binding_id, pat);
894882
}
895-
if let Some(key) = key {
896-
self.name_to_pat_grouping.entry(key).or_default().push(pat);
897-
}
898883
return pat;
899884
}
900885
ast::Pat::TupleStructPat(p) => {
@@ -914,7 +899,6 @@ impl ExprCollector<'_> {
914899
path.map(Pat::Path).unwrap_or(Pat::Missing)
915900
}
916901
ast::Pat::OrPat(p) => {
917-
self.is_lowering_inside_or_pat = true;
918902
let pats = p.pats().map(|p| self.collect_pat_(p, binding_list)).collect();
919903
Pat::Or(pats)
920904
}

crates/hir/src/db.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@
55
//! But we need this for at least LRU caching at the query level.
66
pub use hir_def::db::*;
77
pub use hir_expand::db::{
8-
AstDatabase, AstDatabaseStorage, AstIdMapQuery, HygieneFrameQuery, InternMacroCallQuery,
9-
MacroArgTextQuery, MacroDefQuery, MacroExpandQuery, ParseMacroExpansionQuery,
8+
AstDatabase, AstDatabaseStorage, AstIdMapQuery, ExpandProcMacroQuery, HygieneFrameQuery,
9+
InternMacroCallQuery, MacroArgTextQuery, MacroDefQuery, MacroExpandErrorQuery,
10+
MacroExpandQuery, ParseMacroExpansionQuery,
1011
};
1112
pub use hir_ty::db::*;
1213

crates/hir/src/lib.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2501,10 +2501,6 @@ impl GenericDef {
25012501
}
25022502

25032503
/// A single local definition.
2504-
///
2505-
/// If the definition of this is part of a "MultiLocal", that is a local that has multiple declarations due to or-patterns
2506-
/// then this only references a single one of those.
2507-
/// To retrieve the other locals you should use [`Local::associated_locals`]
25082504
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
25092505
pub struct Local {
25102506
pub(crate) parent: DefWithBodyId,

crates/ide-db/src/apply_change.rs

Lines changed: 49 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -73,68 +73,96 @@ impl RootDatabase {
7373

7474
// AstDatabase
7575
hir::db::AstIdMapQuery
76+
hir::db::ParseMacroExpansionQuery
77+
hir::db::InternMacroCallQuery
7678
hir::db::MacroArgTextQuery
7779
hir::db::MacroDefQuery
78-
hir::db::ParseMacroExpansionQuery
7980
hir::db::MacroExpandQuery
81+
hir::db::ExpandProcMacroQuery
82+
hir::db::MacroExpandErrorQuery
8083
hir::db::HygieneFrameQuery
81-
hir::db::InternMacroCallQuery
8284

8385
// DefDatabase
8486
hir::db::FileItemTreeQuery
85-
hir::db::BlockDefMapQuery
8687
hir::db::CrateDefMapQueryQuery
87-
hir::db::FieldsAttrsQuery
88-
hir::db::VariantsAttrsQuery
89-
hir::db::FieldsAttrsSourceMapQuery
90-
hir::db::VariantsAttrsSourceMapQuery
88+
hir::db::BlockDefMapQuery
9189
hir::db::StructDataQuery
90+
hir::db::StructDataWithDiagnosticsQuery
9291
hir::db::UnionDataQuery
92+
hir::db::UnionDataWithDiagnosticsQuery
9393
hir::db::EnumDataQuery
94+
hir::db::EnumDataWithDiagnosticsQuery
9495
hir::db::ImplDataQuery
96+
hir::db::ImplDataWithDiagnosticsQuery
9597
hir::db::TraitDataQuery
98+
hir::db::TraitDataWithDiagnosticsQuery
99+
hir::db::TraitAliasDataQuery
96100
hir::db::TypeAliasDataQuery
97101
hir::db::FunctionDataQuery
98102
hir::db::ConstDataQuery
99103
hir::db::StaticDataQuery
104+
hir::db::Macro2DataQuery
105+
hir::db::MacroRulesDataQuery
106+
hir::db::ProcMacroDataQuery
100107
hir::db::BodyWithSourceMapQuery
101108
hir::db::BodyQuery
102109
hir::db::ExprScopesQuery
103110
hir::db::GenericParamsQuery
111+
hir::db::VariantsAttrsQuery
112+
hir::db::FieldsAttrsQuery
113+
hir::db::VariantsAttrsSourceMapQuery
114+
hir::db::FieldsAttrsSourceMapQuery
104115
hir::db::AttrsQuery
105116
hir::db::CrateLangItemsQuery
106117
hir::db::LangItemQuery
107118
hir::db::ImportMapQuery
119+
hir::db::FieldVisibilitiesQuery
120+
hir::db::FunctionVisibilityQuery
121+
hir::db::ConstVisibilityQuery
122+
hir::db::CrateSupportsNoStdQuery
108123

109124
// HirDatabase
110125
hir::db::InferQueryQuery
126+
hir::db::MirBodyQuery
127+
hir::db::BorrowckQuery
111128
hir::db::TyQuery
112129
hir::db::ValueTyQuery
113130
hir::db::ImplSelfTyQuery
131+
hir::db::ConstParamTyQuery
132+
hir::db::ConstEvalQuery
133+
hir::db::ConstEvalDiscriminantQuery
114134
hir::db::ImplTraitQuery
115135
hir::db::FieldTypesQuery
136+
hir::db::LayoutOfAdtQuery
137+
hir::db::TargetDataLayoutQuery
116138
hir::db::CallableItemSignatureQuery
139+
hir::db::ReturnTypeImplTraitsQuery
117140
hir::db::GenericPredicatesForParamQuery
118141
hir::db::GenericPredicatesQuery
142+
hir::db::TraitEnvironmentQuery
119143
hir::db::GenericDefaultsQuery
120144
hir::db::InherentImplsInCrateQuery
121-
hir::db::TraitEnvironmentQuery
145+
hir::db::InherentImplsInBlockQuery
146+
hir::db::IncoherentInherentImplCratesQuery
122147
hir::db::TraitImplsInCrateQuery
148+
hir::db::TraitImplsInBlockQuery
123149
hir::db::TraitImplsInDepsQuery
124-
hir::db::AssociatedTyDataQuery
150+
hir::db::InternCallableDefQuery
151+
hir::db::InternLifetimeParamIdQuery
152+
hir::db::InternImplTraitIdQuery
153+
hir::db::InternTypeOrConstParamIdQuery
154+
hir::db::InternClosureQuery
155+
hir::db::InternGeneratorQuery
125156
hir::db::AssociatedTyDataQuery
126157
hir::db::TraitDatumQuery
127158
hir::db::StructDatumQuery
128159
hir::db::ImplDatumQuery
129160
hir::db::FnDefDatumQuery
130-
hir::db::ReturnTypeImplTraitsQuery
131-
hir::db::InternCallableDefQuery
132-
hir::db::InternTypeOrConstParamIdQuery
133-
hir::db::InternImplTraitIdQuery
134-
hir::db::InternClosureQuery
161+
hir::db::FnDefVarianceQuery
162+
hir::db::AdtVarianceQuery
135163
hir::db::AssociatedTyValueQuery
136164
hir::db::TraitSolveQueryQuery
137-
hir::db::InternTypeOrConstParamIdQuery
165+
hir::db::ProgramClausesForChalkEnvQuery
138166

139167
// SymbolsDatabase
140168
crate::symbol_index::ModuleSymbolsQuery
@@ -153,8 +181,14 @@ impl RootDatabase {
153181
hir::db::InternConstQuery
154182
hir::db::InternStaticQuery
155183
hir::db::InternTraitQuery
184+
hir::db::InternTraitAliasQuery
156185
hir::db::InternTypeAliasQuery
157186
hir::db::InternImplQuery
187+
hir::db::InternExternBlockQuery
188+
hir::db::InternBlockQuery
189+
hir::db::InternMacro2Query
190+
hir::db::InternProcMacroQuery
191+
hir::db::InternMacroRulesQuery
158192
];
159193

160194
acc.sort_by_key(|it| std::cmp::Reverse(it.1));

0 commit comments

Comments
 (0)