Skip to content

Commit 7a23496

Browse files
committed
single option
1 parent 515a676 commit 7a23496

File tree

12 files changed

+95
-30
lines changed

12 files changed

+95
-30
lines changed

compiler/rustc_mir_transform/src/annotate_moves.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ pub(crate) struct AnnotateMoves;
3838

3939
impl<'tcx> crate::MirPass<'tcx> for AnnotateMoves {
4040
fn is_enabled(&self, sess: &rustc_session::Session) -> bool {
41-
sess.opts.unstable_opts.annotate_moves && sess.opts.debuginfo != DebugInfo::None
41+
sess.opts.unstable_opts.annotate_moves.is_enabled()
42+
&& sess.opts.debuginfo != DebugInfo::None
4243
}
4344

4445
fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
@@ -52,7 +53,8 @@ impl<'tcx> crate::MirPass<'tcx> for AnnotateMoves {
5253
.sess
5354
.opts
5455
.unstable_opts
55-
.annotate_moves_size_limit
56+
.annotate_moves
57+
.size_limit()
5658
.unwrap_or(DEFAULT_ANNOTATE_MOVES_SIZE_LIMIT);
5759

5860
// Common params, including selectively borrowing the bits of Body we need to avoid

compiler/rustc_session/src/config.rs

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,29 @@ pub enum CoverageLevel {
219219
Condition,
220220
}
221221

222+
/// The different settings that the `-Z annotate-moves` flag can have.
223+
#[derive(Clone, Copy, PartialEq, Hash, Debug)]
224+
pub enum AnnotateMoves {
225+
/// `-Z annotate-moves=no` (or `off`, `false` etc.)
226+
Disabled,
227+
/// `-Z annotate-moves` or `-Z annotate-moves=yes` (use default size limit)
228+
/// `-Z annotate-moves=SIZE` (use specified size limit)
229+
Enabled(Option<u64>),
230+
}
231+
232+
impl AnnotateMoves {
233+
pub fn is_enabled(&self) -> bool {
234+
matches!(self, AnnotateMoves::Enabled(_))
235+
}
236+
237+
pub fn size_limit(&self) -> Option<u64> {
238+
match self {
239+
AnnotateMoves::Disabled => None,
240+
AnnotateMoves::Enabled(limit) => *limit,
241+
}
242+
}
243+
}
244+
222245
// The different settings that the `-Z offload` flag can have.
223246
#[derive(Clone, Copy, PartialEq, Hash, Debug)]
224247
pub enum Offload {
@@ -3227,13 +3250,13 @@ pub(crate) mod dep_tracking {
32273250
};
32283251

32293252
use super::{
3230-
AutoDiff, BranchProtection, CFGuard, CFProtection, CollapseMacroDebuginfo, CoverageOptions,
3231-
CrateType, DebugInfo, DebugInfoCompression, ErrorOutputType, FmtDebug, FunctionReturn,
3232-
InliningThreshold, InstrumentCoverage, InstrumentXRay, LinkerPluginLto, LocationDetail,
3233-
LtoCli, MirStripDebugInfo, NextSolverConfig, Offload, OomStrategy, OptLevel, OutFileName,
3234-
OutputType, OutputTypes, PatchableFunctionEntry, Polonius, RemapPathScopeComponents,
3235-
ResolveDocLinks, SourceFileHashAlgorithm, SplitDwarfKind, SwitchWithOptPath,
3236-
SymbolManglingVersion, WasiExecModel,
3253+
AnnotateMoves, AutoDiff, BranchProtection, CFGuard, CFProtection, CollapseMacroDebuginfo,
3254+
CoverageOptions, CrateType, DebugInfo, DebugInfoCompression, ErrorOutputType, FmtDebug,
3255+
FunctionReturn, InliningThreshold, InstrumentCoverage, InstrumentXRay, LinkerPluginLto,
3256+
LocationDetail, LtoCli, MirStripDebugInfo, NextSolverConfig, Offload, OomStrategy,
3257+
OptLevel, OutFileName, OutputType, OutputTypes, PatchableFunctionEntry, Polonius,
3258+
RemapPathScopeComponents, ResolveDocLinks, SourceFileHashAlgorithm, SplitDwarfKind,
3259+
SwitchWithOptPath, SymbolManglingVersion, WasiExecModel,
32373260
};
32383261
use crate::lint;
32393262
use crate::utils::NativeLib;
@@ -3276,6 +3299,7 @@ pub(crate) mod dep_tracking {
32763299

32773300
impl_dep_tracking_hash_via_hash!(
32783301
(),
3302+
AnnotateMoves,
32793303
AutoDiff,
32803304
Offload,
32813305
bool,

compiler/rustc_session/src/options.rs

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -790,6 +790,8 @@ mod desc {
790790
pub(crate) const parse_opt_langid: &str = "a language identifier";
791791
pub(crate) const parse_opt_pathbuf: &str = "a path";
792792
pub(crate) const parse_list: &str = "a space-separated list of strings";
793+
pub(crate) const parse_annotate_moves: &str =
794+
"either a boolean (`y`, `yes`, `on`, `true`, `n`, `no`, `off` or `false`), or a number";
793795
pub(crate) const parse_list_with_polarity: &str =
794796
"a comma-separated list of strings, with elements beginning with + or -";
795797
pub(crate) const parse_autodiff: &str = "a comma separated list of settings: `Enable`, `PrintSteps`, `PrintTA`, `PrintTAFn`, `PrintAA`, `PrintPerf`, `PrintModBefore`, `PrintModAfter`, `PrintModFinal`, `PrintPasses`, `NoPostopt`, `LooseTypes`, `Inline`";
@@ -1633,6 +1635,38 @@ pub mod parse {
16331635
true
16341636
}
16351637

1638+
pub(crate) fn parse_annotate_moves(slot: &mut AnnotateMoves, v: Option<&str>) -> bool {
1639+
match v {
1640+
// No value provided: -Z annotate-moves (enable with default limit)
1641+
None => {
1642+
*slot = AnnotateMoves::Enabled(None);
1643+
true
1644+
}
1645+
Some(s) => {
1646+
// Try to parse as boolean first
1647+
match s {
1648+
"y" | "yes" | "on" | "true" => {
1649+
*slot = AnnotateMoves::Enabled(None);
1650+
return true;
1651+
}
1652+
"n" | "no" | "off" | "false" => {
1653+
*slot = AnnotateMoves::Disabled;
1654+
return true;
1655+
}
1656+
_ => {}
1657+
}
1658+
1659+
// Try to parse as number (size limit)
1660+
if let Ok(size_limit) = s.parse::<u64>() {
1661+
*slot = AnnotateMoves::Enabled(Some(size_limit));
1662+
true
1663+
} else {
1664+
false
1665+
}
1666+
}
1667+
}
1668+
}
1669+
16361670
pub(crate) fn parse_lto(slot: &mut LtoCli, v: Option<&str>) -> bool {
16371671
if v.is_some() {
16381672
let mut bool_arg = None;
@@ -2384,12 +2418,9 @@ options! {
23842418
"print some statistics about AST and HIR (default: no)"),
23852419
instrument_mcount: bool = (false, parse_bool, [TRACKED],
23862420
"insert function instrument code for mcount-based tracing (default: no)"),
2387-
annotate_moves: bool = (false, parse_bool, [TRACKED],
2421+
annotate_moves: AnnotateMoves = (AnnotateMoves::Disabled, parse_annotate_moves, [TRACKED],
23882422
"emit debug info for compiler-generated move and copy operations \
2389-
to make them visible in profilers (default: no)"),
2390-
annotate_moves_size_limit: Option<u64> = (None, parse_opt_number, [TRACKED],
2391-
"the minimum size object to annotate move/copy operations \
2392-
(default: 65 bytes)"),
2423+
to make them visible in profilers. Can be a boolean or a size limit in bytes (default: disabled)"),
23932424
instrument_xray: Option<InstrumentXRay> = (None, parse_instrument_xray, [TRACKED],
23942425
"insert function instrument code for XRay-based tracing (default: no)
23952426
Optional extra settings:

src/doc/unstable-book/src/compiler-flags/annotate-moves.md

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,26 +12,34 @@ their presence in debug info makes expensive memory operations visible in profil
1212
## Syntax
1313

1414
```bash
15-
rustc -Z annotate-moves[=<boolean>]
16-
rustc -Z annotate-moves-size-limit=<bytes>
15+
rustc -Z annotate-moves[=<value>]
1716
```
1817

18+
Where `<value>` can be:
19+
- A boolean: `true`, `false`, `yes`, `no`, `on`, `off`
20+
- A number: size threshold in bytes (e.g., `128`)
21+
- Omitted: enables with default threshold (65 bytes)
22+
1923
## Options
2024

21-
- `-Z annotate-moves`: Enable/disable move/copy annotation (default: `false`)
22-
- `-Z annotate-moves-size-limit=N`: Only annotate operations on types >= N bytes (default: 65 bytes)
25+
- `-Z annotate-moves` or `-Z annotate-moves=true`: Enable with default size limit (65 bytes)
26+
- `-Z annotate-moves=false`: Disable annotation
27+
- `-Z annotate-moves=N`: Enable with custom size limit of N bytes
2328

2429
## Examples
2530

2631
```bash
27-
# Enable annotation with default threshold (pointer size)
32+
# Enable annotation with default threshold (65 bytes)
2833
rustc -Z annotate-moves main.rs
2934

3035
# Enable with custom 128-byte threshold
31-
rustc -Z annotate-moves -Z annotate-moves-size-limit=128 main.rs
36+
rustc -Z annotate-moves=128 main.rs
3237

3338
# Only annotate very large moves (1KB+)
34-
rustc -Z annotate-moves -Z annotate-moves-size-limit=1024 main.rs
39+
rustc -Z annotate-moves=1024 main.rs
40+
41+
# Explicitly disable
42+
rustc -Z annotate-moves=false main.rs
3543
```
3644

3745
## Behavior

tests/codegen-llvm/annotate-moves/annotate-moves-integration.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//@ compile-flags: -Z annotate-moves -Z annotate-moves-size-limit=50 -Copt-level=0 -g
1+
//@ compile-flags: -Z annotate-moves=50 -Copt-level=0 -g
22

33
#![crate_type = "lib"]
44

tests/codegen-llvm/annotate-moves/annotate-moves-size-limit.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//
2-
//@ compile-flags: -Z annotate-moves -Z annotate-moves-size-limit=100 -Copt-level=0 -g
2+
//@ compile-flags: -Z annotate-moves=100 -Copt-level=0 -g
33

44
#![crate_type = "lib"]
55

tests/mir-opt/annotate-moves/async.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//@ compile-flags: -Z annotate-moves -Z annotate-moves-size-limit=1 -C debuginfo=full
1+
//@ compile-flags: -Z annotate-moves=1 -C debuginfo=full
22
//@ ignore-std-debug-assertions
33
//@ edition: 2021
44

tests/mir-opt/annotate-moves/basic.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//@ compile-flags: -Z annotate-moves -Z annotate-moves-size-limit=8 -C debuginfo=full
1+
//@ compile-flags: -Z annotate-moves=8 -C debuginfo=full
22
//@ ignore-std-debug-assertions
33
//@ edition: 2021
44

tests/mir-opt/annotate-moves/iter.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//@ compile-flags: -Z annotate-moves -Z annotate-moves-size-limit=8 -C debuginfo=full
1+
//@ compile-flags: -Z annotate-moves=8 -C debuginfo=full
22
//@ ignore-std-debug-assertions
33
//@ edition: 2021
44

tests/ui/annotate-moves/annotate-moves-basic.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//@ check-pass
2-
//@ compile-flags: -Z annotate-moves -Z annotate-moves-size-limit=100
2+
//@ compile-flags: -Z annotate-moves=100
33

44
// Test that valid annotate-moves flags are accepted
55

0 commit comments

Comments
 (0)