Reinstate support for merging modules with non-const globals. #40252
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.
#36260 introduced a change in
jl_merge_modules
, now requiring const-ness of global variable declarations:julia/src/jitlayers.cpp
Lines 947 to 948 in 40267bb
Meanwhile, in GPU land we don't really have proper globals (suggestions on how to implement those are appreciated, but with NVPTX we can't use LLVM's JITs), so we use functions emitting
weak
GVs to emulate globals like such:We can have multiple calls to these kind of functions, emitting duplicate globals, which LLVM's IRMover happily links together when we finish emitting a function:
julia/src/codegen.cpp
Lines 7380 to 7387 in 40267bb
However, when the calls originate from different methods,
jl_compile_workqueue
ends up callingjl_merge_modules
which doesn't support linking these together, triggering the assertion at the top of this issue instead.Solutions that come to mind:
jl_merge_modules
over to LLVM's IRMover, although there's probably a reason we aren't already doing that (@vtjnash?)I do realize that the assertion is specific to how Base Julia emits LLVM global variables, but it'd be nice to get existing code working again, and I'm happy to work on a better fix after that.