-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Conversation
See the included comment for a detailed explanation of why this is sound.
(rust_highfive has picked a reviewer for you, use r? to override) |
Can I get a perf run? |
@bors try @rust-timer queue |
Awaiting bors try build completion |
⌛ Trying commit 32c360b with merge 1cdff26b98d4c2377ea6ae8929f1daebbf58f2b0... |
☀️ Try build successful - checks-azure |
Queued 1cdff26b98d4c2377ea6ae8929f1daebbf58f2b0 with parent 6d69cab, future comparison URL. |
Finished benchmarking try commit 1cdff26b98d4c2377ea6ae8929f1daebbf58f2b0, comparison URL. |
It looks like this resulted in I have absolutely no idea what's going on with |
r? @eddyb for review or re-assignment. |
Early exit looks fine to me (haven't read the comment):
r? @nikomatsakis for the final say |
// 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`). |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
@Aaron1011 any updates? |
I guess this is blocked on me. Sorry @Aaron1011. Let me glance over it again, but I think it's fine. |
@craterbot check Let's just do a "quick check"... |
👌 Experiment ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more |
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. |
OK, I think I'm inclined to r+ instead. The only question is whether to improve the wording of the comment. |
🚧 Experiment ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more |
🎉 Experiment
|
Welp I never did R+ -- but we see 2 regressions, interesting. |
Both spurious |
@bors r+ |
📌 Commit ff6e4ee has been approved by |
⌛ Testing commit ff6e4ee with merge c9613c332e62aa1b5350d49ee1d8a6693c0a227f... |
@bors retry yield |
@bors rollup=never |
☀️ Test successful - checks-actions, checks-azure |
See the included comment for a detailed explanation of why this is
sound.