-
Notifications
You must be signed in to change notification settings - Fork 13.9k
Always make tuple elements a coercion site #147834
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
base: master
Are you sure you want to change the base?
Conversation
|
|
|
|
||
| /// Returns a list of tuple type arguments, or `None` if `self` isn't a tuple. | ||
| #[inline] | ||
| pub fn tuple(self) -> Option<&'tcx List<Ty<'tcx>>> { |
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.
| pub fn tuple(self) -> Option<&'tcx List<Ty<'tcx>>> { | |
| pub fn opt_tuple_fields(self) -> Option<&'tcx List<Ty<'tcx>>> { |
seems like it does the same thing as tuple_fields it just doesnt panic
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.
That is indeed the case, is there a problem with that? In the code I wrote I found this a lot more convenient than checking the type first.
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.
no it's fine I just found the differences in the names doesn't really reflect the differences in behaviour
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.
If you have a better idea for the names I can rename them
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.
i suggested a different name already :P
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.
🤦🏻
I swear I sleep at night sometimes
tests/ui/tuple/coercion.rs
Outdated
| // This one can't work without a redesign on the coercion system. | ||
| // We currently only eagerly add never-to-any coercions, not any others. | ||
| // Thus, because we don't have an expectation when typechecking `&[]`, | ||
| // we don't add a coercion => this doesn't work. | ||
| let y = (&[],); | ||
| let _: (&[u8],) = y; //~ error: mismatched types |
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.
can you split the failing cases out to a different test so that the working stuff can be marked // @check-pass . It's also nice because this change probably needs an FCP because we start allowing more code to compile so having a simple "this is the test that now passes" is nice
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.
I've split the tests
|
@bors try @rust-timer queue should crater this as it is theoretically breaking, though I don't actually expect any breakage here 🤔 |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Always make tuple elements a coercion site
|
When we stabilize the never type do we intend to change how NeverToAny coercions work? Will we continue unconditionally coercing |
This comment has been minimized.
This comment has been minimized.
|
Finished benchmarking commit (f77b5bc): comparison URL. Overall result: ❌✅ regressions and improvements - please read the text belowBenchmarking this pull request means it may be perf-sensitive – we'll automatically label it not fit for rolling up. You can override this, but we strongly advise not to, due to possible changes in compiler perf. Next Steps: If you can justify the regressions found in this try perf run, please do so in sufficient writing along with @bors rollup=never Instruction countOur most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.
Max RSS (memory usage)Results (primary 1.4%, secondary -1.2%)A less reliable metric. May be of interest, but not used to determine the overall result above.
CyclesResults (primary -2.1%, secondary -3.8%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Binary sizeThis benchmark run did not return any relevant results for this metric. Bootstrap: 473.373s -> 475.58s (0.47%) |
|
@craterbot check |
|
👌 Experiment ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more |
I don't expect / haven't heard of any desire to make any changes with how we insert NeverToAny coercions. |
f43cd30 to
5e6e9dc
Compare
5e6e9dc to
74c8722
Compare
|
This PR was rebased onto a different master commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
|
🚧 Experiment ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more |
|
🎉 Experiment
Footnotes
|
|
👌 Experiment ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more |
|
🚧 Experiment ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more |
|
🎉 Experiment
Footnotes
|
|
Hi @rust-lang/types. Element expressions of tuples are currently coercion sites. The compiler currently assumes that when type checking tuple element exprs, if we have no expectation for what the type should be, that we don't need to try coercing to anything. For example: fn foo() {
// compiles on stable, `a` has type `(!, ())`
let a = (loop {}, ());
}Here we have a tuple expr with no expectation for its type as the This can cause code to fail to compile that should compile: fn foo() {
// fails on stable
let a = (loop {}, ());
let a: (u8, ()) = a; // `(u8, ())` and `(!, ())` are different types
}This is inconsistent with every other coercion site where coercions are unconditionally performed, for example array exprs: // compiles on stable
fn foo() {
let a = [loop {}];
let a: [u8; 1] = a;
}This PR causes us to start coercing tuple element exprs even when there is no expectation, so the previous code example now compiles: fn foo() {
// compiles on this PR
let a = (loop {}, ()); // coerces to `(?x, ())`
let a: (u8, ()) = a;
}This is theoretically breaking as is any change where we change the results of type inference. It may also be breaking due to introducing more NeverToAny coercions which in older editions could cause fallback to There was only one case of breakage actually found by crater. I've looked at it for not too long and couldn't see what the problem was. It occurs in macro code and the breakage went away after hand-expanding macros, I therefore assume this is the second case where fallback is now occuring in an older edition crate causing an I think the theoretical breakage here is fine as the change in this PR is a clear bug fix in the current implementation of never type coercions. The actual breakage found by crater also seems somewhat fine to me (1 crate is not that many), though I would like to properly understand the breakage and open a PR fixing the crate before actually landing this. @rfcbot fcp merge |
|
Team member @BoxyUwU has proposed to merge this. The next step is review by the rest of the tagged team members: Concerns:
Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up! See this document for info about what commands tagged team members can give me. |
|
@rfcbot concern investigate and migrate broken crate |
Previously we only used
check_expr_coercible_to_typeif we had an expectation (usingcheck_expr_with_expectation(NoExpectation)otherwise). Normally that'd be fine, because without an expectation we can't insert a coercion anyway. However, for the case of never-to-any coercion specifically, we do insert it eagerly, so this prevents some code from compiling, for example:With this PR we are always using
check_expr_coercible_to_type(using an infer var if there is no expectation), which allows slightly more code to compile.Fixes #112856
r? BoxyUwU