rust/compiler
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
```
https://github.com/rust-lang/rust/pull/110837/commits/1c1c8e442add0f46905a57a25a6cba52b8b0c54d#diff-a841b6a4538657add3f39bc895744331453d0625e7aace128b1f604f0b63c8fdR80
2023-04-28 09:26:59 +00:00
..
rustc fix link 2023-03-11 10:53:47 -06:00
rustc_abi Split {Idx, IndexVec, IndexSlice} into their own modules 2023-04-24 13:53:35 +00:00
rustc_apfloat
rustc_arena Allow clippy::from_mut_ref 2023-04-09 22:29:56 +02:00
rustc_ast Rollup merge of #110873 - clubby789:migrate-rustc-parse-trivial, r=compiler-errors 2023-04-28 07:34:02 +02:00
rustc_ast_lowering Rollup merge of #110766 - m-ou-se:fmt-rt, r=jyn514 2023-04-28 07:34:02 +02:00
rustc_ast_passes Auto merge of #110407 - Nilstrieb:fluent-macro, r=davidtwco 2023-04-19 08:26:47 +00:00
rustc_ast_pretty minor tweaks 2023-04-21 02:14:04 -07:00
rustc_attr Add rustc_fluent_macro to decouple fluent from rustc_macros 2023-04-18 18:56:22 +00:00
rustc_baked_icu_data update ICU4X to 1.1.0 2023-02-04 22:28:59 +01:00
rustc_borrowck Rollup merge of #110556 - kylematsuda:earlybinder-explicit-item-bounds, r=compiler-errors 2023-04-25 21:06:32 +02:00
rustc_builtin_macros Fix static string lints 2023-04-25 18:59:55 +01:00
rustc_codegen_cranelift rename needs_infer to has_infer 2023-04-27 08:35:19 +01:00
rustc_codegen_gcc rename needs_infer to has_infer 2023-04-27 08:35:19 +01:00
rustc_codegen_llvm rename needs_subst to has_param 2023-04-27 08:35:19 +01:00
rustc_codegen_ssa Auto merge of #110837 - scottmcm:offset-for-add, r=compiler-errors 2023-04-28 09:26:59 +00:00
rustc_const_eval Rollup merge of #110766 - m-ou-se:fmt-rt, r=jyn514 2023-04-28 07:34:02 +02:00
rustc_data_structures Auto merge of #107782 - Zoxc:worker-local, r=cjgillot 2023-04-27 17:43:09 +00:00
rustc_driver Remove unneeded extern crate 2023-02-02 07:47:39 +01:00
rustc_driver_impl Fix ICE on --print=... i/o errors 2023-04-25 08:17:18 -07:00
rustc_error_codes Spelling - compiler 2023-04-17 16:09:18 -04:00
rustc_error_messages Add rustc_fluent_macro to decouple fluent from rustc_macros 2023-04-18 18:56:22 +00:00
rustc_errors Rollup merge of #110578 - bvanjoi:fix-issue-110547, r=jackh726 2023-04-21 06:44:30 +02:00
rustc_expand Fix static string lints 2023-04-25 18:59:55 +01:00
rustc_feature Revert "Remove #[alloc_error_handler] from the compiler and library" 2023-04-25 00:08:35 +02:00
rustc_fluent_macro Remove unused synstructure dep 2023-04-22 22:03:33 +01:00
rustc_fs_util Add try_canonicalize to rustc_fs_util and use it over fs::canonicalize 2023-03-16 21:50:23 +01:00
rustc_graphviz Fix uninlined_format_args for some compiler crates 2023-01-05 19:01:12 +01:00
rustc_hir Split {Idx, IndexVec, IndexSlice} into their own modules 2023-04-24 13:53:35 +00:00
rustc_hir_analysis Auto merge of #110837 - scottmcm:offset-for-add, r=compiler-errors 2023-04-28 09:26:59 +00:00
rustc_hir_pretty minor tweaks 2023-04-21 02:14:04 -07:00
rustc_hir_typeck Rollup merge of #110893 - BoxyUwU:inline_const_nits, r=compiler-errors 2023-04-28 10:52:00 +09:00
rustc_incremental Auto merge of #110407 - Nilstrieb:fluent-macro, r=davidtwco 2023-04-19 08:26:47 +00:00
rustc_index Decorative changes to IndexVec 2023-04-24 13:53:37 +00:00
rustc_infer Rollup merge of #110838 - nnethercote:more-Folder-Visitable-cleanups, r=lcnr 2023-04-27 21:34:14 +02:00
rustc_interface Auto merge of #107782 - Zoxc:worker-local, r=cjgillot 2023-04-27 17:43:09 +00:00
rustc_lexer Revert "Don't recover lifetimes/labels containing emojis as character literals" 2023-04-10 06:52:41 +00:00
rustc_lint rename needs_subst to has_param 2023-04-27 08:35:19 +01:00
rustc_lint_defs Add a few more missing lints 2023-04-27 18:43:03 +00:00
rustc_llvm [LLVM17] Adapt to ExplicitEmulatedTLS removal. 2023-04-24 08:45:15 +00:00
rustc_log Stabilize IsTerminal 2023-04-10 17:24:23 +09:00
rustc_macros Split {Idx, IndexVec, IndexSlice} into their own modules 2023-04-24 13:53:35 +00:00
rustc_metadata Auto merge of #110634 - saethlin:pointy-decoder, r=cjgillot 2023-04-26 02:36:42 +00:00
rustc_middle Rollup merge of #110838 - nnethercote:more-Folder-Visitable-cleanups, r=lcnr 2023-04-27 21:34:14 +02:00
rustc_mir_build Split {Idx, IndexVec, IndexSlice} into their own modules 2023-04-24 13:53:35 +00:00
rustc_mir_dataflow Split {Idx, IndexVec, IndexSlice} into their own modules 2023-04-24 13:53:35 +00:00
rustc_mir_transform Auto merge of #110882 - BoxyUwU:rename-some-ty-flags, r=compiler-errors 2023-04-27 09:55:37 +00:00
rustc_monomorphize rename needs_subst to has_param 2023-04-27 08:35:19 +01:00
rustc_parse Migrate trivially translatable rustc_parse diagnostics 2023-04-27 01:53:06 +01:00
rustc_parse_format Fix typos in compiler 2023-04-10 22:02:52 +02:00
rustc_passes Migrate rustc_passes to translatable diagnostics 2023-04-26 11:40:21 +01:00
rustc_plugin_impl Add rustc_fluent_macro to decouple fluent from rustc_macros 2023-04-18 18:56:22 +00:00
rustc_privacy add EarlyBinder to output of explicit_item_bounds; replace bound_explicit_item_bounds usages; remove bound_explicit_item_bounds query 2023-04-20 12:36:50 -06:00
rustc_query_impl Auto merge of #110634 - saethlin:pointy-decoder, r=cjgillot 2023-04-26 02:36:42 +00:00
rustc_query_system Rollup merge of #110886 - nnethercote:dep-graph-cleanups, r=cjgillot 2023-04-27 21:34:17 +02:00
rustc_resolve Fix static string lints 2023-04-25 18:59:55 +01:00
rustc_serialize Rewrite MemDecoder around pointers not a slice 2023-04-23 17:25:11 -04:00
rustc_session Rollup merge of #110594 - infdahai:cfg_chore, r=jyn514 2023-04-26 01:55:52 -05:00
rustc_smir Add Call terminator to SMIR 2023-04-20 12:00:41 -03:00
rustc_span Rollup merge of #110766 - m-ou-se:fmt-rt, r=jyn514 2023-04-28 07:34:02 +02:00
rustc_symbol_mangling rename needs_subst to has_param 2023-04-27 08:35:19 +01:00
rustc_target Add loongarch64 asm! support 2023-04-25 14:15:31 +08:00
rustc_trait_selection rename needs_subst to has_param 2023-04-27 08:35:19 +01:00
rustc_traits rename needs_infer to has_infer 2023-04-27 08:35:19 +01:00
rustc_transmute Remove unused TypeFoldable/TypeVisitable impls. 2023-04-26 15:19:50 +10:00
rustc_ty_utils rename needs_infer to has_infer 2023-04-27 08:35:19 +01:00
rustc_type_ir Rollup merge of #110838 - nnethercote:more-Folder-Visitable-cleanups, r=lcnr 2023-04-27 21:34:14 +02:00