1
Fork 0

Basic removal of Ty from places (boring)

This commit is contained in:
Boxy 2024-06-03 01:10:24 +01:00
parent 7ebd2bdbf6
commit 58feec9b85
71 changed files with 331 additions and 581 deletions

View file

@ -462,7 +462,7 @@ impl<'cx, 'tcx> TypeFolder<TyCtxt<'tcx>> for Canonicalizer<'cx, 'tcx> {
// any equated inference vars correctly!
let root_vid = self.infcx.unwrap().root_const_var(vid);
if root_vid != vid {
ct = ty::Const::new_var(self.tcx, root_vid, ct.ty());
ct = ty::Const::new_var(self.tcx, root_vid);
vid = root_vid;
}
@ -481,7 +481,7 @@ impl<'cx, 'tcx> TypeFolder<TyCtxt<'tcx>> for Canonicalizer<'cx, 'tcx> {
ui = ty::UniverseIndex::ROOT;
}
return self.canonicalize_const_var(
CanonicalVarInfo { kind: CanonicalVarKind::Const(ui, ct.ty()) },
CanonicalVarInfo { kind: CanonicalVarKind::Const(ui) },
ct,
);
}
@ -510,9 +510,7 @@ impl<'cx, 'tcx> TypeFolder<TyCtxt<'tcx>> for Canonicalizer<'cx, 'tcx> {
}
ty::ConstKind::Placeholder(placeholder) => {
return self.canonicalize_const_var(
CanonicalVarInfo {
kind: CanonicalVarKind::PlaceholderConst(placeholder, ct.ty()),
},
CanonicalVarInfo { kind: CanonicalVarKind::PlaceholderConst(placeholder) },
ct,
);
}
@ -719,9 +717,7 @@ impl<'cx, 'tcx> Canonicalizer<'cx, 'tcx> {
CanonicalVarKind::Region(u) => {
CanonicalVarKind::Region(reverse_universe_map[&u])
}
CanonicalVarKind::Const(u, t) => {
CanonicalVarKind::Const(reverse_universe_map[&u], t)
}
CanonicalVarKind::Const(u) => CanonicalVarKind::Const(reverse_universe_map[&u]),
CanonicalVarKind::PlaceholderTy(placeholder) => {
CanonicalVarKind::PlaceholderTy(ty::Placeholder {
universe: reverse_universe_map[&placeholder.universe],
@ -734,14 +730,11 @@ impl<'cx, 'tcx> Canonicalizer<'cx, 'tcx> {
..placeholder
})
}
CanonicalVarKind::PlaceholderConst(placeholder, t) => {
CanonicalVarKind::PlaceholderConst(
ty::Placeholder {
universe: reverse_universe_map[&placeholder.universe],
..placeholder
},
t,
)
CanonicalVarKind::PlaceholderConst(placeholder) => {
CanonicalVarKind::PlaceholderConst(ty::Placeholder {
universe: reverse_universe_map[&placeholder.universe],
..placeholder
})
}
},
})
@ -806,6 +799,6 @@ impl<'cx, 'tcx> Canonicalizer<'cx, 'tcx> {
!self.infcx.is_some_and(|infcx| const_var != infcx.shallow_resolve_const(const_var))
);
let var = self.canonical_var(info, const_var.into());
ty::Const::new_bound(self.tcx, self.binder_index, var, self.fold_ty(const_var.ty()))
ty::Const::new_bound(self.tcx, self.binder_index, var)
}
}

View file

