Skip to content

Commit 49c341a

Browse files
authored
Merge branch 'master' into gb/once-fix
2 parents 354581d + 7ee404c commit 49c341a

File tree

127 files changed

+1723
-1419
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

127 files changed

+1723
-1419
lines changed

Compiler/src/abstractinterpretation.jl

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1352,6 +1352,8 @@ function const_prop_call(interp::AbstractInterpreter,
13521352
end
13531353
assign_parentchild!(frame, sv)
13541354
if !typeinf(interp, frame)
1355+
sv.time_caches += frame.time_caches
1356+
sv.time_paused += frame.time_paused
13551357
add_remark!(interp, sv, "[constprop] Fresh constant inference hit a cycle")
13561358
@assert frame.frameid != 0 && frame.cycleid == frame.frameid
13571359
callstack = frame.callstack::Vector{AbsIntState}
@@ -1736,8 +1738,8 @@ function abstract_apply(interp::AbstractInterpreter, argtypes::Vector{Any}, si::
17361738
retinfos = ApplyCallInfo[]
17371739
retinfo = UnionSplitApplyCallInfo(retinfos)
17381740
exctype = Union{}
1739-
ctypes´ = Vector{Any}[]
1740-
infos´ = Vector{MaybeAbstractIterationInfo}[]
1741+
ctypes´::Vector{Vector{Any}} = Vector{Any}[]
1742+
infos´::Vector{Vector{MaybeAbstractIterationInfo}} = Vector{MaybeAbstractIterationInfo}[]
17411743
local ti, argtypesi
17421744
local ctfuture::Future{AbstractIterationResult}
17431745
local callfuture::Future{CallMeta}
@@ -2156,7 +2158,11 @@ function form_partially_defined_struct(𝕃ᵢ::AbstractLattice, @nospecialize(o
21562158
if fields[fldidx] === Union{}
21572159
return nothing # `Union{}` field never transitions to be defined
21582160
end
2159-
undefs = partialstruct_init_undefs(objt, fldcnt)
2161+
undefs = partialstruct_init_undefs(objt, fields)
2162+
if undefs === nothing
2163+
# this object never exists at runtime, avoid creating unprofitable `PartialStruct`
2164+
return nothing
2165+
end
21602166
undefs[fldidx] = false
21612167
return PartialStruct(𝕃ᵢ, objt0, undefs, fields)
21622168
end
@@ -2618,6 +2624,8 @@ function abstract_call_known(interp::AbstractInterpreter, @nospecialize(f),
26182624
arginfo::ArgInfo, si::StmtInfo, sv::AbsIntState,
26192625
max_methods::Int = get_max_methods(interp, f, sv))
26202626
(; fargs, argtypes) = arginfo
2627+
argtypes::Vector{Any} = arginfo.argtypes # declare type because the closure below captures `argtypes`
2628+
fargs = arginfo.fargs
26212629
la = length(argtypes)
26222630
𝕃ᵢ = typeinf_lattice(interp)
26232631
if isa(f, Builtin)
@@ -4351,6 +4359,7 @@ end
43514359
# make as much progress on `frame` as possible (by handling cycles)
43524360
warnlength::Int = 2500
43534361
function typeinf(interp::AbstractInterpreter, frame::InferenceState)
4362+
time_before = _time_ns()
43544363
callstack = frame.callstack::Vector{AbsIntState}
43554364
nextstates = CurrentState[]
43564365
takenext = frame.frameid
@@ -4382,24 +4391,30 @@ function typeinf(interp::AbstractInterpreter, frame::InferenceState)
43824391
# get_compileable_sig), but still must be finished up since it may see and
43834392
# change the local variables of the InferenceState at currpc, we do this
43844393
# even if the nextresult status is already completed.
4385-
continue
43864394
elseif isdefined(nextstates[nextstateid], :result) || !isempty(callee.ip)
43874395
# Next make progress on this frame
43884396
prev = length(callee.tasks) + 1
43894397
nextstates[nextstateid] = typeinf_local(interp, callee, nextstates[nextstateid])
43904398
reverse!(callee.tasks, prev)
43914399
elseif callee.cycleid == length(callstack)
43924400
# With no active ip's and no cycles, frame is done
4393-
finish_nocycle(interp, callee)
4401+
time_now = _time_ns()
4402+
callee.time_self_ns += (time_now - time_before)
4403+
time_before = time_now
4404+
finish_nocycle(interp, callee, time_before)
43944405
callee.frameid == 0 && break
43954406
takenext = length(callstack)
43964407
nextstateid = takenext + 1 - frame.frameid
43974408
#@assert length(nextstates) == nextstateid + 1
43984409
#@assert all(i -> !isdefined(nextstates[i], :result), nextstateid+1:length(nextstates))
43994410
resize!(nextstates, nextstateid)
4411+
continue
44004412
elseif callee.cycleid == callee.frameid
44014413
# If the current frame is the top part of a cycle, check if the whole cycle
44024414
# is done, and if not, pick the next item to work on.
4415+
time_now = _time_ns()
4416+
callee.time_self_ns += (time_now - time_before)
4417+
time_before = time_now
44034418
no_active_ips_in_cycle = true
44044419
for i = callee.cycleid:length(callstack)
44054420
caller = callstack[i]::InferenceState
@@ -4410,7 +4425,7 @@ function typeinf(interp::AbstractInterpreter, frame::InferenceState)
44104425
end
44114426
end
44124427
if no_active_ips_in_cycle
4413-
finish_cycle(interp, callstack, callee.cycleid)
4428+
finish_cycle(interp, callstack, callee.cycleid, time_before)
44144429
end
44154430
takenext = length(callstack)
44164431
nextstateid = takenext + 1 - frame.frameid
@@ -4420,10 +4435,14 @@ function typeinf(interp::AbstractInterpreter, frame::InferenceState)
44204435
else
44214436
#@assert length(nextstates) == nextstateid
44224437
end
4438+
continue
44234439
else
44244440
# Continue to the next frame in this cycle
44254441
takenext = takenext - 1
44264442
end
4443+
time_now = _time_ns()
4444+
callee.time_self_ns += (time_now - time_before)
4445+
time_before = time_now
44274446
end
44284447
#@assert all(nextresult -> !isdefined(nextresult, :result), nextstates)
44294448
return is_inferred(frame)

Compiler/src/inferencestate.jl

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,10 @@ mutable struct InferenceState
302302
bestguess #::Type
303303
exc_bestguess
304304
ipo_effects::Effects
305+
time_start::UInt64
306+
time_caches::Float64
307+
time_paused::UInt64
308+
time_self_ns::UInt64
305309

306310
#= flags =#
307311
# Whether to restrict inference of abstract call sites to avoid excessive work
@@ -392,6 +396,7 @@ mutable struct InferenceState
392396
currbb, currpc, ip, handler_info, ssavalue_uses, bb_vartables, bb_saw_latestworld, ssavaluetypes, ssaflags, edges, stmt_info,
393397
tasks, pclimitations, limitations, cycle_backedges, callstack, parentid, frameid, cycleid,
394398
result, unreachable, bestguess, exc_bestguess, ipo_effects,
399+
_time_ns(), 0.0, 0, 0,
395400
restrict_abstract_call_sites, cache_mode, insert_coverage,
396401
interp)
397402

@@ -815,6 +820,8 @@ mutable struct IRInterpretationState
815820
const mi::MethodInstance
816821
world::WorldWithRange
817822
curridx::Int
823+
time_caches::Float64
824+
time_paused::UInt64
818825
const argtypes_refined::Vector{Bool}
819826
const sptypes::Vector{VarState}
820827
const tpdum::TwoPhaseDefUseMap
@@ -849,7 +856,8 @@ mutable struct IRInterpretationState
849856
tasks = WorkThunk[]
850857
edges = Any[]
851858
callstack = AbsIntState[]
852-
return new(spec_info, ir, mi, WorldWithRange(world, valid_worlds), curridx, argtypes_refined, ir.sptypes, tpdum,
859+
return new(spec_info, ir, mi, WorldWithRange(world, valid_worlds),
860+
curridx, 0.0, 0, argtypes_refined, ir.sptypes, tpdum,
853861
ssa_refined, lazyreachability, tasks, edges, callstack, 0, 0)
854862
end
855863
end
@@ -989,12 +997,12 @@ ascending the tree from the given `AbsIntState`).
989997
Note that cycles may be visited in any order.
990998
"""
991999
struct AbsIntStackUnwind
992-
sv::AbsIntState
1000+
callstack::Vector{AbsIntState}
1001+
AbsIntStackUnwind(sv::AbsIntState) = new(sv.callstack::Vector{AbsIntState})
9931002
end
994-
iterate(unw::AbsIntStackUnwind) = (unw.sv, length(unw.sv.callstack::Vector{AbsIntState}))
995-
function iterate(unw::AbsIntStackUnwind, frame::Int)
1003+
function iterate(unw::AbsIntStackUnwind, frame::Int=length(unw.callstack))
9961004
frame == 0 && return nothing
997-
return ((unw.sv.callstack::Vector{AbsIntState})[frame], frame - 1)
1005+
return (unw.callstack[frame], frame - 1)
9981006
end
9991007

10001008
struct AbsIntCycle

Compiler/src/ssair/passes.jl

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1027,17 +1027,19 @@ end
10271027
sig = sig.body
10281028
isa(sig, DataType) || return nothing
10291029
sig.name === Tuple.name || return nothing
1030-
length(sig.parameters) >= 1 || return nothing
1030+
sig_parameters = sig.parameters::SimpleVector
1031+
length_sig_parameters = length(sig_parameters)
1032+
length_sig_parameters >= 1 || return nothing
10311033

1032-
i = let sig=sig
1033-
findfirst(j::Int->has_typevar(sig.parameters[j], tvar), 1:length(sig.parameters))
1034+
function has_typevar_closure(j::Int)
1035+
has_typevar(sig_parameters[j], tvar)
10341036
end
1037+
1038+
i = findfirst(has_typevar_closure, 1:length_sig_parameters)
10351039
i === nothing && return nothing
1036-
let sig=sig
1037-
any(j::Int->has_typevar(sig.parameters[j], tvar), i+1:length(sig.parameters))
1038-
end && return nothing
1040+
any(has_typevar_closure, i+1:length_sig_parameters) && return nothing
10391041

1040-
arg = sig.parameters[i]
1042+
arg = sig_parameters[i]
10411043

10421044
rarg = def.args[2 + i]
10431045
isa(rarg, SSAValue) || return nothing

Compiler/src/tfuncs.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1995,7 +1995,7 @@ function tuple_tfunc(𝕃::AbstractLattice, argtypes::Vector{Any})
19951995
typ = Tuple{params...}
19961996
# replace a singleton type with its equivalent Const object
19971997
issingletontype(typ) && return Const(typ.instance)
1998-
return anyinfo ? PartialStruct(𝕃, typ, partialstruct_init_undefs(typ, argtypes), argtypes) : typ
1998+
return anyinfo ? PartialStruct(𝕃, typ, partialstruct_init_undefs(typ, argtypes)::Vector, argtypes) : typ
19991999
end
20002000

20012001
@nospecs function memorynew_tfunc(𝕃::AbstractLattice, memtype, memlen)

0 commit comments

Comments
 (0)