Skip to content

Commit 63bbaef

Browse files
committed
Deprecate $ for xor() (#18696)
This includes: - occurrances of $ (as infix operator) and $= in base - occurances of $ in test - the definition in the manual - the entry in REPL help This commit does not introduce an alternative, that will happen in the next commit.
1 parent f56d594 commit 63bbaef

34 files changed

+146
-143
lines changed

base/arraymath.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ promote_array_type{S<:Integer}(::typeof(./), ::Type{S}, ::Type{Bool}, T::Type) =
5252
promote_array_type{S<:Integer}(::typeof(.\), ::Type{S}, ::Type{Bool}, T::Type) = T
5353
promote_array_type{S<:Integer}(F, ::Type{S}, ::Type{Bool}, T::Type) = T
5454

55-
for f in (:+, :-, :div, :mod, :&, :|, :$)
55+
for f in (:+, :-, :div, :mod, :&, :|, :xor)
5656
@eval ($f)(A::AbstractArray, B::AbstractArray) =
5757
_elementwise($f, promote_eltype_op($f, A, B), A, B)
5858
end
@@ -68,7 +68,7 @@ function _elementwise{T}(op, ::Type{T}, A::AbstractArray, B::AbstractArray)
6868
return F
6969
end
7070

71-
for f in (:.+, :.-, :.*, :./, :.\, :.^, :, :.%, :.<<, :.>>, :div, :mod, :rem, :&, :|, :$)
71+
for f in (:.+, :.-, :.*, :./, :.\, :.^, :, :.%, :.<<, :.>>, :div, :mod, :rem, :&, :|, :xor)
7272
@eval begin
7373
function ($f){T}(A::Number, B::AbstractArray{T})
7474
R = promote_op($f, typeof(A), T)

base/associative.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ const hasha_seed = UInt === UInt64 ? 0x6d35bb51952d5539 : 0x952d5539
251251
function hash(a::Associative, h::UInt)
252252
h = hash(hasha_seed, h)
253253
for (k,v) in a
254-
h $= hash(k, hash(v))
254+
h = xor(h, hash(k, hash(v)))
255255
end
256256
return h
257257
end

base/bitarray.jl

+12-12
Original file line numberDiff line numberDiff line change
@@ -1333,12 +1333,12 @@ function (|)(B::BitArray, x::Bool)
13331333
end
13341334
(|)(x::Bool, B::BitArray) = B | x
13351335

1336-
function ($)(B::BitArray, x::Bool)
1336+
function xor(B::BitArray, x::Bool)
13371337
x ? ~B : copy(B)
13381338
end
1339-
($)(x::Bool, B::BitArray) = B $ x
1339+
xor(x::Bool, B::BitArray) = xor(B, x)
13401340

1341-
for f in (:&, :|, :$)
1341+
for f in (:&, :|, :xor)
13421342
@eval begin
13431343
function ($f)(A::BitArray, B::BitArray)
13441344
F = BitArray(promote_shape(size(A),size(B))...)
@@ -2007,10 +2007,10 @@ end
20072007

20082008
map!(f::Union{typeof(*), typeof(min)}, dest::BitArray, A::BitArray, B::BitArray) = map!(&, dest, A, B)
20092009
map!(f::typeof(max), dest::BitArray, A::BitArray, B::BitArray) = map!(|, dest, A, B)
2010-
map!(f::typeof(!=), dest::BitArray, A::BitArray, B::BitArray) = map!($, dest, A, B)
2010+
map!(f::typeof(!=), dest::BitArray, A::BitArray, B::BitArray) = map!(xor, dest, A, B)
20112011
map!(f::Union{typeof(>=), typeof(^)}, dest::BitArray, A::BitArray, B::BitArray) = map!(BitChunkFunctor((p, q) -> p | ~q), dest, A, B)
20122012
map!(f::typeof(<=), dest::BitArray, A::BitArray, B::BitArray) = map!(BitChunkFunctor((p, q) -> ~p | q), dest, A, B)
2013-
map!(f::typeof(==), dest::BitArray, A::BitArray, B::BitArray) = map!(BitChunkFunctor((p, q) -> ~(p $ q)), dest, A, B)
2013+
map!(f::typeof(==), dest::BitArray, A::BitArray, B::BitArray) = map!(BitChunkFunctor((p, q) -> ~xor(p, q)), dest, A, B)
20142014
map!(f::typeof(<), dest::BitArray, A::BitArray, B::BitArray) = map!(BitChunkFunctor((p, q) -> ~p & q), dest, A, B)
20152015
map!(f::typeof(>), dest::BitArray, A::BitArray, B::BitArray) = map!(BitChunkFunctor((p, q) -> p & ~q), dest, A, B)
20162016

@@ -2028,7 +2028,7 @@ function map!(f::Union{typeof(identity), typeof(~)}, dest::BitArray, A::BitArray
20282028
destc[end] = f(Ac[end]) & _msk_end(A)
20292029
dest
20302030
end
2031-
function map!(f::Union{BitChunkFunctor, typeof(&), typeof(|), typeof($)}, dest::BitArray, A::BitArray, B::BitArray)
2031+
function map!(f::Union{BitChunkFunctor, typeof(&), typeof(|), typeof(xor)}, dest::BitArray, A::BitArray, B::BitArray)
20322032
size(A) == size(B) == size(dest) || throw(DimensionMismatch("sizes of dest, A, and B must all match"))
20332033
isempty(A) && return dest
20342034
destc = dest.chunks
@@ -2056,12 +2056,12 @@ transpose(B::BitVector) = reshape(copy(B), 1, length(B))
20562056
# http://www.hackersdelight.org/hdcodetxt/transpose8.c.txt
20572057
function transpose8x8(x::UInt64)
20582058
y = x
2059-
t = (y $ (y >>> 7)) & 0x00aa00aa00aa00aa
2060-
y = y $ t $ (t << 7)
2061-
t = (y $ (y >>> 14)) & 0x0000cccc0000cccc
2062-
y = y $ t $ (t << 14)
2063-
t = (y $ (y >>> 28)) & 0x00000000f0f0f0f0
2064-
return y $ t $ (t << 28)
2059+
t = xor(y, y >>> 7) & 0x00aa00aa00aa00aa
2060+
y = xor(y, t, t << 7)
2061+
t = xor(y, y >>> 14) & 0x0000cccc0000cccc
2062+
y = xor(y, t, t << 14)
2063+
t = xor(y, y >>> 28) & 0x00000000f0f0f0f0
2064+
return xor(y, t, t << 28)
20652065
end
20662066

20672067
function form_8x8_chunk(Bc::Vector{UInt64}, i1::Int, i2::Int, m::Int, cgap::Int, cinc::Int, nc::Int, msk8::UInt64)

base/bool.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ end
2323
(~)(x::Bool) = !x
2424
(&)(x::Bool, y::Bool) = box(Bool,and_int(unbox(Bool,x),unbox(Bool,y)))
2525
(|)(x::Bool, y::Bool) = box(Bool,or_int(unbox(Bool,x),unbox(Bool,y)))
26-
($)(x::Bool, y::Bool) = (x!=y)
26+
xor(x::Bool, y::Bool) = (x!=y)
2727

2828
>>(x::Bool, c::Unsigned) = Int(x) >> c
2929
<<(x::Bool, c::Unsigned) = Int(x) << c

base/broadcast.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -472,9 +472,9 @@ function broadcast_bitarrays(scalarf, bitf, A::AbstractArray{Bool}, B::AbstractA
472472
return F
473473
end
474474

475-
biteq(a::UInt64, b::UInt64) = ~a $ b
475+
biteq(a::UInt64, b::UInt64) = xor(~a, b)
476476
bitlt(a::UInt64, b::UInt64) = ~a & b
477-
bitneq(a::UInt64, b::UInt64) = a $ b
477+
bitneq(a::UInt64, b::UInt64) = xor(a, b)
478478
bitle(a::UInt64, b::UInt64) = ~a | b
479479

480480
.==(A::AbstractArray{Bool}, B::AbstractArray{Bool}) = broadcast_bitarrays(==, biteq, A, B)

base/c.jl

+5-5
Original file line numberDiff line numberDiff line change
@@ -187,24 +187,24 @@ function transcode(::Type{UInt16}, src::Vector{UInt8})
187187
push!(dst, a)
188188
a = b; continue
189189
elseif a < 0xe0 # 2-byte UTF-8
190-
push!(dst, 0x3080 $ (UInt16(a) << 6) $ b)
190+
push!(dst, xor(0x3080, UInt16(a) << 6, b))
191191
elseif i < n # 3/4-byte character
192192
c = src[i += 1]
193193
if -64 <= (c % Int8) # invalid UTF-8 (non-continuation)
194194
push!(dst, a, b)
195195
a = c; continue
196196
elseif a < 0xf0 # 3-byte UTF-8
197-
push!(dst, 0x2080 $ (UInt16(a) << 12) $ (UInt16(b) << 6) $ c)
197+
push!(dst, xor(0x2080, UInt16(a) << 12, UInt16(b) << 6, c))
198198
elseif i < n
199199
d = src[i += 1]
200200
if -64 <= (d % Int8) # invalid UTF-8 (non-continuation)
201201
push!(dst, a, b, c)
202202
a = d; continue
203203
elseif a == 0xf0 && b < 0x90 # overlong encoding
204-
push!(dst, 0x2080 $ (UInt16(b) << 12) $ (UInt16(c) << 6) $ d)
204+
push!(dst, xor(0x2080, UInt16(b) << 12, UInt16(c) << 6, d))
205205
else # 4-byte UTF-8
206206
push!(dst, 0xe5b8 + (UInt16(a) << 8) + (UInt16(b) << 2) + (c >> 4),
207-
0xdc80 $ (UInt16(c & 0xf) << 6) $ d)
207+
xor(0xdc80, UInt16(c & 0xf) << 6, d))
208208
end
209209
else # too short
210210
push!(dst, a, b, c)
@@ -273,7 +273,7 @@ function transcode(::Type{UInt8}, src::Vector{UInt16})
273273
a += 0x2840
274274
dst[j += 1] = 0xf0 | ((a >> 8) % UInt8)
275275
dst[j += 1] = 0x80 | ((a % UInt8) >> 2)
276-
dst[j += 1] = 0xf0 $ ((((a % UInt8) << 4) & 0x3f) $ (b >> 6) % UInt8)
276+
dst[j += 1] = xor(0xf0, ((a % UInt8) << 4) & 0x3f, (b >> 6) % UInt8)
277277
dst[j += 1] = 0x80 | ((b % UInt8) & 0x3f)
278278
else
279279
dst[j += 1] = 0xe0 | ((a >> 12) % UInt8)

base/char.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ in(x::Char, y::Char) = x == y
3333
isless(x::Char, y::Char) = UInt32(x) < UInt32(y)
3434

3535
const hashchar_seed = 0xd4d64234
36-
hash(x::Char, h::UInt) = hash_uint64(((UInt64(x)+hashchar_seed)<<32) $ UInt64(h))
36+
hash(x::Char, h::UInt) = hash_uint64(xor((UInt64(x)+hashchar_seed)<<32, UInt64(h)))
3737

3838
-(x::Char, y::Char) = Int(x) - Int(y)
3939
-(x::Char, y::Integer) = Char(Int32(x) - Int32(y))

base/combinatorics.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ function isperm(A)
7373
n = length(A)
7474
used = falses(n)
7575
for a in A
76-
(0 < a <= n) && (used[a] $= true) || return false
76+
(0 < a <= n) && (used[a] = xor(used[a], true)) || return false
7777
end
7878
true
7979
end

base/complex.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ const hash_0_imag = hash(0, h_imag)
127127
function hash(z::Complex, h::UInt)
128128
# TODO: with default argument specialization, this would be better:
129129
# hash(real(z), h $ hash(imag(z), h $ h_imag) $ hash(0, h $ h_imag))
130-
hash(real(z), h $ hash(imag(z), h_imag) $ hash_0_imag)
130+
hash(real(z), xor(h, hash(imag(z), h_imag), hash_0_imag))
131131
end
132132

133133
## generic functions of complex numbers ##

base/dSFMT.jl

+10-10
Original file line numberDiff line numberDiff line change
@@ -115,19 +115,19 @@ function dsfmt_jump_add!(dest::Vector{UInt64}, src::Vector{UInt64})
115115
while i <= N-diff
116116
j = i*2-1
117117
p = j + diff*2
118-
dest[j] $= src[p]
119-
dest[j+1] $= src[p+1]
118+
dest[j] = xor(dest[j], src[p])
119+
dest[j+1] = xor(dest[j+1], src[p+1])
120120
i += 1
121121
end
122122
while i <= N
123123
j = i*2-1
124124
p = j + (diff - N)*2
125-
dest[j] $= src[p]
126-
dest[j+1] $= src[p+1]
125+
dest[j] = xor(dest[j], src[p])
126+
dest[j+1] = xor(dest[j+1], src[p+1])
127127
i += 1
128128
end
129-
dest[N*2+1] $= src[N*2+1]
130-
dest[N*2+2] $= src[N*2+2]
129+
dest[N*2+1] = xor(dest[N*2+1], src[N*2+1])
130+
dest[N*2+2] = xor(dest[N*2+2], src[N*2+2])
131131
return dest
132132
end
133133

@@ -148,10 +148,10 @@ function dsfmt_jump_next_state!(mts::Vector{UInt64})
148148
t1 = mts[a+1]
149149
L0 = mts[u]
150150
L1 = mts[u+1]
151-
mts[u] = (t0 << SL1) $ (L1 >> 32) $ (L1 << 32) $ mts[b]
152-
mts[u+1] = (t1 << SL1) $ (L0 >> 32) $ (L0 << 32) $ mts[b+1]
153-
mts[a] = (mts[u] >> SR) $ (mts[u] & MSK1) $ t0
154-
mts[a+1] = (mts[u+1] >> SR) $ (mts[u+1] & MSK2) $ t1
151+
mts[u] = xor(t0 << SL1, L1 >> 32, L1 << 32, mts[b])
152+
mts[u+1] = xor(t1 << SL1, L0 >> 32, L0 << 32, mts[b+1])
153+
mts[a] = xor(mts[u] >> SR, mts[u] & MSK1, t0)
154+
mts[a+1] = xor(mts[u+1] >> SR, mts[u+1] & MSK2, t1)
155155

156156
mts[end] = (mts[end] + 2) % (N*2)
157157
return mts

base/deprecated.jl

+4-1
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ for (Fun, func) in [(:IdFun, :identity),
303303
(:ConjFun, :conj),
304304
(:AndFun, :&),
305305
(:OrFun, :|),
306-
(:XorFun, :$),
306+
(:XorFun, :xor),
307307
(:AddFun, :+),
308308
(:DotAddFun, :.+),
309309
(:SubFun, :-),
@@ -1021,6 +1021,9 @@ end))
10211021

10221022
@deprecate ipermutedims(A::AbstractArray,p) permutedims(A, invperm(p))
10231023

1024+
# 18696
1025+
@deprecate ($) xor
1026+
10241027
@deprecate is (===)
10251028

10261029

base/docs/helpdb/Base.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -3394,8 +3394,8 @@ Compute the Dawson function (scaled imaginary error function) of `x`, defined by
33943394
dawson
33953395

33963396
"""
3397-
\$(x, y)
3397+
xor(x, y)
33983398
33993399
Bitwise exclusive or.
34003400
"""
3401-
Base.:$(x, y)
3401+
Base.xor(x, y)

base/exports.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ export
205205
!==,
206206
,
207207
,
208-
$,
208+
xor,
209209
%,
210210
÷,
211211
&,

base/fastmath.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ mul_fast{T<:FloatTypes}(x::T, y::T, zs::T...) =
153153
cmp_fast{T<:FloatTypes}(x::T, y::T) = ifelse(x==y, 0, ifelse(x<y, -1, +1))
154154
function mod_fast{T<:FloatTypes}(x::T, y::T)
155155
r = rem(x,y)
156-
ifelse((r > 0) $ (y > 0), r+y, r)
156+
ifelse(xor(r > 0, y > 0), r+y, r)
157157
end
158158
end
159159

base/float.jl

+4-4
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ _default_type(T::Union{Type{Real},Type{AbstractFloat}}) = Float64
342342
## floating point arithmetic ##
343343
-(x::Float64) = box(Float64,neg_float(unbox(Float64,x)))
344344
-(x::Float32) = box(Float32,neg_float(unbox(Float32,x)))
345-
-(x::Float16) = reinterpret(Float16, reinterpret(UInt16,x) $ 0x8000)
345+
-(x::Float16) = reinterpret(Float16, xor(reinterpret(UInt16,x), 0x8000))
346346

347347
for op in (:+,:-,:*,:/,:\,:^)
348348
@eval ($op)(a::Float16, b::Float16) = Float16(($op)(Float32(a), Float32(b)))
@@ -381,7 +381,7 @@ function mod{T<:AbstractFloat}(x::T, y::T)
381381
r = rem(x,y)
382382
if r == 0
383383
copysign(r,y)
384-
elseif (r > 0) $ (y > 0)
384+
elseif xor(r > 0, y > 0)
385385
r+y
386386
else
387387
r
@@ -512,7 +512,7 @@ const hx_NaN = hx(UInt64(0), NaN, UInt(0 ))
512512

513513
hash(x::UInt64, h::UInt) = hx(x, Float64(x), h)
514514
hash(x::Int64, h::UInt) = hx(reinterpret(UInt64,abs(x)), Float64(x), h)
515-
hash(x::Float64, h::UInt) = isnan(x) ? (hx_NaN $ h) : hx(box(UInt64,fptoui(unbox(Float64,abs(x)))), x, h)
515+
hash(x::Float64, h::UInt) = isnan(x) ? xor(hx_NaN, h) : hx(box(UInt64,fptoui(unbox(Float64,abs(x)))), x, h)
516516

517517
hash(x::Union{Bool,Int8,UInt8,Int16,UInt16,Int32,UInt32}, h::UInt) = hash(Int64(x), h)
518518
hash(x::Float32, h::UInt) = hash(Float64(x), h)
@@ -558,7 +558,7 @@ function nextfloat(f::Union{Float16,Float32,Float64}, d::Integer)
558558
fu = fumax
559559
else
560560
du = da % U
561-
if fneg $ dneg
561+
if xor(fneg, dneg)
562562
if du > fu
563563
fu = min(fumax, du - fu)
564564
fneg = !fneg

base/gmp.jl

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ module GMP
44

55
export BigInt
66

7-
import Base: *, +, -, /, <, <<, >>, >>>, <=, ==, >, >=, ^, (~), (&), (|), ($),
7+
import Base: *, +, -, /, <, <<, >>, >>>, <=, ==, >, >=, ^, (~), (&), (|), xor,
88
binomial, cmp, convert, div, divrem, factorial, fld, gcd, gcdx, lcm, mod,
99
ndigits, promote_rule, rem, show, isqrt, string, powermod,
1010
sum, trailing_zeros, trailing_ones, count_ones, base, tryparse_internal,
@@ -194,7 +194,7 @@ function convert{T<:Signed}(::Type{T}, x::BigInt)
194194
else
195195
0 <= n <= cld(sizeof(T),sizeof(Limb)) || throw(InexactError())
196196
y = x % T
197-
(x.size > 0) $ (y > 0) && throw(InexactError()) # catch overflow
197+
xor(x.size > 0, y > 0) && throw(InexactError()) # catch overflow
198198
y
199199
end
200200
end
@@ -249,7 +249,7 @@ promote_rule{T<:Integer}(::Type{BigInt}, ::Type{T}) = BigInt
249249
for (fJ, fC) in ((:+, :add), (:-,:sub), (:*, :mul),
250250
(:fld, :fdiv_q), (:div, :tdiv_q), (:mod, :fdiv_r), (:rem, :tdiv_r),
251251
(:gcd, :gcd), (:lcm, :lcm),
252-
(:&, :and), (:|, :ior), (:$, :xor))
252+
(:&, :and), (:|, :ior), (:xor, :xor))
253253
@eval begin
254254
function ($fJ)(x::BigInt, y::BigInt)
255255
z = BigInt()
@@ -279,7 +279,7 @@ function invmod(x::BigInt, y::BigInt)
279279
end
280280

