Skip to content

Commit 9a4b7ff

Browse files
committed
Remove CXX NonNullUniquePtr.
1 parent ddbf2f6 commit 9a4b7ff

File tree

3 files changed

+20
-72
lines changed

3 files changed

+20
-72
lines changed

genmc-sys/src/cxx_extra.rs

Lines changed: 0 additions & 48 deletions
This file was deleted.

genmc-sys/src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
pub use self::ffi::*;
22

3-
pub mod cxx_extra;
3+
pub use cxx::UniquePtr;
4+
45

56
/// Defined in "genmc/src/Support/SAddr.hpp"
67
/// FIXME: currently we use `getGlobalAllocStaticMask()` to ensure the constant is consistent between Miri and GenMC,

src/concurrency/genmc/mod.rs

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::sync::Arc;
33

44
use genmc_sys::{
55
ActionKind, GENMC_GLOBAL_ADDRESSES_MASK, GenmcScalar, GenmcThreadId, MemOrdering,
6-
MiriGenMCShim, RMWBinOp, StoreEventType, createGenmcHandle,
6+
MiriGenMCShim, RMWBinOp, StoreEventType, UniquePtr, createGenmcHandle,
77
};
88
use rustc_abi::{Align, Size};
99
use rustc_const_eval::interpret::{AllocId, InterpCx, InterpResult, interp_ok};
@@ -45,7 +45,7 @@ struct ExitStatus {
4545
}
4646

