From b5cb0f364f88b3d5d3d8c5c6f0886fa6726adde8 Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Mon, 30 Oct 2023 09:58:54 +0000 Subject: [PATCH] Turn const_caller_location from a query to a hook --- compiler/rustc_codegen_cranelift/src/common.rs | 4 ++-- compiler/rustc_codegen_ssa/src/mir/block.rs | 4 ++-- compiler/rustc_const_eval/src/const_eval/mod.rs | 9 +++++---- compiler/rustc_const_eval/src/lib.rs | 2 +- compiler/rustc_middle/src/hooks/mod.rs | 3 +++ compiler/rustc_middle/src/query/mod.rs | 4 ---- 6 files changed, 13 insertions(+), 13 deletions(-) diff --git a/compiler/rustc_codegen_cranelift/src/common.rs b/compiler/rustc_codegen_cranelift/src/common.rs index 9771f44f62cfb..bf2a5aed8afd5 100644 --- a/compiler/rustc_codegen_cranelift/src/common.rs +++ b/compiler/rustc_codegen_cranelift/src/common.rs @@ -436,13 +436,13 @@ impl<'tcx> FunctionCx<'_, '_, 'tcx> { use rustc_session::RemapFileNameExt; let topmost = span.ctxt().outer_expn().expansion_cause().unwrap_or(span); let caller = fx.tcx.sess.source_map().lookup_char_pos(topmost.lo()); - let const_loc = fx.tcx.const_caller_location(( + let const_loc = fx.tcx.const_caller_location( rustc_span::symbol::Symbol::intern( &caller.file.name.for_codegen(&fx.tcx.sess).to_string_lossy(), ), caller.line as u32, caller.col_display as u32 + 1, - )); + ); crate::constant::codegen_const_value(fx, const_loc, fx.tcx.caller_location_ty()) }; diff --git a/compiler/rustc_codegen_ssa/src/mir/block.rs b/compiler/rustc_codegen_ssa/src/mir/block.rs index caade768795f6..73f25bd599b05 100644 --- a/compiler/rustc_codegen_ssa/src/mir/block.rs +++ b/compiler/rustc_codegen_ssa/src/mir/block.rs @@ -1457,11 +1457,11 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { use rustc_session::RemapFileNameExt; let topmost = span.ctxt().outer_expn().expansion_cause().unwrap_or(span); let caller = tcx.sess.source_map().lookup_char_pos(topmost.lo()); - let const_loc = tcx.const_caller_location(( + let const_loc = tcx.const_caller_location( Symbol::intern(&caller.file.name.for_codegen(self.cx.sess()).to_string_lossy()), caller.line as u32, caller.col_display as u32 + 1, - )); + ); OperandRef::from_const(bx, const_loc, bx.tcx().caller_location_ty()) }; diff --git a/compiler/rustc_const_eval/src/const_eval/mod.rs b/compiler/rustc_const_eval/src/const_eval/mod.rs index bcbe996be7d88..47a7e3b469b32 100644 --- a/compiler/rustc_const_eval/src/const_eval/mod.rs +++ b/compiler/rustc_const_eval/src/const_eval/mod.rs @@ -21,11 +21,12 @@ pub use machine::*; pub(crate) use valtrees::{const_to_valtree_inner, valtree_to_const_value}; pub(crate) fn const_caller_location( - tcx: TyCtxt<'_>, - (file, line, col): (Symbol, u32, u32), + tcx: TyCtxtAt<'_>, + file: Symbol, + line: u32, + col: u32, ) -> mir::ConstValue<'_> { - trace!("const_caller_location: {}:{}:{}", file, line, col); - let mut ecx = mk_eval_cx(tcx, DUMMY_SP, ty::ParamEnv::reveal_all(), CanAccessStatics::No); + let mut ecx = mk_eval_cx(tcx.tcx, tcx.span, ty::ParamEnv::reveal_all(), CanAccessStatics::No); let loc_place = ecx.alloc_caller_location(file, line, col); if intern_const_alloc_recursive(&mut ecx, InternKind::Constant, &loc_place).is_err() { diff --git a/compiler/rustc_const_eval/src/lib.rs b/compiler/rustc_const_eval/src/lib.rs index 1fd5723f2775e..471d63751bd0b 100644 --- a/compiler/rustc_const_eval/src/lib.rs +++ b/compiler/rustc_const_eval/src/lib.rs @@ -49,7 +49,7 @@ pub fn provide(providers: &mut Providers) { const_eval::provide(providers); providers.eval_to_const_value_raw = const_eval::eval_to_const_value_raw_provider; providers.eval_to_allocation_raw = const_eval::eval_to_allocation_raw_provider; - providers.const_caller_location = const_eval::const_caller_location; + providers.hooks.const_caller_location = const_eval::const_caller_location; providers.eval_to_valtree = |tcx, param_env_and_value| { let (param_env, raw) = param_env_and_value.into_parts(); const_eval::eval_to_valtree(tcx, param_env, raw) diff --git a/compiler/rustc_middle/src/hooks/mod.rs b/compiler/rustc_middle/src/hooks/mod.rs index 572751d951189..34838ca4302f3 100644 --- a/compiler/rustc_middle/src/hooks/mod.rs +++ b/compiler/rustc_middle/src/hooks/mod.rs @@ -67,4 +67,7 @@ declare_hooks! { /// Tries to destructure an `mir::Const` ADT or array into its variant index /// and its field values. This should only be used for pretty printing. hook try_destructure_mir_constant_for_diagnostics(val: mir::ConstValue<'tcx>, ty: Ty<'tcx>) -> Option>; + + /// Getting a &core::panic::Location referring to a span. + hook const_caller_location(file: rustc_span::Symbol, line: u32, col: u32) -> mir::ConstValue<'tcx>; } diff --git a/compiler/rustc_middle/src/query/mod.rs b/compiler/rustc_middle/src/query/mod.rs index 062b03e71fdc1..f9ec368361c59 100644 --- a/compiler/rustc_middle/src/query/mod.rs +++ b/compiler/rustc_middle/src/query/mod.rs @@ -1101,10 +1101,6 @@ rustc_queries! { desc { "destructuring type level constant"} } - query const_caller_location(key: (rustc_span::Symbol, u32, u32)) -> mir::ConstValue<'tcx> { - desc { "getting a &core::panic::Location referring to a span" } - } - // FIXME get rid of this with valtrees query lit_to_const( key: LitToConstInput<'tcx>