Skip to content

Commit 7381e22

Browse files
committed
improve inferred effects for reshape for Array
Use `LazyString` in `throw_dmrsa`.
1 parent 16197f8 commit 7381e22

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-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: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,17 @@ 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_noub(effects)
110+
@test Base.Compiler.is_nortcall(effects)
111+
end
112+
end
113+
end
103114
@testset "reshaping SubArrays" begin
104115
a = Array(reshape(1:5, 1, 5))
105116
@testset "linearfast" begin

0 commit comments

Comments
 (0)