Skip to content

miri: Add separate initializer for SOFT_ASSERTIONS #18137

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
11 changes: 11 additions & 0 deletions src/ore/src/assert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,23 @@ use crate::env;
// The rules about what you can do in a `ctor` function are somewhat fuzzy,
// because Rust does not explicitly support constructors. But a scan of the
// stdlib suggests that reading environment variables is safe enough.
#[cfg(not(miri))]
#[ctor::ctor]
pub static SOFT_ASSERTIONS: AtomicBool = {
let default = cfg!(debug_assertions) || env::is_var_truthy("MZ_SOFT_ASSERTIONS");
AtomicBool::new(default)
};

/// Always enable soft assertions when running [Miri].
///
/// Note: Miri also doesn't support global constructors, aka [`ctor`], if it ever does we could
/// get rid of this second definition. See <https://github.com/rust-lang/miri/issues/450> for
/// more details.
///
/// [Miri]: https://github.com/rust-lang/miri
#[cfg(miri)]
pub static SOFT_ASSERTIONS: AtomicBool = AtomicBool::new(true);

/// Asserts that a condition is true if soft assertions are enabled.
///
/// Soft assertions have a small runtime cost even when disabled. See
Expand Down
1 change: 0 additions & 1 deletion src/stash/tests/stash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -925,7 +925,6 @@ async fn test_stash_table(stash: &mut Stash) {
}

#[test]
#[cfg_attr(miri, ignore)] // Broken, see #18122
fn test_table() {
fn uniqueness_violation(a: &String, b: &String) -> bool {
a == b
Expand Down