Skip to content

Commit 30a7a5b

Browse files
committed
Define cfg(rtopt) when optimizing. Turn off runtime sanity checks
Naturally, and sadly, turning off sanity checks in the runtime is a noticable performance win. The particular test I'm running goes from ~1.5 s to ~1.3s. Sanity checks are turned *on* when not optimizing, or when cfg includes `rtdebug` or `rtassert`.
1 parent 4c75d36 commit 30a7a5b

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

Makefile.in

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,8 @@ ifdef CFG_DISABLE_OPTIMIZE
9696
$(info cfg: disabling rustc optimization (CFG_DISABLE_OPTIMIZE))
9797
CFG_RUSTC_FLAGS +=
9898
else
99-
CFG_RUSTC_FLAGS += -O
99+
# The rtopt cfg turns off runtime sanity checks
100+
CFG_RUSTC_FLAGS += -O --cfg rtopt
100101
endif
101102

102103
ifdef CFG_ENABLE_DEBUG

src/libstd/macros.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,10 @@ macro_rules! rtdebug (
2727

2828
macro_rules! rtassert (
2929
( $arg:expr ) => ( {
30-
if !$arg {
31-
rtabort!("assertion failed: %s", stringify!($arg));
30+
if ::rt::util::ENFORCE_SANITY {
31+
if !$arg {
32+
rtabort!("assertion failed: %s", stringify!($arg));
33+
}
3234
}
3335
} )
3436
)

src/libstd/rt/util.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ use unstable::atomics::{AtomicInt, INIT_ATOMIC_INT, SeqCst};
1919
#[cfg(target_os="macos")]
2020
use unstable::running_on_valgrind;
2121

22+
// Indicates whether we should perform expensive sanity checks, including rtassert!
23+
pub static ENFORCE_SANITY: bool = !cfg!(rtopt) || cfg!(rtdebug) || cfg!(rtassert);
24+
2225
/// Get the number of cores available
2326
pub fn num_cpus() -> uint {
2427
#[fixed_stack_segment]; #[inline(never)];

0 commit comments

Comments
 (0)