Skip to content

Commit bd8734f

Browse files
authored
Add --compiled-modules=existing command line option (#50586)
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.
1 parent 0f56da8 commit bd8734f

File tree

5 files changed

+8
-4
lines changed

5 files changed

+8
-4
lines changed

base/loading.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1948,7 +1948,7 @@ function _require(pkg::PkgId, env=nothing)
19481948
end
19491949
end
19501950

1951-
if JLOptions().use_compiled_modules != 0
1951+
if JLOptions().use_compiled_modules == 1
19521952
if (0 == ccall(:jl_generating_output, Cint, ())) || (JLOptions().incremental != 0)
19531953
if !pkg_precompile_attempted && isinteractive() && isassigned(PKG_PRECOMPILE_HOOK)
19541954
pkg_precompile_attempted = true

base/util.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ function julia_cmd(julia=joinpath(Sys.BINDIR, julia_exename()); cpu_target::Unio
205205
end
206206
opts.can_inline == 0 && push!(addflags, "--inline=no")
207207
opts.use_compiled_modules == 0 && push!(addflags, "--compiled-modules=no")
208+
opts.use_compiled_modules == 2 && push!(addflags, "--compiled-modules=existing")
208209
opts.opt_level == 2 || push!(addflags, "-O$(opts.opt_level)")
209210
opts.opt_level_min == 0 || push!(addflags, "--min-optlevel=$(opts.opt_level_min)")
210211
push!(addflags, "-g$(opts.debug_level)")

doc/src/manual/command-line-interface.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ The following is a complete list of command-line switches available when launchi
101101
|`--startup-file={yes*\|no}` |Load `JULIA_DEPOT_PATH/config/startup.jl`; if `JULIA_DEPOT_PATH` environment variable is unset, load `~/.julia/config/startup.jl`|
102102
|`--handle-signals={yes*\|no}` |Enable or disable Julia's default signal handlers|
103103
|`--sysimage-native-code={yes*\|no}` |Use native code from system image if available|
104-
|`--compiled-modules={yes*\|no}` |Enable or disable incremental precompilation of modules|
104+
|`--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.|
105105
|`--pkgimages={yes*\|no}` |Enable or disable usage of native code caching in the form of pkgimages|
106106
|`-e`, `--eval <expr>` |Evaluate `<expr>`|
107107
|`-E`, `--print <expr>` |Evaluate `<expr>` and display the result|

src/jloptions.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ static const char opts[] =
110110
" --handle-signals={yes*|no} Enable or disable Julia's default signal handlers\n"
111111
" --sysimage-native-code={yes*|no}\n"
112112
" Use native code from system image if available\n"
113-
" --compiled-modules={yes*|no}\n"
113+
" --compiled-modules={yes*|no|existing}\n"
114114
" Enable or disable incremental precompilation of modules\n"
115115
" --pkgimages={yes*|no}\n"
116116
" Enable or disable usage of native code caching in the form of pkgimages ($)\n\n"
@@ -460,8 +460,10 @@ JL_DLLEXPORT void jl_parse_opts(int *argcp, char ***argvp)
460460
jl_options.use_compiled_modules = JL_OPTIONS_USE_COMPILED_MODULES_YES;
461461
else if (!strcmp(optarg,"no"))
462462
jl_options.use_compiled_modules = JL_OPTIONS_USE_COMPILED_MODULES_NO;
463+
else if (!strcmp(optarg,"existing"))
464+
jl_options.use_compiled_modules = JL_OPTIONS_USE_COMPILED_MODULES_EXISTING;
463465
else
464-
jl_errorf("julia: invalid argument to --compiled-modules={yes|no} (%s)", optarg);
466+
jl_errorf("julia: invalid argument to --compiled-modules={yes|no|existing} (%s)", optarg);
465467
break;
466468
case opt_pkgimages:
467469
pkgimage_explicit = 1;

src/julia.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2295,6 +2295,7 @@ JL_DLLEXPORT int jl_generating_output(void) JL_NOTSAFEPOINT;
22952295
#define JL_OPTIONS_USE_SYSIMAGE_NATIVE_CODE_YES 1
22962296
#define JL_OPTIONS_USE_SYSIMAGE_NATIVE_CODE_NO 0
22972297

2298+
#define JL_OPTIONS_USE_COMPILED_MODULES_EXISTING 2
22982299
#define JL_OPTIONS_USE_COMPILED_MODULES_YES 1
22992300
#define JL_OPTIONS_USE_COMPILED_MODULES_NO 0
23002301

0 commit comments

Comments
 (0)