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

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)) 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 pub fn mk_place_elems_from_iter<I, T>(self, iter: I) -> T::Output
where where
I: Iterator<Item = T>, I: Iterator<Item = T>,

View File

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