Skip to content

Commit

Permalink
Make profiler_runtime Option<String>
Browse files Browse the repository at this point in the history
  • Loading branch information
bogon-right committed Oct 23, 2022
1 parent 36068ca commit 04963ab
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 15 deletions.
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_ssa/src/back/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1163,7 +1163,7 @@ fn add_profiler_libraries(sess: &Session, crate_type: CrateType, linker: &mut dy
|| sess.opts.unstable_opts.profile
|| sess.opts.cg.profile_generate.enabled())
// If user doesn't provide custom profiler runtime, link default llvm profiler.
&& sess.opts.unstable_opts.profiler_runtime == "profiler_builtins"
&& sess.opts.unstable_opts.profiler_runtime.is_none()
{
link_profiler_runtime(sess, linker);
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_interface/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -770,7 +770,7 @@ fn test_unstable_options_tracking_hash() {
tracked!(profile, true);
tracked!(profile_emit, Some(PathBuf::from("abc")));
tracked!(profile_sample_use, Some(PathBuf::from("abc")));
tracked!(profiler_runtime, "abc".to_string());
tracked!(profiler_runtime, Some("abc".to_string()));
tracked!(relax_elf_relocations, Some(true));
tracked!(relro_level, Some(RelroLevel::Full));
tracked!(remap_cwd_prefix, Some(PathBuf::from("abc")));
Expand Down
18 changes: 10 additions & 8 deletions compiler/rustc_metadata/src/creader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -764,21 +764,23 @@ impl<'a> CrateLoader<'a> {
|| !(self.sess.instrument_coverage()
|| self.sess.opts.unstable_opts.profile
|| self.sess.opts.cg.profile_generate.enabled())
|| self.sess.opts.unstable_opts.profiler_runtime == "profiler_builtins"
{
return;
}

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

let name = Symbol::intern(&self.sess.opts.unstable_opts.profiler_runtime);
let name = Symbol::intern(profiler_runtime);

let Some(cnum) = self.resolve_crate(name, DUMMY_SP, CrateDepKind::Implicit) else { return; };
let data = self.cstore.get_crate_data(cnum);
let Some(cnum) = self.resolve_crate(name, DUMMY_SP, CrateDepKind::Implicit) else { return; };
let data = self.cstore.get_crate_data(cnum);

// Sanity check the loaded crate to ensure it is indeed a profiler runtime
if !data.is_profiler_runtime() {
self.sess.emit_err(NotProfilerRuntime { crate_name: name });
// Sanity check the loaded crate to ensure it is indeed a profiler runtime
if !data.is_profiler_runtime() {
self.sess.emit_err(NotProfilerRuntime { crate_name: name });
}
}
}

Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_metadata/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -601,7 +601,7 @@ pub struct CannotFindCrate {
pub missing_core: bool,
pub current_crate: String,
pub is_nightly_build: bool,
pub profiler_runtime: Symbol,
pub profiler_runtime: Option<Symbol>,
pub locator_triple: TargetTriple,
}

Expand Down Expand Up @@ -641,7 +641,7 @@ impl IntoDiagnostic<'_> for CannotFindCrate {
if self.is_nightly_build {
diag.help(rustc_errors::fluent::metadata_consider_building_std);
}
} else if self.crate_name == self.profiler_runtime {
} else if Some(self.crate_name) == self.profiler_runtime {
diag.note(rustc_errors::fluent::metadata_compiler_missing_profiler);
} else if self.crate_name.as_str().starts_with("rustc_") {
diag.help(rustc_errors::fluent::metadata_install_missing_components);
Expand Down
7 changes: 6 additions & 1 deletion compiler/rustc_metadata/src/locator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1124,7 +1124,12 @@ impl CrateError {
.clone()
.unwrap_or("<unknown>".to_string()),
is_nightly_build: sess.is_nightly_build(),
profiler_runtime: Symbol::intern(&sess.opts.unstable_opts.profiler_runtime),
profiler_runtime: sess
.opts
.unstable_opts
.profiler_runtime
.as_ref()
.map(|x| Symbol::intern(x)),
locator_triple: locator.triple,
});
}
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_session/src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1483,8 +1483,8 @@ options! {
(default based on relative source path)"),
profile_sample_use: Option<PathBuf> = (None, parse_opt_pathbuf, [TRACKED],
"use the given `.prof` file for sampled profile-guided optimization (also known as AutoFDO)"),
profiler_runtime: String = (String::from("profiler_builtins"), parse_string, [TRACKED],
"name of the profiler runtime crate to automatically inject (default: `profiler_builtins`)"),
profiler_runtime: Option<String> = (None, parse_opt_string, [TRACKED],
"name of the profiler runtime crate to automatically inject"),
query_dep_graph: bool = (false, parse_bool, [UNTRACKED],
"enable queries of the dependency graph for regression testing (default: no)"),
randomize_layout: bool = (false, parse_bool, [TRACKED],
Expand Down

0 comments on commit 04963ab

Please sign in to comment.