Skip to content

Commit 20f9b9e

Browse files
authored
Merge pull request #1869 from JuliaLang/teh/inval3
Yet more inference/invalidation fixes
2 parents cdfc445 + 605f488 commit 20f9b9e

File tree

12 files changed

+212
-188
lines changed

12 files changed

+212
-188
lines changed

.travis.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,17 @@ language: julia
22

33
julia:
44
# - 1.0
5-
- 1.4
5+
# - 1.4
66
- nightly
77

88
os:
99
- linux
1010
- osx
1111

12+
env:
13+
- JULIA_PKG_SERVER="https://pkg.julialang.org"
14+
- JULIA_PKG_SERVER=""
15+
1216
notifications:
1317
email: false
1418

@@ -33,7 +37,7 @@ script:
3337
jobs:
3438
include:
3539
- stage: docs
36-
julia: 1.4
40+
julia: nightly
3741
os: linux
3842
script:
3943
- julia -e 'using UUIDs; write("Project.toml", replace(read("Project.toml", String), r"uuid = .*?\n" =>"uuid = \"$(uuid4())\"\n"))'

src/API.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,9 @@ function gc(ctx::Context=Context(); collect_delay::Period=Day(7), kwargs...)
402402
function write_condensed_usage(usage_by_depot, fname)
403403
for (depot, usage) in usage_by_depot
404404
# Keep only the keys of the files that are still extant
405-
usage = filter(p -> p[1] in all_index_files, usage)
405+
usage = let oldusage = usage
406+
filter(p -> p[1] in all_index_files, oldusage)
407+
end
406408

407409
# Expand it back into a dict of arrays-of-dicts
408410
usage = Dict(k => [Dict("time" => v)] for (k, v) in usage)

src/Artifacts.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ end
390390
Given an `entry` for the artifact named `name`, located within the file `artifacts_toml`,
391391
returns the `Platform` object that this entry specifies. Returns `nothing` on error.
392392
"""
393-
function unpack_platform(entry::Dict, name::String, artifacts_toml::String)
393+
function unpack_platform(entry::Dict, name::String, artifacts_toml::String)::Union{Nothing,Platform}
394394
if !haskey(entry, "os")
395395
@error("Invalid artifacts file at '$(artifacts_toml)': platform-specific artifact entry '$name' missing 'os' key")
396396
return nothing
@@ -403,9 +403,9 @@ function unpack_platform(entry::Dict, name::String, artifacts_toml::String)
403403

404404
# Helpers to pull out `Symbol`s and `VersionNumber`s while preserving `nothing`.
405405
nosym(x::Nothing) = nothing
406-
nosym(x) = Symbol(lowercase(x))
406+
nosym(x) = Symbol(lowercase(x))::Symbol
407407
nover(x::Nothing) = nothing
408-
nover(x) = VersionNumber(x)
408+
nover(x) = VersionNumber(x)::VersionNumber
409409

410410
# Extract architecture, libc, libgfortran version and cxxabi (if given)
411411
arch = nosym(get(entry, "arch", nothing))

src/BinaryPlatforms.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ julia> arch(MacOS())
255255
:x86_64
256256
```
257257
"""
258-
arch(p::Platform) = p.arch
258+
arch(p::Platform) = p.arch::Symbol
259259
arch(u::UnknownPlatform) = nothing
260260

261261
"""
@@ -271,7 +271,7 @@ julia> libc(Linux(:aarch64))
271271
julia> libc(FreeBSD(:x86_64))
272272
```
273273
"""
274-
libc(p::Platform) = p.libc
274+
libc(p::Platform) = p.libc::Union{Nothing,Symbol}
275275
libc(u::UnknownPlatform) = nothing
276276

277277
"""
@@ -288,7 +288,7 @@ julia> call_abi(FreeBSD(:armv7l))
288288
:eabihf
289289
```
290290
"""
291-
call_abi(p::Platform) = p.call_abi
291+
call_abi(p::Platform) = p.call_abi::Union{Nothing,Symbol}
292292
call_abi(u::UnknownPlatform) = nothing
293293

