Skip to content

Commit 5f3474e

Browse files
committed
deprecate precedence of & and |. for #5187
1 parent ea5b0a3 commit 5f3474e

34 files changed

+227
-202
lines changed

NEWS.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@ Language changes
6969
* The parsing of `1<<2*3` as `1<<(2*3)` is deprecated, and will change to
7070
`(1<<2)*3` in a future version ([#13079]).
7171

72+
* The precedence of `&` and `|` is deprecated, and will change to match that of
73+
`&&` and `||`. In the meantime, such expressions should be parenthesized ([#5187]).
74+
7275
* The parsing of `<|` is now right associative. `|>` remains left associative ([#24153]).
7376

7477
* `{ }` expressions now use `braces` and `bracescat` as expression heads instead

base/bitarray.jl

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ dumpbitcache(Bc::Vector{UInt64}, bind::Int, C::Vector{Bool}) =
324324

325325
## custom iterator ##
326326
start(B::BitArray) = 0
327-
next(B::BitArray, i::Int) = (B.chunks[_div64(i)+1] & (UInt64(1)<<_mod64(i)) != 0, i+1)
327+
next(B::BitArray, i::Int) = ((B.chunks[_div64(i)+1] & (UInt64(1)<<_mod64(i))) != 0, i+1)
328328
done(B::BitArray, i::Int) = i >= length(B)
329329

330330
## similar, fill!, copy! etc ##
@@ -702,7 +702,7 @@ function _unsafe_setindex!(B::BitArray, X::AbstractArray, I::BitArray)
702702
@inbounds C = Bc[i]
703703
u = UInt64(1)
704704
for j = 1:(i < lc ? 64 : last_chunk_len)
705-
if Imsk & u != 0
705+
if (Imsk & u) != 0
706706
lx < c && throw_setindex_mismatch(X, c)
707707
@inbounds x = convert(Bool, X[c])
708708
C = ifelse(x, C | u, C & ~u)
@@ -1068,7 +1068,7 @@ function (-)(B::BitArray)
10681068
u = UInt64(1)
10691069
c = Bc[i]
10701070
for j = 1:64
1071-
if c & u != 0
1071+
if (c & u) != 0
10721072
A[ind] = -1
10731073
end
10741074
ind += 1
@@ -1078,7 +1078,7 @@ function (-)(B::BitArray)
10781078
u = UInt64(1)
10791079
c = Bc[end]
10801080
for j = 0:_mod64(l-1)
1081-
if c & u != 0
1081+
if (c & u) != 0
10821082
A[ind] = -1
10831083
end
10841084
ind += 1
@@ -1449,7 +1449,7 @@ function unsafe_bitfindnext(Bc::Vector{UInt64}, start::Integer)
14491449
mask = _msk64 << within_chunk_start
14501450

14511451
@inbounds begin
1452-
if Bc[chunk_start] & mask != 0
1452+
if (Bc[chunk_start] & mask) != 0
14531453
return (chunk_start-1) << 6 + trailing_zeros(Bc[chunk_start] & mask) + 1
14541454
end
14551455

@@ -1485,7 +1485,7 @@ function findnextnot(B::BitArray, start::Integer)
14851485
mask = ~(_msk64 << within_chunk_start)
14861486

14871487
@inbounds if chunk_start < l
1488-
if Bc[chunk_start] | mask != _msk64
1488+
if (Bc[chunk_start] | mask) != _msk64
14891489
return (chunk_start-1) << 6 + trailing_ones(Bc[chunk_start] | mask) + 1
14901490
end
14911491
for i = chunk_start+1:l-1
@@ -1496,7 +1496,7 @@ function findnextnot(B::BitArray, start::Integer)
14961496
if Bc[l] != _msk_end(B)
14971497
return (l-1) << 6 + trailing_ones(Bc[l]) + 1
14981498
end
1499-
elseif Bc[l] | mask != _msk_end(B)
1499+
elseif (Bc[l] | mask) != _msk_end(B)
15001500
return (l-1) << 6 + trailing_ones(Bc[l] | mask) + 1
15011501
end
15021502
return 0
@@ -1530,7 +1530,7 @@ function unsafe_bitfindprev(Bc::Vector{UInt64}, start::Integer)
15301530
mask = _msk_end(start)
15311531

15321532
@inbounds begin
1533-
if Bc[chunk_start] & mask != 0
1533+
if (Bc[chunk_start] & mask) != 0
15341534
return (chunk_start-1) << 6 + (64 - leading_zeros(Bc[chunk_start] & mask))
15351535
end
15361536

@@ -1560,7 +1560,7 @@ function findprevnot(B::BitArray, start::Integer)
15601560
mask = ~_msk_end(start)
15611561

15621562
@inbounds begin
1563-
if Bc[chunk_start] | mask != _msk64
1563+
if (Bc[chunk_start] | mask) != _msk64
15641564
return (chunk_start-1) << 6 + (64 - leading_ones(Bc[chunk_start] | mask))
15651565
end
15661566

@@ -1608,7 +1608,7 @@ function find(B::BitArray)
16081608
u = UInt64(1)
16091609
c = Bc[i]
16101610
for j = 1:64
1611-
if c & u != 0
1611+
if (c & u) != 0
16121612
I[Icount] = Bcount
16131613
Icount += 1
16141614
end
@@ -1619,7 +1619,7 @@ function find(B::BitArray)
16191619
u = UInt64(1)
16201620
c = Bc[end]
16211621
for j = 0:_mod64(l-1)
1622-
if c & u != 0
1622+
if (c & u) != 0
16231623
I[Icount] = Bcount
16241624
Icount += 1
16251625
end
@@ -1839,7 +1839,7 @@ function read!(s::IO, B::BitArray)
18391839
n = length(B)
18401840
Bc = B.chunks
18411841
nc = length(read!(s, Bc))
1842-
if length(Bc) > 0 && Bc[end] & _msk_end(n) Bc[end]
1842+
if length(Bc) > 0 && (Bc[end] & _msk_end(n)) Bc[end]
18431843
Bc[end] &= _msk_end(n) # ensure that the BitArray is not broken
18441844
throw(DimensionMismatch("read mismatch, found non-zero bits after BitArray length"))
18451845
end

base/c.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ function transcode(::Type{UInt8}, src::Vector{UInt16})
281281
m += 1
282282
elseif a < 0x800 # 2-byte UTF-8
283283
m += 2
284-
elseif a & 0xfc00 == 0xd800 && i < length(src)
284+
elseif (a & 0xfc00) == 0xd800 && i < length(src)
285285
b = src[i += 1]
286286
if (b & 0xfc00) == 0xdc00 # 2-unit UTF-16 sequence => 4-byte UTF-8
287287
m += 4
@@ -307,7 +307,7 @@ function transcode(::Type{UInt8}, src::Vector{UInt16})
307307
elseif a < 0x800 # 2-byte UTF-8
308308
dst[j += 1] = 0xc0 | ((a >> 6) % UInt8)
309309
dst[j += 1] = 0x80 | ((a % UInt8) & 0x3f)
310-
elseif a & 0xfc00 == 0xd800 && i < n
310+
elseif (a & 0xfc00) == 0xd800 && i < n
311311
b = src[i += 1]
312312
if (b & 0xfc00) == 0xdc00
313313
# 2-unit UTF-16 sequence => 4-byte UTF-8

base/char.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ function UInt32(c::Char)
3333
malformed_char(c)::Union{}
3434
u &= 0xffffffff >> l1
3535
u >>= t0
36-
(u & 0x0000007f >> 0) | (u & 0x00007f00 >> 2) |
37-
(u & 0x007f0000 >> 4) | (u & 0x7f000000 >> 6)
36+
((u & 0x0000007f) >> 0) | ((u & 0x00007f00) >> 2) |
37+
((u & 0x007f0000) >> 4) | ((u & 0x7f000000) >> 6)
3838
end
3939

4040
function Char(u::UInt32)

base/deprecated.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1429,10 +1429,11 @@ end
14291429
# ::ANY is deprecated in src/method.c
14301430
# also remove all instances of `jl_ANY_flag` in src/
14311431

1432-
# issue #13079
1432+
# issue #13079, #5187
14331433
# in julia-parser.scm:
14341434
# move prec-bitshift after prec-rational
1435-
# remove parse-with-chains-warn and bitshift-warn
1435+
# move & and | to && and || level
1436+
# remove dep-check and related code
14361437
# update precedence table in doc/src/manual/mathematical-operations.md
14371438

14381439
# deprecate remaining vectorized methods over SparseVectors (zero-preserving)

base/filesystem.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ function read(f::File, ::Type{Char})
158158
while s l && !eof(f)
159159
p = position(f)
160160
b = read(f, UInt8)
161-
if b & 0xc0 != 0x80
161+
if (b & 0xc0) != 0x80
162162
seek(f, p)
163163
break
164164
end

base/float.jl

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ function Float64(x::Int128)
101101
y &= ~UInt64(trailing_zeros(x) == (n-54)) # fix last bit to round to even
102102
end
103103
d = ((n+1022) % UInt64) << 52
104-
reinterpret(Float64, s | d + y)
104+
reinterpret(Float64, (s | d) + y)
105105
end
106106

107107
function Float32(x::UInt128)
@@ -131,7 +131,7 @@ function Float32(x::Int128)
131131
y &= ~UInt32(trailing_zeros(x) == (n-25)) # fix last bit to round to even
132132
end
133133
d = ((n+126) % UInt32) << 23
134-
reinterpret(Float32, s | d + y)
134+
reinterpret(Float32, (s | d) + y)
135135
end
136136

137137
function Float16(val::Float32)
@@ -140,7 +140,7 @@ function Float16(val::Float32)
140140
t = 0x8000 (0x8000 & ((f >> 0x10) % UInt16))
141141
return reinterpret(Float16, t ((f >> 0xd) % UInt16))
142142
end
143-
i = (f >> 23) & 0x1ff + 1
143+
i = ((f >> 23) & 0x1ff) + 1
144144
sh = shifttable[i]
145145
f &= 0x007fffff
146146
h::UInt16 = basetable[i] + (f >> sh)
@@ -150,7 +150,7 @@ function Float16(val::Float32)
150150
nextbit = (f >> (sh-1)) & 1
151151
if nextbit != 0
152152
# Round halfway to even or check lower bits
153-
if h&1 == 1 || (f & ((1<<(sh-1))-1)) != 0
153+
if (h&1) == 1 || (f & ((1<<(sh-1))-1)) != 0
154154
h += 1
155155
end
156156
end
@@ -209,30 +209,30 @@ const shifttable = Vector{UInt8}(uninitialized, 512)
209209
for i = 0:255
210210
e = i - 127
211211
if e < -24 # Very small numbers map to zero
212-
basetable[i|0x000+1] = 0x0000
213-
basetable[i|0x100+1] = 0x8000
214-
shifttable[i|0x000+1] = 24
215-
shifttable[i|0x100+1] = 24
212+
basetable[(i|0x000)+1] = 0x0000
213+
basetable[(i|0x100)+1] = 0x8000
214+
shifttable[(i|0x000)+1] = 24
215+
shifttable[(i|0x100)+1] = 24
216216
elseif e < -14 # Small numbers map to denorms
217-
basetable[i|0x000+1] = (0x0400>>(-e-14))
218-
basetable[i|0x100+1] = (0x0400>>(-e-14)) | 0x8000
219-
shifttable[i|0x000+1] = -e-1
220-
shifttable[i|0x100+1] = -e-1
217+
basetable[(i|0x000)+1] = (0x0400>>(-e-14))
218+
basetable[(i|0x100)+1] = (0x0400>>(-e-14)) | 0x8000
219+
shifttable[(i|0x000)+1] = -e-1
220+
shifttable[(i|0x100)+1] = -e-1
221221
elseif e <= 15 # Normal numbers just lose precision
222-
basetable[i|0x000+1] = ((e+15)<<10)
223-
basetable[i|0x100+1] = ((e+15)<<10) | 0x8000
224-
shifttable[i|0x000+1] = 13
225-
shifttable[i|0x100+1] = 13
222+
basetable[(i|0x000)+1] = ((e+15)<<10)
223+
basetable[(i|0x100)+1] = ((e+15)<<10) | 0x8000
224+
shifttable[(i|0x000)+1] = 13
225+
shifttable[(i|0x100)+1] = 13
226226
elseif e < 128 # Large numbers map to Infinity
227-
basetable[i|0x000+1] = 0x7C00
228-
basetable[i|0x100+1] = 0xFC00
229-
shifttable[i|0x000+1] = 24
230-
shifttable[i|0x100+1] = 24
227+
basetable[(i|0x000)+1] = 0x7C00
228+
basetable[(i|0x100)+1] = 0xFC00
229+
shifttable[(i|0x000)+1] = 24
230+
shifttable[(i|0x100)+1] = 24
231231
else # Infinity and NaN's stay Infinity and NaN's
232-
basetable[i|0x000+1] = 0x7C00
233-
basetable[i|0x100+1] = 0xFC00
234-
shifttable[i|0x000+1] = 13
235-
shifttable[i|0x100+1] = 13
232+
basetable[(i|0x000)+1] = 0x7C00
233+
basetable[(i|0x100)+1] = 0xFC00
234+
shifttable[(i|0x000)+1] = 13
235+
shifttable[(i|0x100)+1] = 13
236236
end
237237
end
238238

@@ -309,7 +309,7 @@ end
309309

310310
function unsafe_trunc(::Type{UInt128}, x::Float64)
311311
xu = reinterpret(UInt64,x)
312-
k = Int(xu >> 52) & 0x07ff - 1075
312+
k = (Int(xu >> 52) & 0x07ff) - 1075
313313
xu = (xu & 0x000f_ffff_ffff_ffff) | 0x0010_0000_0000_0000
314314
if k <= 0
315315
UInt128(xu >> -k)
@@ -323,7 +323,7 @@ end
323323

324324
function unsafe_trunc(::Type{UInt128}, x::Float32)
325325
xu = reinterpret(UInt32,x)
326-
k = Int(xu >> 23) & 0x00ff - 150
326+
k = (Int(xu >> 23) & 0x00ff) - 150
327327
xu = (xu & 0x007f_ffff) | 0x0080_0000
328328
if k <= 0
329329
UInt128(xu >> -k)
@@ -435,10 +435,10 @@ end
435435
function ==(x::Float16, y::Float16)
436436
ix = reinterpret(UInt16,x)
437437
iy = reinterpret(UInt16,y)
438-
if (ix|iy)&0x7fff > 0x7c00 #isnan(x) || isnan(y)
438+
if ((ix|iy)&0x7fff) > 0x7c00 #isnan(x) || isnan(y)
439439
return false
440440
end
441-
if (ix|iy)&0x7fff == 0x0000
441+
if ((ix|iy)&0x7fff) == 0x0000
442442
return true
443443
end
444444
return ix == iy
@@ -539,7 +539,7 @@ abs(x::Float64) = abs_float(x)
539539
Test whether a floating point number is not a number (NaN).
540540
"""
541541
isnan(x::AbstractFloat) = x != x
542-
isnan(x::Float16) = reinterpret(UInt16,x)&0x7fff > 0x7c00
542+
isnan(x::Float16) = (reinterpret(UInt16,x) & 0x7fff) > 0x7c00
543543
isnan(x::Real) = false
544544

545545
"""
@@ -556,7 +556,7 @@ false
556556
```
557557
"""
558558
isfinite(x::AbstractFloat) = x - x == 0
559-
isfinite(x::Float16) = reinterpret(UInt16,x)&0x7c00 != 0x7c00
559+
isfinite(x::Float16) = (reinterpret(UInt16,x) & 0x7c00) != 0x7c00
560560
isfinite(x::Real) = decompose(x)[3] != 0
561561
isfinite(x::Integer) = true
562562

@@ -718,7 +718,7 @@ Test whether a floating point number is subnormal.
718718
"""
719719
function issubnormal(x::T) where {T<:IEEEFloat}
720720
y = reinterpret(Unsigned, x)
721-
(y & exponent_mask(T) == 0) & (y & significand_mask(T) != 0)
721+
((y & exponent_mask(T)) == 0) & ((y & significand_mask(T)) != 0)
722722
end
723723

724724
@eval begin
@@ -873,7 +873,7 @@ uinttype(::Type{Float64}) = UInt64
873873
uinttype(::Type{Float32}) = UInt32
874874
uinttype(::Type{Float16}) = UInt16
875875

876-
Base.iszero(x::Float16) = reinterpret(UInt16, x) & ~sign_mask(Float16) == 0x0000
876+
Base.iszero(x::Float16) = (reinterpret(UInt16, x) & ~sign_mask(Float16)) == 0x0000
877877

878878
## Array operations on floating point numbers ##
879879

base/gmp.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ function BigInt(x::Integer)
310310
end
311311

312312

313-
rem(x::BigInt, ::Type{Bool}) = !iszero(x) & unsafe_load(x.d) % Bool # never unsafe here
313+
rem(x::BigInt, ::Type{Bool}) = (!iszero(x) & unsafe_load(x.d)) % Bool # never unsafe here
314314

315315
rem(x::BigInt, ::Type{T}) where T<:Union{SLimbMax,ULimbMax} =
316316
iszero(x) ? zero(T) : flipsign(unsafe_load(x.d) % T, x.size)

base/grisu/bignums.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ function assignpoweruint16!(x::Bignum,base::UInt16,power_exponent::Int)
375375
end
376376
zero!(x)
377377
shifts::Int = 0
378-
while base & UInt16(1) == UInt16(0)
378+
while (base & UInt16(1)) == UInt16(0)
379379
base >>= UInt16(1)
380380
shifts += 1
381381
end

base/hashing2.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ function decompose(x::Float16)::NTuple{3,Int}
101101
isinf(x) && return ifelse(x < 0, -1, 1), 0, 0
102102
n = reinterpret(UInt16, x)
103103
s = (n & 0x03ff) % Int16
104-
e = (n & 0x7c00 >> 10) % Int
104+
e = ((n & 0x7c00) >> 10) % Int
105105
s |= Int16(e != 0) << 10
106106
d = ifelse(signbit(x), -1, 1)
107107
s, e - 25 + (e == 0), d
@@ -112,7 +112,7 @@ function decompose(x::Float32)::NTuple{3,Int}
112112
isinf(x) && return ifelse(x < 0, -1, 1), 0, 0
113113
n = reinterpret(UInt32, x)
114114
s = (n & 0x007fffff) % Int32
115-
e = (n & 0x7f800000 >> 23) % Int
115+
e = ((n & 0x7f800000) >> 23) % Int
116116
s |= Int32(e != 0) << 23
117117
d = ifelse(signbit(x), -1, 1)
118118
s, e - 150 + (e == 0), d
@@ -123,7 +123,7 @@ function decompose(x::Float64)::Tuple{Int64, Int, Int}
123123
isinf(x) && return ifelse(x < 0, -1, 1), 0, 0
124124
n = reinterpret(UInt64, x)
125125
s = (n & 0x000fffffffffffff) % Int64
126-
e = (n & 0x7ff0000000000000 >> 52) % Int
126+
e = ((n & 0x7ff0000000000000) >> 52) % Int
127127
s |= Int64(e != 0) << 52
128128
d = ifelse(signbit(x), -1, 1)
129129
s, e - 1075 + (e == 0), d

0 commit comments

Comments
 (0)