@ -70,7 +70,7 @@ where
GenericArgKind::Type(ty) => ty,
r => bug!("{:?} is a type but value is {:?}", bound_ty, r),
},
consts: &mut |bound_ct: ty::BoundVar, _| match var_values[bound_ct].unpack() {
consts: &mut |bound_ct: ty::BoundVar| match var_values[bound_ct].unpack() {
GenericArgKind::Const(ct) => ct,
c => bug!("{:?} is a const but value is {:?}", bound_ct, c),
},

View file

@ -143,8 +143,8 @@ impl<'tcx> InferCtxt<'tcx> {
ty::Region::new_placeholder(self.tcx, placeholder_mapped).into()
}
CanonicalVarKind::Const(ui, ty) => {
self.next_const_var_in_universe(ty, span, universe_map(ui)).into()
CanonicalVarKind::Const(ui) => {
self.next_const_var_in_universe(span, universe_map(ui)).into()
}
CanonicalVarKind::Effect => {
let vid = self
@ -153,13 +153,12 @@ impl<'tcx> InferCtxt<'tcx> {
.effect_unification_table()
.new_key(EffectVarValue::Unknown)
.vid;
ty::Const::new_infer(self.tcx, ty::InferConst::EffectVar(vid), self.tcx.types.bool)
.into()
ty::Const::new_infer(self.tcx, ty::InferConst::EffectVar(vid)).into()
}
CanonicalVarKind::PlaceholderConst(ty::PlaceholderConst { universe, bound }, ty) => {
CanonicalVarKind::PlaceholderConst(ty::PlaceholderConst { universe, bound }) => {
let universe_mapped = universe_map(universe);
let placeholder_mapped = ty::PlaceholderConst { universe: universe_mapped, bound };
ty::Const::new_placeholder(self.tcx, placeholder_mapped, ty).into()
ty::Const::new_placeholder(self.tcx, placeholder_mapped).into()
}
}
}

View file

@ -543,9 +543,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
match arg.unpack() {
GenericArgKind::Lifetime(_) => bug!("unexpected lifetime"),
GenericArgKind::Type(_) => self.next_ty_var(DUMMY_SP).into(),
GenericArgKind::Const(arg) => {
self.next_const_var(arg.ty(), DUMMY_SP).into()
}
GenericArgKind::Const(_) => self.next_const_var(DUMMY_SP).into(),
}
}))
.unwrap();

View file

