Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't deprecate splat #48038

Merged
merged 1 commit into from
Jan 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions base/deprecated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -318,8 +318,6 @@ const var"@_noinline_meta" = var"@noinline"

# BEGIN 1.9 deprecations

@deprecate splat(x) Splat(x) false

# We'd generally like to avoid direct external access to internal fields
# Core.Compiler.is_inlineable and Core.Compiler.set_inlineable! move towards this direction,
# but we need to keep these around for compat
Expand Down
2 changes: 1 addition & 1 deletion base/exports.jl
Original file line number Diff line number Diff line change
Expand Up @@ -816,7 +816,7 @@ export
atreplinit,
exit,
ntuple,
Splat,
splat,

# I/O and events
close,
Expand Down
2 changes: 1 addition & 1 deletion base/iterators.jl
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ the `zip` iterator is a tuple of values of its subiterators.

`zip()` with no arguments yields an infinite iterator of empty tuples.

See also: [`enumerate`](@ref), [`Splat`](@ref Base.Splat).
See also: [`enumerate`](@ref), [`Base.splat`](@ref).

# Examples
```jldoctest
Expand Down
35 changes: 24 additions & 11 deletions base/operators.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1212,41 +1212,54 @@ used to implement specialized methods.
<(x) = Fix2(<, x)

"""
Splat(f)
splat(f)

Equivalent to
```julia
my_splat(f) = args->f(args...)
```
i.e. given a function returns a new function that takes one argument and splats
its argument into the original function. This is useful as an adaptor to pass
a multi-argument function in a context that expects a single argument, but
passes a tuple as that single argument. Additionally has pretty printing.

!!! compat "Julia 1.9"
This function was introduced in Julia 1.9, replacing `Base.splat(f)`.
it into the original function. This is useful as an adaptor to pass a
multi-argument function in a context that expects a single argument, but passes
a tuple as that single argument.

# Example usage:
```jldoctest
julia> map(Base.Splat(+), zip(1:3,4:6))
julia> map(splat(+), zip(1:3,4:6))
3-element Vector{Int64}:
5
7
9

julia> my_add = Base.Splat(+)
Splat(+)
julia> my_add = splat(+)
splat(+)

julia> my_add((1,2,3))
6
```
"""
splat(f) = Splat(f)

"""
Base.Splat{F} <: Function

Represents a splatted function. That is
```julia
Base.Splat(f)(args) === f(args...)
```
The preferred way to construct an instance of `Base.Splat` is to use the [`splat`](@ref) function.

!!! compat "Julia 1.9"
Splat requires at least Julia 1.9. In earlier versions `splat` returns an anonymous function instead.

See also [`splat`](@ref).
"""
struct Splat{F} <: Function
f::F
Splat(f) = new{Core.Typeof(f)}(f)
end
(s::Splat)(args) = s.f(args...)
print(io::IO, s::Splat) = print(io, "Splat(", s.f, ')')
print(io::IO, s::Splat) = print(io, "splat(", s.f, ')')
show(io::IO, s::Splat) = print(io, s)

## in and related operators
Expand Down
4 changes: 2 additions & 2 deletions base/strings/search.jl
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ function _searchindex(s::Union{AbstractString,ByteArray},
if i === nothing return 0 end
ii = nextind(s, i)::Int
a = Iterators.Stateful(trest)
matched = all(Splat(==), zip(SubString(s, ii), a))
matched = all(splat(==), zip(SubString(s, ii), a))
(isempty(a) && matched) && return i
i = ii
end
Expand Down Expand Up @@ -506,7 +506,7 @@ function _rsearchindex(s::AbstractString,
a = Iterators.Stateful(trest)
b = Iterators.Stateful(Iterators.reverse(
pairs(SubString(s, 1, ii))))
matched = all(Splat(==), zip(a, (x[2] for x in b)))
matched = all(splat(==), zip(a, (x[2] for x in b)))
if matched && isempty(a)
isempty(b) && return firstindex(s)
return nextind(s, popfirst!(b)[1])::Int
Expand Down
2 changes: 1 addition & 1 deletion doc/src/base/base.md
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ new
Base.:(|>)
Base.:(∘)
Base.ComposedFunction
Base.Splat
Base.splat
Base.Fix1
Base.Fix2
```
Expand Down
2 changes: 1 addition & 1 deletion doc/src/devdocs/ast.md
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ These symbols appear in the `head` field of [`Expr`](@ref)s in lowered form.
* `splatnew`

