Skip to content

Commit d0f74ff

Browse files
committed
Rename stagedfunction → @generated function
This fixes the long-standing name "bug". Note that it only affects surface syntax. Internally, generated functions still use the old language (e.g., Expr(:stagedfunction, ...), isstaged, stagedcache, etc). This adds a temporary deprecation to the `stagedfunction` keyword -- the keyword should be entirely removed before the 0.4 release.
1 parent ed020a5 commit d0f74ff

16 files changed

+114
-98
lines changed

base/array.jl

+3-3
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ end
322322
# sure about the behaviour and use unsafe_getindex; in the general case
323323
# we can't and must use getindex, otherwise silent corruption can happen)
324324

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

404-
stagedfunction assign_bool_scalar_1d!(A::Array, x, I::AbstractArray{Bool})
404+
@generated function assign_bool_scalar_1d!(A::Array, x, I::AbstractArray{Bool})
405405
idxop = I <: Union(Array{Bool}, BitArray) ? :unsafe_getindex : :getindex
406406
quote
407407
checkbounds(A, I)
@@ -414,7 +414,7 @@ stagedfunction assign_bool_scalar_1d!(A::Array, x, I::AbstractArray{Bool})
414414
end
415415
end
416416

417-
stagedfunction assign_bool_vector_1d!(A::Array, X::AbstractArray, I::AbstractArray{Bool})
417+
@generated function assign_bool_vector_1d!(A::Array, X::AbstractArray, I::AbstractArray{Bool})
418418
idxop = I <: Union(Array{Bool}, BitArray) ? :unsafe_getindex : :getindex
419419
quote
420420
checkbounds(A, I)

base/base.jl

+12-2
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,25 @@ convert{T}(::Type{Tuple{Vararg{T}}}, x::Tuple) = cnvt_all(T, x...)
4343
cnvt_all(T) = ()
4444
cnvt_all(T, x, rest...) = tuple(convert(T,x), cnvt_all(T, rest...)...)
4545

46-
stagedfunction tuple_type_head{T<:Tuple}(::Type{T})
46+
macro generated(f)
47+
isa(f, Expr) || error("invalid syntax; @generated must be used with a function definition")
48+
if is(f.head, :function) || isdefined(:length) && is(f.head, :(=)) && length(f.args) == 2 && f.args[1].head == :call
49+
f.head = :stagedfunction
50+
return Expr(:escape, f)
51+
else
52+
error("invalid syntax; @generated must be used with a function definition")
53+
end
54+
end
55+
56+
@generated function tuple_type_head{T<:Tuple}(::Type{T})
4757
T.parameters[1]
4858
end
4959

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

54-
stagedfunction tuple_type_tail{T<:Tuple}(::Type{T})
64+
@generated function tuple_type_tail{T<:Tuple}(::Type{T})
5565
if isvatuple(T) && length(T.parameters) == 1
5666
return T
5767
end

base/bitarray.jl

+3-3
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ end
380380
# we can't and must use getindex, otherwise silent corruption can happen)
381381
# (multiple signatures for disambiguation)
382382
for IT in [AbstractVector{Bool}, AbstractArray{Bool}]
383-
@eval stagedfunction getindex(B::BitArray, I::$IT)
383+
@eval @generated function getindex(B::BitArray, I::$IT)
384384
idxop = I <: Union(Array{Bool}, BitArray) ? :unsafe_getindex : :getindex
385385
quote
386386
checkbounds(B, I)
@@ -446,7 +446,7 @@ function setindex!(B::BitArray, x, I::BitArray)
446446
return B
447447
end
448448

449-
stagedfunction setindex!(B::BitArray, x, I::AbstractArray{Bool})
449+
@generated function setindex!(B::BitArray, x, I::AbstractArray{Bool})
450450
idxop = I <: Array{Bool} ? :unsafe_getindex : :getindex
451451
quote
452452
checkbounds(B, I)
@@ -493,7 +493,7 @@ function setindex!(B::BitArray, X::AbstractArray, I::BitArray)
493493
return B
494494
end
495495

