Skip to content

Commit 5e93c29

Browse files
authored
improve various inferrabilities, fix some errors (#40463)
1 parent 8ecb306 commit 5e93c29

File tree

12 files changed

+29
-24
lines changed

12 files changed

+29
-24
lines changed

base/compiler/ssair/inlining.jl

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -710,7 +710,7 @@ function compileable_specialization(et::Union{EdgeTracker, Nothing}, match::Meth
710710
end
711711

712712
function compileable_specialization(et::Union{EdgeTracker, Nothing}, result::InferenceResult)
713-
mi = specialize_method(result.linfo.def, result.linfo.specTypes,
713+
mi = specialize_method(result.linfo.def::Method, result.linfo.specTypes,
714714
result.linfo.sparam_vals, false, true)
715715
mi !== nothing && et !== nothing && push!(et, mi::MethodInstance)
716716
return mi
@@ -746,8 +746,10 @@ function resolve_todo(todo::InliningTodo, state::InliningState)
746746
end
747747
end
748748

749-
if isconst && state.et !== nothing
750-
push!(state.et, todo.mi)
749+
et = state.et
750+
751+
if isconst && et !== nothing
752+
push!(et, todo.mi)
751753
return ConstantCase(src)
752754
end
753755

@@ -756,14 +758,13 @@ function resolve_todo(todo::InliningTodo, state::InliningState)
756758
end
757759

758760
if src === nothing
759-
return compileable_specialization(state.et, spec.match)
761+
return compileable_specialization(et, spec.match)
760762
end
761763

762764
if isa(src, IRCode)
763765
src = copy(src)
764766
end
765767

766-
et = state.et
767768
et !== nothing && push!(et, todo.mi)
768769
return InliningTodo(todo.mi, src)
769770
end

base/compiler/ssair/verify.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ function verify_ir(ir::IRCode, print::Bool=true)
111111
end
112112
elseif isexpr(terminator, :enter)
113113
@label enter_check
114-
if length(block.succs) != 2 || (block.succs != [terminator.args[1], idx+1] && block.succs != [idx+1, terminator.args[1]])
114+
if length(block.succs) != 2 || (block.succs != Int[terminator.args[1], idx+1] && block.succs != Int[idx+1, terminator.args[1]])
115115
@verify_error "Block $idx successors ($(block.succs)), does not match :enter terminator"
116116
error("")
117117
end

base/deprecated.jl

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -117,12 +117,14 @@ function firstcaller(bt::Vector, funcsyms)
117117
end
118118
found = lkup.func in funcsyms
119119
# look for constructor type name
120-
if !found && lkup.linfo isa Core.MethodInstance
120+
if !found
121121
li = lkup.linfo
122-
ft = ccall(:jl_first_argument_datatype, Any, (Any,), li.def.sig)
123-
if isa(ft, DataType) && ft.name === Type.body.name
124-
ft = unwrap_unionall(ft.parameters[1])
125-
found = (isa(ft, DataType) && ft.name.name in funcsyms)
122+
if li isa Core.MethodInstance
123+
ft = ccall(:jl_first_argument_datatype, Any, (Any,), (li.def::Method).sig)
124+
if isa(ft, DataType) && ft.name === Type.body.name
125+
ft = unwrap_unionall(ft.parameters[1])
126+
found = (isa(ft, DataType) && ft.name.name in funcsyms)
127+
end
126128
end
127129
end
128130
end

base/iterators.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1316,7 +1316,7 @@ See also: [`first`](@ref), [`last`](@ref).
13161316
@boundscheck if i === nothing
13171317
throw(ArgumentError("Collection is empty, must contain exactly 1 element"))
13181318
end
1319-
(ret, state) = i
1319+
(ret, state) = i::NTuple{2,Any}
13201320
@boundscheck if iterate(x, state) !== nothing
13211321
throw(ArgumentError("Collection has multiple elements, must contain exactly 1 element"))
13221322
end

base/loading.jl

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -312,8 +312,9 @@ function pathof(m::Module)
312312
pkgid === nothing && return nothing
313313
origin = get(Base.pkgorigins, pkgid, nothing)
314314
origin === nothing && return nothing
315-
origin.path === nothing && return nothing
316-
return fixup_stdlib_path(origin.path)
315+
path = origin.path
316+
path === nothing && return nothing
317+
return fixup_stdlib_path(path)
317318
end
318319

319320
"""
@@ -563,7 +564,8 @@ function explicit_manifest_entry_path(manifest_file::String, pkg::PkgId, entry::
563564
hash === nothing && return nothing
564565
hash = SHA1(hash)
565566
# Keep the 4 since it used to be the default
566-
for slug in (version_slug(pkg.uuid, hash, 4), version_slug(pkg.uuid, hash))
567+
uuid = pkg.uuid::UUID # checked within `explicit_manifest_uuid_path`
568+
for slug in (version_slug(uuid, hash, 4), version_slug(uuid, hash))
567569
for depot in DEPOT_PATH
568570
path = abspath(depot, "packages", pkg.name, slug)
569571
ispath(path) && return path

base/strings/basic.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ isempty(s::AbstractString) = iszero(ncodeunits(s)::Int)
183183

184184
function getindex(s::AbstractString, i::Integer)
185185
@boundscheck checkbounds(s, i)
186-
@inbounds return isvalid(s, i) ? iterate(s, i)[1] : string_index_err(s, i)
186+
@inbounds return isvalid(s, i) ? (iterate(s, i)::NTuple{2,Any})[1] : string_index_err(s, i)
187187
end
188188

189189
getindex(s::AbstractString, i::Colon) = s

base/strings/util.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -665,8 +665,8 @@ function hex2bytes!(dest::AbstractArray{UInt8}, itr)
665665

666666
next = iterate(itr)
667667
@inbounds for i in eachindex(dest)
668-
x,state = next
669-
y,state = iterate(itr, state)
668+
x,state = next::NTuple{2,Any}
669+
y,state = iterate(itr, state)::NTuple{2,Any}
670670
next = iterate(itr, state)
671671
dest[i] = number_from_hex(x) << 4 + number_from_hex(y)
672672
end

base/toml_parser.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ function Base.showerror(io::IO, err::ParserError)
321321
printstyled(io, " error: "; color=Base.error_color())
322322
println(io, format_error_message_for_err_type(err))
323323
# In this case we want the arrow to point one character
324-
pos = err.pos
324+
pos = err.pos::Int
325325
err.type == ErrUnexpectedEofExpectedValue && (pos += 1)
326326
str1, err1 = point_to_line(err.str, pos, pos, io)
327327
@static if VERSION <= v"1.6.0-DEV.121"

base/version.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ function tryparse(::Type{VersionNumber}, v::AbstractString)
110110
m = match(VERSION_REGEX, v)
111111
m === nothing && return nothing
112112
major, minor, patch, minus, prerl, plus, build = m.captures
113-
major = parse(VInt, major)
113+
major = parse(VInt, major::AbstractString)
114114
minor = minor !== nothing ? parse(VInt, minor) : VInt(0)
115115
patch = patch !== nothing ? parse(VInt, patch) : VInt(0)
116116
if prerl !== nothing && !isempty(prerl) && prerl[1] == '-'

stdlib/Distributed/src/cluster.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ function check_worker_state(w::Worker)
171171
end
172172
end
173173

174-
exec_conn_func(id::Int) = exec_conn_func(worker_from_id(id))
174+
exec_conn_func(id::Int) = exec_conn_func(worker_from_id(id)::Worker)
175175
function exec_conn_func(w::Worker)
176176
try
177177
f = notnothing(w.conn_func)

0 commit comments

Comments
 (0)