Skip to content

Commit ee66728

Browse files
authored
Merge pull request #39080 from aviatesk/typingedges
minor typing improvements for `(frame::InferenceState).stmt_edges`
2 parents e2f4073 + 628b7ac commit ee66728

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

base/compiler/inferencestate.jl

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ mutable struct InferenceState
1717
valid_worlds::WorldRange
1818
nargs::Int
1919
stmt_types::Vector{Any}
20-
stmt_edges::Vector{Any}
20+
stmt_edges::Vector{Union{Nothing, Vector{Any}}}
2121
stmt_info::Vector{Any}
2222
# return type
2323
bestguess #::Type
@@ -66,7 +66,7 @@ mutable struct InferenceState
6666
stmt_info = Any[ nothing for i = 1:length(code) ]
6767

6868
n = length(code)
69-
s_edges = Any[ nothing for i = 1:n ]
69+
s_edges = Union{Nothing, Vector{Any}}[ nothing for i = 1:n ]
7070
s_types = Any[ nothing for i = 1:n ]
7171

7272
# initial types
@@ -245,21 +245,23 @@ end
245245
# temporarily accumulate our edges to later add as backedges in the callee
246246
function add_backedge!(li::MethodInstance, caller::InferenceState)
247247
isa(caller.linfo.def, Method) || return # don't add backedges to toplevel exprs
248-
if caller.stmt_edges[caller.currpc] === nothing
249-
caller.stmt_edges[caller.currpc] = []
248+
edges = caller.stmt_edges[caller.currpc]
249+
if edges === nothing
250+
edges = caller.stmt_edges[caller.currpc] = []
250251
end
251-
push!(caller.stmt_edges[caller.currpc], li)
252+
push!(edges, li)
252253
nothing
253254
end
254255

255256
# used to temporarily accumulate our no method errors to later add as backedges in the callee method table
256257
function add_mt_backedge!(mt::Core.MethodTable, @nospecialize(typ), caller::InferenceState)
257258
isa(caller.linfo.def, Method) || return # don't add backedges to toplevel exprs
258-
if caller.stmt_edges[caller.currpc] === nothing
259-
caller.stmt_edges[caller.currpc] = []
259+
edges = caller.stmt_edges[caller.currpc]
260+
if edges === nothing
261+
edges = caller.stmt_edges[caller.currpc] = []
260262
end
261-
push!(caller.stmt_edges[caller.currpc], mt)
262-
push!(caller.stmt_edges[caller.currpc], typ)
263+
push!(edges, mt)
264+
push!(edges, typ)
263265
nothing
264266
end
265267

base/compiler/typeinfer.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ function store_backedges(frame::InferenceResult, edges::Vector{Any})
432432
nothing
433433
end
434434

435-
function store_backedges(caller::MethodInstance, edges::Vector)
435+
function store_backedges(caller::MethodInstance, edges::Vector{Any})
436436
i = 1
437437
while i <= length(edges)
438438
to = edges[i]

0 commit comments

Comments
 (0)