Auto merge of #91672 - b-naber:merge-normalize-erasing-regions-queries, r=jackh726
Implement normalize_erasing_regions queries in terms of 'try' version Attempt to lessen performance regression caused by https://github.com/rust-lang/rust/pull/91255 r? `@jackh726`
This commit is contained in:
commit
9b45f04414
@ -1658,27 +1658,6 @@
|
|||||||
remap_env_constness
|
remap_env_constness
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME: Implement `normalize_generic_arg_after_erasing_regions` and
|
|
||||||
// `normalize_mir_const_after_erasing_regions` in terms of
|
|
||||||
// `try_normalize_generic_arg_after_erasing_regions` and
|
|
||||||
// `try_normalize_mir_const_after_erasing_regions`, respectively.
|
|
||||||
|
|
||||||
/// Do not call this query directly: invoke `normalize_erasing_regions` instead.
|
|
||||||
query normalize_generic_arg_after_erasing_regions(
|
|
||||||
goal: ParamEnvAnd<'tcx, GenericArg<'tcx>>
|
|
||||||
) -> GenericArg<'tcx> {
|
|
||||||
desc { "normalizing `{}`", goal.value }
|
|
||||||
remap_env_constness
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Do not call this query directly: invoke `normalize_erasing_regions` instead.
|
|
||||||
query normalize_mir_const_after_erasing_regions(
|
|
||||||
goal: ParamEnvAnd<'tcx, mir::ConstantKind<'tcx>>
|
|
||||||
) -> mir::ConstantKind<'tcx> {
|
|
||||||
desc { "normalizing `{}`", goal.value }
|
|
||||||
remap_env_constness
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Do not call this query directly: invoke `try_normalize_erasing_regions` instead.
|
/// Do not call this query directly: invoke `try_normalize_erasing_regions` instead.
|
||||||
query try_normalize_generic_arg_after_erasing_regions(
|
query try_normalize_generic_arg_after_erasing_regions(
|
||||||
goal: ParamEnvAnd<'tcx, GenericArg<'tcx>>
|
goal: ParamEnvAnd<'tcx, GenericArg<'tcx>>
|
||||||
|
@ -176,7 +176,10 @@ fn normalize_generic_arg_after_erasing_regions(
|
|||||||
let arg = self.param_env.and(arg);
|
let arg = self.param_env.and(arg);
|
||||||
debug!(?arg);
|
debug!(?arg);
|
||||||
|
|
||||||
self.tcx.normalize_generic_arg_after_erasing_regions(arg)
|
self.tcx.try_normalize_generic_arg_after_erasing_regions(arg).unwrap_or_else(|_| bug!(
|
||||||
|
"Failed to normalize {:?}, maybe try to call `try_normalize_erasing_regions` instead",
|
||||||
|
arg.value
|
||||||
|
))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -197,7 +200,9 @@ fn fold_const(&mut self, c: &'tcx ty::Const<'tcx>) -> &'tcx ty::Const<'tcx> {
|
|||||||
fn fold_mir_const(&mut self, c: mir::ConstantKind<'tcx>) -> mir::ConstantKind<'tcx> {
|
fn fold_mir_const(&mut self, c: mir::ConstantKind<'tcx>) -> mir::ConstantKind<'tcx> {
|
||||||
// FIXME: This *probably* needs canonicalization too!
|
// FIXME: This *probably* needs canonicalization too!
|
||||||
let arg = self.param_env.and(c);
|
let arg = self.param_env.and(c);
|
||||||
self.tcx.normalize_mir_const_after_erasing_regions(arg)
|
self.tcx
|
||||||
|
.try_normalize_mir_const_after_erasing_regions(arg)
|
||||||
|
.unwrap_or_else(|_| bug!("failed to normalize {:?}", c))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,20 +8,13 @@
|
|||||||
|
|
||||||
crate fn provide(p: &mut Providers) {
|
crate fn provide(p: &mut Providers) {
|
||||||
*p = Providers {
|
*p = Providers {
|
||||||
normalize_generic_arg_after_erasing_regions: |tcx, goal| {
|
try_normalize_generic_arg_after_erasing_regions: |tcx, goal| {
|
||||||
debug!("normalize_generic_arg_after_erasing_regions(goal={:#?})", goal);
|
debug!("try_normalize_generic_arg_after_erasing_regions(goal={:#?}", goal);
|
||||||
|
|
||||||
tcx.sess
|
tcx.sess
|
||||||
.perf_stats
|
.perf_stats
|
||||||
.normalize_generic_arg_after_erasing_regions
|
.normalize_generic_arg_after_erasing_regions
|
||||||
.fetch_add(1, Ordering::Relaxed);
|
.fetch_add(1, Ordering::Relaxed);
|
||||||
normalize_after_erasing_regions(tcx, goal)
|
|
||||||
},
|
|
||||||
normalize_mir_const_after_erasing_regions: |tcx, goal| {
|
|
||||||
normalize_after_erasing_regions(tcx, goal)
|
|
||||||
},
|
|
||||||
try_normalize_generic_arg_after_erasing_regions: |tcx, goal| {
|
|
||||||
debug!("try_normalize_generic_arg_after_erasing_regions(goal={:#?}", goal);
|
|
||||||
|
|
||||||
try_normalize_after_erasing_regions(tcx, goal)
|
try_normalize_after_erasing_regions(tcx, goal)
|
||||||
},
|
},
|
||||||
@ -32,38 +25,6 @@
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
#[instrument(level = "debug", skip(tcx))]
|
|
||||||
fn normalize_after_erasing_regions<'tcx, T: TypeFoldable<'tcx> + PartialEq + Copy>(
|
|
||||||
tcx: TyCtxt<'tcx>,
|
|
||||||
goal: ParamEnvAnd<'tcx, T>,
|
|
||||||
) -> T {
|
|
||||||
let ParamEnvAnd { param_env, value } = goal;
|
|
||||||
tcx.infer_ctxt().enter(|infcx| {
|
|
||||||
let cause = ObligationCause::dummy();
|
|
||||||
match infcx.at(&cause, param_env).normalize(value) {
|
|
||||||
Ok(Normalized { value: normalized_value, obligations: normalized_obligations }) => {
|
|
||||||
// We don't care about the `obligations`; they are
|
|
||||||
// always only region relations, and we are about to
|
|
||||||
// erase those anyway:
|
|
||||||
debug_assert_eq!(
|
|
||||||
normalized_obligations.iter().find(|p| not_outlives_predicate(&p.predicate)),
|
|
||||||
None,
|
|
||||||
);
|
|
||||||
|
|
||||||
let resolved_value = infcx.resolve_vars_if_possible(normalized_value);
|
|
||||||
// It's unclear when `resolve_vars` would have an effect in a
|
|
||||||
// fresh `InferCtxt`. If this assert does trigger, it will give
|
|
||||||
// us a test case.
|
|
||||||
debug_assert_eq!(normalized_value, resolved_value);
|
|
||||||
let erased = infcx.tcx.erase_regions(resolved_value);
|
|
||||||
debug_assert!(!erased.needs_infer(), "{:?}", erased);
|
|
||||||
erased
|
|
||||||
}
|
|
||||||
Err(NoSolution) => bug!("could not fully normalize `{:?}`", value),
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
#[instrument(level = "debug", skip(tcx))]
|
#[instrument(level = "debug", skip(tcx))]
|
||||||
fn try_normalize_after_erasing_regions<'tcx, T: TypeFoldable<'tcx> + PartialEq + Copy>(
|
fn try_normalize_after_erasing_regions<'tcx, T: TypeFoldable<'tcx> + PartialEq + Copy>(
|
||||||
tcx: TyCtxt<'tcx>,
|
tcx: TyCtxt<'tcx>,
|
||||||
|
Loading…
Reference in New Issue
Block a user