Skip to content

Commit f0a91f7

Browse files
andyferrisAndy Ferris
authored andcommitted
Use Val(x) and f(::Val{x})
Replaces `f(Val{x})` on call sites with `f(Val(x))`, using a new `@pure` function `Val(x) = Val{x}()`. This simplifies the method definitions from `f(::Type{Val{x}}) where x` to `f(::Val{x}) where x`. This form also has the advantage that multiple singleton instances can be put in a tuple and inference will work (similarly with multiple-return functions).
1 parent bf83397 commit f0a91f7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+261
-216
lines changed

NEWS.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,12 @@ Library improvements
8686
* `@test isequal(x, y)` and `@test isapprox(x, y)` now prints an evaluated expression when
8787
the test fails ([#22296]).
8888

89+
* Uses of `Val{c}` in `Base` has been replaced with `Val{c}()`, which is now easily
90+
accessible via the `@pure` constructor `Val(c)`. Functions are defined as
91+
`f(::Val{c}) = ...` and called by `f(Val(c))`. Notable affected functions include:
92+
`ntuple`, `Base.literal_pow`, `sqrtm`, `lufact`, `lufact!`, `qrfact`, `qrfact!`,
93+
`cholfact`, `cholfact!`, `_broadcast!`, `reshape`, `cat` and `cat_t`.
94+
8995
Compiler/Runtime improvements
9096
-----------------------------
9197

base/abstractarray.jl

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ julia> size(A,3,2)
2828
"""
2929
size(t::AbstractArray{T,N}, d) where {T,N} = d <= N ? size(t)[d] : 1
3030
size(x, d1::Integer, d2::Integer, dx::Vararg{Integer, N}) where {N} =
31-
(size(x, d1), size(x, d2), ntuple(k->size(x, dx[k]), Val{N})...)
31+
(size(x, d1), size(x, d2), ntuple(k->size(x, dx[k]), Val(N))...)
3232

3333
"""
3434
indices(A, d)
@@ -954,13 +954,13 @@ function _getindex(::IndexCartesian, A::AbstractArray{T,N}, I::Vararg{Int, N}) w
954954
getindex(A, I...)
955955
end
956956
_to_subscript_indices(A::AbstractArray, i::Int) = (@_inline_meta; _unsafe_ind2sub(A, i))
957-
_to_subscript_indices(A::AbstractArray{T,N}) where {T,N} = (@_inline_meta; fill_to_length((), 1, Val{N})) # TODO: DEPRECATE FOR #14770
957+
_to_subscript_indices(A::AbstractArray{T,N}) where {T,N} = (@_inline_meta; fill_to_length((), 1, Val(N))) # TODO: DEPRECATE FOR #14770
958958
_to_subscript_indices(A::AbstractArray{T,0}) where {T} = () # TODO: REMOVE FOR #14770
959959
_to_subscript_indices(A::AbstractArray{T,0}, i::Int) where {T} = () # TODO: REMOVE FOR #14770
960960
_to_subscript_indices(A::AbstractArray{T,0}, I::Int...) where {T} = () # TODO: DEPRECATE FOR #14770
961961
function _to_subscript_indices(A::AbstractArray{T,N}, I::Int...) where {T,N} # TODO: DEPRECATE FOR #14770
962962
@_inline_meta
963-
J, Jrem = IteratorsMD.split(I, Val{N})
963+
J, Jrem = IteratorsMD.split(I, Val(N))
964964
_to_subscript_indices(A, J, Jrem)
965965
end
966966
_to_subscript_indices(A::AbstractArray, J::Tuple, Jrem::Tuple{}) =
@@ -1203,7 +1203,7 @@ cat_shape(dims, shape::Tuple) = shape
12031203

12041204
_cshp(ndim::Int, ::Tuple{}, ::Tuple{}, ::Tuple{}) = ()
12051205
_cshp(ndim::Int, ::Tuple{}, ::Tuple{}, nshape) = nshape
1206-
_cshp(ndim::Int, dims, ::Tuple{}, ::Tuple{}) = ntuple(b -> 1, Val{length(dims)})
1206+
_cshp(ndim::Int, dims, ::Tuple{}, ::Tuple{}) = ntuple(b -> 1, Val(length(dims)))
12071207
@inline _cshp(ndim::Int, dims, shape, ::Tuple{}) =
12081208
(shape[1] + dims[1], _cshp(ndim + 1, tail(dims), tail(shape), ())...)
12091209
@inline _cshp(ndim::Int, dims, ::Tuple{}, nshape) =
@@ -1226,7 +1226,7 @@ end
12261226
_cs(d, a, b) = (a == b ? a : throw(DimensionMismatch(
12271227
"mismatch in dimension $d (expected $a got $b)")))
12281228

1229-
dims2cat(::Type{Val{n}}) where {n} = ntuple(i -> (i == n), Val{n})
1229+
dims2cat(::Val{n}) where {n} = ntuple(i -> (i == n), Val(n))
12301230
dims2cat(dims) = ntuple(i -> (i in dims), maximum(dims))
12311231

12321232
cat(dims, X...) = cat_t(dims, promote_eltypeof(X...), X...)
@@ -1290,7 +1290,7 @@ julia> vcat(c...)
12901290
4 5 6
12911291
```
12921292
"""
1293-
vcat(X...) = cat(Val{1}, X...)
1293+
vcat(X...) = cat(Val(1), X...)
12941294
"""
12951295
hcat(A...)
12961296
@@ -1331,28 +1331,28 @@ julia> hcat(c...)
13311331
3 6
13321332
```
13331333
"""
1334-
hcat(X...) = cat(Val{2}, X...)
1334+
hcat(X...) = cat(Val(2), X...)
13351335

1336-
typed_vcat(T::Type, X...) = cat_t(Val{1}, T, X...)
1337-
typed_hcat(T::Type, X...) = cat_t(Val{2}, T, X...)
1336+
typed_vcat(T::Type, X...) = cat_t(Val(1), T, X...)
1337+
typed_hcat(T::Type, X...) = cat_t(Val(2), T, X...)
13381338

13391339
cat(catdims, A::AbstractArray{T}...) where {T} = cat_t(catdims, T, A...)
13401340

13411341
# The specializations for 1 and 2 inputs are important
13421342
# especially when running with --inline=no, see #11158
1343-
vcat(A::AbstractArray) = cat(Val{1}, A)
1344-
vcat(A::AbstractArray, B::AbstractArray) = cat(Val{1}, A, B)
1345-
vcat(A::AbstractArray...) = cat(Val{1}, A...)
1346-
hcat(A::AbstractArray) = cat(Val{2}, A)
1347-
hcat(A::AbstractArray, B::AbstractArray) = cat(Val{2}, A, B)
1348-
hcat(A::AbstractArray...) = cat(Val{2}, A...)
1349-
1350-
typed_vcat(T::Type, A::AbstractArray) = cat_t(Val{1}, T, A)
1351-
typed_vcat(T::Type, A::AbstractArray, B::AbstractArray) = cat_t(Val{1}, T, A, B)
1352-
typed_vcat(T::Type, A::AbstractArray...) = cat_t(Val{1}, T, A...)
1353-
typed_hcat(T::Type, A::AbstractArray) = cat_t(Val{2}, T, A)
1354-
typed_hcat(T::Type, A::AbstractArray, B::AbstractArray) = cat_t(Val{2}, T, A, B)
1355-
typed_hcat(T::Type, A::AbstractArray...) = cat_t(Val{2}, T, A...)
1343+
vcat(A::AbstractArray) = cat(Val(1), A)
1344+
vcat(A::AbstractArray, B::AbstractArray) = cat(Val(1), A, B)
1345+
vcat(A::AbstractArray...) = cat(Val(1), A...)
1346+
hcat(A::AbstractArray) = cat(Val(2), A)
1347+
hcat(A::AbstractArray, B::AbstractArray) = cat(Val(2), A, B)
1348+
hcat(A::AbstractArray...) = cat(Val(2), A...)
1349+
1350+
typed_vcat(T::Type, A::AbstractArray) = cat_t(Val(1), T, A)
1351+
typed_vcat(T::Type, A::AbstractArray, B::AbstractArray) = cat_t(Val(1), T, A, B)
1352+
typed_vcat(T::Type, A::AbstractArray...) = cat_t(Val(1), T, A...)
1353+
typed_hcat(T::Type, A::AbstractArray) = cat_t(Val(2), T, A)
1354+
typed_hcat(T::Type, A::AbstractArray, B::AbstractArray) = cat_t(Val(2), T, A, B)
1355+
typed_hcat(T::Type, A::AbstractArray...) = cat_t(Val(2), T, A...)
13561356

13571357
# 2d horizontal and vertical concatenation
13581358

@@ -1721,7 +1721,7 @@ _sub2ind_vec(i) = ()
17211721

17221722
function ind2sub(inds::Union{DimsInteger{N},Indices{N}}, ind::AbstractVector{<:Integer}) where N
17231723
M = length(ind)
1724-
t = ntuple(n->similar(ind),Val{N})
1724+
t = ntuple(n->similar(ind),Val(N))
17251725
for (i,idx) in enumerate(IndexLinear(), ind)
17261726
sub = ind2sub(inds, idx)
17271727
for j = 1:N

base/abstractarraymath.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -368,8 +368,8 @@ julia> repeat([1 2; 3 4], inner=(2, 1), outer=(1, 3))
368368
```
369369
"""
370370
function repeat(A::AbstractArray;
371-
inner=ntuple(n->1, Val{ndims(A)}),
372-
outer=ntuple(n->1, Val{ndims(A)}))
371+
inner=ntuple(n->1, Val(ndims(A))),
372+
outer=ntuple(n->1, Val(ndims(A))))
373373
return _repeat(A, rep_kw2tup(inner), rep_kw2tup(outer))
374374
end
375375

base/array.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ end
8585
size(a::Array, d) = arraysize(a, d)
8686
size(a::Vector) = (arraysize(a,1),)
8787
size(a::Matrix) = (arraysize(a,1), arraysize(a,2))
88-
size(a::Array{<:Any,N}) where {N} = (@_inline_meta; ntuple(M -> size(a, M), Val{N}))
88+
size(a::Array{<:Any,N}) where {N} = (@_inline_meta; ntuple(M -> size(a, M), Val(N)))
8989

9090
asize_from(a::Array, n) = n > ndims(a) ? () : (arraysize(a,n), asize_from(a, n+1)...)
9191

base/bitarray.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,7 @@ reshape(B::BitArray, dims::Tuple{Vararg{Int}}) = _bitreshape(B, dims)
480480
function _bitreshape(B::BitArray, dims::NTuple{N,Int}) where N
481481
prod(dims) == length(B) ||
482482
throw(DimensionMismatch("new dimensions $(dims) must be consistent with array size $(length(B))"))
483-
Br = BitArray{N}(ntuple(i->0,Val{N})...)
483+
Br = BitArray{N}(ntuple(i->0,Val(N))...)
484484
Br.chunks = B.chunks
485485
Br.len = prod(dims)
486486
N != 1 && (Br.dims = dims)

base/broadcast.jl

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ Base.@propagate_inbounds _broadcast_getindex(::Any, A, I) = A[I]
134134
## Broadcasting core
135135
# nargs encodes the number of As arguments (which matches the number
136136
# of keeps). The first two type parameters are to ensure specialization.
137-
@generated function _broadcast!(f, B::AbstractArray, keeps::K, Idefaults::ID, A::AT, Bs::BT, ::Type{Val{N}}, iter) where {K,ID,AT,BT,N}
137+
@generated function _broadcast!(f, B::AbstractArray, keeps::K, Idefaults::ID, A::AT, Bs::BT, ::Val{N}, iter) where {K,ID,AT,BT,N}
138138
nargs = N + 1
139139
quote
140140
$(Expr(:meta, :inline))
@@ -157,7 +157,7 @@ end
157157

158158
# For BitArray outputs, we cache the result in a "small" Vector{Bool},
159159
# and then copy in chunks into the output
160-
@generated function _broadcast!(f, B::BitArray, keeps::K, Idefaults::ID, A::AT, Bs::BT, ::Type{Val{N}}, iter) where {K,ID,AT,BT,N}
160+
@generated function _broadcast!(f, B::BitArray, keeps::K, Idefaults::ID, A::AT, Bs::BT, ::Val{N}, iter) where {K,ID,AT,BT,N}
161161
nargs = N + 1
162162
quote
163163
$(Expr(:meta, :inline))
@@ -207,12 +207,12 @@ as in `broadcast!(f, A, A, B)` to perform `A[:] = broadcast(f, A, B)`.
207207
@boundscheck check_broadcast_indices(shape, A, Bs...)
208208
keeps, Idefaults = map_newindexer(shape, A, Bs)
209209
iter = CartesianRange(shape)
210-
_broadcast!(f, C, keeps, Idefaults, A, Bs, Val{N}, iter)
210+
_broadcast!(f, C, keeps, Idefaults, A, Bs, Val(N), iter)
211211
return C
212212
end
213213

214214
# broadcast with computed element type
215-
@generated function _broadcast!(f, B::AbstractArray, keeps::K, Idefaults::ID, As::AT, ::Type{Val{nargs}}, iter, st, count) where {K,ID,AT,nargs}
215+
@generated function _broadcast!(f, B::AbstractArray, keeps::K, Idefaults::ID, As::AT, ::Val{nargs}, iter, st, count) where {K,ID,AT,nargs}
216216
quote
217217
$(Expr(:meta, :noinline))
218218
# destructure the keeps and As tuples
@@ -238,7 +238,7 @@ end
238238
new[II] = B[II]
239239
end
240240
new[I] = V
241-
return _broadcast!(f, new, keeps, Idefaults, As, Val{nargs}, iter, st, count+1)
241+
return _broadcast!(f, new, keeps, Idefaults, As, Val(nargs), iter, st, count+1)
242242
end
243243
count += 1
244244
end
@@ -259,12 +259,12 @@ function broadcast_t(f, ::Type{Any}, shape, iter, As...)
259259
B = similar(Array{typeof(val)}, shape)
260260
end
261261
B[I] = val
262-
return _broadcast!(f, B, keeps, Idefaults, As, Val{nargs}, iter, st, 1)
262+
return _broadcast!(f, B, keeps, Idefaults, As, Val(nargs), iter, st, 1)
263263
end
264264
@inline function broadcast_t(f, T, shape, iter, A, Bs::Vararg{Any,N}) where N
265265
C = similar(Array{T}, shape)
266266
keeps, Idefaults = map_newindexer(shape, A, Bs)
267-
_broadcast!(f, C, keeps, Idefaults, A, Bs, Val{N}, iter)
267+
_broadcast!(f, C, keeps, Idefaults, A, Bs, Val(N), iter)
268268
return C
269269
end
270270

@@ -275,7 +275,7 @@ end
275275
@inline function broadcast_t(f, ::Type{Bool}, shape, iter, A, Bs::Vararg{Any,N}) where N
276276
C = similar(BitArray, shape)
277277
keeps, Idefaults = map_newindexer(shape, A, Bs)
278-
_broadcast!(f, C, keeps, Idefaults, A, Bs, Val{N}, iter)
278+
_broadcast!(f, C, keeps, Idefaults, A, Bs, Val(N), iter)
279279
return C
280280
end
281281

@@ -335,9 +335,9 @@ end
335335
@inline broadcast_c(f, ::Type{Tuple}, A, Bs...) =
336336
tuplebroadcast(f, first_tuple(A, Bs...), A, Bs...)
337337
@inline tuplebroadcast(f, ::NTuple{N,Any}, As...) where {N} =
338-
ntuple(k -> f(tuplebroadcast_getargs(As, k)...), Val{N})
338+
ntuple(k -> f(tuplebroadcast_getargs(As, k)...), Val(N))
339339
@inline tuplebroadcast(f, ::NTuple{N,Any}, ::Type{T}, As...) where {N,T} =
340-
ntuple(k -> f(T, tuplebroadcast_getargs(As, k)...), Val{N})
340+
ntuple(k -> f(T, tuplebroadcast_getargs(As, k)...), Val(N))
341341
first_tuple(A::Tuple, Bs...) = A
342342
@inline first_tuple(A, Bs...) = first_tuple(Bs...)
343343
tuplebroadcast_getargs(::Tuple{}, k) = ()

base/deprecated.jl

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1354,12 +1354,12 @@ end
13541354
@deprecate versioninfo(io::IO, verbose::Bool) versioninfo(io, verbose=verbose)
13551355

13561356
# PR #22188
1357-
@deprecate cholfact!(A::StridedMatrix, uplo::Symbol, ::Type{Val{false}}) cholfact!(Hermitian(A, uplo), Val{false})
1357+
@deprecate cholfact!(A::StridedMatrix, uplo::Symbol, ::Type{Val{false}}) cholfact!(Hermitian(A, uplo), Val(false))
13581358
@deprecate cholfact!(A::StridedMatrix, uplo::Symbol) cholfact!(Hermitian(A, uplo))
1359-
@deprecate cholfact(A::StridedMatrix, uplo::Symbol, ::Type{Val{false}}) cholfact(Hermitian(A, uplo), Val{false})
1359+
@deprecate cholfact(A::StridedMatrix, uplo::Symbol, ::Type{Val{false}}) cholfact(Hermitian(A, uplo), Val(false))
13601360
@deprecate cholfact(A::StridedMatrix, uplo::Symbol) cholfact(Hermitian(A, uplo))
1361-
@deprecate cholfact!(A::StridedMatrix, uplo::Symbol, ::Type{Val{true}}; tol = 0.0) cholfact!(Hermitian(A, uplo), Val{true}, tol = tol)
1362-
@deprecate cholfact(A::StridedMatrix, uplo::Symbol, ::Type{Val{true}}; tol = 0.0) cholfact(Hermitian(A, uplo), Val{true}, tol = tol)
1361+
@deprecate cholfact!(A::StridedMatrix, uplo::Symbol, ::Type{Val{true}}; tol = 0.0) cholfact!(Hermitian(A, uplo), Val(true), tol = tol)
1362+
@deprecate cholfact(A::StridedMatrix, uplo::Symbol, ::Type{Val{true}}; tol = 0.0) cholfact(Hermitian(A, uplo), Val(true), tol = tol)
13631363

13641364
# PR #22245
13651365
@deprecate isposdef(A::AbstractMatrix, UL::Symbol) isposdef(Hermitian(A, UL))
@@ -1519,6 +1519,30 @@ function replace(s::AbstractString, pat, f, n::Integer)
15191519
end
15201520
end
15211521

1522+
# PR #22475
1523+
@deprecate ntuple{N}(f, ::Type{Val{N}}) ntuple(f, Val(N))
1524+
@deprecate fill_to_length{N}(t, val, ::Type{Val{N}}) fill_to_length(t, val, Val(N)) false
1525+
@deprecate literal_pow{N}(a, b, ::Type{Val{N}}) literal_pow(a, b, Val(N)) false
1526+
@eval IteratorsMD @deprecate split{n}(t, V::Type{Val{n}}) split(t, Val(n)) false
1527+
@deprecate sqrtm{T,realmatrix}(A::UpperTriangular{T},::Type{Val{realmatrix}}) sqrtm(A, Val(realmatrix))
1528+
@deprecate lufact(A::AbstractMatrix, ::Type{Val{false}}) lufact(A, Val(false))
1529+
@deprecate lufact(A::AbstractMatrix, ::Type{Val{true}}) lufact(A, Val(true))
1530+
@deprecate lufact!(A::AbstractMatrix, ::Type{Val{false}}) lufact!(A, Val(false))
1531+
@deprecate lufact!(A::AbstractMatrix, ::Type{Val{true}}) lufact!(A, Val(true))
1532+
@deprecate qrfact(A::AbstractMatrix, ::Type{Val{false}}) qrfact(A, Val(false))
1533+
@deprecate qrfact(A::AbstractMatrix, ::Type{Val{true}}) qrfact(A, Val(true))
1534+
@deprecate qrfact!(A::AbstractMatrix, ::Type{Val{false}}) qrfact!(A, Val(false))
1535+
@deprecate qrfact!(A::AbstractMatrix, ::Type{Val{true}}) qrfact!(A, Val(true))
1536+
@deprecate cholfact(A::AbstractMatrix, ::Type{Val{false}}) cholfact(A, Val(false))
1537+
@deprecate cholfact(A::AbstractMatrix, ::Type{Val{true}}; tol = 0.0) cholfact(A, Val(true); tol = tol)
1538+
@deprecate cholfact!(A::AbstractMatrix, ::Type{Val{false}}) cholfact!(A, Val(false))
1539+
@deprecate cholfact!(A::AbstractMatrix, ::Type{Val{true}}; tol = 0.0) cholfact!(A, Val(true); tol = tol)
1540+
@deprecate cat{N}(::Type{Val{N}}, A::AbstractArray...) cat(Val(N), A...)
1541+
@deprecate cat{N}(::Type{Val{N}}, A::SparseArrays._SparseConcatGroup...) cat(Val(N), A...)
1542+
@deprecate cat{N}(::Type{Val{N}}, A::SparseArrays._DenseConcatGroup...) cat(Val(N), A...)
1543+
@deprecate cat_t{N,T}(::Type{Val{N}}, ::Type{T}, A, B) cat_t(Val(N), T, A, B) false
1544+
@deprecate reshape{N}(A::AbstractArray, ::Type{Val{N}}) reshape(A, Val(N))
1545+
15221546
# END 0.7 deprecations
15231547

15241548
# BEGIN 1.0 deprecations

base/essentials.jl

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -313,18 +313,33 @@ struct Colon
313313
end
314314
const (:) = Colon()
315315

316-
# For passing constants through type inference
317316
"""
318-
Val{c}
317+
Val(c)
319318
320-
Create a "value type" out of `c`, which must be an `isbits` value. The intent of this
321-
construct is to be able to dispatch on constants, e.g., `f(Val{false})` allows you to
322-
dispatch directly (at compile-time) to an implementation `f(::Type{Val{false}})`, without
323-
having to test the boolean value at runtime.
319+
Return `Val{c}()`, which contains no run-time data. Types like this can be used to
320+
pass the information between functions through the value `c`, which must be an `isbits`
321+
value. The intent of this construct is to be able to dispatch on constants directly (at
322+
compile time) without having to test the value of the constant at run time.
323+
324+
# Examples
325+
```jldoctest
326+
julia> f(::Val{true}) = "Good"
327+
f (generic function with 1 method)
328+
329+
julia> f(::Val{false}) = "Bad"
330+
f (generic function with 2 methods)
331+
332+
julia> f(Val(true))
333+
"Good"
334+
```
324335
"""
325-
struct Val{T}
336+
struct Val{x}
326337
end
327338

339+
Val(x) = (@_pure_meta; Val{x}())
340+
341+
show(io::IO, ::Val{x}) where {x} = print(io, "Val($x)")
342+
328343
# used by interpolating quote and some other things in the front end
329344
function vector_any(xs::ANY...)
330345
n = length(xs)

base/intfuncs.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -198,14 +198,14 @@ end
198198
^(x::Number, p::Integer) = power_by_squaring(x,p)
199199
^(x, p::Integer) = power_by_squaring(x,p)
200200

201-
# x^p for any literal integer p is lowered to Base.literal_pow(^, x, Val{p})
201+
# x^p for any literal integer p is lowered to Base.literal_pow(^, x, Val(p))
202202
# to enable compile-time optimizations specialized to p.
203203
# However, we still need a fallback that calls the function ^ which may either
204204
# mean Base.^ or something else, depending on context.
205205
# We mark these @inline since if the target is marked @inline,
206206
# we want to make sure that gets propagated,
207207
# even if it is over the inlining threshold.
208-
@inline literal_pow(f, x, ::Type{Val{p}}) where {p} = f(x,p)
208+
@inline literal_pow(f, x, ::Val{p}) where {p} = f(x,p)
209209

210210
# Restrict inlining to hardware-supported arithmetic types, which
211211
# are fast enough to benefit from inlining.
@@ -216,10 +216,10 @@ const HWNumber = Union{HWReal, Complex{<:HWReal}, Rational{<:HWReal}}
216216
# numeric types. In terms of Val we can do it much more simply.
217217
# (The first argument prevents unexpected behavior if a function ^
218218
# is defined that is not equal to Base.^)
219-
@inline literal_pow(::typeof(^), x::HWNumber, ::Type{Val{0}}) = one(x)
220-
@inline literal_pow(::typeof(^), x::HWNumber, ::Type{Val{1}}) = x
221-
@inline literal_pow(::typeof(^), x::HWNumber, ::Type{Val{2}}) = x*x
222-
@inline literal_pow(::typeof(^), x::HWNumber, ::Type{Val{3}}) = x*x*x
219+
@inline literal_pow(::typeof(^), x::HWNumber, ::Val{0}) = one(x)
220+
@inline literal_pow(::typeof(^), x::HWNumber, ::Val{1}) = x
221+
@inline literal_pow(::typeof(^), x::HWNumber, ::Val{2}) = x*x
222+
@inline literal_pow(::typeof(^), x::HWNumber, ::Val{3}) = x*x*x
223223

224224
# b^p mod m
225225

base/linalg/arnoldi.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ function A_mul_B!(y::StridedVector{T}, A::AtA_or_AAt{T}, x::StridedVector{T}) wh
339339
return A_mul_B!(y, A.A, A.buffer)
340340
end
341341
end
342-
size(A::AtA_or_AAt) = ntuple(i -> min(size(A.A)...), Val{2})
342+
size(A::AtA_or_AAt) = ntuple(i -> min(size(A.A)...), Val(2))
343343
ishermitian(s::AtA_or_AAt) = true
344344

345345

0 commit comments

Comments
 (0)