Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[experiment] Use new solver in MIR validator subtyping checks #112365

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading