-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
Description
Summary
juliac
segfaults when a somewhat involved const = ...
statement is evaluated that's not in a package definition.
Description
While working on a --trim
CI test for NonlinearSolve.jl (SciML/NonlinearSolve.jl#665) I came across the following segfault:
I have some code that's roughly
const autodiff = AutoForwardDiff(; chunksize = 1)
const alg = TrustRegion(; autodiff, linsolve = LS.CholeskyFactorization())
const prob = NonlinearLeastSquaresProblem{false}(...)
const cache = init(prob, alg)
function minimize(x)
reinit!(cache, x)
solve!(cache)
return cache.u
end
with a relatively straightforward objective function (just a linsolve and cholesky on a regular Vector).
When using an appropriate entrypoint that calls minimize
this program trims fine, as long as the code is in a package definition. However, when it is merely wrapped in a module, or simply include
d, the cache = init(prob, alg)
segfaults the juliac compiler.
In particular, trying to trim
include("optimization_trimmable.jl")
function (@main)(argv::Vector{String})::Cint
minimize(1.0)
return 0
end
or even
module MyMod
include("optimization_trimmable.jl")
end
function (@main)(argv::Vector{String})::Cint
MyMod.minimize(1.0)
return 0
end
segfaults juliac
.
What I expected to happen
That is trims just fine, as it does when we swap out main_segfault.jl
with main_trimmable.jl
below.
How to reproduce
git clone [email protected]:RomeoV/NonlinearSolve.jl.git
cd NonlinearSolve.jl
git checkout ca0d0f2a8cf752a68c48ab88cf4c850bb1acbc49
cd test/trim
export JULIAC=$(julia +1.12 -E 'joinpath(Sys.BINDIR, Base.DATAROOTDIR, "julia", "juliac", "juliac.jl")' | tr -d '"')
julia +1.12 --depwarn=error --project ${JULIAC} --experimental --trim=unsafe-warn --output-exe main main_segfault.jl