Skip to content

Commit

Permalink
Artifacts: Improve type-stability
Browse files Browse the repository at this point in the history
This improves Artifacts.jl to make `_artifact_str` full type-stable,
which allows `artifact"..."` to be used with `juliac`.

This is a requirement for JLL support w/ trimmed executables.

Dependent on JuliaLang#55016
  • Loading branch information
topolarity committed Sep 6, 2024
1 parent 561633b commit 8bdc150
Showing 1 changed file with 14 additions and 16 deletions.
30 changes: 14 additions & 16 deletions stdlib/Artifacts/src/Artifacts.jl
Original file line number Diff line number Diff line change
Expand Up @@ -175,13 +175,11 @@ function load_overrides(;force::Bool = false)::Dict{Symbol, Any}
end
end

overrides = Dict{Symbol,Any}(
# Overrides by UUID
:UUID => overrides_uuid,

# Overrides by hash
:hash => overrides_hash
)
overrides = Dict{Symbol,Any}()
# Overrides by UUID
overrides[:UUID] = overrides_uuid
# Overrides by hash
overrides[:hash] = overrides_hash

ARTIFACT_OVERRIDES[] = overrides
return overrides
Expand Down Expand Up @@ -351,7 +349,7 @@ function process_overrides(artifact_dict::Dict, pkg_uuid::Base.UUID)

# If we've got a platform-specific friend, override all hashes:
artifact_dict_name = artifact_dict[name]
if isa(artifact_dict_name, Array)
if isa(artifact_dict_name, Vector{Any})
for entry in artifact_dict_name
entry = entry::Dict{String,Any}
hash = SHA1(entry["git-tree-sha1"]::String)
Expand Down Expand Up @@ -544,7 +542,7 @@ function jointail(dir, tail)
end
end

function _artifact_str(__module__, artifacts_toml, name, path_tail, artifact_dict, hash, platform, @nospecialize(lazyartifacts))
function _artifact_str(__module__, artifacts_toml, name, path_tail, artifact_dict, hash, platform, ::Val{LazyArtifacts}) where LazyArtifacts
pkg = Base.PkgId(__module__)
if pkg.uuid !== nothing
# Process overrides for this UUID, if we know what it is
Expand All @@ -563,11 +561,11 @@ function _artifact_str(__module__, artifacts_toml, name, path_tail, artifact_dic
# If not, try determining what went wrong:
meta = artifact_meta(name, artifact_dict, artifacts_toml; platform)
if meta !== nothing && get(meta, "lazy", false)
if lazyartifacts isa Module && isdefined(lazyartifacts, :ensure_artifact_installed)
if nameof(lazyartifacts) in (:Pkg, :Artifacts)
if LazyArtifacts isa Module && isdefined(LazyArtifacts, :ensure_artifact_installed)
if nameof(LazyArtifacts) in (:Pkg, :Artifacts)
Base.depwarn("using Pkg instead of using LazyArtifacts is deprecated", :var"@artifact_str", force=true)
end
return jointail(lazyartifacts.ensure_artifact_installed(string(name), meta, artifacts_toml; platform), path_tail)
return jointail(LazyArtifacts.ensure_artifact_installed(string(name), meta, artifacts_toml; platform), path_tail)
end
error("Artifact $(repr(name)) is a lazy artifact; package developers must call `using LazyArtifacts` in $(__module__) before using lazy artifacts.")
end
Expand Down Expand Up @@ -699,10 +697,10 @@ macro artifact_str(name, platform=nothing)

# Check if the user has provided `LazyArtifacts`, and thus supports lazy artifacts
# If not, check to see if `Pkg` or `Pkg.Artifacts` has been imported.
lazyartifacts = nothing
LazyArtifacts = nothing
for module_name in (:LazyArtifacts, :Pkg, :Artifacts)
if isdefined(__module__, module_name)
lazyartifacts = GlobalRef(__module__, module_name)
LazyArtifacts = GlobalRef(__module__, module_name)
break
end
end
Expand All @@ -714,7 +712,7 @@ macro artifact_str(name, platform=nothing)
platform = HostPlatform()
artifact_name, artifact_path_tail, hash = artifact_slash_lookup(name, artifact_dict, artifacts_toml, platform)
return quote
Base.invokelatest(_artifact_str, $(__module__), $(artifacts_toml), $(artifact_name), $(artifact_path_tail), $(artifact_dict), $(hash), $(platform), $(lazyartifacts))::String
Base.invokelatest(_artifact_str, $(__module__), $(artifacts_toml), $(artifact_name), $(artifact_path_tail), $(artifact_dict), $(hash), $(platform), Val($(LazyArtifacts)))::String
end
else
if platform === nothing
Expand All @@ -723,7 +721,7 @@ macro artifact_str(name, platform=nothing)
return quote
local platform = $(esc(platform))
local artifact_name, artifact_path_tail, hash = artifact_slash_lookup($(esc(name)), $(artifact_dict), $(artifacts_toml), platform)
Base.invokelatest(_artifact_str, $(__module__), $(artifacts_toml), artifact_name, artifact_path_tail, $(artifact_dict), hash, platform, $(lazyartifacts))::String
Base.invokelatest(_artifact_str, $(__module__), $(artifacts_toml), artifact_name, artifact_path_tail, $(artifact_dict), hash, platform, Val($(LazyArtifacts)))::String
end
end
end
Expand Down

0 comments on commit 8bdc150

Please sign in to comment.