JuliaLang / JuliaLang/PrecompileTools.jl
Feature request: manually run precompilation code during testing
- Dominant language
- Julia
- Stars
- 249
- Forks
- 18
- PR merge metrics
- No merged PRs in 30d
Description
It would be great if there was a way I could manually trigger the code within `@setup_workload` to run, outside of precompilation. The primary use-case for this would be to run the precompilation code during testing so it shows up on code coverage, and so that some precompilation errors show up as errors during testing.
My current workaround is to call a function containing all my precompilation code, with `mode=:precompile` -> `@setup_workload`, and `mode=:compile` -> (run as-is). https://github.com/MilesCranmer/SymbolicRegression.jl/blob/641180a561e350918e3fd6a8fd7c898d31bef11b/src/precompile.jl#L34
```julia
macro maybe_compile_workload(mode, ex)
precompile_ex = Expr(
:macrocall, Symbol("@compile_workload"), LineNumberNode(@__LINE__), ex
)
return quote
if $(esc(mode)) == :compile
$(esc(ex))
elseif $(esc(mode)) == :precompile
$(esc(precompile_ex))
else
error("Invalid value for mode: " * show($(esc(mode))))
end
end
end
```
with the function:
```julia
function do_precompilation(; mode=:precompile)
@maybe_setup_workload mode begin
...
end
```
so I can have `do_precompilation()` in my precompilation code, and `do_precompilation(; mode=:compile)` in my testing code.
However this seems like it would be of common interest so it would be great if there could be a way I could force `@compile_workload` code to execute outside of precompilation.
---
Brought up in https://github.com/MilesCranmer/SymbolicRegression.jl/pull/198 w/ @timholy
Contributor guide
No contributing guide indexed for this repository
Research direction
Start by reading the issue's descriptions of @setup_workload and @compile_workload, then compare the current workaround with PrecompileTools' workload execution entry points. Determine how a testing-mode invocation could execute the workload outside precompilation while preserving normal precompilation behavior. Done means the requested manual execution path exists and the precompilation errors and coverage behavior can be exercised during testing.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- julia
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100