Skip to content

Commit

Permalink
use where syntax in most remaining files (#22211)
Browse files Browse the repository at this point in the history
  • Loading branch information
rfourquet authored and ararslan committed Jun 5, 2017
1 parent abf3bce commit d318753
Show file tree
Hide file tree
Showing 67 changed files with 202 additions and 194 deletions.
4 changes: 2 additions & 2 deletions base/abstractarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -870,7 +870,7 @@ end
# to transform the indices such that we can call the only getindex method that
# we require the type A{T,N} <: AbstractArray{T,N} to define; either:
# getindex(::A, ::Int) # if IndexStyle(A) == IndexLinear() OR
# getindex{T,N}(::A{T,N}, ::Vararg{Int, N}) # if IndexCartesian()
# getindex(::A{T,N}, ::Vararg{Int, N}) where {T,N} # if IndexCartesian()
# If the subtype hasn't defined the required method, it falls back to the
# _getindex function again where an error is thrown to prevent stack overflows.

Expand Down Expand Up @@ -1192,7 +1192,7 @@ end
_cs(d, a, b) = (a == b ? a : throw(DimensionMismatch(
"mismatch in dimension $d (expected $a got $b)")))

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

cat(dims, X...) = cat_t(dims, promote_eltypeof(X...), X...)
Expand Down
2 changes: 1 addition & 1 deletion base/associative.jl
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ String
```
"""
valtype(::Type{Associative{K,V}}) where {K,V} = V
valtype{A<:Associative}(::Type{A}) = valtype(supertype(A))
valtype(::Type{A}) where {A<:Associative} = valtype(supertype(A))
valtype(a::Associative) = valtype(typeof(a))

"""
Expand Down
20 changes: 10 additions & 10 deletions base/atomics.jl
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ end
Atomic() = Atomic{Int}()

"""
Threads.atomic_cas!{T}(x::Atomic{T}, cmp::T, newval::T)
Threads.atomic_cas!(x::Atomic{T}, cmp::T, newval::T) where T
Atomically compare-and-set `x`
Expand Down Expand Up @@ -104,7 +104,7 @@ Base.Threads.Atomic{Int64}(2)
function atomic_cas! end

"""
Threads.atomic_xchg!{T}(x::Atomic{T}, newval::T)
Threads.atomic_xchg!(x::Atomic{T}, newval::T) where T
Atomically exchange the value in `x`
Expand All @@ -127,7 +127,7 @@ julia> x[]
function atomic_xchg! end

"""
Threads.atomic_add!{T}(x::Atomic{T}, val::T)
Threads.atomic_add!(x::Atomic{T}, val::T) where T
Atomically add `val` to `x`
Expand All @@ -149,7 +149,7 @@ julia> x[]
function atomic_add! end

"""
Threads.atomic_sub!{T}(x::Atomic{T}, val::T)
Threads.atomic_sub!(x::Atomic{T}, val::T) where T
Atomically subtract `val` from `x`
Expand All @@ -171,7 +171,7 @@ julia> x[]
function atomic_sub! end

"""
Threads.atomic_and!{T}(x::Atomic{T}, val::T)
Threads.atomic_and!(x::Atomic{T}, val::T) where T
Atomically bitwise-and `x` with `val`
Expand All @@ -193,7 +193,7 @@ julia> x[]
function atomic_and! end

"""
Threads.atomic_nand!{T}(x::Atomic{T}, val::T)
Threads.atomic_nand!(x::Atomic{T}, val::T) where T
Atomically bitwise-nand (not-and) `x` with `val`
Expand All @@ -215,7 +215,7 @@ julia> x[]
function atomic_nand! end

"""
Threads.atomic_or!{T}(x::Atomic{T}, val::T)
Threads.atomic_or!(x::Atomic{T}, val::T) where T
Atomically bitwise-or `x` with `val`
Expand All @@ -237,7 +237,7 @@ julia> x[]
function atomic_or! end

"""
Threads.atomic_xor!{T}(x::Atomic{T}, val::T)
Threads.atomic_xor!(x::Atomic{T}, val::T) where T
Atomically bitwise-xor (exclusive-or) `x` with `val`
Expand All @@ -259,7 +259,7 @@ julia> x[]
function atomic_xor! end

"""
Threads.atomic_max!{T}(x::Atomic{T}, val::T)
Threads.atomic_max!(x::Atomic{T}, val::T) where T
Atomically store the maximum of `x` and `val` in `x`
Expand All @@ -281,7 +281,7 @@ julia> x[]
function atomic_max! end

"""
Threads.atomic_min!{T}(x::Atomic{T}, val::T)
Threads.atomic_min!(x::Atomic{T}, val::T) where T
Atomically store the minimum of `x` and `val` in `x`
Expand Down
2 changes: 1 addition & 1 deletion base/char.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ convert(::Type{Char}, x::Number) = Char(UInt32(x))
convert(::Type{UInt32}, x::Char) = reinterpret(UInt32, x)
convert(::Type{T}, x::Char) where {T<:Number} = convert(T, UInt32(x))

rem{T<:Number}(x::Char, ::Type{T}) = rem(UInt32(x), T)
rem(x::Char, ::Type{T}) where {T<:Number} = rem(UInt32(x), T)

typemax(::Type{Char}) = reinterpret(Char, typemax(UInt32))
typemin(::Type{Char}) = reinterpret(Char, typemin(UInt32))
Expand Down
10 changes: 5 additions & 5 deletions base/datafmt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,8 @@ mutable struct DLMStore{T} <: DLMHandler
eol::Char
end

function DLMStore{T}(::Type{T}, dims::NTuple{2,Integer},
has_header::Bool, sbuff::String, auto::Bool, eol::Char)
function DLMStore(::Type{T}, dims::NTuple{2,Integer},
has_header::Bool, sbuff::String, auto::Bool, eol::Char) where T
(nrows,ncols) = dims
nrows <= 0 && throw(ArgumentError("number of rows in dims must be > 0, got $nrows"))
ncols <= 0 && throw(ArgumentError("number of columns in dims must be > 0, got $ncols"))
Expand All @@ -223,7 +223,7 @@ _chrinstr(sbuff::String, chr::UInt8, startpos::Int, endpos::Int) =
(Ptr{UInt8}, Int32, Csize_t), pointer(sbuff)+startpos-1, chr, endpos-startpos+1))

function store_cell(dlmstore::DLMStore{T}, row::Int, col::Int,
quoted::Bool, startpos::Int, endpos::Int) where T
quoted::Bool, startpos::Int, endpos::Int) where T
drow = row - dlmstore.hdr_offset

ncols = dlmstore.ncols
Expand Down Expand Up @@ -408,7 +408,7 @@ function colval(sbuff::String, startpos::Int, endpos::Int, cells::Array{Bool,2},
isnull(n) || (cells[row, col] = get(n))
isnull(n)
end
function colval{T<:Integer}(sbuff::String, startpos::Int, endpos::Int, cells::Array{T,2}, row::Int, col::Int)
function colval(sbuff::String, startpos::Int, endpos::Int, cells::Array{T,2}, row::Int, col::Int) where T<:Integer
n = tryparse_internal(T, sbuff, startpos, endpos, 0, false)
isnull(n) || (cells[row, col] = get(n))
isnull(n)
Expand Down Expand Up @@ -620,7 +620,7 @@ readcsv(io, T::Type; opts...) = readdlm(io, ',', T; opts...)

# todo: keyword argument for # of digits to print
writedlm_cell(io::IO, elt::AbstractFloat, dlm, quotes) = print_shortest(io, elt)
function writedlm_cell{T}(io::IO, elt::AbstractString, dlm::T, quotes::Bool)
function writedlm_cell(io::IO, elt::AbstractString, dlm::T, quotes::Bool) where T
if quotes && !isempty(elt) && (('"' in elt) || ('\n' in elt) || ((T <: Char) ? (dlm in elt) : contains(elt, dlm)))
print(io, '"', replace(elt, r"\"", "\"\""), '"')
else
Expand Down
2 changes: 1 addition & 1 deletion base/dates/io.jl
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ Parse a date from a date string `dt` using a `DateFormat` object `df`.
"""
Date(dt::AbstractString,df::DateFormat=ISODateFormat) = parse(Date, dt, df)

@generated function format{S, T}(io::IO, dt::TimeType, fmt::DateFormat{S, T})
@generated function format(io::IO, dt::TimeType, fmt::DateFormat{<:Any,T}) where T
N = nfields(T)
quote
ts = fmt.tokens
Expand Down
8 changes: 4 additions & 4 deletions base/dates/periods.jl
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ end
for (op, Ty, Tz) in ((:*, Real, :P),
(:/, :P, Float64), (:/, Real, :P))
@eval begin
function ($op){P<:Period}(X::StridedArray{P}, y::$Ty)
function ($op)(X::StridedArray{P}, y::$Ty) where P<:Period
Z = similar(X, $Tz)
for (Idst, Isrc) in zip(eachindex(Z), eachindex(X))
@inbounds Z[Idst] = ($op)(X[Isrc], y)
Expand All @@ -100,8 +100,8 @@ for (op, Ty, Tz) in ((:*, Real, :P),
end

# intfuncs
Base.gcdx{T<:Period}(a::T, b::T) = ((g, x, y) = gcdx(value(a), value(b)); return T(g), x, y)
Base.abs{T<:Period}(a::T) = T(abs(value(a)))
Base.gcdx(a::T, b::T) where {T<:Period} = ((g, x, y) = gcdx(value(a), value(b)); return T(g), x, y)
Base.abs(a::T) where {T<:Period} = T(abs(value(a)))

periodisless(::Period,::Year) = true
periodisless(::Period,::Month) = true
Expand Down Expand Up @@ -136,7 +136,7 @@ periodisless(::Nanosecond,::Microsecond) = true
periodisless(::Period,::Nanosecond) = false

# return (next coarser period, conversion factor):
coarserperiod{P<:Period}(::Type{P}) = (P, 1)
coarserperiod(::Type{P}) where {P<:Period} = (P, 1)
coarserperiod(::Type{Nanosecond}) = (Microsecond, 1000)
coarserperiod(::Type{Microsecond}) = (Millisecond, 1000)
coarserperiod(::Type{Millisecond}) = (Second, 1000)
Expand Down
2 changes: 1 addition & 1 deletion base/dict.jl
Original file line number Diff line number Diff line change
Expand Up @@ -680,5 +680,5 @@ function similar(t::ImmutableDict)
return t
end

_similar_for{P<:Pair}(c::Dict, ::Type{P}, itr, isz) = similar(c, P)
_similar_for(c::Dict, ::Type{P}, itr, isz) where {P<:Pair} = similar(c, P)
_similar_for(c::Associative, T, itr, isz) = throw(ArgumentError("for Associatives, similar requires an element type of Pair;\n if calling map, consider a comprehension instead"))
2 changes: 1 addition & 1 deletion base/distributed/remotecall.jl
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ function send_add_client(rr::AbstractRemoteRef, i)
end
end

channel_type{T}(rr::RemoteChannel{T}) = T
channel_type(rr::RemoteChannel{T}) where {T} = T

serialize(s::AbstractSerializer, f::Future) = serialize(s, f, isnull(f.v))
serialize(s::AbstractSerializer, rr::RemoteChannel) = serialize(s, rr, true)
Expand Down
2 changes: 1 addition & 1 deletion base/distributed/workerpool.jl
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ function serialize(S::AbstractSerializer, pool::WorkerPool)
serialize(S, pool.ref)
end

deserialize{T<:WorkerPool}(S::AbstractSerializer, t::Type{T}) = T(deserialize(S))
deserialize(S::AbstractSerializer, t::Type{T}) where {T<:WorkerPool} = T(deserialize(S))

wp_local_push!(pool::AbstractWorkerPool, w::Int) = (push!(pool.workers, w); put!(pool.channel, w); pool)
wp_local_length(pool::AbstractWorkerPool) = length(pool.workers)
Expand Down
4 changes: 2 additions & 2 deletions base/docs/Docs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ by a `Union` of `Tuple` types. For example the following `Method` definition
is stored as `Tuple{Any, Any}` in the `MultiDoc` while
f{T}(x::T, y = ?) = ...
f(x::T, y = ?) where {T} = ...
is stored as `Union{Tuple{T, Any}, Tuple{T}} where T`.
Expand Down Expand Up @@ -426,7 +426,7 @@ function summarize(io::IO, m::Module, binding)
end
end

function summarize{T}(io::IO, ::T, binding)
function summarize(io::IO, ::T, binding) where T
println(io, "`", binding, "` is of type `", T, "`.\n")
summarize(io, T, binding)
end
Expand Down
2 changes: 1 addition & 1 deletion base/env.jl
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ by zero or more `"var"=>val` arguments `kv`. `withenv` is generally used via the
environment variable (if it is set). When `withenv` returns, the original environment has
been restored.
"""
function withenv{T<:AbstractString}(f::Function, keyvals::Pair{T}...)
function withenv(f::Function, keyvals::Pair{T}...) where T<:AbstractString
old = Dict{T,Any}()
for (key,val) in keyvals
old[key] = get(ENV,key,nothing)
Expand Down
2 changes: 1 addition & 1 deletion base/essentials.jl
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ function tuple_type_tail(T::DataType)
end

tuple_type_cons(::Type, ::Type{Union{}}) = Union{}
function tuple_type_cons{S,T<:Tuple}(::Type{S}, ::Type{T})
function tuple_type_cons(::Type{S}, ::Type{T}) where T<:Tuple where S
@_pure_meta
Tuple{S, T.parameters...}
end
Expand Down
6 changes: 3 additions & 3 deletions base/fastmath.jl
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,9 @@ mul_fast(x::T, y::T) where {T<:FloatTypes} = mul_float_fast(x, y)
div_fast(x::T, y::T) where {T<:FloatTypes} = div_float_fast(x, y)
rem_fast(x::T, y::T) where {T<:FloatTypes} = rem_float_fast(x, y)

add_fast{T<:FloatTypes}(x::T, y::T, zs::T...) =
add_fast(x::T, y::T, zs::T...) where {T<:FloatTypes} =
add_fast(add_fast(x, y), zs...)
mul_fast{T<:FloatTypes}(x::T, y::T, zs::T...) =
mul_fast(x::T, y::T, zs::T...) where {T<:FloatTypes} =
mul_fast(mul_fast(x, y), zs...)

@fastmath begin
Expand Down Expand Up @@ -208,7 +208,7 @@ ComplexTypes = Union{Complex64, Complex128}
eq_fast(a::T, y::Complex{T}) where {T<:FloatTypes} =
(a==real(y)) & (T(0)==imag(y))

ne_fast{T<:ComplexTypes}(x::T, y::T) = !(x==y)
ne_fast(x::T, y::T) where {T<:ComplexTypes} = !(x==y)
end

# fall-back implementations and type promotion
Expand Down
8 changes: 4 additions & 4 deletions base/fft/FFTW.jl
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ size(a::FakeArray) = a.sz
strides(a::FakeArray) = a.st
unsafe_convert(::Type{Ptr{T}}, a::FakeArray{T}) where {T} = convert(Ptr{T}, C_NULL)
pointer(a::FakeArray{T}) where {T} = convert(Ptr{T}, C_NULL)
FakeArray{T,N}(::Type{T}, sz::NTuple{N,Int}) = FakeArray{T,N}(sz, colmajorstrides(sz))
FakeArray{T}(::Type{T}, sz::Int...) = FakeArray(T, sz)
FakeArray(::Type{T}, sz::NTuple{N,Int}) where {T,N} = FakeArray{T,N}(sz, colmajorstrides(sz))
FakeArray(::Type{T}, sz::Int...) where {T} = FakeArray(T, sz)
fakesimilar(flags, X, T) = flags & ESTIMATE != 0 ? FakeArray(T, size(X)) : Array{T}(size(X))
alignment_of(A::FakeArray) = Int32(0)

Expand Down Expand Up @@ -194,9 +194,9 @@ if Base.libfftw_name == "libmkl_rt"
alignment_of(A::StridedArray{<:fftwSingle}) =
convert(Int32, convert(Int64, pointer(A)) % 16)
else
alignment_of{T<:fftwDouble}(A::StridedArray{T}) =
alignment_of(A::StridedArray{T}) where {T<:fftwDouble} =
ccall((:fftw_alignment_of, libfftw), Int32, (Ptr{T},), A)
alignment_of{T<:fftwSingle}(A::StridedArray{T}) =
alignment_of(A::StridedArray{T}) where {T<:fftwSingle} =
ccall((:fftwf_alignment_of, libfftwf), Int32, (Ptr{T},), A)
end

Expand Down
2 changes: 1 addition & 1 deletion base/gmp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ end


rem(x::BigInt, ::Type{Bool}) = ((x&1)!=0)
function rem{T<:Union{Unsigned,Signed}}(x::BigInt, ::Type{T})
function rem(x::BigInt, ::Type{T}) where T<:Union{Unsigned,Signed}
u = zero(T)
for l = 1:min(abs(x.size), cld(sizeof(T),sizeof(Limb)))
u += (unsafe_load(x.d,l)%T) << ((sizeof(Limb)<<3)*(l-1))
Expand Down
2 changes: 1 addition & 1 deletion base/grisu/float.jl
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ function _significand(d::T) where T<:AbstractFloat
s = uint_t(d) & SignificandMask(T)
return !isdenormal(d) ? s + HiddenBit(T) : s
end
isdenormal{T<:AbstractFloat}(d::T) = (uint_t(d) & ExponentMask(T)) == 0
isdenormal(d::T) where {T<:AbstractFloat} = (uint_t(d) & ExponentMask(T)) == 0

function normalizedbound(f::AbstractFloat)
v = Float(_significand(f),_exponent(f))
Expand Down
9 changes: 5 additions & 4 deletions base/io.jl
Original file line number Diff line number Diff line change
Expand Up @@ -290,9 +290,10 @@ function write(io::IO, xs...)
return written
end

@noinline unsafe_write{T}(s::IO, p::Ref{T}, n::Integer) = unsafe_write(s, unsafe_convert(Ref{T}, p)::Ptr, n) # mark noinline to ensure ref is gc-rooted somewhere (by the caller)
@noinline unsafe_write(s::IO, p::Ref{T}, n::Integer) where {T} =
unsafe_write(s, unsafe_convert(Ref{T}, p)::Ptr, n) # mark noinline to ensure ref is gc-rooted somewhere (by the caller)
unsafe_write(s::IO, p::Ptr, n::Integer) = unsafe_write(s, convert(Ptr{UInt8}, p), convert(UInt, n))
write{T}(s::IO, x::Ref{T}) = unsafe_write(s, x, Core.sizeof(T))
write(s::IO, x::Ref{T}) where {T} = unsafe_write(s, x, Core.sizeof(T))
write(s::IO, x::Int8) = write(s, reinterpret(UInt8, x))
function write(s::IO, x::Union{Int16,UInt16,Int32,UInt32,Int64,UInt64,Int128,UInt128,Float16,Float32,Float64})
return write(s, Ref(x))
Expand All @@ -313,7 +314,7 @@ end
return unsafe_write(s, pointer(a), sizeof(a))
end

@noinline function write{T}(s::IO, a::Array{T}) # mark noinline to ensure the array is gc-rooted somewhere (by the caller)
@noinline function write(s::IO, a::Array{T}) where T # mark noinline to ensure the array is gc-rooted somewhere (by the caller)
if isbits(T)
return unsafe_write(s, pointer(a), sizeof(a))
else
Expand Down Expand Up @@ -437,7 +438,7 @@ function readuntil(s::IO, delim::Char)
return String(take!(out))
end

function readuntil{T}(s::IO, delim::T)
function readuntil(s::IO, delim::T) where T
out = T[]
while !eof(s)
c = read(s, T)
Expand Down
2 changes: 1 addition & 1 deletion base/iostream.jl
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ function unsafe_write(s::IOStream, p::Ptr{UInt8}, nb::UInt)
return Int(ccall(:ios_write, Csize_t, (Ptr{Void}, Ptr{Void}, Csize_t), s.ios, p, nb))
end

function write{T,N}(s::IOStream, a::SubArray{T,N,<:Array})
function write(s::IOStream, a::SubArray{T,N,<:Array}) where {T,N}
if !isbits(T) || stride(a,1)!=1
return invoke(write, Tuple{Any, AbstractArray}, s, a)
end
Expand Down
4 changes: 2 additions & 2 deletions base/iterators.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ _diff_length(a, b, ::IsInfinite, ::IsInfinite) = 0
_diff_length(a, b, ::IsInfinite, B) = length(a) # inherit behaviour, error
_diff_length(a, b, A, B) = max(length(a)-length(b), 0)

and_iteratorsize{T}(isz::T, ::T) = isz
and_iteratorsize(isz::T, ::T) where {T} = isz
and_iteratorsize(::HasLength, ::HasShape) = HasLength()
and_iteratorsize(::HasShape, ::HasLength) = HasLength()
and_iteratorsize(a, b) = SizeUnknown()
Expand Down Expand Up @@ -645,7 +645,7 @@ eltype(::Type{Prod{I1,I2}}) where {I1,I2} = tuple_type_cons(eltype(I1), eltype(I
iteratoreltype(::Type{Prod{I1,I2}}) where {I1,I2} = and_iteratoreltype(iteratoreltype(I1),iteratoreltype(I2))
iteratorsize(::Type{Prod{I1,I2}}) where {I1,I2} = prod_iteratorsize(iteratorsize(I1),iteratorsize(I2))

@inline function next{I1,I2}(p::Prod{I1,I2}, st)
@inline function next(p::Prod, st)
x = prod_next(p, st)
((x[1][1],x[1][2]...), x[2])
end
Expand Down
2 changes: 1 addition & 1 deletion base/libgit2/reference.jl
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ then `ref` will be peeled until an object other than a [`GitTag`](@ref) is obtai
Only annotated tags can be peeled to `GitTag` objects. Lightweight tags (the default)
are references under `refs/tags/` which point directly to `GitCommit` objects.
"""
function peel{T<:GitObject}(::Type{T}, ref::GitReference)
function peel(::Type{T}, ref::GitReference) where T<:GitObject
obj_ptr_ptr = Ref{Ptr{Void}}(C_NULL)
@check ccall((:git_reference_peel, :libgit2), Cint,
(Ptr{Ptr{Void}}, Ptr{Void}, Cint), obj_ptr_ptr, ref.ptr, Consts.OBJECT(T))
Expand Down
Loading

0 comments on commit d318753

Please sign in to comment.