4747
pub struct GenmcCtx {
48-
handle: RefCell<NonNullUniquePtr<MiriGenMCShim>>,
48+
handle: RefCell<UniquePtr<MiriGenMCShim>>,
4949

5050
// TODO GENMC (PERFORMANCE): could use one RefCell for all internals instead of multiple
5151
thread_infos: RefCell<ThreadInfoManager>,
@@ -66,14 +66,9 @@ impl GenmcCtx {
6666
/// Create a new `GenmcCtx` from a given config.
6767
pub fn new(miri_config: &MiriConfig) -> Self {
6868
let genmc_config = miri_config.genmc_config.as_ref().unwrap();
69-
info!("GenMC: Creating new GenMC Context");
70-
71-
let handle = createGenmcHandle(&genmc_config.params);
72-
let non_null_handle = NonNullUniquePtr::new(handle).expect("GenMC should not return null");
73-
let non_null_handle = RefCell::new(non_null_handle);
74-
69+
let handle = RefCell::new(createGenmcHandle(&genmc_config.params));
7570
Self {
76-
handle: non_null_handle,
71+
handle,
7772
thread_infos: Default::default(),
7873
allow_data_races: Cell::new(false),
7974
global_allocations: Default::default(),
@@ -83,20 +78,20 @@ impl GenmcCtx {
8378

8479
pub fn get_blocked_execution_count(&self) -> u64 {
8580
let mc = self.handle.borrow();
86-
mc.as_ref().getBlockedExecutionCount()
81+
mc.as_ref().unwrap().getBlockedExecutionCount()
8782
}
8883

8984
pub fn get_explored_execution_count(&self) -> u64 {
9085
let mc = self.handle.borrow();
91-
mc.as_ref().getExploredExecutionCount()
86+
mc.as_ref().unwrap().getExploredExecutionCount()
9287
}
9388

9489
/// This function determines if we should continue exploring executions or if we are done.
9590
///
9691
/// In GenMC mode, the input program should be repeatedly executed until this function returns `true` or an error is found.
9792
pub fn is_exploration_done(&self) -> bool {
9893
let mut mc = self.handle.borrow_mut();
99-
mc.as_mut().isExplorationDone()
94+
mc.as_mut().unwrap().isExplorationDone()
10095
}
10196

10297
pub fn get_exit_status(&self) -> Option<(i32, bool)> {
@@ -121,7 +116,7 @@ impl GenmcCtx {
121116
self.exit_status.set(None);
122117

123118
let mut mc = self.handle.borrow_mut();
124-
mc.as_mut().handleExecutionStart();
119+
mc.as_mut().unwrap().handleExecutionStart();
125120
}
126121

127122
/// Inform GenMC that the program's execution has ended.
@@ -133,7 +128,7 @@ impl GenmcCtx {
133128
_ecx: &InterpCx<'tcx, MiriMachine<'tcx>>,
134129
) -> Result<(), String> {
135130
let mut mc = self.handle.borrow_mut();
136-
let result = mc.as_mut().handleExecutionEnd();
131+
let result = mc.as_mut().unwrap().handleExecutionEnd();
137132
if let Some(msg) = result.as_ref() {
138133
let msg = msg.to_string_lossy().to_string();
139134
info!("GenMC: execution ended with error \"{msg}\"");
@@ -345,7 +340,7 @@ impl GenmcCtx {
345340
let genmc_old_value = scalar_to_genmc_scalar(ecx, old_value)?;
346341

347342
let mut mc = self.handle.borrow_mut();
348-
let pinned_mc = mc.as_mut();
343+
let pinned_mc = mc.as_mut().unwrap();
349344
let cas_result = pinned_mc.handleCompareExchange(
350345
genmc_tid.0,
351346
genmc_address,
@@ -498,7 +493,7 @@ impl GenmcCtx {
498493
let alignment = alignment.bytes();
499494

500495
let mut mc = self.handle.borrow_mut();
501-
let pinned_mc = mc.as_mut();
496+
let pinned_mc = mc.as_mut().unwrap();
502497
let chosen_address = pinned_mc.handleMalloc(genmc_tid.0, genmc_size, alignment);
503498

504499
assert_ne!(chosen_address, 0, "GenMC malloc returned nullptr.");
@@ -542,7 +537,7 @@ impl GenmcCtx {
542537
let genmc_size = size.bytes().max(1);
543538

544539
let mut mc = self.handle.borrow_mut();
545-
let pinned_mc = mc.as_mut();
540+
let pinned_mc = mc.as_mut().unwrap();
546541
pinned_mc.handleFree(genmc_tid.0, genmc_address, genmc_size);
547542

548543
// TODO GENMC (ERROR HANDLING): can this ever fail?
@@ -566,7 +561,7 @@ impl GenmcCtx {
566561
let genmc_new_tid = thread_infos.add_thread(new_thread_id);
567562

568563
let mut mc = self.handle.borrow_mut();
569-
mc.as_mut().handleThreadCreate(genmc_new_tid.0, genmc_parent_tid.0);
564+
mc.as_mut().unwrap().handleThreadCreate(genmc_new_tid.0, genmc_parent_tid.0);
570565

571566
interp_ok(())
572567
}
@@ -583,7 +578,7 @@ impl GenmcCtx {
583578
let genmc_child_tid = thread_infos.get_info(child_thread_id).genmc_tid;
584579

585580
let mut mc = self.handle.borrow_mut();
586-
mc.as_mut().handleThreadJoin(genmc_curr_tid.0, genmc_child_tid.0);
581+
mc.as_mut().unwrap().handleThreadJoin(genmc_curr_tid.0, genmc_child_tid.0);
587582

588583
interp_ok(())
589584
}
@@ -603,7 +598,7 @@ impl GenmcCtx {
603598
);
604599

605600
let mut mc = self.handle.borrow_mut();
606-
let pinned_mc = mc.as_mut();
601+
let pinned_mc = mc.as_mut().unwrap();
607602
pinned_mc.handleThreadFinish(genmc_tid.0, ret_val);
608603
}
609604

@@ -666,7 +661,7 @@ impl GenmcCtx {
666661
let genmc_size = size.bytes();
667662

668663
let mut mc = self.handle.borrow_mut();
669-
let pinned_mc = mc.as_mut();
664+
let pinned_mc = mc.as_mut().unwrap();
670665
let load_result = pinned_mc.handleLoad(
671666
genmc_tid.0,
672667
genmc_address,
@@ -719,7 +714,7 @@ impl GenmcCtx {
719714
);
720715

721716
let mut mc = self.handle.borrow_mut();
722-
let pinned_mc = mc.as_mut();
717+
let pinned_mc = mc.as_mut().unwrap();
723718
let store_result = pinned_mc.handleStore(
724719
genmc_tid.0,
725720
genmc_address,
@@ -838,7 +833,7 @@ impl GenmcCtx {
838833
let curr_thread_info = thread_infos.get_info(active_thread_id);
839834

840835
let mut mc = self.handle.borrow_mut();
841-
let pinned_mc = mc.as_mut();
836+
let pinned_mc = mc.as_mut().unwrap();
842837
let result =
843838
pinned_mc.scheduleNext(curr_thread_info.genmc_tid.0, curr_thread_next_instr_kind);
844839
if result >= 0 {

0 commit comments

Comments
 (0)