diff options
| author | Ralf Jung <post@ralfj.de> | 2020-06-11 09:53:38 +0200 |
|---|---|---|
| committer | Ralf Jung <post@ralfj.de> | 2020-06-12 09:43:55 +0200 |
| commit | 32b01c78d0502c8a4cc36abbe8dc3c000436df98 (patch) | |
| tree | 2862ac3fbd5d233d2d95a7a2d4222beafea7468c | |
| parent | 0ac6fd0405c2f3defa9ad8ee3d4026469fbda018 (diff) | |
avoid computing cur_span all the time
| -rw-r--r-- | src/librustc_mir/const_eval/eval_queries.rs | 12 | ||||
| -rw-r--r-- | src/librustc_mir/interpret/eval_context.rs | 8 |
2 files changed, 14 insertions, 6 deletions
diff --git a/src/librustc_mir/const_eval/eval_queries.rs b/src/librustc_mir/const_eval/eval_queries.rs index 28e77bb57cd..310b09f7163 100644 --- a/src/librustc_mir/const_eval/eval_queries.rs +++ b/src/librustc_mir/const_eval/eval_queries.rs @@ -317,7 +317,10 @@ pub fn const_eval_raw_provider<'tcx>( if is_static { // Ensure that if the above error was either `TooGeneric` or `Reported` // an error must be reported. - let v = err.report_as_error(ecx.tcx_at(), "could not evaluate static initializer"); + let v = err.report_as_error( + ecx.tcx.at(ecx.cur_span()), + "could not evaluate static initializer", + ); // If this is `Reveal:All`, then we need to make sure an error is reported but if // this is `Reveal::UserFacing`, then it's expected that we could get a @@ -373,13 +376,16 @@ pub fn const_eval_raw_provider<'tcx>( // anything else (array lengths, enum initializers, constant patterns) are // reported as hard errors } else { - err.report_as_error(ecx.tcx_at(), "evaluation of constant value failed") + err.report_as_error( + ecx.tcx.at(ecx.cur_span()), + "evaluation of constant value failed", + ) } } } } else { // use of broken constant from other crate - err.report_as_error(ecx.tcx_at(), "could not evaluate constant") + err.report_as_error(ecx.tcx.at(ecx.cur_span()), "could not evaluate constant") } }) } diff --git a/src/librustc_mir/interpret/eval_context.rs b/src/librustc_mir/interpret/eval_context.rs index 47e791854df..866cdce7b77 100644 --- a/src/librustc_mir/interpret/eval_context.rs +++ b/src/librustc_mir/interpret/eval_context.rs @@ -323,7 +323,9 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { #[inline(always)] pub fn tcx_at(&self) -> TyCtxtAt<'tcx> { - self.tcx.at(self.cur_span()) + // Computing the current span has a non-trivial cost, and for cycle errors + // the "root span" is good enough. + self.tcx.at(self.root_span) } #[inline(always)] @@ -406,7 +408,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { #[inline] pub fn type_is_freeze(&self, ty: Ty<'tcx>) -> bool { - ty.is_freeze(self.tcx, self.param_env, self.cur_span()) + ty.is_freeze(self.tcx, self.param_env, self.root_span) } pub fn load_mir( @@ -889,7 +891,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { // FIXME: We can hit delay_span_bug if this is an invalid const, interning finds // that problem, but we never run validation to show an error. Can we ensure // this does not happen? - let val = self.tcx_at().const_eval_raw(param_env.and(gid))?; + let val = self.tcx.at(self.cur_span()).const_eval_raw(param_env.and(gid))?; self.raw_const_to_mplace(val) } |
