Skip to content

Commit

Permalink
improve performance
Browse files Browse the repository at this point in the history
  • Loading branch information
aviatesk committed Jul 25, 2024
1 parent 460d9fb commit b618a9a
Showing 1 changed file with 18 additions and 15 deletions.
33 changes: 18 additions & 15 deletions base/compiler/abstractinterpretation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3450,24 +3450,13 @@ function typeinf_local(interp::AbstractInterpreter, frame::InferenceState)
if changes !== nothing
stoverwrite1!(currstate, changes)
end
function apply_refinement!(slot::SlotNumber, @nospecialize(newtyp))
if changes !== nothing && slot == changes.var
return # type propagation from statement (like assignment) should have the precedence
end
vtype = currstate[slot_id(slot)]
oldtyp = vtype.typ
if (𝕃ᵢ, newtyp, oldtyp)
stmtupdate = StateUpdate(slot, VarState(newtyp, vtype.undef), false)
stoverwrite1!(currstate, stmtupdate)
end
end
if refinements isa SlotRefinement
apply_refinement!(refinements.slot, refinements.typ)
apply_refinement!(𝕃ᵢ, refinements.slot, refinements.typ, currstate, changes)
elseif refinements isa Vector{Any}
for i = 1:length(refinements)
slotrefinement = refinements[i]
slotrefinement === nothing && continue
apply_refinement!(SlotNumber(i), slotrefinement)
newtyp = refinements[i]
newtyp === nothing && continue
apply_refinement!(𝕃ᵢ, SlotNumber(i), newtyp, currstate, changes)
end
end
if rt === nothing
Expand Down Expand Up @@ -3508,6 +3497,20 @@ function typeinf_local(interp::AbstractInterpreter, frame::InferenceState)
nothing
end

function apply_refinement!(𝕃ᵢ::AbstractLattice, slot::SlotNumber, @nospecialize(newtyp),
currstate::VarTable, currchanges::Union{Nothing,StateUpdate})
if currchanges !== nothing && currchanges.var == slot
return # type propagation from statement (like assignment) should have the precedence
end
vtype = currstate[slot_id(slot)]
oldtyp = vtype.typ
= strictpartialorder(𝕃ᵢ)
if newtyp oldtyp
stmtupdate = StateUpdate(slot, VarState(newtyp, vtype.undef), false)
stoverwrite1!(currstate, stmtupdate)
end
end

function conditional_change(𝕃ᵢ::AbstractLattice, currstate::VarTable, condt::Conditional, then_or_else::Bool)
vtype = currstate[condt.slot]
oldtyp = vtype.typ
Expand Down

0 comments on commit b618a9a

Please sign in to comment.