Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix some inference failures in Base.require call graph #44628

Merged
merged 4 commits into from
Mar 16, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion base/cmd.jl
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ function show(io::IO, cmd::Cmd)
print(io, '`')
if print_cpus
print(io, ", ")
show(io, collect(Int, cmd.cpus))
show(io, collect(Int, something(cmd.cpus))
print(io, ")")
end
print_env && (print(io, ","); show(io, cmd.env))
Expand Down
8 changes: 6 additions & 2 deletions base/deprecated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,12 @@ function depwarn(msg, funcsym; force::Bool=false)
_module=begin
bt = backtrace()
frame, caller = firstcaller(bt, funcsym)
# TODO: Is it reasonable to attribute callers without linfo to Core?
caller.linfo isa Core.MethodInstance ? caller.linfo.def.module : Core
linfo = caller.linfo
if linfo isa Core.MethodInstance
linfo.def isa Module ? linfo.def : linfo.def.module
else
Core # TODO: Is it reasonable to attribute callers without linfo to Core?
end
end,
_file=String(caller.file),
_line=caller.line,
Expand Down
17 changes: 11 additions & 6 deletions base/loading.jl
Original file line number Diff line number Diff line change
Expand Up @@ -599,7 +599,8 @@ end

function is_v1_format_manifest(raw_manifest::Dict)
if haskey(raw_manifest, "manifest_format")
if raw_manifest["manifest_format"] isa Dict && haskey(raw_manifest["manifest_format"], "uuid")
mf = raw_manifest["manifest_format"]
if mf isa Dict && haskey(mf, "uuid")
# the off-chance where an old format manifest has a dep called "manifest_format"
return true
end
Expand All @@ -615,7 +616,7 @@ function get_deps(raw_manifest::Dict)
return raw_manifest
else
# if the manifest has no deps, there won't be a `deps` field
return get(Dict{String, Any}, raw_manifest, "deps")
return get(Dict{String, Any}, raw_manifest, "deps")::Dict{String, Any}
end
end

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

function source_path(default::Union{AbstractString,Nothing}="")
s = current_task().storage
if s !== nothing && haskey(s::IdDict{Any,Any}, :SOURCE_PATH)
return s[:SOURCE_PATH]::Union{Nothing,String}
if s !== nothing
s = s::IdDict{Any,Any}
if haskey(s, :SOURCE_PATH)
return s[:SOURCE_PATH]::Union{Nothing,String}
end
end
return default
end
Expand Down Expand Up @@ -1895,7 +1900,7 @@ function get_preferences_hash(uuid::Union{UUID, Nothing}, prefs_list::Vector{Str
for name in prefs_list
prefs_value = get(prefs, name, nothing)
if prefs_value !== nothing
h = hash(prefs_value, h)
h = hash(prefs_value, h)::UInt
end
end
# We always return a `UInt64` so that our serialization format is stable
Expand Down
2 changes: 1 addition & 1 deletion base/process.jl
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ end
@noinline function _spawn_primitive(file, cmd::Cmd, stdio::SpawnIOs)
loop = eventloop()
cpumask = cmd.cpus
cpumask === nothing || (cpumask = as_cpumask(cmd.cpus))
cpumask === nothing || (cpumask = as_cpumask(cpumask))
GC.@preserve stdio begin
iohandles = Tuple{Cint, UInt}[ # assuming little-endian layout
let h = rawhandle(io)
Expand Down
32 changes: 17 additions & 15 deletions base/show.jl
Original file line number Diff line number Diff line change
Expand Up @@ -727,11 +727,11 @@ function show_typealias(io::IO, @nospecialize(x::Type))
end

function make_typealiases(@nospecialize(x::Type))
Any === x && return Core.svec(), Union{}
x <: Tuple && return Core.svec(), Union{}
aliases = SimpleVector[]
Any === x && return aliases, Union{}
x <: Tuple && return aliases, Union{}
mods = modulesof!(Set{Module}(), x)
Core in mods && push!(mods, Base)
aliases = SimpleVector[]
vars = Dict{Symbol,TypeVar}()
xenv = UnionAll[]
each = Any[]
Expand Down Expand Up @@ -783,23 +783,24 @@ function make_typealiases(@nospecialize(x::Type))
end
end
if isempty(aliases)
return Core.svec(), Union{}
return aliases, Union{}
end
sort!(aliases, by = x -> x[4], rev = true) # heuristic sort by "best" environment
sort!(aliases, by = x -> x[4]::Tuple{Int,Int}, rev = true) # heuristic sort by "best" environment
let applied = Union{}
applied1 = Union{}
keep = SimpleVector[]
prev = (0, 0)
for alias in aliases
if alias[4][1] < 2
alias4 = alias[4]::Tuple{Int,Int}
if alias4[1] < 2
if !(alias[3] <: applied)
applied1 = Union{applied1, alias[3]}
push!(keep, alias)
end
elseif alias[4] == prev || !(alias[3] <: applied)
elseif alias4 == prev || !(alias[3] <: applied)
applied = applied1 = Union{applied1, alias[3]}
push!(keep, alias)
prev = alias[4]
prev = alias4
end
end
return keep, applied1
Expand All @@ -825,16 +826,17 @@ function show_unionaliases(io::IO, x::Union)
end
if first && !tvar && length(aliases) == 1
alias = aliases[1]
wheres = make_wheres(io, alias[2], x)
show_typealias(io, alias[1], x, alias[2], wheres)
env = alias[2]::SimpleVector
wheres = make_wheres(io, env, x)
show_typealias(io, alias[1], x, env, wheres)
show_wheres(io, wheres)
else
for alias in aliases
print(io, first ? "Union{" : ", ")
first = false
env = alias[2]
wheres = make_wheres(io, alias[2], x)
show_typealias(io, alias[1], x, alias[2], wheres)
env = alias[2]::SimpleVector
wheres = make_wheres(io, env, x)
show_typealias(io, alias[1], x, env, wheres)
show_wheres(io, wheres)
end
if tvar
Expand Down Expand Up @@ -879,7 +881,7 @@ end
show(io::IO, @nospecialize(x::Type)) = _show_type(io, inferencebarrier(x))
function _show_type(io::IO, @nospecialize(x::Type))
if print_without_params(x)
show_type_name(io, unwrap_unionall(x).name)
show_type_name(io, (unwrap_unionall(x)::DataType).name)
return
elseif get(io, :compact, true) && show_typealias(io, x)
return
Expand Down Expand Up @@ -1006,7 +1008,7 @@ function show_datatype(io::IO, x::DataType, wheres::Vector{TypeVar}=TypeVar[])
end
else
show_type_name(io, x.name)
show_typeparams(io, parameters, unwrap_unionall(x.name.wrapper).parameters, wheres)
show_typeparams(io, parameters, (unwrap_unionall(x.name.wrapper)::DataType).parameters, wheres)
end
end

Expand Down
2 changes: 1 addition & 1 deletion base/stat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ show(io::IO, ::MIME"text/plain", st::StatStruct) = show_statstruct(io, st, false

macro stat_call(sym, arg1type, arg)
return quote
stat_buf = zeros(UInt8, ccall(:jl_sizeof_stat, Int32, ()))
stat_buf = zeros(UInt8, Int(ccall(:jl_sizeof_stat, Int32, ())))
r = ccall($(Expr(:quote, sym)), Int32, ($(esc(arg1type)), Ptr{UInt8}), $(esc(arg)), stat_buf)
if !(r in (0, Base.UV_ENOENT, Base.UV_ENOTDIR, Base.UV_EINVAL))
uv_error(string("stat(", repr($(esc(arg))), ")"), r)
Expand Down
2 changes: 1 addition & 1 deletion base/toml_parser.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1165,7 +1165,7 @@ function parse_string_continue(l::Parser, multiline::Bool, quoted::Bool)::Err{St
end

function take_chunks(l::Parser, unescape::Bool)::String
nbytes = sum(length, l.chunks)
nbytes = sum(length, l.chunks; init=0)
str = Base._string_n(nbytes)
offset = 1
for chunk in l.chunks
Expand Down