Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
wesleywiser committed Feb 17, 2020
1 parent fc23a81 commit 2c7e3b5
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 13 deletions.
34 changes: 21 additions & 13 deletions src/librustc/mir/interpret/error.rs
Expand Up @@ -4,17 +4,20 @@ use crate::hir::map::definitions::DefPathData;
use crate::mir;
use crate::ty::layout::{Align, LayoutError, Size};
use crate::ty::query::TyCtxtAt;
use crate::ty::tls;
use crate::ty::{self, layout, Ty};

use backtrace::Backtrace;
use hir::GeneratorKind;
use rustc_data_structures::sync::Lock;
use rustc_errors::{struct_span_err, DiagnosticBuilder};
use rustc_hir as hir;
use rustc_macros::HashStable;
use rustc_session::CtfeBacktrace;
use rustc_span::symbol::Symbol;
use rustc_span::{Pos, Span};
use rustc_target::spec::abi::Abi;
use std::{any::Any, env, fmt};
use std::{any::Any, fmt};

#[derive(Debug, Copy, Clone, PartialEq, Eq, HashStable, RustcEncodable, RustcDecodable)]
pub enum ErrorHandled {
Expand Down Expand Up @@ -241,21 +244,26 @@ 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") {
// Matching `RUST_BACKTRACE` -- we treat "0" the same as "not present".
Ok(ref val) if val != "0" => {
let mut backtrace = Backtrace::new_unresolved();
let capture_backtrace = tls::with_context_opt(|ctxt| {
if let Some(ctxt) = ctxt {
let l = Lock::borrow(&ctxt.tcx.sess.ctfe_backtrace);
*l
} else {
CtfeBacktrace::Disabled
}
});

if val == "immediate" {
// Print it now.
print_backtrace(&mut backtrace);
None
} else {
Some(Box::new(backtrace))
}
let backtrace = match capture_backtrace {
CtfeBacktrace::Disabled => None,
CtfeBacktrace::Capture => Some(Box::new(Backtrace::new_unresolved())),
CtfeBacktrace::Immediate => {
// Print it now.
let mut backtrace = Backtrace::new_unresolved();
print_backtrace(&mut backtrace);
None
}
_ => None,
};

InterpErrorInfo { kind, backtrace }
}
}
Expand Down
16 changes: 16 additions & 0 deletions src/librustc_session/session.rs
Expand Up @@ -49,6 +49,13 @@ pub struct OptimizationFuel {
out_of_fuel: bool,
}

#[derive(Clone, Copy)]
pub enum CtfeBacktrace {
Disabled,
Capture,
Immediate,
}

/// Represents the data associated with a compilation
/// session for a single crate.
pub struct Session {
Expand Down Expand Up @@ -136,6 +143,8 @@ pub struct Session {
/// Path for libraries that will take preference over libraries shipped by Rust.
/// Used by windows-gnu targets to priortize system mingw-w64 libraries.
pub system_library_path: OneThread<RefCell<Option<Option<PathBuf>>>>,

pub ctfe_backtrace: Lock<CtfeBacktrace>,
}

pub struct PerfStats {
Expand Down Expand Up @@ -1036,6 +1045,12 @@ fn build_session_(
sopts.debugging_opts.time_passes,
);

let ctfe_backtrace = Lock::new(match env::var("RUSTC_CTFE_BACKTRACE") {
Ok(ref val) if val == "immediate" => CtfeBacktrace::Immediate,
Ok(ref val) if val != "0" => CtfeBacktrace::Capture,
_ => CtfeBacktrace::Disabled,
});

let sess = Session {
target: target_cfg,
host,
Expand Down Expand Up @@ -1073,6 +1088,7 @@ fn build_session_(
trait_methods_not_found: Lock::new(Default::default()),
confused_type_with_std_module: Lock::new(Default::default()),
system_library_path: OneThread::new(RefCell::new(Default::default())),
ctfe_backtrace,
};

validate_commandline_args_with_session_available(&sess);
Expand Down

0 comments on commit 2c7e3b5

Please sign in to comment.