Skip to content

Commit 8ce7a02

Browse files
committed
mark some more key functions are @pure
1 parent c416e9f commit 8ce7a02

File tree

3 files changed

+16
-23
lines changed

3 files changed

+16
-23
lines changed

base/abstractarray.jl

-9
Original file line numberDiff line numberDiff line change
@@ -117,15 +117,6 @@ linearindexing(A::AbstractArray, B::AbstractArray...) = linearindexing(linearind
117117
linearindexing(::LinearFast, ::LinearFast) = LinearFast()
118118
linearindexing(::LinearIndexing, ::LinearIndexing) = LinearSlow()
119119

120-
# The real @inline macro is not available this early in the bootstrap, so this
121-
# internal macro splices the meta Expr directly into the function body.
122-
macro _inline_meta()
123-
Expr(:meta, :inline)
124-
end
125-
macro _noinline_meta()
126-
Expr(:meta, :noinline)
127-
end
128-
129120
## Bounds checking ##
130121
@generated function trailingsize{T,N,n}(A::AbstractArray{T,N}, ::Type{Val{n}})
131122
n > N && return 1

base/iterator.jl

+2-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ immutable Zip{I, Z<:AbstractZipIterator} <: AbstractZipIterator
4545
end
4646
zip(a, b, c...) = Zip(a, zip(b, c...))
4747
length(z::Zip) = min(length(z.a), length(z.z))
48-
@generated function tuple_type_cons{S,T<:Tuple}(::Type{S}, ::Type{T})
48+
function tuple_type_cons{S,T<:Tuple}(::Type{S}, ::Type{T})
49+
@_pure_meta
4950
Tuple{S, T.parameters...}
5051
end
5152
eltype{I,Z}(::Type{Zip{I,Z}}) = tuple_type_cons(eltype(I), eltype(Z))

base/reflection.jl

+14-13
Original file line numberDiff line numberDiff line change
@@ -71,25 +71,25 @@ isconst(m::Module, s::Symbol) =
7171
object_id(x::ANY) = ccall(:jl_object_id, UInt, (Any,), x)
7272

7373
# type predicates
74-
isimmutable(x::ANY) = (isa(x,Tuple) || !typeof(x).mutable)
75-
isstructtype(t::DataType) = nfields(t) != 0 || (t.size==0 && !t.abstract)
76-
isstructtype(x) = false
77-
isbits(t::DataType) = !t.mutable & t.pointerfree & isleaftype(t)
78-
isbits(t::Type) = false
79-
isbits(x) = isbits(typeof(x))
80-
isleaftype(t::ANY) = ccall(:jl_is_leaf_type, Int32, (Any,), t) != 0
74+
isimmutable(x::ANY) = (@_pure_meta; (isa(x,Tuple) || !typeof(x).mutable))
75+
isstructtype(t::DataType) = (@_pure_meta; nfields(t) != 0 || (t.size==0 && !t.abstract))
76+
isstructtype(x) = (@_pure_meta; false)
77+
isbits(t::DataType) = (@_pure_meta; !t.mutable & t.pointerfree & isleaftype(t))
78+
isbits(t::Type) = (@_pure_meta; false)
79+
isbits(x) = (@_pure_meta; isbits(typeof(x)))
80+
isleaftype(t::ANY) = (@_pure_meta; ccall(:jl_is_leaf_type, Int32, (Any,), t) != 0)
8181

82-
typeintersect(a::ANY,b::ANY) = ccall(:jl_type_intersection, Any, (Any,Any), a, b)
83-
typeseq(a::ANY,b::ANY) = a<:b && b<:a
82+
typeintersect(a::ANY,b::ANY) = (@_pure_meta; ccall(:jl_type_intersection, Any, (Any,Any), a, b))
83+
typeseq(a::ANY,b::ANY) = (@_pure_meta; a<:b && b<:a)
8484

8585
function fieldoffsets(x::DataType)
8686
offsets = Array(Int, nfields(x))
8787
ccall(:jl_field_offsets, Void, (Any, Ptr{Int}), x, offsets)
8888
offsets
8989
end
9090

91-
type_alignment(x::DataType) = ccall(:jl_get_alignment,Csize_t,(Any,),x)
92-
field_offset(x::DataType,idx) = ccall(:jl_get_field_offset,Csize_t,(Any,Int32),x,idx)
91+
type_alignment(x::DataType) = (@_pure_meta; ccall(:jl_get_alignment,Csize_t,(Any,),x))
92+
field_offset(x::DataType,idx) = (@_pure_meta; ccall(:jl_get_field_offset,Csize_t,(Any,Int32),x,idx))
9393

9494
# return all instances, for types that can be enumerated
9595
function instances end
@@ -114,11 +114,12 @@ subtypes(m::Module, x::DataType) = sort(collect(_subtypes(m, x)), by=string)
114114
subtypes(x::DataType) = subtypes(Main, x)
115115

116116
# function reflection
117-
isgeneric(f::ANY) = (isa(f,Function) && isa(f.env,MethodTable))
117+
isgeneric(f::ANY) = (@_pure_meta; (isa(f,Function) && isa(f.env,MethodTable)))
118118

119119
function_name(f::Function) = isgeneric(f) ? f.env.name : (:anonymous)
120120

121121
function to_tuple_type(t::ANY)
122+
@_pure_meta
122123
if isa(t,Tuple) || isa(t,AbstractArray) || isa(t,SimpleVector)
123124
t = Tuple{t...}
124125
end
@@ -132,7 +133,7 @@ function to_tuple_type(t::ANY)
132133
t
133134
end
134135

135-
tt_cons(t::ANY, tup::ANY) = Tuple{t, (isa(tup, Type) ? tup.parameters : tup)...}
136+
tt_cons(t::ANY, tup::ANY) = (@_pure_meta; Tuple{t, (isa(tup, Type) ? tup.parameters : tup)...})
136137

137138
code_lowered(f, t::ANY) = map(m->uncompressed_ast(m.func.code), methods(f, t))
138139
function methods(f::Function,t::ANY)

0 commit comments

Comments
 (0)