-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
implement a julia specific debug mode with --debug
#53404
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -203,12 +203,13 @@ might decide to check anyways, as an aid to debugging if they fail. | |
The optional message `text` is displayed upon assertion failure. | ||
|
||
!!! warning | ||
An assert might be disabled at some optimization levels. | ||
Assertions can be enabled/disabled depending on the `--debug` flag passed to Julia. | ||
Assert should therefore only be used as a debugging tool | ||
and not used for authentication verification (e.g., verifying passwords or checking array bounds). | ||
The code must not rely on the side effects of running `cond` for the correct behavior | ||
of a function. | ||
|
||
|
||
# Examples | ||
```jldoctest | ||
julia> @assert iseven(3) "3 is an odd number!" | ||
|
@@ -218,6 +219,9 @@ julia> @assert isodd(3) "What even are numbers?" | |
``` | ||
""" | ||
macro assert(ex, msgs...) | ||
enable_asserts = !isdefined(Main, :Base) || Main.Base.julia_debug | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I assume this is the canonical way to check if something is running as a script? possibly should factor that out into an independent There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is not checking if it is a script actually, it is making sure that asserts are emitted when e.g. building the compiler (and There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. gotcha
vchuravy marked this conversation as resolved.
Show resolved
Hide resolved
|
||
enable_asserts || return nothing | ||
|
||
msg = isempty(msgs) ? ex : msgs[1] | ||
if isa(msg, AbstractString) | ||
msg = msg # pass-through | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1177,4 +1177,5 @@ public | |
# misc | ||
notnothing, | ||
runtests, | ||
text_colors | ||
text_colors, | ||
isdebug |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes me a bit nervous to have a compiler time setting that I can easily change by writing a global.