Skip to content

Commit 313e691

Browse files
Auto merge of #142702 - compiler-errors:remono, r=<try>
[perf] Re-monomorphize `FnMutDelegate` I'm curious if perf has changed since #101857, since I see `FnMutDelegate` a lot in perf traces in the new solver. As noted in #99730 (comment), I'll pay attention to the bootstrap times too.
2 parents d1d8e38 + d2a2554 commit 313e691

File tree

3 files changed

+26
-21
lines changed

3 files changed

+26
-21
lines changed

compiler/rustc_borrowck/src/type_check/relate_tys.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ impl<'a, 'b, 'tcx> NllTypeRelating<'a, 'b, 'tcx> {
167167
let infcx = self.type_checker.infcx;
168168
let mut lazy_universe = None;
169169
let delegate = FnMutDelegate {
170-
regions: &mut |br: ty::BoundRegion| {
170+
regions: |br: ty::BoundRegion| {
171171
// The first time this closure is called, create a
172172
// new universe for the placeholders we will make
173173
// from here out.
@@ -184,10 +184,10 @@ impl<'a, 'b, 'tcx> NllTypeRelating<'a, 'b, 'tcx> {
184184

185185
placeholder_reg
186186
},
187-
types: &mut |_bound_ty: ty::BoundTy| {
187+
types: |_bound_ty: ty::BoundTy| {
188188
unreachable!("we only replace regions in nll_relate, not types")
189189
},
190-
consts: &mut |_bound_var: ty::BoundVar| {
190+
consts: |_bound_var: ty::BoundVar| {
191191
unreachable!("we only replace regions in nll_relate, not consts")
192192
},
193193
};
@@ -211,7 +211,7 @@ impl<'a, 'b, 'tcx> NllTypeRelating<'a, 'b, 'tcx> {
211211
let infcx = self.type_checker.infcx;
212212
let mut reg_map = FxHashMap::default();
213213
let delegate = FnMutDelegate {
214-
regions: &mut |br: ty::BoundRegion| {
214+
regions: |br: ty::BoundRegion| {
215215
if let Some(ex_reg_var) = reg_map.get(&br) {
216216
*ex_reg_var
217217
} else {
@@ -222,10 +222,10 @@ impl<'a, 'b, 'tcx> NllTypeRelating<'a, 'b, 'tcx> {
222222
ex_reg_var
223223
}
224224
},
225-
types: &mut |_bound_ty: ty::BoundTy| {
225+
types: |_bound_ty: ty::BoundTy| {
226226
unreachable!("we only replace regions in nll_relate, not types")
227227
},
228-
consts: &mut |_bound_var: ty::BoundVar| {
228+
consts: |_bound_var: ty::BoundVar| {
229229
unreachable!("we only replace regions in nll_relate, not consts")
230230
},
231231
};

compiler/rustc_infer/src/infer/relate/higher_ranked.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,19 +33,19 @@ impl<'tcx> InferCtxt<'tcx> {
3333
let next_universe = self.create_next_universe();
3434

3535
let delegate = FnMutDelegate {
36-
regions: &mut |br: ty::BoundRegion| {
36+
regions: |br: ty::BoundRegion| {
3737
ty::Region::new_placeholder(
3838
self.tcx,
3939
ty::PlaceholderRegion { universe: next_universe, bound: br },
4040
)
4141
},
42-
types: &mut |bound_ty: ty::BoundTy| {
42+
types: |bound_ty: ty::BoundTy| {
4343
Ty::new_placeholder(
4444
self.tcx,
4545
ty::PlaceholderType { universe: next_universe, bound: bound_ty },
4646
)
4747
},
48-
consts: &mut |bound_var: ty::BoundVar| {
48+
consts: |bound_var: ty::BoundVar| {
4949
ty::Const::new_placeholder(
5050
self.tcx,
5151
ty::PlaceholderConst { universe: next_universe, bound: bound_var },

compiler/rustc_middle/src/ty/fold.rs

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,18 @@ pub trait BoundVarReplacerDelegate<'tcx> {
6666
/// A simple delegate taking 3 mutable functions. The used functions must
6767
/// always return the same result for each bound variable, no matter how
6868
/// frequently they are called.
69-
pub struct FnMutDelegate<'a, 'tcx> {
70-
pub regions: &'a mut (dyn FnMut(ty::BoundRegion) -> ty::Region<'tcx> + 'a),
71-
pub types: &'a mut (dyn FnMut(ty::BoundTy) -> Ty<'tcx> + 'a),
72-
pub consts: &'a mut (dyn FnMut(ty::BoundVar) -> ty::Const<'tcx> + 'a),
69+
pub struct FnMutDelegate<R, T, C> {
70+
pub regions: R,
71+
pub types: T,
72+
pub consts: C,
7373
}
7474

75-
impl<'a, 'tcx> BoundVarReplacerDelegate<'tcx> for FnMutDelegate<'a, 'tcx> {
75+
impl<'tcx, R, T, C> BoundVarReplacerDelegate<'tcx> for FnMutDelegate<R, T, C>
76+
where
77+
R: FnMut(ty::BoundRegion) -> ty::Region<'tcx>,
78+
T: FnMut(ty::BoundTy) -> Ty<'tcx>,
79+
C: FnMut(ty::BoundVar) -> ty::Const<'tcx>,
80+
{
7681
fn replace_region(&mut self, br: ty::BoundRegion) -> ty::Region<'tcx> {
7782
(self.regions)(br)
7883
}
@@ -215,7 +220,7 @@ impl<'tcx> TyCtxt<'tcx> {
215220
pub fn instantiate_bound_regions_uncached<T, F>(
216221
self,
217222
value: Binder<'tcx, T>,
218-
mut replace_regions: F,
223+
replace_regions: F,
219224
) -> T
220225
where
221226
F: FnMut(ty::BoundRegion) -> ty::Region<'tcx>,
@@ -226,9 +231,9 @@ impl<'tcx> TyCtxt<'tcx> {
226231
value
227232
} else {
228233
let delegate = FnMutDelegate {
229-
regions: &mut replace_regions,
230-
types: &mut |b| bug!("unexpected bound ty in binder: {b:?}"),
231-
consts: &mut |b| bug!("unexpected bound ct in binder: {b:?}"),
234+
regions: replace_regions,
235+
types: |b| bug!("unexpected bound ty in binder: {b:?}"),
236+
consts: |b| bug!("unexpected bound ct in binder: {b:?}"),
232237
};
233238
let mut replacer = BoundVarReplacer::new(self, delegate);
234239
value.fold_with(&mut replacer)
@@ -286,21 +291,21 @@ impl<'tcx> TyCtxt<'tcx> {
286291
self.replace_escaping_bound_vars_uncached(
287292
value,
288293
FnMutDelegate {
289-
regions: &mut |r: ty::BoundRegion| {
294+
regions: |r: ty::BoundRegion| {
290295
ty::Region::new_bound(
291296
self,
292297
ty::INNERMOST,
293298
ty::BoundRegion { var: shift_bv(r.var), kind: r.kind },
294299
)
295300
},
296-
types: &mut |t: ty::BoundTy| {
301+
types: |t: ty::BoundTy| {
297302
Ty::new_bound(
298303
self,
299304
ty::INNERMOST,
300305
ty::BoundTy { var: shift_bv(t.var), kind: t.kind },
301306
)
302307
},
303-
consts: &mut |c| ty::Const::new_bound(self, ty::INNERMOST, shift_bv(c)),
308+
consts: |c| ty::Const::new_bound(self, ty::INNERMOST, shift_bv(c)),
304309
},
305310
)
306311
}

0 commit comments

Comments
 (0)