Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RFC: deprecate parsing * inside <<. part of #13079 #22859

Merged
merged 1 commit into from
Jul 20, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
----------------

Expand Down
6 changes: 6 additions & 0 deletions base/deprecated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion base/dict.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion base/grisu/fastshortest.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions base/multinverses.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion base/random.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
43 changes: 41 additions & 2 deletions src/julia-parser.scm
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down