Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[perf experiment] Split the resolver tables into per-owner tables #138995

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from
Draft
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
2 changes: 1 addition & 1 deletion compiler/rustc_ast_lowering/src/asm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use super::errors::{
};
use crate::{
AllowReturnTypeNotation, ImplTraitContext, ImplTraitPosition, ParamMode,
ResolverAstLoweringExt, fluent_generated as fluent,
fluent_generated as fluent,
};

impl<'a, 'hir> LoweringContext<'a, 'hir> {
Expand Down
23 changes: 12 additions & 11 deletions compiler/rustc_ast_lowering/src/delegation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@ use rustc_ast::*;
use rustc_errors::ErrorGuaranteed;
use rustc_hir::def_id::DefId;
use rustc_middle::span_bug;
use rustc_middle::ty::{Asyncness, ResolverAstLowering};
use rustc_middle::ty::Asyncness;
use rustc_span::{Ident, Span};
use {rustc_ast as ast, rustc_hir as hir};

use super::{GenericArgsMode, ImplTraitContext, LoweringContext, ParamMode};
use crate::{AllowReturnTypeNotation, ImplTraitPosition, ResolverAstLoweringExt};
use crate::{AllowReturnTypeNotation, ImplTraitPosition, PerOwnerResolver};

pub(crate) struct DelegationResults<'hir> {
pub body_id: hir::BodyId,
Expand Down Expand Up @@ -82,6 +82,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
DefKind::AssocFn => match def_id.as_local() {
Some(local_def_id) => self
.resolver
.general
.delegation_fn_sigs
.get(&local_def_id)
.is_some_and(|sig| sig.has_self),
Expand Down Expand Up @@ -150,7 +151,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
if let Some(local_sig_id) = sig_id.as_local() {
// Map may be filled incorrectly due to recursive delegation.
// Error will be emitted later during HIR ty lowering.
match self.resolver.delegation_fn_sigs.get(&local_sig_id) {
match self.resolver.general.delegation_fn_sigs.get(&local_sig_id) {
Some(sig) => (sig.param_count, sig.c_variadic),
None => (0, false),
}
Expand Down Expand Up @@ -198,7 +199,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
span: Span,
) -> hir::FnSig<'hir> {
let header = if let Some(local_sig_id) = sig_id.as_local() {
match self.resolver.delegation_fn_sigs.get(&local_sig_id) {
match self.resolver.general.delegation_fn_sigs.get(&local_sig_id) {
Some(sig) => {
let parent = self.tcx.parent(sig_id);
// HACK: we override the default safety instead of generating attributes from the ether.
Expand Down Expand Up @@ -280,7 +281,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
&& idx == 0
{
let mut self_resolver = SelfResolver {
resolver: this.resolver,
resolver: &mut this.resolver,
path_id: delegation.id,
self_param_id: pat_node_id,
};
Expand Down Expand Up @@ -426,25 +427,25 @@ impl<'hir> LoweringContext<'_, 'hir> {
}
}

struct SelfResolver<'a> {
resolver: &'a mut ResolverAstLowering,
struct SelfResolver<'a, 'b> {
resolver: &'b mut PerOwnerResolver<'a>,
path_id: NodeId,
self_param_id: NodeId,
}

impl<'a> SelfResolver<'a> {
impl SelfResolver<'_, '_> {
fn try_replace_id(&mut self, id: NodeId) {
if let Some(res) = self.resolver.partial_res_map.get(&id)
if let Some(res) = self.resolver.general.partial_res_map.get(&id)
&& let Some(Res::Local(sig_id)) = res.full_res()
&& sig_id == self.path_id
{
let new_res = PartialRes::new(Res::Local(self.self_param_id));
self.resolver.partial_res_map.insert(id, new_res);
self.resolver.general.partial_res_map.insert(id, new_res);
}
}
}

impl<'ast, 'a> Visitor<'ast> for SelfResolver<'a> {
impl<'ast> Visitor<'ast> for SelfResolver<'_, '_> {
fn visit_path(&mut self, path: &'ast Path, id: NodeId) {
self.try_replace_id(id);
visit::walk_path(self, path);
Expand Down
7 changes: 2 additions & 5 deletions compiler/rustc_ast_lowering/src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@ use super::errors::{
InclusiveRangeWithNoEnd, MatchArmWithNoBody, NeverPatternWithBody, NeverPatternWithGuard,
UnderscoreExprLhsAssign,
};
use super::{
GenericArgsMode, ImplTraitContext, LoweringContext, ParamMode, ResolverAstLoweringExt,
};
use super::{GenericArgsMode, ImplTraitContext, LoweringContext, ParamMode};
use crate::errors::{InvalidLegacyConstGenericArg, UseConstGenericArg, YieldInClosure};
use crate::{AllowReturnTypeNotation, FnDeclKind, ImplTraitPosition, fluent_generated};

Expand Down Expand Up @@ -488,9 +486,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
let mut generic_args = ThinVec::new();
for (idx, arg) in args.iter().cloned().enumerate() {
if legacy_args_idx.contains(&idx) {
let parent_def_id = self.current_hir_id_owner.def_id;
let node_id = self.next_node_id();
self.create_def(parent_def_id, node_id, None, DefKind::AnonConst, f.span);
self.create_def(node_id, None, DefKind::AnonConst, f.span);
let mut visitor = WillCreateDefIdsVisitor {};
let const_value = if let ControlFlow::Break(span) = visitor.visit_expr(&arg) {
AstP(Expr {
Expand Down
7 changes: 5 additions & 2 deletions compiler/rustc_ast_lowering/src/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ use super::errors::{
use super::stability::{enabled_names, gate_unstable_abi};
use super::{
AstOwner, FnDeclKind, ImplTraitContext, ImplTraitPosition, LoweringContext, ParamMode,
ResolverAstLoweringExt,
};

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

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

#[instrument(level = "debug", skip(self))]
fn lower_assoc_item(&mut self, item: &AssocItem, ctxt: AssocCtxt) {
self.with_lctx(item.id, |lctx| lctx.lower_assoc_item(item, ctxt))
}
Expand Down
Loading