Skip to content

Commit 9e3c439

Browse files
RalfJungeddyb
authored andcommitted
we can now print on entering/leaving the topmost frame, and make sure it stays that way
1 parent 3972a05 commit 9e3c439

File tree

2 files changed

+13
-16
lines changed

2 files changed

+13
-16
lines changed

src/librustc_mir/const_eval.rs

+9-8
Original file line numberDiff line numberDiff line change
@@ -602,14 +602,15 @@ pub fn const_eval_raw_provider<'a, 'tcx>(
602602
other => return other,
603603
}
604604
}
605-
// the first trace is for replicating an ice
606-
// There's no tracking issue, but the next two lines concatenated link to the discussion on
607-
// zulip. It's not really possible to test this, because it doesn't show up in diagnostics
608-
// or MIR.
609-
// https://rust-lang.zulipchat.com/#narrow/stream/146212-t-compiler.2Fconst-eval/
610-
// subject/anon_const_instance_printing/near/135980032
611-
trace!("const eval: {}", key.value.instance);
612-
trace!("const eval: {:?}", key);
605+
if cfg!(debug_assertions) {
606+
// Make sure we format the instance even if we do not print it.
607+
// This serves as a regression test against an ICE on printing.
608+
// The next two lines concatenated contain some discussion:
609+
// https://rust-lang.zulipchat.com/#narrow/stream/146212-t-compiler.2Fconst-eval/
610+
// subject/anon_const_instance_printing/near/135980032
611+
let instance = key.value.instance.to_string();
612+
trace!("const eval: {:?} ({})", key, instance);
613+
}
613614

614615
let cid = key.value;
615616
let def_id = cid.instance.def.def_id();

src/librustc_mir/interpret/eval_context.rs

+4-8
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,7 @@ impl<'a, 'mir, 'tcx: 'mir, M: Machine<'a, 'mir, 'tcx>> EvalContext<'a, 'mir, 'tc
450450
return_place: Option<PlaceTy<'tcx, M::PointerTag>>,
451451
return_to_block: StackPopCleanup,
452452
) -> EvalResult<'tcx> {
453-
if self.stack.len() > 1 { // FIXME should be "> 0", printing topmost frame crashes rustc...
453+
if self.stack.len() > 0 {
454454
info!("PAUSING({}) {}", self.cur_frame(), self.frame().instance);
455455
}
456456
::log_settings::settings().indentation += 1;
@@ -525,9 +525,7 @@ impl<'a, 'mir, 'tcx: 'mir, M: Machine<'a, 'mir, 'tcx>> EvalContext<'a, 'mir, 'tc
525525
self.frame_mut().locals = locals;
526526
}
527527

528-
if self.stack.len() > 1 { // FIXME no check should be needed, but some instances ICE
529-
info!("ENTERING({}) {}", self.cur_frame(), self.frame().instance);
530-
}
528+
info!("ENTERING({}) {}", self.cur_frame(), self.frame().instance);
531529

532530
if self.stack.len() > self.tcx.sess.const_eval_stack_frame_limit {
533531
err!(StackFrameLimitReached)
@@ -537,9 +535,7 @@ impl<'a, 'mir, 'tcx: 'mir, M: Machine<'a, 'mir, 'tcx>> EvalContext<'a, 'mir, 'tc
537535
}
538536

539537
pub(super) fn pop_stack_frame(&mut self) -> EvalResult<'tcx> {
540-
if self.stack.len() > 1 { // FIXME no check should be needed, but some instances ICE
541-
info!("LEAVING({}) {}", self.cur_frame(), self.frame().instance);
542-
}
538+
info!("LEAVING({}) {}", self.cur_frame(), self.frame().instance);
543539
::log_settings::settings().indentation -= 1;
544540
let frame = self.stack.pop().expect(
545541
"tried to pop a stack frame, but there were none",
@@ -591,7 +587,7 @@ impl<'a, 'mir, 'tcx: 'mir, M: Machine<'a, 'mir, 'tcx>> EvalContext<'a, 'mir, 'tc
591587
StackPopCleanup::None { .. } => {}
592588
}
593589

594-
if self.stack.len() > 1 { // FIXME should be "> 0", printing topmost frame crashes rustc...
590+
if self.stack.len() > 0 {
595591
info!("CONTINUING({}) {}", self.cur_frame(), self.frame().instance);
596592
}
597593

0 commit comments

Comments
 (0)