rust/compiler/rustc_hir_analysis/src
bors 43a78029b4 Auto merge of #110837 - scottmcm:offset-for-add, r=compiler-errors
Use MIR's `Offset` for pointer `add` too

~~Status: draft while waiting for #110822 to land, since this is built atop that.~~
~~r? `@ghost~~`

Canonical Rust code has mostly moved to `add`/`sub` on pointers, which take `usize`, instead of `offset` which takes `isize`.  (And, relatedly, when `sub_ptr` was added it turned out it replaced every single in-tree use of `offset_from`, because `usize` is just so much more useful than `isize` in Rust.)

Unfortunately, `intrinsics::offset` could only accept `*const` and `isize`, so there's a *huge* amount of type conversions back and forth being done.  They're identity conversions in the backend, but still end up producing quite a lot of unhelpful MIR.

This PR changes `intrinsics::offset` to accept `*const` *and* `*mut` along with `isize` *and* `usize`.  Conveniently, the backends and CTFE already handle this, since MIR's `BinOp::Offset` [already supports all four combinations](adaac6b166/compiler/rustc_const_eval/src/transform/validate.rs (L523-L528)).

To demonstrate the difference, I added some `mir-opt/pre-codegen/` tests around slice indexing.  Here's the difference to `[T]::get_mut`, since it uses `<*mut _>::add` internally:
```diff
`@@` -79,30 +70,21 `@@` fn slice_get_mut_usize(_1: &mut [u32], _2: usize) -> Option<&mut u32> {
         StorageLive(_12);                // scope 3 at $SRC_DIR/core/src/slice/index.rs:LL:COL
         StorageLive(_9);                 // scope 6 at $SRC_DIR/core/src/slice/index.rs:LL:COL
         _9 = _8 as *mut u32 (PtrToPtr);  // scope 11 at $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL
-        StorageLive(_13);                // scope 13 at $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL
-        _13 = _2 as isize (IntToInt);    // scope 13 at $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL
-        StorageLive(_14);                // scope 15 at $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL
-        StorageLive(_15);                // scope 15 at $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL
-        _15 = _9 as *const u32 (Pointer(MutToConstPointer)); // scope 15 at $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL
-        _14 = Offset(move _15, _13);     // scope 15 at $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL
-        StorageDead(_15);                // scope 15 at $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL
-        _7 = move _14 as *mut u32 (PtrToPtr); // scope 15 at $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL
-        StorageDead(_14);                // scope 15 at $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL
-        StorageDead(_13);                // scope 13 at $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL
+        _7 = Offset(_9, _2);             // scope 13 at $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL
         StorageDead(_9);                 // scope 6 at $SRC_DIR/core/src/slice/index.rs:LL:COL
         StorageDead(_12);                // scope 3 at $SRC_DIR/core/src/slice/index.rs:LL:COL
         StorageDead(_11);                // scope 3 at $SRC_DIR/core/src/slice/index.rs:LL:COL
```
1c1c8e442a (diff-a841b6a4538657add3f39bc895744331453d0625e7aace128b1f604f0b63c8fdR80)
2023-04-28 09:26:59 +00:00
..
astconv rename needs_subst to has_param 2023-04-27 08:35:19 +01:00
check Auto merge of #110837 - scottmcm:offset-for-add, r=compiler-errors 2023-04-28 09:26:59 +00:00
coherence rename needs_subst to has_param 2023-04-27 08:35:19 +01:00
collect Rollup merge of #108760 - clubby789:autolintstuff, r=wesleywiser 2023-04-26 18:51:40 +02:00
impl_wf_check rename needs_infer to has_infer 2023-04-27 08:35:19 +01:00
outlives Rename AliasEq -> AliasRelate 2023-03-23 05:56:40 +00:00
structured_errors Add (..) syntax for RTN 2023-03-28 01:14:28 +00:00
variance Rollup merge of #110556 - kylematsuda:earlybinder-explicit-item-bounds, r=compiler-errors 2023-04-25 21:06:32 +02:00
autoderef.rs Remove type-traversal trait aliases 2023-02-22 17:04:58 +00:00
bounds.rs Fix typos in compiler 2023-04-10 22:02:52 +02:00
check_unused.rs Remove last instances of HashSet in query result types. 2023-03-01 10:20:45 +01:00
collect.rs Make some region folders a little stricter. 2023-04-26 10:14:16 +10:00
constrained_generic_params.rs Remove type-traversal trait aliases 2023-02-22 17:04:58 +00:00
errors.rs Fix static string lints 2023-04-25 18:59:55 +01:00
hir_wf_check.rs Auto merge of #109119 - lcnr:trait-system-cleanup, r=compiler-errors 2023-03-22 05:33:18 +00:00
impl_wf_check.rs Remove type-traversal trait aliases 2023-02-22 17:04:58 +00:00
lib.rs Leave it to the query system to invoke the typeck query instead of invoking it eagerly. 2023-04-21 22:12:45 +00:00
structured_errors.rs rustc_typeck to rustc_hir_analysis 2022-09-27 10:37:23 +02:00