Skip to content

Commit

Permalink
Log precompile _failures_ as well as errors. Pass log level through t…
Browse files Browse the repository at this point in the history
…o helper process.

This allows users to set the debug log level in the process, not just
via the `JULIA_DEBUG=all` environment variable (we _thought_ we had
enabled the debug messages, but we had not! 😬 ).

Also, adds a log statement for precompile statements that _fail_, not
just those that error. For example, this surfaces this failure:

```julia
┌ Debug: Precompilation failed: precompile(Tuple{typeof(Base.deepcopy_internal), Any, Base.IdDict{Any, Any}})
└ @ Main.anonymous none:31
```

Which is a pattern I've noticed in our own precompilation failures,
where Julia seems to be emitting a precompile statement with an abstract
argument (`Any` in this case, but i've seen others) for a method that is
_not_ marked `@nospecialize`, which causes `precompile()` to fail, since
you cannot normally instantiate a method for abstract types.

So that's a separate issue that we need to dig into, but this PR allows
us to identify issues like these. :)
  • Loading branch information
NHDaly committed Oct 16, 2020
1 parent 8d31d60 commit 6aa2fb2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
1 change: 1 addition & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ version = "1.2.2"

[deps]
Libdl = "8f399da3-3557-5675-b5ff-fb832c97cbdb"
Logging = "56ddb016-857b-54e1-b83d-db4d58db5568"
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
UUIDs = "cf7118a7-6976-5b1a-9a39-7adc72f591a4"

Expand Down
16 changes: 13 additions & 3 deletions src/PackageCompiler.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ using Base: active_project
using Libdl: Libdl
using Pkg: Pkg
using UUIDs: UUID, uuid1
using Logging

export create_sysimage, create_app, audit_app, restore_default_sysimage

Expand Down Expand Up @@ -212,6 +213,12 @@ function create_sysimg_object_file(object_file::String, packages::Vector{String}
precompile_code = """
# This @eval prevents symbols from being put into Main
@eval Module() begin
using Logging
# Pass through the user's logging level to the spawned process.
logger = ConsoleLogger(stderr, Logging.$(Logging.min_enabled_level(global_logger())))
global_logger(logger)
PrecompileStagingArea = Module()
for (_pkgid, _mod) in Base.loaded_modules
if !(_pkgid.name in ("Main", "Core", "Base"))
Expand All @@ -226,10 +233,13 @@ function create_sysimg_object_file(object_file::String, packages::Vector{String}
# N with a large number seems to work around it.
statement = replace(statement, r"Vararg{(.*?), N} where N" => s"Vararg{\1, 100}")
try
Base.include_string(PrecompileStagingArea, statement)
catch
success = Base.include_string(PrecompileStagingArea, statement)
if !success
@debug "Precompilation failed: \$statement"
end
catch e
# See julia issue #28808
@debug "failed to execute \$statement"
@debug "Error executing \$statement:\n\$e"
end
end
end # module
Expand Down

0 comments on commit 6aa2fb2

Please sign in to comment.