@@ -1594,11 +1594,11 @@ function try_resolve_finalizer!(ir::IRCode, alloc_idx::Int, finalizer_idx::Int,
1594
1594
inlining:: InliningState , lazydomtree:: LazyDomtree ,
1595
1595
lazypostdomtree:: LazyPostDomtree , @nospecialize (info:: CallInfo ))
1596
1596
# For now, require that:
1597
- # 1. The allocation dominates the finalizer registration
1597
+ # 1. The allocation dominates the finalizer registration.
1598
1598
# 2. The insertion block for the finalizer is the post-dominator of all
1599
1599
# uses (including the finalizer registration).
1600
1600
# 3. The path from the finalizer registration to the finalizer inlining
1601
- # location is nothrow
1601
+ # location is nothrow, otherwise we need to insert `Core._cancel_finalizer` too.
1602
1602
#
1603
1603
# TODO : We could relax the check 2, by inlining the finalizer multiple times.
1604
1604
@@ -1677,8 +1677,8 @@ function try_resolve_finalizer!(ir::IRCode, alloc_idx::Int, finalizer_idx::Int,
1677
1677
attach_after = insert_idx != = nothing
1678
1678
flag = info isa FinalizerInfo ? flags_for_effects (info. effects) : IR_FLAG_NULL
1679
1679
alloc_obj = finalizer_stmt. args[3 ]
1680
- cancel_registration = current_task_ssa != = nothing
1681
- if cancel_registration
1680
+ cancellation_required = current_task_ssa != = nothing
1681
+ if cancellation_required
1682
1682
lookup_idx_ssa = SSAValue (finalizer_idx)
1683
1683
finalize_call = Expr (:call , GlobalRef (Core, :_cancel_finalizer ), alloc_obj, current_task_ssa, lookup_idx_ssa)
1684
1684
newinst = add_flag (NewInstruction (finalize_call, Nothing), flag)
@@ -1702,7 +1702,7 @@ function try_resolve_finalizer!(ir::IRCode, alloc_idx::Int, finalizer_idx::Int,
1702
1702
newinst = add_flag (NewInstruction (Expr (:call , argexprs... ), Nothing), flag)
1703
1703
insert_node! (ir, loc, newinst, attach_after)
1704
1704
end
1705
- if ! cancel_registration
1705
+ if ! cancellation_required
1706
1706
# Erase the call to `finalizer`
1707
1707
ir[SSAValue (finalizer_idx)][:stmt ] = nothing
1708
1708
end
@@ -1721,10 +1721,7 @@ function sroa_mutables!(ir::IRCode, defuses::IdDict{Int,Tuple{SPCSet,SSADefUse}}
1721
1721
finalizer_useidx = useidx
1722
1722
end
1723
1723
end
1724
- if finalizer_useidx === nothing || inlining === nothing
1725
- return true
1726
- end
1727
- return finalizer_useidx
1724
+ return something (finalizer_useidx, true )
1728
1725
end
1729
1726
for (defidx, (intermediaries, defuse)) in defuses
1730
1727
# Find the type for this allocation
@@ -1749,28 +1746,28 @@ function sroa_mutables!(ir::IRCode, defuses::IdDict{Int,Tuple{SPCSet,SSADefUse}}
1749
1746
all_eliminated = all_forwarded = true
1750
1747
if nleaves ≠ nuses_total
1751
1748
finalizer_useidx = find_finalizer_useidx (defuse)
1752
- if finalizer_useidx isa Int
1749
+ if finalizer_useidx isa Int && inlining != = nothing
1753
1750
nargs = length (ir. argtypes) # COMBAK this might need to be `Int(opt.src.nargs)`
1754
1751
estate = EscapeAnalysis. analyze_escapes (ir, nargs, 𝕃ₒ, get_escape_cache (inlining. interp))
1755
1752
einfo = estate[SSAValue (defidx)]
1756
- if EscapeAnalysis. has_no_escape (einfo)
1753
+ if EscapeAnalysis. has_no_escape (EscapeAnalysis . ignore_thrownescapes ( einfo) )
1757
1754
already = BitSet (use. idx for use in defuse. uses)
1758
1755
for idx = einfo. Liveness
1759
1756
if idx ∉ already
1760
1757
push! (defuse. uses, SSAUse (:EALiveness , idx))
1761
1758
end
1762
1759
end
1763
1760
finalizer_idx = defuse. uses[finalizer_useidx]. idx
1764
- try_resolve_finalizer! (ir, defidx, finalizer_idx, defuse, inlining:: InliningState ,
1761
+ try_resolve_finalizer! (ir, defidx, finalizer_idx, defuse, inlining,
1765
1762
lazydomtree, lazypostdomtree, ir[SSAValue (finalizer_idx)][:info ])
1766
1763
end
1767
1764
end
1768
1765
continue
1769
1766
else
1770
1767
finalizer_useidx = find_finalizer_useidx (defuse)
1771
- if finalizer_useidx isa Int
1768
+ if finalizer_useidx isa Int && inlining != = nothing
1772
1769
finalizer_idx = defuse. uses[finalizer_useidx]. idx
1773
- try_resolve_finalizer! (ir, defidx, finalizer_idx, defuse, inlining:: InliningState ,
1770
+ try_resolve_finalizer! (ir, defidx, finalizer_idx, defuse, inlining,
1774
1771
lazydomtree, lazypostdomtree, ir[SSAValue (finalizer_idx)][:info ])
1775
1772
deleteat! (defuse. uses, finalizer_useidx)
1776
1773
all_eliminated = all_forwarded = false # can't eliminate `setfield!` calls safely
0 commit comments