Skip to content

Commit 694902b

Browse files
authored
effects: improve nothrow modeling for Core._svec_len (#59706)
1 parent b420a6d commit 694902b

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
@@ -581,15 +581,19 @@ add_tfunc(nfields, 1, 1, nfields_tfunc, 1)
581581
add_tfunc(Core._expr, 1, INT_INF, @nospecs((𝕃::AbstractLattice, args...)->Expr), 100)
582582
add_tfunc(svec, 0, INT_INF, @nospecs((𝕃::AbstractLattice, args...)->SimpleVector), 20)
583583

584-
@nospecs function _svec_len_tfunc(𝕃::AbstractLattice, s)
584+
@nospecs function _svec_len_tfunc(::AbstractLattice, s)
585585
if isa(s, Const) && isa(s.val, SimpleVector)
586586
return Const(length(s.val))
587587
end
588588
return Int
589589
end
590590
add_tfunc(Core._svec_len, 1, 1, _svec_len_tfunc, 1)
591+
@nospecs function _svec_len_nothrow(𝕃::AbstractLattice, s)
592+
βŠ‘ = partialorder(𝕃)
593+
return s βŠ‘ SimpleVector
594+
end
591595

592-
@nospecs function _svec_ref_tfunc(𝕃::AbstractLattice, s, i)
596+
@nospecs function _svec_ref_tfunc(::AbstractLattice, s, i)
593597
if isa(s, Const) && isa(i, Const)
594598
s, i = s.val, i.val
595599
if isa(s, SimpleVector) && isa(i, Int)
@@ -599,7 +603,7 @@ add_tfunc(Core._svec_len, 1, 1, _svec_len_tfunc, 1)
599603
return Any
600604
end
601605
add_tfunc(Core._svec_ref, 2, 2, _svec_ref_tfunc, 1)
602-
@nospecs function typevar_tfunc(𝕃::AbstractLattice, n, lb_arg, ub_arg)
606+
@nospecs function typevar_tfunc(::AbstractLattice, n, lb_arg, ub_arg)
603607
lb = Union{}
604608
ub = Any
605609
ub_certain = lb_certain = true
@@ -2338,7 +2342,7 @@ function _builtin_nothrow(𝕃::AbstractLattice, @nospecialize(f::Builtin), argt
23382342
return compilerbarrier_nothrow(argtypes[1], nothing)
23392343
elseif f === Core._svec_len
23402344
na == 1 || return false
2341-
return _svec_len_tfunc(𝕃, argtypes[1]) isa Const
2345+
return _svec_len_nothrow(𝕃, argtypes[1])
23422346
elseif f === Core._svec_ref
23432347
na == 2 || return false
23442348
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
@@ -1479,3 +1479,5 @@ let effects = Base.infer_effects((Core.SimpleVector,Int); optimize=false) do sve
14791479
@test !Compiler.is_nothrow(effects)
14801480
@test Compiler.is_terminates(effects)
14811481
end
1482+
1483+
@test Compiler.is_nothrow(Base.infer_effects(length, (Core.SimpleVector,)))

0 commit comments

Comments
Β (0)