]> git.lizzy.rs Git - rust.git/commitdiff
Auto merge of #54487 - RalfJung:ctfe-backtrace, r=oli-obk
authorbors <bors@rust-lang.org>
Sun, 28 Oct 2018 18:49:46 +0000 (18:49 +0000)
committerbors <bors@rust-lang.org>
Sun, 28 Oct 2018 18:49:46 +0000 (18:49 +0000)
Delayed CTFE backtraces

This renames the env var that controls CTFE backtraces from `MIRI_BACKTRACE` to `RUST_CTFE_BACKTRACE` so that we can use `MIRI_BACKTRACE` in the miri tool to only show backtraces of the main miri execution.

It also makes `RUST_CTFE_BACKTRACE` only show backtraces that actually get rendered as errors, instead of showing them eagerly when the `Err` happens. The current behavior is near useless in miri because it shows about one gazillion backtraces for errors that we later catch and do not care about. However, @oli-obk likes the current behavior for rustc CTFE work so it is still available via `RUST_CTFE_BACKTRACE=immediate`.

NOTE: This is based on top of https://github.com/rust-lang/rust/pull/53821. Only [the last three commits](https://github.com/oli-obk/rust/compare/sanity_query...RalfJung:ctfe-backtrace) are new.

Fixes https://github.com/rust-lang/rust/issues/53355

1  2 
src/librustc_mir/const_eval.rs

index d92001704285a84a34240e63dc5846faad6aaa0d,ee610d213e7c79e939654622752aab8ac9799258..73cb203809419a3d313d384285a010508ba4ff6e
@@@ -513,8 -513,7 +513,7 @@@ pub fn const_field<'a, 'tcx>
          op_to_const(&ecx, field, true)
      })();
      result.map_err(|error| {
-         let stacktrace = ecx.generate_stacktrace(None);
-         let err = ::rustc::mir::interpret::ConstEvalErr { error, stacktrace, span: ecx.tcx.span };
+         let err = error_to_const_error(&ecx, error);
          err.report_as_error(ecx.tcx, "could not access field of constant");
          ErrorHandled::Reported
      })
@@@ -532,6 -531,15 +531,15 @@@ pub fn const_variant_index<'a, 'tcx>
      Ok(ecx.read_discriminant(op)?.1)
  }
  
+ pub fn error_to_const_error<'a, 'mir, 'tcx>(
+     ecx: &EvalContext<'a, 'mir, 'tcx, CompileTimeInterpreter<'a, 'mir, 'tcx>>,
+     mut error: EvalError<'tcx>
+ ) -> ConstEvalErr<'tcx> {
+     error.print_backtrace();
+     let stacktrace = ecx.generate_stacktrace(None);
+     ConstEvalErr { error: error.kind, stacktrace, span: ecx.tcx.span }
+ }
  fn validate_const<'a, 'tcx>(
      tcx: ty::TyCtxt<'a, 'tcx, 'tcx>,
      constant: &'tcx ty::Const<'tcx>,
      })();
  
      val.map_err(|error| {
-         let stacktrace = ecx.generate_stacktrace(None);
-         let err = ::rustc::mir::interpret::ConstEvalErr { error, stacktrace, span: ecx.tcx.span };
+         let err = error_to_const_error(&ecx, error);
          match err.struct_error(ecx.tcx, "it is undefined behavior to use this value") {
              Ok(mut diag) => {
                  diag.note("The rules on what exactly is undefined behavior aren't clear, \
@@@ -612,13 -619,6 +619,13 @@@ pub fn const_eval_raw_provider<'a, 'tcx
              other => return other,
          }
      }
 +    // the first trace is for replicating an ice
 +    // There's no tracking issue, but the next two lines concatenated link to the discussion on
 +    // zulip. It's not really possible to test this, because it doesn't show up in diagnostics
 +    // or MIR.
 +    // https://rust-lang.zulipchat.com/#narrow/stream/146212-t-compiler.2Fconst-eval/
 +    // subject/anon_const_instance_printing/near/135980032
 +    trace!("const eval: {}", key.value.instance);
      trace!("const eval: {:?}", key);
  
      let cid = key.value;
          }
          op_to_const(&ecx, op, normalize)
      }).map_err(|error| {
-         let stacktrace = ecx.generate_stacktrace(None);
-         let err = ConstEvalErr { error, stacktrace, span: ecx.tcx.span };
+         let err = error_to_const_error(&ecx, error);
          // errors in statics are always emitted as fatal errors
          if tcx.is_static(def_id).is_some() {
              let err = err.report_as_error(ecx.tcx, "could not evaluate static initializer");
                  // any other kind of error will be reported to the user as a deny-by-default lint
                  _ => if let Some(p) = cid.promoted {
                      let span = tcx.optimized_mir(def_id).promoted[p].span;
-                     if let EvalErrorKind::ReferencedConstant = err.error.kind {
+                     if let EvalErrorKind::ReferencedConstant = err.error {
                          err.report_as_error(
                              tcx.at(span),
                              "evaluation of constant expression failed",