Why does running against a custom sysimage change the behaviour of my program? I thought, at most, it would accelerate the wrong things.
jlfmt.jl
$ cat jlfmt.jl
using JuliaFormatter
function @main(ARGS::Vector{String})::Cint
try
for f in ARGS
if f == "-"
print(format_text(read(stdin, String)))
else
format_file(f)
end
end
return 0
catch e
@error "err:" e
return 1
end
end
beer.jl
$ cat beer.jl
bottle_word(n) = n == 1 ? "bottle" : "bottles"
function f(s)
return 3s^2 + 2s
end
function beer()
for n = 99:-1:0
if n > 0
next_n = n - 1
next_text =
next_n > 0 ? "$next_n $(bottle_word(next_n)) of beer on the wall." :
"no more bottles of beer on the wall."
take_phrase =
n == 1 ? "Take it down and pass it around" :
"Take one down and pass it around "
println(
Core.stdout,
"$n $(bottle_word(n)) of beer on the wall, $n $(bottle_word(n)) of beer.",
)
println(Core.stdout, "$take_phrase, $next_text\n")
else
println(
Core.stdout,
"No more bottles of beer on the wall, no more bottles of beer.",
)
println(
Core.stdout,
"Go to the store and buy some more, 99 bottles of beer on the wall.",
)
end
end
end
function @main(args::Vector{String})::Cint
beer()
return 0
end
Under normal Julia, this is fine:
$ time julia jlfmt.jl beer.jl
real 0m1.331s
user 0m1.120s
sys 0m0.202s
But I compiled a sysimage with
$ time julia --startup-file=no --project=@helix-lsp -e 'import Pkg; Pkg.add(["LanguageServer", "PackageCompiler"]); Pkg.update();using PackageCompiler; create_sysimage([:LanguageServer, :JuliaFormatter], sysimage_path=dirname(Pkg.Types.Context().env.project_file) * "/languageserver.so")'
and it breaks the script:
$ time julia -J/home/kousu/.julia/environments/helix-lsp/languageserver.so jlfmt.jl beer.jl
┌ Warning: Failed to format file /home/kousu/src/beer.jl due to a parsing error, skipping file
│ error =
│ ParseError:
│ # Error @ line 36:10
│
│ function @main(args::Vector{String})::Cint
│ # └─────────────────────────┘ ── Invalid signature in function definition
└ @ JuliaFormatter ~/.julia/packages/JuliaFormatter/zLsPw/src/JuliaFormatter.jl:448
real 0m1.765s
user 0m1.493s
sys 0m0.249s
What is going on? How did I mess up precompile tools so badly? Shouldn’t it go looking in the regular libraries to get uncompiled versions?