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`.
This commit is contained in:
Brian Anderson 2013-08-16 23:14:55 -07:00
parent 4c75d36d0e
commit 30a7a5b8fa
3 changed files with 9 additions and 3 deletions

View File

@ -96,7 +96,8 @@ ifdef CFG_DISABLE_OPTIMIZE
$(info cfg: disabling rustc optimization (CFG_DISABLE_OPTIMIZE))
CFG_RUSTC_FLAGS +=
else
CFG_RUSTC_FLAGS += -O
# The rtopt cfg turns off runtime sanity checks
CFG_RUSTC_FLAGS += -O --cfg rtopt
endif
ifdef CFG_ENABLE_DEBUG

View File

@ -27,8 +27,10 @@ macro_rules! rtdebug (
macro_rules! rtassert (
( $arg:expr ) => ( {
if !$arg {
rtabort!("assertion failed: %s", stringify!($arg));
if ::rt::util::ENFORCE_SANITY {
if !$arg {
rtabort!("assertion failed: %s", stringify!($arg));
}
}
} )
)

View File

@ -19,6 +19,9 @@ use unstable::atomics::{AtomicInt, INIT_ATOMIC_INT, SeqCst};
#[cfg(target_os="macos")]
use unstable::running_on_valgrind;
// Indicates whether we should perform expensive sanity checks, including rtassert!
pub static ENFORCE_SANITY: bool = !cfg!(rtopt) || cfg!(rtdebug) || cfg!(rtassert);
/// Get the number of cores available
pub fn num_cpus() -> uint {
#[fixed_stack_segment]; #[inline(never)];