Skip to content

Commit

Permalink
Fix how the RUSTC_CTFE_BACKTRACE env var is gotten.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
nnethercote committed Feb 3, 2020
1 parent eed12bc commit 15dcf1f
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 1 deletion.
1 change: 1 addition & 0 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3086,6 +3086,7 @@ dependencies = [
"fmt_macros",
"graphviz",
"jobserver",
"lazy_static 1.4.0",
"log",
"measureme",
"parking_lot",
Expand Down
1 change: 1 addition & 0 deletions src/librustc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ fmt_macros = { path = "../libfmt_macros" }
graphviz = { path = "../libgraphviz" }
jobserver = "0.1"
scoped-tls = "1.0"
lazy_static = "1.3"
log = { version = "0.4", features = ["release_max_level_info", "std"] }
rustc-rayon = "0.3.0"
rustc-rayon-core = "0.3.0"
Expand Down
6 changes: 5 additions & 1 deletion src/librustc/mir/interpret/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,11 @@ impl From<ErrorHandled> for InterpErrorInfo<'tcx> {

impl<'tcx> From<InterpError<'tcx>> for InterpErrorInfo<'tcx> {
fn from(kind: InterpError<'tcx>) -> Self {
let backtrace = match env::var("RUSTC_CTFE_BACKTRACE") {
lazy_static::lazy_static! {
static ref ENV_VAR: Result<String, env::VarError> = env::var("RUSTC_CTFE_BACKTRACE");
}

let backtrace = match *ENV_VAR {
// Matching `RUST_BACKTRACE` -- we treat "0" the same as "not present".
Ok(ref val) if val != "0" => {
let mut backtrace = Backtrace::new_unresolved();
Expand Down

0 comments on commit 15dcf1f

Please sign in to comment.