]> git.lizzy.rs Git - rust.git/commitdiff
cleanup tcx usage and a few comments
authorRalf Jung <post@ralfj.de>
Sat, 28 Mar 2020 08:50:24 +0000 (09:50 +0100)
committerRalf Jung <post@ralfj.de>
Sat, 28 Mar 2020 08:50:24 +0000 (09:50 +0100)
src/shims/foreign_items.rs
src/shims/foreign_items/posix.rs
src/shims/foreign_items/windows.rs
src/shims/intrinsics.rs
src/shims/tls.rs

index 6827b72427fb1a4a32c5018b3ba4053ac75ebc7d..0bed688187b08e68c5246dbded72bbfe2c84e104 100644 (file)
@@ -124,7 +124,7 @@ fn emulate_foreign_item(
         };
         // Strip linker suffixes (seen on 32-bit macOS).
         let link_name = link_name.trim_end_matches("$UNIX2003");
-        let tcx = &{ this.tcx.tcx };
+        let tcx = this.tcx.tcx;
 
         // First: functions that diverge.
         let (dest, ret) = match ret {
@@ -133,8 +133,8 @@ fn emulate_foreign_item(
                 // The implementation is provided by the function with the `#[panic_handler]` attribute.
                 "panic_impl" => {
                     this.check_panic_supported()?;
-                    let panic_impl_id = this.tcx.lang_items().panic_impl().unwrap();
-                    let panic_impl_instance = ty::Instance::mono(*this.tcx, panic_impl_id);
+                    let panic_impl_id = tcx.lang_items().panic_impl().unwrap();
+                    let panic_impl_instance = ty::Instance::mono(tcx, panic_impl_id);
                     return Ok(Some(&*this.load_mir(panic_impl_instance.def, None)?));
                 }
                 | "exit"
index 85e9b88b6ec03db7b96c8127a578daa6c604df67..425fe4b1b479a3d3eb477b372a8d6075751b7491 100644 (file)
@@ -17,7 +17,6 @@ fn emulate_foreign_item_by_name(
         ret: mir::BasicBlock,
     ) -> InterpResult<'tcx, bool> {
         let this = self.eval_context_mut();
-        let tcx = &{ this.tcx.tcx };
 
         match link_name {
             // Environment related shims
@@ -65,7 +64,7 @@ fn emulate_foreign_item_by_name(
             "write" => {
                 let fd = this.read_scalar(args[0])?.to_i32()?;
                 let buf = this.read_scalar(args[1])?.not_undef()?;
-                let n = this.read_scalar(args[2])?.to_machine_usize(tcx)?;
+                let n = this.read_scalar(args[2])?.to_machine_usize(this)?;
                 trace!("Called write({:?}, {:?}, {:?})", fd, buf, n);
                 let result = if fd == 1 || fd == 2 {
                     // stdout/stderr
@@ -209,7 +208,7 @@ fn emulate_foreign_item_by_name(
             }
             "pthread_getspecific" => {
                 let key = this.force_bits(this.read_scalar(args[0])?.not_undef()?, args[0].layout.size)?;
-                let ptr = this.machine.tls.load_tls(key, tcx)?;
+                let ptr = this.machine.tls.load_tls(key, this)?;
                 this.write_scalar(ptr, dest)?;
             }
             "pthread_setspecific" => {
index a64ef0f1293522f201afcad964b891c9fba99c48..9e71ba7d90741c6f7ddc316d1bb5a51670874a3a 100644 (file)
@@ -13,7 +13,6 @@ fn emulate_foreign_item_by_name(
         _ret: mir::BasicBlock,
     ) -> InterpResult<'tcx, bool> {
         let this = self.eval_context_mut();
-        let tcx = &{ this.tcx.tcx };
 
         match link_name {
             // Windows API stubs.
@@ -160,7 +159,7 @@ fn emulate_foreign_item_by_name(
             }
             "TlsGetValue" => {
                 let key = u128::from(this.read_scalar(args[0])?.to_u32()?);
-                let ptr = this.machine.tls.load_tls(key, tcx)?;
+                let ptr = this.machine.tls.load_tls(key, this)?;
                 this.write_scalar(ptr, dest)?;
             }
             "TlsSetValue" => {
index 91371e2c9df964fa25e0500e1e58d1432804a55c..84e8cca556a1ce0bb9e01d472e920dd3bf93ca03 100644 (file)
@@ -24,13 +24,12 @@ fn call_intrinsic(
         if this.emulate_intrinsic(span, instance, args, ret)? {
             return Ok(());
         }
-        let tcx = &{ this.tcx.tcx };
         let substs = instance.substs;
 
         // All these intrinsics take raw pointers, so if we access memory directly
         // (as opposed to through a place), we have to remember to erase any tag
         // that might still hang around!
-        let intrinsic_name = &*tcx.item_name(instance.def_id()).as_str();
+        let intrinsic_name = &*this.tcx.item_name(instance.def_id()).as_str();
 
         // First handle intrinsics without return place.
         let (dest, ret) = match ret {
index 6635978cb2e37a472e61772de7ccdfd5f69143c7..461b5b3eed6a246509aa4438cb491b94d3d16c2a 100644 (file)
@@ -70,7 +70,7 @@ pub fn delete_tls_key(&mut self, key: TlsKey) -> InterpResult<'tcx> {
     }
 
     pub fn load_tls(
-        &mut self,
+        &self,
         key: TlsKey,
         cx: &impl HasDataLayout,
     ) -> InterpResult<'tcx, Scalar<Tag>> {
@@ -107,7 +107,8 @@ pub fn set_global_dtor(&mut self, dtor: ty::Instance<'tcx>, data: Scalar<Tag>) -
         Ok(())
     }
 
-    /// Returns a dtor, its argument and its index, if one is supposed to run
+    /// Returns a dtor, its argument and its index, if one is supposed to run.
+    /// `key` is the last dtors that was run; we return the *next* one after that.
     ///
     /// An optional destructor function may be associated with each key value.
     /// At thread exit, if a key value has a non-NULL destructor pointer,
@@ -191,8 +192,10 @@ fn run_tls_dtors(&mut self) -> InterpResult<'tcx> {
             // step until out of stackframes
             this.run()?;
 
+            // Fetch next dtor after `key`.
             dtor = match this.machine.tls.fetch_tls_dtor(Some(key)) {
                 dtor @ Some(_) => dtor,
+                // We ran each dtor once, start over from the beginning.
                 None => this.machine.tls.fetch_tls_dtor(None),
             };
         }