compiler: fold by value

This commit is contained in:
Bastian Kauschke 2020-10-24 02:21:18 +02:00
parent 3ec6720bf1
commit 2bf93bd852
140 changed files with 679 additions and 699 deletions

View file

@ -227,7 +227,7 @@ impl<'tcx> chalk_solve::RustIrDatabase<RustInterner<'tcx>> for RustIrDatabase<'t
let (inputs_and_output, iobinders, _) = crate::chalk::lowering::collect_bound_vars(
&self.interner,
self.interner.tcx,
&sig.inputs_and_output().subst(self.interner.tcx, bound_vars),
sig.inputs_and_output().subst(self.interner.tcx, bound_vars),
);
let argument_types = inputs_and_output[..inputs_and_output.len() - 1]
@ -461,7 +461,7 @@ impl<'tcx> chalk_solve::RustIrDatabase<RustInterner<'tcx>> for RustIrDatabase<'t
) -> Arc<chalk_solve::rust_ir::OpaqueTyDatum<RustInterner<'tcx>>> {
let bound_vars = ty::fold::shift_vars(
self.interner.tcx,
&bound_vars_for_item(self.interner.tcx, opaque_ty_id.0),
bound_vars_for_item(self.interner.tcx, opaque_ty_id.0),
1,
);
let where_clauses = self.where_clauses_for(opaque_ty_id.0, bound_vars);

View file

