Skip to content

Commit f52f522

Browse files
maleadtclaude
andauthored
Add precompile statements for Val{PkgArtifacts} artifact dispatch. (#4682)
* Add precompile statements for `Val{PkgArtifacts}` artifact dispatch. Avoids load-time codegen in JLL packages using `using Pkg.Artifacts`. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * precompile: resolve stdlib `Artifacts` via `parentmodule` and guard internals `PkgArtifacts.Artifacts._artifact_str` resolved to `PkgArtifacts._artifact_str` (since `const Artifacts = PkgArtifacts` shadows the stdlib name and `Pkg` then re-aliases the same way), which is undefined. Use `parentmodule` on an imported stdlib function to reach the real `Artifacts` module, and gate each precompile on `isdefined` so it stays robust if the internals change in future Julia versions. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 43dcd1f commit f52f522

1 file changed

Lines changed: 22 additions & 0 deletions

File tree

src/precompile.jl

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,28 @@ let
206206
Base.precompile(Tuple{Type{Array{Dates.DateTime, 1}}, UndefInitializer, Tuple{Int64}})
207207
Base.precompile(Tuple{Type{Pair{A, B} where {B} where {A}}, String, Dates.DateTime})
208208
Base.precompile(Tuple{typeof(Core.kwcall), NamedTuple{(:internal_call, :strict, :warn_loaded, :timing, :_from_loading, :configs, :manifest, :io, :detachable), Tuple{Bool, Bool, Bool, Bool, Bool, Pair{Base.Cmd, Base.CacheFlags}, Bool, Base.TTY, Bool}}, typeof(Base.Precompilation.precompilepkgs), Array{String, 1}})
209+
210+
# `Val{PkgArtifacts}` flavour of `@artifact_str` dispatch, for JLLs using `using Pkg.Artifacts`.
211+
# `_artifact_str`/`__artifact_str` live in the stdlib `Artifacts` module, which is shadowed
212+
# inside `Pkg` by the `const Artifacts = PkgArtifacts` alias; reach it via an imported function.
213+
let StdlibArtifacts = parentmodule(PkgArtifacts.artifact_paths)
214+
if isdefined(StdlibArtifacts, :_artifact_str)
215+
Base.precompile(
216+
Tuple{
217+
typeof(StdlibArtifacts._artifact_str), Module, String, SubString{String}, String,
218+
Dict{String, Any}, Base.SHA1, Base.BinaryPlatforms.Platform, Val{PkgArtifacts},
219+
}
220+
)
221+
end
222+
if isdefined(StdlibArtifacts, :__artifact_str)
223+
Base.precompile(
224+
Tuple{
225+
typeof(StdlibArtifacts.__artifact_str), Module, String, SubString{String}, String,
226+
Dict{String, Any}, Base.SHA1, Base.BinaryPlatforms.Platform, Val{PkgArtifacts},
227+
}
228+
)
229+
end
230+
end
209231
################
210232
end
211233
end

0 commit comments

Comments
 (0)