]> git.lizzy.rs Git - rust.git/commitdiff
Remove tcx parameter for EnvVars::alloc_env_value
authorChristian Poveda <christianpoveda@protonmail.com>
Wed, 14 Aug 2019 16:22:47 +0000 (11:22 -0500)
committerChristian Poveda <christianpoveda@protonmail.com>
Wed, 14 Aug 2019 18:54:57 +0000 (13:54 -0500)
src/eval.rs
src/shims/env.rs
src/shims/foreign_items.rs

index 496bcf990adc1f77f1c0383bcde8148ccc221ecf..0970edb2b75f3c0b88d0714ec803441431b5aa9a 100644 (file)
@@ -39,8 +39,10 @@ pub fn create_ecx<'mir, 'tcx: 'mir>(
         Evaluator::new(config.communicate),
         MemoryExtra::new(StdRng::seed_from_u64(config.seed.unwrap_or(0)), config.validate),
     );
+
     // Complete initialization.
-    EnvVars::init(&mut ecx, &tcx, config.communicate);
+    EnvVars::init(&mut ecx, config.communicate);
+
     // Setup first stack-frame
     let main_instance = ty::Instance::mono(ecx.tcx.tcx, main_id);
     let main_mir = ecx.load_mir(main_instance.def)?;
index d283cde8e3e9b7656db25d9c7fcb5557cd609b0d..05c5fbb0430989444c07ff391128162f9ec2f3a2 100644 (file)
@@ -1,6 +1,6 @@
 use std::collections::HashMap;
 
-use rustc::ty::{layout::{Size, Align}, TyCtxt};
+use rustc::ty::layout::{Size, Align};
 use rustc_mir::interpret::{Pointer, Memory};
 use crate::stacked_borrows::Tag;
 use crate::*;
@@ -13,12 +13,11 @@ pub struct EnvVars {
 impl EnvVars {
     pub(crate) fn init<'mir, 'tcx>(
         ecx: &mut InterpCx<'mir, 'tcx, Evaluator<'tcx>>,
-        tcx: &TyCtxt<'tcx>,
         communicate: bool,
     ) {
         if communicate {
             for (name, value) in std::env::vars() {
-                let value = alloc_env_value(value.as_bytes(), ecx.memory_mut(), tcx);
+                let value = alloc_env_value(value.as_bytes(), ecx.memory_mut());
                 ecx.machine.env_vars.map.insert(name.into_bytes(), value);
             }
         }
@@ -40,8 +39,8 @@ pub(crate) fn set(&mut self, name: Vec<u8>, ptr: Pointer<Tag>) -> Option<Pointer
 pub(crate) fn alloc_env_value<'mir, 'tcx>(
     bytes: &[u8],
     memory: &mut Memory<'mir, 'tcx, Evaluator<'tcx>>,
-    tcx: &TyCtxt<'tcx>,
 ) -> Pointer<Tag> {
+    let tcx = {memory.tcx.tcx};
     let length = bytes.len() as u64;
     // `+1` for the null terminator.
     let ptr = memory.allocate(
@@ -51,11 +50,11 @@ pub(crate) fn alloc_env_value<'mir, 'tcx>(
     );
     // We just allocated these, so the write cannot fail.
     let alloc = memory.get_mut(ptr.alloc_id).unwrap();
-    alloc.write_bytes(tcx, ptr, &bytes).unwrap();
+    alloc.write_bytes(&tcx, ptr, &bytes).unwrap();
     let trailing_zero_ptr = ptr.offset(
         Size::from_bytes(length),
-        tcx,
+        &tcx,
     ).unwrap();
-    alloc.write_bytes(tcx, trailing_zero_ptr, &[0]).unwrap();
+    alloc.write_bytes(&tcx, trailing_zero_ptr, &[0]).unwrap();
     ptr
 }
index 6705183da47f96c504562382ebf68147d75774d7..088077d5dfa2d4e3fa4a950cd293dac5adef1035 100644 (file)
@@ -466,7 +466,7 @@ fn emulate_foreign_item(
                     }
                 }
                 if let Some((name, value)) = new {
-                    let value_copy = alloc_env_value(&value, this.memory_mut(), tcx);
+                    let value_copy = alloc_env_value(&value, this.memory_mut());
                     if let Some(var) = this.machine.env_vars.set(name.to_owned(), value_copy) {
                         this.memory_mut().deallocate(var, None, MiriMemoryKind::Env.into())?;
                     }