Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
89 commits
Select commit Hold shift + click to select a range
3fc854d
WIP: Add initial support for running Miri flamegraph (no flamegraph o…
Patrick-6 Apr 14, 2025
7fcd173
WIP: Start working on Miri-GenMC interop.
Patrick-6 Mar 14, 2025
af9d846
Remove duplicate tests
Patrick-6 Jul 29, 2025
9d7e964
Clean up comments.
Patrick-6 Jul 29, 2025
1631c9d
Remove leak checks from tests where possible, fix leak check for bloc…
Patrick-6 Jul 30, 2025
d9a6629
Clean up exit handling.
Patrick-6 Jul 30, 2025
c968c94
Remove unused VerificationError enum.
Patrick-6 Jul 29, 2025
24e42d0
Simplify GenMC test includes.
Patrick-6 Jul 30, 2025
50afd6f
Inline test folders, move tests, remove extra test variants.
Patrick-6 Jul 30, 2025
e194cc8
Remove extra newline in program output
Patrick-6 Jul 30, 2025
c0f9987
Remove duplicate call to handleAlloc.
Patrick-6 Jul 30, 2025
cd5be0f
Improve comments
Patrick-6 Jul 30, 2025
8d49e29
Cleanup C++ code.
Patrick-6 Jul 30, 2025
1dba4cd
Use existing truncation function.
Patrick-6 Jul 30, 2025
69f7689
Clean up error handling and logs.
Patrick-6 Jul 30, 2025
92978f0
Clean up thread id mapping code.
Patrick-6 Jul 31, 2025
a9dbdf8
Extract address generator struct, clean up GenMC global allocator code.
Patrick-6 Aug 1, 2025
78208d8
Remove redundant test
Patrick-6 Aug 1, 2025
001d04d
Apply suggestions from code review to C++ code.
Patrick-6 Aug 1, 2025
5d4a027
Apply suggestions from code review to memory allocation code.
Patrick-6 Aug 1, 2025
5c486c4
Clean up code, tests, docs. Remove old debugging code. Add fixes for …
Patrick-6 Aug 1, 2025
1c3b639
Rebase GenMC onto config-move branch, cleanup, add documentation.
Patrick-6 Aug 17, 2025
5035978
Apply suggestions from code review, cleanup, improve error reporting,…
Patrick-6 Aug 18, 2025
17f2e83
Expand documentation and comments, clean up excution graph printing, …
Patrick-6 Aug 20, 2025
bb3db74
Add more doc comments, split off per-execution state, split off sched…
Patrick-6 Aug 20, 2025
f8cde2e
Clean up program exit and blocked execution handling.
Patrick-6 Aug 20, 2025
6925bb2
Remove loom tests, remove disabled tests.
Patrick-6 Jul 27, 2025
6336d30
Remove __VERIFIER_assume
Patrick-6 Jul 26, 2025
4b2708e
Remove Mutex handling, do cleanup.
Patrick-6 Jul 26, 2025
6425cd9
Remove code for warning about missing GenMC support
Patrick-6 Jul 26, 2025
29a24dd
Remove graph printing
Patrick-6 Jul 26, 2025
4ccc075
Remove estimation mode.
Patrick-6 Jul 26, 2025
df33e8e
Simplify scheduling and next instruction type determination, do cleanup
Patrick-6 Jul 26, 2025
8d20224
Remove atomic fence support.
Patrick-6 Jul 26, 2025
63754e4
Remove MIRI_LOG debug prints.
Patrick-6 Jul 26, 2025
c6a039c
Remove support for sending pointers to GenMC.
Patrick-6 Jul 26, 2025
645f7c9
More cleanup
Patrick-6 Jul 26, 2025
fc7fd3a
Remove CXX NonNullUniquePtr.
Patrick-6 Jul 26, 2025
19df2b3
Remove RMW / CAS support
Patrick-6 Jul 26, 2025
fcd889d
C++ code cleanup
Patrick-6 Jul 27, 2025
4081133
Remove mixed atomic-non-atomic and 'read from initial value' support.
Patrick-6 Jul 28, 2025
d80db1c
Disable genmc feature by default.
Patrick-6 Jul 29, 2025
9511e9b
Cleanup and formatting.
Patrick-6 Jul 29, 2025
91c804b
Update GenMC commit.
Patrick-6 Aug 5, 2025
b9973b1
fixup! Remove graph printing
Patrick-6 Aug 20, 2025
483544a
Fix rerun-if
Patrick-6 Aug 21, 2025
1c11a13
Remove accidentially included file.
Patrick-6 Aug 21, 2025
56a71b8
Set separate build directories for the two C++ build steps.
Patrick-6 Aug 21, 2025
dae6996
Update license to match GenMC dependency.
Patrick-6 Aug 23, 2025
52de0d8
Add newlines after every markdown header, add disclaimer about cargo …
Patrick-6 Aug 23, 2025
0310f07
Combine log level documentation into one bullet point
Patrick-6 Aug 23, 2025
f0df253
Use correct path for GenMC rebuild detection.
Patrick-6 Aug 23, 2025
e2ad56a
Remove unused operator implementation
Patrick-6 Aug 23, 2025
190f712
Remove helper macro, fix naming naming conventions.
Patrick-6 Aug 23, 2025
1b29fe4
Cleanup, fix naming conventions.
Patrick-6 Aug 23, 2025
9edc8f4
Define struct before it is used.
Patrick-6 Aug 23, 2025
8f3479d
Fix naming conventions
Patrick-6 Aug 23, 2025
b1813c4
Clean up C++ files
Patrick-6 Aug 27, 2025
545566e
Add clang-format file for C++ code in Miri. Format all C++ files.
Patrick-6 Aug 27, 2025
221f124
Make naming convention consistent for all C++ code.
Patrick-6 Aug 27, 2025
82d9a84
More naming convention fixes, add const where applicable.
Patrick-6 Aug 27, 2025
58f0757
Apply suggestions from code review.
Patrick-6 Aug 27, 2025
81d61af
Apply more suggestions from code review.
Patrick-6 Aug 27, 2025
43f481b
Upgrade CXX version, fix unused warning, minor cleanup.
Patrick-6 Aug 27, 2025
a46f795
Apply suggestions from code review
Patrick-6 Aug 29, 2025
a6d9bd0
Clean up tests, add extra checks, fix 2w2w test
Patrick-6 Aug 29, 2025
af6e8bd
Switch to InterpResult instead of panicking.
Patrick-6 Aug 29, 2025
6e1ce77
Make format command use relative paths
Patrick-6 Aug 29, 2025
eb9c697
Apply suggestions from code review, fix double type definitions betwe…
Patrick-6 Aug 29, 2025
cff2beb
Clean up test and add comments
Patrick-6 Aug 29, 2025
f232722
Inline DUMMY value, clean up non-atomic access handling, improve doc …
Patrick-6 Aug 29, 2025
b788844
Clean up execution end handling, upgrade CXX version and remove hack …
Patrick-6 Aug 30, 2025
12a2d05
Move constructor functions for Result types to C++
Patrick-6 Aug 30, 2025
541762a
Add safety comments, encapsulate possible data races due to GenMC log…
Patrick-6 Aug 30, 2025
bb1008c
Clean up tests
Patrick-6 Aug 30, 2025
fb1c43f
Apply suggestions from code review
Patrick-6 Aug 30, 2025
2168a0d
Clean up log level handling.
Patrick-6 Aug 30, 2025
7bc8044
Cleanup and add comments explaining tests, rename variants, add more …
Patrick-6 Aug 31, 2025
23863bd
Improve comment for next instruction kind detection.
Patrick-6 Aug 31, 2025
7ccf97f
downgrade GenMC logging from info to debug, minor cleanup
Patrick-6 Aug 31, 2025
9a12377
More test cleanup, fix naming and comment.
Patrick-6 Aug 31, 2025
b92c917
Fix safety comment formatting
Patrick-6 Sep 1, 2025
0b891a2
Update GenMC commit and do required changes on the Miri side.
Patrick-6 Sep 1, 2025
3654409
Switch more tests to use pthread closure API, add more correctness ch…
Patrick-6 Sep 1, 2025
a714643
Expand on comment about initial value getter.
Patrick-6 Sep 1, 2025
e456286
Switch GenMC repo
Patrick-6 Sep 1, 2025
01c05f2
Clean up remaining tests and add more correctness checks.
Patrick-6 Sep 1, 2025
04c4e38
Remove comment about GPL dependency
Patrick-6 Sep 1, 2025
6182abe
Improve comments, update default GenMC log level, fix Miri 'info' log
Patrick-6 Sep 1, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions genmc-sys/cpp/include/MiriInterface.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ using ThreadId = int;

/// Set the log level for GenMC.
///
/// # SAFETY
/// # Safety
///
/// This function is not thread safe, since it writes to the global, mutable, non-atomic `logLevel`
/// variable. Any GenMC function may read from `logLevel` unsynchronized.
/// The safest way to use this function is to set the log level exactly once before first calling
Expand All @@ -55,7 +56,8 @@ struct MiriGenmcShim : private GenMCDriver {

/// Create a new `MiriGenmcShim`, which wraps a `GenMCDriver`.
///
/// # SAFETY
/// # Safety
///
/// This function is marked as unsafe since the `logLevel` global variable is non-atomic.
/// This function should not be called in an unsynchronized way with `set_log_level_raw`, since
/// this function and any methods on the returned `MiriGenmcShim` may read the `logLevel`,
Expand Down
39 changes: 0 additions & 39 deletions genmc-sys/src/genmc.rs

This file was deleted.

40 changes: 34 additions & 6 deletions genmc-sys/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
use std::str::FromStr;
use std::sync::OnceLock;

pub use cxx::UniquePtr;

pub use self::ffi::*;

mod genmc;
pub use genmc::Genmc;

/// Defined in "genmc/src/Support/SAddr.hpp".
/// The first bit of all global addresses must be set to `1`.
/// This means the mask, interpreted as an address, is the lower bound of where the global address space starts.
Expand All @@ -20,6 +18,33 @@ pub const GENMC_GLOBAL_ADDRESSES_MASK: u64 = 1 << 63;
/// The main thread always has thread id 0.
pub const GENMC_MAIN_THREAD_ID: i32 = 0;

/// Changing GenMC's log level is not thread safe, so we limit it to only be set once to prevent any data races.
/// This value will be initialized when the first `MiriGenmcShim` is created.
static GENMC_LOG_LEVEL: OnceLock<LogLevel> = OnceLock::new();

// Create a new handle to the GenMC model checker.
// The first call to this function determines the log level of GenMC, any future call with a different log level will panic.
pub fn create_genmc_driver_handle(
params: &GenmcParams,
genmc_log_level: LogLevel,
) -> UniquePtr<MiriGenmcShim> {
// # Safety
//
// Only setting the GenMC log level once is guaranteed by the `OnceLock`.
// No other place calls `set_log_level_raw`, so the `logLevel` value in GenMC will not change once we initialize it once.
// All functions that use GenMC's `logLevel` can only be accessed in safe Rust through a `MiriGenmcShim`.
// There is no way to get `MiriGenmcShim` other than through `create_handle`, and we only call it *after* setting the log level, preventing any possible data races.
assert_eq!(
&genmc_log_level,
GENMC_LOG_LEVEL.get_or_init(|| {
unsafe { set_log_level_raw(genmc_log_level) };
genmc_log_level
}),
"Attempt to change the GenMC log level after it was already set"
);
unsafe { MiriGenmcShim::create_handle(params) }
}

impl GenmcScalar {
pub const UNINIT: Self = Self { value: 0, is_init: false };

Expand Down Expand Up @@ -166,7 +191,8 @@ mod ffi {
SequentiallyConsistent = 6,
}

// # SAFETY
// # Safety
//
// This block is unsafe to allow defining safe methods inside.
//
// `get_global_alloc_static_mask` is safe since it just returns a constant.
Expand All @@ -185,7 +211,8 @@ mod ffi {

/// Set the log level for GenMC.
///
/// # SAFETY
/// # Safety
///
/// This function is not thread safe, since it writes to the global, mutable, non-atomic `logLevel` variable.
/// Any GenMC function may read from `logLevel` unsynchronized.
/// The safest way to use this function is to set the log level exactly once before first calling `create_handle`.
Expand All @@ -194,7 +221,8 @@ mod ffi {

/// Create a new `MiriGenmcShim`, which wraps a `GenMCDriver`.
///
/// # SAFETY
/// # Safety
///
/// This function is marked as unsafe since the `logLevel` global variable is non-atomic.
/// This function should not be called in an unsynchronized way with `set_log_level_raw`, since
/// this function and any methods on the returned `MiriGenmcShim` may read the `logLevel`,
Expand Down
17 changes: 6 additions & 11 deletions src/bin/miri.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ use std::sync::atomic::{AtomicI32, AtomicU32, Ordering};

use miri::{
BacktraceStyle, BorrowTrackerMethod, GenmcConfig, GenmcCtx, MiriConfig, MiriEntryFnType,
ProvenanceMode, RetagFields, TreeBorrowsParams, ValidationMode, initialize_genmc,
run_genmc_mode,
ProvenanceMode, RetagFields, TreeBorrowsParams, ValidationMode, run_genmc_mode,
};
use rustc_abi::ExternAbi;
use rustc_data_structures::sync;
Expand Down Expand Up @@ -187,21 +186,17 @@ impl rustc_driver::Callbacks for MiriCompilerCalls {
optimizations is usually marginal at best.");
}

if let Some(genmc_config) = &config.genmc_config {
if let Some(_genmc_config) = &config.genmc_config {
let eval_entry_once = |genmc_ctx: Rc<GenmcCtx>| {
miri::eval_entry(tcx, entry_def_id, entry_type, &config, Some(genmc_ctx))
};

// Initialize GenMC by setting the log level for the entire program duration.
let genmc = initialize_genmc(genmc_config);

// FIXME(genmc): add estimation mode here.

let return_code =
run_genmc_mode(genmc, &config, eval_entry_once, tcx).unwrap_or_else(|| {
tcx.dcx().abort_if_errors();
rustc_driver::EXIT_FAILURE
});
let return_code = run_genmc_mode(&config, eval_entry_once, tcx).unwrap_or_else(|| {
tcx.dcx().abort_if_errors();
rustc_driver::EXIT_FAILURE
});

exit(return_code);
};
Expand Down
9 changes: 0 additions & 9 deletions src/concurrency/genmc/dummy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,6 @@ use crate::{
ThreadId, ThreadManager, VisitProvenance, VisitWith,
};

#[derive(Clone, Copy)]
pub struct Genmc {}

pub fn initialize_genmc(_genmc_config: &GenmcConfig) -> Genmc {
unreachable!();
}

#[derive(Clone, Copy, Debug)]
pub enum ExitType {
MainThreadFinish,
Expand All @@ -32,11 +25,9 @@ mod run {

use rustc_middle::ty::TyCtxt;

use super::Genmc;
use crate::{GenmcCtx, MiriConfig};

pub fn run_genmc_mode<'tcx>(
_genmc: Genmc,
_config: &MiriConfig,
_eval_entry: impl Fn(Rc<GenmcCtx>) -> Option<i32>,
_tcx: TyCtxt<'tcx>,
Expand Down
18 changes: 7 additions & 11 deletions src/concurrency/genmc/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
use std::cell::{Cell, RefCell};
use std::sync::Arc;

use genmc_sys::{GENMC_GLOBAL_ADDRESSES_MASK, GenmcScalar, MemOrdering, MiriGenmcShim, UniquePtr};
use genmc_sys::{
GENMC_GLOBAL_ADDRESSES_MASK, GenmcScalar, MemOrdering, MiriGenmcShim, UniquePtr,
create_genmc_driver_handle,
};
use rustc_abi::{Align, Size};
use rustc_const_eval::interpret::{AllocId, InterpCx, InterpResult, interp_ok};
use rustc_middle::{mir, throw_machine_stop, throw_ub_format, throw_unsup_format};
Expand All @@ -24,17 +27,9 @@ mod run;
pub(crate) mod scheduling;
mod thread_id_map;

pub use genmc_sys::Genmc;

pub use self::config::GenmcConfig;
pub use self::run::run_genmc_mode;

/// Initialize GenMC by setting everything required.
/// The returned `Genmc` struct is used to interact with GenMC in a safe way.
pub fn initialize_genmc(genmc_config: &GenmcConfig) -> Genmc {
Genmc::new(genmc_config.log_level)
}

#[derive(Clone, Copy, Debug)]
pub enum ExitType {
MainThreadFinish,
Expand Down Expand Up @@ -120,9 +115,10 @@ pub struct GenmcCtx {
/// GenMC Context creation and administrative / query actions
impl GenmcCtx {
/// Create a new `GenmcCtx` from a given config.
fn new(genmc: Genmc, miri_config: &MiriConfig, global_state: Arc<GlobalState>) -> Self {
fn new(miri_config: &MiriConfig, global_state: Arc<GlobalState>) -> Self {
let genmc_config = miri_config.genmc_config.as_ref().unwrap();
let handle = RefCell::new(genmc.create_driver_handle(&genmc_config.params));
let handle =
RefCell::new(create_genmc_driver_handle(&genmc_config.params, genmc_config.log_level));
Self { handle, exec_state: Default::default(), global_state }
}

Expand Down
4 changes: 1 addition & 3 deletions src/concurrency/genmc/run.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use std::rc::Rc;
use std::sync::Arc;

use genmc_sys::Genmc;
use rustc_middle::ty::TyCtxt;

use super::GlobalState;
Expand All @@ -15,7 +14,6 @@ use crate::{GenmcCtx, MiriConfig};
///
/// FIXME(genmc): add estimation mode setting.
pub fn run_genmc_mode<'tcx>(
genmc: Genmc,
config: &MiriConfig,
eval_entry: impl Fn(Rc<GenmcCtx>) -> Option<i32>,
tcx: TyCtxt<'tcx>,
Expand All @@ -24,7 +22,7 @@ pub fn run_genmc_mode<'tcx>(
// It is shared by all `GenmcCtx` in this run.
// FIXME(genmc): implement multithreading once GenMC supports it.
let global_state = Arc::new(GlobalState::new(tcx.target_usize_max()));
let genmc_ctx = Rc::new(GenmcCtx::new(genmc, config, global_state));
let genmc_ctx = Rc::new(GenmcCtx::new(config, global_state));

// `rep` is used to report the progress, Miri will panic on wrap-around.
for rep in 0u64.. {
Expand Down
2 changes: 1 addition & 1 deletion src/concurrency/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ pub mod weak_memory;
mod genmc;

pub use self::data_race_handler::{AllocDataRaceHandler, GlobalDataRaceHandler};
pub use self::genmc::{ExitType, GenmcConfig, GenmcCtx, initialize_genmc, run_genmc_mode};
pub use self::genmc::{ExitType, GenmcConfig, GenmcCtx, run_genmc_mode};
pub use self::vector_clock::VClock;
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ pub use crate::concurrency::thread::{
BlockReason, DynUnblockCallback, EvalContextExt as _, StackEmptyCallback, ThreadId,
ThreadManager, TimeoutAnchor, TimeoutClock, UnblockKind,
};
pub use crate::concurrency::{GenmcConfig, GenmcCtx, initialize_genmc, run_genmc_mode};
pub use crate::concurrency::{GenmcConfig, GenmcCtx, run_genmc_mode};
pub use crate::data_structures::dedup_range_map::DedupRangeMap;
pub use crate::data_structures::mono_hash_map::MonoHashMap;
pub use crate::diagnostics::{
Expand Down
Loading