Skip to content

Commit cc60657

Browse files
timholyaviateskJameson NashKristofferC
authored
Fix some inference failures in Base.require call graph (JuliaLang#44628)
Discovered via JET. This also causes `make_aliases` to always return a `Vector{SimpleVector}` as its first argument. Co-authored-by: Shuhei Kadowaki <[email protected]> Co-authored-by: Jameson Nash <[email protected]> Co-authored-by: Kristoffer Carlsson <[email protected]>
1 parent ac1d693 commit cc60657

File tree

7 files changed

+39
-27
lines changed

7 files changed

+39
-27
lines changed

base/cmd.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ function show(io::IO, cmd::Cmd)
130130
print(io, '`')
131131
if print_cpus
132132
print(io, ", ")
133-
show(io, collect(Int, cmd.cpus))
133+
show(io, collect(Int, something(cmd.cpus)))
134134
print(io, ")")
135135
end
136136
print_env && (print(io, ","); show(io, cmd.env))

base/deprecated.jl

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,13 @@ function depwarn(msg, funcsym; force::Bool=false)
106106
_module=begin
107107
bt = backtrace()
108108
frame, caller = firstcaller(bt, funcsym)
109-
# TODO: Is it reasonable to attribute callers without linfo to Core?
110-
caller.linfo isa Core.MethodInstance ? caller.linfo.def.module : Core
109+
linfo = caller.linfo
110+
if linfo isa Core.MethodInstance
111+
def = linfo.def
112+
def isa Module ? def : def.module
113+
else
114+
Core # TODO: Is it reasonable to attribute callers without linfo to Core?
115+
end
111116
end,
112117
_file=String(caller.file),
113118
_line=caller.line,

base/loading.jl

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -599,7 +599,8 @@ end
599599

600600
function is_v1_format_manifest(raw_manifest::Dict)
601601
if haskey(raw_manifest, "manifest_format")
602-
if raw_manifest["manifest_format"] isa Dict && haskey(raw_manifest["manifest_format"], "uuid")
602+
mf = raw_manifest["manifest_format"]
603+
if mf isa Dict && haskey(mf, "uuid")
603604
# the off-chance where an old format manifest has a dep called "manifest_format"
604605
return true
605606
end
@@ -615,7 +616,7 @@ function get_deps(raw_manifest::Dict)
615616
return raw_manifest
616617
else
617618
# if the manifest has no deps, there won't be a `deps` field
618-
return get(Dict{String, Any}, raw_manifest, "deps")
619+
return get(Dict{String, Any}, raw_manifest, "deps")::Dict{String, Any}
619620
end
620621
end
621622

@@ -896,6 +897,7 @@ const TIMING_IMPORTS = Threads.Atomic{Int}(0)
896897
if staledeps === true
897898
continue
898899
end
900+
staledeps = staledeps::Vector{Any}
899901
try
900902
touch(path_to_try) # update timestamp of precompilation file
901903
catch # file might be read-only and then we fail to update timestamp, which is fine
@@ -1158,7 +1160,7 @@ function set_pkgorigin_version_path(pkg, path)
11581160
d = parsed_toml(project_file)
11591161
v = get(d, "version", nothing)
11601162
if v !== nothing
1161-
pkgorigin.version = VersionNumber(v)
1163+
pkgorigin.version = VersionNumber(v::AbstractString)
11621164
end
11631165
end
11641166
end
@@ -1307,8 +1309,11 @@ include_string(m::Module, txt::AbstractString, fname::AbstractString="string") =
13071309

13081310
function source_path(default::Union{AbstractString,Nothing}="")
13091311
s = current_task().storage
1310-
if s !== nothing && haskey(s::IdDict{Any,Any}, :SOURCE_PATH)
1311-
return s[:SOURCE_PATH]::Union{Nothing,String}
1312+
if s !== nothing
1313+
s = s::IdDict{Any,Any}
1314+
if haskey(s, :SOURCE_PATH)
1315+
return s[:SOURCE_PATH]::Union{Nothing,String}
1316+
end
13121317
end
13131318
return default
13141319
end
@@ -1895,7 +1900,7 @@ function get_preferences_hash(uuid::Union{UUID, Nothing}, prefs_list::Vector{Str
18951900
for name in prefs_list
18961901
prefs_value = get(prefs, name, nothing)
18971902
if prefs_value !== nothing
1898-
h = hash(prefs_value, h)
1903+
h = hash(prefs_value, h)::UInt
18991904
end
19001905
end
19011906
# We always return a `UInt64` so that our serialization format is stable

base/process.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ end
8989
@noinline function _spawn_primitive(file, cmd::Cmd, stdio::SpawnIOs)
9090
loop = eventloop()
9191
cpumask = cmd.cpus
92-
cpumask === nothing || (cpumask = as_cpumask(cmd.cpus))
92+
cpumask === nothing || (cpumask = as_cpumask(cpumask))
9393
GC.@preserve stdio begin
9494
iohandles = Tuple{Cint, UInt}[ # assuming little-endian layout
9595
let h = rawhandle(io)

base/show.jl

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -727,11 +727,11 @@ function show_typealias(io::IO, @nospecialize(x::Type))
727727
end
728728

729729
function make_typealiases(@nospecialize(x::Type))
730-
Any === x && return Core.svec(), Union{}
731-
x <: Tuple && return Core.svec(), Union{}
730+
aliases = SimpleVector[]
731+
Any === x && return aliases, Union{}
732+
x <: Tuple && return aliases, Union{}
732733
mods = modulesof!(Set{Module}(), x)
733734
Core in mods && push!(mods, Base)
734-
aliases = SimpleVector[]
735735
vars = Dict{Symbol,TypeVar}()
736736
xenv = UnionAll[]
737737
each = Any[]
@@ -783,23 +783,24 @@ function make_typealiases(@nospecialize(x::Type))
783783
end
784784
end
785785
if isempty(aliases)
786-
return Core.svec(), Union{}
786+
return aliases, Union{}
787787
end
788-
sort!(aliases, by = x -> x[4], rev = true) # heuristic sort by "best" environment
788+
sort!(aliases, by = x -> x[4]::Tuple{Int,Int}, rev = true) # heuristic sort by "best" environment
789789
let applied = Union{}
790790
applied1 = Union{}
791791
keep = SimpleVector[]
792792
prev = (0, 0)
793793
for alias in aliases
794-
if alias[4][1] < 2
794+
alias4 = alias[4]::Tuple{Int,Int}
795+
if alias4[1] < 2
795796
if !(alias[3] <: applied)
796797
applied1 = Union{applied1, alias[3]}
797798
push!(keep, alias)
798799
end
799-
elseif alias[4] == prev || !(alias[3] <: applied)
800+
elseif alias4 == prev || !(alias[3] <: applied)
800801
applied = applied1 = Union{applied1, alias[3]}
801802
push!(keep, alias)
802-
prev = alias[4]
803+
prev = alias4
803804
end
804805
end
805806
return keep, applied1
@@ -825,16 +826,17 @@ function show_unionaliases(io::IO, x::Union)
825826
end
826827
if first && !tvar && length(aliases) == 1
827828
alias = aliases[1]
828-
wheres = make_wheres(io, alias[2], x)
829-
show_typealias(io, alias[1], x, alias[2], wheres)
829+
env = alias[2]::SimpleVector
830+
wheres = make_wheres(io, env, x)
831+
show_typealias(io, alias[1], x, env, wheres)
830832
show_wheres(io, wheres)
831833
else
832834
for alias in aliases
833835
print(io, first ? "Union{" : ", ")
834836
first = false
835-
env = alias[2]
836-
wheres = make_wheres(io, alias[2], x)
837-
show_typealias(io, alias[1], x, alias[2], wheres)
837+
env = alias[2]::SimpleVector
838+
wheres = make_wheres(io, env, x)
839+
show_typealias(io, alias[1], x, env, wheres)
838840
show_wheres(io, wheres)
839841
end
840842
if tvar
@@ -879,7 +881,7 @@ end
879881
show(io::IO, @nospecialize(x::Type)) = _show_type(io, inferencebarrier(x))
880882
function _show_type(io::IO, @nospecialize(x::Type))
881883
if print_without_params(x)
882-
show_type_name(io, unwrap_unionall(x).name)
884+
show_type_name(io, (unwrap_unionall(x)::DataType).name)
883885
return
884886
elseif get(io, :compact, true) && show_typealias(io, x)
885887
return
@@ -1006,7 +1008,7 @@ function show_datatype(io::IO, x::DataType, wheres::Vector{TypeVar}=TypeVar[])
10061008
end
10071009
else
10081010
show_type_name(io, x.name)
1009-
show_typeparams(io, parameters, unwrap_unionall(x.name.wrapper).parameters, wheres)
1011+
show_typeparams(io, parameters, (unwrap_unionall(x.name.wrapper)::DataType).parameters, wheres)
10101012
end
10111013
end
10121014

base/stat.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ show(io::IO, ::MIME"text/plain", st::StatStruct) = show_statstruct(io, st, false
146146

147147
macro stat_call(sym, arg1type, arg)
148148
return quote
149-
stat_buf = zeros(UInt8, ccall(:jl_sizeof_stat, Int32, ()))
149+
stat_buf = zeros(UInt8, Int(ccall(:jl_sizeof_stat, Int32, ())))
150150
r = ccall($(Expr(:quote, sym)), Int32, ($(esc(arg1type)), Ptr{UInt8}), $(esc(arg)), stat_buf)
151151
if !(r in (0, Base.UV_ENOENT, Base.UV_ENOTDIR, Base.UV_EINVAL))
152152
uv_error(string("stat(", repr($(esc(arg))), ")"), r)

base/toml_parser.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1165,7 +1165,7 @@ function parse_string_continue(l::Parser, multiline::Bool, quoted::Bool)::Err{St
11651165
end
11661166

11671167
function take_chunks(l::Parser, unescape::Bool)::String
1168-
nbytes = sum(length, l.chunks)
1168+
nbytes = sum(length, l.chunks; init=0)
11691169
str = Base._string_n(nbytes)
11701170
offset = 1
11711171
for chunk in l.chunks

0 commit comments

Comments
 (0)