294294
"""
@@ -301,7 +301,7 @@ julia> compiler_abi(Linux(:x86_64))
301301
CompilerABI()
302302
```
303303
"""
304-
compiler_abi(p::Platform) = p.compiler_abi
304+
compiler_abi(p::Platform) = p.compiler_abi::CompilerABI
305305
compiler_abi(p::UnknownPlatform) = CompilerABI()
306306

307307
# Also break out CompilerABI getters for our platforms

src/Operations.jl

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -218,12 +218,8 @@ function set_maximum_version_registry!(ctx::Context, pkg::PackageSpec)
218218
pathvers = keys(load_versions(ctx, path; include_yanked=false))
219219
union!(pkgversions, pathvers)
220220
end
221-
if length(pkgversions) == 0
222-
pkg.version = VersionNumber(0)
223-
else
224-
max_version = maximum(pkgversions)
225-
pkg.version = VersionNumber(max_version.major, max_version.minor, max_version.patch, max_version.prerelease, ("",))
226-
end
221+
max_version = maximum(pkgversions; init=VersionNumber(0))
222+
pkg.version = VersionNumber(max_version.major, max_version.minor, max_version.patch, max_version.prerelease, ("",))
227223
end
228224

229225
function collect_project!(ctx::Context, pkg::PackageSpec, path::String,
@@ -631,7 +627,12 @@ end
631627
function download_artifacts(ctx::Context, pkgs::Vector{PackageSpec}; platform::Platform=platform_key_abi(),
632628
verbose::Bool=false)
633629
# Filter out packages that have no source_path()
634-
pkg_roots = String[p for p in source_path.((ctx,), pkgs) if p !== nothing]
630+
# pkg_roots = String[p for p in source_path.((ctx,), pkgs) if p !== nothing] # this runs up against inference limits?
631+
pkg_roots = String[]
632+
for pkg in pkgs
633+
p = source_path(ctx, pkg)
634+
p !== nothing && push!(pkg_roots, p)
635+
end
635636
return download_artifacts(ctx, pkg_roots; platform=platform, verbose=verbose)
636637
end
637638

@@ -694,12 +695,12 @@ function download_source(ctx::Context, pkgs::Vector{PackageSpec},
694695
end
695696

696697
widths = [textwidth(pkg.name) for (pkg, _) in pkgs_to_install]
697-
max_name = length(widths) == 0 ? 0 : maximum(widths)
698+
max_name = maximum(widths; init=0)
698699

699700
########################################
700701
# Install from archives asynchronously #
701702
########################################
702-
jobs = Channel(ctx.num_concurrent_downloads);
703+
jobs = Channel{eltype(pkgs_to_install)}(ctx.num_concurrent_downloads);
703704
results = Channel(ctx.num_concurrent_downloads);
704705
@async begin
705706
for pkg in pkgs_to_install
@@ -741,7 +742,7 @@ function download_source(ctx::Context, pkgs::Vector{PackageSpec},
741742

742743
missed_packages = Tuple{PackageSpec, String}[]
743744
for i in 1:length(pkgs_to_install)
744-
pkg, exc_or_success, bt_or_path = take!(results)
745+
pkg::PackageSpec, exc_or_success, bt_or_path = take!(results)
745746
exc_or_success isa Exception && pkgerror("Error when installing package $(pkg.name):\n",
746747
sprint(Base.showerror, exc_or_success, bt_or_path))
747748
success, path = exc_or_success, bt_or_path
@@ -906,7 +907,7 @@ function build_versions(ctx::Context, uuids::Vector{UUID}; might_need_to_resolve
906907
# toposort builds by dependencies
907908
order = dependency_order_uuids(ctx, map(first, builds))
908909
sort!(builds, by = build -> order[first(build)])
909-
max_name = isempty(builds) ? 0 : maximum(textwidth.([build[2] for build in builds]))
910+
max_name = maximum(build->textwidth(build[2]), builds; init=0)
910911
# build each package versions in a child process
911912
for (uuid, name, source_path, version) in builds
912913
pkg = PackageSpec(;uuid=uuid, name=name, version=version)
@@ -1649,8 +1650,9 @@ function diff_array(old_ctx::Union{Context,Nothing}, new_ctx::Context; manifest=
16491650
end
16501651
old = manifest ? load_manifest_deps(old_ctx) : load_direct_deps(old_ctx)
16511652
# merge old and new into single array
1652-
all_uuids = union([pkg.uuid for pkg in old], [pkg.uuid for pkg in new])
1653-
return [(uuid, index_pkgs(old, uuid), index_pkgs(new, uuid)) for uuid in all_uuids]
1653+
T, S = Union{UUID,Nothing}, Union{PackageSpec,Nothing}
1654+
all_uuids = union(T[pkg.uuid for pkg in old], T[pkg.uuid for pkg in new])
1655+
return Tuple{T,S,S}[(uuid, index_pkgs(old, uuid), index_pkgs(new, uuid)) for uuid in all_uuids]
16541656
end
16551657

16561658
function is_package_downloaded(ctx, pkg::PackageSpec)
@@ -1752,8 +1754,8 @@ function status(ctx::Context, pkgs::Vector{PackageSpec}=PackageSpec[];
17521754
old_ctx = Context(;env=env_diff)
17531755
end
17541756
# display
1755-
filter_uuids = [pkg.uuid for pkg in pkgs if pkg.uuid !== nothing]
1756-
filter_names = [pkg.name for pkg in pkgs if pkg.name !== nothing]
1757+
filter_uuids = [pkg.uuid::UUID for pkg in pkgs if pkg.uuid !== nothing]
1758+
filter_names = [pkg.name::String for pkg in pkgs if pkg.name !== nothing]
17571759
diff = old_ctx !== nothing
17581760
header = something(header, diff ? :Diff : :Status)
17591761
if mode == PKGMODE_PROJECT || mode == PKGMODE_COMBINED

src/PlatformEngines.jl

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,9 @@ function probe_platform_engines!(;verbose::Bool = false)
420420
if haskey(ENV, "BINARYPROVIDER_DOWNLOAD_ENGINE")
421421
engine = ENV["BINARYPROVIDER_DOWNLOAD_ENGINE"]
422422
es = split(engine)
423-
dl_ngs = filter(e -> e[1].exec[1:length(es)] == es, download_engines)
423+
dl_ngs = let es=es
424+
filter(e -> e[1].exec[1:length(es)] == es, download_engines)
425+
end
424426
if isempty(dl_ngs)
425427
all_ngs = join([d[1].exec[1] for d in download_engines], ", ")
426428
warn_msg = "Ignoring BINARYPROVIDER_DOWNLOAD_ENGINE as its value "
@@ -437,7 +439,9 @@ function probe_platform_engines!(;verbose::Bool = false)
437439
if haskey(ENV, "BINARYPROVIDER_COMPRESSION_ENGINE")
438440
engine = ENV["BINARYPROVIDER_COMPRESSION_ENGINE"]
439441
es = split(engine)
440-
comp_ngs = filter(e -> e[1].exec[1:length(es)] == es, compression_engines)
442+
comp_ngs = let es=es
443+
filter(e -> e[1].exec[1:length(es)] == es, compression_engines)
444+
end
441445
if isempty(comp_ngs)
442446
all_ngs = join([c[1].exec[1] for c in compression_engines], ", ")
443447
warn_msg = "Ignoring BINARYPROVIDER_COMPRESSION_ENGINE as its "
@@ -480,7 +484,7 @@ function probe_platform_engines!(;verbose::Bool = false)
480484
end
481485

482486
# Search for a compression engine
483-
for (test, unpack, package, list, parse, symlink) in compression_engines
487+
for (test::Cmd, unpack, package, list, parse, symlink) in compression_engines
484488
if probe_cmd(`$test`; verbose=verbose)
485489
# Set our compression command generators
486490
gen_unpack_cmd = unpack
@@ -608,7 +612,7 @@ function get_server_dir(url::AbstractString, server=pkg_server())
608612
joinpath(depots1(), "servers", m.captures[1])
609613
end
610614

611-
const AUTH_ERROR_HANDLERS = []
615+
const AUTH_ERROR_HANDLERS = Pair{Union{String, Regex},Any}[]
612616

613617
function handle_auth_error(url, err; verbose::Bool = false)
614618
handled, should_retry = false, false
@@ -640,7 +644,7 @@ is `true`.
640644
641645
`register_auth_error_handler` returns a zero-arg function that can be called to deregister the handler.
642646
"""
643-
function register_auth_error_handler(urlscheme::Union{AbstractString, Regex}, f)
647+
function register_auth_error_handler(urlscheme::Union{AbstractString, Regex}, @nospecialize(f))
644648
unique!(pushfirst!(AUTH_ERROR_HANDLERS, urlscheme => f))
645649
return () -> deregister_auth_error_handler(urlscheme, f)
646650
end
@@ -650,8 +654,8 @@ end
650654
651655
Removes `f` from the stack of authentication error handlers.
652656
"""
653-
function deregister_auth_error_handler(urlscheme::Union{AbstractString, Regex}, f)
654-
filter!(handler -> handler !== (urlscheme => f), AUTH_ERROR_HANDLERS)
657+
function deregister_auth_error_handler(urlscheme::Union{String, Regex}, @nospecialize(f))
658+
filter!(handler -> !(handler.first == urlscheme && handler.second === f), AUTH_ERROR_HANDLERS)
655659
return nothing
656660
end
657661

@@ -677,7 +681,7 @@ function get_auth_header(url::AbstractString; verbose::Bool = false)
677681
@warn "auth file without access_token field" file=auth_file
678682
return handle_auth_error(url, "no-access-token"; verbose=verbose)
679683
end
680-
auth_header = "Authorization: Bearer $(auth_info["access_token"])"
684+
auth_header = "Authorization: Bearer $(auth_info["access_token"]::String)"
681685
# handle token expiration and refresh
682686
expires_at = Inf
683687
if haskey(auth_info, "expires_at")
@@ -705,7 +709,7 @@ function get_auth_header(url::AbstractString; verbose::Bool = false)
705709
end
706710
verbose && @info "Refreshing expired auth token..." file=auth_file
707711
tmp = tempname()
708-
refresh_auth = "Authorization: Bearer $(auth_info["refresh_token"])"
712+
refresh_auth = "Authorization: Bearer $(auth_info["refresh_token"]::String)"
709713
try download(refresh_url, tmp, auth_header=refresh_auth, verbose=verbose)
710714
catch err
711715
@warn "token refresh failure" file=auth_file url=refresh_url err=err
@@ -740,7 +744,7 @@ function get_auth_header(url::AbstractString; verbose::Bool = false)
740744
end
741745
end
742746
mv(tmp, auth_file, force=true)
743-
return "Authorization: Bearer $(auth_info["access_token"])"
747+
return "Authorization: Bearer $(auth_info["access_token"]::String)"
744748
end
745749

746750
function hash_data(strs::AbstractString...)
@@ -780,7 +784,7 @@ function load_telemetry_file(file::AbstractString)
780784
end
781785
end
782786
# bail early if fully opted out
783-
get(info, "telemetry", true) == false && return info
787+
get(info, "telemetry", true) === false && return info
784788
# some validity checking helpers
785789
is_valid_uuid(x) = false
786790
is_valid_salt(x) = false
@@ -873,10 +877,12 @@ function get_telemetry_headers(url::AbstractString, notify::Bool=true)
873877
system = Pkg.BinaryPlatforms.triplet(Pkg.BinaryPlatforms.platform_key_abi())
874878
push!(headers, "Julia-System: $system")
875879
# install-specific information
876-
if info["client_uuid"] != false
877-
push!(headers, "Julia-Client-UUID: $(info["client_uuid"])")
878-
if info["secret_salt"] != false
879-
project = Base.active_project()
880+
if info["client_uuid"] !== false
881+
client_uuid = info["client_uuid"]::String
882+
push!(headers, "Julia-Client-UUID: $client_uuid")
883+
if info["secret_salt"] !== false
884+
secret_salt = info["secret_salt"]::String
885+
salt_hash = hash_data("salt", client_uuid, secret_salt)
880886
if project !== nothing
881887
project_hash = hash_data("project", project, info["secret_salt"])
882888
push!(headers, "Julia-Project-Hash: $project_hash")
@@ -885,7 +891,7 @@ function get_telemetry_headers(url::AbstractString, notify::Bool=true)
885891
end
886892
# CI indicator variables
887893
ci_variables = get(info, "ci_variables", CI_VARIABLES)
888-
ci_variables == true && (ci_variables = CI_VARIABLES)
894+
ci_variables === true && (ci_variables = CI_VARIABLES)
889895
if ci_variables != false
890896
ci_info = String[]
891897
for var in CI_VARIABLES map(uppercase, ci_variables)

src/REPLMode/REPLMode.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,11 @@ function OptionSpecs(decs::Vector{OptionDeclaration})::Dict{String, OptionSpec}
4343
specs = Dict()
4444
for x in decs
4545
opt_spec = OptionSpec(;x...)
46-
@assert get(specs, opt_spec.name, nothing) === nothing # don't overwrite
46+
@assert !haskey(specs, opt_spec.name) # don't overwrite
4747
specs[opt_spec.name] = opt_spec
4848
if opt_spec.short_name !== nothing
49-
@assert get(specs, opt_spec.short_name, nothing) === nothing # don't overwrite
50-
specs[opt_spec.short_name] = opt_spec
49+
@assert !haskey(specs, opt_spec.short_name::String) # don't overwrite
50+
specs[opt_spec.short_name::String] = opt_spec
5151
end
5252
end
5353
return specs
@@ -104,8 +104,8 @@ function CommandSpecs(declarations::Vector{CommandDeclaration})::Dict{String,Com
104104
@assert !haskey(specs, spec.canonical_name) "duplicate spec entry"
105105
specs[spec.canonical_name] = spec
106106
if spec.short_name !== nothing
107-
@assert !haskey(specs, spec.short_name) "duplicate spec entry"
108-
specs[spec.short_name] = spec
107+
@assert !haskey(specs, spec.short_name::String) "duplicate spec entry"
108+
specs[spec.short_name::String] = spec
109109
end
110110
end
111111
return specs

src/Registry.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module Registry
33
import ..Pkg, ..Types, ..API
44
using ..Pkg: depots1
55
using ..Types: RegistrySpec, Context, Context!
6-
6+
using UUIDs
77

88
"""
99
Pkg.Registry.add(url::String)
@@ -103,7 +103,7 @@ status(; kwargs...) = status(Context(); kwargs...)
103103
function status(ctx::Context; io::IO=stdout, as_api=false, kwargs...) # TODO split as_api into own function
104104
Context!(ctx; io=io, kwargs...)
105105
regs = Types.collect_registries()
106-
regs = unique(r -> r.uuid, regs) # Maybe not?
106+
regs = unique(r -> r.uuid, regs; seen=Set{Union{UUID,Nothing}}()) # Maybe not?
107107
as_api && return regs
108108
Types.printpkgstyle(ctx, Symbol("Registry Status"), "")
109109
if isempty(regs)

src/Resolve/graphtype.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -853,7 +853,7 @@ end
853853
function showlogjournal(io::IO, rlog::ResolveLog)
854854
journal = rlog.journal
855855
id(p) = p == UUID0 ? "[global event]" : pkgID(p, rlog)
856-
padding = maximum(length(id(p)) for (p,_) in journal)
856+
padding = maximum(length(id(p)) for (p,_) in journal; init=0)
857857
for (p,msg) in journal
858858
println(io, ' ', rpad(id(p), padding), ": ", msg)
859859
end

0 commit comments

Comments
 (0)