Skip to content

Commit

Permalink
disable float non-determinism for now to be able to complete the sync
Browse files Browse the repository at this point in the history
  • Loading branch information
RalfJung committed Feb 25, 2025
1 parent 5e4c582 commit 716dd22
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 36 deletions.
1 change: 0 additions & 1 deletion src/build_helper/src/git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,6 @@ pub fn get_closest_merge_commit(
"rev-list",
&format!("--author={}", config.git_merge_commit_email),
"-n1",
"--first-parent",
&merge_base,
]);

Expand Down
22 changes: 12 additions & 10 deletions src/tools/miri/src/intrinsics/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,11 +251,12 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
let res = res.to_soft();
// Apply a relative error of 16ULP to introduce some non-determinism
// simulating imprecise implementations and optimizations.
let res = apply_random_float_error_ulp(
this,
res,
4, // log2(16)
);
// FIXME: temporarily disabled as it breaks std tests.
// let res = apply_random_float_error_ulp(
// this,
// res,
// 4, // log2(16)
// );
let res = this.adjust_nan(res, &[f]);
this.write_scalar(res, dest)?;
}
Expand Down Expand Up @@ -286,11 +287,12 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
let res = res.to_soft();
// Apply a relative error of 16ULP to introduce some non-determinism
// simulating imprecise implementations and optimizations.
let res = apply_random_float_error_ulp(
this,
res,
4, // log2(16)
);
// FIXME: temporarily disabled as it breaks std tests.
// let res = apply_random_float_error_ulp(
// this,
// res,
// 4, // log2(16)
// );
let res = this.adjust_nan(res, &[f]);
this.write_scalar(res, dest)?;
}
Expand Down
56 changes: 32 additions & 24 deletions src/tools/miri/src/shims/foreign_items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -765,13 +765,15 @@ trait EvalContextExtPriv<'tcx>: crate::MiriInterpCxExt<'tcx> {
"erfcf" => f_host.erfc(),
_ => bug!(),
};
let res = res.to_soft();
// Apply a relative error of 16ULP to introduce some non-determinism
// simulating imprecise implementations and optimizations.
let res = math::apply_random_float_error_ulp(
this,
res.to_soft(),
4, // log2(16)
);
// FIXME: temporarily disabled as it breaks std tests.
// let res = math::apply_random_float_error_ulp(
// this,
// res,
// 4, // log2(16)
// );
let res = this.adjust_nan(res, &[f]);
this.write_scalar(res, dest)?;
}
Expand All @@ -796,11 +798,12 @@ trait EvalContextExtPriv<'tcx>: crate::MiriInterpCxExt<'tcx> {
};
// Apply a relative error of 16ULP to introduce some non-determinism
// simulating imprecise implementations and optimizations.
let res = math::apply_random_float_error_ulp(
this,
res,
4, // log2(16)
);
// FIXME: temporarily disabled as it breaks std tests.
// let res = math::apply_random_float_error_ulp(
// this,
// res,
// 4, // log2(16)
// );
let res = this.adjust_nan(res, &[f1, f2]);
this.write_scalar(res, dest)?;
}
Expand Down Expand Up @@ -839,13 +842,15 @@ trait EvalContextExtPriv<'tcx>: crate::MiriInterpCxExt<'tcx> {
"erfc" => f_host.erfc(),
_ => bug!(),
};
let res = res.to_soft();
// Apply a relative error of 16ULP to introduce some non-determinism
// simulating imprecise implementations and optimizations.
let res = math::apply_random_float_error_ulp(
this,
res.to_soft(),
4, // log2(16)
);
// FIXME: temporarily disabled as it breaks std tests.
// let res = math::apply_random_float_error_ulp(
// this,
// res.to_soft(),
// 4, // log2(16)
// );
let res = this.adjust_nan(res, &[f]);
this.write_scalar(res, dest)?;
}
Expand All @@ -870,11 +875,12 @@ trait EvalContextExtPriv<'tcx>: crate::MiriInterpCxExt<'tcx> {
};
// Apply a relative error of 16ULP to introduce some non-determinism
// simulating imprecise implementations and optimizations.
let res = math::apply_random_float_error_ulp(
this,
res,
4, // log2(16)
);
// FIXME: temporarily disabled as it breaks std tests.
// let res = math::apply_random_float_error_ulp(
// this,
// res,
// 4, // log2(16)
// );
let res = this.adjust_nan(res, &[f1, f2]);
this.write_scalar(res, dest)?;
}
Expand All @@ -900,10 +906,11 @@ trait EvalContextExtPriv<'tcx>: crate::MiriInterpCxExt<'tcx> {
// Using host floats (but it's fine, these operations do not have guaranteed precision).
let (res, sign) = x.to_host().ln_gamma();
this.write_int(sign, &signp)?;
let res = res.to_soft();
// Apply a relative error of 16ULP to introduce some non-determinism
// simulating imprecise implementations and optimizations.
let res =
math::apply_random_float_error_ulp(this, res.to_soft(), 4 /* log2(16) */);
// FIXME: temporarily disabled as it breaks std tests.
// let res = math::apply_random_float_error_ulp(this, res, 4 /* log2(16) */);
let res = this.adjust_nan(res, &[x]);
this.write_scalar(res, dest)?;
}
Expand All @@ -915,10 +922,11 @@ trait EvalContextExtPriv<'tcx>: crate::MiriInterpCxExt<'tcx> {
// Using host floats (but it's fine, these operations do not have guaranteed precision).
let (res, sign) = x.to_host().ln_gamma();
this.write_int(sign, &signp)?;
let res = res.to_soft();
// Apply a relative error of 16ULP to introduce some non-determinism
// simulating imprecise implementations and optimizations.
let res =
math::apply_random_float_error_ulp(this, res.to_soft(), 4 /* log2(16) */);
// FIXME: temporarily disabled as it breaks std tests.
// let res = math::apply_random_float_error_ulp(this, res, 4 /* log2(16) */);
let res = this.adjust_nan(res, &[x]);
this.write_scalar(res, dest)?;
}
Expand Down
4 changes: 3 additions & 1 deletion src/tools/miri/tests/pass/float.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1281,6 +1281,7 @@ fn test_non_determinism() {
/// Ensure that the operation is non-deterministic
#[track_caller]
fn ensure_nondet<T: PartialEq + std::fmt::Debug>(f: impl Fn() -> T) {

let rounds = 16;
let first = f();
for _ in 1..rounds {
Expand All @@ -1290,7 +1291,8 @@ fn test_non_determinism() {
}
}
// We saw the same thing N times.
panic!("expected non-determinism, got {rounds} times the same result: {first:?}");
// FIXME: temporarily disabled as it breaks std tests.
//panic!("expected non-determinism, got {rounds} times the same result: {first:?}");
}

macro_rules! test_operations_f {
Expand Down

0 comments on commit 716dd22

Please sign in to comment.