Skip to content

Commit d2c1c32

Browse files
committed
disable assert macro unless running in debug mode
1 parent 9392bbe commit d2c1c32

File tree

4 files changed

+10
-11
lines changed

4 files changed

+10
-11
lines changed

base/Base.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ time_ns() = ccall(:jl_hrtime, UInt64, ())
6666

6767
start_base_include = time_ns()
6868

69+
julia_debug = true
70+
isdebug() = julia_debug::Bool
71+
6972
## Load essential files and libraries
7073
include("essentials.jl")
7174
include("ctypes.jl")
@@ -396,6 +399,7 @@ in_sysimage(pkgid::PkgId) = pkgid in _sysimage_modules
396399

397400
if is_primary_base_module
398401
function __init__()
402+
global julia_debug = Base.JLOptions().debug_level >= 2
399403
# try to ensuremake sure OpenBLAS does not set CPU affinity (#1070, #9639)
400404
if !haskey(ENV, "OPENBLAS_MAIN_FREE") && !haskey(ENV, "GOTOBLAS_MAIN_FREE")
401405
ENV["OPENBLAS_MAIN_FREE"] = "1"

base/error.jl

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -190,14 +190,8 @@ windowserror(p, code::UInt32=Libc.GetLastError(); extrainfo=nothing) = throw(Mai
190190
@assert cond [text]
191191
192192
Throw an [`AssertionError`](@ref) if `cond` is `false`. Preferred syntax for writing assertions.
193-
Message `text` is optionally displayed upon assertion failure.
194-
195-
!!! warning
196-
An assert might be disabled at various optimization levels.
197-
Assert should therefore only be used as a debugging tool
198-
and not used for authentication verification (e.g., verifying passwords),
199-
nor should side effects needed for the function to work correctly
200-
be used inside of asserts.
193+
Message `text` is optionally displayed upon assertion failure. Only active when julia is started
194+
in debug mode (`julia -g`).
201195
202196
# Examples
203197
```jldoctest
@@ -208,6 +202,7 @@ julia> @assert isodd(3) "What even are numbers?"
208202
```
209203
"""
210204
macro assert(ex, msgs...)
205+
@isdefined(isdebug) && !(isdebug()) && return nothing
211206
msg = isempty(msgs) ? ex : msgs[1]
212207
if isa(msg, AbstractString)
213208
msg = msg # pass-through

base/loading.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1481,9 +1481,9 @@ function get_preferences(uuid::UUID, cache::TOMLCache = TOMLCache();
14811481
# Fall back to default value of "no preferences".
14821482
return Dict{String,Any}()
14831483
end
1484-
get_preferences_hash(uuid::UUID, cache::TOMLCache = TOMLCache()) = UInt64(hash(get_preferences(uuid, cache)))
1484+
get_preferences_hash(uuid::UUID, cache::TOMLCache = TOMLCache()) = UInt64(hash(julia_debug, hash(get_preferences(uuid, cache))))
14851485
get_preferences_hash(m::Module, cache::TOMLCache = TOMLCache()) = get_preferences_hash(PkgId(m).uuid, cache)
1486-
get_preferences_hash(::Nothing, cache::TOMLCache = TOMLCache()) = UInt64(hash(Dict{String,Any}()))
1486+
get_preferences_hash(::Nothing, cache::TOMLCache = TOMLCache()) = UInt64(hash(julia_debug, hash(Dict{String,Any}())))
14871487

14881488

14891489
# returns true if it "cachefile.ji" is stale relative to "modpath.jl"

doc/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ SRCDIR := $(abspath $(dir $(lastword $(MAKEFILE_LIST))))
77
JULIAHOME := $(abspath $(SRCDIR)/..)
88
SRCCACHE := $(abspath $(JULIAHOME)/deps/srccache)
99
include $(JULIAHOME)/Make.inc
10-
JULIA_EXECUTABLE := $(call spawn,$(build_bindir)/julia) --startup-file=no
10+
JULIA_EXECUTABLE := $(call spawn,$(build_bindir)/julia) --startup-file=no -g2
1111

1212
.PHONY: help clean cleanall html pdf deps deploy
1313

0 commit comments

Comments
 (0)