diff --git a/src/EscapeAnalysis.jl b/src/EscapeAnalysis.jl index 4dceeab..459d4a9 100644 --- a/src/EscapeAnalysis.jl +++ b/src/EscapeAnalysis.jl @@ -1066,6 +1066,8 @@ function escape_builtin!(::typeof(setfield!), astate::AnalysisState, pc::Int, ar return true end +const Arrayish = Union{Array,Core.ImmutableArray} + function escape_builtin!(::typeof(arrayref), astate::AnalysisState, pc::Int, args::Vector{Any}) length(args) ≥ 4 || return false # check potential escapes from this arrayref call @@ -1074,7 +1076,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(Arrayish, boundcheckt, aryt, argtypes, 3) add_thrown_escapes!(astate, pc, args, 2) end # we don't track precise index information about this array and thus don't know what values @@ -1138,7 +1140,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(Array, boundcheckt, aryt, argtypes, 4) && arrayset_typecheck(aryt, valt)) add_thrown_escapes!(astate, pc, args, 2) end @@ -1321,22 +1323,20 @@ end # return true # end -if isdefined(Core, :arrayfreeze) && isdefined(Core, :arraythaw) && isdefined(Core, :mutating_arrayfreeze) +import Core: ImmutableArray, arrayfreeze, mutating_arrayfreeze, arraythaw -escape_builtin!(::typeof(Core.arrayfreeze), astate::AnalysisState, pc::Int, args::Vector{Any}) = +escape_builtin!(::typeof(arrayfreeze), astate::AnalysisState, pc::Int, args::Vector{Any}) = escape_immutable_array!(Array, astate, pc, args) -escape_builtin!(::typeof(Core.mutating_arrayfreeze), astate::AnalysisState, pc::Int, args::Vector{Any}) = +escape_builtin!(::typeof(mutating_arrayfreeze), astate::AnalysisState, pc::Int, args::Vector{Any}) = escape_immutable_array!(Array, astate, pc, args) -escape_builtin!(::typeof(Core.arraythaw), astate::AnalysisState, pc::Int, args::Vector{Any}) = - escape_immutable_array!(Core.ImmutableArray, astate, pc, args) +escape_builtin!(::typeof(arraythaw), astate::AnalysisState, pc::Int, args::Vector{Any}) = + escape_immutable_array!(ImmutableArray, astate, pc, args) function escape_immutable_array!(@nospecialize(arytype), astate::AnalysisState, pc::Int, args::Vector{Any}) length(args) == 2 || return false argextype(args[2], astate.ir) ⊑ₜ arytype || return false return true end -end # if isdefined(Core, :arrayfreeze) && isdefined(Core, :arraythaw) && isdefined(Core, :mutating_arrayfreeze) - # NOTE define fancy package utilities when developing EA as an external package if _TOP_MOD !== Core.Compiler include(@__MODULE__, "utils.jl")