-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
RFC: implement proper debug mode for packages (with support for re-precompilation) #37874
base: master
Are you sure you want to change the base?
Conversation
This is super cool; could we make it a debug |
234c881
to
d2c1c32
Compare
To me, that feels a bit excessive. Just enable everything if the debug level is on? It seems a bit like the Logging levels. Maybe we could have it take the same numerical value as the |
Yeah, I guess it does get close to "logging" terrority of functionality |
This comment has been minimized.
This comment has been minimized.
It should be possible to implement something like this with #37595 as a library. Edit: reworded |
Note that I don't want one to have to add a dependency and do changes in a project file to use debug mode. |
base/error.jl
Outdated
@@ -208,6 +202,7 @@ julia> @assert isodd(3) "What even are numbers?" | |||
``` | |||
""" | |||
macro assert(ex, msgs...) | |||
@isdefined(isdebug) && !(isdebug()) && return nothing |
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.
This is for the Compiler
module where isdebug
is not defined. Is this the best way?
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.
options.jl is already included by this point during bootstrap. So you could just eliminate the julia_debug
global and define isdebug()
directly in error.jl as
isdebug() = JLOptions().debug_level >= 2
?
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.
Yeah, but that ties isdebug
directly to the debugging level (while it is not only tied to it in the sense that it is used to set the variable on startup). With the current implementation you can force julia debug mode without having to start julia itself with -g2
(maybe Pkg wants to do that in Pkg.test
?). I don't know if the extra flexibility is worth it though.
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.
Allowing julia_debug
to change dynamically seems like it could be confusing and lead to inconsistencies between the precompiled code in different modules which are loaded into the session.
But maybe that's a reasonable tradeoff for flexibility, I'm not sure.
Example crazy thing:
module A
if Base.isdebug()
struct X
x
debug_field
end
else
struct X
x
end
end
end
Now other modules which depend on A
can't depend on the value of isdebug()
to use X
correctly (including macros defined by A and expanded in another module).
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.
Allowing julia_debug to change dynamically seems like it could be confusing and lead to inconsistencies between the precompiled code in different modules which are loaded into the session.
Yeah, but julia_debug
is internal so we'll just not change it dynamically in a way like that :P. But yes, I did think about changing this to exactly what you say. Can be discussed at triage as well. This problem already kind of exists in changing environments dynamically, by the way.
@@ -1124,6 +1124,14 @@ static int64_t write_dependency_list(ios_t *s, jl_array_t **udepsp, jl_array_t * | |||
} | |||
write_int32(s, 0); // terminator, for ease of reading | |||
|
|||
// Julia debug mode | |||
jl_value_t *julia_debug = (jl_value_t*)jl_get_global(jl_base_module, jl_symbol("julia_debug")); | |||
if (julia_debug) { |
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.
Perhaps this should call isdebug
instead of going for the global
?
Maybe we could use this to turn |
|
Sorry, my wording was not appropriate (edited now). I wasn't against adding this in |
Ah, yes. 👍 |
@@ -66,6 +66,9 @@ time_ns() = ccall(:jl_hrtime, UInt64, ()) | |||
|
|||
start_base_include = time_ns() | |||
|
|||
julia_debug = true |
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.
Why not make this a Ref
?
I want to second what @quinnj said about being super cool and also debugging levels (but those could be built on top I guess). Apart from that, I think the additional change regarding |
What do you mean with "following semver"? It is explicitly said in the docs that this check can be omitted and the whole point of adding those docs is to allow for exactly a PR like this. |
67822ee
to
1a6c882
Compare
The main question here is probably if the current |
1124b5e
to
184ab91
Compare
184ab91
to
ffa738c
Compare
|
Alright. Just to note, we do some compiler checks based on julia/base/compiler/ssair/driver.jl Lines 139 to 141 in 2bd31a0
|
Yeah there is the difference between debug mode for the runtime + C++ parts of the compiler e.g. |
Okay, and now when I have someone to talk to (yay), what do you think should be done with |
Yeah we used to ship two systemimages back when we still shipped Of course there are evil tricks one can play with |
Is it hard to replicate what |
Bump. @KristofferC Besides the merge conflicts, is there anything else that needs to be done for this? |
Even though there's always been that warning in the docs, I think there's likely a ton of code out there that's relying on 'improper' uses of If we're going to do this, I feel we should at least provide a replacement macro (or method to |
I strongly agree with @MasonProtter. Having something which is like |
#41342 implements an |
This adds a proper debug mode that packages can use. One of the crucial things is that the query for debug mode is available to use during precompilation and that Julia will create a new precompile cache when it changes. With the LRU cache system for
.ji
files one can swap between debug and non-debug mode freely without julia recompiling over and over.This also disables the assertion macro in normal running code.
As an example: Loading a package with this content:
in non-debug mode:
in debug mode:
and then back to non debug mode (note no re-precompilation)
Questions (for triage):
isdebug
?-g
flag we want to use to enable / disable debug mode for packages?@assert
in Base. We don't really want to ship two sysimages so maybe just leave it on there for now?TODO:
@assert
in stdlibsPkg.test
run tests in debug modecc @tkf, @staticfloat