Skip to content

Commit 04963ab

Browse files
author
bogon-right
committed
Make profiler_runtime Option<String>
1 parent 36068ca commit 04963ab

File tree

6 files changed

+22
-15
lines changed

6 files changed

+22
-15
lines changed

Diff for: compiler/rustc_codegen_ssa/src/back/link.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1163,7 +1163,7 @@ fn add_profiler_libraries(sess: &Session, crate_type: CrateType, linker: &mut dy
11631163
|| sess.opts.unstable_opts.profile
11641164
|| sess.opts.cg.profile_generate.enabled())
11651165
// If user doesn't provide custom profiler runtime, link default llvm profiler.
1166-
&& sess.opts.unstable_opts.profiler_runtime == "profiler_builtins"
1166+
&& sess.opts.unstable_opts.profiler_runtime.is_none()
11671167
{
11681168
link_profiler_runtime(sess, linker);
11691169
}

Diff for: compiler/rustc_interface/src/tests.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -770,7 +770,7 @@ fn test_unstable_options_tracking_hash() {
770770
tracked!(profile, true);
771771
tracked!(profile_emit, Some(PathBuf::from("abc")));
772772
tracked!(profile_sample_use, Some(PathBuf::from("abc")));
773-
tracked!(profiler_runtime, "abc".to_string());
773+
tracked!(profiler_runtime, Some("abc".to_string()));
774774
tracked!(relax_elf_relocations, Some(true));
775775
tracked!(relro_level, Some(RelroLevel::Full));
776776
tracked!(remap_cwd_prefix, Some(PathBuf::from("abc")));

Diff for: compiler/rustc_metadata/src/creader.rs

+10-8
Original file line numberDiff line numberDiff line change
@@ -764,21 +764,23 @@ impl<'a> CrateLoader<'a> {
764764
|| !(self.sess.instrument_coverage()
765765
|| self.sess.opts.unstable_opts.profile
766766
|| self.sess.opts.cg.profile_generate.enabled())
767-
|| self.sess.opts.unstable_opts.profiler_runtime == "profiler_builtins"
768767
{
769768
return;
770769
}
771770

772-
info!("loading profiler");
771+
// If user doesn't provide custom profiler runtime, skip injection.
772+
if let Some(profiler_runtime) = &self.sess.opts.unstable_opts.profiler_runtime {
773+
info!("loading profiler: {}", profiler_runtime);
773774

774-
let name = Symbol::intern(&self.sess.opts.unstable_opts.profiler_runtime);
775+
let name = Symbol::intern(profiler_runtime);
775776

776-
let Some(cnum) = self.resolve_crate(name, DUMMY_SP, CrateDepKind::Implicit) else { return; };
777-
let data = self.cstore.get_crate_data(cnum);
777+
let Some(cnum) = self.resolve_crate(name, DUMMY_SP, CrateDepKind::Implicit) else { return; };
778+
let data = self.cstore.get_crate_data(cnum);
778779

779-
// Sanity check the loaded crate to ensure it is indeed a profiler runtime
780-
if !data.is_profiler_runtime() {
781-
self.sess.emit_err(NotProfilerRuntime { crate_name: name });
780+
// Sanity check the loaded crate to ensure it is indeed a profiler runtime
781+
if !data.is_profiler_runtime() {
782+
self.sess.emit_err(NotProfilerRuntime { crate_name: name });
783+
}
782784
}
783785
}
784786

Diff for: compiler/rustc_metadata/src/errors.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -601,7 +601,7 @@ pub struct CannotFindCrate {
601601
pub missing_core: bool,
602602
pub current_crate: String,
603603
pub is_nightly_build: bool,
604-
pub profiler_runtime: Symbol,
604+
pub profiler_runtime: Option<Symbol>,
605605
pub locator_triple: TargetTriple,
606606
}
607607

@@ -641,7 +641,7 @@ impl IntoDiagnostic<'_> for CannotFindCrate {
641641
if self.is_nightly_build {
642642
diag.help(rustc_errors::fluent::metadata_consider_building_std);
643643
}
644-
} else if self.crate_name == self.profiler_runtime {
644+
} else if Some(self.crate_name) == self.profiler_runtime {
645645
diag.note(rustc_errors::fluent::metadata_compiler_missing_profiler);
646646
} else if self.crate_name.as_str().starts_with("rustc_") {
647647
diag.help(rustc_errors::fluent::metadata_install_missing_components);

Diff for: compiler/rustc_metadata/src/locator.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -1124,7 +1124,12 @@ impl CrateError {
11241124
.clone()
11251125
.unwrap_or("<unknown>".to_string()),
11261126
is_nightly_build: sess.is_nightly_build(),
1127-
profiler_runtime: Symbol::intern(&sess.opts.unstable_opts.profiler_runtime),
1127+
profiler_runtime: sess
1128+
.opts
1129+
.unstable_opts
1130+
.profiler_runtime
1131+
.as_ref()
1132+
.map(|x| Symbol::intern(x)),
11281133
locator_triple: locator.triple,
11291134
});
11301135
}

Diff for: compiler/rustc_session/src/options.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1483,8 +1483,8 @@ options! {
14831483
(default based on relative source path)"),
14841484
profile_sample_use: Option<PathBuf> = (None, parse_opt_pathbuf, [TRACKED],
14851485
"use the given `.prof` file for sampled profile-guided optimization (also known as AutoFDO)"),
1486-
profiler_runtime: String = (String::from("profiler_builtins"), parse_string, [TRACKED],
1487-
"name of the profiler runtime crate to automatically inject (default: `profiler_builtins`)"),
1486+
profiler_runtime: Option<String> = (None, parse_opt_string, [TRACKED],
1487+
"name of the profiler runtime crate to automatically inject"),
14881488
query_dep_graph: bool = (false, parse_bool, [UNTRACKED],
14891489
"enable queries of the dependency graph for regression testing (default: no)"),
14901490
randomize_layout: bool = (false, parse_bool, [TRACKED],

0 commit comments

Comments
 (0)