Commit 6901197
committed
Auto merge of rust-lang#148151 - cjgillot:no-offset-of, r=scottmcm
Replace OffsetOf by an actual sum of calls to intrinsic.
This PR changes the way we compute the value of the `offset_of!` macro in MIR. The current implementation uses a dedicated MIR rvalue.
This PR proposes to replace it by an inline constant which sums calls to a new intrinsic `offset_of(variant index, field index)`. The desugaring is done at THIR building time, easier that doing it on MIR.
The new intrinsic is only meant to be used by const-eval. LLVM codegen will refuse to generate code for it.
We replace:
```rust
a = offset_of!(T, Variant1.Field1.Variant2.Field2);
```
By:
```rust
a = const {constant#n};
{constant#n}: usize = {
_1 = offset_of::<T>(index of Variant1, index of Field1);
_2 = offset_of::<U>(index of Variant2, index of Field2); // Where T::Variant1::Field1 has type U
_0 = _1 + _2
}
```
The second commit modifies intrinsic const checking to take `allow_internal_unstable` into account. The new intrinsic should only be called from stable `offset_of!` macro. The intrinsic itself is unstable, const-unstable, but `rustc_intrinsic_const_stable_indirect`.
Fixes rust-lang#123959
Fixes rust-lang#125680
Fixes rust-lang#129425
Fixes rust-lang#136175
r? `@ghost`2 files changed
+22
-2
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2791 | 2791 | | |
2792 | 2792 | | |
2793 | 2793 | | |
| 2794 | + | |
| 2795 | + | |
| 2796 | + | |
| 2797 | + | |
| 2798 | + | |
| 2799 | + | |
| 2800 | + | |
| 2801 | + | |
| 2802 | + | |
| 2803 | + | |
| 2804 | + | |
| 2805 | + | |
| 2806 | + | |
| 2807 | + | |
| 2808 | + | |
| 2809 | + | |
| 2810 | + | |
| 2811 | + | |
| 2812 | + | |
| 2813 | + | |
2794 | 2814 | | |
2795 | 2815 | | |
2796 | 2816 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1424 | 1424 | | |
1425 | 1425 | | |
1426 | 1426 | | |
1427 | | - | |
| 1427 | + | |
1428 | 1428 | | |
1429 | 1429 | | |
1430 | | - | |
| 1430 | + | |
1431 | 1431 | | |
1432 | 1432 | | |
1433 | 1433 | | |
| |||
0 commit comments