Skip to content

use param_env on the trait_cache key #44741

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

Merged
merged 5 commits into from
Sep 26, 2017
Merged
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
11 changes: 6 additions & 5 deletions src/librustc/traits/trans/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand All @@ -31,24 +31,25 @@ 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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Can we extend this comment to say "/// Assumes that this is run after the entire crate has been successfully type-checked."

/// 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>,
trait_ref: ty::PolyTraitRef<'tcx>)
-> Vtable<'tcx, ()>
{
// Remove any references to regions; this helps improve caching.
let trait_ref = self.erase_regions(&trait_ref);

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,
Expand Down Expand Up @@ -167,7 +168,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
Expand Down
6 changes: 4 additions & 2 deletions src/librustc_trans/monomorphize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::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:
Expand Down Expand Up @@ -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, 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()
}
Expand Down
2 changes: 1 addition & 1 deletion src/tools/toolstate.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"