Skip to content

Commit 96dd30a

Browse files
authored
Rollup merge of rust-lang#108405 - Nilstrieb:lazy-crate-name-optimization-fuel, r=WaffleLapkin
Lazily compute crate name for consider_optimizing The extra query is unnecessary in the common case of not having fuel.
2 parents f5fcfcf + 7ee01b4 commit 96dd30a

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

compiler/rustc_middle/src/ty/context.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -794,8 +794,7 @@ impl<'tcx> TyCtxt<'tcx> {
794794
}
795795

796796
pub fn consider_optimizing<T: Fn() -> String>(self, msg: T) -> bool {
797-
let cname = self.crate_name(LOCAL_CRATE);
798-
self.sess.consider_optimizing(cname.as_str(), msg)
797+
self.sess.consider_optimizing(|| self.crate_name(LOCAL_CRATE), msg)
799798
}
800799

801800
/// Obtain all lang items of this crate and all dependencies (recursively)

compiler/rustc_session/src/session.rs

+7-3
Original file line numberDiff line numberDiff line change
@@ -882,10 +882,14 @@ impl Session {
882882

883883
/// We want to know if we're allowed to do an optimization for crate foo from -z fuel=foo=n.
884884
/// This expends fuel if applicable, and records fuel if applicable.
885-
pub fn consider_optimizing<T: Fn() -> String>(&self, crate_name: &str, msg: T) -> bool {
885+
pub fn consider_optimizing(
886+
&self,
887+
get_crate_name: impl Fn() -> Symbol,
888+
msg: impl Fn() -> String,
889+
) -> bool {
886890
let mut ret = true;
887891
if let Some((ref c, _)) = self.opts.unstable_opts.fuel {
888-
if c == crate_name {
892+
if c == get_crate_name().as_str() {
889893
assert_eq!(self.threads(), 1);
890894
let mut fuel = self.optimization_fuel.lock();
891895
ret = fuel.remaining != 0;
@@ -903,7 +907,7 @@ impl Session {
903907
}
904908
}
905909
if let Some(ref c) = self.opts.unstable_opts.print_fuel {
906-
if c == crate_name {
910+
if c == get_crate_name().as_str() {
907911
assert_eq!(self.threads(), 1);
908912
self.print_fuel.fetch_add(1, SeqCst);
909913
}

0 commit comments

Comments
 (0)