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

Fix ICE from #33364 by selectively skipping confirmation pass. #34573

Closed
wants to merge 4 commits into from

Conversation

Projects
None yet
8 participants
@pnkfelix
Copy link
Member

pnkfelix commented Jun 30, 2016

Fix #33364: during trans, confirmation should never fail (because type check has already admitted the source code).

So skip confirmation in that context, unless there is some reason (i.e. unresolved unification variables, or a type undering a Binder for region variables) during projection of an associated item) that we still need to run it.

@rust-highfive

This comment has been minimized.

Copy link
Collaborator

rust-highfive commented Jun 30, 2016

r? @nikomatsakis

(rust_highfive has picked a reviewer for you, use r? to override)

@pnkfelix

This comment has been minimized.

Copy link
Member Author

pnkfelix commented Jun 30, 2016

Oh I need to add the regression test too.

pnkfelix added some commits Jun 29, 2016

Fix ICE in issue #33364. Also, avoid redundant confirmation work in t…
…rans.

The main idea here is that if there are no unification problems to
solve, then trans does not need to do any confirmation of the impls
that it selects for a trait, nor the associated items it projects for
a trait.

(In principle the above mentioned ICE should instead be solved in the
long term via lazy normalization. But for now this is a simpler
solution and a good idea in any case.)
@brson

This comment has been minimized.

Copy link
Contributor

brson commented Jun 30, 2016

Thanks @pnkfelix ! cc @rust-lang/compiler This regression fix needs to land before monday/tuesday to get into 1.10.

@brson brson added the T-compiler label Jun 30, 2016

if selcx.projection_mode().is_any() {
// Issue #33364: `ProjectionMode::Any` means trans, during
// which there is no (good) reason for confirmation to fail
// (because type check has already admitted the source code).

This comment has been minimized.

@eddyb

eddyb Jun 30, 2016

Member

That's not necessarily true if anything does probing (such as checking if a vtable needs to contain a specific method, based on where clauses of that method).

This comment has been minimized.

@pnkfelix

pnkfelix Jul 1, 2016

Author Member

@eddyb Wait so are you saying it is not actually sound for me to skip the confirms via the logic I have put here?

Or ... are you "merely" saying that the comment as written here is misleading?

This comment has been minimized.

@eddyb

eddyb Jul 1, 2016

Member

I'm not sure in which situations this may backfire, but for example, vtable building in trans probes for obligations on methods to decide whether to include them. There are also secondary probes related to specialization, during selection.

@arielb1

This comment has been minimized.

Copy link
Contributor

arielb1 commented Jun 30, 2016

#33364 is a regression from 1.8 to 1.9 - it already hit stable.

@arielb1 arielb1 removed the beta-nominated label Jul 2, 2016

@arielb1

This comment has been minimized.

Copy link
Contributor

arielb1 commented Jul 2, 2016

De-beta-nominating since not a relevant regression.

@@ -1247,6 +1247,34 @@ fn confirm_callable_candidate<'cx, 'gcx, 'tcx>(
fn_sig,
flag);

if selcx.projection_mode().is_any() {

This comment has been minimized.

@nikomatsakis

nikomatsakis Jul 7, 2016

Contributor

Hmm. This is somehow hackier than I had imagined. What I had hoped was that we would attach a (generic) filter function to the FulfillmentContext -- when not in trans, this filter function would accept all work, but within trans, it could be more selective.

EDIT: Not that it wouldn't necessarily always be more selective.

This comment has been minimized.

@eddyb

eddyb Jul 7, 2016

Member

I actually told @pnkfelix about ProjectionMode::Any, he had some finer-grained flag initially.

I'm not sure I understand what situations this hack can produce invalid results in.
Remember that trans doesn't just look for things that are guaranteed to succeed, but also has to be able to correctly tell if something would succeed (for various reasons pointed out in a comment above).

This comment has been minimized.

@nikomatsakis

nikomatsakis Jul 7, 2016

Contributor

@eddyb

Remember that trans doesn't just look for things that are guaranteed to succeed, but also has to be able to correctly tell if something would succeed (for various reasons pointed out in a comment above).

Sometimes yes. It depends on context. This is why I was imagining a filter that the context can provide. =)

Certainly the majority of cases though trans is doing a lot more work than it ought to, just re-resolving things that it knows will pass (and which sometimes yield ICEs when they stumble over other bugs, as in this case).

This comment has been minimized.

@pnkfelix

pnkfelix Jul 13, 2016

Author Member

I'd like to try to make more progress on this, but I also want to make sure I understand the conversation here.

In particular, @nikomatsakis, when you wrote above that you expected a filter to be attached to the FulfillmentContext, did you mean that, or did you mean SelectionContext?

(I ask because I can at least see how a SelectionContext would connect up to the code as written, but attaching it to the FulfillmentContext seems like ... its leaving out details about how that filter would actually prevent this particular confirmation while not messing things up elsewhere. I have no intuition right now as to where the filter fundamentally belongs)

This comment has been minimized.

@pnkfelix

pnkfelix Oct 13, 2016

Author Member

(for those following along this thread, niko left a comment below saying "I meant FulfillmentContext, but I may be incorrect.")

@alexcrichton

This comment has been minimized.

Copy link
Member

alexcrichton commented Jul 14, 2016

triage: beta-nominated

We'll probably want to backport this to ensure the ICE fix gets out soon, even though it's ICE'ing on stable as well. (so long as the compiler team approves of the backport, of course)

@nikomatsakis

This comment has been minimized.

Copy link
Contributor

nikomatsakis commented Jul 20, 2016

@pnkfelix well, I meant FulfillmentContext, but I may be incorrect.

@nikomatsakis

This comment has been minimized.

Copy link
Contributor

nikomatsakis commented Jul 26, 2016

OK, so, I dug a bit more into the approach that I had been advocating for @pnkfelix. I still think that adding a predicate to the FulfillmentContext is a good idea for optimization purposes, but unfortunately it alone was never enough to work around the ICE -- and the other change, which required separating out the OutputTypeParameterMismatch code so that it could be filtered, leads to a complication in projection (where projection succeeds where it ought to fail). I think @pnkfelix tried to talk to me about this while I was on vacation but I did not understand. It seems plausible that we could work around it, but this is a lot of work for what is ultimately a work-around, so I am warming up to a hacky change like the one that @pnkfelix wound up taking on this PR.

@bors

This comment has been minimized.

Copy link
Contributor

bors commented Aug 17, 2016

☔️ The latest upstream changes (presumably #35605) made this pull request unmergeable. Please resolve the merge conflicts.

@nikomatsakis

This comment has been minimized.

Copy link
Contributor

nikomatsakis commented Aug 17, 2016

Sorry I've been slow here. I still feel uncomfortable with trying to decide the right fix.

@nikomatsakis

This comment has been minimized.

Copy link
Contributor

nikomatsakis commented Oct 17, 2016

@pnkfelix and I talked the other day. We want to take a shot at pursuing a somewhat more principled fix here, but this kind of hack is still a possibility. =) Going to close this PR in any case for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.