Skip to content

Commit 2688a06

Browse files
authored
inference: minor refactor for compiler/reflection code (#40745)
1 parent 55c32b5 commit 2688a06

File tree

4 files changed

+10
-17
lines changed

4 files changed

+10
-17
lines changed

base/compiler/abstractinterpretation.jl

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -284,9 +284,6 @@ function abstract_call_gf_by_type(interp::AbstractInterpreter, @nospecialize(f),
284284
return CallMeta(rettype, info)
285285
end
286286

287-
widenwrappedconditional(@nospecialize(typ)) = widenconditional(typ)
288-
widenwrappedconditional(typ::LimitedAccuracy) = LimitedAccuracy(widenconditional(typ.typ), typ.causes)
289-
290287
function add_call_backedges!(interp::AbstractInterpreter,
291288
@nospecialize(rettype),
292289
edges::Vector{MethodInstance},
@@ -1128,7 +1125,7 @@ function abstract_invoke(interp::AbstractInterpreter, argtypes::Vector{Any}, sv:
11281125
end
11291126
method, valid_worlds = result
11301127
update_valid_age!(sv, valid_worlds)
1131-
(ti, env) = ccall(:jl_type_intersection_with_env, Any, (Any, Any), nargtype, method.sig)::SimpleVector
1128+
(ti, env::SimpleVector) = ccall(:jl_type_intersection_with_env, Any, (Any, Any), nargtype, method.sig)::SimpleVector
11321129
rt, edge = typeinf_edge(interp, method, ti, env, sv)
11331130
edge !== nothing && add_backedge!(edge::MethodInstance, sv)
11341131
return CallMeta(rt, InvokeCallInfo(MethodMatch(ti, env, method, argtype <: method.sig)))

base/compiler/typeinfer.jl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -428,8 +428,7 @@ function finish(me::InferenceState, interp::AbstractInterpreter)
428428
# prepare to run optimization passes on fulltree
429429
s_edges = me.stmt_edges[1]
430430
if s_edges === nothing
431-
s_edges = []
432-
me.stmt_edges[1] = s_edges
431+
s_edges = me.stmt_edges[1] = []
433432
end
434433
for edges in me.stmt_edges
435434
edges === nothing && continue

base/compiler/typelattice.jl

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,9 @@ function widenconditional(typ::AnyConditional)
313313
end
314314
widenconditional(t::LimitedAccuracy) = error("unhandled LimitedAccuracy")
315315

316+
widenwrappedconditional(@nospecialize(typ)) = widenconditional(typ)
317+
widenwrappedconditional(typ::LimitedAccuracy) = LimitedAccuracy(widenconditional(typ.typ), typ.causes)
318+
316319
ignorelimited(@nospecialize typ) = typ
317320
ignorelimited(typ::LimitedAccuracy) = typ.typ
318321

@@ -329,10 +332,7 @@ function stupdate!(state::Nothing, changes::StateUpdate)
329332
if isa(newtype, VarState)
330333
newtypetyp = ignorelimited(newtype.typ)
331334
if isa(newtypetyp, Conditional) && slot_id(newtypetyp.var) == changeid
332-
newtypetyp = widenconditional(newtypetyp)
333-
if newtype.typ isa LimitedAccuracy
334-
newtypetyp = LimitedAccuracy(newtypetyp, newtype.typ.causes)
335-
end
335+
newtypetyp = widenwrappedconditional(newtype.typ)
336336
newst[i] = VarState(newtypetyp, newtype.undef)
337337
end
338338
end
@@ -360,10 +360,7 @@ function stupdate!(state::VarTable, changes::StateUpdate)
360360
if !changes.conditional && isa(newtype, VarState)
361361
newtypetyp = ignorelimited(newtype.typ)
362362
if isa(newtypetyp, Conditional) && slot_id(newtypetyp.var) == changeid
363-
newtypetyp = widenconditional(newtypetyp)
364-
if newtype.typ isa LimitedAccuracy
365-
newtypetyp = LimitedAccuracy(newtypetyp, newtype.typ.causes)
366-
end
363+
newtypetyp = widenwrappedconditional(newtype.typ)
367364
newtype = VarState(newtypetyp, newtype.undef)
368365
end
369366
end

base/reflection.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -862,7 +862,7 @@ function code_lowered(@nospecialize(f), @nospecialize(t=Tuple); generated::Bool=
862862
throw(ArgumentError("'debuginfo' must be either :source or :none"))
863863
end
864864
return map(method_instances(f, t)) do m
865-
if generated && isgenerated(m)
865+
if generated && hasgenerator(m)
866866
if may_invoke_generator(m)
867867
return ccall(:jl_code_for_staged, Any, (Any,), m)::CodeInfo
868868
else
@@ -877,8 +877,8 @@ function code_lowered(@nospecialize(f), @nospecialize(t=Tuple); generated::Bool=
877877
end
878878
end
879879

880-
isgenerated(m::Method) = isdefined(m, :generator)
881-
isgenerated(m::Core.MethodInstance) = isgenerated(m.def)
880+
hasgenerator(m::Method) = isdefined(m, :generator)
881+
hasgenerator(m::Core.MethodInstance) = hasgenerator(m.def::Method)
882882

883883
# low-level method lookup functions used by the compiler
884884

0 commit comments

Comments
 (0)