Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upTurn `trans_fulfill_obligation` into a query #44967
Conversation
rust-highfive
assigned
nikomatsakis
Oct 2, 2017
This comment has been minimized.
This comment has been minimized.
|
(rust_highfive has picked a reviewer for you, use r? to override) |
wesleywiser
reviewed
Oct 2, 2017
| /// Assumes that this is run after the entire crate has been successfully type-checked. | ||
| pub fn trans_fulfill_obligation<'a, 'tcx>(ty: TyCtxt<'a, 'tcx, 'tcx>, | ||
| (def_id, param_env, trait_ref): | ||
| (DefId, ty::ParamEnv<'tcx>, ty::PolyTraitRef<'tcx>)) |
This comment has been minimized.
This comment has been minimized.
wesleywiser
Oct 2, 2017
Author
Member
I changed this to take a DefId instead of a Span because it looked like all of the other queries used DefId and not Spans. However, there were two places where DUMMY_SP was passed in. I changed those to use DefIds that seemed appropriate but I'm not sure. I'll indicate those below.
If that wasn't the right thing to do, I can revert it.
This comment has been minimized.
This comment has been minimized.
michaelwoerister
Oct 2, 2017
Contributor
Hm, @nikomatsakis would know more about how the span here is actually used.
| @@ -113,7 +111,7 @@ fn resolve_associated_item<'a, 'tcx>( | |||
|
|
|||
| 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)); | |||
| (trait_id, ty::ParamEnv::empty(traits::Reveal::All), ty::Binder(trait_ref))); | |||
This comment has been minimized.
This comment has been minimized.
| substs: tcx.mk_substs_trait(source_ty, &[target_ty]) | ||
| }); | ||
|
|
||
| match tcx.trans_fulfill_obligation( | ||
| DUMMY_SP, ty::ParamEnv::empty(traits::Reveal::All), trait_ref) { | ||
| (def_id, ty::ParamEnv::empty(traits::Reveal::All), trait_ref)) { |
This comment has been minimized.
This comment has been minimized.
michaelwoerister
reviewed
Oct 2, 2017
| fn hash_stable<W: StableHasherResult>(&self, | ||
| hcx: &mut StableHashingContext<'gcx>, | ||
| hasher: &mut StableHasher<W>) { | ||
| use traits::Vtable::*; |
This comment has been minimized.
This comment has been minimized.
michaelwoerister
Oct 2, 2017
Contributor
The enum discriminant also needs to be hashed:
mem::discriminant(self).hash_stable(hcx, hasher);
michaelwoerister
reviewed
Oct 2, 2017
| fn hash_stable<W: StableHasherResult>(&self, | ||
| hcx: &mut StableHashingContext<'gcx>, | ||
| hasher: &mut StableHasher<W>) { | ||
| self.impl_def_id.hash_stable(hcx, hasher); |
This comment has been minimized.
This comment has been minimized.
michaelwoerister
Oct 2, 2017
•
Contributor
So what we usually do here is use an exhaustive destructuring let statement, so in case a field gets added or removed, we don't miss updating the HashStable implementation:
let traits::VtableImplData {
impl_def_id,
substs,
ref nested,
} = *self;
impl_def_id.hash_stable(hcx, hasher);
substs.hash_stable(hcx, hasher);
nested.hash_stable(hcx, hasher);That means a bit more typing but has proven to be very useful in catching oversights.
This comment has been minimized.
This comment has been minimized.
|
Very nice, thank you, @wesleywiser! Please update the I'll let @nikomatsakis do the rest of the review since trait selection is his field. |
This comment has been minimized.
This comment has been minimized.
|
r? @arielb1 I think you should just not pass the span/defid. It's just used for error reporting, and passing the span around as the query key will prevent all caching. |
arielb1
assigned
arielb1
and unassigned
nikomatsakis
Oct 2, 2017
carols10cents
added
the
S-waiting-on-review
label
Oct 2, 2017
This comment has been minimized.
This comment has been minimized.
|
I agree with @arielb1 -- the query key should just be |
nikomatsakis
reviewed
Oct 3, 2017
|
|
||
| let span = ty.def_span(def_id); | ||
|
|
||
| let obligation_cause = ObligationCause::misc(span, |
This comment has been minimized.
This comment has been minimized.
nikomatsakis
reviewed
Oct 3, 2017
| debug!("Encountered ambiguity selecting `{:?}` during trans, \ | ||
| presuming due to overflow", | ||
| trait_ref); | ||
| ty.sess.span_fatal(span, |
This comment has been minimized.
This comment has been minimized.
nikomatsakis
Oct 3, 2017
•
Contributor
I actually think this case .. hmm .. maybe cannot occur? That is, @arielb1, would that code you added that causes compilation to abort when types get too large perhaps kick in first?
This comment has been minimized.
This comment has been minimized.
|
|
wesleywiser
reviewed
Oct 4, 2017
| (selection ambiguity)"); | ||
| } | ||
| Err(e) => { | ||
| span_bug!(span, "Encountered error `{:?}` selecting `{:?}` during trans", |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
arielb1
Oct 4, 2017
•
Contributor
Just do a bug! I think. I think for better error reporting we should just dump the query stack during each ICE.
wesleywiser
force-pushed the
wesleywiser:trans_fulfill_obligation
branch
2 times, most recently
from
dbddd4e
to
a9862b0
Oct 6, 2017
This comment has been minimized.
This comment has been minimized.
|
I believe I've resolved all of the review feedback. |
theotherjimmy
reviewed
Oct 8, 2017
| @@ -765,6 +765,7 @@ pub fn force_from_dep_node<'a, 'gcx, 'lcx>(tcx: TyCtxt<'a, 'gcx, 'lcx>, | |||
| DepKind::SpecializationGraph => { force!(specialization_graph_of, def_id!()); } | |||
| DepKind::ObjectSafety => { force!(is_object_safe, def_id!()); } | |||
| DepKind::TraitImpls => { force!(trait_impls_of, def_id!()); } | |||
| DepKind::FulfillObligation => { force!(item_body_nested_bodies, def_id!()); } | |||
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
wesleywiser
Oct 8, 2017
Author
Member
Fixed by making it a bug. I don't know how we'd recreate the query key so that seems appropriate to me, but I'm not 100% sure.
wesleywiser
force-pushed the
wesleywiser:trans_fulfill_obligation
branch
from
a9862b0
to
31f4b57
Oct 8, 2017
nikomatsakis
approved these changes
Oct 9, 2017
|
So this looks right to me. The only question in my mind is if the one case -- which used to be a |
This comment has been minimized.
This comment has been minimized.
|
@bors r+ |
This comment has been minimized.
This comment has been minimized.
|
|
nikomatsakis
assigned
nikomatsakis
and unassigned
arielb1
Oct 9, 2017
This comment has been minimized.
This comment has been minimized.
bors
added a commit
that referenced
this pull request
Oct 10, 2017
This comment has been minimized.
This comment has been minimized.
|
|
This comment has been minimized.
This comment has been minimized.
|
Android builder failed. Seems related to some kind of network issue?
|
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
bors
added a commit
that referenced
this pull request
Oct 11, 2017
This comment has been minimized.
This comment has been minimized.
|
|
This comment has been minimized.
This comment has been minimized.
|
Not sure what this means:
|
This comment has been minimized.
This comment has been minimized.
|
@bors retry LLDB segfault. |
This comment has been minimized.
This comment has been minimized.
bors
added a commit
that referenced
this pull request
Oct 12, 2017
This comment has been minimized.
This comment has been minimized.
|
|
wesleywiser commentedOct 2, 2017
Part of #44891