@ -79,7 +79,6 @@ impl<'a, 'tcx> TypeFreshener<'a, 'tcx> {
&mut self,
input: Result<ty::Const<'tcx>, ty::InferConst>,
freshener: F,
ty: Ty<'tcx>,
) -> ty::Const<'tcx>
where
F: FnOnce(u32) -> ty::InferConst,
@ -91,7 +90,7 @@ impl<'a, 'tcx> TypeFreshener<'a, 'tcx> {
Entry::Vacant(entry) => {
let index = self.const_freshen_count;
self.const_freshen_count += 1;
let ct = ty::Const::new_infer(self.infcx.tcx, freshener(index), ty);
let ct = ty::Const::new_infer(self.infcx.tcx, freshener(index));
entry.insert(ct);
ct
}
@ -149,7 +148,7 @@ impl<'a, 'tcx> TypeFolder<TyCtxt<'tcx>> for TypeFreshener<'a, 'tcx> {
ty::InferConst::Var(inner.const_unification_table().find(v).vid)
});
drop(inner);
self.freshen_const(input, ty::InferConst::Fresh, ct.ty())
self.freshen_const(input, ty::InferConst::Fresh)
}
ty::ConstKind::Infer(ty::InferConst::EffectVar(v)) => {
let mut inner = self.infcx.inner.borrow_mut();
@ -158,7 +157,7 @@ impl<'a, 'tcx> TypeFolder<TyCtxt<'tcx>> for TypeFreshener<'a, 'tcx> {
ty::InferConst::EffectVar(inner.effect_unification_table().find(v).vid)
});
drop(inner);
self.freshen_const(input, ty::InferConst::Fresh, ct.ty())
self.freshen_const(input, ty::InferConst::Fresh)
}
ty::ConstKind::Infer(ty::InferConst::Fresh(i)) => {
if i >= self.const_freshen_count {

View file

@ -392,18 +392,18 @@ impl<'tcx> ty::InferCtxtLike for InferCtxt<'tcx> {
self.opportunistic_resolve_float_var(vid)
}
fn opportunistic_resolve_ct_var(&self, vid: ConstVid, ty: Ty<'tcx>) -> ty::Const<'tcx> {
fn opportunistic_resolve_ct_var(&self, vid: ConstVid) -> ty::Const<'tcx> {
match self.probe_const_var(vid) {
Ok(ct) => ct,
Err(_) => ty::Const::new_var(self.tcx, self.root_const_var(vid), ty),
Err(_) => ty::Const::new_var(self.tcx, self.root_const_var(vid)),
}
}
fn opportunistic_resolve_effect_var(&self, vid: EffectVid, ty: Ty<'tcx>) -> ty::Const<'tcx> {
fn opportunistic_resolve_effect_var(&self, vid: EffectVid) -> ty::Const<'tcx> {
match self.probe_effect_var(vid) {
Some(ct) => ct,
None => {
ty::Const::new_infer(self.tcx, InferConst::EffectVar(self.root_effect_var(vid)), ty)
ty::Const::new_infer(self.tcx, InferConst::EffectVar(self.root_effect_var(vid)))
}
}
}
@ -832,9 +832,7 @@ impl<'tcx> InferCtxt<'tcx> {
(0..table.len())
.map(|i| ty::EffectVid::from_usize(i))
.filter(|&vid| table.probe_value(vid).is_unknown())
.map(|v| {
ty::Const::new_infer(self.tcx, ty::InferConst::EffectVar(v), self.tcx.types.bool)
})
.map(|v| ty::Const::new_infer(self.tcx, ty::InferConst::EffectVar(v)))
.collect()
}
@ -993,27 +991,22 @@ impl<'tcx> InferCtxt<'tcx> {
Ty::new_var(self.tcx, vid)
}
pub fn next_const_var(&self, ty: Ty<'tcx>, span: Span) -> ty::Const<'tcx> {
self.next_const_var_with_origin(ty, ConstVariableOrigin { span, param_def_id: None })
pub fn next_const_var(&self, span: Span) -> ty::Const<'tcx> {
self.next_const_var_with_origin(ConstVariableOrigin { span, param_def_id: None })
}
pub fn next_const_var_with_origin(
&self,
ty: Ty<'tcx>,
origin: ConstVariableOrigin,
) -> ty::Const<'tcx> {
pub fn next_const_var_with_origin(&self, origin: ConstVariableOrigin) -> ty::Const<'tcx> {
let vid = self
.inner
.borrow_mut()
.const_unification_table()
.new_key(ConstVariableValue::Unknown { origin, universe: self.universe() })
.vid;
ty::Const::new_var(self.tcx, vid, ty)
ty::Const::new_var(self.tcx, vid)
}
pub fn next_const_var_in_universe(
&self,
ty: Ty<'tcx>,
span: Span,
universe: ty::UniverseIndex,
) -> ty::Const<'tcx> {
@ -1024,7 +1017,7 @@ impl<'tcx> InferCtxt<'tcx> {
.const_unification_table()
.new_key(ConstVariableValue::Unknown { origin, universe })
.vid;
ty::Const::new_var(self.tcx, vid, ty)
ty::Const::new_var(self.tcx, vid)
}
pub fn next_const_var_id(&self, origin: ConstVariableOrigin) -> ConstVid {
@ -1135,15 +1128,7 @@ impl<'tcx> InferCtxt<'tcx> {
.const_unification_table()
.new_key(ConstVariableValue::Unknown { origin, universe: self.universe() })
.vid;
ty::Const::new_var(
self.tcx,
const_var_id,
self.tcx
.type_of(param.def_id)
.no_bound_vars()
.expect("const parameter types cannot be generic"),
)
.into()
ty::Const::new_var(self.tcx, const_var_id).into()
}
}
}
@ -1157,7 +1142,7 @@ impl<'tcx> InferCtxt<'tcx> {
.no_bound_vars()
.expect("const parameter types cannot be generic");
debug_assert_eq!(self.tcx.types.bool, ty);
ty::Const::new_infer(self.tcx, ty::InferConst::EffectVar(effect_vid), ty).into()
ty::Const::new_infer(self.tcx, ty::InferConst::EffectVar(effect_vid)).into()
}
/// Given a set of generics defined on a type or impl, returns the generic parameters mapping each
@ -1469,10 +1454,10 @@ impl<'tcx> InferCtxt<'tcx> {
.or_insert_with(|| self.infcx.next_ty_var(self.span).into())
.expect_ty()
}
fn replace_const(&mut self, bv: ty::BoundVar, ty: Ty<'tcx>) -> ty::Const<'tcx> {
fn replace_const(&mut self, bv: ty::BoundVar) -> ty::Const<'tcx> {
self.map
.entry(bv)
.or_insert_with(|| self.infcx.next_const_var(ty, self.span).into())
.or_insert_with(|| self.infcx.next_const_var(self.span).into())
.expect_const()
}
}
@ -1526,11 +1511,11 @@ impl<'tcx> InferCtxt<'tcx> {
&self,
param_env: ty::ParamEnv<'tcx>,
unevaluated: ty::UnevaluatedConst<'tcx>,
ty: Ty<'tcx>,
span: Span,
) -> Result<ty::Const<'tcx>, ErrorHandled> {
match self.const_eval_resolve(param_env, unevaluated, span) {
Ok(Some(val)) => Ok(ty::Const::new_value(self.tcx, val, ty)),
// THISPR
Ok(Some(val)) => Ok(ty::Const::new_value(self.tcx, val, todo!())),
Ok(None) => {
let tcx = self.tcx;
let def_id = unevaluated.def;
@ -1964,11 +1949,6 @@ fn replace_param_and_infer_args_with_placeholder<'tcx>(
fn fold_const(&mut self, c: ty::Const<'tcx>) -> ty::Const<'tcx> {
if let ty::ConstKind::Infer(_) = c.kind() {
let ty = c.ty();
// If the type references param or infer then ICE ICE ICE
if ty.has_non_region_param() || ty.has_non_region_infer() {
bug!("const `{c}`'s type should not reference params or types");
}
ty::Const::new_placeholder(
self.tcx,
ty::PlaceholderConst {
@ -1979,7 +1959,6 @@ fn replace_param_and_infer_args_with_placeholder<'tcx>(
idx
}),
},
ty,
)
} else {
c.super_fold_with(self)

View file

@ -653,7 +653,7 @@ impl<'tcx> TypeRelation<'tcx> for Generalizer<'_, 'tcx> {
{
variable_table.union(vid, new_var_id);
}
Ok(ty::Const::new_var(self.tcx(), new_var_id, c.ty()))
Ok(ty::Const::new_var(self.tcx(), new_var_id))
}
}
}
@ -671,11 +671,7 @@ impl<'tcx> TypeRelation<'tcx> for Generalizer<'_, 'tcx> {
args,
args,
)?;
Ok(ty::Const::new_unevaluated(
self.tcx(),
ty::UnevaluatedConst { def, args },
c.ty(),
))
Ok(ty::Const::new_unevaluated(self.tcx(), ty::UnevaluatedConst { def, args }))
}
ty::ConstKind::Placeholder(placeholder) => {
if self.for_universe.can_name(placeholder.universe) {

View file

@ -43,11 +43,10 @@ impl<'tcx> InferCtxt<'tcx> {
ty::PlaceholderType { universe: next_universe, bound: bound_ty },
)
},
consts: &mut |bound_var: ty::BoundVar, ty| {
consts: &mut |bound_var: ty::BoundVar| {
ty::Const::new_placeholder(
self.tcx,
ty::PlaceholderConst { universe: next_universe, bound: bound_var },
ty,
)
},
};

View file

@ -244,7 +244,7 @@ impl<'a, 'tcx> TypeFolder<TyCtxt<'tcx>> for InferenceFudger<'a, 'tcx> {
// Recreate it with a fresh variable here.
let idx = vid.index() - self.const_vars.0.start.index();
let origin = self.const_vars.1[idx];
self.infcx.next_const_var_with_origin(ct.ty(), origin)
self.infcx.next_const_var_with_origin(origin)
} else {
ct
}