Skip to content

Commit

Permalink
deprecate precedence of & and |. for #5187
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffBezanson committed Dec 29, 2017
1 parent ea5b0a3 commit 5f3474e
Show file tree
Hide file tree
Showing 34 changed files with 227 additions and 202 deletions.
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ Language changes
* The parsing of `1<<2*3` as `1<<(2*3)` is deprecated, and will change to
`(1<<2)*3` in a future version ([#13079]).

* The precedence of `&` and `|` is deprecated, and will change to match that of
`&&` and `||`. In the meantime, such expressions should be parenthesized ([#5187]).

* The parsing of `<|` is now right associative. `|>` remains left associative ([#24153]).

* `{ }` expressions now use `braces` and `bracescat` as expression heads instead
Expand Down
24 changes: 12 additions & 12 deletions base/bitarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ dumpbitcache(Bc::Vector{UInt64}, bind::Int, C::Vector{Bool}) =

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

## similar, fill!, copy! etc ##
Expand Down Expand Up @@ -702,7 +702,7 @@ function _unsafe_setindex!(B::BitArray, X::AbstractArray, I::BitArray)
@inbounds C = Bc[i]
u = UInt64(1)
for j = 1:(i < lc ? 64 : last_chunk_len)
if Imsk & u != 0
if (Imsk & u) != 0
lx < c && throw_setindex_mismatch(X, c)
@inbounds x = convert(Bool, X[c])
C = ifelse(x, C | u, C & ~u)
Expand Down Expand Up @@ -1068,7 +1068,7 @@ function (-)(B::BitArray)
u = UInt64(1)
c = Bc[i]
for j = 1:64
if c & u != 0
if (c & u) != 0
A[ind] = -1
end
ind += 1
Expand All @@ -1078,7 +1078,7 @@ function (-)(B::BitArray)
u = UInt64(1)
c = Bc[end]
for j = 0:_mod64(l-1)
if c & u != 0
if (c & u) != 0
A[ind] = -1
end
ind += 1
Expand Down Expand Up @@ -1449,7 +1449,7 @@ function unsafe_bitfindnext(Bc::Vector{UInt64}, start::Integer)
mask = _msk64 << within_chunk_start

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

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

@inbounds if chunk_start < l
if Bc[chunk_start] | mask != _msk64
if (Bc[chunk_start] | mask) != _msk64
return (chunk_start-1) << 6 + trailing_ones(Bc[chunk_start] | mask) + 1
end
for i = chunk_start+1:l-1
Expand All @@ -1496,7 +1496,7 @@ function findnextnot(B::BitArray, start::Integer)
if Bc[l] != _msk_end(B)
return (l-1) << 6 + trailing_ones(Bc[l]) + 1
end
elseif Bc[l] | mask != _msk_end(B)
elseif (Bc[l] | mask) != _msk_end(B)
return (l-1) << 6 + trailing_ones(Bc[l] | mask) + 1
end
return 0
Expand Down Expand Up @@ -1530,7 +1530,7 @@ function unsafe_bitfindprev(Bc::Vector{UInt64}, start::Integer)
mask = _msk_end(start)

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

Expand Down Expand Up @@ -1560,7 +1560,7 @@ function findprevnot(B::BitArray, start::Integer)
mask = ~_msk_end(start)

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

Expand Down Expand Up @@ -1608,7 +1608,7 @@ function find(B::BitArray)
u = UInt64(1)
c = Bc[i]
for j = 1:64
if c & u != 0
if (c & u) != 0
I[Icount] = Bcount
Icount += 1
end
Expand All @@ -1619,7 +1619,7 @@ function find(B::BitArray)
u = UInt64(1)
c = Bc[end]
for j = 0:_mod64(l-1)
if c & u != 0
if (c & u) != 0
I[Icount] = Bcount
Icount += 1
end
Expand Down Expand Up @@ -1839,7 +1839,7 @@ function read!(s::IO, B::BitArray)
n = length(B)
Bc = B.chunks
nc = length(read!(s, Bc))
if length(Bc) > 0 && Bc[end] & _msk_end(n) Bc[end]
if length(Bc) > 0 && (Bc[end] & _msk_end(n)) Bc[end]
Bc[end] &= _msk_end(n) # ensure that the BitArray is not broken
throw(DimensionMismatch("read mismatch, found non-zero bits after BitArray length"))
end
Expand Down
4 changes: 2 additions & 2 deletions base/c.jl
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ function transcode(::Type{UInt8}, src::Vector{UInt16})
m += 1
elseif a < 0x800 # 2-byte UTF-8
m += 2
elseif a & 0xfc00 == 0xd800 && i < length(src)
elseif (a & 0xfc00) == 0xd800 && i < length(src)
b = src[i += 1]
if (b & 0xfc00) == 0xdc00 # 2-unit UTF-16 sequence => 4-byte UTF-8
m += 4
Expand All @@ -307,7 +307,7 @@ function transcode(::Type{UInt8}, src::Vector{UInt16})
elseif a < 0x800 # 2-byte UTF-8
dst[j += 1] = 0xc0 | ((a >> 6) % UInt8)
dst[j += 1] = 0x80 | ((a % UInt8) & 0x3f)
elseif a & 0xfc00 == 0xd800 && i < n
elseif (a & 0xfc00) == 0xd800 && i < n
b = src[i += 1]
if (b & 0xfc00) == 0xdc00
# 2-unit UTF-16 sequence => 4-byte UTF-8
Expand Down
4 changes: 2 additions & 2 deletions base/char.jl
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ function UInt32(c::Char)
malformed_char(c)::Union{}
u &= 0xffffffff >> l1
u >>= t0
(u & 0x0000007f >> 0) | (u & 0x00007f00 >> 2) |
(u & 0x007f0000 >> 4) | (u & 0x7f000000 >> 6)
((u & 0x0000007f) >> 0) | ((u & 0x00007f00) >> 2) |
((u & 0x007f0000) >> 4) | ((u & 0x7f000000) >> 6)
end

function Char(u::UInt32)
Expand Down
5 changes: 3 additions & 2 deletions base/deprecated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1429,10 +1429,11 @@ end
# ::ANY is deprecated in src/method.c
# also remove all instances of `jl_ANY_flag` in src/

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

# deprecate remaining vectorized methods over SparseVectors (zero-preserving)
Expand Down
2 changes: 1 addition & 1 deletion base/filesystem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ function read(f::File, ::Type{Char})
while s l && !eof(f)
p = position(f)
b = read(f, UInt8)
if b & 0xc0 != 0x80
if (b & 0xc0) != 0x80
seek(f, p)
break
end
Expand Down
64 changes: 32 additions & 32 deletions base/float.jl
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ function Float64(x::Int128)
y &= ~UInt64(trailing_zeros(x) == (n-54)) # fix last bit to round to even
end
d = ((n+1022) % UInt64) << 52
reinterpret(Float64, s | d + y)
reinterpret(Float64, (s | d) + y)
end

function Float32(x::UInt128)
Expand Down Expand Up @@ -131,7 +131,7 @@ function Float32(x::Int128)
y &= ~UInt32(trailing_zeros(x) == (n-25)) # fix last bit to round to even
end
d = ((n+126) % UInt32) << 23
reinterpret(Float32, s | d + y)
reinterpret(Float32, (s | d) + y)
end

function Float16(val::Float32)
Expand All @@ -140,7 +140,7 @@ function Float16(val::Float32)
t = 0x8000 (0x8000 & ((f >> 0x10) % UInt16))
return reinterpret(Float16, t ((f >> 0xd) % UInt16))
end
i = (f >> 23) & 0x1ff + 1
i = ((f >> 23) & 0x1ff) + 1
sh = shifttable[i]
f &= 0x007fffff
h::UInt16 = basetable[i] + (f >> sh)
Expand All @@ -150,7 +150,7 @@ function Float16(val::Float32)
nextbit = (f >> (sh-1)) & 1
if nextbit != 0
# Round halfway to even or check lower bits
if h&1 == 1 || (f & ((1<<(sh-1))-1)) != 0
if (h&1) == 1 || (f & ((1<<(sh-1))-1)) != 0
h += 1
end
end
Expand Down Expand Up @@ -209,30 +209,30 @@ const shifttable = Vector{UInt8}(uninitialized, 512)
for i = 0:255
e = i - 127
if e < -24 # Very small numbers map to zero
basetable[i|0x000+1] = 0x0000
basetable[i|0x100+1] = 0x8000
shifttable[i|0x000+1] = 24
shifttable[i|0x100+1] = 24
basetable[(i|0x000)+1] = 0x0000
basetable[(i|0x100)+1] = 0x8000
shifttable[(i|0x000)+1] = 24
shifttable[(i|0x100)+1] = 24
elseif e < -14 # Small numbers map to denorms
basetable[i|0x000+1] = (0x0400>>(-e-14))
basetable[i|0x100+1] = (0x0400>>(-e-14)) | 0x8000
shifttable[i|0x000+1] = -e-1
shifttable[i|0x100+1] = -e-1
basetable[(i|0x000)+1] = (0x0400>>(-e-14))
basetable[(i|0x100)+1] = (0x0400>>(-e-14)) | 0x8000
shifttable[(i|0x000)+1] = -e-1
shifttable[(i|0x100)+1] = -e-1
elseif e <= 15 # Normal numbers just lose precision
basetable[i|0x000+1] = ((e+15)<<10)
basetable[i|0x100+1] = ((e+15)<<10) | 0x8000
shifttable[i|0x000+1] = 13
shifttable[i|0x100+1] = 13
basetable[(i|0x000)+1] = ((e+15)<<10)
basetable[(i|0x100)+1] = ((e+15)<<10) | 0x8000
shifttable[(i|0x000)+1] = 13
shifttable[(i|0x100)+1] = 13
elseif e < 128 # Large numbers map to Infinity
basetable[i|0x000+1] = 0x7C00
basetable[i|0x100+1] = 0xFC00
shifttable[i|0x000+1] = 24
shifttable[i|0x100+1] = 24
basetable[(i|0x000)+1] = 0x7C00
basetable[(i|0x100)+1] = 0xFC00
shifttable[(i|0x000)+1] = 24
shifttable[(i|0x100)+1] = 24
else # Infinity and NaN's stay Infinity and NaN's
basetable[i|0x000+1] = 0x7C00
basetable[i|0x100+1] = 0xFC00
shifttable[i|0x000+1] = 13
shifttable[i|0x100+1] = 13
basetable[(i|0x000)+1] = 0x7C00
basetable[(i|0x100)+1] = 0xFC00
shifttable[(i|0x000)+1] = 13
shifttable[(i|0x100)+1] = 13
end
end

Expand Down Expand Up @@ -309,7 +309,7 @@ end

function unsafe_trunc(::Type{UInt128}, x::Float64)
xu = reinterpret(UInt64,x)
k = Int(xu >> 52) & 0x07ff - 1075
k = (Int(xu >> 52) & 0x07ff) - 1075
xu = (xu & 0x000f_ffff_ffff_ffff) | 0x0010_0000_0000_0000
if k <= 0
UInt128(xu >> -k)
Expand All @@ -323,7 +323,7 @@ end

function unsafe_trunc(::Type{UInt128}, x::Float32)
xu = reinterpret(UInt32,x)
k = Int(xu >> 23) & 0x00ff - 150
k = (Int(xu >> 23) & 0x00ff) - 150
xu = (xu & 0x007f_ffff) | 0x0080_0000
if k <= 0
UInt128(xu >> -k)
Expand Down Expand Up @@ -435,10 +435,10 @@ end
function ==(x::Float16, y::Float16)
ix = reinterpret(UInt16,x)
iy = reinterpret(UInt16,y)
if (ix|iy)&0x7fff > 0x7c00 #isnan(x) || isnan(y)
if ((ix|iy)&0x7fff) > 0x7c00 #isnan(x) || isnan(y)
return false
end
if (ix|iy)&0x7fff == 0x0000
if ((ix|iy)&0x7fff) == 0x0000
return true
end
return ix == iy
Expand Down Expand Up @@ -539,7 +539,7 @@ abs(x::Float64) = abs_float(x)
Test whether a floating point number is not a number (NaN).
"""
isnan(x::AbstractFloat) = x != x
isnan(x::Float16) = reinterpret(UInt16,x)&0x7fff > 0x7c00
isnan(x::Float16) = (reinterpret(UInt16,x) & 0x7fff) > 0x7c00
isnan(x::Real) = false

"""
Expand All @@ -556,7 +556,7 @@ false
```
"""
isfinite(x::AbstractFloat) = x - x == 0
isfinite(x::Float16) = reinterpret(UInt16,x)&0x7c00 != 0x7c00
isfinite(x::Float16) = (reinterpret(UInt16,x) & 0x7c00) != 0x7c00
isfinite(x::Real) = decompose(x)[3] != 0
isfinite(x::Integer) = true

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

@eval begin
Expand Down Expand Up @@ -873,7 +873,7 @@ uinttype(::Type{Float64}) = UInt64
uinttype(::Type{Float32}) = UInt32
uinttype(::Type{Float16}) = UInt16

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

## Array operations on floating point numbers ##

Expand Down
2 changes: 1 addition & 1 deletion base/gmp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ function BigInt(x::Integer)
end


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

rem(x::BigInt, ::Type{T}) where T<:Union{SLimbMax,ULimbMax} =
iszero(x) ? zero(T) : flipsign(unsafe_load(x.d) % T, x.size)
Expand Down
2 changes: 1 addition & 1 deletion base/grisu/bignums.jl
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ function assignpoweruint16!(x::Bignum,base::UInt16,power_exponent::Int)
end
zero!(x)
shifts::Int = 0
while base & UInt16(1) == UInt16(0)
while (base & UInt16(1)) == UInt16(0)
base >>= UInt16(1)
shifts += 1
end
Expand Down
6 changes: 3 additions & 3 deletions base/hashing2.jl
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ function decompose(x::Float16)::NTuple{3,Int}
isinf(x) && return ifelse(x < 0, -1, 1), 0, 0
n = reinterpret(UInt16, x)
s = (n & 0x03ff) % Int16
e = (n & 0x7c00 >> 10) % Int
e = ((n & 0x7c00) >> 10) % Int
s |= Int16(e != 0) << 10
d = ifelse(signbit(x), -1, 1)
s, e - 25 + (e == 0), d
Expand All @@ -112,7 +112,7 @@ function decompose(x::Float32)::NTuple{3,Int}
isinf(x) && return ifelse(x < 0, -1, 1), 0, 0
n = reinterpret(UInt32, x)
s = (n & 0x007fffff) % Int32
e = (n & 0x7f800000 >> 23) % Int
e = ((n & 0x7f800000) >> 23) % Int
s |= Int32(e != 0) << 23
d = ifelse(signbit(x), -1, 1)
s, e - 150 + (e == 0), d
Expand All @@ -123,7 +123,7 @@ function decompose(x::Float64)::Tuple{Int64, Int, Int}
isinf(x) && return ifelse(x < 0, -1, 1), 0, 0
n = reinterpret(UInt64, x)
s = (n & 0x000fffffffffffff) % Int64
e = (n & 0x7ff0000000000000 >> 52) % Int
e = ((n & 0x7ff0000000000000) >> 52) % Int
s |= Int64(e != 0) << 52
d = ifelse(signbit(x), -1, 1)
s, e - 1075 + (e == 0), d
Expand Down
Loading

0 comments on commit 5f3474e

Please sign in to comment.