From 6b3a3ae733d71364a44c948b1a655db3a153bfb5 Mon Sep 17 00:00:00 2001 From: Hendrik Ranocha Date: Tue, 30 Aug 2022 15:44:43 +0200 Subject: [PATCH 1/4] improve type stability of `mightalias(A::AbstractArray, B::AbstractArray)` This improvement prevents some invalidations in abstractarray.jl when loading Static.jl. --- base/abstractarray.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/base/abstractarray.jl b/base/abstractarray.jl index c3d04dcbef39d..e96f284163d81 100644 --- a/base/abstractarray.jl +++ b/base/abstractarray.jl @@ -1492,7 +1492,7 @@ Perform a conservative test to check if arrays `A` and `B` might share the same By default, this simply checks if either of the arrays reference the same memory regions, as identified by their [`Base.dataids`](@ref). """ -mightalias(A::AbstractArray, B::AbstractArray) = !isbits(A) && !isbits(B) && !_isdisjoint(dataids(A), dataids(B)) +mightalias(A::AbstractArray, B::AbstractArray) = !(isbits(A)::Bool) && !(isbits(B)::Bool) && !_isdisjoint(dataids(A), dataids(B)) mightalias(x, y) = false _isdisjoint(as::Tuple{}, bs::Tuple{}) = true From a42af13099ef2bd3e0aaacf376429b97db708dee Mon Sep 17 00:00:00 2001 From: Hendrik Ranocha Date: Wed, 31 Aug 2022 15:05:50 +0200 Subject: [PATCH 2/4] Revert "improve type stability of `mightalias(A::AbstractArray, B::AbstractArray)`" This reverts commit 6b3a3ae733d71364a44c948b1a655db3a153bfb5. --- base/abstractarray.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/base/abstractarray.jl b/base/abstractarray.jl index e96f284163d81..c3d04dcbef39d 100644 --- a/base/abstractarray.jl +++ b/base/abstractarray.jl @@ -1492,7 +1492,7 @@ Perform a conservative test to check if arrays `A` and `B` might share the same By default, this simply checks if either of the arrays reference the same memory regions, as identified by their [`Base.dataids`](@ref). """ -mightalias(A::AbstractArray, B::AbstractArray) = !(isbits(A)::Bool) && !(isbits(B)::Bool) && !_isdisjoint(dataids(A), dataids(B)) +mightalias(A::AbstractArray, B::AbstractArray) = !isbits(A) && !isbits(B) && !_isdisjoint(dataids(A), dataids(B)) mightalias(x, y) = false _isdisjoint(as::Tuple{}, bs::Tuple{}) = true From 8bbc8a0829507ad17452cf295b842688c4b79ba6 Mon Sep 17 00:00:00 2001 From: Hendrik Ranocha Date: Wed, 31 Aug 2022 15:07:17 +0200 Subject: [PATCH 3/4] improve type stability of `findall(testf::Function, A::AbstractArray)` This prevents some invalidations in `mightalias(A::AbstractArray, B::AbstractArray)` in abstractarray.jl when loading Static.jl. --- base/array.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/base/array.jl b/base/array.jl index 85296b4d94f21..1f564f5aa4c9c 100644 --- a/base/array.jl +++ b/base/array.jl @@ -2325,7 +2325,7 @@ findall(testf::Function, A) = collect(first(p) for p in pairs(A) if testf(last(p # Broadcasting is much faster for small testf, and computing # integer indices from logical index using findall has a negligible cost -findall(testf::Function, A::AbstractArray) = findall(testf.(A)) +findall(testf::Function, A::AbstractArray) = findall(map(testf, A)) """ findall(A) From 71ba31d4dd05695256caf198ee81c302439434a2 Mon Sep 17 00:00:00 2001 From: Hendrik Ranocha Date: Wed, 31 Aug 2022 15:45:09 +0200 Subject: [PATCH 4/4] improve type stability of `findall(testf::Function, A::AbstractArray)` This prevents some invalidations in `mightalias(A::AbstractArray, B::AbstractArray)` in abstractarray.jl when loading Static.jl. Here we specialize on the function instead of using map since broadcasting returns a BitArray, map a Vector{Bool}. --- base/array.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/base/array.jl b/base/array.jl index 1f564f5aa4c9c..e50c1a9c806ad 100644 --- a/base/array.jl +++ b/base/array.jl @@ -2325,7 +2325,7 @@ findall(testf::Function, A) = collect(first(p) for p in pairs(A) if testf(last(p # Broadcasting is much faster for small testf, and computing # integer indices from logical index using findall has a negligible cost -findall(testf::Function, A::AbstractArray) = findall(map(testf, A)) +findall(testf::F, A::AbstractArray) where {F<:Function} = findall(testf.(A)) """ findall(A)