Skip to content

Commit

Permalink
Merge pull request #10884 from JuliaLang/mb/namebug
Browse files Browse the repository at this point in the history
Rename stagedfunction → @generated function
  • Loading branch information
mbauman committed Apr 20, 2015
2 parents 5499882 + fa1174a commit 37041bb
Show file tree
Hide file tree
Showing 16 changed files with 115 additions and 99 deletions.
6 changes: 3 additions & 3 deletions base/array.jl
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ end
# sure about the behaviour and use unsafe_getindex; in the general case
# we can't and must use getindex, otherwise silent corruption can happen)

stagedfunction getindex_bool_1d(A::Array, I::AbstractArray{Bool})
@generated function getindex_bool_1d(A::Array, I::AbstractArray{Bool})
idxop = I <: Union(Array{Bool}, BitArray) ? :unsafe_getindex : :getindex
quote
checkbounds(A, I)
Expand Down Expand Up @@ -401,7 +401,7 @@ end
# sure about the behaviour and use unsafe_getindex; in the general case
# we can't and must use getindex, otherwise silent corruption can happen)

stagedfunction assign_bool_scalar_1d!(A::Array, x, I::AbstractArray{Bool})
@generated function assign_bool_scalar_1d!(A::Array, x, I::AbstractArray{Bool})
idxop = I <: Union(Array{Bool}, BitArray) ? :unsafe_getindex : :getindex
quote
checkbounds(A, I)
Expand All @@ -414,7 +414,7 @@ stagedfunction assign_bool_scalar_1d!(A::Array, x, I::AbstractArray{Bool})
end
end

stagedfunction assign_bool_vector_1d!(A::Array, X::AbstractArray, I::AbstractArray{Bool})
@generated function assign_bool_vector_1d!(A::Array, X::AbstractArray, I::AbstractArray{Bool})
idxop = I <: Union(Array{Bool}, BitArray) ? :unsafe_getindex : :getindex
quote
checkbounds(A, I)
Expand Down
14 changes: 12 additions & 2 deletions base/base.jl
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,25 @@ convert{T}(::Type{Tuple{Vararg{T}}}, x::Tuple) = cnvt_all(T, x...)
cnvt_all(T) = ()
cnvt_all(T, x, rest...) = tuple(convert(T,x), cnvt_all(T, rest...)...)

stagedfunction tuple_type_head{T<:Tuple}(::Type{T})
macro generated(f)
isa(f, Expr) || error("invalid syntax; @generated must be used with a function definition")
if is(f.head, :function) || isdefined(:length) && is(f.head, :(=)) && length(f.args) == 2 && f.args[1].head == :call
f.head = :stagedfunction
return Expr(:escape, f)
else
error("invalid syntax; @generated must be used with a function definition")
end
end

@generated function tuple_type_head{T<:Tuple}(::Type{T})
T.parameters[1]
end

isvarargtype(t::ANY) = isa(t,DataType)&&is((t::DataType).name,Vararg.name)
isvatuple(t::DataType) = (n = length(t.parameters); n > 0 && isvarargtype(t.parameters[n]))
unwrapva(t::ANY) = isvarargtype(t) ? t.parameters[1] : t

stagedfunction tuple_type_tail{T<:Tuple}(::Type{T})
@generated function tuple_type_tail{T<:Tuple}(::Type{T})
if isvatuple(T) && length(T.parameters) == 1
return T
end
Expand Down
6 changes: 3 additions & 3 deletions base/bitarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ end
# we can't and must use getindex, otherwise silent corruption can happen)
# (multiple signatures for disambiguation)
for IT in [AbstractVector{Bool}, AbstractArray{Bool}]
@eval stagedfunction getindex(B::BitArray, I::$IT)
@eval @generated function getindex(B::BitArray, I::$IT)
idxop = I <: Union(Array{Bool}, BitArray) ? :unsafe_getindex : :getindex
quote
checkbounds(B, I)
Expand Down Expand Up @@ -446,7 +446,7 @@ function setindex!(B::BitArray, x, I::BitArray)
return B
end

