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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 12 additions & 12 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 5 additions & 5 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 10 additions & 10 deletions
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

0 commit comments

Comments
 (0)