-
Notifications
You must be signed in to change notification settings - Fork 13.7k
Commit 0e7119f
authored
Unrolled build for #145174
Rollup merge of #145174 - 197g:issue-145148-select-unpredictable-drop, r=joboet
Ensure consistent drop for panicking drop in hint::select_unpredictable
There are a few alternatives to the implementation. The principal problem is that the selected value must be owned (in the sense of having a drop flag of sorts) when the unselected value is dropped, such that panic unwind goes through the drop of both. This ownership must then be passed on in return when the drop went smoothly.
The basic way of achieving this is by extracting the selected value first, at the cost of relying on the optimizer a little more for detecting the copy as constructing the return value despite having a place in the body. Unfortunately, that causes LLVM to discard the !unpredictable annotation (for some reason that is beyond my comprehension of LLVM).
<details>
<summary>Extract from the build log showing an unannotated select being used</summary>
```
2025年08月09日T16:51:06.8790764Z 39: define noundef i64 `@test_int2(i1` noundef zeroext %p, i64 noundef %a, i64 noundef %b) unnamed_addr #0 personality ptr `@rust_eh_personality` {
2025年08月09日T16:51:06.8791368Z check:47'0 X~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: no match found
2025年08月09日T16:51:06.8791700Z 40: start:
2025年08月09日T16:51:06.8791858Z check:47'0 ~~~~~~~
2025年08月09日T16:51:06.8792043Z 41: %ret.i = select i1 %p, i64 %a, i64 %b
2025年08月09日T16:51:06.8792293Z check:47'0 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2025年08月09日T16:51:06.8792686Z check:47'1 ? possible intended match
2025年08月09日T16:51:06.8792946Z 42: ret i64 %ret.i
2025年08月09日T16:51:06.8793127Z check:47'0 ~~~~~~~~~~~~~~~~
```
</details>
So instead, this PR includes a guard to drop the selected `MaybeUnit<T>` which is active only for the section where the unselected value is dropped. That leaves the code for selecting the result intact leading to the expected ir. That complicates the 'unselection' process a little bit since we require _both_ values as a result of that intrinsic call. Since the arguments alias, this portion as well as the drop guard uses raw pointers.
Closes: #145148
Prior: #139977 2 files changed
+71
-2
lines changedLines changed: 35 additions & 2 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
776 | 776 |
| |
777 | 777 |
| |
778 | 778 |
| |
779 | + | ||
780 | + | ||
781 | + | ||
782 | + | ||
783 | + | ||
784 | + | ||
785 | + | ||
786 | + | ||
787 | + | ||
788 | + | ||
789 | + | ||
790 | + | ||
791 | + | ||
792 | + | ||
793 | + | ||
794 | + | ||
795 | + | ||
779 | 796 |
| |
780 | 797 |
| |
781 | 798 |
| |
782 | 799 |
| |
783 | - | ||
784 | - | ||
800 | + | ||
801 | + | ||
802 | + | ||
803 | + | ||
804 | + | ||
805 | + | ||
806 | + | ||
807 | + | ||
808 | + | ||
809 | + | ||
810 | + | ||
811 | + | ||
812 | + | ||
813 | + | ||
814 | + | ||
815 | + | ||
816 | + | ||
817 | + | ||
785 | 818 |
| |
786 | 819 |
| |
787 | 820 |
|
Lines changed: 36 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
21 | 21 |
| |
22 | 22 |
| |
23 | 23 |
| |
24 | + | ||
25 | + | ||
26 | + | ||
27 | + | ||
28 | + | ||
29 | + | ||
30 | + | ||
31 | + | ||
32 | + | ||
33 | + | ||
34 | + | ||
35 | + | ||
36 | + | ||
37 | + | ||
38 | + | ||
39 | + | ||
40 | + | ||
41 | + | ||
42 | + | ||
43 | + | ||
44 | + | ||
45 | + | ||
46 | + | ||
47 | + | ||
48 | + | ||
49 | + | ||
50 | + | ||
51 | + | ||
52 | + | ||
53 | + | ||
54 | + | ||
55 | + | ||
56 | + | ||
57 | + | ||
58 | + | ||
59 | + |
0 commit comments