Skip to content

[perf] Re-monomorphize FnMutDelegate #142702

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

Closed
wants to merge 1 commit into from
Closed
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
12 changes: 6 additions & 6 deletions compiler/rustc_borrowck/src/type_check/relate_tys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ impl<'a, 'b, 'tcx> NllTypeRelating<'a, 'b, 'tcx> {
let infcx = self.type_checker.infcx;
let mut lazy_universe = None;
let delegate = FnMutDelegate {
regions: &mut |br: ty::BoundRegion| {
regions: |br: ty::BoundRegion| {
// The first time this closure is called, create a
// new universe for the placeholders we will make
// from here out.
Expand All @@ -184,10 +184,10 @@ impl<'a, 'b, 'tcx> NllTypeRelating<'a, 'b, 'tcx> {

placeholder_reg
},
types: &mut |_bound_ty: ty::BoundTy| {
types: |_bound_ty: ty::BoundTy| {
unreachable!("we only replace regions in nll_relate, not types")
},
consts: &mut |_bound_var: ty::BoundVar| {
consts: |_bound_var: ty::BoundVar| {
unreachable!("we only replace regions in nll_relate, not consts")
},
};
Expand All @@ -211,7 +211,7 @@ impl<'a, 'b, 'tcx> NllTypeRelating<'a, 'b, 'tcx> {
let infcx = self.type_checker.infcx;
let mut reg_map = FxHashMap::default();
let delegate = FnMutDelegate {
regions: &mut |br: ty::BoundRegion| {
regions: |br: ty::BoundRegion| {
if let Some(ex_reg_var) = reg_map.get(&br) {
*ex_reg_var
} else {
Expand All @@ -222,10 +222,10 @@ impl<'a, 'b, 'tcx> NllTypeRelating<'a, 'b, 'tcx> {
ex_reg_var
}
},
types: &mut |_bound_ty: ty::BoundTy| {
types: |_bound_ty: ty::BoundTy| {
unreachable!("we only replace regions in nll_relate, not types")
},
consts: &mut |_bound_var: ty::BoundVar| {
consts: |_bound_var: ty::BoundVar| {
unreachable!("we only replace regions in nll_relate, not consts")
},
};
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_infer/src/infer/relate/higher_ranked.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,19 @@ impl<'tcx> InferCtxt<'tcx> {
let next_universe = self.create_next_universe();

let delegate = FnMutDelegate {
regions: &mut |br: ty::BoundRegion| {
regions: |br: ty::BoundRegion| {
ty::Region::new_placeholder(
self.tcx,
ty::PlaceholderRegion { universe: next_universe, bound: br },
)
},
types: &mut |bound_ty: ty::BoundTy| {
types: |bound_ty: ty::BoundTy| {
Ty::new_placeholder(
self.tcx,
ty::PlaceholderType { universe: next_universe, bound: bound_ty },
)
},
consts: &mut |bound_var: ty::BoundVar| {
consts: |bound_var: ty::BoundVar| {
ty::Const::new_placeholder(
self.tcx,
ty::PlaceholderConst { universe: next_universe, bound: bound_var },
Expand Down
29 changes: 17 additions & 12 deletions compiler/rustc_middle/src/ty/fold.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,18 @@ pub trait BoundVarReplacerDelegate<'tcx> {
/// A simple delegate taking 3 mutable functions. The used functions must
/// always return the same result for each bound variable, no matter how
/// frequently they are called.
pub struct FnMutDelegate<'a, 'tcx> {
pub regions: &'a mut (dyn FnMut(ty::BoundRegion) -> ty::Region<'tcx> + 'a),
pub types: &'a mut (dyn FnMut(ty::BoundTy) -> Ty<'tcx> + 'a),
pub consts: &'a mut (dyn FnMut(ty::BoundVar) -> ty::Const<'tcx> + 'a),
pub struct FnMutDelegate<R, T, C> {
pub regions: R,
pub types: T,
pub consts: C,
}

impl<'a, 'tcx> BoundVarReplacerDelegate<'tcx> for FnMutDelegate<'a, 'tcx> {
impl<'tcx, R, T, C> BoundVarReplacerDelegate<'tcx> for FnMutDelegate<R, T, C>
where
R: FnMut(ty::BoundRegion) -> ty::Region<'tcx>,
T: FnMut(ty::BoundTy) -> Ty<'tcx>,
C: FnMut(ty::BoundVar) -> ty::Const<'tcx>,
{
fn replace_region(&mut self, br: ty::BoundRegion) -> ty::Region<'tcx> {
(self.regions)(br)
}
Expand Down Expand Up @@ -215,7 +220,7 @@ impl<'tcx> TyCtxt<'tcx> {
pub fn instantiate_bound_regions_uncached<T, F>(
self,
value: Binder<'tcx, T>,
mut replace_regions: F,
replace_regions: F,
) -> T
where
F: FnMut(ty::BoundRegion) -> ty::Region<'tcx>,
Expand All @@ -226,9 +231,9 @@ impl<'tcx> TyCtxt<'tcx> {
value
} else {
let delegate = FnMutDelegate {
regions: &mut replace_regions,
types: &mut |b| bug!("unexpected bound ty in binder: {b:?}"),
consts: &mut |b| bug!("unexpected bound ct in binder: {b:?}"),
regions: replace_regions,
types: |b| bug!("unexpected bound ty in binder: {b:?}"),
consts: |b| bug!("unexpected bound ct in binder: {b:?}"),
};
let mut replacer = BoundVarReplacer::new(self, delegate);
value.fold_with(&mut replacer)
Expand Down Expand Up @@ -286,21 +291,21 @@ impl<'tcx> TyCtxt<'tcx> {
self.replace_escaping_bound_vars_uncached(
value,
FnMutDelegate {
regions: &mut |r: ty::BoundRegion| {
regions: |r: ty::BoundRegion| {
ty::Region::new_bound(
self,
ty::INNERMOST,
ty::BoundRegion { var: shift_bv(r.var), kind: r.kind },
)
},
types: &mut |t: ty::BoundTy| {
types: |t: ty::BoundTy| {
Ty::new_bound(
self,
ty::INNERMOST,
ty::BoundTy { var: shift_bv(t.var), kind: t.kind },
)
},
consts: &mut |c| ty::Const::new_bound(self, ty::INNERMOST, shift_bv(c)),
consts: |c| ty::Const::new_bound(self, ty::INNERMOST, shift_bv(c)),
},
)
}
Expand Down
Loading