rust/library
bors bbb6f68e28 Auto merge of #147803 - jsgf:move-copy-codegen, r=madsmtm,saethlin
Add -Zannotate-moves for profiler visibility of move/copy operations (codegen)

**Note:** this is an alternative implementation of https://github.com/rust-lang/rust/pull/147206; rather than being a MIR transform, it adds the annotations closer to codegen. It's functionally the same but the implementation is lower impact and it could be more correct.

---

This implements a new unstable compiler flag `-Zannotate-moves` that makes move and copy operations visible in profilers by creating synthetic debug information. This is achieved with zero runtime cost by manipulating debug info scopes to make moves/copies appear as calls to `compiler_move<T, SIZE>` and `compiler_copy<T, SIZE>` marker functions in profiling tools.

This allows developers to identify expensive move/copy operations in their code using standard profiling tools, without requiring specialized tooling or runtime instrumentation.

The implementation works at codegen time. When processing MIR operands (`Operand::Move` and `Operand::Copy`), the codegen creates an `OperandRef` with an optional `move_annotation` field containing an `Instance` of the appropriate profiling marker function. When storing the operand, `store_with_annotation()` wraps the store operation in a synthetic debug scope that makes it appear inlined from the marker.

Two marker functions (`compiler_move` and `compiler_copy`) are defined in `library/core/src/profiling.rs`. These are never actually called - they exist solely as debug info anchors.

Operations are only annotated if:
   - We're generating debug info and the feature is enabled.
   - Meets the size threshold (default: 65 bytes, configurable via `-Zannotate-moves=SIZE`), and is non-zero
   - Has a memory representation

This has a very small size impact on object file size. With the default limit it's well under 0.1%, and even with a very small limit of 8 bytes it's still ~1.5%. This could be enabled by default.
2025-11-08 07:57:14 +00:00
..
alloc Rollup merge of #147808 - hkBst:btree-3, r=joboet 2025-11-07 00:21:19 -05:00
alloctests Rollup merge of #147808 - hkBst:btree-3, r=joboet 2025-11-07 00:21:19 -05:00
backtrace@b65ab935fb Update the backtrace submodule 2025-06-16 07:00:13 +00:00
compiler-builtins Mark float intrinsics with no preconditions as safe 2025-09-21 20:37:51 -04:00
core Auto merge of #147803 - jsgf:move-copy-codegen, r=madsmtm,saethlin 2025-11-08 07:57:14 +00:00
coretests Revert "unicode_data refactors RUST-147622" 2025-11-03 19:53:11 +08:00
panic_abort Use core via rustc-std-workspace-core in library/panic* 2025-07-31 22:47:24 +00:00
panic_unwind Remove no longer necessary lint allow 2025-11-04 21:29:07 +00:00
portable-simd Add alignment parameter to simd_masked_{load,store} 2025-11-04 02:30:59 +05:30
proc_macro Update CURRENT_RUSTC_VERSION post-bump 2025-10-28 13:22:00 -07:00
profiler_builtins Fix profiler_builtins build script to handle full path to profiler lib 2025-04-11 16:57:38 +02:00
rtstartup Update cfg(bootstrap) 2025-07-01 10:55:49 -07:00
rustc-std-workspace-alloc Disable unit tests for stdlib packages that don't contain any 2025-07-24 09:15:28 +00:00
rustc-std-workspace-core Use core via rustc-std-workspace-core in library/panic* 2025-07-31 22:47:24 +00:00
rustc-std-workspace-std Disable unit tests for stdlib packages that don't contain any 2025-07-24 09:15:28 +00:00
std Rollup merge of #148495 - ChrisDenton:path_is_empty, r=workingjubilee 2025-11-05 10:59:20 +11:00
std_detect Rollup merge of #147586 - folkertdev:std-detect-expands-to-true, r=Amanieu 2025-11-06 14:07:16 +11:00
stdarch Merge ref '73e6c9ebd9' from rust-lang/rust 2025-11-02 14:45:26 +01:00
sysroot Add panic=immediate-abort 2025-09-21 13:12:18 -04:00
test Rollup merge of #142807 - sourcefrog:failfast, r=dtolnay 2025-09-17 14:56:41 +10:00
unwind Move wasm throw intrinsic back to unwind 2025-10-30 15:13:32 +03:00
windows_targets Rollup merge of #144399 - bjorn3:stdlib_tests_separate_packages, r=Mark-Simulacrum 2025-07-28 08:36:53 +02:00
Cargo.lock Auto merge of #147029 - neuschaefer:memchr-2.7.6, r=marcoieni 2025-11-07 21:58:38 +00:00
Cargo.toml Remove the std workspace patch for compiler-builtins 2025-08-19 18:56:35 +00:00