Skip to content

Commit

Permalink
Add --compiled-modules=existing command line option (#50586)
Browse files Browse the repository at this point in the history
Occasionally when developing new compiler features, it is not possible
for me to precompile the package I'm developing (because it relies on
the new compiler features, which are only available if Revise'd in).
`--compiled-modules=no` is an option, but for packages with deep
dependency stacks, this is not practical (in addition to slowing down
use of development utilities like Revise, Cthulhu or Plots). Originally
I tried to add a mode to `--compiled-modules` that would avoid using
compiled modules for anything that's dev'ed, but that's a pretty
complicated thing to figure out in the loading code, because you could
have a non-`dev`'ed package that depends on a `dev`'ed package and you'd
want to avoid loading that as well, but we don't technically have
explicit dependency links at the loading level. This sidesteps all that
and just adds a simpler option: `existing`. This option simply uses any
pre-existing cache files if they exist, but refuses to create new ones.
This does effectively the same thing, because the only packages with
stale cache files are usually the ones that I've edited. However, the
semantics are much simpler for loading to implement.
  • Loading branch information
Keno authored Jul 19, 2023
1 parent 0f56da8 commit bd8734f
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion base/loading.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1948,7 +1948,7 @@ function _require(pkg::PkgId, env=nothing)
end
end

if JLOptions().use_compiled_modules != 0
if JLOptions().use_compiled_modules == 1
if (0 == ccall(:jl_generating_output, Cint, ())) || (JLOptions().incremental != 0)
if !pkg_precompile_attempted && isinteractive() && isassigned(PKG_PRECOMPILE_HOOK)
pkg_precompile_attempted = true
Expand Down
1 change: 1 addition & 0 deletions base/util.jl
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ function julia_cmd(julia=joinpath(Sys.BINDIR, julia_exename()); cpu_target::Unio
end
opts.can_inline == 0 && push!(addflags, "--inline=no")
opts.use_compiled_modules == 0 && push!(addflags, "--compiled-modules=no")
opts.use_compiled_modules == 2 && push!(addflags, "--compiled-modules=existing")
opts.opt_level == 2 || push!(addflags, "-O$(opts.opt_level)")
opts.opt_level_min == 0 || push!(addflags, "--min-optlevel=$(opts.opt_level_min)")
push!(addflags, "-g$(opts.debug_level)")
Expand Down
2 changes: 1 addition & 1 deletion doc/src/manual/command-line-interface.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ The following is a complete list of command-line switches available when launchi
|`--startup-file={yes*\|no}` |Load `JULIA_DEPOT_PATH/config/startup.jl`; if `JULIA_DEPOT_PATH` environment variable is unset, load `~/.julia/config/startup.jl`|
|`--handle-signals={yes*\|no}` |Enable or disable Julia's default signal handlers|
|`--sysimage-native-code={yes*\|no}` |Use native code from system image if available|
|`--compiled-modules={yes*\|no}` |Enable or disable incremental precompilation of modules|
|`--compiled-modules={yes*\|no|existing}` |Enable or disable incremental precompilation of modules. The `existing` option allows use of existing compiled modules that were previously precompiled, but disallows creation of new precompile files.|
|`--pkgimages={yes*\|no}` |Enable or disable usage of native code caching in the form of pkgimages|
|`-e`, `--eval <expr>` |Evaluate `<expr>`|
|`-E`, `--print <expr>` |Evaluate `<expr>` and display the result|
Expand Down
6 changes: 4 additions & 2 deletions src/jloptions.c
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ static const char opts[] =
" --handle-signals={yes*|no} Enable or disable Julia's default signal handlers\n"
" --sysimage-native-code={yes*|no}\n"
" Use native code from system image if available\n"
" --compiled-modules={yes*|no}\n"
" --compiled-modules={yes*|no|existing}\n"
" Enable or disable incremental precompilation of modules\n"
" --pkgimages={yes*|no}\n"
" Enable or disable usage of native code caching in the form of pkgimages ($)\n\n"
Expand Down Expand Up @@ -460,8 +460,10 @@ JL_DLLEXPORT void jl_parse_opts(int *argcp, char ***argvp)
jl_options.use_compiled_modules = JL_OPTIONS_USE_COMPILED_MODULES_YES;
else if (!strcmp(optarg,"no"))
jl_options.use_compiled_modules = JL_OPTIONS_USE_COMPILED_MODULES_NO;
else if (!strcmp(optarg,"existing"))
jl_options.use_compiled_modules = JL_OPTIONS_USE_COMPILED_MODULES_EXISTING;
else
jl_errorf("julia: invalid argument to --compiled-modules={yes|no} (%s)", optarg);
jl_errorf("julia: invalid argument to --compiled-modules={yes|no|existing} (%s)", optarg);
break;
case opt_pkgimages:
pkgimage_explicit = 1;
Expand Down
1 change: 1 addition & 0 deletions src/julia.h
Original file line number Diff line number Diff line change
Expand Up @@ -2295,6 +2295,7 @@ JL_DLLEXPORT int jl_generating_output(void) JL_NOTSAFEPOINT;
#define JL_OPTIONS_USE_SYSIMAGE_NATIVE_CODE_YES 1
#define JL_OPTIONS_USE_SYSIMAGE_NATIVE_CODE_NO 0

#define JL_OPTIONS_USE_COMPILED_MODULES_EXISTING 2
#define JL_OPTIONS_USE_COMPILED_MODULES_YES 1
#define JL_OPTIONS_USE_COMPILED_MODULES_NO 0

Expand Down

0 comments on commit bd8734f

Please sign in to comment.