@ -86,7 +86,7 @@ impl<'tcx> LowerInto<'tcx, chalk_ir::InEnvironment<chalk_ir::Goal<RustInterner<'
let (predicate, binders, _named_regions) = collect_bound_vars(
interner,
interner.tcx,
&predicate.bound_atom_with_opt_escaping(interner.tcx),
predicate.bound_atom_with_opt_escaping(interner.tcx),
);
let consequence = match predicate {
ty::PredicateAtom::TypeWellFormedFromEnv(ty) => {
@ -141,7 +141,7 @@ impl<'tcx> LowerInto<'tcx, chalk_ir::GoalData<RustInterner<'tcx>>> for ty::Predi
let (predicate, binders, _named_regions) = collect_bound_vars(
interner,
interner.tcx,
&self.bound_atom_with_opt_escaping(interner.tcx),
self.bound_atom_with_opt_escaping(interner.tcx),
);
let value = match predicate {
@ -293,7 +293,7 @@ impl<'tcx> LowerInto<'tcx, chalk_ir::Ty<RustInterner<'tcx>>> for Ty<'tcx> {
}
ty::FnPtr(sig) => {
let (inputs_and_outputs, binders, _named_regions) =
collect_bound_vars(interner, interner.tcx, &sig.inputs_and_output());
collect_bound_vars(interner, interner.tcx, sig.inputs_and_output());
chalk_ir::TyKind::Function(chalk_ir::FnPointer {
num_binders: binders.len(interner),
sig: sig.lower_into(interner),
@ -578,7 +578,7 @@ impl<'tcx> LowerInto<'tcx, Option<chalk_ir::QuantifiedWhereClause<RustInterner<'
let (predicate, binders, _named_regions) = collect_bound_vars(
interner,
interner.tcx,
&self.bound_atom_with_opt_escaping(interner.tcx),
self.bound_atom_with_opt_escaping(interner.tcx),
);
let value = match predicate {
ty::PredicateAtom::Trait(predicate, _) => {
@ -627,10 +627,10 @@ impl<'tcx> LowerInto<'tcx, chalk_ir::Binders<chalk_ir::QuantifiedWhereClauses<Ru
// Binders<&[Binders<WhereClause<I>>]>
// This means that any variables that are escaping `self` need to be
// shifted in by one so that they are still escaping.
let shifted_predicates = ty::fold::shift_vars(interner.tcx, &self, 1);
let shifted_predicates = ty::fold::shift_vars(interner.tcx, self, 1);
let (predicates, binders, _named_regions) =
collect_bound_vars(interner, interner.tcx, &shifted_predicates);
collect_bound_vars(interner, interner.tcx, shifted_predicates);
let self_ty = interner.tcx.mk_ty(ty::Bound(
// This is going to be wrapped in a binder
ty::DebruijnIndex::from_usize(1),
@ -707,7 +707,7 @@ impl<'tcx> LowerInto<'tcx, Option<chalk_solve::rust_ir::QuantifiedInlineBound<Ru
let (predicate, binders, _named_regions) = collect_bound_vars(
interner,
interner.tcx,
&self.bound_atom_with_opt_escaping(interner.tcx),
self.bound_atom_with_opt_escaping(interner.tcx),
);
match predicate {
ty::PredicateAtom::Trait(predicate, _) => Some(chalk_ir::Binders::new(
@ -808,10 +808,10 @@ impl<'tcx> LowerInto<'tcx, chalk_solve::rust_ir::AliasEqBound<RustInterner<'tcx>
/// It's important to note that because of prior substitution, we may have
/// late-bound regions, even outside of fn contexts, since this is the best way
/// to prep types for chalk lowering.
crate fn collect_bound_vars<'a, 'tcx, T: TypeFoldable<'tcx>>(
crate fn collect_bound_vars<'tcx, T: TypeFoldable<'tcx>>(
interner: &RustInterner<'tcx>,
tcx: TyCtxt<'tcx>,
ty: &'a Binder<T>,
ty: Binder<T>,
) -> (T, chalk_ir::VariableKinds<RustInterner<'tcx>>, BTreeMap<DefId, u32>) {
let mut bound_vars_collector = BoundVarsCollector::new();
ty.as_ref().skip_binder().visit_with(&mut bound_vars_collector);
@ -824,7 +824,7 @@ crate fn collect_bound_vars<'a, 'tcx, T: TypeFoldable<'tcx>>(
.collect();
let mut bound_var_substitutor = NamedBoundVarSubstitutor::new(tcx, &named_parameters);
let new_ty = ty.as_ref().skip_binder().fold_with(&mut bound_var_substitutor);
let new_ty = ty.skip_binder().fold_with(&mut bound_var_substitutor);
for var in named_parameters.values() {
parameters.insert(*var, chalk_ir::VariableKind::Lifetime);
@ -833,7 +833,7 @@ crate fn collect_bound_vars<'a, 'tcx, T: TypeFoldable<'tcx>>(
(0..parameters.len()).for_each(|i| {
parameters
.get(&(i as u32))
.or_else(|| bug!("Skipped bound var index: ty={:?}, parameters={:?}", ty, parameters));
.or_else(|| bug!("Skipped bound var index: parameters={:?}", parameters));
});
let binders =
@ -941,7 +941,7 @@ impl<'a, 'tcx> TypeFolder<'tcx> for NamedBoundVarSubstitutor<'a, 'tcx> {
self.tcx
}
fn fold_binder<T: TypeFoldable<'tcx>>(&mut self, t: &Binder<T>) -> Binder<T> {
fn fold_binder<T: TypeFoldable<'tcx>>(&mut self, t: Binder<T>) -> Binder<T> {
self.binder_index.shift_in(1);
let result = t.super_fold_with(self);
self.binder_index.shift_out(1);
@ -1001,7 +1001,7 @@ impl<'tcx> TypeFolder<'tcx> for ParamsSubstitutor<'tcx> {
self.tcx
}
fn fold_binder<T: TypeFoldable<'tcx>>(&mut self, t: &Binder<T>) -> Binder<T> {
fn fold_binder<T: TypeFoldable<'tcx>>(&mut self, t: Binder<T>) -> Binder<T> {
self.binder_index.shift_in(1);
let result = t.super_fold_with(self);
self.binder_index.shift_out(1);

View file

@ -106,7 +106,7 @@ fn dropck_outlives<'tcx>(
// do not themselves define a destructor", more or less. We have
// to push them onto the stack to be expanded.
for ty in constraints.dtorck_types.drain(..) {
match infcx.at(&cause, param_env).normalize(&ty) {
match infcx.at(&cause, param_env).normalize(ty) {
Ok(Normalized { value: ty, obligations }) => {
fulfill_cx.register_predicate_obligations(infcx, obligations);

View file

@ -115,7 +115,7 @@ fn compute_implied_outlives_bounds<'tcx>(
}
ty::PredicateAtom::TypeOutlives(ty::OutlivesPredicate(ty_a, r_b)) => {
let ty_a = infcx.resolve_vars_if_possible(&ty_a);
let ty_a = infcx.resolve_vars_if_possible(ty_a);
let mut components = smallvec![];
tcx.push_outlives_components(ty_a, &mut components);
implied_bounds_from_components(r_b, components)

View file

@ -21,7 +21,7 @@ fn normalize_generic_arg_after_erasing_regions<'tcx>(
tcx.sess.perf_stats.normalize_generic_arg_after_erasing_regions.fetch_add(1, Ordering::Relaxed);
tcx.infer_ctxt().enter(|infcx| {
let cause = ObligationCause::dummy();
match infcx.at(&cause, param_env).normalize(&value) {
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
@ -31,8 +31,8 @@ fn normalize_generic_arg_after_erasing_regions<'tcx>(
None,
);
let normalized_value = infcx.resolve_vars_if_possible(&normalized_value);
infcx.tcx.erase_regions(&normalized_value)
let normalized_value = infcx.resolve_vars_if_possible(normalized_value);
infcx.tcx.erase_regions(normalized_value)
}
Err(NoSolution) => bug!("could not fully normalize `{:?}`", value),
}

View file

@ -70,7 +70,7 @@ impl AscribeUserTypeCx<'me, 'tcx> {
DUMMY_SP,
hir::CRATE_HIR_ID,
self.param_env,
&value,
value,
)
.into_value_registering_obligations(self.infcx, self.fulfill_cx)
}
@ -184,7 +184,7 @@ where
{
let (param_env, Normalize { value }) = key.into_parts();
let Normalized { value, obligations } =
infcx.at(&ObligationCause::dummy(), param_env).normalize(&value)?;
infcx.at(&ObligationCause::dummy(), param_env).normalize(value)?;
fulfill_cx.register_predicate_obligations(infcx, obligations);
Ok(value)
}