Skip to content

Ban registering obligations during InferCtxt snapshots. - #41325

Merged
bors merged 6 commits into
rust-lang:masterfrom
eddyb:isolate-snapshots-for-good
Apr 19, 2017
Merged

Ban registering obligations during InferCtxt snapshots.#41325
bors merged 6 commits into
rust-lang:masterfrom
eddyb:isolate-snapshots-for-good

Conversation

@eddyb

Copy link
Copy Markdown
Contributor

Back in #33852, a flag was added to InferCtxt to prevent rolling back a snapshot if obligations were added to some FulfillmentContext during the snapshot, to prevent leaking fresh inference variables (created during that snapshot, so their indices would get reused) in obligations, which could ICE or worse.

But that isn't enough in the long run, as type-checking ends up relying on success implying that eager side-effects are fine, and while stray obligations do get caught nowadays, those errors prevent, e.g. the speculative coercions from #37658, which have to be rolled back even if they succeed.

We can't just allow those obligations to stay around though, because we end up, again, in ICEs or worse.
Instead, this PR modifies lookup_method_in_trait_adjusted to return InferOk containing the obligations that Autoderef::finalize_as_infer_ok can propagate to deref coercions.

As there shouldn't be anything left that registers obligations during snapshots, it's completely banned.

r? @nikomatsakis@arielb1

@eddybeddyb added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Apr 15, 2017
// register obligations, within a snapshot. Very useful, much
// better than grovelling through megabytes of RUST_LOG output.
//
// HOWEVER, in some cases the flag is wrong. In particular, we

@arielb1arielb1Apr 15, 2017

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Maybe it's better to have a within_snapshot boolean on FulfillmentCx that disables the check?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Yeah it's not super clear what the best option is. It's probably a good idea to tie fulfillment contexts to inference contexts (through lifetimes?) and maybe have a snapshot depth... or maybe an "epoch"?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Longer term, I have been hoping to just get rid of the notion of snapshots except for very short-term (e.g., to make a unification operation atomic) and then create nested fulfillment contexts for "probing sessions".

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Well, maybe that's not a complete answer. Still, I guess I hope that we can move things into nested contexts and generally remove the need for snapshots.

@GuillaumeGomezGuillaumeGomez mentioned this pull request Apr 15, 2017
@eddyb

eddyb commented Apr 16, 2017

Copy link
Copy Markdown
ContributorAuthor

Crater run has found one root regression.

EDIT: reproduced it (looks like obligations need to be selected eagerly for binops - Travis failure is similar):

