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

Follow ups to #54341 (Move nargs/isva to CodeInfo) #54453

Merged
merged 1 commit into from
May 14, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
8 changes: 4 additions & 4 deletions base/compiler/abstractinterpretation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1709,7 +1709,7 @@ function abstract_apply(interp::AbstractInterpreter, argtypes::Vector{Any}, si::
return CallMeta(res, exct, effects, retinfo)
end

function argtype_by_index(argtypes::Vector{Any}, i::Integer)
function argtype_by_index(argtypes::Vector{Any}, i::Int)
n = length(argtypes)
na = argtypes[n]
if isvarargtype(na)
Expand Down Expand Up @@ -2880,12 +2880,12 @@ end
struct BestguessInfo{Interp<:AbstractInterpreter}
interp::Interp
bestguess
nargs::UInt
nargs::Int
slottypes::Vector{Any}
changes::VarTable
function BestguessInfo(interp::Interp, @nospecialize(bestguess), nargs::UInt,
function BestguessInfo(interp::Interp, @nospecialize(bestguess), nargs::Int,
slottypes::Vector{Any}, changes::VarTable) where Interp<:AbstractInterpreter
new{Interp}(interp, bestguess, Int(nargs), slottypes, changes)
new{Interp}(interp, bestguess, nargs, slottypes, changes)
end
end

Expand Down
29 changes: 15 additions & 14 deletions base/compiler/inferenceresult.jl
Original file line number Diff line number Diff line change
Expand Up @@ -36,44 +36,44 @@ function pick_const_arg(𝕃::AbstractLattice, @nospecialize(given_argtype), @no
# declared method signature, narrow it down using `tmeet`
given_argtype = tmeet(𝕃, given_argtype, cache_argtype)
end
return given_argtype
else
given_argtype = cache_argtype
return cache_argtype
end
return given_argtype
end

function pick_const_args!(𝕃::AbstractLattice, given_argtypes::Vector{Any}, cache_argtypes::Vector{Any})
if length(given_argtypes) == 0 || length(cache_argtypes) == 0
ngiven = length(given_argtypes)
ncache = length(cache_argtypes)
if ngiven == 0 || ncache == 0
return Any[]
end
given_va = given_argtypes[end]
cache_va = cache_argtypes[end]
if isvarargtype(given_va)
ngiven = length(given_argtypes)
va = unwrapva(given_va)
if isvarargtype(cache_va)
# Process the common prefix, then join
nprocessargs = max(length(given_argtypes)-1, length(cache_argtypes)-1)
nprocessargs = max(ngiven-1, ncache-1)
resize!(given_argtypes, nprocessargs+1)
given_argtypes[end] = Vararg{pick_const_arg(𝕃, unwrapva(given_va), unwrapva(cache_va))}
given_argtypes[end] = Vararg{pick_const_arg(𝕃, va, unwrapva(cache_va))}
else
nprocessargs = length(cache_argtypes)
nprocessargs = ncache
resize!(given_argtypes, nprocessargs)
end
for i = ngiven:nprocessargs
given_argtypes[i] = va
end
elseif isvarargtype(cache_va)
nprocessargs = length(given_argtypes)
nprocessargs = ngiven
else
@assert length(given_argtypes) == length(cache_argtypes)
nprocessargs = length(given_argtypes)
@assert ngiven == ncache
nprocessargs = ngiven
end
for i = 1:nprocessargs
given_argtype = given_argtypes[i]
cache_argtype = argtype_by_index(cache_argtypes, i)
given_argtype = pick_const_arg(𝕃, given_argtype, cache_argtype)
given_argtypes[i] = given_argtype
given_argtypes[i] = pick_const_arg(𝕃, given_argtype, cache_argtype)
end
return given_argtypes
end
Expand All @@ -90,8 +90,9 @@ function is_argtype_match(𝕃::AbstractLattice,
end

function va_process_argtypes(𝕃::AbstractLattice, given_argtypes::Vector{Any}, nargs::UInt, isva::Bool)
nargs = Int(nargs)
if isva || (!isempty(given_argtypes) && isvarargtype(given_argtypes[end]))
isva_given_argtypes = Vector{Any}(undef, Int(nargs))
isva_given_argtypes = Vector{Any}(undef, nargs)
for i = 1:(nargs-isva)
newarg = argtype_by_index(given_argtypes, i)
if isva && has_conditional(𝕃) && isa(newarg, Conditional)
Expand Down Expand Up @@ -126,7 +127,7 @@ end
function most_general_argtypes(method::Union{Method,Nothing}, @nospecialize(specTypes))
mi_argtypes = Any[(unwrap_unionall(specTypes)::DataType).parameters...]
nargtypes = length(mi_argtypes)
nargs = isa(method, Method) ? method.nargs : 0
nargs = isa(method, Method) ? Int(method.nargs) : 0
if length(mi_argtypes) < nargs && isvarargtype(mi_argtypes[end])
resize!(mi_argtypes, nargs)
end
Expand Down
2 changes: 1 addition & 1 deletion base/compiler/inferencestate.jl
Original file line number Diff line number Diff line change
Expand Up @@ -853,7 +853,7 @@ function print_callstack(sv::InferenceState)
end

function narguments(sv::InferenceState, include_va::Bool=true)
nargs = sv.src.nargs
nargs = Int(sv.src.nargs)
if !include_va
nargs -= sv.src.isva
end
Expand Down
2 changes: 1 addition & 1 deletion base/compiler/optimize.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1254,7 +1254,7 @@ function slot2reg(ir::IRCode, ci::CodeInfo, sv::OptimizationState)
# need `ci` for the slot metadata, IR for the code
svdef = sv.linfo.def
@timeit "domtree 1" domtree = construct_domtree(ir)
defuse_insts = scan_slot_def_use(ci.nargs, ci, ir.stmts.stmt)
defuse_insts = scan_slot_def_use(Int(ci.nargs), ci, ir.stmts.stmt)
𝕃ₒ = optimizer_lattice(sv.inlining.interp)
@timeit "construct_ssa" ir = construct_ssa!(ci, ir, sv, domtree, defuse_insts, 𝕃ₒ) # consumes `ir`
# NOTE now we have converted `ir` to the SSA form and eliminated slots
Expand Down
2 changes: 1 addition & 1 deletion base/compiler/ssair/slot2ssa.jl
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ function scan_entry!(result::Vector{SlotInfo}, idx::Int, @nospecialize(stmt))
end
end

function scan_slot_def_use(nargs::Integer, ci::CodeInfo, code::Vector{Any})
function scan_slot_def_use(nargs::Int, ci::CodeInfo, code::Vector{Any})
nslots = length(ci.slotflags)
result = SlotInfo[SlotInfo() for i = 1:nslots]
# Set defs for arguments
Expand Down
2 changes: 1 addition & 1 deletion base/compiler/typeinfer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ function adjust_effects(sv::InferenceState)
# this frame is known to be safe
ipo_effects = Effects(ipo_effects; nothrow=true)
end
if is_inaccessiblemem_or_argmemonly(ipo_effects) && all(1:narguments(sv, #=include_va=#true)) do i::UInt
if is_inaccessiblemem_or_argmemonly(ipo_effects) && all(1:narguments(sv, #=include_va=#true)) do i::Int
return is_mutation_free_argtype(sv.slottypes[i])
end
ipo_effects = Effects(ipo_effects; inaccessiblememonly=ALWAYS_TRUE)
Expand Down