From 77d3ca1bad2f99fe9a0691551c5524fcc290a406 Mon Sep 17 00:00:00 2001 From: Douglas Campos Date: Tue, 19 Sep 2017 22:39:00 -0400 Subject: [PATCH 1/5] add ParamEnv to the trait_cache key --- src/librustc/traits/trans/mod.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/librustc/traits/trans/mod.rs b/src/librustc/traits/trans/mod.rs index 9c4a260b35d49..3bc8a65df1c14 100644 --- a/src/librustc/traits/trans/mod.rs +++ b/src/librustc/traits/trans/mod.rs @@ -38,17 +38,17 @@ impl<'a, 'tcx> TyCtxt<'a, 'tcx, 'tcx> { { // Remove any references to regions; this helps improve caching. let trait_ref = self.erase_regions(&trait_ref); + let param_env = ty::ParamEnv::empty(Reveal::All); - self.trans_trait_caches.trait_cache.memoize(trait_ref, || { + self.trans_trait_caches.trait_cache.memoize((param_env, trait_ref), || { debug!("trans::fulfill_obligation(trait_ref={:?}, def_id={:?})", - trait_ref, trait_ref.def_id()); + (param_env, trait_ref), trait_ref.def_id()); // Do the initial selection for the obligation. This yields the // shallow result we are looking for -- that is, what specific impl. self.infer_ctxt().enter(|infcx| { let mut selcx = SelectionContext::new(&infcx); - let param_env = ty::ParamEnv::empty(Reveal::All); let obligation_cause = ObligationCause::misc(span, ast::DUMMY_NODE_ID); let obligation = Obligation::new(obligation_cause, @@ -167,7 +167,7 @@ pub struct TraitSelectionCache<'tcx> { } impl<'tcx> DepTrackingMapConfig for TraitSelectionCache<'tcx> { - type Key = ty::PolyTraitRef<'tcx>; + type Key = (ty::ParamEnv<'tcx>, ty::PolyTraitRef<'tcx>); type Value = Vtable<'tcx, ()>; fn to_dep_kind() -> DepKind { DepKind::TraitSelect From c900abf42df64d1724d2a435b9ad5351ecbc3081 Mon Sep 17 00:00:00 2001 From: Douglas Campos Date: Wed, 20 Sep 2017 22:51:35 -0400 Subject: [PATCH 2/5] expose ParamEnv as a param --- src/librustc/traits/trans/mod.rs | 4 ++-- src/librustc_trans/monomorphize.rs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/librustc/traits/trans/mod.rs b/src/librustc/traits/trans/mod.rs index 3bc8a65df1c14..06001ecb11b06 100644 --- a/src/librustc/traits/trans/mod.rs +++ b/src/librustc/traits/trans/mod.rs @@ -19,7 +19,7 @@ use std::cell::RefCell; use std::marker::PhantomData; use syntax::ast; use syntax_pos::Span; -use traits::{FulfillmentContext, Obligation, ObligationCause, Reveal, SelectionContext, Vtable}; +use traits::{FulfillmentContext, Obligation, ObligationCause, SelectionContext, Vtable}; use ty::{self, Ty, TyCtxt}; use ty::subst::{Subst, Substs}; use ty::fold::{TypeFoldable, TypeFolder}; @@ -33,12 +33,12 @@ impl<'a, 'tcx> TyCtxt<'a, 'tcx, 'tcx> { /// obligations *could be* resolved if we wanted to. pub fn trans_fulfill_obligation(self, span: Span, + param_env: ty::ParamEnv<'tcx>, trait_ref: ty::PolyTraitRef<'tcx>) -> Vtable<'tcx, ()> { // Remove any references to regions; this helps improve caching. let trait_ref = self.erase_regions(&trait_ref); - let param_env = ty::ParamEnv::empty(Reveal::All); self.trans_trait_caches.trait_cache.memoize((param_env, trait_ref), || { debug!("trans::fulfill_obligation(trait_ref={:?}, def_id={:?})", diff --git a/src/librustc_trans/monomorphize.rs b/src/librustc_trans/monomorphize.rs index 2be7a81b1cd49..8ca843ac5bb82 100644 --- a/src/librustc_trans/monomorphize.rs +++ b/src/librustc_trans/monomorphize.rs @@ -112,7 +112,7 @@ fn resolve_associated_item<'a, 'tcx>( def_id, trait_id, rcvr_substs); let trait_ref = ty::TraitRef::from_method(tcx, trait_id, rcvr_substs); - let vtbl = tcx.trans_fulfill_obligation(DUMMY_SP, ty::Binder(trait_ref)); + let vtbl = tcx.trans_fulfill_obligation(DUMMY_SP, ty::ParamEnv::empty(traits::Reveal::All), ty::Binder(trait_ref)); // Now that we know which impl is being used, we can dispatch to // the actual function: @@ -226,7 +226,7 @@ pub fn custom_coerce_unsize_info<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, substs: tcx.mk_substs_trait(source_ty, &[target_ty]) }); - match tcx.trans_fulfill_obligation(DUMMY_SP, trait_ref) { + match tcx.trans_fulfill_obligation(DUMMY_SP, ty::ParamEnv::empty(traits::Reveal::All), trait_ref) { traits::VtableImpl(traits::VtableImplData { impl_def_id, .. }) => { tcx.coerce_unsized_info(impl_def_id).custom_kind.unwrap() } From 119882eaa59cfabe2ab62f74ec7c76f7e9b95cb1 Mon Sep 17 00:00:00 2001 From: Douglas Campos Date: Thu, 21 Sep 2017 11:19:52 -0400 Subject: [PATCH 3/5] add comment per @nikomatsakis request --- src/librustc/traits/trans/mod.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/librustc/traits/trans/mod.rs b/src/librustc/traits/trans/mod.rs index 06001ecb11b06..947e7117c4ea2 100644 --- a/src/librustc/traits/trans/mod.rs +++ b/src/librustc/traits/trans/mod.rs @@ -31,6 +31,7 @@ impl<'a, 'tcx> TyCtxt<'a, 'tcx, 'tcx> { /// (necessarily) resolve all nested obligations on the impl. Note /// that type check should guarantee to us that all nested /// obligations *could be* resolved if we wanted to. + /// Assumes that this is run after the entire crate has been successfully type-checked. pub fn trans_fulfill_obligation(self, span: Span, param_env: ty::ParamEnv<'tcx>, From 043d873b322ff2b5acfe221e756ad090f71879b9 Mon Sep 17 00:00:00 2001 From: Douglas Campos Date: Thu, 21 Sep 2017 11:53:37 -0400 Subject: [PATCH 4/5] fix tidy errors --- src/librustc_trans/monomorphize.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/librustc_trans/monomorphize.rs b/src/librustc_trans/monomorphize.rs index 8ca843ac5bb82..62ccd55b483ca 100644 --- a/src/librustc_trans/monomorphize.rs +++ b/src/librustc_trans/monomorphize.rs @@ -112,7 +112,8 @@ fn resolve_associated_item<'a, 'tcx>( def_id, trait_id, rcvr_substs); let trait_ref = ty::TraitRef::from_method(tcx, trait_id, rcvr_substs); - let vtbl = tcx.trans_fulfill_obligation(DUMMY_SP, ty::ParamEnv::empty(traits::Reveal::All), ty::Binder(trait_ref)); + let vtbl = tcx.trans_fulfill_obligation( + DUMMY_SP, ty::ParamEnv::empty(traits::Reveal::All), ty::Binder(trait_ref)); // Now that we know which impl is being used, we can dispatch to // the actual function: @@ -226,7 +227,8 @@ pub fn custom_coerce_unsize_info<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, substs: tcx.mk_substs_trait(source_ty, &[target_ty]) }); - match tcx.trans_fulfill_obligation(DUMMY_SP, ty::ParamEnv::empty(traits::Reveal::All), trait_ref) { + match tcx.trans_fulfill_obligation( + DUMMY_SP, ty::ParamEnv::empty(traits::Reveal::All), trait_ref) { traits::VtableImpl(traits::VtableImplData { impl_def_id, .. }) => { tcx.coerce_unsized_info(impl_def_id).custom_kind.unwrap() } From 9d52cb2f84fe3e3c1a4a1945de8116d60290b05b Mon Sep 17 00:00:00 2001 From: Douglas Campos Date: Mon, 25 Sep 2017 09:49:32 -0400 Subject: [PATCH 5/5] those changes break miri, PR will be issued later --- src/tools/toolstate.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tools/toolstate.toml b/src/tools/toolstate.toml index 707b316190d65..3cc815ef34edd 100644 --- a/src/tools/toolstate.toml +++ b/src/tools/toolstate.toml @@ -23,7 +23,7 @@ # Each tool has a list of people to ping # ping @oli-obk @RalfJung @eddyb -miri = "Testing" +miri = "Broken" # ping @Manishearth @llogiq @mcarton @oli-obk clippy = "Broken"