Skip to content

Commit ddbf2f6

Browse files
committed
More cleanup
1 parent a5781e0 commit ddbf2f6

File tree

4 files changed

+31
-64
lines changed

4 files changed

+31
-64
lines changed

src/concurrency/genmc/dummy.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,6 @@ impl GenmcCtx {
187187
_alloc_id: AllocId,
188188
_address: Size,
189189
_size: Size,
190-
_align: Align,
191190
_kind: MemoryKind,
192191
) -> InterpResult<'tcx> {
193192
unreachable!()

src/concurrency/genmc/mod.rs

Lines changed: 5 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -484,16 +484,8 @@ impl GenmcCtx {
484484
) -> InterpResult<'tcx, u64> {
485485
let machine = &ecx.machine;
486486
let chosen_address = if memory_kind == MiriMemoryKind::Global.into() {
487-
info!("GenMC: global memory allocation: {alloc_id:?}");
488487
ecx.get_global_allocation_address(&self.global_allocations, alloc_id)?
489488
} else {
490-
// TODO GENMC: Does GenMC need to know about the kind of Memory?
491-
492-
// eprintln!(
493-
// "handle_alloc ({memory_kind:?}): Custom backtrace: {}",
494-
// std::backtrace::Backtrace::force_capture()
495-
// );
496-
// TODO GENMC: should we put this before the special handling for globals?
497489
if self.allow_data_races.get() {
498490
unreachable!(); // FIXME(genmc): can this happen and if yes, how should this be handled?
499491
}
@@ -502,31 +494,24 @@ impl GenmcCtx {
502494
let genmc_tid = thread_infos.get_info(curr_thread).genmc_tid;
503495
// GenMC doesn't support ZSTs, so we set the minimum size to 1 byte
504496
let genmc_size = size.bytes().max(1);
505-
info!(
506-
"GenMC: handle_alloc (thread: {curr_thread:?} ({genmc_tid:?}), size: {}, alignment: {alignment:?}, memory_kind: {memory_kind:?})",
507-
size.bytes()
508-
);
509497

510498
let alignment = alignment.bytes();
511499

512500
let mut mc = self.handle.borrow_mut();
513501
let pinned_mc = mc.as_mut();
514502
let chosen_address = pinned_mc.handleMalloc(genmc_tid.0, genmc_size, alignment);
515-
info!("GenMC: handle_alloc: got address '{chosen_address}' ({chosen_address:#x})");
516503

517-
// TODO GENMC:
518-
if chosen_address == 0 {
519-
throw_unsup_format!("TODO GENMC: we got address '0' from malloc");
520-
}
504+
assert_ne!(chosen_address, 0, "GenMC malloc returned nullptr.");
505+
// Non-global addresses should not be in the global address space.
521506
assert_eq!(0, chosen_address & GENMC_GLOBAL_ADDRESSES_MASK);
522507
chosen_address
523508
};
509+
524510
// Sanity check the address alignment:
525-
assert_eq!(
511+
debug_assert_eq!(
526512
0,
527513
chosen_address % alignment.bytes(),
528-
"GenMC returned address {chosen_address} == {chosen_address:#x} with lower alignment than requested ({:})!",
529-
alignment.bytes()
514+
"Allocated address {chosen_address:#x} does not have requested alignment ({alignment:?})!"
530515
);
531516

532517
interp_ok(chosen_address)
@@ -538,7 +523,6 @@ impl GenmcCtx {
538523
alloc_id: AllocId,
539524
address: Size,
540525
size: Size,
541-
align: Align,
542526
kind: MemoryKind,
543527
) -> InterpResult<'tcx> {
544528
assert_ne!(
@@ -552,10 +536,6 @@ impl GenmcCtx {
552536
let thread_infos = self.thread_infos.borrow();
553537
let curr_thread = machine.threads.active_thread();
554538
let genmc_tid = thread_infos.get_info(curr_thread).genmc_tid;
555-
info!(
556-
"GenMC: memory deallocation, thread: {curr_thread:?} ({genmc_tid:?}), address: {addr} == {addr:#x}, size: {size:?}, align: {align:?}, memory_kind: {kind:?}",
557-
addr = address.bytes()
558-
);
559539

560540
let genmc_address = address.bytes();
561541
// GenMC doesn't support ZSTs, so we set the minimum size to 1 byte
@@ -585,14 +565,9 @@ impl GenmcCtx {
585565
let genmc_parent_tid = thread_infos.get_info(curr_thread_id).genmc_tid;
586566
let genmc_new_tid = thread_infos.add_thread(new_thread_id);
587567

588-
info!(
589-
"GenMC: handling thread creation (thread {curr_thread_id:?} ({genmc_parent_tid:?}) spawned thread {new_thread_id:?} ({genmc_new_tid:?}))"
590-
);
591-
592568
let mut mc = self.handle.borrow_mut();
593569
mc.as_mut().handleThreadCreate(genmc_new_tid.0, genmc_parent_tid.0);
594570

595-
// TODO GENMC (ERROR HANDLING): can this ever fail?
596571
interp_ok(())
597572
}
598573

@@ -607,10 +582,6 @@ impl GenmcCtx {
607582
let genmc_curr_tid = thread_infos.get_info(active_thread_id).genmc_tid;
608583
let genmc_child_tid = thread_infos.get_info(child_thread_id).genmc_tid;
609584

610-
info!(
611-
"GenMC: handling thread joining (thread {active_thread_id:?} ({genmc_curr_tid:?}) joining thread {child_thread_id:?} ({genmc_child_tid:?}))"
612-
);
613-
614585
let mut mc = self.handle.borrow_mut();
615586
mc.as_mut().handleThreadJoin(genmc_curr_tid.0, genmc_child_tid.0);
616587

src/concurrency/thread.rs

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,8 @@ pub enum BlockReason {
113113
}
114114

115115
/// The state of a thread.
116-
// TODO GENMC: is this ok to be pub?
117-
pub enum ThreadState<'tcx> {
116+
// FIXME(genmc,question): is this ok to be public?
117+
pub(crate) enum ThreadState<'tcx> {
118118
/// The thread is enabled and can be executed.
119119
Enabled,
120120
/// The thread is blocked on something.
@@ -136,16 +136,16 @@ impl<'tcx> std::fmt::Debug for ThreadState<'tcx> {
136136
}
137137

138138
impl<'tcx> ThreadState<'tcx> {
139-
// TODO GENMC: is it ok if these are pub?
140-
pub fn is_enabled(&self) -> bool {
139+
// FIXME(genmc,question): is it ok for these to be public?
140+
pub(crate) fn is_enabled(&self) -> bool {
141141
matches!(self, ThreadState::Enabled)
142142
}
143143

144-
pub fn is_terminated(&self) -> bool {
144+
pub(crate) fn is_terminated(&self) -> bool {
145145
matches!(self, ThreadState::Terminated)
146146
}
147147

148-
pub fn is_blocked_on(&self, reason: BlockReason) -> bool {
148+
pub(crate) fn is_blocked_on(&self, reason: BlockReason) -> bool {
149149
matches!(*self, ThreadState::Blocked { reason: actual_reason, .. } if actual_reason == reason)
150150
}
151151
}
@@ -211,8 +211,8 @@ impl<'tcx> Thread<'tcx> {
211211
self.thread_name.as_deref()
212212
}
213213

214-
pub fn get_state(&self) -> &ThreadState<'tcx> {
215-
// TODO GENMC: should this implementation detail be exposed?
214+
// FIXME(genmc,question): is this ok to be public? (it exposes implementation details)
215+
pub(crate) fn get_state(&self) -> &ThreadState<'tcx> {
216216
&self.state
217217
}
218218

@@ -349,10 +349,10 @@ impl VisitProvenance for Frame<'_, Provenance, FrameExtra<'_>> {
349349
}
350350
}
351351

352+
// FIXME(genmc,question): is this ok to be public?
352353
/// The moment in time when a blocked thread should be woken up.
353-
// TODO GENMC: is this ok to be pub?
354354
#[derive(Debug)]
355-
pub enum Timeout {
355+
pub(crate) enum Timeout {
356356
Monotonic(Instant),
357357
RealTime(SystemTime),
358358
}
@@ -499,8 +499,11 @@ impl<'tcx> ThreadManager<'tcx> {
499499
&mut self.threads[self.active_thread].stack
500500
}
501501

502-
/// TODO GENMC: this function can probably be removed once the GenmcCtx code is finished:
503-
pub fn get_thread_stack(&self, id: ThreadId) -> &[Frame<'tcx, Provenance, FrameExtra<'tcx>>] {
502+
// FIXME(genmc,question): is this ok to exist?
503+
pub(crate) fn get_thread_stack(
504+
&self,
505+
id: ThreadId,
506+
) -> &[Frame<'tcx, Provenance, FrameExtra<'tcx>>] {
504507
&self.threads[id].stack
505508
}
506509

@@ -538,11 +541,6 @@ impl<'tcx> ThreadManager<'tcx> {
538541
self.threads.len()
539542
}
540543

541-
/// Get the total of threads that are currently enabled, i.e., could continue executing.
542-
pub fn get_enabled_thread_count(&self) -> usize {
543-
self.threads.iter().filter(|t| t.state.is_enabled()).count()
544-
}
545-
546544
/// Get the total of threads that are currently live, i.e., not yet terminated.
547545
/// (They might be blocked.)
548546
pub fn get_live_thread_count(&self) -> usize {
@@ -934,10 +932,6 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
934932
assert!(thread.stack.is_empty(), "only threads with an empty stack can be terminated");
935933
thread.state = ThreadState::Terminated;
936934

937-
// TODO GENMC (QUESTION): Can we move this down to where the GenmcCtx is?
938-
if let Some(data_race) = this.machine.data_race.as_vclocks_mut() {
939-
data_race.thread_terminated(&this.machine.threads);
940-
}
941935
// Deallocate TLS.
942936
let gone_thread = this.active_thread();
943937
{
@@ -969,10 +963,16 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
969963
}
970964
}
971965

972-
// Inform GenMC that the thread finished.
973-
// This needs to happen once all accesses to the thread are done, including freeing any TLS statics.
974-
if let Some(genmc_ctx) = this.machine.data_race.as_genmc_ref() {
975-
genmc_ctx.handle_thread_finish(&this.machine.threads);
966+
// FIXME(genmc,question): Is it correct to move this code here?
967+
match &mut this.machine.data_race {
968+
GlobalDataRaceHandler::None => {}
969+
GlobalDataRaceHandler::Vclocks(data_race) =>
970+
data_race.thread_terminated(&this.machine.threads),
971+
GlobalDataRaceHandler::Genmc(genmc_ctx) => {
972+
// Inform GenMC that the thread finished.
973+
// This needs to happen once all accesses to the thread are done, including freeing any TLS statics.
974+
genmc_ctx.handle_thread_finish(&this.machine.threads)
975+
}
976976
}
977977

978978
// Unblock joining threads.

src/machine.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1462,7 +1462,7 @@ impl<'tcx> Machine<'tcx> for MiriMachine<'tcx> {
14621462
match &machine.data_race {
14631463
GlobalDataRaceHandler::None => {}
14641464
GlobalDataRaceHandler::Genmc(genmc_ctx) =>
1465-
genmc_ctx.handle_dealloc(machine, alloc_id, ptr.addr(), size, align, kind)?,
1465+
genmc_ctx.handle_dealloc(machine, alloc_id, ptr.addr(), size, kind)?,
14661466
GlobalDataRaceHandler::Vclocks(_global_state) => {
14671467
let data_race = alloc_extra.data_race.as_vclocks_mut().unwrap();
14681468
data_race.write(
@@ -1673,7 +1673,6 @@ impl<'tcx> Machine<'tcx> for MiriMachine<'tcx> {
16731673
frame: &Frame<'tcx, Provenance, FrameExtra<'tcx>>,
16741674
local: mir::Local,
16751675
) -> InterpResult<'tcx> {
1676-
// TODO GENMC: does GenMC care about local reads/writes?
16771676
if let Some(data_race) = &frame.extra.data_race {
16781677
data_race.local_read(local, &ecx.machine);
16791678
}
@@ -1685,7 +1684,6 @@ impl<'tcx> Machine<'tcx> for MiriMachine<'tcx> {
16851684
local: mir::Local,
16861685
storage_live: bool,
16871686
) -> InterpResult<'tcx> {
1688-
// TODO GENMC: does GenMC care about local reads/writes?
16891687
if let Some(data_race) = &ecx.frame().extra.data_race {
16901688
data_race.local_write(local, storage_live, &ecx.machine);
16911689
}
@@ -1715,7 +1713,6 @@ impl<'tcx> Machine<'tcx> for MiriMachine<'tcx> {
17151713
machine,
17161714
);
17171715
}
1718-
// TODO GENMC: how to handle this (if at all)?
17191716
interp_ok(())
17201717
}
17211718

0 commit comments

Comments
 (0)