Skip to content

Commit 57d4939

Browse files
committed
Rename at-pure to at-unsafe_pure
1 parent f89921f commit 57d4939

File tree

12 files changed

+27
-27
lines changed

12 files changed

+27
-27
lines changed

base/broadcast.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ BroadcastStyle(a::AbstractArrayStyle, ::Style{Tuple}) = a
135135
BroadcastStyle(::A, ::A) where A<:ArrayStyle = A()
136136
BroadcastStyle(::ArrayStyle, ::ArrayStyle) = Unknown()
137137
BroadcastStyle(::A, ::A) where A<:AbstractArrayStyle = A()
138-
Base.@pure function BroadcastStyle(a::A, b::B) where {A<:AbstractArrayStyle{M},B<:AbstractArrayStyle{N}} where {M,N}
138+
Base.@unsafe_pure function BroadcastStyle(a::A, b::B) where {A<:AbstractArrayStyle{M},B<:AbstractArrayStyle{N}} where {M,N}
139139
if Base.typename(A).wrapper == Base.typename(B).wrapper
140140
return A(_max(Val(M),Val(N)))
141141
end

base/compiler/abstractinterpretation.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -670,11 +670,11 @@ function abstract_call(@nospecialize(f), fargs::Union{Tuple{},Vector{Any}}, argt
670670
rty = abstract_call(<:, fargs, argtypes, vtypes, sv)
671671
return rty
672672
elseif length(argtypes) == 2 && isa(argtypes[2], Const) && isa(argtypes[2].val, SimpleVector) && istopfunction(tm, f, :length)
673-
# mark length(::SimpleVector) as @pure
673+
# mark length(::SimpleVector) as @unsafe_pure
674674
return Const(length(argtypes[2].val))
675675
elseif length(argtypes) == 3 && isa(argtypes[2], Const) && isa(argtypes[3], Const) &&
676676
isa(argtypes[2].val, SimpleVector) && isa(argtypes[3].val, Int) && istopfunction(tm, f, :getindex)
677-
# mark getindex(::SimpleVector, i::Int) as @pure
677+
# mark getindex(::SimpleVector, i::Int) as @unsafe_pure
678678
svecval = argtypes[2].val::SimpleVector
679679
idx = argtypes[3].val::Int
680680
if 1 <= idx <= length(svecval) && isassigned(svecval, idx)

base/compiler/optimize.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ function optimize(me::InferenceState)
196196
proven_pure = false
197197
# must be proven pure to use const_api; otherwise we might skip throwing errors
198198
# (issue #20704)
199-
# TODO: Improve this analysis; if a function is marked @pure we should really
199+
# TODO: Improve this analysis; if a function is marked @unsafe_pure we should really
200200
# only care about certain errors (e.g. method errors and type errors).
201201
if length(me.src.code) < 10
202202
proven_pure = true

base/compiler/typelattice.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
# The type of a value might be constant
99
struct Const
1010
val
11-
actual::Bool # if true, we obtained `val` by actually calling a @pure function
11+
actual::Bool # if true, we obtained `val` by actually calling a @unsafe_pure function
1212
Const(@nospecialize(v)) = new(v, false)
1313
Const(@nospecialize(v), a::Bool) = new(v, a)
1414
end

base/expr.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ macro noinline(ex)
200200
esc(isa(ex, Expr) ? pushmeta!(ex, :noinline) : ex)
201201
end
202202

203-
macro pure(ex)
203+
macro unsafe_pure(ex)
204204
esc(isa(ex, Expr) ? pushmeta!(ex, :pure) : ex)
205205
end
206206

base/irrationals.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ AbstractFloat(x::AbstractIrrational) = Float64(x)
2929
Float16(x::AbstractIrrational) = Float16(Float32(x))
3030
Complex{T}(x::AbstractIrrational) where {T<:Real} = Complex{T}(T(x))
3131

32-
@pure function Rational{T}(x::AbstractIrrational) where T<:Integer
32+
@unsafe_pure function Rational{T}(x::AbstractIrrational) where T<:Integer
3333
o = precision(BigFloat)
3434
p = 256
3535
while true
@@ -45,7 +45,7 @@ Complex{T}(x::AbstractIrrational) where {T<:Real} = Complex{T}(T(x))
4545
end
4646
(::Type{Rational{BigInt}})(x::AbstractIrrational) = throw(ArgumentError("Cannot convert an AbstractIrrational to a Rational{BigInt}: use rationalize(Rational{BigInt}, x) instead"))
4747

48-
@pure function (t::Type{T})(x::AbstractIrrational, r::RoundingMode) where T<:Union{Float32,Float64}
48+
@unsafe_pure function (t::Type{T})(x::AbstractIrrational, r::RoundingMode) where T<:Union{Float32,Float64}
4949
setprecision(BigFloat, 256) do
5050
T(BigFloat(x), r)
5151
end
@@ -78,11 +78,11 @@ end
7878
<=(x::AbstractFloat, y::AbstractIrrational) = x < y
7979

8080
# Irrational vs Rational
81-
@pure function rationalize(::Type{T}, x::AbstractIrrational; tol::Real=0) where T
81+
@unsafe_pure function rationalize(::Type{T}, x::AbstractIrrational; tol::Real=0) where T
8282
return rationalize(T, big(x), tol=tol)
8383
end
84-
@pure function lessrational(rx::Rational{<:Integer}, x::AbstractIrrational)
85-
# an @pure version of `<` for determining if the rationalization of
84+
@unsafe_pure function lessrational(rx::Rational{<:Integer}, x::AbstractIrrational)
85+
# an @unsafe_pure version of `<` for determining if the rationalization of
8686
# an irrational number required rounding up or down
8787
return rx < big(x)
8888
end

base/namedtuple.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -186,14 +186,14 @@ function map(f, nt::NamedTuple{names}, nts::NamedTuple...) where names
186186
end
187187

188188
# a version of `in` for the older world these generated functions run in
189-
@pure function sym_in(x::Symbol, itr::Tuple{Vararg{Symbol}})
189+
@unsafe_pure function sym_in(x::Symbol, itr::Tuple{Vararg{Symbol}})
190190
for y in itr
191191
y === x && return true
192192
end
193193
return false
194194
end
195195

196-
@pure function merge_names(an::Tuple{Vararg{Symbol}}, bn::Tuple{Vararg{Symbol}})
196+
@unsafe_pure function merge_names(an::Tuple{Vararg{Symbol}}, bn::Tuple{Vararg{Symbol}})
197197
names = Symbol[an...]
198198
for n in bn
199199
if !sym_in(n, an)
@@ -203,7 +203,7 @@ end
203203
(names...,)
204204
end
205205

206-
@pure function merge_types(names::Tuple{Vararg{Symbol}}, a::Type{<:NamedTuple}, b::Type{<:NamedTuple})
206+
@unsafe_pure function merge_types(names::Tuple{Vararg{Symbol}}, a::Type{<:NamedTuple}, b::Type{<:NamedTuple})
207207
bn = _nt_names(b)
208208
Tuple{Any[ fieldtype(sym_in(n, bn) ? b : a, n) for n in names ]...}
209209
end
@@ -270,7 +270,7 @@ haskey(nt::NamedTuple, key::Union{Integer, Symbol}) = isdefined(nt, key)
270270
get(nt::NamedTuple, key::Union{Integer, Symbol}, default) = haskey(nt, key) ? getfield(nt, key) : default
271271
get(f::Callable, nt::NamedTuple, key::Union{Integer, Symbol}) = haskey(nt, key) ? getfield(nt, key) : f()
272272

273-
@pure function diff_names(an::Tuple{Vararg{Symbol}}, bn::Tuple{Vararg{Symbol}})
273+
@unsafe_pure function diff_names(an::Tuple{Vararg{Symbol}}, bn::Tuple{Vararg{Symbol}})
274274
names = Symbol[]
275275
for n in an
276276
if !sym_in(n, bn)

base/set.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,7 @@ promote_valuetype(x::Pair{K, V}, y::Pair...) where {K, V} =
460460
promote_type(V, promote_valuetype(y...))
461461

462462
# Subtract singleton types which are going to be replaced
463-
@pure issingletontype(T::DataType) = isdefined(T, :instance)
463+
@unsafe_pure issingletontype(T::DataType) = isdefined(T, :instance)
464464
issingletontype(::Type) = false
465465
function subtract_singletontype(::Type{T}, x::Pair{K}) where {T, K}
466466
if issingletontype(K)

doc/src/manual/types.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1374,7 +1374,7 @@ for cases where you don't need a more elaborate hierarchy.
13741374
julia> struct Val{x}
13751375
end
13761376
1377-
julia> Base.@pure Val(x) = Val{x}()
1377+
julia> Base.@unsafe_pure Val(x) = Val{x}()
13781378
Val
13791379
```
13801380

stdlib/LinearAlgebra/src/LinearAlgebra.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import Base: USE_BLAS64, abs, acos, acosh, acot, acoth, acsc, acsch, adjoint, as
1818
setindex!, show, similar, sin, sincos, sinh, size, size_to_strides, sqrt, StridedReinterpretArray,
1919
StridedReshapedArray, strides, stride, tan, tanh, transpose, trunc, typed_hcat, vec
2020
using Base: hvcat_fill, iszero, IndexLinear, _length, promote_op, promote_typeof,
21-
@propagate_inbounds, @pure, reduce, typed_vcat
21+
@propagate_inbounds, @unsafe_pure, reduce, typed_vcat
2222
using Base.Broadcast: Broadcasted
2323

2424
# We use `_length` because of non-1 indices; releases after julia 0.5

stdlib/LinearAlgebra/src/deprecated.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ _RowVector_depstring() = string("`ConjRowVector` and `RowVector` have been depre
403403
"of the associated changes.")
404404

405405
@inline check_types(::Type{T1}, ::AbstractVector{T2}) where {T1,T2} = check_types(T1, T2)
406-
@pure check_types(::Type{T1}, ::Type{T2}) where {T1,T2} = T1 === transpose_type(T2) ? nothing :
406+
@unsafe_pure check_types(::Type{T1}, ::Type{T2}) where {T1,T2} = T1 === transpose_type(T2) ? nothing :
407407
error("Element type mismatch. Tried to create a `RowVector{$T1}` from an `AbstractVector{$T2}`")
408408

409409
# The element type may be transformed as transpose is recursive

test/compiler/compiler.jl

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ f18450() = ifelse(true, Tuple{Vararg{Int}}, Tuple{Vararg})
440440
@test !Core.Compiler.isconstType(Type{Tuple})
441441

442442
# ensure pure attribute applies correctly to all signatures of fpure
443-
Base.@pure function fpure(a=rand(); b=rand())
443+
Base.@unsafe_pure function fpure(a=rand(); b=rand())
444444
# use the `rand` function since it is known to be `@inline`
445445
# but would be too big to inline
446446
return a + b + rand()
@@ -456,8 +456,8 @@ gpure(x::Irrational) = fpure(x)
456456
@test gpure() == gpure() == gpure()
457457
@test gpure(π) == gpure(π) == gpure(π)
458458

459-
# Make sure @pure works for functions using the new syntax
460-
Base.@pure (fpure2(x::T) where T) = T
459+
# Make sure @unsafe_pure works for functions using the new syntax
460+
Base.@unsafe_pure (fpure2(x::T) where T) = T
461461
@test which(fpure2, (Int64,)).pure
462462

463463
# issue #10880
@@ -752,7 +752,7 @@ f20267(x::T20267{T}, y::T) where (T) = f20267(Any[1][1], x.inds)
752752

753753
# issue #20704
754754
f20704(::Int) = 1
755-
Base.@pure b20704(@nospecialize(x)) = f20704(x)
755+
Base.@unsafe_pure b20704(@nospecialize(x)) = f20704(x)
756756
@test b20704(42) === 1
757757
@test_throws MethodError b20704(42.0)
758758

@@ -763,16 +763,16 @@ v20704() = Val{b20704(Any[1.0][1])}
763763
@test_throws MethodError v20704()
764764
@test Base.return_types(v20704, ()) == Any[Type{Val{1}}]
765765

766-
Base.@pure g20704(::Int) = 1
766+
Base.@unsafe_pure g20704(::Int) = 1
767767
h20704(@nospecialize(x)) = g20704(x)
768768
@test g20704(1) === 1
769769
@test_throws MethodError h20704(1.2)
770770

771-
Base.@pure c20704() = (f20704(1.0); 1)
771+
Base.@unsafe_pure c20704() = (f20704(1.0); 1)
772772
d20704() = c20704()
773773
@test_throws MethodError d20704()
774774

775-
Base.@pure function a20704(x)
775+
Base.@unsafe_pure function a20704(x)
776776
rand()
777777
42
778778
end
@@ -1013,7 +1013,7 @@ typeargs = (Type{Int},Type{Int},Type{Int},Type{Int},Type{Int},Type{Int})
10131013

10141014
# demonstrate that inference must converge
10151015
# while doing constant propagation
1016-
Base.@pure plus1(x) = x + 1
1016+
Base.@unsafe_pure plus1(x) = x + 1
10171017
f21933(x::Val{T}) where {T} = f(Val(plus1(T)))
10181018
code_typed(f21933, (Val{1},))
10191019
Base.return_types(f21933, (Val{1},))

0 commit comments

Comments
 (0)