Skip to content

Commit 972498c

Browse files
author
Jeremy Fitzhardinge
committed
Build with -Zannotate-moves by default
Build rustc and tools with -Zannotate-moves by default. Adds toml config options to set the annotation size limit. This has no measurable effect on output binary size or compile time.
1 parent 42ebbd2 commit 972498c

File tree

5 files changed

+25
-0
lines changed

5 files changed

+25
-0
lines changed

bootstrap.example.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -831,6 +831,11 @@
831831
# If an explicit setting is given, it will be used for all parts of the codebase.
832832
#rust.new-symbol-mangling = true|false (see comment)
833833

834+
# Size limit in bytes for move/copy annotations (-Zannotate-moves). Only types
835+
# at or above this size will be annotated. If not specified, uses the default
836+
# limit (65 bytes).
837+
#rust.annotate-moves-size-limit = 65
838+
834839
# Select LTO mode that will be used for compiling rustc. By default, thin local LTO
835840
# (LTO within a single crate) is used (like for any Rust crate). You can also select
836841
# "thin" or "fat" to apply Thin/Fat LTO to the `rustc_driver` dylib, or "off" to disable

src/bootstrap/src/core/builder/cargo.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -673,6 +673,16 @@ impl Builder<'_> {
673673
rustflags.arg("-Csymbol-mangling-version=legacy");
674674
}
675675

676+
// Always enable move/copy annotations for profiler visibility (non-stage0 only).
677+
// Note that -Zannotate-moves is only effective with debugging info enabled.
678+
if build_compiler_stage >= 1 {
679+
if let Some(limit) = self.config.rust_annotate_moves_size_limit {
680+
rustflags.arg(&format!("-Zannotate-moves={limit}"));
681+
} else {
682+
rustflags.arg("-Zannotate-moves");
683+
}
684+
}
685+
676686
// FIXME: the following components don't build with `-Zrandomize-layout` yet:
677687
// - rust-analyzer, due to the rowan crate
678688
// so we exclude an entire category of steps here due to lack of fine-grained control over

src/bootstrap/src/core/config/config.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,7 @@ pub struct Config {
217217
pub rust_randomize_layout: bool,
218218
pub rust_remap_debuginfo: bool,
219219
pub rust_new_symbol_mangling: Option<bool>,
220+
pub rust_annotate_moves_size_limit: Option<u64>,
220221
pub rust_profile_use: Option<String>,
221222
pub rust_profile_generate: Option<String>,
222223
pub rust_lto: RustcLto,
@@ -561,6 +562,7 @@ impl Config {
561562
control_flow_guard: rust_control_flow_guard,
562563
ehcont_guard: rust_ehcont_guard,
563564
new_symbol_mangling: rust_new_symbol_mangling,
565+
annotate_moves_size_limit: rust_annotate_moves_size_limit,
564566
profile_generate: rust_profile_generate,
565567
profile_use: rust_profile_use,
566568
download_rustc: rust_download_rustc,
@@ -1405,6 +1407,7 @@ impl Config {
14051407
reproducible_artifacts: flags_reproducible_artifact,
14061408
reuse: build_reuse.map(PathBuf::from),
14071409
rust_analyzer_info,
1410+
rust_annotate_moves_size_limit,
14081411
rust_break_on_ice: rust_break_on_ice.unwrap_or(true),
14091412
rust_codegen_backends: rust_codegen_backends
14101413
.map(|backends| parse_codegen_backends(backends, "rust"))

src/bootstrap/src/core/config/toml/rust.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ define_config! {
6060
control_flow_guard: Option<bool> = "control-flow-guard",
6161
ehcont_guard: Option<bool> = "ehcont-guard",
6262
new_symbol_mangling: Option<bool> = "new-symbol-mangling",
63+
annotate_moves_size_limit: Option<u64> = "annotate-moves-size-limit",
6364
profile_generate: Option<String> = "profile-generate",
6465
profile_use: Option<String> = "profile-use",
6566
// ignored; this is set from an env var set by bootstrap.py
@@ -364,6 +365,7 @@ pub fn check_incompatible_options_for_ci_rustc(
364365
control_flow_guard: _,
365366
ehcont_guard: _,
366367
new_symbol_mangling: _,
368+
annotate_moves_size_limit: _,
367369
profile_generate: _,
368370
profile_use: _,
369371
download_rustc: _,

src/bootstrap/src/utils/change_tracker.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -591,4 +591,9 @@ pub const CONFIG_CHANGE_HISTORY: &[ChangeInfo] = &[
591591
severity: ChangeSeverity::Info,
592592
summary: "`yarn` is now used instead of `npm` to install dependencies for some extra tidy checks. Use `build.yarn` to manually specify the path to `yarn` (`build.npm` is no longer used).",
593593
},
594+
ChangeInfo {
595+
change_id: 148803,
596+
severity: ChangeSeverity::Info,
597+
summary: "The `-Zannotate-moves` option is now always enabled when building rustc, sysroot and tools.",
598+
},
594599
];

0 commit comments

Comments
 (0)