@@ -361,9 +361,10 @@ function ir_inline_item!(compact::IncrementalCompact, idx::Int, argexprs::Vector
361
361
if extra_coverage_line != 0
362
362
insert_node_here! (compact, NewInstruction (Expr (:code_coverage_effect ), Nothing, extra_coverage_line))
363
363
end
364
+ sp_ssa = nothing
364
365
if ! validate_sparams (sparam_vals)
365
366
# N.B. This works on the caller-side argexprs, (i.e. before the va fixup below)
366
- sparam_vals = insert_node_here! (compact,
367
+ sp_ssa = insert_node_here! (compact,
367
368
effect_free (NewInstruction (Expr (:call , Core. _compute_sparams, def, argexprs... ), SimpleVector, topline)))
368
369
end
369
370
if def. isva
@@ -398,7 +399,7 @@ function ir_inline_item!(compact::IncrementalCompact, idx::Int, argexprs::Vector
398
399
# face of rename_arguments! mutating in place - should figure out
399
400
# something better eventually.
400
401
inline_compact[idx′] = nothing
401
- stmt′ = ssa_substitute! (idx′, stmt′, argexprs, sig, sparam_vals, linetable_offset, boundscheck, inline_compact)
402
+ stmt′ = ssa_substitute! (idx′, stmt′, argexprs, sig, sparam_vals, sp_ssa, linetable_offset, boundscheck, inline_compact)
402
403
if isa (stmt′, ReturnNode)
403
404
val = stmt′. val
404
405
return_value = SSAValue (idx′)
@@ -425,7 +426,7 @@ function ir_inline_item!(compact::IncrementalCompact, idx::Int, argexprs::Vector
425
426
inline_compact = IncrementalCompact (compact, spec. ir, compact. result_idx)
426
427
for ((_, idx′), stmt′) in inline_compact
427
428
inline_compact[idx′] = nothing
428
- stmt′ = ssa_substitute! (idx′, stmt′, argexprs, sig, sparam_vals, linetable_offset, boundscheck, inline_compact)
429
+ stmt′ = ssa_substitute! (idx′, stmt′, argexprs, sig, sparam_vals, sp_ssa, linetable_offset, boundscheck, inline_compact)
429
430
if isa (stmt′, ReturnNode)
430
431
if isdefined (stmt′, :val )
431
432
val = stmt′. val
903
904
904
905
function can_inline_typevars (method:: Method , argtypes:: Vector{Any} )
905
906
may_have_fcalls (method) && return false
906
- any (@nospecialize (x) -> x isa UnionAll, argtypes[2 : end ]) && return false
907
907
return true
908
908
end
909
909
can_inline_typevars (m:: MethodMatch , argtypes:: Vector{Any} ) = can_inline_typevars (m. method, argtypes)
@@ -1724,15 +1724,30 @@ function late_inline_special_case!(
1724
1724
end
1725
1725
1726
1726
function ssa_substitute! (idx:: Int , @nospecialize (val), arg_replacements:: Vector{Any} ,
1727
- @nospecialize (spsig), spvals:: Union{SimpleVector, SSAValue} ,
1727
+ @nospecialize (spsig), spvals:: SimpleVector ,
1728
+ spvals_ssa:: Union{Nothing, SSAValue} ,
1728
1729
linetable_offset:: Int32 , boundscheck:: Symbol , compact:: IncrementalCompact )
1729
1730
compact. result[idx][:flag ] &= ~ IR_FLAG_INBOUNDS
1730
1731
compact. result[idx][:line ] += linetable_offset
1731
- return ssa_substitute_op! (val, arg_replacements, spsig, spvals, boundscheck, compact, idx)
1732
+ return ssa_substitute_op! (val, arg_replacements, spsig, spvals, spvals_ssa, boundscheck, compact, idx)
1733
+ end
1734
+
1735
+ function insert_spval! (compact:: IncrementalCompact , idx:: Int , spvals_ssa:: SSAValue , spidx:: Int , do_isdefined:: Bool )
1736
+ ret = insert_node! (compact, SSAValue (idx),
1737
+ effect_free (NewInstruction (Expr (:call , Core. _svec_ref, false , spvals_ssa, spidx), Any)))
1738
+ tcheck_not = nothing
1739
+ if do_isdefined
1740
+ tcheck = insert_node! (compact, SSAValue (idx),
1741
+ effect_free (NewInstruction (Expr (:call , Core. isa, ret, Core. TypeVar), Bool)))
1742
+ tcheck_not = insert_node! (compact, SSAValue (idx),
1743
+ effect_free (NewInstruction (Expr (:call , not_int, tcheck), Bool)))
1744
+ end
1745
+ return (ret, tcheck_not)
1732
1746
end
1733
1747
1734
1748
function ssa_substitute_op! (@nospecialize (val), arg_replacements:: Vector{Any} ,
1735
- @nospecialize (spsig), spvals:: Union{SimpleVector, SSAValue} ,
1749
+ @nospecialize (spsig), spvals:: SimpleVector ,
1750
+ spvals_ssa:: Union{Nothing, SSAValue} ,
1736
1751
boundscheck:: Symbol , compact:: IncrementalCompact , idx:: Int )
1737
1752
if isa (val, Argument)
1738
1753
return arg_replacements[val. n]
@@ -1741,20 +1756,36 @@ function ssa_substitute_op!(@nospecialize(val), arg_replacements::Vector{Any},
1741
1756
e = val:: Expr
1742
1757
head = e. head
1743
1758
if head === :static_parameter
1744
- if isa (spvals, SimpleVector)
1745
- return quoted (spvals[e. args[1 ]:: Int ])
1759
+ spidx = e. args[1 ]:: Int
1760
+ val = spvals[spidx]
1761
+ if ! isa (val, TypeVar) && val != = Vararg
1762
+ return quoted (val)
1746
1763
else
1747
- ret = insert_node! (compact, SSAValue (idx),
1748
- effect_free (NewInstruction (Expr (:call , Core. _svec_ref, false , spvals, e. args[1 ]), Any)))
1764
+ flag = compact[SSAValue (idx)][:flag ]
1765
+ maybe_undef = (flag & IR_FLAG_NOTHROW) == 0 && isa (val, TypeVar)
1766
+ (ret, tcheck_not) = insert_spval! (compact, idx, spvals_ssa, spidx, maybe_undef)
1767
+ if maybe_undef
1768
+ insert_node! (compact, SSAValue (idx),
1769
+ non_effect_free (NewInstruction (Expr (:throw_undef_if_not , val. name, tcheck_not), Nothing)))
1770
+ end
1749
1771
return ret
1750
1772
end
1751
- elseif head === :cfunction && isa (spvals, SimpleVector)
1773
+ elseif head === :isdefined && isa (e. args[1 ], Expr) && e. args[1 ]. head === :static_parameter
1774
+ spidx = (e. args[1 ]:: Expr ). args[1 ]:: Int
1775
+ val = spvals[spidx]
1776
+ if ! isa (val, TypeVar)
1777
+ return true
1778
+ else
1779
+ (_, tcheck_not) = insert_spval! (compact, idx, spvals_ssa, spidx, true )
1780
+ return tcheck_not
1781
+ end
1782
+ elseif head === :cfunction && spvals_ssa === nothing
1752
1783
@assert ! isa (spsig, UnionAll) || ! isempty (spvals)
1753
1784
e. args[3 ] = ccall (:jl_instantiate_type_in_env , Any, (Any, Any, Ptr{Any}), e. args[3 ], spsig, spvals)
1754
1785
e. args[4 ] = svec (Any[
1755
1786
ccall (:jl_instantiate_type_in_env , Any, (Any, Any, Ptr{Any}), argt, spsig, spvals)
1756
1787
for argt in e. args[4 ]:: SimpleVector ]. .. )
1757
- elseif head === :foreigncall && isa (spvals, SimpleVector)
1788
+ elseif head === :foreigncall && spvals_ssa === nothing
1758
1789
@assert ! isa (spsig, UnionAll) || ! isempty (spvals)
1759
1790
for i = 1 : length (e. args)
1760
1791
if i == 2
@@ -1778,7 +1809,7 @@ function ssa_substitute_op!(@nospecialize(val), arg_replacements::Vector{Any},
1778
1809
isa (val, Union{SSAValue, NewSSAValue}) && return val # avoid infinite loop
1779
1810
urs = userefs (val)
1780
1811
for op in urs
1781
- op[] = ssa_substitute_op! (op[], arg_replacements, spsig, spvals, boundscheck, compact, idx)
1812
+ op[] = ssa_substitute_op! (op[], arg_replacements, spsig, spvals, spvals_ssa, boundscheck, compact, idx)
1782
1813
end
1783
1814
return urs[]
1784
1815
end
0 commit comments