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

Add an intrinsic for ptr::from_raw_parts(_mut) #123840

Merged
merged 11 commits into from
Apr 21, 2024
Prev Previous commit
Update tests after 123949
  • Loading branch information
scottmcm committed Apr 21, 2024
commit 5e785b1420d8d26f360a33919700868c877cbbbc
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,19 @@ fn demo_byte_add_fat(_1: *const [u32], _2: usize) -> *const [u32] {
debug n => _2;
let mut _0: *const [u32];
scope 1 (inlined std::ptr::const_ptr::<impl *const [u32]>::byte_add) {
debug self => _1;
debug count => _2;
let mut _3: *const u8;
let mut _4: *const u8;
scope 2 (inlined std::ptr::const_ptr::<impl *const [u32]>::cast::<u8>) {
debug self => _1;
}
scope 3 (inlined std::ptr::const_ptr::<impl *const u8>::add) {
debug self => _3;
debug count => _2;
}
scope 4 (inlined std::ptr::const_ptr::<impl *const u8>::with_metadata_of::<[u32]>) {
debug self => _4;
debug meta => _1;
let mut _5: *const ();
let mut _7: usize;
scope 5 (inlined std::ptr::metadata::<[u32]>) {
debug ptr => _1;
let mut _6: std::ptr::metadata::PtrRepr<[u32]>;
}
scope 6 (inlined std::ptr::from_raw_parts::<[u32]>) {
debug data_pointer => _5;
debug metadata => _7;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,19 @@ fn demo_byte_add_fat(_1: *const [u32], _2: usize) -> *const [u32] {
debug n => _2;
let mut _0: *const [u32];
scope 1 (inlined std::ptr::const_ptr::<impl *const [u32]>::byte_add) {
debug self => _1;
debug count => _2;
let mut _3: *const u8;
let mut _4: *const u8;
scope 2 (inlined std::ptr::const_ptr::<impl *const [u32]>::cast::<u8>) {
debug self => _1;
}
scope 3 (inlined std::ptr::const_ptr::<impl *const u8>::add) {
debug self => _3;
debug count => _2;
}
scope 4 (inlined std::ptr::const_ptr::<impl *const u8>::with_metadata_of::<[u32]>) {
debug self => _4;
debug meta => _1;
let mut _5: *const ();
let mut _7: usize;
scope 5 (inlined std::ptr::metadata::<[u32]>) {
debug ptr => _1;
let mut _6: std::ptr::metadata::PtrRepr<[u32]>;
}
scope 6 (inlined std::ptr::from_raw_parts::<[u32]>) {
debug data_pointer => _5;
debug metadata => _7;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,16 @@ fn demo_byte_add_thin(_1: *const u32, _2: usize) -> *const u32 {
debug n => _2;
let mut _0: *const u32;
scope 1 (inlined std::ptr::const_ptr::<impl *const u32>::byte_add) {
debug self => _1;
debug count => _2;
let mut _3: *const u8;
let mut _4: *const u8;
scope 2 (inlined std::ptr::const_ptr::<impl *const u32>::cast::<u8>) {
debug self => _1;
}
scope 3 (inlined std::ptr::const_ptr::<impl *const u8>::add) {
debug self => _3;
debug count => _2;
}
scope 4 (inlined std::ptr::const_ptr::<impl *const u8>::with_metadata_of::<u32>) {
debug self => _4;
debug meta => _1;
let mut _5: *const ();
scope 5 (inlined std::ptr::metadata::<u32>) {
debug ptr => _1;
}
scope 6 (inlined std::ptr::from_raw_parts::<u32>) {
debug data_pointer => _5;
debug metadata => const ();
}
}
}
Expand All @@ -35,10 +24,7 @@ fn demo_byte_add_thin(_1: *const u32, _2: usize) -> *const u32 {
_3 = _1 as *const u8 (PtrToPtr);
_4 = Offset(_3, _2);
StorageDead(_3);
StorageLive(_5);
_5 = _4 as *const () (PtrToPtr);
_0 = _4 as *const u32 (PtrToPtr);
StorageDead(_5);
return;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,16 @@ fn demo_byte_add_thin(_1: *const u32, _2: usize) -> *const u32 {
debug n => _2;
let mut _0: *const u32;
scope 1 (inlined std::ptr::const_ptr::<impl *const u32>::byte_add) {
debug self => _1;
debug count => _2;
let mut _3: *const u8;
let mut _4: *const u8;
scope 2 (inlined std::ptr::const_ptr::<impl *const u32>::cast::<u8>) {
debug self => _1;
}
scope 3 (inlined std::ptr::const_ptr::<impl *const u8>::add) {
debug self => _3;
debug count => _2;
}
scope 4 (inlined std::ptr::const_ptr::<impl *const u8>::with_metadata_of::<u32>) {
debug self => _4;
debug meta => _1;
let mut _5: *const ();
scope 5 (inlined std::ptr::metadata::<u32>) {
debug ptr => _1;
}
scope 6 (inlined std::ptr::from_raw_parts::<u32>) {
debug data_pointer => _5;
debug metadata => const ();
}
}
}
Expand All @@ -35,10 +24,7 @@ fn demo_byte_add_thin(_1: *const u32, _2: usize) -> *const u32 {
_3 = _1 as *const u8 (PtrToPtr);
_4 = Offset(_3, _2);
StorageDead(_3);
StorageLive(_5);
_5 = _4 as *const () (PtrToPtr);
_0 = _4 as *const u32 (PtrToPtr);
Copy link
Member Author

Choose a reason for hiding this comment

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

As a serendipitous bonus, this PR means that using byte_add on a thin pointer is no longer worse in MIR than casting to *const u8 and offsetting yourself, as with unit metadata there's no longer any union dances needed, just the straight-forward casting.

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh, even better -- with #123949 it also drops the irrelevant cast to *const ().

StorageDead(_5);
return;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,42 +7,25 @@ fn slice_ptr_get_unchecked_range(_1: *const [u32], _2: std::ops::Range<usize>) -
let mut _3: usize;
let mut _4: usize;
scope 1 (inlined std::ptr::const_ptr::<impl *const [u32]>::get_unchecked::<std::ops::Range<usize>>) {
debug self => _1;
debug ((index: std::ops::Range<usize>).0: usize) => _3;
debug ((index: std::ops::Range<usize>).1: usize) => _4;
scope 2 (inlined <std::ops::Range<usize> as SliceIndex<[u32]>>::get_unchecked) {
debug ((self: std::ops::Range<usize>).0: usize) => _3;
debug ((self: std::ops::Range<usize>).1: usize) => _4;
debug slice => _1;
let _5: usize;
let mut _6: *const u32;
let mut _7: *const u32;
scope 3 {
debug new_len => _5;
scope 6 (inlined std::ptr::const_ptr::<impl *const [u32]>::as_ptr) {
debug self => _1;
}
scope 7 (inlined std::ptr::const_ptr::<impl *const u32>::add) {
debug self => _6;
debug count => _3;
}
scope 8 (inlined slice_from_raw_parts::<u32>) {
debug data => _7;
debug len => _5;
let mut _8: *const ();
scope 9 (inlined std::ptr::const_ptr::<impl *const u32>::cast::<()>) {
debug self => _7;
}
scope 10 (inlined std::ptr::from_raw_parts::<[u32]>) {
debug data_pointer => _8;
debug metadata => _5;
}
}
}
scope 4 (inlined std::ptr::const_ptr::<impl *const [u32]>::len) {
debug self => _1;
scope 5 (inlined std::ptr::metadata::<[u32]>) {
debug ptr => _1;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,42 +7,25 @@ fn slice_ptr_get_unchecked_range(_1: *const [u32], _2: std::ops::Range<usize>) -
let mut _3: usize;
let mut _4: usize;
scope 1 (inlined std::ptr::const_ptr::<impl *const [u32]>::get_unchecked::<std::ops::Range<usize>>) {
debug self => _1;
debug ((index: std::ops::Range<usize>).0: usize) => _3;
debug ((index: std::ops::Range<usize>).1: usize) => _4;
scope 2 (inlined <std::ops::Range<usize> as SliceIndex<[u32]>>::get_unchecked) {
debug ((self: std::ops::Range<usize>).0: usize) => _3;
debug ((self: std::ops::Range<usize>).1: usize) => _4;
debug slice => _1;
let _5: usize;
let mut _6: *const u32;
let mut _7: *const u32;
scope 3 {
debug new_len => _5;
scope 6 (inlined std::ptr::const_ptr::<impl *const [u32]>::as_ptr) {
debug self => _1;
}
scope 7 (inlined std::ptr::const_ptr::<impl *const u32>::add) {
debug self => _6;
debug count => _3;
}
scope 8 (inlined slice_from_raw_parts::<u32>) {
debug data => _7;
debug len => _5;
let mut _8: *const ();
scope 9 (inlined std::ptr::const_ptr::<impl *const u32>::cast::<()>) {
debug self => _7;
}
scope 10 (inlined std::ptr::from_raw_parts::<[u32]>) {
debug data_pointer => _8;
debug metadata => _5;
}
}
}
scope 4 (inlined std::ptr::const_ptr::<impl *const [u32]>::len) {
debug self => _1;
scope 5 (inlined std::ptr::metadata::<[u32]>) {
debug ptr => _1;
}
}
}
Expand Down
Loading