496-
stagedfunction setindex!(B::BitArray, X::AbstractArray, I::AbstractArray{Bool})
496+
@generated function setindex!(B::BitArray, X::AbstractArray, I::AbstractArray{Bool})
497497
idxop = I <: Array{Bool} ? :unsafe_getindex : :getindex
498498
quote
499499
checkbounds(B, I)

base/broadcast.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ broadcast!_function(f::Function) = (B, As...) -> broadcast!(f, B, As...)
239239
broadcast_function(f::Function) = (As...) -> broadcast(f, As...)
240240

241241
broadcast_getindex(src::AbstractArray, I::AbstractArray...) = broadcast_getindex!(Array(eltype(src), broadcast_shape(I...)), src, I...)
242-
stagedfunction broadcast_getindex!(dest::AbstractArray, src::AbstractArray, I::AbstractArray...)
242+
@generated function broadcast_getindex!(dest::AbstractArray, src::AbstractArray, I::AbstractArray...)
243243
N = length(I)
244244
Isplat = Expr[:(I[$d]) for d = 1:N]
245245
quote
@@ -254,7 +254,7 @@ stagedfunction broadcast_getindex!(dest::AbstractArray, src::AbstractArray, I::A
254254
end
255255
end
256256

257-
stagedfunction broadcast_setindex!(A::AbstractArray, x, I::AbstractArray...)
257+
@generated function broadcast_setindex!(A::AbstractArray, x, I::AbstractArray...)
258258
N = length(I)
259259
Isplat = Expr[:(I[$d]) for d = 1:N]
260260
quote

base/constants.jl

+3-3
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ convert(::Type{Float16}, x::MathConst) = Float16(Float32(x))
1313
convert{T<:Real}(::Type{Complex{T}}, x::MathConst) = convert(Complex{T}, convert(T,x))
1414
convert{T<:Integer}(::Type{Rational{T}}, x::MathConst) = convert(Rational{T}, Float64(x))
1515

16-
stagedfunction call{T<:Union(Float32,Float64),s}(t::Type{T},c::MathConst{s},r::RoundingMode)
16+
@generated function call{T<:Union(Float32,Float64),s}(t::Type{T},c::MathConst{s},r::RoundingMode)
1717
f = T(big(c()),r())
1818
:($f)
1919
end
@@ -43,13 +43,13 @@ end
4343
<=(x::FloatingPoint,y::MathConst) = x < y
4444

4545
# MathConst vs Rational
46-
stagedfunction <{T}(x::MathConst, y::Rational{T})
46+
@generated function <{T}(x::MathConst, y::Rational{T})
4747
bx = big(x())
4848
bx < 0 && T <: Unsigned && return true
4949
rx = rationalize(T,bx,tol=0)
5050
rx < bx ? :($rx < y) : :($rx <= y)
5151
end
52-
stagedfunction <{T}(x::Rational{T}, y::MathConst)
52+
@generated function <{T}(x::Rational{T}, y::MathConst)
5353
by = big(y())
5454
by < 0 && T <: Unsigned && return false
5555
ry = rationalize(T,by,tol=0)

base/exports.jl

+1
Original file line numberDiff line numberDiff line change
@@ -1387,6 +1387,7 @@ export
13871387
@parallel,
13881388

13891389
# metaprogramming utilities
1390+
@generated,
13901391
@gensym,
13911392
@eval,
13921393
@vectorize_1arg,

base/iterator.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ immutable Zip{I, Z<:AbstractZipIterator} <: AbstractZipIterator
4343
end
4444
zip(a, b, c...) = Zip(a, zip(b, c...))
4545
length(z::Zip) = min(length(z.a), length(z.z))
46-
stagedfunction tuple_type_cons{S,T<:Tuple}(::Type{S}, ::Type{T})
46+
@generated function tuple_type_cons{S,T<:Tuple}(::Type{S}, ::Type{T})
4747
Tuple{S, T.parameters...}
4848
end
4949
eltype{I,Z}(::Type{Zip{I,Z}}) = tuple_type_cons(eltype(I), eltype(Z))

0 commit comments

Comments
 (0)