Skip to content

Commit f007c01

Browse files
authored
fix array_builtin_common_nothrow for arrayref (#50152)
1 parent 7cd7a1b commit f007c01

File tree

2 files changed

+21
-14
lines changed

2 files changed

+21
-14
lines changed

base/compiler/tfuncs.jl

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2041,8 +2041,9 @@ function array_type_undefable(@nospecialize(arytype))
20412041
end
20422042
end
20432043

2044-
function array_builtin_common_nothrow(argtypes::Vector{Any}, first_idx_idx::Int, isarrayref::Bool)
2045-
length(argtypes) >= 4 || return false
2044+
function array_builtin_common_nothrow(argtypes::Vector{Any}, isarrayref::Bool)
2045+
first_idx_idx = isarrayref ? 3 : 4
2046+
length(argtypes) first_idx_idx || return false
20462047
boundscheck = argtypes[1]
20472048
arytype = argtypes[2]
20482049
array_builtin_common_typecheck(boundscheck, arytype, argtypes, first_idx_idx) || return false
@@ -2086,11 +2087,11 @@ end
20862087
@nospecs function _builtin_nothrow(𝕃::AbstractLattice, f, argtypes::Vector{Any}, rt)
20872088
= Core.Compiler.:(𝕃)
20882089
if f === arrayset
2089-
array_builtin_common_nothrow(argtypes, 4, #=isarrayref=#false) || return false
2090+
array_builtin_common_nothrow(argtypes, #=isarrayref=#false) || return false
20902091
# Additionally check element type compatibility
20912092
return arrayset_typecheck(argtypes[2], argtypes[3])
20922093
elseif f === arrayref || f === const_arrayref
2093-
return array_builtin_common_nothrow(argtypes, 3, #=isarrayref=#true)
2094+
return array_builtin_common_nothrow(argtypes, #=isarrayref=#true)
20942095
elseif f === Core._expr
20952096
length(argtypes) >= 1 || return false
20962097
return argtypes[1] Symbol

test/compiler/effects.jl

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -760,21 +760,27 @@ end
760760
# arrayref
761761
# --------
762762

763-
let effects = Base.infer_effects(Base.arrayref, (Vector{Any},Int))
764-
@test Core.Compiler.is_consistent_if_inaccessiblememonly(effects)
765-
@test Core.Compiler.is_effect_free(effects)
766-
@test !Core.Compiler.is_nothrow(effects)
767-
@test Core.Compiler.is_terminates(effects)
763+
for tt = Any[(Bool,Vector{Any},Int),
764+
(Bool,Matrix{Any},Int,Int)]
765+
@testset let effects = Base.infer_effects(Base.arrayref, tt)
766+
@test Core.Compiler.is_consistent_if_inaccessiblememonly(effects)
767+
@test Core.Compiler.is_effect_free(effects)
768+
@test !Core.Compiler.is_nothrow(effects)
769+
@test Core.Compiler.is_terminates(effects)
770+
end
768771
end
769772

770773
# arrayset
771774
# --------
772775

773-
let effects = Base.infer_effects(Base.arrayset, (Vector{Any},Any,Int))
774-
@test Core.Compiler.is_consistent_if_inaccessiblememonly(effects)
775-
@test Core.Compiler.is_effect_free_if_inaccessiblememonly(effects)
776-
@test !Core.Compiler.is_nothrow(effects)
777-
@test Core.Compiler.is_terminates(effects)
776+
for tt = Any[(Bool,Vector{Any},Any,Int),
777+
(Bool,Matrix{Any},Any,Int,Int)]
778+
@testset let effects = Base.infer_effects(Base.arrayset, tt)
779+
@test Core.Compiler.is_consistent_if_inaccessiblememonly(effects)
780+
@test Core.Compiler.is_effect_free_if_inaccessiblememonly(effects)
781+
@test !Core.Compiler.is_nothrow(effects)
782+
@test Core.Compiler.is_terminates(effects)
783+
end
778784
end
779785
# nothrow for arrayset
780786
@test Base.infer_effects((Vector{Int},Int,Int)) do a, v, i

0 commit comments

Comments
 (0)