Skip to content

Commit

Permalink
simplify argument collection, delay constant argument array allocation
Browse files Browse the repository at this point in the history
  • Loading branch information
aviatesk committed Nov 1, 2021
1 parent b52e664 commit 3606e59
Showing 1 changed file with 14 additions and 15 deletions.
29 changes: 14 additions & 15 deletions base/compiler/abstractinterpretation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1597,36 +1597,34 @@ function abstract_eval_statement(interp::AbstractInterpreter, @nospecialize(e),
elseif ehead === :new
t = instanceof_tfunc(abstract_eval_value(interp, e.args[1], vtypes, sv))[1]
if isconcretetype(t) && !ismutabletype(t)
args = Vector{Any}(undef, length(e.args)-1)
ats = Vector{Any}(undef, length(e.args)-1)
nargs = length(e.args) - 1
ats = Vector{Any}(undef, nargs)
local anyrefine = false
local allconst = true
for i = 2:length(e.args)
at = widenconditional(abstract_eval_value(interp, e.args[i], vtypes, sv))
ft = fieldtype(t, i-1)
at = tmeet(at, ft)
if !anyrefine
anyrefine = has_nontrivial_const_info(at) || # constant information
at fieldtype(t, i - 1) # just a type-level information, but more precise than the declared type
at ft # just a type-level information, but more precise than the declared type
end
ats[i-1] = at
if at === Bottom
t = Bottom
anyrefine = allconst = false
break
elseif at isa Const
if !(at.val isa fieldtype(t, i - 1))
t = Bottom
anyrefine = allconst = false
break
end
args[i-1] = at.val
else
@goto t_computed
elseif !isa(at, Const)
allconst = false
end
end
# For now, don't allow partially initialized Const/PartialStruct
if t !== Bottom && fieldcount(t) == length(ats)
if fieldcount(t) == nargs
if allconst
t = Const(ccall(:jl_new_structv, Any, (Any, Ptr{Cvoid}, UInt32), t, args, length(args)))
argvals = Vector{Any}(undef, nargs)
for j in 1:nargs
argvals[j] = (ats[j]::Const).val
end
t = Const(ccall(:jl_new_structv, Any, (Any, Ptr{Cvoid}, UInt32), t, argvals, nargs))
elseif anyrefine
t = PartialStruct(t, ats)
end
Expand Down Expand Up @@ -1718,6 +1716,7 @@ function abstract_eval_statement(interp::AbstractInterpreter, @nospecialize(e),
else
t = abstract_eval_value_expr(interp, e, vtypes, sv)
end
@label t_computed
@assert !isa(t, TypeVar) "unhandled TypeVar"
if isa(t, DataType) && isdefined(t, :instance)
# replace singleton types with their equivalent Const object
Expand Down

0 comments on commit 3606e59

Please sign in to comment.