Skip to content

Commit 7c34fc3

Browse files
committed
Clean up TODOs and comments, improve error handling.
1 parent 84b26eb commit 7c34fc3

File tree

8 files changed

+44
-38
lines changed

8 files changed

+44
-38
lines changed

genmc-sys/build.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ mod downloading {
2626
use super::GENMC_DOWNLOAD_PATH;
2727

2828
/// The GenMC repository the we get our commit from.
29-
pub(crate) const GENMC_GITHUB_URL: &str = "https://github.com/MPI-SWS/genmc.git";
29+
pub(crate) const GENMC_GITHUB_URL: &str = "https://github.com/Patrick-6/genmc.git";
3030
/// The GenMC commit we depend on. It must be available on the specified GenMC repository.
31-
pub(crate) const GENMC_COMMIT: &str = "3438dd2c1202cd4a47ed7881d099abf23e4167ab";
31+
pub(crate) const GENMC_COMMIT: &str = "56997d85fc9c07f75431570d49ce4892b22b8e6e";
3232

3333
pub(crate) fn download_genmc() -> PathBuf {
3434
let Ok(genmc_download_path) = PathBuf::from_str(GENMC_DOWNLOAD_PATH);

genmc-sys/src/lib.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,18 +66,20 @@ mod ffi {
6666

6767
/**** \/ Result & Error types \/ ****/
6868

69+
// FIXME(genmc): Rework error handling (likely requires changes on the GenMC side).
70+
6971
#[must_use]
7072
#[derive(Debug)]
7173
struct LoadResult {
7274
is_read_opt: bool,
73-
read_value: GenmcScalar, // TODO GENMC: handle bigger values
74-
error: UniquePtr<CxxString>, // TODO GENMC: pass more error info here
75+
read_value: GenmcScalar,
76+
error: UniquePtr<CxxString>,
7577
}
7678

7779
#[must_use]
7880
#[derive(Debug)]
7981
struct StoreResult {
80-
error: UniquePtr<CxxString>, // TODO GENMC: pass more error info here
82+
error: UniquePtr<CxxString>,
8183
isCoMaxWrite: bool,
8284
}
8385

src/alloc_addresses/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ pub struct GlobalStateInner {
3333
/// sorted by address. We cannot use a `HashMap` since we can be given an address that is offset
3434
/// from the base address, and we need to find the `AllocId` it belongs to. This is not the
3535
/// *full* inverse of `base_addr`; dead allocations have been removed.
36-
/// TODO GENMC: keep dead allocations in GenMC mode?
36+
/// FIXME(genmc,dead allocs): keep dead allocations in GenMC mode?
3737
int_to_ptr_map: Vec<(u64, AllocId)>,
3838
/// The base address for each allocation. We cannot put that into
3939
/// `AllocExtra` because function pointers also have a base address, and
@@ -516,7 +516,7 @@ impl<'tcx> MiriMachine<'tcx> {
516516
let pos =
517517
global_state.int_to_ptr_map.binary_search_by_key(&addr, |(addr, _)| *addr).unwrap();
518518

519-
// TODO GENMC(DOCUMENTATION):
519+
// FIXME(genmc,dead allocs): keep dead allocations in GenMC mode?
520520
if self.data_race.as_genmc_ref().is_none() {
521521
let removed = global_state.int_to_ptr_map.remove(pos);
522522
assert_eq!(removed, (addr, dead_id)); // double-check that we removed the right thing

src/concurrency/genmc/config.rs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,11 @@ impl GenmcConfig {
2727
if trimmed_arg.is_empty() {
2828
return Ok(()); // this corresponds to "-Zmiri-genmc"
2929
}
30-
let genmc_config = genmc_config.as_mut().unwrap();
30+
let _genmc_config = genmc_config.as_mut().unwrap();
3131
let Some(trimmed_arg) = trimmed_arg.strip_prefix("-") else {
3232
return Err(format!("Invalid GenMC argument \"-Zmiri-genmc{trimmed_arg}\""));
3333
};
34-
if trimmed_arg == "symmetry-reduction" {
35-
// TODO GENMC (PERFORMANCE): maybe make this the default, have an option to turn it off instead
36-
genmc_config.params.do_symmetry_reduction = true;
37-
} else {
38-
// TODO GENMC: how to properly handle this?
39-
return Err(format!("Invalid GenMC argument: \"-Zmiri-genmc-{trimmed_arg}\""));
40-
}
41-
return Ok(());
34+
// FIXME(genmc): Add parsing for remaining parameters.
35+
return Err(format!("Invalid GenMC argument: \"-Zmiri-genmc-{trimmed_arg}\""));
4236
}
4337
}

src/concurrency/genmc/helper.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ pub fn scalar_to_genmc_scalar<'tcx>(
6363
) -> InterpResult<'tcx, GenmcScalar> {
6464
interp_ok(match scalar {
6565
rustc_const_eval::interpret::Scalar::Int(scalar_int) => {
66-
// TODO GENMC: u128 support
67-
let value: u64 = scalar_int.to_uint(scalar_int.size()).try_into().unwrap(); // TODO GENMC: doesn't work for size != 8
66+
// FIXME(genmc): 128bit atomics support
67+
let value: u64 = scalar_int.to_uint(scalar_int.size()).try_into().unwrap();
6868
GenmcScalar { value, is_init: true }
6969
}
7070
rustc_const_eval::interpret::Scalar::Ptr(_pointer, _size) =>

src/concurrency/genmc/miri_genmc.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ pub fn run_genmc_mode(
1212
tracing::info!("Miri-GenMC loop {}", rep + 1);
1313
let result = eval_entry(genmc_ctx.clone());
1414

15-
// TODO GENMC (ERROR REPORTING): we currently do this here, so we can still print the GenMC graph above
15+
// FIXME(genmc): tell GenMC to print the execution graph here (if requested by the user).
16+
1617
let return_code = result?;
1718

1819
let is_exploration_done = genmc_ctx.is_exploration_done();
@@ -33,7 +34,7 @@ pub fn run_genmc_mode(
3334
eprintln!("Number of blocked executions seen: {blocked_execution_count}");
3435
}
3536

36-
// TODO GENMC: what is an appropriate return code? (since there are possibly many)
37+
// Return the return code of the last execution.
3738
return Some(return_code);
3839
}
3940
}

src/concurrency/genmc/mod.rs

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ struct ExitStatus {
4343
pub struct GenmcCtx {
4444
handle: RefCell<UniquePtr<MiriGenMCShim>>,
4545

46-
// TODO GENMC (PERFORMANCE): could use one RefCell for all internals instead of multiple
46+
// FIXME(genmc,performance): we could use one RefCell for all internals instead of multiple
4747
thread_infos: RefCell<ThreadInfoManager>,
4848

4949
/// Some actions Miri does are allowed to cause data races.
@@ -54,6 +54,8 @@ pub struct GenmcCtx {
5454
/// The `AllocId` for globals is stable across executions, so we can use it as an identifier.
5555
global_allocations: Arc<GlobalAllocationHandler>,
5656

57+
/// The exit status of the program.
58+
/// `None` if no thread has called `exit` and the main thread isn't finished yet.
5759
exit_status: Cell<Option<ExitStatus>>,
5860
}
5961

@@ -126,9 +128,10 @@ impl GenmcCtx {
126128
let mut mc = self.handle.borrow_mut();
127129
let result = mc.as_mut().unwrap().handleExecutionEnd();
128130
if let Some(msg) = result.as_ref() {
131+
// FIXME(genmc): error handling (may need changes on GenMC side first).
129132
let msg = msg.to_string_lossy().to_string();
130133
info!("GenMC: execution ended with error \"{msg}\"");
131-
Err(msg) // TODO GENMC: add more error info here, and possibly handle this without requiring to clone the CxxString
134+
Err(msg)
132135
} else {
133136
Ok(())
134137
}
@@ -162,7 +165,7 @@ impl GenmcCtx {
162165
old_val: Option<Scalar>,
163166
) -> InterpResult<'tcx, Scalar> {
164167
info!("GenMC: atomic_load: old_val: {old_val:?}");
165-
assert!(!self.allow_data_races.get()); // TODO GENMC: handle this properly
168+
assert!(!self.allow_data_races.get()); // FIXME(genmc): ensure correct behavior whereever `allow_data_races` is used.
166169
let ordering = ordering.convert();
167170
let genmc_old_value = option_scalar_to_genmc_scalar(ecx, old_val)?;
168171
let read_value =
@@ -181,7 +184,7 @@ impl GenmcCtx {
181184
old_value: Option<Scalar>,
182185
ordering: AtomicWriteOrd,
183186
) -> InterpResult<'tcx, bool> {
184-
assert!(!self.allow_data_races.get()); // TODO GENMC: handle this properly
187+
assert!(!self.allow_data_races.get());
185188
let ordering = ordering.convert();
186189
let genmc_value = scalar_to_genmc_scalar(ecx, value)?;
187190
let genmc_old_value = option_scalar_to_genmc_scalar(ecx, old_value)?;
@@ -319,7 +322,6 @@ impl GenmcCtx {
319322
machine: &MiriMachine<'tcx>,
320323
address: Size,
321324
size: Size,
322-
// old_value: Option<Scalar>, // TODO GENMC(mixed atomic-non-atomic): is this needed?
323325
) -> InterpResult<'tcx> {
324326
info!(
325327
"GenMC: received memory_store (non-atomic): address: {:#x}, size: {}",
@@ -336,7 +338,6 @@ impl GenmcCtx {
336338
}
337339

338340
if size.bytes() <= 8 {
339-
// TODO GENMC(mixed atomic-non-atomics): anything to do here?
340341
let _is_co_max_write = self.atomic_store_impl(
341342
machine,
342343
address,
@@ -436,7 +437,6 @@ impl GenmcCtx {
436437
let pinned_mc = mc.as_mut().unwrap();
437438
pinned_mc.handleFree(genmc_tid.0, genmc_address, genmc_size);
438439

439-
// TODO GENMC (ERROR HANDLING): can this ever fail?
440440
interp_ok(())
441441
}
442442

@@ -445,11 +445,11 @@ impl GenmcCtx {
445445
pub(crate) fn handle_thread_create<'tcx>(
446446
&self,
447447
threads: &ThreadManager<'tcx>,
448-
_start_routine: crate::Pointer, // TODO GENMC: pass info to GenMC
448+
_start_routine: crate::Pointer, // FIXME(genmc): symmetry reduction will need this info
449449
_func_arg: &crate::ImmTy<'tcx>,
450450
new_thread_id: ThreadId,
451451
) -> InterpResult<'tcx> {
452-
assert!(!self.allow_data_races.get()); // TODO GENMC: handle this properly
452+
assert!(!self.allow_data_races.get());
453453
let mut thread_infos = self.thread_infos.borrow_mut();
454454

455455
let curr_thread_id = threads.active_thread();
@@ -467,7 +467,7 @@ impl GenmcCtx {
467467
active_thread_id: ThreadId,
468468
child_thread_id: ThreadId,
469469
) -> InterpResult<'tcx> {
470-
assert!(!self.allow_data_races.get()); // TODO GENMC: handle this properly
470+
assert!(!self.allow_data_races.get());
471471
let thread_infos = self.thread_infos.borrow();
472472

473473
let genmc_curr_tid = thread_infos.get_info(active_thread_id).genmc_tid;
@@ -480,7 +480,7 @@ impl GenmcCtx {
480480
}
481481

482482
pub(crate) fn handle_thread_finish<'tcx>(&self, threads: &ThreadManager<'tcx>) {
483-
assert!(!self.allow_data_races.get()); // TODO GENMC: handle this properly
483+
assert!(!self.allow_data_races.get());
484484
let curr_thread_id = threads.active_thread();
485485

486486
let thread_infos = self.thread_infos.borrow();
@@ -544,7 +544,7 @@ impl GenmcCtx {
544544
if size.bytes() > 8 {
545545
throw_unsup_format!("{UNSUPPORTED_ATOMICS_SIZE_MSG}");
546546
}
547-
assert!(!self.allow_data_races.get()); // TODO GENMC: handle this properly
547+
assert!(!self.allow_data_races.get());
548548
let thread_infos = self.thread_infos.borrow();
549549
let curr_thread_id = machine.threads.active_thread();
550550
let genmc_tid = thread_infos.get_info(curr_thread_id).genmc_tid;
@@ -571,9 +571,10 @@ impl GenmcCtx {
571571
}
572572

573573
if let Some(error) = load_result.error.as_ref() {
574+
// FIXME(genmc): error handling
574575
let msg = error.to_string_lossy().to_string();
575576
info!("GenMC: load operation returned an error: \"{msg}\"");
576-
throw_ub_format!("{}", msg); // TODO GENMC: proper error handling: find correct error here
577+
throw_ub_format!("{}", msg);
577578
}
578579

579580
info!("GenMC: load returned value: {:?}", load_result.read_value);
@@ -621,9 +622,10 @@ impl GenmcCtx {
621622
);
622623

623624
if let Some(error) = store_result.error.as_ref() {
625+
// FIXME(genmc): error handling
624626
let msg = error.to_string_lossy().to_string();
625627
info!("GenMC: store operation returned an error: \"{msg}\"");
626-
throw_ub_format!("{}", msg); // TODO GENMC: proper error handling: find correct error here
628+
throw_ub_format!("{}", msg);
627629
}
628630

629631
interp_ok(store_result.isCoMaxWrite)
@@ -635,7 +637,7 @@ impl GenmcCtx {
635637
&self,
636638
ecx: &InterpCx<'tcx, MiriMachine<'tcx>>,
637639
) -> InterpResult<'tcx, ThreadId> {
638-
assert!(!self.allow_data_races.get()); // TODO GENMC: handle this properly
640+
assert!(!self.allow_data_races.get());
639641
let thread_manager = &ecx.machine.threads;
640642
let active_thread_id = thread_manager.active_thread();
641643

@@ -674,7 +676,6 @@ impl GenmcCtx {
674676
let result =
675677
pinned_mc.scheduleNext(curr_thread_info.genmc_tid.0, curr_thread_next_instr_kind);
676678
if result >= 0 {
677-
// TODO GENMC: can we ensure this thread_id is valid?
678679
let genmc_next_thread_id = result.try_into().unwrap();
679680
let genmc_next_thread_id = GenmcThreadId(genmc_next_thread_id);
680681
let thread_infos = self.thread_infos.borrow();

src/concurrency/genmc/thread_info_manager.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ impl ThreadInfoManager {
5757
let index = self.thread_infos.len();
5858
let genmc_tid = GenmcThreadId(index.try_into().unwrap());
5959
let thread_info = ThreadInfo::new(thread_id, genmc_tid);
60-
// TODO GENMC: Document this in place where ThreadIds are created
60+
// FIXME(genmc): Document this in place where ThreadIds are created
6161
assert!(
6262
self.tid_map.insert(thread_id, genmc_tid).is_none(),
6363
"Cannot reuse thread ids: thread id {thread_id:?} already inserted"
@@ -76,6 +76,14 @@ impl ThreadInfoManager {
7676
#[must_use]
7777
pub fn get_info_genmc(&self, genmc_tid: GenmcThreadId) -> &ThreadInfo {
7878
let index: usize = genmc_tid.0.try_into().unwrap();
79-
&self.thread_infos[index]
79+
let Some(infos) = self.thread_infos.get(index) else {
80+
panic!(
81+
"GenMC returned invalid thread id: {}, existing thread ids: {}..{}",
82+
genmc_tid.0,
83+
GENMC_MAIN_THREAD_ID.0,
84+
self.thread_infos.len()
85+
);
86+
};
87+
infos
8088
}
8189
}

0 commit comments

Comments
 (0)