Skip to content

Commit 32b01c7

Browse files
committed
avoid computing cur_span all the time
1 parent 0ac6fd0 commit 32b01c7

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

src/librustc_mir/const_eval/eval_queries.rs

+9-3
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,10 @@ pub fn const_eval_raw_provider<'tcx>(
317317
if is_static {
318318
// Ensure that if the above error was either `TooGeneric` or `Reported`
319319
// an error must be reported.
320-
let v = err.report_as_error(ecx.tcx_at(), "could not evaluate static initializer");
320+
let v = err.report_as_error(
321+
ecx.tcx.at(ecx.cur_span()),
322+
"could not evaluate static initializer",
323+
);
321324

322325
// If this is `Reveal:All`, then we need to make sure an error is reported but if
323326
// this is `Reveal::UserFacing`, then it's expected that we could get a
@@ -373,13 +376,16 @@ pub fn const_eval_raw_provider<'tcx>(
373376
// anything else (array lengths, enum initializers, constant patterns) are
374377
// reported as hard errors
375378
} else {
376-
err.report_as_error(ecx.tcx_at(), "evaluation of constant value failed")
379+
err.report_as_error(
380+
ecx.tcx.at(ecx.cur_span()),
381+
"evaluation of constant value failed",
382+
)
377383
}
378384
}
379385
}
380386
} else {
381387
// use of broken constant from other crate
382-
err.report_as_error(ecx.tcx_at(), "could not evaluate constant")
388+
err.report_as_error(ecx.tcx.at(ecx.cur_span()), "could not evaluate constant")
383389
}
384390
})
385391
}

src/librustc_mir/interpret/eval_context.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,9 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
323323

324324
#[inline(always)]
325325
pub fn tcx_at(&self) -> TyCtxtAt<'tcx> {
326-
self.tcx.at(self.cur_span())
326+
// Computing the current span has a non-trivial cost, and for cycle errors
327+
// the "root span" is good enough.
328+
self.tcx.at(self.root_span)
327329
}
328330

329331
#[inline(always)]
@@ -406,7 +408,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
406408

407409
#[inline]
408410
pub fn type_is_freeze(&self, ty: Ty<'tcx>) -> bool {
409-
ty.is_freeze(self.tcx, self.param_env, self.cur_span())
411+
ty.is_freeze(self.tcx, self.param_env, self.root_span)
410412
}
411413

412414
pub fn load_mir(
@@ -889,7 +891,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
889891
// FIXME: We can hit delay_span_bug if this is an invalid const, interning finds
890892
// that problem, but we never run validation to show an error. Can we ensure
891893
// this does not happen?
892-
let val = self.tcx_at().const_eval_raw(param_env.and(gid))?;
894+
let val = self.tcx.at(self.cur_span()).const_eval_raw(param_env.and(gid))?;
893895
self.raw_const_to_mplace(val)
894896
}
895897

0 commit comments

Comments
 (0)