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

[perf] Skip attempting to run coerce_unsized on an inference variable #69530

Merged
merged 2 commits into from
May 10, 2020

Conversation

Aaron1011
Copy link
Member

See the included comment for a detailed explanation of why this is
sound.

See the included comment for a detailed explanation of why this is
sound.
@rust-highfive
Copy link
Collaborator

r? @petrochenkov

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

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Feb 27, 2020
@Aaron1011
Copy link
Member Author

Can I get a perf run?

@jonas-schievink
Copy link
Contributor

@bors try @rust-timer queue

@rust-timer
Copy link
Collaborator

Awaiting bors try build completion

@bors
Copy link
Contributor

bors commented Feb 27, 2020

⌛ Trying commit 32c360b with merge 1cdff26b98d4c2377ea6ae8929f1daebbf58f2b0...

@bors
Copy link
Contributor

bors commented Feb 28, 2020

☀️ Try build successful - checks-azure
Build commit: 1cdff26b98d4c2377ea6ae8929f1daebbf58f2b0 (1cdff26b98d4c2377ea6ae8929f1daebbf58f2b0)

@rust-timer
Copy link
Collaborator

Queued 1cdff26b98d4c2377ea6ae8929f1daebbf58f2b0 with parent 6d69cab, future comparison URL.

@rust-timer
Copy link
Collaborator

Finished benchmarking try commit 1cdff26b98d4c2377ea6ae8929f1daebbf58f2b0, comparison URL.

@Aaron1011
Copy link
Member Author

Aaron1011 commented Feb 28, 2020

It looks like this resulted in clean/baseline-incremental improvements across several different benchmarks, in the range of 1-1.7%.

I have absolutely no idea what's going on with syn-opt (maybe related to #69060?)

@petrochenkov
Copy link
Contributor

r? @eddyb for review or re-assignment.

@rust-highfive rust-highfive assigned eddyb and unassigned petrochenkov Feb 28, 2020
@eddyb
Copy link
Member

eddyb commented Feb 28, 2020

syn-opt is indeed unreliable.

Early exit looks fine to me (haven't read the comment):

  • source: _: Trait is always ambiguous anyway
  • target: we can never coerce without knowing what we're coercing to (except maybe ! but that's not an unsizing coercion)

r? @nikomatsakis for the final say

@rust-highfive rust-highfive assigned nikomatsakis and unassigned eddyb Feb 28, 2020
// If either `source` or `target` is a type variable, then any applicable impl
// would need to be generic over the self-type (`impl<T> CoerceUnsized<SomeType> for T`)
// or generic over the `CoerceUnsized` type parameter (`impl<T> CoerceUnsized<T> for
// SomeType`).
Copy link
Contributor

Choose a reason for hiding this comment

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

This paragraph feels a bit misleading, although the conclusion is likely correct. In particular, if (say) the "source" type is an unbound inference variable, then it's not that the other, more narrow impls don't apply, right? It's more that any impl could apply, and hence we wind up with an ambiguous result?

That said, the trait selection code refuses to proceed (always yields ambiguous) if the source type is unknown, so this short-circuit here has no effect I imagine. I do feel like this could change behavior if the target type is unknown, since there may be at most one impl that could apply, though I feel like we probably don't want to be coercing then -- I sort of expect this coerce to only trigger if we are coercing to a "fat-pointer type", but I don't see any code that forces this to be the case.

In general, though, we don't try to coerce from cases where the source or target types are unknown anyhow, right? Well, I think that's true,but it doesn't seem to be enforced by any kind of "blanket check" in the coerce_to routine.

Copy link
Member Author

Choose a reason for hiding this comment

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

then it's not that the other, more narrow impls don't apply, right? It's more that any impl could apply, and hence we wind up with an ambiguous result?

When I was writing this, my concern was blanket impls - I wanted to be sure that we wouldn't bail out when we could have actually picked a blanket impl.

I do feel like this could change behavior if the target type is unknown, since there may be at most one impl that could apply

That's a good point. Since unsizing coercions happen fairly 'early' during typeck, it's possible that we might skip performing an unsizing coercion that turns out to be 'reasonable' (e.g. we later unify the target variable with the expected type).

In general, though, we don't try to coerce from cases where the source or target types are unknown anyhow, right?

I'm not quite sure what you mean.

Copy link
Contributor

Choose a reason for hiding this comment

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

The way I think of coercions, they trigger only when we know the source/target well enough to see that the coercion applies (otherwise we just unify). But I think that is not an 'obvious property' of the code as written.

@Dylan-DPC-zz Dylan-DPC-zz added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Mar 29, 2020
@Dylan-DPC-zz
Copy link

@Aaron1011 any updates?

@nikomatsakis
Copy link
Contributor

I guess this is blocked on me. Sorry @Aaron1011. Let me glance over it again, but I think it's fine.

@nikomatsakis
Copy link
Contributor

nikomatsakis commented Apr 20, 2020

@craterbot check

Let's just do a "quick check"...

@craterbot
Copy link
Collaborator

👌 Experiment pr-69530 created and queued.
🤖 Automatically detected try build 1cdff26b98d4c2377ea6ae8929f1daebbf58f2b0
🔍 You can check out the queue and this experiment's details.

ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more

@craterbot craterbot added S-waiting-on-crater Status: Waiting on a crater run to be completed. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Apr 20, 2020
@Mark-Simulacrum
Copy link
Member

FYI: Crater here won't be done for around a week and a half with current queue and since we're likely to schedule beta crater runs (which take up around a week's worth of time as well), probably closer to two to three weeks from now that this will be run through crater.

@nikomatsakis
Copy link
Contributor

OK, I think I'm inclined to r+ instead.

The only question is whether to improve the wording of the comment.

@craterbot
Copy link
Collaborator

🚧 Experiment pr-69530 is now running

ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more

@craterbot
Copy link
Collaborator

🎉 Experiment pr-69530 is completed!
📊 2 regressed and 5 fixed (99934 total)
📰 Open the full report.

⚠️ If you notice any spurious failure please add them to the blacklist!
ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more

@craterbot craterbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-crater Status: Waiting on a crater run to be completed. labels May 8, 2020
@nikomatsakis
Copy link
Contributor

Welp I never did R+ -- but we see 2 regressions, interesting.

@nikomatsakis
Copy link
Contributor

Both spurious

@nikomatsakis
Copy link
Contributor

@bors r+

@bors
Copy link
Contributor

bors commented May 8, 2020

📌 Commit ff6e4ee has been approved by nikomatsakis

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels May 8, 2020
@bors
Copy link
Contributor

bors commented May 8, 2020

⌛ Testing commit ff6e4ee with merge c9613c332e62aa1b5350d49ee1d8a6693c0a227f...

@Dylan-DPC-zz
Copy link

@bors retry yield

@RalfJung
Copy link
Member

RalfJung commented May 9, 2020

@bors rollup=never
(PR title suggests perf impact)

@bors
Copy link
Contributor

bors commented May 9, 2020

⌛ Testing commit ff6e4ee with merge 0a3619c...

@bors
Copy link
Contributor

bors commented May 10, 2020

☀️ Test successful - checks-actions, checks-azure
Approved by: nikomatsakis
Pushing 0a3619c to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label May 10, 2020
@bors bors merged commit 0a3619c into rust-lang:master May 10, 2020
@Aaron1011 Aaron1011 deleted the perf/skip-coerce-var branch May 10, 2020 19:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merged-by-bors This PR was explicitly merged by bors. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.