Skip to content

Commit 3a728bd

Browse files
Rollup merge of #79346 - tmiasko:more-names, r=jonas-schievink
Allow using `-Z fewer-names=no` to retain value names Change `-Z fewer-names` into an optional boolean flag and allow using it to either discard value names when true or retain them when false, regardless of other settings.
2 parents 3f36f92 + fafe3cd commit 3a728bd

File tree

4 files changed

+31
-8
lines changed

4 files changed

+31
-8
lines changed

compiler/rustc_interface/src/tests.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -547,7 +547,7 @@ fn test_debugging_options_tracking_hash() {
547547
tracked!(debug_macros, true);
548548
tracked!(dep_info_omit_d_target, true);
549549
tracked!(dual_proc_macros, true);
550-
tracked!(fewer_names, true);
550+
tracked!(fewer_names, Some(true));
551551
tracked!(force_overflow_checks, Some(true));
552552
tracked!(force_unstable_if_unmarked, true);
553553
tracked!(fuel, Some(("abc".to_string(), 99)));

compiler/rustc_session/src/options.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -900,7 +900,7 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options,
900900
"emits a future-incompatibility report for lints (RFC 2834)"),
901901
emit_stack_sizes: bool = (false, parse_bool, [UNTRACKED],
902902
"emit a section containing stack size metadata (default: no)"),
903-
fewer_names: bool = (false, parse_bool, [TRACKED],
903+
fewer_names: Option<bool> = (None, parse_opt_bool, [TRACKED],
904904
"reduce memory use by retaining fewer names within compilation artifacts (LLVM-IR) \
905905
(default: no)"),
906906
force_overflow_checks: Option<bool> = (None, parse_opt_bool, [TRACKED],

compiler/rustc_session/src/session.rs

+9-6
Original file line numberDiff line numberDiff line change
@@ -734,12 +734,15 @@ impl Session {
734734
self.opts.cg.panic.unwrap_or(self.target.panic_strategy)
735735
}
736736
pub fn fewer_names(&self) -> bool {
737-
let more_names = self.opts.output_types.contains_key(&OutputType::LlvmAssembly)
738-
|| self.opts.output_types.contains_key(&OutputType::Bitcode)
739-
// AddressSanitizer and MemorySanitizer use alloca name when reporting an issue.
740-
|| self.opts.debugging_opts.sanitizer.intersects(SanitizerSet::ADDRESS | SanitizerSet::MEMORY);
741-
742-
self.opts.debugging_opts.fewer_names || !more_names
737+
if let Some(fewer_names) = self.opts.debugging_opts.fewer_names {
738+
fewer_names
739+
} else {
740+
let more_names = self.opts.output_types.contains_key(&OutputType::LlvmAssembly)
741+
|| self.opts.output_types.contains_key(&OutputType::Bitcode)
742+
// AddressSanitizer and MemorySanitizer use alloca name when reporting an issue.
743+
|| self.opts.debugging_opts.sanitizer.intersects(SanitizerSet::ADDRESS | SanitizerSet::MEMORY);
744+
!more_names
745+
}
743746
}
744747

745748
pub fn unstable_options(&self) -> bool {

src/test/codegen/fewer-names.rs

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// no-system-llvm
2+
// compile-flags: -Coverflow-checks=no -O
3+
// revisions: YES NO
4+
// [YES]compile-flags: -Zfewer-names=yes
5+
// [NO] compile-flags: -Zfewer-names=no
6+
#![crate_type = "lib"]
7+
8+
#[no_mangle]
9+
pub fn sum(x: u32, y: u32) -> u32 {
10+
// YES-LABEL: define i32 @sum(i32 %0, i32 %1)
11+
// YES-NEXT: %3 = add i32 %1, %0
12+
// YES-NEXT: ret i32 %3
13+
14+
// NO-LABEL: define i32 @sum(i32 %x, i32 %y)
15+
// NO-NEXT: start:
16+
// NO-NEXT: %z = add i32 %y, %x
17+
// NO-NEXT: ret i32 %z
18+
let z = x + y;
19+
z
20+
}

0 commit comments

Comments
 (0)