Skip to content

Commit

Permalink
release 1.10: backport the lattice fix for array op type checks (#52773
Browse files Browse the repository at this point in the history
…) (#52774)
  • Loading branch information
aviatesk authored Jan 7, 2024
1 parent 6a107d0 commit 5c0a2a6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
4 changes: 2 additions & 2 deletions base/compiler/ssair/EscapeAnalysis/EscapeAnalysis.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1615,7 +1615,7 @@ function escape_builtin!(::typeof(arrayref), astate::AnalysisState, pc::Int, arg
argtypes = Any[argextype(args[i], astate.ir) for i in 2:length(args)]
boundcheckt = argtypes[1]
aryt = argtypes[2]
if !array_builtin_common_typecheck(boundcheckt, aryt, argtypes, 3)
if !array_builtin_common_typecheck(𝕃ₒ, boundcheckt, aryt, argtypes, 3)
add_thrown_escapes!(astate, pc, args, 2)
end
ary = args[3]
Expand Down Expand Up @@ -1679,7 +1679,7 @@ function escape_builtin!(::typeof(arrayset), astate::AnalysisState, pc::Int, arg
boundcheckt = argtypes[1]
aryt = argtypes[2]
valt = argtypes[3]
if !(array_builtin_common_typecheck(boundcheckt, aryt, argtypes, 4) &&
if !(array_builtin_common_typecheck(𝕃ₒ, boundcheckt, aryt, argtypes, 4) &&
arrayset_typecheck(aryt, valt))
add_thrown_escapes!(astate, pc, args, 2)
end
Expand Down
13 changes: 7 additions & 6 deletions base/compiler/tfuncs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2034,12 +2034,12 @@ function array_type_undefable(@nospecialize(arytype))
end
end

function array_builtin_common_nothrow(argtypes::Vector{Any}, isarrayref::Bool)
function array_builtin_common_nothrow(𝕃::AbstractLattice, argtypes::Vector{Any}, isarrayref::Bool)
first_idx_idx = isarrayref ? 3 : 4
length(argtypes) first_idx_idx || return false
boundscheck = argtypes[1]
arytype = argtypes[2]
array_builtin_common_typecheck(boundscheck, arytype, argtypes, first_idx_idx) || return false
array_builtin_common_typecheck(𝕃, boundscheck, arytype, argtypes, first_idx_idx) || return false
if isarrayref
# If we could potentially throw undef ref errors, bail out now.
arytype = widenconst(arytype)
Expand All @@ -2056,8 +2056,9 @@ function array_builtin_common_nothrow(argtypes::Vector{Any}, isarrayref::Bool)
return false
end

@nospecs function array_builtin_common_typecheck(boundscheck, arytype,
argtypes::Vector{Any}, first_idx_idx::Int)
@nospecs function array_builtin_common_typecheck(𝕃::AbstractLattice,
boundscheck, arytype, argtypes::Vector{Any}, first_idx_idx::Int)
= Core.Compiler.:(𝕃)
(boundscheck Bool && arytype Array) || return false
for i = first_idx_idx:length(argtypes)
argtypes[i] Int || return false
Expand All @@ -2080,11 +2081,11 @@ end
@nospecs function _builtin_nothrow(𝕃::AbstractLattice, f, argtypes::Vector{Any}, rt)
= Core.Compiler.:(𝕃)
if f === arrayset
array_builtin_common_nothrow(argtypes, #=isarrayref=#false) || return false
array_builtin_common_nothrow(𝕃, argtypes, #=isarrayref=#false) || return false
# Additionally check element type compatibility
return arrayset_typecheck(argtypes[2], argtypes[3])
elseif f === arrayref || f === const_arrayref
return array_builtin_common_nothrow(argtypes, #=isarrayref=#true)
return array_builtin_common_nothrow(𝕃, argtypes, #=isarrayref=#true)
elseif f === Core._expr
length(argtypes) >= 1 || return false
return argtypes[1] Symbol
Expand Down

0 comments on commit 5c0a2a6

Please sign in to comment.