Skip to content

Commit

Permalink
Use new solver in MIR validator subtyping checks
Browse files Browse the repository at this point in the history
  • Loading branch information
compiler-errors committed Dec 18, 2023
1 parent 3f28fe1 commit 1c30b50
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 6 deletions.
9 changes: 8 additions & 1 deletion compiler/rustc_const_eval/src/interpret/eval_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,14 @@ pub(super) fn mir_assign_valid_types<'tcx>(
// all normal lifetimes are erased, higher-ranked types with their
// late-bound lifetimes are still around and can lead to type
// differences.
if util::relate_types(tcx, param_env, Variance::Covariant, src.ty, dest.ty) {
if util::relate_types(
tcx,
param_env,
Variance::Covariant,
src.ty,
dest.ty,
tcx.next_trait_solver_globally(),
) {
// Make sure the layout is equal, too -- just to be safe. Miri really
// needs layout equality. For performance reason we skip this check when
// the types are equal. Equal types *can* have different layouts when
Expand Down
3 changes: 2 additions & 1 deletion compiler/rustc_const_eval/src/transform/validate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -634,7 +634,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
Variance::Covariant
};

crate::util::relate_types(self.tcx, self.param_env, variance, src, dest)
crate::util::relate_types(self.tcx, self.param_env, variance, src, dest, true)
}
}

Expand Down Expand Up @@ -792,6 +792,7 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
Variance::Covariant,
ty,
place_ref.ty(&self.body.local_decls, self.tcx).ty,
true,
) {
self.fail(
location,
Expand Down
13 changes: 9 additions & 4 deletions compiler/rustc_const_eval/src/util/compare_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,16 @@ pub fn is_equal_up_to_subtyping<'tcx>(
param_env: ParamEnv<'tcx>,
src: Ty<'tcx>,
dest: Ty<'tcx>,
next_trait_solver: bool,
) -> bool {
// Fast path.
if src == dest {
return true;
}

// Check for subtyping in either direction.
relate_types(tcx, param_env, Variance::Covariant, src, dest)
|| relate_types(tcx, param_env, Variance::Covariant, dest, src)
relate_types(tcx, param_env, Variance::Covariant, src, dest, next_trait_solver)
|| relate_types(tcx, param_env, Variance::Covariant, dest, src, next_trait_solver)
}

/// Returns whether `src` is a subtype of `dest`, i.e. `src <: dest`.
Expand All @@ -42,13 +43,17 @@ pub fn relate_types<'tcx>(
variance: Variance,
src: Ty<'tcx>,
dest: Ty<'tcx>,
next_trait_solver: bool,
) -> bool {
if src == dest {
return true;
}

let mut builder =
tcx.infer_ctxt().ignoring_regions().with_opaque_type_inference(DefiningAnchor::Bubble);
let mut builder = tcx
.infer_ctxt()
.ignoring_regions()
.with_next_trait_solver(next_trait_solver)
.with_opaque_type_inference(DefiningAnchor::Bubble);
let infcx = builder.build();
let ocx = ObligationCtxt::new(&infcx);
let cause = ObligationCause::dummy();
Expand Down
3 changes: 3 additions & 0 deletions compiler/rustc_mir_transform/src/inline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ impl<'tcx> Inliner<'tcx> {
ty::Variance::Covariant,
output_type,
destination_ty,
true,
) {
trace!(?output_type, ?destination_ty);
return Err("failed to normalize return type");
Expand Down Expand Up @@ -256,6 +257,7 @@ impl<'tcx> Inliner<'tcx> {
ty::Variance::Covariant,
input_type,
arg_ty,
true,
) {
trace!(?arg_ty, ?input_type);
return Err("failed to normalize tuple argument type");
Expand All @@ -271,6 +273,7 @@ impl<'tcx> Inliner<'tcx> {
ty::Variance::Covariant,
input_type,
arg_ty,
true,
) {
trace!(?arg_ty, ?input_type);
return Err("failed to normalize argument type");
Expand Down

0 comments on commit 1c30b50

Please sign in to comment.