Skip to content

Commit a6b131d

Browse files
committed
Auto merge of #142830 - cjgillot:lower-incr-2, r=<try>
Make lowering incremental, take 3/N Rebase of #88186 that was rebased by #127262 No real change in design, so I'm not expecting a perf miracle. r? `@ghost`
2 parents 6d0c9e2 + 0e2f90b commit a6b131d

File tree

27 files changed

+352
-327
lines changed

27 files changed

+352
-327
lines changed

compiler/rustc_ast/src/ast.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4033,6 +4033,17 @@ impl TryFrom<ItemKind> for ForeignItemKind {
40334033

40344034
pub type ForeignItem = Item<ForeignItemKind>;
40354035

4036+
#[derive(Debug)]
4037+
pub enum AstOwner<'a> {
4038+
NonOwner,
4039+
Synthetic(rustc_span::def_id::LocalDefId),
4040+
Crate(&'a Crate),
4041+
Item(&'a Item),
4042+
TraitItem(&'a AssocItem),
4043+
ImplItem(&'a AssocItem),
4044+
ForeignItem(&'a ForeignItem),
4045+
}
4046+
40364047
// Some nodes are used a lot. Make sure they don't unintentionally get bigger.
40374048
#[cfg(target_pointer_width = "64")]
40384049
mod size_asserts {

compiler/rustc_ast_lowering/src/asm.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ 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

26-
impl<'a, 'hir> LoweringContext<'a, 'hir> {
26+
impl<'hir> LoweringContext<'hir> {
2727
pub(crate) fn lower_inline_asm(
2828
&mut self,
2929
sp: Span,
@@ -200,7 +200,6 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
200200
},
201201
InlineAsmOperand::Sym { sym } => {
202202
let static_def_id = self
203-
.resolver
204203
.get_partial_res(sym.id)
205204
.and_then(|res| res.full_res())
206205
.and_then(|res| match res {

compiler/rustc_ast_lowering/src/block.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use smallvec::SmallVec;
55

66
use crate::{ImplTraitContext, ImplTraitPosition, LoweringContext};
77

8-
impl<'a, 'hir> LoweringContext<'a, 'hir> {
8+
impl<'hir> LoweringContext<'hir> {
99
pub(super) fn lower_block(
1010
&mut self,
1111
b: &Block,

compiler/rustc_ast_lowering/src/delegation.rs

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,14 @@ 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

53-
use super::{GenericArgsMode, ImplTraitContext, LoweringContext, ParamMode};
54-
use crate::{AllowReturnTypeNotation, ImplTraitPosition, ResolverAstLoweringExt};
53+
use super::{
54+
AllowReturnTypeNotation, GenericArgsMode, ImplTraitContext, ImplTraitPosition, LoweringContext,
55+
ParamMode,
56+
};
5557

5658
pub(crate) struct DelegationResults<'hir> {
5759
pub body_id: hir::BodyId,
@@ -60,7 +62,7 @@ pub(crate) struct DelegationResults<'hir> {
6062
pub generics: &'hir hir::Generics<'hir>,
6163
}
6264

63-
impl<'hir> LoweringContext<'_, 'hir> {
65+
impl<'hir> LoweringContext<'hir> {
6466
/// Defines whether the delegatee is an associated function whose first parameter is `self`.
6567
pub(crate) fn delegatee_is_method(
6668
&self,
@@ -125,8 +127,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
125127
}
126128

127129
fn get_resolution_id(&self, node_id: NodeId, span: Span) -> Result<DefId, ErrorGuaranteed> {
128-
let def_id =
129-
self.resolver.get_partial_res(node_id).and_then(|r| r.expect_full_res().opt_def_id());
130+
let def_id = self.get_partial_res(node_id).and_then(|r| r.expect_full_res().opt_def_id());
130131
def_id.ok_or_else(|| {
131132
self.tcx.dcx().span_delayed_bug(
132133
span,
@@ -281,7 +282,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
281282
&& idx == 0
282283
{
283284
let mut self_resolver = SelfResolver {
284-
resolver: this.resolver,
285+
ctxt: this,
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<'r, 'hir> {
432+
ctxt: &'r mut LoweringContext<'hir>,
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.ctxt.get_partial_res(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.ctxt.partial_res_overrides.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_id(&mut self, id: NodeId) {
450451
self.try_replace_id(id);
451452
}

compiler/rustc_ast_lowering/src/expr.rs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use rustc_data_structures::stack::ensure_sufficient_stack;
88
use rustc_hir as hir;
99
use rustc_hir::HirId;
1010
use rustc_hir::def::{DefKind, Res};
11+
use rustc_hir::definitions::DefPathData;
1112
use rustc_middle::span_bug;
1213
use rustc_middle::ty::TyCtxt;
1314
use rustc_session::errors::report_lit_error;
@@ -51,7 +52,7 @@ impl<'v> rustc_ast::visit::Visitor<'v> for WillCreateDefIdsVisitor {
5152
}
5253
}
5354

54-
impl<'hir> LoweringContext<'_, 'hir> {
55+
impl<'hir> LoweringContext<'hir> {
5556
fn lower_exprs(&mut self, exprs: &[AstP<Expr>]) -> &'hir [hir::Expr<'hir>] {
5657
self.arena.alloc_from_iter(exprs.iter().map(|x| self.lower_expr_mut(x)))
5758
}
@@ -491,7 +492,13 @@ impl<'hir> LoweringContext<'_, 'hir> {
491492
for (idx, arg) in args.iter().cloned().enumerate() {
492493
if legacy_args_idx.contains(&idx) {
493494
let node_id = self.next_node_id();
494-
self.create_def(node_id, None, DefKind::AnonConst, f.span);
495+
self.create_def(
496+
node_id,
497+
None,
498+
DefKind::AnonConst,
499+
DefPathData::LateAnonConst,
500+
f.span,
501+
);
495502
let mut visitor = WillCreateDefIdsVisitor {};
496503
let const_value = if let ControlFlow::Break(span) = visitor.visit_expr(&arg) {
497504
AstP(Expr {
@@ -1263,7 +1270,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
12631270
whole_span: Span,
12641271
) -> hir::ExprKind<'hir> {
12651272
// Return early in case of an ordinary assignment.
1266-
fn is_ordinary(lower_ctx: &mut LoweringContext<'_, '_>, lhs: &Expr) -> bool {
1273+
fn is_ordinary(lower_ctx: &mut LoweringContext<'_>, lhs: &Expr) -> bool {
12671274
match &lhs.kind {
12681275
ExprKind::Array(..)
12691276
| ExprKind::Struct(..)
@@ -1323,7 +1330,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
13231330
) -> Option<(&'a Option<AstP<QSelf>>, &'a Path)> {
13241331
if let ExprKind::Path(qself, path) = &expr.kind {
13251332
// Does the path resolve to something disallowed in a tuple struct/variant pattern?
1326-
if let Some(partial_res) = self.resolver.get_partial_res(expr.id) {
1333+
if let Some(partial_res) = self.get_partial_res(expr.id) {
13271334
if let Some(res) = partial_res.full_res()
13281335
&& !res.expected_in_tuple_struct_pat()
13291336
{
@@ -1345,7 +1352,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
13451352
) -> Option<(&'a Option<AstP<QSelf>>, &'a Path)> {
13461353
if let ExprKind::Path(qself, path) = &expr.kind {
13471354
// Does the path resolve to something disallowed in a unit struct/variant pattern?
1348-
if let Some(partial_res) = self.resolver.get_partial_res(expr.id) {
1355+
if let Some(partial_res) = self.get_partial_res(expr.id) {
13491356
if let Some(res) = partial_res.full_res()
13501357
&& !res.expected_in_unit_struct_pat()
13511358
{

compiler/rustc_ast_lowering/src/format.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use rustc_span::{Ident, Span, Symbol, sym};
88

99
use super::LoweringContext;
1010

11-
impl<'hir> LoweringContext<'_, 'hir> {
11+
impl<'hir> LoweringContext<'hir> {
1212
pub(crate) fn lower_format_args(&mut self, sp: Span, fmt: &FormatArgs) -> hir::ExprKind<'hir> {
1313
// Never call the const constructor of `fmt::Arguments` if the
1414
// format_args!() had any arguments _before_ flattening/inlining.
@@ -229,7 +229,7 @@ enum ArgumentType {
229229
/// <core::fmt::Argument>::new_…(arg)
230230
/// ```
231231
fn make_argument<'hir>(
232-
ctx: &mut LoweringContext<'_, 'hir>,
232+
ctx: &mut LoweringContext<'hir>,
233233
sp: Span,
234234
arg: &'hir hir::Expr<'hir>,
235235
ty: ArgumentType,
@@ -278,7 +278,7 @@ fn make_argument<'hir>(
278278
/// <core::fmt::rt::Count>::Implied
279279
/// ```
280280
fn make_count<'hir>(
281-
ctx: &mut LoweringContext<'_, 'hir>,
281+
ctx: &mut LoweringContext<'hir>,
282282
sp: Span,
283283
count: &Option<FormatCount>,
284284
argmap: &mut FxIndexMap<(usize, ArgumentType), Option<Span>>,
@@ -329,7 +329,7 @@ fn make_count<'hir>(
329329
/// }
330330
/// ```
331331
fn make_format_spec<'hir>(
332-
ctx: &mut LoweringContext<'_, 'hir>,
332+
ctx: &mut LoweringContext<'hir>,
333333
sp: Span,
334334
placeholder: &FormatPlaceholder,
335335
argmap: &mut FxIndexMap<(usize, ArgumentType), Option<Span>>,
@@ -390,7 +390,7 @@ fn make_format_spec<'hir>(
390390
}
391391

392392
fn expand_format_args<'hir>(
393-
ctx: &mut LoweringContext<'_, 'hir>,
393+
ctx: &mut LoweringContext<'hir>,
394394
macsp: Span,
395395
fmt: &FormatArgs,
396396
allow_const: bool,

0 commit comments

Comments
 (0)