Skip to content

Commit 02897e0

Browse files
committed
cleanup tcx usage and a few comments
1 parent f4308a0 commit 02897e0

File tree

5 files changed

+12
-12
lines changed

5 files changed

+12
-12
lines changed

src/shims/foreign_items.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
124124
};
125125
// Strip linker suffixes (seen on 32-bit macOS).
126126
let link_name = link_name.trim_end_matches("$UNIX2003");
127-
let tcx = &{ this.tcx.tcx };
127+
let tcx = this.tcx.tcx;
128128

129129
// First: functions that diverge.
130130
let (dest, ret) = match ret {
@@ -133,8 +133,8 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
133133
// The implementation is provided by the function with the `#[panic_handler]` attribute.
134134
"panic_impl" => {
135135
this.check_panic_supported()?;
136-
let panic_impl_id = this.tcx.lang_items().panic_impl().unwrap();
137-
let panic_impl_instance = ty::Instance::mono(*this.tcx, panic_impl_id);
136+
let panic_impl_id = tcx.lang_items().panic_impl().unwrap();
137+
let panic_impl_instance = ty::Instance::mono(tcx, panic_impl_id);
138138
return Ok(Some(&*this.load_mir(panic_impl_instance.def, None)?));
139139
}
140140
| "exit"

src/shims/foreign_items/posix.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
1717
ret: mir::BasicBlock,
1818
) -> InterpResult<'tcx, bool> {
1919
let this = self.eval_context_mut();
20-
let tcx = &{ this.tcx.tcx };
2120

2221
match link_name {
2322
// Environment related shims
@@ -65,7 +64,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
6564
"write" => {
6665
let fd = this.read_scalar(args[0])?.to_i32()?;
6766
let buf = this.read_scalar(args[1])?.not_undef()?;
68-
let n = this.read_scalar(args[2])?.to_machine_usize(tcx)?;
67+
let n = this.read_scalar(args[2])?.to_machine_usize(this)?;
6968
trace!("Called write({:?}, {:?}, {:?})", fd, buf, n);
7069
let result = if fd == 1 || fd == 2 {
7170
// stdout/stderr
@@ -209,7 +208,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
209208
}
210209
"pthread_getspecific" => {
211210
let key = this.force_bits(this.read_scalar(args[0])?.not_undef()?, args[0].layout.size)?;
212-
let ptr = this.machine.tls.load_tls(key, tcx)?;
211+
let ptr = this.machine.tls.load_tls(key, this)?;
213212
this.write_scalar(ptr, dest)?;
214213
}
215214
"pthread_setspecific" => {

src/shims/foreign_items/windows.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
1313
_ret: mir::BasicBlock,
1414
) -> InterpResult<'tcx, bool> {
1515
let this = self.eval_context_mut();
16-
let tcx = &{ this.tcx.tcx };
1716

1817
match link_name {
1918
// Windows API stubs.
@@ -160,7 +159,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
160159
}
161160
"TlsGetValue" => {
162161
let key = u128::from(this.read_scalar(args[0])?.to_u32()?);
163-
let ptr = this.machine.tls.load_tls(key, tcx)?;
162+
let ptr = this.machine.tls.load_tls(key, this)?;
164163
this.write_scalar(ptr, dest)?;
165164
}
166165
"TlsSetValue" => {

src/shims/intrinsics.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,12 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
2424
if this.emulate_intrinsic(span, instance, args, ret)? {
2525
return Ok(());
2626
}
27-
let tcx = &{ this.tcx.tcx };
2827
let substs = instance.substs;
2928

3029
// All these intrinsics take raw pointers, so if we access memory directly
3130
// (as opposed to through a place), we have to remember to erase any tag
3231
// that might still hang around!
33-
let intrinsic_name = &*tcx.item_name(instance.def_id()).as_str();
32+
let intrinsic_name = &*this.tcx.item_name(instance.def_id()).as_str();
3433

3534
// First handle intrinsics without return place.
3635
let (dest, ret) = match ret {

src/shims/tls.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ impl<'tcx> TlsData<'tcx> {
7070
}
7171

7272
pub fn load_tls(
73-
&mut self,
73+
&self,
7474
key: TlsKey,
7575
cx: &impl HasDataLayout,
7676
) -> InterpResult<'tcx, Scalar<Tag>> {
@@ -107,7 +107,8 @@ impl<'tcx> TlsData<'tcx> {
107107
Ok(())
108108
}
109109

110-
/// Returns a dtor, its argument and its index, if one is supposed to run
110+
/// Returns a dtor, its argument and its index, if one is supposed to run.
111+
/// `key` is the last dtors that was run; we return the *next* one after that.
111112
///
112113
/// An optional destructor function may be associated with each key value.
113114
/// At thread exit, if a key value has a non-NULL destructor pointer,
@@ -191,8 +192,10 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
191192
// step until out of stackframes
192193
this.run()?;
193194

195+
// Fetch next dtor after `key`.
194196
dtor = match this.machine.tls.fetch_tls_dtor(Some(key)) {
195197
dtor @ Some(_) => dtor,
198+
// We ran each dtor once, start over from the beginning.
196199
None => this.machine.tls.fetch_tls_dtor(None),
197200
};
198201
}

0 commit comments

Comments
 (0)