Add mk_canonical_var_infos_from_iter.

It's missing, and is useful in two places.
This commit is contained in:
Nicholas Nethercote 2023-02-20 10:46:37 +11:00
parent 11c2c596e4
commit c09f5b6a6b
3 changed files with 28 additions and 23 deletions

View File

@ -270,9 +270,9 @@ fn decode(decoder: &mut D) -> Self {
impl<'tcx, D: TyDecoder<I = TyCtxt<'tcx>>> Decodable<D> for CanonicalVarInfos<'tcx> {
fn decode(decoder: &mut D) -> Self {
let len = decoder.read_usize();
let interned: Vec<CanonicalVarInfo<'tcx>> =
(0..len).map(|_| Decodable::decode(decoder)).collect();
decoder.interner().mk_canonical_var_infos(&interned)
decoder.interner().mk_canonical_var_infos_from_iter(
(0..len).map::<CanonicalVarInfo<'tcx>, _>(|_| Decodable::decode(decoder)),
)
}
}

View File

@ -2253,6 +2253,14 @@ pub fn mk_substs_from_iter<I, T>(self, iter: I) -> T::Output
T::collect_and_apply(iter, |xs| self.mk_substs(xs))
}
pub fn mk_canonical_var_infos_from_iter<I, T>(self, iter: I) -> T::Output
where
I: Iterator<Item = T>,
T: CollectAndApply<CanonicalVarInfo<'tcx>, &'tcx List<CanonicalVarInfo<'tcx>>>,
{
T::collect_and_apply(iter, |xs| self.mk_canonical_var_infos(xs))
}
pub fn mk_place_elems_from_iter<I, T>(self, iter: I) -> T::Output
where
I: Iterator<Item = T>,

View File

@ -102,9 +102,7 @@ pub(crate) fn evaluate_goal<'tcx>(
.iter()
.map(|p| p.lower_into(interner).fold_with(&mut reverse_param_substitutor)),
);
let variables: Vec<_> = binders
.iter(interner)
.map(|var| {
let variables = binders.iter(interner).map(|var| {
let kind = match var.kind {
chalk_ir::VariableKind::Ty(ty_kind) => CanonicalVarKind::Ty(match ty_kind {
chalk_ir::TyVariableKind::General => CanonicalTyVarKind::General(
@ -113,20 +111,19 @@ pub(crate) fn evaluate_goal<'tcx>(
chalk_ir::TyVariableKind::Integer => CanonicalTyVarKind::Int,
chalk_ir::TyVariableKind::Float => CanonicalTyVarKind::Float,
}),
chalk_ir::VariableKind::Lifetime => CanonicalVarKind::Region(
ty::UniverseIndex::from_usize(var.skip_kind().counter),
),
chalk_ir::VariableKind::Lifetime => {
CanonicalVarKind::Region(ty::UniverseIndex::from_usize(var.skip_kind().counter))
}
// FIXME(compiler-errors): We don't currently have a way of turning
// a Chalk ty back into a rustc ty, right?
chalk_ir::VariableKind::Const(_) => todo!(),
};
CanonicalVarInfo { kind }
})
.collect();
});
let max_universe = binders.iter(interner).map(|v| v.skip_kind().counter).max().unwrap_or(0);
let sol = Canonical {
max_universe: ty::UniverseIndex::from_usize(max_universe),
variables: tcx.mk_canonical_var_infos(&variables),
variables: tcx.mk_canonical_var_infos_from_iter(variables),
value: QueryResponse {
var_values: CanonicalVarValues { var_values },
region_constraints: QueryRegionConstraints::default(),