Skip to content

Commit 82c05fe

Browse files
committed
Do not create a DerefLen place for Box<[T]>.
1 parent e5fedce commit 82c05fe

6 files changed

+492
-1
lines changed

compiler/rustc_mir_dataflow/src/value_analysis.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -758,7 +758,9 @@ impl Map {
758758
self.value_count += 1;
759759
}
760760

761-
if let Some(ref_ty) = ty.builtin_deref(true) && let ty::Slice(..) = ref_ty.ty.kind() {
761+
if let ty::Ref(_, ref_ty, _) | ty::RawPtr(ty::TypeAndMut { ty: ref_ty, .. }) = ty.kind()
762+
&& let ty::Slice(..) = ref_ty.kind()
763+
{
762764
assert!(self.places[place].value_index.is_none(), "slices are not scalars");
763765

764766
// Prepend new child to the linked list.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
- // MIR for `main` before DataflowConstProp
2+
+ // MIR for `main` after DataflowConstProp
3+
4+
fn main() -> () {
5+
let mut _0: ();
6+
let _1: A;
7+
let mut _2: std::boxed::Box<[bool]>;
8+
scope 1 {
9+
debug a => _1;
10+
}
11+
scope 2 (inlined <Box<[bool]> as Default>::default) {
12+
let _3: std::ptr::Unique<[bool]>;
13+
let mut _4: std::ptr::Unique<[bool; 0]>;
14+
scope 3 {
15+
debug ptr => _3;
16+
}
17+
scope 4 (inlined Unique::<[bool; 0]>::dangling) {
18+
let mut _5: std::ptr::NonNull<[bool; 0]>;
19+
scope 5 (inlined NonNull::<[bool; 0]>::dangling) {
20+
let mut _7: usize;
21+
scope 6 {
22+
let _6: *mut [bool; 0];
23+
scope 7 {
24+
debug ptr => _6;
25+
scope 11 (inlined NonNull::<[bool; 0]>::new_unchecked) {
26+
debug ptr => _6;
27+
let mut _8: *const [bool; 0];
28+
scope 12 {
29+
scope 13 (inlined NonNull::<T>::new_unchecked::runtime::<[bool; 0]>) {
30+
debug ptr => _6;
31+
let _9: !;
32+
scope 14 (inlined ptr::mut_ptr::<impl *mut [bool; 0]>::is_null) {
33+
debug self => _6;
34+
let mut _10: *mut u8;
35+
scope 15 {
36+
scope 16 (inlined ptr::mut_ptr::<impl *mut T>::is_null::runtime_impl) {
37+
debug ptr => _10;
38+
let mut _11: usize;
39+
scope 17 (inlined ptr::mut_ptr::<impl *mut u8>::addr) {
40+
debug self => _10;
41+
let mut _12: *mut ();
42+
scope 18 {
43+
scope 19 (inlined ptr::mut_ptr::<impl *mut u8>::cast::<()>) {
44+
debug self => _10;
45+
}
46+
}
47+
}
48+
}
49+
}
50+
}
51+
}
52+
}
53+
}
54+
}
55+
scope 8 (inlined align_of::<[bool; 0]>) {
56+
}
57+
scope 9 (inlined invalid_mut::<[bool; 0]>) {
58+
debug addr => _7;
59+
scope 10 {
60+
}
61+
}
62+
}
63+
}
64+
}
65+
}
66+
67+
bb0: {
68+
StorageLive(_1);
69+
StorageLive(_2);
70+
StorageLive(_3);
71+
StorageLive(_4);
72+
StorageLive(_5);
73+
StorageLive(_6);
74+
StorageLive(_7);
75+
_7 = const 1_usize;
76+
_6 = const {0x1 as *mut [bool; 0]};
77+
StorageDead(_7);
78+
StorageLive(_8);
79+
StorageLive(_10);
80+
_10 = const {0x1 as *mut u8};
81+
StorageLive(_11);
82+
StorageLive(_12);
83+
_12 = const {0x1 as *mut ()};
84+
_11 = const 1_usize;
85+
StorageDead(_12);
86+
StorageDead(_10);
87+
switchInt(const 1_usize) -> [0: bb2, otherwise: bb3];
88+
}
89+
90+
bb1: {
91+
StorageDead(_1);
92+
return;
93+
}
94+
95+
bb2: {
96+
StorageDead(_11);
97+
_9 = core::panicking::panic_nounwind(const "unsafe precondition(s) violated: NonNull::new_unchecked requires that the pointer is non-null") -> unwind unreachable;
98+
}
99+
100+
bb3: {
101+
StorageDead(_11);
102+
_8 = const {0x1 as *const [bool; 0]};
103+
_5 = const NonNull::<[bool; 0]> {{ pointer: {0x1 as *const [bool; 0]} }};
104+
StorageDead(_8);
105+
StorageDead(_6);
106+
_4 = const Unique::<[bool; 0]> {{ pointer: NonNull::<[bool; 0]> {{ pointer: {0x1 as *const [bool; 0]} }}, _marker: PhantomData::<[bool; 0]> }};
107+
StorageDead(_5);
108+
_3 = const Unique::<[bool]> {{ pointer: NonNull::<[bool]> {{ pointer: ByRef { alloc: ConstAllocation { .. }, offset: Size(0 bytes) }: *const [bool] }}, _marker: PhantomData::<[bool]> }};
109+
StorageDead(_4);
110+
_2 = const Box::<[bool]>(Unique::<[bool]> {{ pointer: NonNull::<[bool]> {{ pointer: ByRef { alloc: ConstAllocation { .. }, offset: Size(0 bytes) }: *const [bool] }}, _marker: PhantomData::<[bool]> }}, std::alloc::Global);
111+
StorageDead(_3);
112+
_1 = A { foo: const Box::<[bool]>(Unique::<[bool]> {{ pointer: NonNull::<[bool]> {{ pointer: ByRef { alloc: ConstAllocation { .. }, offset: Size(0 bytes) }: *const [bool] }}, _marker: PhantomData::<[bool]> }}, std::alloc::Global) };
113+
StorageDead(_2);
114+
drop(_1) -> [return: bb1, unwind unreachable];
115+
}
116+
}
117+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
- // MIR for `main` before DataflowConstProp
2+
+ // MIR for `main` after DataflowConstProp
3+
4+
fn main() -> () {
5+
let mut _0: ();
6+
let _1: A;
7+
let mut _2: std::boxed::Box<[bool]>;
8+
scope 1 {
9+
debug a => _1;
10+
}
11+
scope 2 (inlined <Box<[bool]> as Default>::default) {
12+
let _3: std::ptr::Unique<[bool]>;
13+
let mut _4: std::ptr::Unique<[bool; 0]>;
14+
scope 3 {
15+
debug ptr => _3;
16+
}
17+
scope 4 (inlined Unique::<[bool; 0]>::dangling) {
18+
let mut _5: std::ptr::NonNull<[bool; 0]>;
19+
scope 5 (inlined NonNull::<[bool; 0]>::dangling) {
20+
let mut _7: usize;
21+
scope 6 {
22+
let _6: *mut [bool; 0];
23+
scope 7 {
24+
debug ptr => _6;
25+
scope 11 (inlined NonNull::<[bool; 0]>::new_unchecked) {
26+
debug ptr => _6;
27+
let mut _8: *const [bool; 0];
28+
scope 12 {
29+
scope 13 (inlined NonNull::<T>::new_unchecked::runtime::<[bool; 0]>) {
30+
debug ptr => _6;
31+
let _9: !;
32+
scope 14 (inlined ptr::mut_ptr::<impl *mut [bool; 0]>::is_null) {
33+
debug self => _6;
34+
let mut _10: *mut u8;
35+
scope 15 {
36+
scope 16 (inlined ptr::mut_ptr::<impl *mut T>::is_null::runtime_impl) {
37+
debug ptr => _10;
38+
let mut _11: usize;
39+
scope 17 (inlined ptr::mut_ptr::<impl *mut u8>::addr) {
40+
debug self => _10;
41+
let mut _12: *mut ();
42+
scope 18 {
43+
scope 19 (inlined ptr::mut_ptr::<impl *mut u8>::cast::<()>) {
44+
debug self => _10;
45+
}
46+
}
47+
}
48+
}
49+
}
50+
}
51+
}
52+
}
53+
}
54+
}
55+
scope 8 (inlined align_of::<[bool; 0]>) {
56+
}
57+
scope 9 (inlined invalid_mut::<[bool; 0]>) {
58+
debug addr => _7;
59+
scope 10 {
60+
}
61+
}
62+
}
63+
}
64+
}
65+
}
66+
67+
bb0: {
68+
StorageLive(_1);
69+
StorageLive(_2);
70+
StorageLive(_3);
71+
StorageLive(_4);
72+
StorageLive(_5);
73+
StorageLive(_6);
74+
StorageLive(_7);
75+
_7 = const 1_usize;
76+
_6 = const {0x1 as *mut [bool; 0]};
77+
StorageDead(_7);
78+
StorageLive(_8);
79+
StorageLive(_10);
80+
_10 = const {0x1 as *mut u8};
81+
StorageLive(_11);
82+
StorageLive(_12);
83+
_12 = const {0x1 as *mut ()};
84+
_11 = const 1_usize;
85+
StorageDead(_12);
86+
StorageDead(_10);
87+
switchInt(const 1_usize) -> [0: bb3, otherwise: bb4];
88+
}
89+
90+
bb1: {
91+
StorageDead(_1);
92+
return;
93+
}
94+
95+
bb2 (cleanup): {
96+
resume;
97+
}
98+
99+
bb3: {
100+
StorageDead(_11);
101+
_9 = core::panicking::panic_nounwind(const "unsafe precondition(s) violated: NonNull::new_unchecked requires that the pointer is non-null") -> unwind unreachable;
102+
}
103+
104+
bb4: {
105+
StorageDead(_11);
106+
_8 = const {0x1 as *const [bool; 0]};
107+
_5 = const NonNull::<[bool; 0]> {{ pointer: {0x1 as *const [bool; 0]} }};
108+
StorageDead(_8);
109+
StorageDead(_6);
110+
_4 = const Unique::<[bool; 0]> {{ pointer: NonNull::<[bool; 0]> {{ pointer: {0x1 as *const [bool; 0]} }}, _marker: PhantomData::<[bool; 0]> }};
111+
StorageDead(_5);
112+
_3 = const Unique::<[bool]> {{ pointer: NonNull::<[bool]> {{ pointer: ByRef { alloc: ConstAllocation { .. }, offset: Size(0 bytes) }: *const [bool] }}, _marker: PhantomData::<[bool]> }};
113+
StorageDead(_4);
114+
_2 = const Box::<[bool]>(Unique::<[bool]> {{ pointer: NonNull::<[bool]> {{ pointer: ByRef { alloc: ConstAllocation { .. }, offset: Size(0 bytes) }: *const [bool] }}, _marker: PhantomData::<[bool]> }}, std::alloc::Global);
115+
StorageDead(_3);
116+
_1 = A { foo: const Box::<[bool]>(Unique::<[bool]> {{ pointer: NonNull::<[bool]> {{ pointer: ByRef { alloc: ConstAllocation { .. }, offset: Size(0 bytes) }: *const [bool] }}, _marker: PhantomData::<[bool]> }}, std::alloc::Global) };
117+
StorageDead(_2);
118+
drop(_1) -> [return: bb1, unwind: bb2];
119+
}
120+
}
121+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
- // MIR for `main` before DataflowConstProp
2+
+ // MIR for `main` after DataflowConstProp
3+
4+
fn main() -> () {
5+
let mut _0: ();
6+
let _1: A;
7+
let mut _2: std::boxed::Box<[bool]>;
8+
scope 1 {
9+
debug a => _1;
10+
}
11+
scope 2 (inlined <Box<[bool]> as Default>::default) {
12+
let _3: std::ptr::Unique<[bool]>;
13+
let mut _4: std::ptr::Unique<[bool; 0]>;
14+
scope 3 {
15+
debug ptr => _3;
16+
}
17+
scope 4 (inlined Unique::<[bool; 0]>::dangling) {
18+
let mut _5: std::ptr::NonNull<[bool; 0]>;
19+
scope 5 (inlined NonNull::<[bool; 0]>::dangling) {
20+
let mut _7: usize;
21+
scope 6 {
22+
let _6: *mut [bool; 0];
23+
scope 7 {
24+
debug ptr => _6;
25+
scope 11 (inlined NonNull::<[bool; 0]>::new_unchecked) {
26+
debug ptr => _6;
27+
let mut _8: *const [bool; 0];
28+
scope 12 {
29+
scope 13 (inlined NonNull::<T>::new_unchecked::runtime::<[bool; 0]>) {
30+
debug ptr => _6;
31+
let _9: !;
32+
scope 14 (inlined ptr::mut_ptr::<impl *mut [bool; 0]>::is_null) {
33+
debug self => _6;
34+
let mut _10: *mut u8;
35+
scope 15 {
36+
scope 16 (inlined ptr::mut_ptr::<impl *mut T>::is_null::runtime_impl) {
37+
debug ptr => _10;
38+
let mut _11: usize;
39+
scope 17 (inlined ptr::mut_ptr::<impl *mut u8>::addr) {
40+
debug self => _10;
41+
let mut _12: *mut ();
42+
scope 18 {
43+
scope 19 (inlined ptr::mut_ptr::<impl *mut u8>::cast::<()>) {
44+
debug self => _10;
45+
}
46+
}
47+
}
48+
}
49+
}
50+
}
51+
}
52+
}
53+
}
54+
}
55+
scope 8 (inlined align_of::<[bool; 0]>) {
56+
}
57+
scope 9 (inlined invalid_mut::<[bool; 0]>) {
58+
debug addr => _7;
59+
scope 10 {
60+
}
61+
}
62+
}
63+
}
64+
}
65+
}
66+
67+
bb0: {
68+
StorageLive(_1);
69+
StorageLive(_2);
70+
StorageLive(_3);
71+
StorageLive(_4);
72+
StorageLive(_5);
73+
StorageLive(_6);
74+
StorageLive(_7);
75+
_7 = const 1_usize;
76+
_6 = const {0x1 as *mut [bool; 0]};
77+
StorageDead(_7);
78+
StorageLive(_8);
79+
StorageLive(_10);
80+
_10 = const {0x1 as *mut u8};
81+
StorageLive(_11);
82+
StorageLive(_12);
83+
_12 = const {0x1 as *mut ()};
84+
_11 = const 1_usize;
85+
StorageDead(_12);
86+
StorageDead(_10);
87+
switchInt(const 1_usize) -> [0: bb2, otherwise: bb3];
88+
}
89+
90+
bb1: {
91+
StorageDead(_1);
92+
return;
93+
}
94+
95+
bb2: {
96+
StorageDead(_11);
97+
_9 = core::panicking::panic_nounwind(const "unsafe precondition(s) violated: NonNull::new_unchecked requires that the pointer is non-null") -> unwind unreachable;
98+
}
99+
100+
bb3: {
101+
StorageDead(_11);
102+
_8 = const {0x1 as *const [bool; 0]};
103+
_5 = const NonNull::<[bool; 0]> {{ pointer: {0x1 as *const [bool; 0]} }};
104+
StorageDead(_8);
105+
StorageDead(_6);
106+
_4 = const Unique::<[bool; 0]> {{ pointer: NonNull::<[bool; 0]> {{ pointer: {0x1 as *const [bool; 0]} }}, _marker: PhantomData::<[bool; 0]> }};
107+
StorageDead(_5);
108+
_3 = const Unique::<[bool]> {{ pointer: NonNull::<[bool]> {{ pointer: ByRef { alloc: ConstAllocation { .. }, offset: Size(0 bytes) }: *const [bool] }}, _marker: PhantomData::<[bool]> }};
109+
StorageDead(_4);
110+
_2 = const Box::<[bool]>(Unique::<[bool]> {{ pointer: NonNull::<[bool]> {{ pointer: ByRef { alloc: ConstAllocation { .. }, offset: Size(0 bytes) }: *const [bool] }}, _marker: PhantomData::<[bool]> }}, std::alloc::Global);
111+
StorageDead(_3);
112+
_1 = A { foo: const Box::<[bool]>(Unique::<[bool]> {{ pointer: NonNull::<[bool]> {{ pointer: ByRef { alloc: ConstAllocation { .. }, offset: Size(0 bytes) }: *const [bool] }}, _marker: PhantomData::<[bool]> }}, std::alloc::Global) };
113+
StorageDead(_2);
114+
drop(_1) -> [return: bb1, unwind unreachable];
115+
}
116+
}
117+

0 commit comments

Comments
 (0)