Skip to content

Commit 6ddfe68

Browse files
committed
Abstract resolver
1 parent c53be12 commit 6ddfe68

File tree

18 files changed

+134
-185
lines changed

18 files changed

+134
-185
lines changed

compiler/rustc_ast_lowering/src/asm.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use crate::{
2323
AllowReturnTypeNotation, ImplTraitContext, ImplTraitPosition, ParamMode, ResolverAstLoweringExt,
2424
};
2525

26-
impl<'hir> LoweringContext<'_, '_, 'hir> {
26+
impl<'hir, R: ResolverAstLoweringExt<'hir>> LoweringContext<'_, 'hir, R> {
2727
pub(crate) fn lower_inline_asm(
2828
&mut self,
2929
sp: Span,

compiler/rustc_ast_lowering/src/block.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ use rustc_hir::Target;
44
use rustc_span::sym;
55
use smallvec::SmallVec;
66

7-
use crate::{ImplTraitContext, ImplTraitPosition, LoweringContext};
7+
use crate::{ImplTraitContext, ImplTraitPosition, LoweringContext, ResolverAstLoweringExt};
88

9-
impl<'hir> LoweringContext<'_, '_, 'hir> {
9+
impl<'hir, R: ResolverAstLoweringExt<'hir>> LoweringContext<'_, 'hir, R> {
1010
pub(super) fn lower_block(
1111
&mut self,
1212
b: &Block,

compiler/rustc_ast_lowering/src/contract.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ use std::sync::Arc;
22

33
use thin_vec::thin_vec;
44

5-
use crate::LoweringContext;
5+
use crate::{LoweringContext, ResolverAstLoweringExt};
66

7-
impl<'hir> LoweringContext<'_, '_, 'hir> {
7+
impl<'hir, R: ResolverAstLoweringExt<'hir>> LoweringContext<'_, 'hir, R> {
88
/// Lowered contracts are guarded with the `contract_checks` compiler flag,
99
/// i.e. the flag turns into a boolean guard in the lowered HIR. The reason
1010
/// for not eliminating the contract code entirely when the `contract_checks`

compiler/rustc_ast_lowering/src/delegation.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ use smallvec::SmallVec;
5959
use crate::delegation::generics::{GenericsGenerationResult, GenericsGenerationResults};
6060
use crate::errors::{CycleInDelegationSignatureResolution, UnresolvedDelegationCallee};
6161
use crate::{
62-
AllowReturnTypeNotation, CombinedResolverAstLowering, GenericArgsMode, ImplTraitContext,
63-
ImplTraitPosition, LoweringContext, ParamMode, ResolverAstLoweringExt,
62+
AllowReturnTypeNotation, GenericArgsMode, ImplTraitContext, ImplTraitPosition, LoweringContext,
63+
ParamMode, ResolverAstLoweringExt,
6464
};
6565

6666
mod generics;
@@ -134,7 +134,7 @@ impl DelegationIds {
134134
}
135135
}
136136

137-
impl<'hir> LoweringContext<'_, '_, 'hir> {
137+
impl<'hir, R: ResolverAstLoweringExt<'hir>> LoweringContext<'_, 'hir, R> {
138138
fn is_method(&self, def_id: DefId, span: Span) -> bool {
139139
match self.tcx.def_kind(def_id) {
140140
DefKind::Fn => false,
@@ -814,25 +814,25 @@ impl<'hir> LoweringContext<'_, '_, 'hir> {
814814
}
815815
}
816816

817-
struct SelfResolver<'a, 'b, 'tcx> {
818-
resolver: &'a mut CombinedResolverAstLowering<'b, 'tcx>,
817+
struct SelfResolver<'a, 'tcx> {
818+
resolver: &'a mut dyn ResolverAstLoweringExt<'tcx>,
819819
path_id: NodeId,
820820
self_param_id: NodeId,
821821
}
822822

823-
impl SelfResolver<'_, '_, '_> {
823+
impl SelfResolver<'_, '_> {
824824
fn try_replace_id(&mut self, id: NodeId) {
825825
if let Some(res) = self.resolver.get_partial_res(id)
826826
&& let Some(Res::Local(sig_id)) = res.full_res()
827827
&& sig_id == self.path_id
828828
{
829829
let new_res = PartialRes::new(Res::Local(self.self_param_id));
830-
self.resolver.mut_part.partial_res_map.insert(id, new_res);
830+
self.resolver.insert_partial_res(id, new_res);
831831
}
832832
}
833833
}
834834

835-
impl<'ast, 'a> Visitor<'ast> for SelfResolver<'a, '_, '_> {
835+
impl<'ast, 'a> Visitor<'ast> for SelfResolver<'a, '_> {
836836
fn visit_id(&mut self, id: NodeId) {
837837
self.try_replace_id(id);
838838
}

compiler/rustc_ast_lowering/src/delegation/generics.rs

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,9 @@ impl<T> DelegationGenerics<T> {
5858
}
5959

6060
impl<'hir> HirOrAstGenerics<'hir> {
61-
pub(super) fn into_hir_generics(
61+
pub(super) fn into_hir_generics<R: ResolverAstLoweringExt<'hir>>(
6262
&mut self,
63-
ctx: &mut LoweringContext<'_, '_, 'hir>,
63+
ctx: &mut LoweringContext<'_, 'hir, R>,
6464
item_id: NodeId,
6565
span: Span,
6666
) -> &mut HirOrAstGenerics<'hir> {
@@ -98,9 +98,9 @@ impl<'hir> HirOrAstGenerics<'hir> {
9898
}
9999
}
100100

101-
pub(super) fn into_generic_args(
101+
pub(super) fn into_generic_args<R: ResolverAstLoweringExt<'hir>>(
102102
&self,
103-
ctx: &mut LoweringContext<'_, '_, 'hir>,
103+
ctx: &mut LoweringContext<'_, 'hir, R>,
104104
add_lifetimes: bool,
105105
span: Span,
106106
) -> Option<&'hir hir::GenericArgs<'hir>> {
@@ -136,11 +136,11 @@ impl<'a> GenericsGenerationResult<'a> {
136136
}
137137

138138
impl<'hir> GenericsGenerationResults<'hir> {
139-
pub(super) fn all_params(
139+
pub(super) fn all_params<R: ResolverAstLoweringExt<'hir>>(
140140
&mut self,
141141
item_id: NodeId,
142142
span: Span,
143-
ctx: &mut LoweringContext<'_, '_, 'hir>,
143+
ctx: &mut LoweringContext<'_, 'hir, R>,
144144
) -> impl Iterator<Item = hir::GenericParam<'hir>> {
145145
// Now we always call `into_hir_generics` both on child and parent,
146146
// however in future we would not do that, when scenarios like
@@ -178,11 +178,11 @@ impl<'hir> GenericsGenerationResults<'hir> {
178178
/// and `generate_lifetime_predicate` functions) we need to add them to delegation generics.
179179
/// Those predicates will not affect resulting predicate inheritance and folding
180180
/// in `rustc_hir_analysis`, as we inherit all predicates from delegation signature.
181-
pub(super) fn all_predicates(
181+
pub(super) fn all_predicates<R: ResolverAstLoweringExt<'hir>>(
182182
&mut self,
183183
item_id: NodeId,
184184
span: Span,
185-
ctx: &mut LoweringContext<'_, '_, 'hir>,
185+
ctx: &mut LoweringContext<'_, 'hir, R>,
186186
) -> impl Iterator<Item = hir::WherePredicate<'hir>> {
187187
// Now we always call `into_hir_generics` both on child and parent,
188188
// however in future we would not do that, when scenarios like
@@ -207,7 +207,7 @@ impl<'hir> GenericsGenerationResults<'hir> {
207207
}
208208
}
209209

210-
impl<'hir> LoweringContext<'_, '_, 'hir> {
210+
impl<'hir, R: ResolverAstLoweringExt<'hir>> LoweringContext<'_, 'hir, R> {
211211
pub(super) fn lower_delegation_generics(
212212
&mut self,
213213
delegation: &Delegation,
@@ -289,22 +289,22 @@ impl<'hir> LoweringContext<'_, '_, 'hir> {
289289

290290
// Note that we use self.disambiguator here, if we will create new every time
291291
// we will get ICE if params have the same name.
292-
self.resolver.mut_part.node_id_to_def_id.insert(
293-
p.id,
294-
self.tcx
295-
.create_def(
296-
self.resolver.def_id(item_id).unwrap(),
297-
Some(p.ident.name),
298-
match p.kind {
299-
GenericParamKind::Lifetime => DefKind::LifetimeParam,
300-
GenericParamKind::Type { .. } => DefKind::TyParam,
301-
GenericParamKind::Const { .. } => DefKind::ConstParam,
302-
},
303-
None,
304-
&mut self.disambiguator,
305-
)
306-
.def_id(),
307-
);
292+
let def_id = self
293+
.tcx
294+
.create_def(
295+
self.resolver.def_id(item_id).unwrap(),
296+
Some(p.ident.name),
297+
match p.kind {
298+
GenericParamKind::Lifetime => DefKind::LifetimeParam,
299+
GenericParamKind::Type { .. } => DefKind::TyParam,
300+
GenericParamKind::Const { .. } => DefKind::ConstParam,
301+
},
302+
None,
303+
&mut self.disambiguator,
304+
)
305+
.def_id();
306+
307+
self.resolver.insert_new_def_id(p.id, def_id);
308308
}
309309

310310
// Fallback to default generic param lowering, we modified them in the loop above.
@@ -509,7 +509,7 @@ impl<'hir> LoweringContext<'_, '_, 'hir> {
509509

510510
let node_id = self.next_node_id();
511511

512-
self.resolver.mut_part.partial_res_map.insert(node_id, hir::def::PartialRes::new(res));
512+
self.resolver.insert_partial_res(node_id, hir::def::PartialRes::new(res));
513513

514514
GenericParamKind::Const {
515515
ty: Box::new(Ty {

compiler/rustc_ast_lowering/src/expr.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ impl<'v> rustc_ast::visit::Visitor<'v> for WillCreateDefIdsVisitor {
5353
}
5454
}
5555

56-
impl<'hir> LoweringContext<'_, '_, 'hir> {
56+
impl<'hir, R: ResolverAstLoweringExt<'hir>> LoweringContext<'_, 'hir, R> {
5757
fn lower_exprs(&mut self, exprs: &[Box<Expr>]) -> &'hir [hir::Expr<'hir>] {
5858
self.arena.alloc_from_iter(exprs.iter().map(|x| self.lower_expr_mut(x)))
5959
}
@@ -1232,7 +1232,10 @@ impl<'hir> LoweringContext<'_, '_, 'hir> {
12321232
whole_span: Span,
12331233
) -> hir::ExprKind<'hir> {
12341234
// Return early in case of an ordinary assignment.
1235-
fn is_ordinary(lower_ctx: &mut LoweringContext<'_, '_, '_>, lhs: &Expr) -> bool {
1235+
fn is_ordinary<'hir, R: ResolverAstLoweringExt<'hir>>(
1236+
lower_ctx: &mut LoweringContext<'_, 'hir, R>,
1237+
lhs: &Expr,
1238+
) -> bool {
12361239
match &lhs.kind {
12371240
ExprKind::Array(..)
12381241
| ExprKind::Struct(..)

compiler/rustc_ast_lowering/src/format.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@ use rustc_session::config::FmtDebug;
77
use rustc_span::{ByteSymbol, DesugaringKind, Ident, Span, Symbol, sym};
88

99
use super::LoweringContext;
10+
use crate::ResolverAstLoweringExt;
1011

11-
impl<'hir> LoweringContext<'_, '_, 'hir> {
12+
impl<'hir, R: ResolverAstLoweringExt<'hir>> LoweringContext<'_, 'hir, R> {
1213
pub(crate) fn lower_format_args(&mut self, sp: Span, fmt: &FormatArgs) -> hir::ExprKind<'hir> {
1314
// Never call the const constructor of `fmt::Arguments` if the
1415
// format_args!() had any arguments _before_ flattening/inlining.
@@ -229,8 +230,8 @@ enum ArgumentType {
229230
/// ```text
230231
/// <core::fmt::Argument>::new_…(arg)
231232
/// ```
232-
fn make_argument<'hir>(
233-
ctx: &mut LoweringContext<'_, '_, 'hir>,
233+
fn make_argument<'hir, R: ResolverAstLoweringExt<'hir>>(
234+
ctx: &mut LoweringContext<'_, 'hir, R>,
234235
sp: Span,
235236
arg: &'hir hir::Expr<'hir>,
236237
ty: ArgumentType,
@@ -276,8 +277,8 @@ fn make_count(
276277
}
277278
}
278279

279-
fn expand_format_args<'hir>(
280-
ctx: &mut LoweringContext<'_, '_, 'hir>,
280+
fn expand_format_args<'hir, R: ResolverAstLoweringExt<'hir>>(
281+
ctx: &mut LoweringContext<'_, 'hir, R>,
281282
macsp: Span,
282283
fmt: &FormatArgs,
283284
allow_const: bool,

compiler/rustc_ast_lowering/src/item.rs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,10 @@ use super::{
2424
AstOwner, FnDeclKind, ImplTraitContext, ImplTraitPosition, LoweringContext, ParamMode,
2525
RelaxedBoundForbiddenReason, RelaxedBoundPolicy, ResolverAstLoweringExt,
2626
};
27-
use crate::CombinedResolverAstLowering;
2827

29-
pub(super) struct ItemLowerer<'a, 'b, 'hir> {
28+
pub(super) struct ItemLowerer<'a, 'hir, R: ResolverAstLoweringExt<'hir>> {
3029
pub(super) tcx: TyCtxt<'hir>,
31-
pub(super) resolver: &'a mut CombinedResolverAstLowering<'b, 'hir>,
30+
pub(super) resolver: &'a mut R,
3231
pub(super) ast_index: &'a IndexSlice<LocalDefId, AstOwner<'a>>,
3332
pub(super) owners: &'a mut IndexVec<LocalDefId, hir::MaybeOwner<'hir>>,
3433
}
@@ -52,13 +51,13 @@ fn add_ty_alias_where_clause(
5251
if before.0 || !after.0 { before } else { after };
5352
}
5453

55-
impl<'hir> ItemLowerer<'_, '_, 'hir> {
54+
impl<'hir, R: ResolverAstLoweringExt<'hir>> ItemLowerer<'_, 'hir, R> {
5655
fn with_lctx(
5756
&mut self,
5857
owner: NodeId,
59-
f: impl FnOnce(&mut LoweringContext<'_, '_, 'hir>) -> hir::OwnerNode<'hir>,
58+
f: impl FnOnce(&mut LoweringContext<'_, 'hir, R>) -> hir::OwnerNode<'hir>,
6059
) {
61-
let mut lctx = LoweringContext::new(self.tcx, self.ast_index, &mut self.resolver);
60+
let mut lctx = LoweringContext::new(self.tcx, self.ast_index, self.resolver);
6261
lctx.with_hir_id_owner(owner, |lctx| f(lctx));
6362

6463
for (def_id, info) in lctx.children {
@@ -100,7 +99,7 @@ impl<'hir> ItemLowerer<'_, '_, 'hir> {
10099
}
101100
}
102101

103-
impl<'hir> LoweringContext<'_, '_, 'hir> {
102+
impl<'hir, R: ResolverAstLoweringExt<'hir>> LoweringContext<'_, 'hir, R> {
104103
pub(super) fn lower_mod(
105104
&mut self,
106105
items: &[Box<Item>],
@@ -1476,7 +1475,7 @@ impl<'hir> LoweringContext<'_, '_, 'hir> {
14761475
pub(crate) fn lower_coroutine_body_with_moved_arguments(
14771476
&mut self,
14781477
decl: &FnDecl,
1479-
lower_body: impl FnOnce(&mut LoweringContext<'_, '_, 'hir>) -> hir::Expr<'hir>,
1478+
lower_body: impl FnOnce(&mut LoweringContext<'_, 'hir, R>) -> hir::Expr<'hir>,
14801479
fn_decl_span: Span,
14811480
body_span: Span,
14821481
coroutine_kind: CoroutineKind,
@@ -1613,7 +1612,7 @@ impl<'hir> LoweringContext<'_, '_, 'hir> {
16131612
parameters.push(new_parameter);
16141613
}
16151614

1616-
let mkbody = |this: &mut LoweringContext<'_, '_, 'hir>| {
1615+
let mkbody = |this: &mut LoweringContext<'_, 'hir, R>| {
16171616
// Create a block from the user's function body:
16181617
let user_body = lower_body(this);
16191618

0 commit comments

Comments
 (0)