Similar to `new`, except field values are passed as a single tuple. Works similarly to
`Base.Splat(new)` if `new` were a first-class function, hence the name.
`splat(new)` if `new` were a first-class function, hence the name.

* `isdefined`

Expand Down
2 changes: 1 addition & 1 deletion stdlib/LinearAlgebra/src/LinearAlgebra.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import Base: USE_BLAS64, abs, acos, acosh, acot, acoth, acsc, acsch, adjoint, as
vec, zero
using Base: IndexLinear, promote_eltype, promote_op, promote_typeof,
@propagate_inbounds, reduce, typed_hvcat, typed_vcat, require_one_based_indexing,
Splat
splat
using Base.Broadcast: Broadcasted, broadcasted
using Base.PermutedDimsArrays: CommutativeOps
using OpenBLAS_jll
Expand Down
2 changes: 1 addition & 1 deletion stdlib/LinearAlgebra/src/qr.jl
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ function Base.hash(F::QRCompactWY, h::UInt)
return hash(F.factors, foldr(hash, _triuppers_qr(F.T); init=hash(QRCompactWY, h)))
end
function Base.:(==)(A::QRCompactWY, B::QRCompactWY)
return A.factors == B.factors && all(Splat(==), zip(_triuppers_qr.((A.T, B.T))...))
return A.factors == B.factors && all(splat(==), zip(_triuppers_qr.((A.T, B.T))...))
end
function Base.isequal(A::QRCompactWY, B::QRCompactWY)
return isequal(A.factors, B.factors) && all(zip(_triuppers_qr.((A.T, B.T))...)) do (a, b)
Expand Down
4 changes: 2 additions & 2 deletions test/broadcast.jl
Original file line number Diff line number Diff line change
Expand Up @@ -903,13 +903,13 @@ end
ys = 1:2:20
bc = Broadcast.instantiate(Broadcast.broadcasted(*, xs, ys))
@test IndexStyle(bc) == IndexLinear()
@test sum(bc) == mapreduce(Base.Splat(*), +, zip(xs, ys))
@test sum(bc) == mapreduce(Base.splat(*), +, zip(xs, ys))

xs2 = reshape(xs, 1, :)
ys2 = reshape(ys, 1, :)
bc = Broadcast.instantiate(Broadcast.broadcasted(*, xs2, ys2))
@test IndexStyle(bc) == IndexCartesian()
@test sum(bc) == mapreduce(Base.Splat(*), +, zip(xs, ys))
@test sum(bc) == mapreduce(Base.splat(*), +, zip(xs, ys))

xs = 1:5:3*5
ys = 1:4:3*4
Expand Down
2 changes: 1 addition & 1 deletion test/compiler/inference.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3260,7 +3260,7 @@ j30385(T, y) = k30385(f30385(T, y))
@test @inferred(j30385(:dummy, 1)) == "dummy"

@test Base.return_types(Tuple, (NamedTuple{<:Any,Tuple{Any,Int}},)) == Any[Tuple{Any,Int}]
@test Base.return_types(Base.Splat(tuple), (typeof((a=1,)),)) == Any[Tuple{Int}]
@test Base.return_types(Base.splat(tuple), (typeof((a=1,)),)) == Any[Tuple{Int}]

# test that return_type_tfunc isn't affected by max_methods differently than return_type
_rttf_test(::Int8) = 0
Expand Down
2 changes: 1 addition & 1 deletion test/iterators.jl
Original file line number Diff line number Diff line change
Expand Up @@ -618,7 +618,7 @@ end
@test length(I) == iterate_length(I) == simd_iterate_length(I) == simd_trip_count(I)
@test collect(I) == iterate_elements(I) == simd_iterate_elements(I) == index_elements(I)
end
@test all(Base.Splat(==), zip(Iterators.flatten(map(collect, P)), iter))
@test all(Base.splat(==), zip(Iterators.flatten(map(collect, P)), iter))
end
end
@testset "empty/invalid partitions" begin
Expand Down