Skip to content

Commit 96f2815

Browse files
committed
deprecate parsing * inside <<. part of #13079
1 parent 88435c0 commit 96f2815

7 files changed

+55
-7
lines changed

NEWS.md

+3
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ Language changes
1919
* Declaring arguments as `x::ANY` to avoid specialization has been replaced
2020
by `@nospecialize x`. ([#22666]).
2121

22+
* The parsing of `1<<2*3` as `1<<(2*3)` is deprecated, and will change to
23+
`(1<<2)*3` in a future version ([#13079]).
24+
2225
Breaking changes
2326
----------------
2427

base/deprecated.jl

+6
Original file line numberDiff line numberDiff line change
@@ -1581,6 +1581,12 @@ end
15811581

15821582
@deprecate String(io::GenericIOBuffer) String(take!(copy(io)))
15831583

1584+
# issue #13079
1585+
# in julia-parser.scm:
1586+
# move prec-bitshift after prec-rational
1587+
# remove parse-with-chains-warn and bitshift-warn
1588+
# update precedence table in doc/src/manual/mathematical-operations.md
1589+
15841590
# END 0.7 deprecations
15851591

15861592
# BEGIN 1.0 deprecations

base/dict.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ function rehash!(h::Dict{K,V}, newsz = length(h.keys)) where V where K
271271
end
272272

273273
max_values(::Type) = typemax(Int)
274-
max_values(T::Type{<:Union{Void,BitIntegerSmall}}) = 1 << 8*sizeof(T)
274+
max_values(T::Type{<:Union{Void,BitIntegerSmall}}) = 1 << (8*sizeof(T))
275275
max_values(T::Union) = max(max_values(T.a), max_values(T.b))
276276
max_values(::Type{Bool}) = 2
277277

base/grisu/fastshortest.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ const SmallPowersOfTen = [
5555
1000000, 10000000, 100000000, 1000000000]
5656

5757
function bigpowten(n,n_bits)
58-
guess = (n_bits + 1) * 1233 >> 12
58+
guess = ((n_bits + 1) * 1233) >> 12
5959
guess += 1
6060
i = SmallPowersOfTen[guess+1]
6161
return n < i ? (SmallPowersOfTen[guess], guess-1) : (i,guess)

base/multinverses.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -135,12 +135,12 @@ end
135135
UnsignedMultiplicativeInverse(x::Unsigned) = UnsignedMultiplicativeInverse{typeof(x)}(x)
136136

137137
function div(a::T, b::SignedMultiplicativeInverse{T}) where T
138-
x = ((widen(a)*b.multiplier) >>> sizeof(a)*8) % T
138+
x = ((widen(a)*b.multiplier) >>> (sizeof(a)*8)) % T
139139
x += (a*b.addmul) % T
140140
ifelse(abs(b.divisor) == 1, a*b.divisor, (signbit(x) + (x >> b.shift)) % T)
141141
end
142142
function div(a::T, b::UnsignedMultiplicativeInverse{T}) where T
143-
x = ((widen(a)*b.multiplier) >>> sizeof(a)*8) % T
143+
x = ((widen(a)*b.multiplier) >>> (sizeof(a)*8)) % T
144144
x = ifelse(b.add, convert(T, convert(T, (convert(T, a - x) >>> 1)) + x), x)
145145
ifelse(b.divisor == 1, a, x >>> b.shift)
146146
end

base/random.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -614,7 +614,7 @@ function rand!(r::MersenneTwister, A::Array{UInt128}, n::Int=length(A))
614614
if n > 0
615615
u = rand_ui2x52_raw(r)
616616
for i = 1:n
617-
@inbounds A[i] ⊻= u << 12*i
617+
@inbounds A[i] ⊻= u << (12*i)
618618
end
619619
end
620620
A

src/julia-parser.scm

+41-2
Original file line numberDiff line numberDiff line change
@@ -865,9 +865,48 @@
865865
(else
866866
(loop (list 'call t ex (down s))))))))))
867867

868+
(define (parse-with-chains-warn s down ops chain-ops)
869+
(let loop ((ex (down s))
870+
(got #f))
871+
(let ((t (peek-token s)))
872+
(if (not (ops t))
873+
(cons ex got)
874+
(let ((spc (ts:space? s)))
875+
(take-token s)
876+
(cond ((and space-sensitive spc (memq t unary-and-binary-ops)
877+
(not (eqv? (peek-char (ts:port s)) #\ )))
878+
;; here we have "x -y"
879+
(ts:put-back! s t spc)
880+
(cons ex got))
881+
((memq t chain-ops)
882+
(loop (list* 'call t ex
883+
(parse-chain s down t))
884+
#t))
885+
(else
886+
(loop (list 'call t ex (down s))
887+
got))))))))
888+
868889
(define (parse-expr s) (parse-with-chains s parse-shift is-prec-plus? '(+ ++)))
869-
(define (parse-shift s) (parse-LtoR s parse-term is-prec-bitshift?))
870-
(define (parse-term s) (parse-with-chains s parse-rational is-prec-times? '(*)))
890+
891+
(define (bitshift-warn s)
892+
(syntax-deprecation s (string "call to `*` inside call to bitshift operator")
893+
"parenthesized call to `*`"))
894+
895+
(define (parse-shift s) #;(parse-LtoR s parse-term is-prec-bitshift?)
896+
(let loop ((ex (parse-term s))
897+
(t (peek-token s))
898+
(warn1 #f))
899+
(let ((ex (car ex))
900+
(warn (cdr ex)))
901+
(if (is-prec-bitshift? t)
902+
(begin (if warn (bitshift-warn s))
903+
(take-token s)
904+
(let ((nxt (parse-term s)))
905+
(loop (cons (list 'call t ex (car nxt)) (cdr nxt)) (peek-token s) (cdr nxt))))
906+
(begin (if warn1 (bitshift-warn s))
907+
ex)))))
908+
909+
(define (parse-term s) (parse-with-chains-warn s parse-rational is-prec-times? '(*)))
871910
(define (parse-rational s) (parse-LtoR s parse-unary-subtype is-prec-rational?))
872911

873912
;; parse `<: A where B` as `<: (A where B)` (issue #21545)

0 commit comments

Comments
 (0)