Skip to content

Commit 48d5276

Browse files
committed
effects: improve nothrow modeling for Core._svec_len (#59706)
1 parent 2907ebd commit 48d5276

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

β€ŽCompiler/src/tfuncs.jlβ€Ž

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -586,15 +586,19 @@ add_tfunc(nfields, 1, 1, nfields_tfunc, 1)
586586
add_tfunc(Core._expr, 1, INT_INF, @nospecs((𝕃::AbstractLattice, args...)->Expr), 100)
587587
add_tfunc(svec, 0, INT_INF, @nospecs((𝕃::AbstractLattice, args...)->SimpleVector), 20)
588588

589-
@nospecs function _svec_len_tfunc(𝕃::AbstractLattice, s)
589+
@nospecs function _svec_len_tfunc(::AbstractLattice, s)
590590
if isa(s, Const) && isa(s.val, SimpleVector)
591591
return Const(length(s.val))
592592
end
593593
return Int
594594
end
595595
add_tfunc(Core._svec_len, 1, 1, _svec_len_tfunc, 1)
596+
@nospecs function _svec_len_nothrow(𝕃::AbstractLattice, s)
597+
βŠ‘ = partialorder(𝕃)
598+
return s βŠ‘ SimpleVector
599+
end
596600

597-
@nospecs function _svec_ref_tfunc(𝕃::AbstractLattice, s, i)
601+
@nospecs function _svec_ref_tfunc(::AbstractLattice, s, i)
598602
if isa(s, Const) && isa(i, Const)
599603
s, i = s.val, i.val
600604
if isa(s, SimpleVector) && isa(i, Int)
@@ -604,7 +608,7 @@ add_tfunc(Core._svec_len, 1, 1, _svec_len_tfunc, 1)
604608
return Any
605609
end
606610
add_tfunc(Core._svec_ref, 2, 2, _svec_ref_tfunc, 1)
607-
@nospecs function typevar_tfunc(𝕃::AbstractLattice, n, lb_arg, ub_arg)
611+
@nospecs function typevar_tfunc(::AbstractLattice, n, lb_arg, ub_arg)
608612
lb = Union{}
609613
ub = Any
610614
ub_certain = lb_certain = true
@@ -2363,7 +2367,7 @@ function _builtin_nothrow(𝕃::AbstractLattice, @nospecialize(f::Builtin), argt
23632367
return compilerbarrier_nothrow(argtypes[1], nothing)
23642368
elseif f === Core._svec_len
23652369
na == 1 || return false
2366-
return _svec_len_tfunc(𝕃, argtypes[1]) isa Const
2370+
return _svec_len_nothrow(𝕃, argtypes[1])
23672371
elseif f === Core._svec_ref
23682372
na == 2 || return false
23692373
return _svec_ref_tfunc(𝕃, argtypes[1], argtypes[2]) isa Const

β€ŽCompiler/test/effects.jlβ€Ž

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1471,3 +1471,5 @@ let effects = Base.infer_effects((Core.SimpleVector,Int); optimize=false) do sve
14711471
@test !Compiler.is_nothrow(effects)
14721472
@test Compiler.is_terminates(effects)
14731473
end
1474+
1475+
@test Compiler.is_nothrow(Base.infer_effects(length, (Core.SimpleVector,)))

0 commit comments

Comments
Β (0)