Skip to content

Commit 9c702e9

Browse files
nsajkoKristofferC
authored andcommitted
improve inferred effects for reshape for Array (#58672)
(cherry picked from commit 1052201)
1 parent d87f8f9 commit 9c702e9

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

base/reshapedarray.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ length(R::ReshapedArrayIterator) = length(R.iter)
3636
eltype(::Type{<:ReshapedArrayIterator{I}}) where {I} = @isdefined(I) ? ReshapedIndex{eltype(I)} : Any
3737

3838
@noinline throw_dmrsa(dims, len) =
39-
throw(DimensionMismatch("new dimensions $(dims) must be consistent with array length $len"))
39+
throw(DimensionMismatch(LazyString("new dimensions ", dims, " must be consistent with array length ", len)))
4040

4141
## reshape(::Array, ::Dims) returns a new Array (to avoid conditionally aliasing the structure, only the data)
4242
# reshaping to same # of dimensions

test/arrayops.jl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,18 @@ using Dates
100100
@test Array{eltype(a)}(a) !== a
101101
@test Vector(a) !== a
102102
end
103+
@testset "effect inference for `reshape` for `Array`" begin
104+
for Arr (Array{<:Any, 0}, Vector, Matrix, Array{<:Any, 3})
105+
for Shape (Tuple{Int}, Tuple{Int, Int})
106+
effects = Base.infer_effects(reshape, Tuple{Arr{Float32}, Shape})
107+
@test Base.Compiler.is_effect_free(effects)
108+
@test Base.Compiler.is_terminates(effects)
109+
@test Base.Compiler.is_notaskstate(effects)
110+
@test Base.Compiler.is_noub(effects)
111+
@test Base.Compiler.is_nortcall(effects)
112+
end
113+
end
114+
end
103115
@testset "reshaping SubArrays" begin
104116
a = Array(reshape(1:5, 1, 5))
105117
@testset "linearfast" begin

0 commit comments

Comments
 (0)