281281
# More efficient commutative operations
282-
for (fJ, fC) in ((:+, :add), (:*, :mul), (:&, :and), (:|, :ior), (:$, :xor))
282+
for (fJ, fC) in ((:+, :add), (:*, :mul), (:&, :and), (:|, :ior), (:xor, :xor))
283283
@eval begin
284284
function ($fJ)(a::BigInt, b::BigInt, c::BigInt)
285285
z = BigInt()

base/hashing.jl

+9-9
Original file line numberDiff line numberDiff line change
@@ -14,34 +14,34 @@ hash(x::ANY, h::UInt) = 3*object_id(x) - h
1414
function hash_64_64(n::UInt64)
1515
local a::UInt64 = n
1616
a = ~a + a << 21
17-
a = a $ a >> 24
17+
a = xor(a, a >> 24)
1818
a = a + a << 3 + a << 8
19-
a = a $ a >> 14
19+
a = xor(a, a >> 14)
2020
a = a + a << 2 + a << 4
21-
a = a $ a >> 28
21+
a = xor(a, a >> 28)
2222
a = a + a << 31
2323
return a
2424
end
2525

2626
function hash_64_32(n::UInt64)
2727
local a::UInt64 = n
2828
a = ~a + a << 18
29-
a = a $ a >> 31
29+
a = xor(a, a >> 31)
3030
a = a * 21
31-
a = a $ a >> 11
31+
a = xor(a, a >> 11)
3232
a = a + a << 6
33-
a = a $ a >> 22
33+
a = xor(a, a >> 22)
3434
return a % UInt32
3535
end
3636

3737
function hash_32_32(n::UInt32)
3838
local a::UInt32 = n
3939
a = a + 0x7ed55d16 + a << 12
40-
a = a $ 0xc761c23c $ a >> 19
40+
a = xor(a, 0xc761c23c, a >> 19)
4141
a = a + 0x165667b1 + a << 5
42-
a = a + 0xd3a2646c $ a << 9
42+
a = a + xor(0xd3a2646c, a << 9)
4343
a = a + 0xfd7046c5 + a << 3
44-
a = a $ 0xb55a4f09 $ a >> 16
44+
a = xor(a, 0xb55a4f09, a >> 16)
4545
return a
4646
end
4747

0 commit comments

Comments
 (0)