Skip to content

Commit 15dcf1f

Browse files
committed
Fix how the RUSTC_CTFE_BACKTRACE env var is gotten.
This environment variable is currently obtained very frequently in CTFE-heavy code; using `lazy_static` avoids repeating the work. For the `ctfe-stress-4` benchmark this eliminates 67% of allocations done, and for `coercions` it eliminates 17% of allocations done.
1 parent eed12bc commit 15dcf1f

File tree

3 files changed

+7
-1
lines changed

3 files changed

+7
-1
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3086,6 +3086,7 @@ dependencies = [
30863086
"fmt_macros",
30873087
"graphviz",
30883088
"jobserver",
3089+
"lazy_static 1.4.0",
30893090
"log",
30903091
"measureme",
30913092
"parking_lot",

src/librustc/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ fmt_macros = { path = "../libfmt_macros" }
1616
graphviz = { path = "../libgraphviz" }
1717
jobserver = "0.1"
1818
scoped-tls = "1.0"
19+
lazy_static = "1.3"
1920
log = { version = "0.4", features = ["release_max_level_info", "std"] }
2021
rustc-rayon = "0.3.0"
2122
rustc-rayon-core = "0.3.0"

src/librustc/mir/interpret/error.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,11 @@ impl From<ErrorHandled> for InterpErrorInfo<'tcx> {
223223

224224
impl<'tcx> From<InterpError<'tcx>> for InterpErrorInfo<'tcx> {
225225
fn from(kind: InterpError<'tcx>) -> Self {
226-
let backtrace = match env::var("RUSTC_CTFE_BACKTRACE") {
226+
lazy_static::lazy_static! {
227+
static ref ENV_VAR: Result<String, env::VarError> = env::var("RUSTC_CTFE_BACKTRACE");
228+
}
229+
230+
let backtrace = match *ENV_VAR {
227231
// Matching `RUST_BACKTRACE` -- we treat "0" the same as "not present".
228232
Ok(ref val) if val != "0" => {
229233
let mut backtrace = Backtrace::new_unresolved();

0 commit comments

Comments
 (0)