From ce7b75527687cbeea672f2052e06599d085c344c Mon Sep 17 00:00:00 2001 From: ouz-a Date: Wed, 24 Aug 2022 22:08:44 +0300 Subject: [PATCH 1/4] Prevent MIRI ice by bubbling up --- compiler/rustc_traits/src/normalize_erasing_regions.rs | 4 ++-- compiler/rustc_traits/src/normalize_projection_ty.rs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/compiler/rustc_traits/src/normalize_erasing_regions.rs b/compiler/rustc_traits/src/normalize_erasing_regions.rs index 5d394ed2263ff..3820e31507d57 100644 --- a/compiler/rustc_traits/src/normalize_erasing_regions.rs +++ b/compiler/rustc_traits/src/normalize_erasing_regions.rs @@ -1,4 +1,4 @@ -use rustc_infer::infer::TyCtxtInferExt; +use rustc_infer::infer::{DefiningAnchor,TyCtxtInferExt}; use rustc_middle::traits::query::NoSolution; use rustc_middle::ty::query::Providers; use rustc_middle::ty::{self, ParamEnvAnd, TyCtxt, TypeFoldable}; @@ -30,7 +30,7 @@ fn try_normalize_after_erasing_regions<'tcx, T: TypeFoldable<'tcx> + PartialEq + goal: ParamEnvAnd<'tcx, T>, ) -> Result { let ParamEnvAnd { param_env, value } = goal; - tcx.infer_ctxt().enter(|infcx| { + tcx.infer_ctxt().with_opaque_type_inference(DefiningAnchor::Bubble).enter(|infcx| { let cause = ObligationCause::dummy(); match infcx.at(&cause, param_env).normalize(value) { Ok(Normalized { value: normalized_value, obligations: normalized_obligations }) => { diff --git a/compiler/rustc_traits/src/normalize_projection_ty.rs b/compiler/rustc_traits/src/normalize_projection_ty.rs index 98bb42c9afda1..2ea4182c5e100 100644 --- a/compiler/rustc_traits/src/normalize_projection_ty.rs +++ b/compiler/rustc_traits/src/normalize_projection_ty.rs @@ -1,5 +1,5 @@ use rustc_infer::infer::canonical::{Canonical, QueryResponse}; -use rustc_infer::infer::TyCtxtInferExt; +use rustc_infer::infer::{DefiningAnchor,TyCtxtInferExt}; use rustc_infer::traits::TraitEngineExt as _; use rustc_middle::ty::query::Providers; use rustc_middle::ty::{ParamEnvAnd, TyCtxt}; @@ -21,7 +21,7 @@ fn normalize_projection_ty<'tcx>( debug!("normalize_provider(goal={:#?})", goal); tcx.sess.perf_stats.normalize_projection_ty.fetch_add(1, Ordering::Relaxed); - tcx.infer_ctxt().enter_canonical_trait_query( + tcx.infer_ctxt().with_opaque_type_inference(DefiningAnchor::Bubble).enter_canonical_trait_query( &goal, |infcx, fulfill_cx, ParamEnvAnd { param_env, value: goal }| { let selcx = &mut SelectionContext::new(infcx); From 8b0690a1a2d65edfb816735d8474dd3d76e09d2d Mon Sep 17 00:00:00 2001 From: ouz-a Date: Wed, 24 Aug 2022 22:28:29 +0300 Subject: [PATCH 2/4] fmt --- compiler/rustc_traits/src/normalize_erasing_regions.rs | 2 +- compiler/rustc_traits/src/normalize_projection_ty.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/compiler/rustc_traits/src/normalize_erasing_regions.rs b/compiler/rustc_traits/src/normalize_erasing_regions.rs index 3820e31507d57..be09a1933a1eb 100644 --- a/compiler/rustc_traits/src/normalize_erasing_regions.rs +++ b/compiler/rustc_traits/src/normalize_erasing_regions.rs @@ -1,4 +1,4 @@ -use rustc_infer::infer::{DefiningAnchor,TyCtxtInferExt}; +use rustc_infer::infer::{DefiningAnchor, TyCtxtInferExt}; use rustc_middle::traits::query::NoSolution; use rustc_middle::ty::query::Providers; use rustc_middle::ty::{self, ParamEnvAnd, TyCtxt, TypeFoldable}; diff --git a/compiler/rustc_traits/src/normalize_projection_ty.rs b/compiler/rustc_traits/src/normalize_projection_ty.rs index 2ea4182c5e100..dc98220707638 100644 --- a/compiler/rustc_traits/src/normalize_projection_ty.rs +++ b/compiler/rustc_traits/src/normalize_projection_ty.rs @@ -1,5 +1,5 @@ use rustc_infer::infer::canonical::{Canonical, QueryResponse}; -use rustc_infer::infer::{DefiningAnchor,TyCtxtInferExt}; +use rustc_infer::infer::{DefiningAnchor, TyCtxtInferExt}; use rustc_infer::traits::TraitEngineExt as _; use rustc_middle::ty::query::Providers; use rustc_middle::ty::{ParamEnvAnd, TyCtxt}; From 144838e762e184dd52299141a50cbcbc20362f36 Mon Sep 17 00:00:00 2001 From: ouz-a Date: Thu, 25 Aug 2022 01:09:41 +0300 Subject: [PATCH 3/4] add comment --- compiler/rustc_traits/src/normalize_erasing_regions.rs | 1 + compiler/rustc_traits/src/normalize_projection_ty.rs | 1 + 2 files changed, 2 insertions(+) diff --git a/compiler/rustc_traits/src/normalize_erasing_regions.rs b/compiler/rustc_traits/src/normalize_erasing_regions.rs index be09a1933a1eb..a4acf480a3438 100644 --- a/compiler/rustc_traits/src/normalize_erasing_regions.rs +++ b/compiler/rustc_traits/src/normalize_erasing_regions.rs @@ -30,6 +30,7 @@ fn try_normalize_after_erasing_regions<'tcx, T: TypeFoldable<'tcx> + PartialEq + goal: ParamEnvAnd<'tcx, T>, ) -> Result { let ParamEnvAnd { param_env, value } = goal; + // HACK (ouz-a) This prevents MIRI ICE see #100967 tcx.infer_ctxt().with_opaque_type_inference(DefiningAnchor::Bubble).enter(|infcx| { let cause = ObligationCause::dummy(); match infcx.at(&cause, param_env).normalize(value) { diff --git a/compiler/rustc_traits/src/normalize_projection_ty.rs b/compiler/rustc_traits/src/normalize_projection_ty.rs index dc98220707638..12f0cab959255 100644 --- a/compiler/rustc_traits/src/normalize_projection_ty.rs +++ b/compiler/rustc_traits/src/normalize_projection_ty.rs @@ -21,6 +21,7 @@ fn normalize_projection_ty<'tcx>( debug!("normalize_provider(goal={:#?})", goal); tcx.sess.perf_stats.normalize_projection_ty.fetch_add(1, Ordering::Relaxed); + // HACK (ouz-a) This prevents MIRI ICE see #100967 tcx.infer_ctxt().with_opaque_type_inference(DefiningAnchor::Bubble).enter_canonical_trait_query( &goal, |infcx, fulfill_cx, ParamEnvAnd { param_env, value: goal }| { From e29d1ada3d40fbe22f74e92ca522aa4bc7806804 Mon Sep 17 00:00:00 2001 From: ouz-a Date: Thu, 25 Aug 2022 13:17:09 +0300 Subject: [PATCH 4/4] Clearer comment --- compiler/rustc_traits/src/normalize_erasing_regions.rs | 2 +- compiler/rustc_traits/src/normalize_projection_ty.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/compiler/rustc_traits/src/normalize_erasing_regions.rs b/compiler/rustc_traits/src/normalize_erasing_regions.rs index a4acf480a3438..2121bf142e47d 100644 --- a/compiler/rustc_traits/src/normalize_erasing_regions.rs +++ b/compiler/rustc_traits/src/normalize_erasing_regions.rs @@ -30,7 +30,7 @@ fn try_normalize_after_erasing_regions<'tcx, T: TypeFoldable<'tcx> + PartialEq + goal: ParamEnvAnd<'tcx, T>, ) -> Result { let ParamEnvAnd { param_env, value } = goal; - // HACK (ouz-a) This prevents MIRI ICE see #100967 + // HACK (ouz-a) We bubble up here to prevent MIRI ICE see #100967 tcx.infer_ctxt().with_opaque_type_inference(DefiningAnchor::Bubble).enter(|infcx| { let cause = ObligationCause::dummy(); match infcx.at(&cause, param_env).normalize(value) { diff --git a/compiler/rustc_traits/src/normalize_projection_ty.rs b/compiler/rustc_traits/src/normalize_projection_ty.rs index 12f0cab959255..3ece79a0a1de9 100644 --- a/compiler/rustc_traits/src/normalize_projection_ty.rs +++ b/compiler/rustc_traits/src/normalize_projection_ty.rs @@ -21,7 +21,7 @@ fn normalize_projection_ty<'tcx>( debug!("normalize_provider(goal={:#?})", goal); tcx.sess.perf_stats.normalize_projection_ty.fetch_add(1, Ordering::Relaxed); - // HACK (ouz-a) This prevents MIRI ICE see #100967 + // HACK (ouz-a) We bubble up here to prevent MIRI ICE see #100967 tcx.infer_ctxt().with_opaque_type_inference(DefiningAnchor::Bubble).enter_canonical_trait_query( &goal, |infcx, fulfill_cx, ParamEnvAnd { param_env, value: goal }| {