Skip to content

Commit 8bdc150

Browse files
committed
Artifacts: Improve type-stability
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
1 parent 561633b commit 8bdc150

File tree

1 file changed

+14
-16
lines changed

1 file changed

+14
-16
lines changed

stdlib/Artifacts/src/Artifacts.jl

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -175,13 +175,11 @@ function load_overrides(;force::Bool = false)::Dict{Symbol, Any}
175175
end
176176
end
177177

178-
overrides = Dict{Symbol,Any}(
179-
# Overrides by UUID
180-
:UUID => overrides_uuid,
181-
182-
# Overrides by hash
183-
:hash => overrides_hash
184-
)
178+
overrides = Dict{Symbol,Any}()
179+
# Overrides by UUID
180+
overrides[:UUID] = overrides_uuid
181+
# Overrides by hash
182+
overrides[:hash] = overrides_hash
185183

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

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

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

700698
# Check if the user has provided `LazyArtifacts`, and thus supports lazy artifacts
701699
# If not, check to see if `Pkg` or `Pkg.Artifacts` has been imported.
702-
lazyartifacts = nothing
700+
LazyArtifacts = nothing
703701
for module_name in (:LazyArtifacts, :Pkg, :Artifacts)
704702
if isdefined(__module__, module_name)
705-
lazyartifacts = GlobalRef(__module__, module_name)
703+
LazyArtifacts = GlobalRef(__module__, module_name)
706704
break
707705
end
708706
end
@@ -714,7 +712,7 @@ macro artifact_str(name, platform=nothing)
714712
platform = HostPlatform()
715713
artifact_name, artifact_path_tail, hash = artifact_slash_lookup(name, artifact_dict, artifacts_toml, platform)
716714
return quote
717-
Base.invokelatest(_artifact_str, $(__module__), $(artifacts_toml), $(artifact_name), $(artifact_path_tail), $(artifact_dict), $(hash), $(platform), $(lazyartifacts))::String
715+
Base.invokelatest(_artifact_str, $(__module__), $(artifacts_toml), $(artifact_name), $(artifact_path_tail), $(artifact_dict), $(hash), $(platform), Val($(LazyArtifacts)))::String
718716
end
719717
else
720718
if platform === nothing
@@ -723,7 +721,7 @@ macro artifact_str(name, platform=nothing)
723721
return quote
724722
local platform = $(esc(platform))
725723
local artifact_name, artifact_path_tail, hash = artifact_slash_lookup($(esc(name)), $(artifact_dict), $(artifacts_toml), platform)
726-
Base.invokelatest(_artifact_str, $(__module__), $(artifacts_toml), artifact_name, artifact_path_tail, $(artifact_dict), hash, platform, $(lazyartifacts))::String
724+
Base.invokelatest(_artifact_str, $(__module__), $(artifacts_toml), artifact_name, artifact_path_tail, $(artifact_dict), hash, platform, Val($(LazyArtifacts)))::String
727725
end
728726
end
729727
end

0 commit comments

Comments
 (0)