Skip to content

Commit e12315f

Browse files
committed
Auto merge of #138995 - oli-obk:split-resolver, r=<try>
[perf experiment] Split the resolver tables into per-owner tables r? `@ghost` just doing some experiments to see if splitting `hir_crate` is feasible by checking if splitting the resolver's output into per-owner queries is feasible (#95004) Basically necessary for #138705 as that can't be landed perf-wise while the `hir_crate` query is still a thing
2 parents 18a029c + 009ef31 commit e12315f

File tree

20 files changed

+484
-251
lines changed

20 files changed

+484
-251
lines changed

Cargo.lock

-1
Original file line numberDiff line numberDiff line change
@@ -4409,7 +4409,6 @@ dependencies = [
44094409
"rustc_feature",
44104410
"rustc_fluent_macro",
44114411
"rustc_hir",
4412-
"rustc_index",
44134412
"rustc_macros",
44144413
"rustc_metadata",
44154414
"rustc_middle",

compiler/rustc_ast_lowering/src/asm.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use super::errors::{
2020
};
2121
use crate::{
2222
AllowReturnTypeNotation, ImplTraitContext, ImplTraitPosition, ParamMode,
23-
ResolverAstLoweringExt, fluent_generated as fluent,
23+
fluent_generated as fluent,
2424
};
2525

2626
impl<'a, 'hir> LoweringContext<'a, 'hir> {

compiler/rustc_ast_lowering/src/delegation.rs

+12-11
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,12 @@ use rustc_ast::*;
4646
use rustc_errors::ErrorGuaranteed;
4747
use rustc_hir::def_id::DefId;
4848
use rustc_middle::span_bug;
49-
use rustc_middle::ty::{Asyncness, ResolverAstLowering};
49+
use rustc_middle::ty::Asyncness;
5050
use rustc_span::{Ident, Span, Symbol};
5151
use {rustc_ast as ast, rustc_hir as hir};
5252

5353
use super::{GenericArgsMode, ImplTraitContext, LoweringContext, ParamMode};
54-
use crate::{AllowReturnTypeNotation, ImplTraitPosition, ResolverAstLoweringExt};
54+
use crate::{AllowReturnTypeNotation, ImplTraitPosition, PerOwnerResolver};
5555

5656
pub(crate) struct DelegationResults<'hir> {
5757
pub body_id: hir::BodyId,
@@ -82,6 +82,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
8282
DefKind::AssocFn => match def_id.as_local() {
8383
Some(local_def_id) => self
8484
.resolver
85+
.general
8586
.delegation_fn_sigs
8687
.get(&local_def_id)
8788
.is_some_and(|sig| sig.has_self),
@@ -150,7 +151,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
150151
if let Some(local_sig_id) = sig_id.as_local() {
151152
// Map may be filled incorrectly due to recursive delegation.
152153
// Error will be emitted later during HIR ty lowering.
153-
match self.resolver.delegation_fn_sigs.get(&local_sig_id) {
154+
match self.resolver.general.delegation_fn_sigs.get(&local_sig_id) {
154155
Some(sig) => (sig.param_count, sig.c_variadic),
155156
None => (0, false),
156157
}
@@ -198,7 +199,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
198199
span: Span,
199200
) -> hir::FnSig<'hir> {
200201
let header = if let Some(local_sig_id) = sig_id.as_local() {
201-
match self.resolver.delegation_fn_sigs.get(&local_sig_id) {
202+
match self.resolver.general.delegation_fn_sigs.get(&local_sig_id) {
202203
Some(sig) => {
203204
let parent = self.tcx.parent(sig_id);
204205
// HACK: we override the default safety instead of generating attributes from the ether.
@@ -281,7 +282,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
281282
&& idx == 0
282283
{
283284
let mut self_resolver = SelfResolver {
284-
resolver: this.resolver,
285+
resolver: &mut this.resolver,
285286
path_id: delegation.id,
286287
self_param_id: pat_node_id,
287288
};
@@ -427,25 +428,25 @@ impl<'hir> LoweringContext<'_, 'hir> {
427428
}
428429
}
429430

430-
struct SelfResolver<'a> {
431-
resolver: &'a mut ResolverAstLowering,
431+
struct SelfResolver<'a, 'b> {
432+
resolver: &'b mut PerOwnerResolver<'a>,
432433
path_id: NodeId,
433434
self_param_id: NodeId,
434435
}
435436

436-
impl<'a> SelfResolver<'a> {
437+
impl SelfResolver<'_, '_> {
437438
fn try_replace_id(&mut self, id: NodeId) {
438-
if let Some(res) = self.resolver.partial_res_map.get(&id)
439+
if let Some(res) = self.resolver.general.partial_res_map.get(&id)
439440
&& let Some(Res::Local(sig_id)) = res.full_res()
440441
&& sig_id == self.path_id
441442
{
442443
let new_res = PartialRes::new(Res::Local(self.self_param_id));
443-
self.resolver.partial_res_map.insert(id, new_res);
444+
self.resolver.general.partial_res_map.insert(id, new_res);
444445
}
445446
}
446447
}
447448

448-
impl<'ast, 'a> Visitor<'ast> for SelfResolver<'a> {
449+
impl<'ast> Visitor<'ast> for SelfResolver<'_, '_> {
449450
fn visit_path(&mut self, path: &'ast Path, id: NodeId) {
450451
self.try_replace_id(id);
451452
visit::walk_path(self, path);

compiler/rustc_ast_lowering/src/expr.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,7 @@ use super::errors::{
2323
InclusiveRangeWithNoEnd, MatchArmWithNoBody, NeverPatternWithBody, NeverPatternWithGuard,
2424
UnderscoreExprLhsAssign,
2525
};
26-
use super::{
27-
GenericArgsMode, ImplTraitContext, LoweringContext, ParamMode, ResolverAstLoweringExt,
28-
};
26+
use super::{GenericArgsMode, ImplTraitContext, LoweringContext, ParamMode};
2927
use crate::errors::{InvalidLegacyConstGenericArg, UseConstGenericArg, YieldInClosure};
3028
use crate::{AllowReturnTypeNotation, FnDeclKind, ImplTraitPosition, fluent_generated};
3129

@@ -488,9 +486,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
488486
let mut generic_args = ThinVec::new();
489487
for (idx, arg) in args.iter().cloned().enumerate() {
490488
if legacy_args_idx.contains(&idx) {
491-
let parent_def_id = self.current_hir_id_owner.def_id;
492489
let node_id = self.next_node_id();
493-
self.create_def(parent_def_id, node_id, None, DefKind::AnonConst, f.span);
490+
self.create_def(node_id, None, DefKind::AnonConst, f.span);
494491
let mut visitor = WillCreateDefIdsVisitor {};
495492
let const_value = if let ControlFlow::Break(span) = visitor.visit_expr(&arg) {
496493
AstP(Expr {

compiler/rustc_ast_lowering/src/item.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ use super::errors::{
2020
use super::stability::{enabled_names, gate_unstable_abi};
2121
use super::{
2222
AstOwner, FnDeclKind, ImplTraitContext, ImplTraitPosition, LoweringContext, ParamMode,
23-
ResolverAstLoweringExt,
2423
};
2524

2625
pub(super) struct ItemLowerer<'a, 'hir> {
@@ -88,7 +87,10 @@ impl<'a, 'hir> ItemLowerer<'a, 'hir> {
8887

8988
#[instrument(level = "debug", skip(self, c))]
9089
fn lower_crate(&mut self, c: &Crate) {
91-
debug_assert_eq!(self.resolver.node_id_to_def_id[&CRATE_NODE_ID], CRATE_DEF_ID);
90+
debug_assert_eq!(
91+
self.resolver.owners[&CRATE_NODE_ID].node_id_to_def_id[&CRATE_NODE_ID],
92+
CRATE_DEF_ID
93+
);
9294
self.with_lctx(CRATE_NODE_ID, |lctx| {
9395
let module = lctx.lower_mod(&c.items, &c.spans);
9496
// FIXME(jdonszelman): is dummy span ever a problem here?
@@ -102,6 +104,7 @@ impl<'a, 'hir> ItemLowerer<'a, 'hir> {
102104
self.with_lctx(item.id, |lctx| hir::OwnerNode::Item(lctx.lower_item(item)))
103105
}
104106

107+
#[instrument(level = "debug", skip(self))]
105108
fn lower_assoc_item(&mut self, item: &AssocItem, ctxt: AssocCtxt) {
106109
self.with_lctx(item.id, |lctx| lctx.lower_assoc_item(item, ctxt))
107110
}

0 commit comments

Comments
 (0)