stagedfunction setindex!(B::BitArray, x, I::AbstractArray{Bool})
@generated function setindex!(B::BitArray, x, I::AbstractArray{Bool})
idxop = I <: Array{Bool} ? :unsafe_getindex : :getindex
quote
checkbounds(B, I)
Expand Down Expand Up @@ -493,7 +493,7 @@ function setindex!(B::BitArray, X::AbstractArray, I::BitArray)
return B
end

stagedfunction setindex!(B::BitArray, X::AbstractArray, I::AbstractArray{Bool})
@generated function setindex!(B::BitArray, X::AbstractArray, I::AbstractArray{Bool})
idxop = I <: Array{Bool} ? :unsafe_getindex : :getindex
quote
checkbounds(B, I)
Expand Down
4 changes: 2 additions & 2 deletions base/broadcast.jl
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ broadcast!_function(f::Function) = (B, As...) -> broadcast!(f, B, As...)
broadcast_function(f::Function) = (As...) -> broadcast(f, As...)

broadcast_getindex(src::AbstractArray, I::AbstractArray...) = broadcast_getindex!(Array(eltype(src), broadcast_shape(I...)), src, I...)
stagedfunction broadcast_getindex!(dest::AbstractArray, src::AbstractArray, I::AbstractArray...)
@generated function broadcast_getindex!(dest::AbstractArray, src::AbstractArray, I::AbstractArray...)
N = length(I)
Isplat = Expr[:(I[$d]) for d = 1:N]
quote
Expand All @@ -254,7 +254,7 @@ stagedfunction broadcast_getindex!(dest::AbstractArray, src::AbstractArray, I::A
end
end

stagedfunction broadcast_setindex!(A::AbstractArray, x, I::AbstractArray...)
@generated function broadcast_setindex!(A::AbstractArray, x, I::AbstractArray...)
N = length(I)
Isplat = Expr[:(I[$d]) for d = 1:N]
quote
Expand Down
6 changes: 3 additions & 3 deletions base/constants.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ convert(::Type{Float16}, x::MathConst) = Float16(Float32(x))
convert{T<:Real}(::Type{Complex{T}}, x::MathConst) = convert(Complex{T}, convert(T,x))
convert{T<:Integer}(::Type{Rational{T}}, x::MathConst) = convert(Rational{T}, Float64(x))

stagedfunction call{T<:Union(Float32,Float64),s}(t::Type{T},c::MathConst{s},r::RoundingMode)
@generated function call{T<:Union(Float32,Float64),s}(t::Type{T},c::MathConst{s},r::RoundingMode)
f = T(big(c()),r())
:($f)
end
Expand Down Expand Up @@ -43,13 +43,13 @@ end
<=(x::FloatingPoint,y::MathConst) = x < y

# MathConst vs Rational
stagedfunction <{T}(x::MathConst, y::Rational{T})
@generated function <{T}(x::MathConst, y::Rational{T})
bx = big(x())
bx < 0 && T <: Unsigned && return true
rx = rationalize(T,bx,tol=0)
rx < bx ? :($rx < y) : :($rx <= y)
end
stagedfunction <{T}(x::Rational{T}, y::MathConst)
@generated function <{T}(x::Rational{T}, y::MathConst)
by = big(y())
by < 0 && T <: Unsigned && return false
ry = rationalize(T,by,tol=0)
Expand Down
1 change: 1 addition & 0 deletions base/exports.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1385,6 +1385,7 @@ export
@parallel,

# metaprogramming utilities
@generated,
@gensym,
@eval,
@vectorize_1arg,
Expand Down
2 changes: 1 addition & 1 deletion base/iterator.jl
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ immutable Zip{I, Z<:AbstractZipIterator} <: AbstractZipIterator
end
zip(a, b, c...) = Zip(a, zip(b, c...))
length(z::Zip) = min(length(z.a), length(z.z))
stagedfunction tuple_type_cons{S,T<:Tuple}(::Type{S}, ::Type{T})
@generated function tuple_type_cons{S,T<:Tuple}(::Type{S}, ::Type{T})
Tuple{S, T.parameters...}
end
eltype{I,Z}(::Type{Zip{I,Z}}) = tuple_type_cons(eltype(I), eltype(Z))
Expand Down
Loading

0 comments on commit 37041bb

Please sign in to comment.