Repository navigation
Conversation
blegat
force-pushed
the
bl/juliac-trace-only
branch
from
November 16, 2026 07:50
211c0df to
f2a36ab
Compare
With `--trim=no`, the JuliaC test does not check that the executable still works once it is trimmed. With `--trim=unsafe-warn`, JuliaC only compiles the methods it can reach from `main` through calls that it can infer, so a call that is dynamically dispatched fails at run time unless its method happens to be compiled for another reason. Like JuMPy does for its compiled backends, we first run MyApp in ordinary Julia with `--trace-dispatch` and every method that was dynamically dispatched to becomes an entry point of the image, see `entry.jl`. With this, the test passes without any change to the source code of MOI so the following PRs can focus on the code paths that the tracing does not cover.
The tracing only covers the code paths that the traced run actually executes. To test the code paths that it does not cover, we add commands to MyApp that are not traced. Each of them writes the traced model with one difference (a duplicate name, another objective type, ...) so that it tests exactly one code path that the tracing does not contain, and the test compares the file written by the executable with the one written by Julia. `_model` builds the traced model, `_run` runs a command with the executable and with Julia, and the outer testset makes sure that all commands are run even if one of them fails.
blegat
force-pushed
the
bl/juliac-trace-only
branch
from
November 16, 2026 08:09
f2a36ab to
4167509
Compare
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
I found an approach that makes it much easier to compile MOI with JuliaC. Take this simple program that writes a MOF file:
MathOptInterface.jl/test/JuliaC/MyApp/src/MyApp.jl
Line 16 in 2aecedb
JuliaC normally goes throw it and try to infer all the methods that it can reach and then give up when it reaches parts that are too type unstable so the number of methods is growing exponentially.
I tried a few approaches to make the MOF writer more type stable but some changes were starting to make the code quite complex and less extensible.
The idea to make it work with a code like MOI where we have a few type instability here and there is to run some Julia program with
--trace-dispatchand record all the traces. Then, we give these traces to JuliaC and ask it to also consider them as new roots to start with to see all the new methods it can reach.Thanks to this, if one type instability is a bottleneck that prevents JuliaC to see all the methods should compile with that bottleneck, if that bottleneck is easily reach with one trace, you only need one trace to be able to compile everything!
This is the method I am using now in JuMPy and in this PR, I am implementing in the test with it as well. Some changes in the MOF writer that allows JuliaC to work better would still make sense (let's see in follow-up PRs) even with this change but at least now there is a clear tradeoff.