Skip to content
Draft
Show file tree
Hide file tree
Changes from 81 commits
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
24 changes: 12 additions & 12 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 25 additions & 3 deletions doc/genmc.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ Miri-GenMC integrates that model checker into Miri.

## Usage

**IMPORTANT: The license of GenMC and thus the `genmc-sys` crate in the Miri repo is currently "GPL-3.0-or-later", so a binary produced with the `genmc` feature is subject to the requirements of the GPL. As long as that remains the case, the `genmc` feature of Miri is OFF-BY-DEFAULT and must be OFF for all Miri releases.**

For testing/developing Miri-GenMC (while keeping in mind the licensing issues):
For testing/developing Miri-GenMC:
- clone the Miri repo.
- build Miri-GenMC with `./miri build --features=genmc`.
- OR: install Miri-GenMC in the current system with `./miri install --features=genmc`
Expand All @@ -21,6 +19,21 @@ Basic usage:
MIRIFLAGS="-Zmiri-genmc" cargo miri run
```

Note that `cargo miri test` in GenMC mode is currently not supported.

### Supported Parameters

- `-Zmiri-genmc`: Enable GenMC mode (not required if any other GenMC options are used).
- `-Zmiri-genmc-log=LOG_LEVEL`: Change the log level for GenMC. Default: `warning`.
- `quiet`: Disable logging.
- `error`: Print errors.
- `warning`: Print errors and warnings.
- `tip`: Print errors, warnings and tips.
- If Miri is built with debug assertions, there are additional log levels available (downgraded to `tip` without debug assertions):
- `debug1`: Print revisits considered by GenMC.
- `debug2`: Print the execution graph after every memory access.
- `debug3`: Print reads-from values considered by GenMC.

<!-- FIXME(genmc): explain options. -->

<!-- FIXME(genmc): explain Miri-GenMC specific functions. -->
Expand Down Expand Up @@ -57,6 +70,15 @@ The process for obtaining them is as follows:
If you place this directory inside the Miri folder, it is recommended to call it `genmc-src` as that tells `./miri fmt` to avoid
formatting the Rust files inside that folder.

### Formatting the C++ code

For formatting the C++ code we provide a `.clang-format` file in the `genmc-sys` directory.
With `clang-format` installed, run this command to format the c++ files (replace the `-i` with `--dry-run` to just see the changes.):
```
find ./genmc-sys/cpp/ -name "*.cpp" -o -name "*.hpp" | xargs clang-format --style=file:"./genmc-sys/.clang-format" -i
```
NOTE: this is currently not done automatically on pull requests to Miri.

<!-- FIXME(genmc): explain how submitting code to GenMC should be handled. -->

<!-- FIXME(genmc): explain development. -->
52 changes: 52 additions & 0 deletions genmc-sys/.clang-format
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if all of this is necessary, but it looks a lot like how rustfmt would format.

I did not hook up anything automatic yet for formatting the C++ code (e.g., to ./miri fmt), but I've added the command to run clang-format to doc/genmc.md.

Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# .clang-format

BasedOnStyle: LLVM
Standard: c++20

ColumnLimit: 100
AllowShortFunctionsOnASingleLine: Empty
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
AllowShortBlocksOnASingleLine: Empty
BreakBeforeBraces: Attach

BinPackArguments: false
BinPackParameters: false
AllowAllParametersOfDeclarationOnNextLine: false
AlwaysBreakAfterReturnType: None

# Force parameters to break and align
AlignAfterOpenBracket: BlockIndent
AllowAllArgumentsOnNextLine: false

# Spacing around braces and parentheses
SpaceBeforeCtorInitializerColon: true
SpaceBeforeInheritanceColon: true
SpaceInEmptyBlock: false
SpacesInContainerLiterals: true
SpacesInParensOptions:
InCStyleCasts: false
InConditionalStatements: false
InEmptyParentheses: false
Other: false
SpacesInSquareBrackets: false

# Brace spacing for initializers
Cpp11BracedListStyle: false
SpaceBeforeCpp11BracedList: true

# Import grouping: group standard, external, and project includes.
IncludeBlocks: Regroup
SortIncludes: true

# Granularity: sort includes per module/file.
IncludeIsMainRegex: '([-_](test|unittest))?$'

# Miscellaneous
SpaceAfterCStyleCast: true
SpaceBeforeParens: ControlStatements
PointerAlignment: Left
IndentCaseLabels: true
IndentWidth: 4
TabWidth: 4
UseTab: Never
8 changes: 3 additions & 5 deletions genmc-sys/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
[package]
authors = ["Miri Team"]
# The parts in this repo are MIT OR Apache-2.0, but we are linking in
# code from https://github.com/MPI-SWS/genmc which is GPL-3.0-or-later.
license = "(MIT OR Apache-2.0) AND GPL-3.0-or-later"
license = "MIT OR Apache-2.0"
name = "genmc-sys"
version = "0.1.0"
edition = "2024"

[dependencies]
cxx = { version = "1.0.160", features = ["c++20"] }
cxx = { version = "1.0.173", features = ["c++20"] }

[build-dependencies]
cc = "1.2.30"
cmake = "0.1.54"
git2 = { version = "0.20.2", default-features = false, features = ["https"] }
cxx-build = { version = "1.0.160", features = ["parallel"] }
cxx-build = { version = "1.0.173", features = ["parallel"] }
42 changes: 26 additions & 16 deletions genmc-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ mod downloading {
use super::GENMC_DOWNLOAD_PATH;

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

pub(crate) fn download_genmc() -> PathBuf {
let Ok(genmc_download_path) = PathBuf::from_str(GENMC_DOWNLOAD_PATH);
Expand Down Expand Up @@ -176,6 +176,11 @@ fn link_to_llvm(config_file: &Path) -> (String, String) {

/// Build the GenMC model checker library and the Rust-C++ interop library with cxx.rs
fn compile_cpp_dependencies(genmc_path: &Path) {
// Give each step a separate build directory to prevent interference.
let out_dir = PathBuf::from(std::env::var("OUT_DIR").as_deref().unwrap());
let genmc_build_dir = out_dir.join("genmc");
let interface_build_dir = out_dir.join("miri_genmc");

// Part 1:
// Compile the GenMC library using cmake.

Expand All @@ -186,8 +191,11 @@ fn compile_cpp_dependencies(genmc_path: &Path) {
let enable_genmc_debug = matches!(std::env::var("PROFILE").as_deref().unwrap(), "debug");

let mut config = cmake::Config::new(cmakelists_path);
config.profile(GENMC_CMAKE_PROFILE);
config.define("GENMC_DEBUG", if enable_genmc_debug { "ON" } else { "OFF" });
config
.always_configure(false) // We don't need to reconfigure on subsequent compilation runs.
.out_dir(genmc_build_dir)
.profile(GENMC_CMAKE_PROFILE)
.define("GENMC_DEBUG", if enable_genmc_debug { "ON" } else { "OFF" });

// The actual compilation happens here:
let genmc_install_dir = config.build();
Expand All @@ -210,6 +218,13 @@ fn compile_cpp_dependencies(genmc_path: &Path) {
// These definitions are parsed into a cmake list and then printed to the config.h file, so they are ';' separated.
let definitions = llvm_definitions.split(";");

let cpp_files = [
"./cpp/src/MiriInterface/EventHandling.cpp",
"./cpp/src/MiriInterface/Exploration.cpp",
"./cpp/src/MiriInterface/Setup.cpp",
"./cpp/src/MiriInterface/ThreadManagement.cpp",
];

let mut bridge = cxx_build::bridge("src/lib.rs");
// FIXME(genmc,cmake): Remove once the GenMC debug setting is available in the config.h file.
if enable_genmc_debug {
Expand All @@ -223,32 +238,27 @@ fn compile_cpp_dependencies(genmc_path: &Path) {
.std("c++23")
.include(genmc_include_dir)
.include(llvm_include_dirs)
.include("./src_cpp")
.file("./src_cpp/MiriInterface.hpp")
.file("./src_cpp/MiriInterface.cpp")
.include("./cpp/include")
.files(&cpp_files)
.out_dir(interface_build_dir)
.compile("genmc_interop");

// Link the Rust-C++ interface library generated by cxx_build:
println!("cargo::rustc-link-lib=static=genmc_interop");
}

fn main() {
// Make sure we don't accidentally distribute a binary with GPL code.
if option_env!("RUSTC_STAGE").is_some() {
panic!(
"genmc should not be enabled in the rustc workspace since it includes a GPL dependency"
);
}

// Select which path to use for the GenMC repo:
let genmc_path = if let Ok(genmc_src_path) = std::env::var("GENMC_SRC_PATH") {
let genmc_path = if let Some(genmc_src_path) = option_env!("GENMC_SRC_PATH") {
let genmc_src_path =
PathBuf::from_str(&genmc_src_path).expect("GENMC_SRC_PATH should contain a valid path");
assert!(
genmc_src_path.exists(),
"GENMC_SRC_PATH={} does not exist!",
genmc_src_path.display()
);
// Rebuild files in the given path change.
println!("cargo::rerun-if-changed={}", genmc_src_path.display());
genmc_src_path
} else {
downloading::download_genmc()
Expand All @@ -263,5 +273,5 @@ fn main() {
// cloned (since cargo detects that as a file modification).
println!("cargo::rerun-if-changed={RUST_CXX_BRIDGE_FILE_PATH}");
println!("cargo::rerun-if-changed=./src");
println!("cargo::rerun-if-changed=./src_cpp");
println!("cargo::rerun-if-changed=./cpp");
}
Loading
Loading