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

@@ -444,7 +444,7 @@ pub(in crate::solve) fn instantiate_canonical_state<'tcx, T: TypeFoldable<TyCtxt
infcx.next_region_var(RegionVariableOrigin::MiscVariable(span)).into()
}
ty::GenericArgKind::Type(_) => infcx.next_ty_var(span).into(),
ty::GenericArgKind::Const(ct) => infcx.next_const_var(ct.ty(), span).into(),
ty::GenericArgKind::Const(_) => infcx.next_const_var(span).into(),
};
orig_values.push(unconstrained);

View File

@@ -609,8 +609,8 @@ impl<'tcx> EvalCtxt<'_, InferCtxt<'tcx>> {
ty
}
pub(super) fn next_const_infer(&mut self, ty: Ty<'tcx>) -> ty::Const<'tcx> {
let ct = self.infcx.next_const_var(ty, DUMMY_SP);
pub(super) fn next_const_infer(&mut self) -> ty::Const<'tcx> {
let ct = self.infcx.next_const_var(DUMMY_SP);
self.inspect.add_var_value(ct);
ct
}
@@ -620,7 +620,7 @@ impl<'tcx> EvalCtxt<'_, InferCtxt<'tcx>> {
pub(super) fn next_term_infer_of_kind(&mut self, kind: ty::Term<'tcx>) -> ty::Term<'tcx> {
match kind.unpack() {
ty::TermKind::Ty(_) => self.next_ty_infer().into(),
ty::TermKind::Const(ct) => self.next_const_infer(ct.ty()).into(),
ty::TermKind::Const(_) => self.next_const_infer().into(),
}
}
@@ -1037,14 +1037,14 @@ impl<'tcx> EvalCtxt<'_, InferCtxt<'tcx>> {
&self,
param_env: ty::ParamEnv<'tcx>,
unevaluated: ty::UnevaluatedConst<'tcx>,
ty: Ty<'tcx>,
) -> Option<ty::Const<'tcx>> {
use rustc_middle::mir::interpret::ErrorHandled;
match self.infcx.const_eval_resolve(param_env, unevaluated, DUMMY_SP) {
Ok(Some(val)) => Some(ty::Const::new_value(self.interner(), val, ty)),
// THISPR
Ok(Some(val)) => Some(ty::Const::new_value(self.interner(), val, todo!())),
Ok(None) | Err(ErrorHandled::TooGeneric(_)) => None,
Err(ErrorHandled::Reported(e, _)) => {
Some(ty::Const::new_error(self.interner(), e.into(), ty))
Some(ty::Const::new_error(self.interner(), e.into()))
}
}
}
@@ -1124,7 +1124,7 @@ impl<'tcx> TypeFolder<TyCtxt<'tcx>> for ReplaceAliasWithInfer<'_, '_, 'tcx> {
fn fold_const(&mut self, ct: ty::Const<'tcx>) -> ty::Const<'tcx> {
match ct.kind() {
ty::ConstKind::Unevaluated(..) if !ct.has_escaping_bound_vars() => {
let infer_ct = self.ecx.next_const_infer(ct.ty());
let infer_ct = self.ecx.next_const_infer();
let normalizes_to = ty::PredicateKind::AliasRelate(
ct.into(),
infer_ct.into(),

View File

@@ -208,7 +208,7 @@ impl<'a, 'tcx> InspectCandidate<'a, 'tcx> {
Some(ty::PredicateKind::NormalizesTo(ty::NormalizesTo { alias, term })) => {
let unconstrained_term = match term.unpack() {
ty::TermKind::Ty(_) => infcx.next_ty_var(span).into(),
ty::TermKind::Const(ct) => infcx.next_const_var(ct.ty(), span).into(),
ty::TermKind::Const(_) => infcx.next_const_var(span).into(),
};
let goal =
goal.with(infcx.tcx, ty::NormalizesTo { alias, term: unconstrained_term });

View File

@@ -169,7 +169,7 @@ impl<'a, 'tcx> EvalCtxt<'a, InferCtxt<'tcx>> {
// FIXME(generic_const_exprs): Implement handling for generic
// const expressions here.
if let Some(_normalized) = self.try_const_eval_resolve(param_env, uv, ct.ty()) {
if let Some(_normalized) = self.try_const_eval_resolve(param_env, uv) {
self.evaluate_added_goals_and_make_canonical_response(Certainty::Yes)
} else {
self.evaluate_added_goals_and_make_canonical_response(Certainty::AMBIGUOUS)
@@ -217,7 +217,8 @@ impl<'a, 'tcx> EvalCtxt<'a, InferCtxt<'tcx>> {
self.evaluate_added_goals_and_make_canonical_response(Certainty::Yes)
}
_ => {
self.eq(goal.param_env, ct.ty(), ty)?;
// THISPR
self.eq(goal.param_env, todo!(), ty)?;
self.evaluate_added_goals_and_make_canonical_response(Certainty::Yes)
}
}

View File

@@ -109,7 +109,6 @@ where
fn normalize_unevaluated_const(
&mut self,
ty: Ty<'tcx>,
uv: ty::UnevaluatedConst<'tcx>,
) -> Result<ty::Const<'tcx>, Vec<E>> {
let infcx = self.at.infcx;
@@ -126,7 +125,7 @@ where
self.depth += 1;
let new_infer_ct = infcx.next_const_var(ty, self.at.cause.span);
let new_infer_ct = infcx.next_const_var(self.at.cause.span);
let obligation = Obligation::new(
tcx,
self.at.cause.clone(),
@@ -143,7 +142,7 @@ where
let ct = infcx.resolve_vars_if_possible(new_infer_ct);
ct.try_fold_with(self)?
} else {
ty::Const::new_unevaluated(tcx, uv, ty).try_super_fold_with(self)?
ty::Const::new_unevaluated(tcx, uv).try_super_fold_with(self)?
};
self.depth -= 1;
@@ -214,7 +213,7 @@ where
if uv.has_escaping_bound_vars() {
let (uv, mapped_regions, mapped_types, mapped_consts) =
BoundVarReplacer::replace_bound_vars(infcx, &mut self.universes, uv);
let result = ensure_sufficient_stack(|| self.normalize_unevaluated_const(ct.ty(), uv))?;
let result = ensure_sufficient_stack(|| self.normalize_unevaluated_const(uv))?;
Ok(PlaceholderReplacer::replace_placeholders(
infcx,
mapped_regions,
@@ -224,7 +223,7 @@ where
result,
))
} else {
ensure_sufficient_stack(|| self.normalize_unevaluated_const(ct.ty(), uv))
ensure_sufficient_stack(|| self.normalize_unevaluated_const(uv))
}
}
}

View File

@@ -12,10 +12,6 @@ impl<'tcx> EvalCtxt<'_, InferCtxt<'tcx>> {
if let Some(normalized_const) = self.try_const_eval_resolve(
goal.param_env,
ty::UnevaluatedConst::new(goal.predicate.alias.def_id, goal.predicate.alias.args),
self.interner()
.type_of(goal.predicate.alias.def_id)
.no_bound_vars()
.expect("const ty should not rely on other generics"),
) {
self.instantiate_normalizes_to_term(goal, normalized_const.into());
self.evaluate_added_goals_and_make_canonical_response(Certainty::Yes)

View File

@@ -201,13 +201,7 @@ impl<'tcx> assembly::GoalKind<'tcx> for NormalizesTo<'tcx> {
let error_response = |ecx: &mut EvalCtxt<'_, InferCtxt<'tcx>>, reason| {
let guar = tcx.dcx().span_delayed_bug(tcx.def_span(assoc_def.item.def_id), reason);
let error_term = match assoc_def.item.kind {
ty::AssocKind::Const => ty::Const::new_error(
tcx,
guar,
tcx.type_of(goal.predicate.def_id())
.instantiate(tcx, goal.predicate.alias.args),
)
.into(),
ty::AssocKind::Const => ty::Const::new_error(tcx, guar).into(),
ty::AssocKind::Type => Ty::new_error(tcx, guar).into(),
// This makes no sense...
ty::AssocKind::Fn => span_bug!(
@@ -253,7 +247,6 @@ impl<'tcx> assembly::GoalKind<'tcx> for NormalizesTo<'tcx> {
ty::EarlyBinder::bind(
ty::Const::new_error_with_message(
tcx,
tcx.type_of(assoc_def.item.def_id).instantiate_identity(),
DUMMY_SP,
"associated const projection is not supported yet",
)