diff --git a/NEWS.md b/NEWS.md index 978838ee128a6..88e952d3ad429 100644 --- a/NEWS.md +++ b/NEWS.md @@ -19,6 +19,9 @@ Language changes * Declaring arguments as `x::ANY` to avoid specialization has been replaced by `@nospecialize x`. ([#22666]). + * The parsing of `1<<2*3` as `1<<(2*3)` is deprecated, and will change to + `(1<<2)*3` in a future version ([#13079]). + Breaking changes ---------------- diff --git a/base/deprecated.jl b/base/deprecated.jl index 51d9cd4e63fff..6d6cb80788759 100644 --- a/base/deprecated.jl +++ b/base/deprecated.jl @@ -1563,6 +1563,12 @@ end # ::ANY is deprecated in src/method.c # also remove all instances of `jl_ANY_flag` in src/ +# issue #13079 +# in julia-parser.scm: +# move prec-bitshift after prec-rational +# remove parse-with-chains-warn and bitshift-warn +# update precedence table in doc/src/manual/mathematical-operations.md + # PR #22182 @deprecate is_apple Sys.isapple @deprecate is_bsd Sys.isbsd diff --git a/base/dict.jl b/base/dict.jl index e78a99a32d30b..e0ddcaaee649e 100644 --- a/base/dict.jl +++ b/base/dict.jl @@ -271,7 +271,7 @@ function rehash!(h::Dict{K,V}, newsz = length(h.keys)) where V where K end max_values(::Type) = typemax(Int) -max_values(T::Type{<:Union{Void,BitIntegerSmall}}) = 1 << 8*sizeof(T) +max_values(T::Type{<:Union{Void,BitIntegerSmall}}) = 1 << (8*sizeof(T)) max_values(T::Union) = max(max_values(T.a), max_values(T.b)) max_values(::Type{Bool}) = 2 diff --git a/base/grisu/fastshortest.jl b/base/grisu/fastshortest.jl index f9009a7703753..c7b70dea84acc 100644 --- a/base/grisu/fastshortest.jl +++ b/base/grisu/fastshortest.jl @@ -55,7 +55,7 @@ const SmallPowersOfTen = [ 1000000, 10000000, 100000000, 1000000000] function bigpowten(n,n_bits) - guess = (n_bits + 1) * 1233 >> 12 + guess = ((n_bits + 1) * 1233) >> 12 guess += 1 i = SmallPowersOfTen[guess+1] return n < i ? (SmallPowersOfTen[guess], guess-1) : (i,guess) diff --git a/base/multinverses.jl b/base/multinverses.jl index d436860f14506..319072e7214ac 100644 --- a/base/multinverses.jl +++ b/base/multinverses.jl @@ -135,12 +135,12 @@ end UnsignedMultiplicativeInverse(x::Unsigned) = UnsignedMultiplicativeInverse{typeof(x)}(x) function div(a::T, b::SignedMultiplicativeInverse{T}) where T - x = ((widen(a)*b.multiplier) >>> sizeof(a)*8) % T + x = ((widen(a)*b.multiplier) >>> (sizeof(a)*8)) % T x += (a*b.addmul) % T ifelse(abs(b.divisor) == 1, a*b.divisor, (signbit(x) + (x >> b.shift)) % T) end function div(a::T, b::UnsignedMultiplicativeInverse{T}) where T - x = ((widen(a)*b.multiplier) >>> sizeof(a)*8) % T + x = ((widen(a)*b.multiplier) >>> (sizeof(a)*8)) % T x = ifelse(b.add, convert(T, convert(T, (convert(T, a - x) >>> 1)) + x), x) ifelse(b.divisor == 1, a, x >>> b.shift) end diff --git a/base/random.jl b/base/random.jl index 79c2e5cdb4987..9aa296a3e0c29 100644 --- a/base/random.jl +++ b/base/random.jl @@ -614,7 +614,7 @@ function rand!(r::MersenneTwister, A::Array{UInt128}, n::Int=length(A)) if n > 0 u = rand_ui2x52_raw(r) for i = 1:n - @inbounds A[i] ⊻= u << 12*i + @inbounds A[i] ⊻= u << (12*i) end end A diff --git a/src/julia-parser.scm b/src/julia-parser.scm index dc142f5b5f6ea..60d6bcd5f167b 100644 --- a/src/julia-parser.scm +++ b/src/julia-parser.scm @@ -865,9 +865,48 @@ (else (loop (list 'call t ex (down s)))))))))) +(define (parse-with-chains-warn s down ops chain-ops) + (let loop ((ex (down s)) + (got #f)) + (let ((t (peek-token s))) + (if (not (ops t)) + (cons ex got) + (let ((spc (ts:space? s))) + (take-token s) + (cond ((and space-sensitive spc (memq t unary-and-binary-ops) + (not (eqv? (peek-char (ts:port s)) #\ ))) + ;; here we have "x -y" + (ts:put-back! s t spc) + (cons ex got)) + ((memq t chain-ops) + (loop (list* 'call t ex + (parse-chain s down t)) + #t)) + (else + (loop (list 'call t ex (down s)) + got)))))))) + (define (parse-expr s) (parse-with-chains s parse-shift is-prec-plus? '(+ ++))) -(define (parse-shift s) (parse-LtoR s parse-term is-prec-bitshift?)) -(define (parse-term s) (parse-with-chains s parse-rational is-prec-times? '(*))) + +(define (bitshift-warn s) + (syntax-deprecation s (string "call to `*` inside call to bitshift operator") + "parenthesized call to `*`")) + +(define (parse-shift s) #;(parse-LtoR s parse-term is-prec-bitshift?) + (let loop ((ex (parse-term s)) + (t (peek-token s)) + (warn1 #f)) + (let ((ex (car ex)) + (warn (cdr ex))) + (if (is-prec-bitshift? t) + (begin (if warn (bitshift-warn s)) + (take-token s) + (let ((nxt (parse-term s))) + (loop (cons (list 'call t ex (car nxt)) (cdr nxt)) (peek-token s) (cdr nxt)))) + (begin (if warn1 (bitshift-warn s)) + ex))))) + +(define (parse-term s) (parse-with-chains-warn s parse-rational is-prec-times? '(*))) (define (parse-rational s) (parse-LtoR s parse-unary-subtype is-prec-rational?)) ;; parse `<: A where B` as `<: (A where B)` (issue #21545)