-
Notifications
You must be signed in to change notification settings - Fork 13.9k
Add NonNull pattern types #142339
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
Add NonNull pattern types #142339
Conversation
|
Some changes occurred to the CTFE machinery changes to the core type system Some changes occurred in src/tools/clippy cc @rust-lang/clippy HIR ty lowering was modified cc @fmease Some changes occurred in compiler/rustc_codegen_cranelift cc @bjorn3 Some changes occurred to MIR optimizations cc @rust-lang/wg-mir-opt Some changes occurred to the CTFE / Miri interpreter cc @rust-lang/miri The Miri subtree was changed cc @rust-lang/miri Some changes occurred in src/tools/rustfmt cc @rust-lang/rustfmt changes to the core type system Some changes occurred in compiler/rustc_codegen_ssa |
This comment has been minimized.
This comment has been minimized.
02f19f4 to
57dc73a
Compare
This comment has been minimized.
This comment has been minimized.
57dc73a to
0adc902
Compare
This comment has been minimized.
This comment has been minimized.
0adc902 to
9944787
Compare
This comment has been minimized.
This comment has been minimized.
9944787 to
8c271d9
Compare
compiler/rustc_trait_selection/src/traits/select/confirmation.rs
Outdated
Show resolved
Hide resolved
8c271d9 to
50cab82
Compare
|
These commits modify the If this was unintentional then you should revert the changes before this PR is merged. |
|
☔ The latest upstream changes (presumably #143434) made this pull request unmergeable. Please resolve the merge conflicts. |
1c997f2 to
47869c2
Compare
This comment has been minimized.
This comment has been minimized.
47869c2 to
b20dd1d
Compare
This comment has been minimized.
This comment has been minimized.
b20dd1d to
96205ed
Compare
|
☔ The latest upstream changes (presumably #143582) made this pull request unmergeable. Please resolve the merge conflicts. |
96205ed to
66255f9
Compare
|
☔ The latest upstream changes (presumably #143934) made this pull request unmergeable. Please resolve the merge conflicts. |
66255f9 to
962d6ac
Compare
962d6ac to
8f23c36
Compare
| // Make wide pointer pattern types contain only a single field | ||
| // of the wide pointer type itself. | ||
| layout.fields = FieldsShape::Arbitrary { | ||
| offsets: [Size::ZERO].into_iter().collect(), | ||
| memory_index: [0].into_iter().collect(), | ||
| } |
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.
don't understand what this is doing/why we're inventing a field. also this applies to thin pointers too :3
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 was encountering annoying to handle situations in various places (like const validation) where I had to duplicate the logic for pointers (wide or thin) on pattern types, because the pattern types directly contained all the information. Now that the pattern types "wrap" the pointer type, all the normal pointer logic simply runs after recursively walking the pattern type's layout. So this makes everything else more robutst, even if technically not necessary
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 edited the comment to clarify this
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.
talked about this sync. we think layout of all pattern types should do this "has a field" thing rather than it being !null pattern types of pointers specifically
7522c0d to
15800b9
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
15800b9 to
d3e56c9
Compare
|
☔ The latest upstream changes (presumably #146221) made this pull request unmergeable. Please resolve the merge conflicts. |
d3e56c9 to
713d711
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. |
This comment has been minimized.
This comment has been minimized.
713d711 to
2a3c83b
Compare
2a3c83b to
9a953cf
Compare
This comment has been minimized.
This comment has been minimized.
9a953cf to
375899c
Compare
|
@bors r=BoxyUwU |
Rollup of 7 pull requests Successful merges: - #141445 (Add `FromIterator` impls for `ascii::Char`s to `String`s) - #142339 (Add NonNull pattern types) - #147768 (Code refactoring on hir report_no_match_method_error) - #147788 (const Cell methods) - #147932 (Create UTF-8 version of `OsStr`/`OsString`) - #147933 (os_str: Make platform docs more consistent) - #147948 (PassWrapper: Access GlobalValueSummaryInfo::SummaryList via getter for LLVM 22+) r? `@ghost` `@rustbot` modify labels: rollup
Rollup of 7 pull requests Successful merges: - rust-lang/rust#141445 (Add `FromIterator` impls for `ascii::Char`s to `String`s) - rust-lang/rust#142339 (Add NonNull pattern types) - rust-lang/rust#147768 (Code refactoring on hir report_no_match_method_error) - rust-lang/rust#147788 (const Cell methods) - rust-lang/rust#147932 (Create UTF-8 version of `OsStr`/`OsString`) - rust-lang/rust#147933 (os_str: Make platform docs more consistent) - rust-lang/rust#147948 (PassWrapper: Access GlobalValueSummaryInfo::SummaryList via getter for LLVM 22+) r? `@ghost` `@rustbot` modify labels: rollup
|
|
||
| fn main() { | ||
| unsafe { | ||
| let _: NonNull<dyn Trait> = NonNull { pointer: transmute(&mut () as *mut dyn Trait) }; |
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.
@oli-obk the unsizing here happens before pattern types are even involved, doesn't it? It happens during the &mut () as *mut dyn Trait. So I don't see how this tests anything about pattern type unsizing.
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.
It's not about unsizing pattern types, but just about the existence of unsized pattern types. I don't think unsizing pattern types works but I'll add some tests
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.
NonNull<dyn Trait> is a sized type, so I don't think there is an unsized pattern type in this example.
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 i mean we can't do NonNull<()> unsizing to NonNull<dyn Trait>. The pointer is obviously sized. Am I using the terminology wrong again? 😅
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 was just nitpicking about this part:
but just about the existence of unsized pattern types
This is more like, "pattern types for wide pointers" or so?
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'm a bit confused by this test -- it only covers is !null pattern types, but the name is much more general than that? Would be good to have a comment explaining the point of this. The commit message says something about "unsizing pattern types with pointer base"?
These are the final piece missing for
We cannot use the previous scheme of using an integer range for raw pointers, as we're not just changing the layout of raw pointers anymore, but also the type representation. And we can't represent "any provenance or NonZero" natively as patterns. So I created a new
!nullpattern. Since this is all unstable representation stuff for replacing rustc_layout_scalar_range_start with pattern types, the divergence from normal patterns is fine, especially since T-lang seems interested in exploring general negation patternsr? @BoxyUwU