use rustc_index::vec::IndexVec;
+use rustc_middle::ty::SymbolName;
use rustc_target::abi::call::FnAbi;
use rustc_target::abi::{Integer, Primitive};
use rustc_target::spec::{HasTargetSpec, Target};
+use crate::constant::ConstantCx;
use crate::prelude::*;
pub(crate) fn pointer_ty(tcx: TyCtxt<'_>) -> types::Type {
}
}
-pub(crate) struct FunctionCx<'m, 'clif, 'tcx> {
- pub(crate) cx: &'clif mut crate::CodegenCx<'m, 'tcx>,
+pub(crate) struct FunctionCx<'m, 'clif, 'tcx: 'm> {
+ pub(crate) cx: &'clif mut crate::CodegenCx<'tcx>,
+ pub(crate) module: &'m mut dyn Module,
pub(crate) tcx: TyCtxt<'tcx>,
pub(crate) pointer_type: Type, // Cached from module
+ pub(crate) constants_cx: ConstantCx,
pub(crate) instance: Instance<'tcx>,
+ pub(crate) symbol_name: SymbolName<'tcx>,
pub(crate) mir: &'tcx Body<'tcx>,
pub(crate) fn_abi: Option<FnAbi<'tcx, Ty<'tcx>>>,
/// When `#[track_caller]` is used, the implicit caller location is stored in this variable.
pub(crate) caller_location: Option<CValue<'tcx>>,
- /// See [`crate::optimize::code_layout`] for more information.
- pub(crate) cold_blocks: EntitySet<Block>,
-
pub(crate) clif_comments: crate::pretty_clif::CommentWriter,
pub(crate) source_info_set: indexmap::IndexSet<SourceInfo>,
let topmost = span.ctxt().outer_expn().expansion_cause().unwrap_or(span);
let caller = self.tcx.sess.source_map().lookup_char_pos(topmost.lo());
let const_loc = self.tcx.const_caller_location((
- rustc_span::symbol::Symbol::intern(&caller.file.name.to_string()),
+ rustc_span::symbol::Symbol::intern(
+ &caller.file.name.prefer_remapped().to_string_lossy(),
+ ),
caller.line as u32,
caller.col_display as u32 + 1,
));
}
pub(crate) fn triple(&self) -> &target_lexicon::Triple {
- self.cx.module.isa().triple()
+ self.module.isa().triple()
}
- pub(crate) fn anonymous_str(&mut self, prefix: &str, msg: &str) -> Value {
- use std::collections::hash_map::DefaultHasher;
- use std::hash::{Hash, Hasher};
-
- let mut hasher = DefaultHasher::new();
- msg.hash(&mut hasher);
- let msg_hash = hasher.finish();
+ pub(crate) fn anonymous_str(&mut self, msg: &str) -> Value {
let mut data_ctx = DataContext::new();
data_ctx.define(msg.as_bytes().to_vec().into_boxed_slice());
- let msg_id = self
- .cx
- .module
- .declare_data(&format!("__{}_{:08x}", prefix, msg_hash), Linkage::Local, false, false)
- .unwrap();
+ let msg_id = self.module.declare_anonymous_data(false, false).unwrap();
// Ignore DuplicateDefinition error, as the data will be the same
- let _ = self.cx.module.define_data(msg_id, &data_ctx);
+ let _ = self.module.define_data(msg_id, &data_ctx);
- let local_msg_id = self.cx.module.declare_data_in_func(msg_id, self.bcx.func);
+ let local_msg_id = self.module.declare_data_in_func(msg_id, self.bcx.func);
if self.clif_comments.enabled() {
self.add_comment(local_msg_id, msg);
}