fnmain(){letmut s = String::new();
s += {&String::new()};// ^^^^^^^^^^^^^^ expected str, found struct `std::string::String`// note: expected type `&str`// found type `&std::string::String`}

EDIT2: pushed a fix.

@nikomatsakisnikomatsakis left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks good to me, do we want to do a crater run or anything like that? I could imagine some subtle effects (as evidenced by the last commit).

@nikomatsakis

Copy link
Copy Markdown
Contributor

Ah, I see @eddyb is ahead of me here. Very good.

@nikomatsakis

Copy link
Copy Markdown
Contributor

@bors r+

@bors

bors commented Apr 17, 2017

Copy link
Copy Markdown
Collaborator

📌 Commit cd64ff9 has been approved by nikomatsakis

@nikomatsakis

Copy link
Copy Markdown
Contributor

@bors r-

@nikomatsakis

Copy link
Copy Markdown
Contributor

Actually, @arielb1, were you satisfied? (If so, feel free to r=me, or you :)

@eddybeddyb mentioned this pull request Apr 18, 2017
@arielb1

Copy link
Copy Markdown
Contributor

@bors r+

@bors

bors commented Apr 18, 2017

Copy link
Copy Markdown
Collaborator

📌 Commit cd64ff9 has been approved by arielb1

frewsxcv added a commit to frewsxcv/rust that referenced this pull request Apr 18, 2017
…=arielb1
Ban registering obligations during InferCtxt snapshots.
Back in rust-lang#33852, a flag was added to `InferCtxt` to prevent rolling back a snapshot if obligations were added to some `FulfillmentContext` during the snapshot, to prevent leaking fresh inference variables (created during that snapshot, so their indices would get reused) in obligations, which could ICE or worse.
But that isn't enough in the long run, as type-checking ends up relying on success implying that eager side-effects are fine, and while stray obligations *do* get caught nowadays, those errors prevent, e.g. the speculative coercions from rust-lang#37658, which *have to* be rolled back *even* if they succeed.
We can't just allow those obligations to stay around though, because we end up, again, in ICEs or worse.
Instead, this PR modifies `lookup_method_in_trait_adjusted` to return `InferOk` containing the obligations that `Autoderef::finalize_as_infer_ok` can propagate to deref coercions.
As there shouldn't be *anything* left that registers obligations during snapshots, it's completely banned.
r? @nikomatsakis@arielb1
@frewsxcvfrewsxcv mentioned this pull request Apr 18, 2017
frewsxcv added a commit to frewsxcv/rust that referenced this pull request Apr 18, 2017
…=arielb1
Ban registering obligations during InferCtxt snapshots.
Back in rust-lang#33852, a flag was added to `InferCtxt` to prevent rolling back a snapshot if obligations were added to some `FulfillmentContext` during the snapshot, to prevent leaking fresh inference variables (created during that snapshot, so their indices would get reused) in obligations, which could ICE or worse.
But that isn't enough in the long run, as type-checking ends up relying on success implying that eager side-effects are fine, and while stray obligations *do* get caught nowadays, those errors prevent, e.g. the speculative coercions from rust-lang#37658, which *have to* be rolled back *even* if they succeed.
We can't just allow those obligations to stay around though, because we end up, again, in ICEs or worse.
Instead, this PR modifies `lookup_method_in_trait_adjusted` to return `InferOk` containing the obligations that `Autoderef::finalize_as_infer_ok` can propagate to deref coercions.
As there shouldn't be *anything* left that registers obligations during snapshots, it's completely banned.
r? @nikomatsakis@arielb1
@frewsxcvfrewsxcv mentioned this pull request Apr 18, 2017
frewsxcv added a commit to frewsxcv/rust that referenced this pull request Apr 18, 2017
…=arielb1
Ban registering obligations during InferCtxt snapshots.
Back in rust-lang#33852, a flag was added to `InferCtxt` to prevent rolling back a snapshot if obligations were added to some `FulfillmentContext` during the snapshot, to prevent leaking fresh inference variables (created during that snapshot, so their indices would get reused) in obligations, which could ICE or worse.
But that isn't enough in the long run, as type-checking ends up relying on success implying that eager side-effects are fine, and while stray obligations *do* get caught nowadays, those errors prevent, e.g. the speculative coercions from rust-lang#37658, which *have to* be rolled back *even* if they succeed.
We can't just allow those obligations to stay around though, because we end up, again, in ICEs or worse.
Instead, this PR modifies `lookup_method_in_trait_adjusted` to return `InferOk` containing the obligations that `Autoderef::finalize_as_infer_ok` can propagate to deref coercions.
As there shouldn't be *anything* left that registers obligations during snapshots, it's completely banned.
r? @nikomatsakis@arielb1
@frewsxcvfrewsxcv mentioned this pull request Apr 18, 2017
frewsxcv added a commit to frewsxcv/rust that referenced this pull request Apr 18, 2017
…=arielb1
Ban registering obligations during InferCtxt snapshots.
Back in rust-lang#33852, a flag was added to `InferCtxt` to prevent rolling back a snapshot if obligations were added to some `FulfillmentContext` during the snapshot, to prevent leaking fresh inference variables (created during that snapshot, so their indices would get reused) in obligations, which could ICE or worse.
But that isn't enough in the long run, as type-checking ends up relying on success implying that eager side-effects are fine, and while stray obligations *do* get caught nowadays, those errors prevent, e.g. the speculative coercions from rust-lang#37658, which *have to* be rolled back *even* if they succeed.
We can't just allow those obligations to stay around though, because we end up, again, in ICEs or worse.
Instead, this PR modifies `lookup_method_in_trait_adjusted` to return `InferOk` containing the obligations that `Autoderef::finalize_as_infer_ok` can propagate to deref coercions.
As there shouldn't be *anything* left that registers obligations during snapshots, it's completely banned.
r? @nikomatsakis@arielb1
@frewsxcvfrewsxcv mentioned this pull request Apr 18, 2017
@frewsxcvfrewsxcv mentioned this pull request Apr 19, 2017
@bors

bors commented Apr 19, 2017

Copy link
Copy Markdown
Collaborator

⌛ Testing commit cd64ff9 with merge 467aaab...

bors added a commit that referenced this pull request Apr 19, 2017
Ban registering obligations during InferCtxt snapshots.
Back in #33852, a flag was added to `InferCtxt` to prevent rolling back a snapshot if obligations were added to some `FulfillmentContext` during the snapshot, to prevent leaking fresh inference variables (created during that snapshot, so their indices would get reused) in obligations, which could ICE or worse.
But that isn't enough in the long run, as type-checking ends up relying on success implying that eager side-effects are fine, and while stray obligations *do* get caught nowadays, those errors prevent, e.g. the speculative coercions from #37658, which *have to* be rolled back *even* if they succeed.
We can't just allow those obligations to stay around though, because we end up, again, in ICEs or worse.
Instead, this PR modifies `lookup_method_in_trait_adjusted` to return `InferOk` containing the obligations that `Autoderef::finalize_as_infer_ok` can propagate to deref coercions.
As there shouldn't be *anything* left that registers obligations during snapshots, it's completely banned.
r? @nikomatsakis@arielb1
@bors

bors commented Apr 19, 2017

Copy link
Copy Markdown
Collaborator

☀️ Test successful - status-appveyor, status-travis
Approved by: arielb1
Pushing 467aaab to master...

@bors
bors merged commit cd64ff9 into rust-lang:masterApr 19, 2017
@eddyb
eddyb deleted the isolate-snapshots-for-good branch April 19, 2017 11:17
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-reviewStatus: Awaiting review from the assignee but also interested parties.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

@eddyb@nikomatsakis@bors@arielb1