Skip to content

Commit

Permalink
[stdlib] Make debug_assert generate llvm.assume when ASSERT=none
Browse files Browse the repository at this point in the history
Signed-off-by: Yiwu Chen <[email protected]>
  • Loading branch information
soraros committed Oct 14, 2024
1 parent 9ac8c78 commit 92f1cae
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
5 changes: 5 additions & 0 deletions stdlib/src/builtin/debug_assert.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ These are Mojo built-ins, so you don't need to import them.
from os import abort
from sys import is_defined, triple_is_nvidia_cuda
from sys._build import is_debug_build
from sys.intrinsics import assume
from sys.param_env import env_get_string
from sys.ffi import external_call, c_uint, c_size_t, c_char
from sys.info import sizeof
Expand Down Expand Up @@ -109,6 +110,8 @@ fn debug_assert[
if cond:
return
_debug_assert_msg_literal(message, __call_location())
else:
assume(cond)


@always_inline
Expand Down Expand Up @@ -279,6 +282,8 @@ fn debug_assert[
if cond:
return
_debug_assert_msg(messages, __call_location())
else:
assume(cond)


@no_inline
Expand Down
2 changes: 1 addition & 1 deletion stdlib/src/sys/intrinsics.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -1555,4 +1555,4 @@ fn assume(val: Bool):
Args:
val: The input value which is assumed to be `True`.
"""
llvm_intrinsic["llvm.assume", NoneType](val)
llvm_intrinsic["llvm.assume", NoneType, has_side_effect=False](val)

0 comments on commit 92f1cae

Please sign in to comment.