Skip to content

Commit c2db97b

Browse files
author
Andy Ferris
committed
Replace pure annotations in promotion with inline
1 parent 8518fcb commit c2db97b

File tree

1 file changed

+21
-17
lines changed

1 file changed

+21
-17
lines changed

base/promotion.jl

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -123,13 +123,13 @@ end
123123
## promotion mechanism ##
124124

125125
promote_type() = (@_pure_meta; Bottom)
126-
promote_type(T) = (@_pure_meta; T)
127-
promote_type(T, S, U, V...) = (@_pure_meta; promote_type(T, promote_type(S, U, V...)))
126+
promote_type(T) = T
127+
promote_type(T, S, U, V...) = (@_inline_meta; promote_type(T, promote_type(S, U, V...)))
128128

129129
promote_type(::Type{Bottom}, ::Type{Bottom}) = (@_pure_meta; Bottom)
130-
promote_type(::Type{T}, ::Type{T}) where {T} = (@_pure_meta; T)
131-
promote_type(::Type{T}, ::Type{Bottom}) where {T} = (@_pure_meta; T)
132-
promote_type(::Type{Bottom}, ::Type{T}) where {T} = (@_pure_meta; T)
130+
promote_type(::Type{T}, ::Type{T}) where {T} = T
131+
promote_type(::Type{T}, ::Type{Bottom}) where {T} = T
132+
promote_type(::Type{Bottom}, ::Type{T}) where {T} = T
133133

134134
"""
135135
promote_type(type1, type2)
@@ -152,7 +152,7 @@ BigFloat
152152
```
153153
"""
154154
function promote_type(::Type{T}, ::Type{S}) where {T,S}
155-
@_pure_meta
155+
@_inline_meta
156156
# Try promote_rule in both orders. Typically only one is defined,
157157
# and there is a fallback returning Bottom below, so the common case is
158158
# promote_type(T, S) =>
@@ -161,26 +161,30 @@ function promote_type(::Type{T}, ::Type{S}) where {T,S}
161161
promote_result(T, S, promote_rule(T,S), promote_rule(S,T))
162162
end
163163

164-
promote_rule(T, S) = (@_pure_meta; Bottom)
164+
# TODO: this is not hyperpure, but the pure anotation seems necessary for inference to work
165+
promote_rule(::Type{<:Any}, ::Type{<:Any}) = (@_pure_meta; Bottom)
165166

166-
promote_result(t,s,T,S) = (@_pure_meta; promote_type(T,S))
167+
promote_result(::Type{<:Any},::Type{<:Any},::Type{T},::Type{S}) where {T,S} = (@_inline_meta; promote_type(T,S))
167168
# If no promote_rule is defined, both directions give Bottom. In that
168169
# case use typejoin on the original types instead.
169-
promote_result(::Type{T},::Type{S},::Type{Bottom},::Type{Bottom}) where {T,S} = (@_pure_meta; typejoin(T, S))
170+
promote_result(::Type{T},::Type{S},::Type{Bottom},::Type{Bottom}) where {T,S} = (@_inline_meta; typejoin(T, S))
170171

171172
promote() = ()
172173
promote(x) = (x,)
173174
function promote(x::T, y::S) where {T,S}
175+
@_inline_meta
174176
(convert(promote_type(T,S),x), convert(promote_type(T,S),y))
175177
end
176-
promote_typeof(x) = (@_pure_meta; typeof(x))
177-
promote_typeof(x, xs...) = (@_pure_meta; promote_type(typeof(x), promote_typeof(xs...)))
178+
promote_typeof(x) = typeof(x)
179+
promote_typeof(x, xs...) = (@_inline_meta; promote_type(typeof(x), promote_typeof(xs...)))
178180
function promote(x, y, z)
181+
@_inline_meta
179182
(convert(promote_typeof(x,y,z), x),
180183
convert(promote_typeof(x,y,z), y),
181184
convert(promote_typeof(x,y,z), z))
182185
end
183186
function promote(x, y, zs...)
187+
@_inline_meta
184188
(convert(promote_typeof(x,y,zs...), x),
185189
convert(promote_typeof(x,y,zs...), y),
186190
convert(Tuple{Vararg{promote_typeof(x,y,zs...)}}, zs)...)
@@ -195,16 +199,16 @@ end
195199
# happens, and +(promote(x,y)...) is called again, causing a stack
196200
# overflow.
197201
function promote_result(::Type{T},::Type{S},::Type{Bottom},::Type{Bottom}) where {T<:Number,S<:Number}
198-
@_pure_meta
202+
@_inline_meta
199203
promote_to_supertype(T, S, typejoin(T,S))
200204
end
201205

202206
# promote numeric types T and S to typejoin(T,S) if T<:S or S<:T
203207
# for example this makes promote_type(Integer,Real) == Real without
204208
# promoting arbitrary pairs of numeric types to Number.
205-
promote_to_supertype(::Type{T}, ::Type{T}, ::Type{T}) where {T<:Number} = (@_pure_meta; T)
206-
promote_to_supertype(::Type{T}, ::Type{S}, ::Type{T}) where {T<:Number,S<:Number} = (@_pure_meta; T)
207-
promote_to_supertype(::Type{T}, ::Type{S}, ::Type{S}) where {T<:Number,S<:Number} = (@_pure_meta; S)
209+
promote_to_supertype(::Type{T}, ::Type{T}, ::Type{T}) where {T<:Number} = (@_inline_meta; T)
210+
promote_to_supertype(::Type{T}, ::Type{S}, ::Type{T}) where {T<:Number,S<:Number} = (@_inline_meta; T)
211+
promote_to_supertype(::Type{T}, ::Type{S}, ::Type{S}) where {T<:Number,S<:Number} = (@_inline_meta; S)
208212
promote_to_supertype(::Type{T}, ::Type{S}, ::Type) where {T<:Number,S<:Number} =
209213
error("no promotion exists for ", T, " and ", S)
210214

@@ -304,15 +308,15 @@ minmax(x::Real, y::Real) = minmax(promote(x, y)...)
304308
# "Promotion" that takes a function into account and tries to preserve
305309
# non-concrete types. These are meant to be used mainly by elementwise
306310
# operations, so it is advised against overriding them
307-
_default_type(T::Type) = (@_pure_meta; T)
311+
_default_type(T::Type) = (@_inline_meta; T)
308312

309313
if isdefined(Core, :Inference)
310314
const _return_type = Core.Inference.return_type
311315
else
312316
_return_type(f::ANY, t::ANY) = Any
313317
end
314318

315-
promote_op(::Any...) = (@_pure_meta; Any)
319+
promote_op(::Any...) = (@_inline_meta; Any)
316320
function promote_op{S}(f, ::Type{S})
317321
@_inline_meta
318322
T = _return_type(f, Tuple{_default_type(S)})

0 commit comments

Comments
 (0)