Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR is the result a series of fixes I implemented for
FFTWto play nicely withjuliac --trim. Sort of solves #319. Its not perfect, but I think it should be better than nothing for those of us who depend onFFTWfor making meaningful evaluations of--trim.Library Loading
This temporarily solves the issues surrounding the current way of loading libraries, which should be replaced in the future (as suggested by the comment at https://github.com/JuliaMath/FFTW.jl/blob/master/src/FFTW.jl#L33)
FakeLazyLibraryfor type stability.And two issues related to
ccall(::FakeLazyLibrary, ...)forwarding the call todlopen(::FakeLazyLibrary):dlopenin__init__to ensure it gets precompiled (which won't happen by default since it is only called from the C layer).Base.unsafe_store!(cglobal(:jl_libdl_dlopen_func, Any), dlopen)before callingfftis necessary in all entrypoints forccallto become aware ofdlopen. Theoretically this could be done inFFTW, but I think its best to avoid messing with Julias internal mechanisms for applications outside of experimenting with--trim.The related code on the Julia side is https://github.com/JuliaLang/julia/blob/f5f4c0174ed51de3811da861c0bf01b4e9f10972/src/runtime_ccall.cpp#L86 and https://github.com/JuliaLang/julia/blob/41e50a77e6f6b9b2cfea9056529224c56923dac6/base/libdl.jl#L488.
Other Type-Instability Fixes
Some additional type instabilities that are probably worth fixing even if the library loading mechanism is updated in the future:
FFTWPlanDestructorfor type stable destruction.string(args...)withjoin([str1, str2, ...]).@syncinspawnloop. I would be happy for a better proposal for how to solve this. The core issue is thatspawnloopis precompiled even if only one thread is used. The internal use of aChannel{Any}in@syncmakes this problematic. Compared to https://github.com/JuliaLang/julia/blob/29a4bbf950aefa6116b296d48ef966ab36c5ca84/base/task.jl#L584, the only significant difference I can only see is that the real@syncgives a nicer handling and representation of errors. I hope I did not miss anything. Worst case, we could drop this from the PR and leave it to the user to overridespawnloopusing--trim.Example
With this PR the following will build with
--trimand run without errors: