make miri memory TyCtxtAt a TyCtxt

This commit is contained in:
Ralf Jung 2020-06-01 08:42:40 +02:00
parent e91bf6c881
commit 871513d02c
2 changed files with 11 additions and 12 deletions

View File

@ -301,7 +301,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
machine, machine,
tcx, tcx,
param_env, param_env,
memory: Memory::new(tcx, memory_extra), memory: Memory::new(*tcx, memory_extra),
vtables: FxHashMap::default(), vtables: FxHashMap::default(),
} }
} }
@ -309,7 +309,6 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
#[inline(always)] #[inline(always)]
pub fn set_span(&mut self, span: Span) { pub fn set_span(&mut self, span: Span) {
self.tcx.span = span; self.tcx.span = span;
self.memory.tcx.span = span;
} }
#[inline(always)] #[inline(always)]

View File

@ -14,7 +14,7 @@ use std::ptr;
use rustc_ast::ast::Mutability; use rustc_ast::ast::Mutability;
use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_middle::ty::{self, query::TyCtxtAt, Instance, ParamEnv}; use rustc_middle::ty::{self, TyCtxt, Instance, ParamEnv};
use rustc_target::abi::{Align, HasDataLayout, Size, TargetDataLayout}; use rustc_target::abi::{Align, HasDataLayout, Size, TargetDataLayout};
use super::{ use super::{
@ -115,7 +115,7 @@ pub struct Memory<'mir, 'tcx, M: Machine<'mir, 'tcx>> {
pub extra: M::MemoryExtra, pub extra: M::MemoryExtra,
/// Lets us implement `HasDataLayout`, which is awfully convenient. /// Lets us implement `HasDataLayout`, which is awfully convenient.
pub tcx: TyCtxtAt<'tcx>, pub tcx: TyCtxt<'tcx>,
} }
impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> HasDataLayout for Memory<'mir, 'tcx, M> { impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> HasDataLayout for Memory<'mir, 'tcx, M> {
@ -126,7 +126,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> HasDataLayout for Memory<'mir, 'tcx, M>
} }
impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> { impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
pub fn new(tcx: TyCtxtAt<'tcx>, extra: M::MemoryExtra) -> Self { pub fn new(tcx: TyCtxt<'tcx>, extra: M::MemoryExtra) -> Self {
Memory { Memory {
alloc_map: M::MemoryMap::default(), alloc_map: M::MemoryMap::default(),
extra_fn_ptr_map: FxHashMap::default(), extra_fn_ptr_map: FxHashMap::default(),
@ -425,7 +425,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
/// `M::tag_allocation`. /// `M::tag_allocation`.
fn get_global_alloc( fn get_global_alloc(
memory_extra: &M::MemoryExtra, memory_extra: &M::MemoryExtra,
tcx: TyCtxtAt<'tcx>, tcx: TyCtxt<'tcx>,
id: AllocId, id: AllocId,
is_write: bool, is_write: bool,
) -> InterpResult<'tcx, Cow<'tcx, Allocation<M::PointerTag, M::AllocExtra>>> { ) -> InterpResult<'tcx, Cow<'tcx, Allocation<M::PointerTag, M::AllocExtra>>> {
@ -455,7 +455,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
throw_unsup!(ReadForeignStatic(def_id)) throw_unsup!(ReadForeignStatic(def_id))
} }
trace!("get_global_alloc: Need to compute {:?}", def_id); trace!("get_global_alloc: Need to compute {:?}", def_id);
let instance = Instance::mono(tcx.tcx, def_id); let instance = Instance::mono(tcx, def_id);
let gid = GlobalId { instance, promoted: None }; let gid = GlobalId { instance, promoted: None };
// Use the raw query here to break validation cycles. Later uses of the static // Use the raw query here to break validation cycles. Later uses of the static
// will call the full query anyway. // will call the full query anyway.
@ -664,14 +664,14 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
pub fn dump_allocs(&self, mut allocs: Vec<AllocId>) { pub fn dump_allocs(&self, mut allocs: Vec<AllocId>) {
// Cannot be a closure because it is generic in `Tag`, `Extra`. // Cannot be a closure because it is generic in `Tag`, `Extra`.
fn write_allocation_track_relocs<'tcx, Tag: Copy + fmt::Debug, Extra>( fn write_allocation_track_relocs<'tcx, Tag: Copy + fmt::Debug, Extra>(
tcx: TyCtxtAt<'tcx>, tcx: TyCtxt<'tcx>,
allocs_to_print: &mut VecDeque<AllocId>, allocs_to_print: &mut VecDeque<AllocId>,
alloc: &Allocation<Tag, Extra>, alloc: &Allocation<Tag, Extra>,
) { ) {
for &(_, target_id) in alloc.relocations().values() { for &(_, target_id) in alloc.relocations().values() {
allocs_to_print.push_back(target_id); allocs_to_print.push_back(target_id);
} }
pretty::write_allocation(tcx.tcx, alloc, &mut std::io::stderr()).unwrap(); pretty::write_allocation(tcx, alloc, &mut std::io::stderr()).unwrap();
} }
allocs.sort(); allocs.sort();
@ -820,7 +820,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
return Ok(()); return Ok(());
} }
}; };
let tcx = self.tcx.tcx; let tcx = self.tcx;
self.get_raw_mut(ptr.alloc_id)?.write_bytes(&tcx, ptr, src) self.get_raw_mut(ptr.alloc_id)?.write_bytes(&tcx, ptr, src)
} }
@ -846,7 +846,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
return Ok(()); return Ok(());
} }
}; };
let tcx = self.tcx.tcx; let tcx = self.tcx;
let allocation = self.get_raw_mut(ptr.alloc_id)?; let allocation = self.get_raw_mut(ptr.alloc_id)?;
for idx in 0..len { for idx in 0..len {
@ -888,7 +888,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
let relocations = let relocations =
self.get_raw(src.alloc_id)?.prepare_relocation_copy(self, src, size, dest, length); self.get_raw(src.alloc_id)?.prepare_relocation_copy(self, src, size, dest, length);
let tcx = self.tcx.tcx; let tcx = self.tcx;
// This checks relocation edges on the src. // This checks relocation edges on the src.
let src_bytes = let src_bytes =