From: Ralf Jung Date: Sat, 28 Mar 2020 08:50:24 +0000 (+0100) Subject: cleanup tcx usage and a few comments X-Git-Url: https://git.lizzy.rs/?a=commitdiff_plain;h=02897e03cfe6b04d28c0f3197563d1dba3f7658d;p=rust.git cleanup tcx usage and a few comments --- diff --git a/src/shims/foreign_items.rs b/src/shims/foreign_items.rs index 6827b72427f..0bed688187b 100644 --- a/src/shims/foreign_items.rs +++ b/src/shims/foreign_items.rs @@ -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" diff --git a/src/shims/foreign_items/posix.rs b/src/shims/foreign_items/posix.rs index 85e9b88b6ec..425fe4b1b47 100644 --- a/src/shims/foreign_items/posix.rs +++ b/src/shims/foreign_items/posix.rs @@ -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" => { diff --git a/src/shims/foreign_items/windows.rs b/src/shims/foreign_items/windows.rs index a64ef0f1293..9e71ba7d907 100644 --- a/src/shims/foreign_items/windows.rs +++ b/src/shims/foreign_items/windows.rs @@ -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" => { diff --git a/src/shims/intrinsics.rs b/src/shims/intrinsics.rs index 91371e2c9df..84e8cca556a 100644 --- a/src/shims/intrinsics.rs +++ b/src/shims/intrinsics.rs @@ -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 { diff --git a/src/shims/tls.rs b/src/shims/tls.rs index 6635978cb2e..461b5b3eed6 100644 --- a/src/shims/tls.rs +++ b/src/shims/tls.rs @@ -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> { @@ -107,7 +107,8 @@ pub fn set_global_dtor(&mut self, dtor: ty::Instance<'tcx>, data: Scalar) - 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), }; }