Skip to content

Commit 0f72a6d

Browse files
authored
Rollup merge of #103610 - wesleywiser:thinlto_cgu1, r=michaelwoerister
Allow use of `-Clto=thin` with `-Ccodegen-units=1` in general The current logic to ignore ThinLTO when `-Ccodegen-units=1` makes sense for local ThinLTO but even in this scenario, a user may still want (non-local) ThinLTO for the purpose of optimizing dependencies into the final crate which is being compiled with 1 CGU. The previous behavior was even more confusing because if you were generating a binary (`--emit=link`), then you would get ThinLTO but if you asked for LLVM IR or bytecode, then it would silently change to using regular LTO. With this change, we only override the defaults for local ThinLTO if you ask for a single output such as LLVM IR or bytecode and in all other cases honor the requested LTO setting. r? `@michaelwoerister`
2 parents 214d6b6 + 7c6345d commit 0f72a6d

File tree

3 files changed

+11
-14
lines changed

3 files changed

+11
-14
lines changed

compiler/rustc_session/src/config.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -738,7 +738,7 @@ impl Default for Options {
738738
actually_rustdoc: false,
739739
trimmed_def_paths: TrimmedDefPaths::default(),
740740
cli_forced_codegen_units: None,
741-
cli_forced_thinlto_off: false,
741+
cli_forced_local_thinlto_off: false,
742742
remap_path_prefix: Vec::new(),
743743
real_rust_source_base_dir: None,
744744
edition: DEFAULT_EDITION,
@@ -1721,7 +1721,7 @@ fn should_override_cgus_and_disable_thinlto(
17211721
error_format: ErrorOutputType,
17221722
mut codegen_units: Option<usize>,
17231723
) -> (bool, Option<usize>) {
1724-
let mut disable_thinlto = false;
1724+
let mut disable_local_thinlto = false;
17251725
// Issue #30063: if user requests LLVM-related output to one
17261726
// particular path, disable codegen-units.
17271727
let incompatible: Vec<_> = output_types
@@ -1746,12 +1746,12 @@ fn should_override_cgus_and_disable_thinlto(
17461746
}
17471747
early_warn(error_format, "resetting to default -C codegen-units=1");
17481748
codegen_units = Some(1);
1749-
disable_thinlto = true;
1749+
disable_local_thinlto = true;
17501750
}
17511751
}
17521752
_ => {
17531753
codegen_units = Some(1);
1754-
disable_thinlto = true;
1754+
disable_local_thinlto = true;
17551755
}
17561756
}
17571757
}
@@ -1760,7 +1760,7 @@ fn should_override_cgus_and_disable_thinlto(
17601760
early_error(error_format, "value for codegen units must be a positive non-zero integer");
17611761
}
17621762

1763-
(disable_thinlto, codegen_units)
1763+
(disable_local_thinlto, codegen_units)
17641764
}
17651765

17661766
fn check_thread_count(unstable_opts: &UnstableOptions, error_format: ErrorOutputType) {
@@ -2265,7 +2265,7 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options {
22652265
let output_types = parse_output_types(&unstable_opts, matches, error_format);
22662266

22672267
let mut cg = CodegenOptions::build(matches, error_format);
2268-
let (disable_thinlto, mut codegen_units) = should_override_cgus_and_disable_thinlto(
2268+
let (disable_local_thinlto, mut codegen_units) = should_override_cgus_and_disable_thinlto(
22692269
&output_types,
22702270
matches,
22712271
error_format,
@@ -2508,7 +2508,7 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options {
25082508
actually_rustdoc: false,
25092509
trimmed_def_paths: TrimmedDefPaths::default(),
25102510
cli_forced_codegen_units: codegen_units,
2511-
cli_forced_thinlto_off: disable_thinlto,
2511+
cli_forced_local_thinlto_off: disable_local_thinlto,
25122512
remap_path_prefix,
25132513
real_rust_source_base_dir,
25142514
edition,

compiler/rustc_session/src/options.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ top_level_options!(
181181
#[rustc_lint_opt_deny_field_access("use `Session::codegen_units` instead of this field")]
182182
cli_forced_codegen_units: Option<usize> [UNTRACKED],
183183
#[rustc_lint_opt_deny_field_access("use `Session::lto` instead of this field")]
184-
cli_forced_thinlto_off: bool [UNTRACKED],
184+
cli_forced_local_thinlto_off: bool [UNTRACKED],
185185

186186
/// Remap source path prefixes in all output (messages, object files, debug, etc.).
187187
remap_path_prefix: Vec<(PathBuf, PathBuf)> [TRACKED_NO_CRATE_HASH],

compiler/rustc_session/src/session.rs

+3-6
Original file line numberDiff line numberDiff line change
@@ -1018,11 +1018,8 @@ impl Session {
10181018
return config::Lto::Fat;
10191019
}
10201020
config::LtoCli::Thin => {
1021-
return if self.opts.cli_forced_thinlto_off {
1022-
config::Lto::Fat
1023-
} else {
1024-
config::Lto::Thin
1025-
};
1021+
// The user explicitly asked for ThinLTO
1022+
return config::Lto::Thin;
10261023
}
10271024
}
10281025

@@ -1034,7 +1031,7 @@ impl Session {
10341031

10351032
// If processing command line options determined that we're incompatible
10361033
// with ThinLTO (e.g., `-C lto --emit llvm-ir`) then return that option.
1037-
if self.opts.cli_forced_thinlto_off {
1034+
if self.opts.cli_forced_local_thinlto_off {
10381035
return config::Lto::No;
10391036
}
10401037

0 commit comments

Comments
 (0)