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

remove 0.5 syntax deprecation warnings #20327

Merged
merged 3 commits into from
Feb 5, 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 @@ -166,6 +166,9 @@ This section lists changes that do not have deprecation warnings.
that internally uses twice-precision arithmetic. These two
outcomes exhibit differences in both precision and speed.

* `A=>B` expressions are now parsed as calls instead of using `=>` as the
expression head ([#20327]).

* The `count` function no longer sums non-boolean values ([#20404])

Library improvements
Expand Down
9 changes: 3 additions & 6 deletions base/show.jl
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ const uni_ops = Set{Symbol}([:(+), :(-), :(!), :(¬), :(~), :(<:), :(>:), :(√)
const expr_infix_wide = Set{Symbol}([
:(=), :(+=), :(-=), :(*=), :(/=), :(\=), :(^=), :(&=), :(|=), :(÷=), :(%=), :(>>>=), :(>>=), :(<<=),
:(.=), :(.+=), :(.-=), :(.*=), :(./=), :(.\=), :(.^=), :(.&=), :(.|=), :(.÷=), :(.%=), :(.>>>=), :(.>>=), :(.<<=),
:(&&), :(||), :(<:), :(=>), :($=), :(⊻=)]) # `$=` should be removed after deprecation is removed, issue #18977
:(&&), :(||), :(<:), :($=), :(⊻=)]) # `$=` should be removed after deprecation is removed, issue #18977
const expr_infix = Set{Symbol}([:(:), :(->), Symbol("::")])
const expr_infix_any = union(expr_infix, expr_infix_wide)
const all_ops = union(quoted_syms, uni_ops, expr_infix_any)
Expand Down Expand Up @@ -800,16 +800,13 @@ function show_unquoted(io::IO, ex::Expr, indent::Int, prec::Int)
show_call(io, head, ex.args[1], funcargslike, indent)

# comprehensions
elseif (head === :typed_comprehension || head === :typed_dict_comprehension) && length(args) == 2
isdict = (head === :typed_dict_comprehension)
isdict && print(io, '(')
elseif head === :typed_comprehension && length(args) == 2
show_unquoted(io, args[1], indent)
isdict && print(io, ')')
print(io, '[')
show_generator(io, args[2], indent)
print(io, ']')

elseif (head === :comprehension || head === :dict_comprehension) && length(args) == 1
elseif head === :comprehension && length(args) == 1
print(io, '[')
show_generator(io, args[1], indent)
print(io, ']')
Expand Down
2 changes: 1 addition & 1 deletion base/test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -954,7 +954,7 @@ function parse_testset_args(args)
elseif isa(arg, Expr) && arg.head == :(=)
# we're building up a Dict literal here
key = Expr(:quote, arg.args[1])
push!(options.args, Expr(:(=>), key, arg.args[2]))
push!(options.args, Expr(:call, :(=>), key, arg.args[2]))
else
error("Unexpected argument $arg to @testset")
end
Expand Down
84 changes: 24 additions & 60 deletions src/julia-parser.scm
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
; operators that are special forms, not function names
(define syntactic-operators
(append! (add-dots '(= += -= *= /= //= |\\=| ^= ÷= %= <<= >>= >>>= |\|=| &= ⊻=))
'(:= --> $= => && |\|\|| |.| ... ->)))
'(:= --> $= && |\|\|| |.| ... ->)))
(define syntactic-unary-operators '($ & |::|))

(define syntactic-op? (Set syntactic-operators))
Expand Down Expand Up @@ -123,9 +123,6 @@

(define reserved-word? (Set reserved-words))

(define (dict-literal? l)
(and (length= l 3) (eq? (car l) '=>)))

;; Parser state variables

; disable range colon for parsing ternary conditional operator
Expand Down Expand Up @@ -755,7 +752,9 @@
(begin (ts:put-back! s t)
ex)
(list 'call t ex (parse-assignment s down)))
(list t ex (parse-assignment s down)))))))
(if (eq? t '=>) ;; ~ and => are the only non-syntactic assignment-precedence operators
(list 'call t ex (parse-assignment s down))
(list t ex (parse-assignment s down))))))))

(define (parse-eq s)
(let ((lno (input-port-line (ts:port s))))
Expand Down Expand Up @@ -895,9 +894,7 @@
(else ex))))

(define (invalid-identifier-name? ex)
;; TODO: remove this hack when we remove the special Dict syntax
(or (and (not (eq? ex '=>)) (syntactic-op? ex))
(eq? ex '....)))
(or (syntactic-op? ex) (eq? ex '....)))

(define (parse-unary s)
(let ((t (require-token s)))
Expand Down Expand Up @@ -999,11 +996,6 @@
(parse-where-chain s decl-sig)
decl-sig)))

(define (deprecated-dict-replacement ex)
(if (dict-literal? ex)
(string "Dict{" (deparse (cadr ex)) #\, (deparse (caddr ex)) "}")
"Dict"))

(define (disallowed-space ex t)
(error (string "space before \"" t "\" not allowed in \""
(deparse ex) " " (deparse t) "\"")))
Expand Down Expand Up @@ -1054,7 +1046,7 @@
;; ref is syntax, so we can distinguish
;; a[i] = x from
;; ref(a,i) = x
(let ((al (with-end-symbol (parse-cat s #\] (dict-literal? ex)))))
(let ((al (with-end-symbol (parse-cat s #\]))))
(if (null? al)
(loop (list 'ref ex))
(case (car al)
Expand All @@ -1064,11 +1056,6 @@
(loop (list* 'typed_vcat ex (cdr al))))
((comprehension)
(loop (list* 'typed_comprehension ex (cdr al))))
((dict_comprehension)
(syntax-deprecation
s (string #\( (deparse ex) #\) "[a=>b for (a,b) in c]")
(string (deprecated-dict-replacement ex) "(a=>b for (a,b) in c)"))
(loop (list* 'typed_dict_comprehension ex (cdr al))))
(else (error "unknown parse-cat result (internal error)"))))))
((|.|)
(if (ts:space? s) (disallowed-space ex t))
Expand Down Expand Up @@ -1177,8 +1164,7 @@

((if)
(if (newline? (peek-token s))
(syntax-deprecation s "if with line break before condition" "")
#;(error (string "missing condition in \"if\" at " current-filename
(error (string "missing condition in \"if\" at " current-filename
":" (- (input-port-line (ts:port s)) 1))))
(let* ((test (parse-cond s))
(then (if (memq (require-token s) '(else elseif))
Expand Down Expand Up @@ -1462,8 +1448,7 @@

;; as above, but allows both "i=r" and "i in r"
(define (parse-iteration-spec s)
(let* ((paren? (eqv? (require-token s) #\())
(lhs (parse-pipes s))
(let* ((lhs (parse-pipes s))
(t (peek-token s)))
(cond ((memq t '(= in ∈))
(take-token s)
Expand All @@ -1476,13 +1461,6 @@
`(= ,lhs ,rhs)))
((and (eq? lhs ':) (closing-token? t))
':)
((and paren? (length= lhs 4) (eq? (car lhs) 'call)
(memq (cadr lhs) '(in ∈)))
(syntax-deprecation s "for (...)" "for ...")
`(= ,@(cddr lhs)))
((and paren? (length= lhs 3) (eq? (car lhs) '=))
(syntax-deprecation s "for (...)" "for ...")
lhs)
(else (error "invalid iteration specification")))))

(define (parse-comma-separated-iters s)
Expand Down Expand Up @@ -1602,12 +1580,6 @@
(take-token s))
`(comprehension ,gen))))

(define (parse-dict-comprehension s first closer)
(let ((c (parse-comprehension s first closer)))
(if (dict-literal? (cadr (cadr c)))
`(dict_comprehension ,@(cdr c))
(error "invalid dict comprehension"))))

(define (parse-matrix s first closer gotnewline)
(define (fix head v) (cons head (reverse v)))
(define (update-outer v outer)
Expand Down Expand Up @@ -1653,32 +1625,26 @@
(loop (peek-token s)))
t)))

(define (parse-cat s closer . isdict)
(define (parse-cat s closer)
(with-normal-ops
(with-inside-vec
(if (eqv? (require-token s) closer)
(begin (take-token s)
'())
(let ((first (parse-eq* s)))
(if (and (dict-literal? first)
(or (null? isdict) (car isdict))
(eq? (peek-non-newline-token s) 'for))
(begin
(take-token s)
(parse-dict-comprehension s first closer))
(let ((t (peek-token s)))
(cond ((or (eqv? t #\,) (eqv? t closer))
(parse-vect s first closer))
((eq? t 'for)
(take-token s)
(parse-comprehension s first closer))
((eqv? t #\newline)
(take-token s)
(if (memv (peek-token s) (list #\, closer))
(parse-vect s first closer)
(parse-matrix s first closer #t)))
(else
(parse-matrix s first closer #f))))))))))
(let* ((first (parse-eq* s))
(t (peek-token s)))
(cond ((or (eqv? t #\,) (eqv? t closer))
(parse-vect s first closer))
((eq? t 'for)
(take-token s)
(parse-comprehension s first closer))
((eqv? t #\newline)
(take-token s)
(if (memv (peek-token s) (list #\, closer))
(parse-vect s first closer)
(parse-matrix s first closer #t)))
(else
(parse-matrix s first closer #f))))))))

(define (kw-to-= e) (if (kwarg? e) (cons '= (cdr e)) e))
(define (=-to-kw e) (if (assignment? e) (cons 'kw (cdr e)) e))
Expand Down Expand Up @@ -2042,15 +2008,13 @@
(if (eqv? (require-token s) #\})
(begin (take-token s)
'(cell1d))
(let ((vex (parse-cat s #\} #t)))
(let ((vex (parse-cat s #\})))
(if (null? vex)
'(cell1d)
(case (car vex)
((vect) `(cell1d ,@(cdr vex)))
((hcat) `(cell2d 1 ,(length (cdr vex)) ,@(cdr vex)))
((comprehension) (error "{a for a in b} syntax is discontinued"))
((dict_comprehension) (error "{a=>b for (a,b) in c} syntax is discontinued"))
((dict) `(cell1d ,@(cdr vec)))
(else
(if (and (pair? (cadr vex)) (eq? (caadr vex) 'row))
(let ((nr (length (cdr vex)))
Expand Down
63 changes: 13 additions & 50 deletions src/julia-syntax.scm
Original file line number Diff line number Diff line change
Expand Up @@ -275,10 +275,6 @@
(and (symbol? s)
(eqv? (string.char (string s) 0) #\#)))

(define (is-call-name? name)
(or (eq? name 'call) (and (pair? name) (sym-ref? name)
(equal? (caddr name) '(inert call)))))

(define (replace-vars e renames)
(cond ((symbol? e) (lookup e renames e))
((or (not (pair? e)) (quoted? e)) e)
Expand Down Expand Up @@ -331,9 +327,7 @@
(error "function argument and static parameter names must be distinct")))
(if (or (and name (not (sym-ref? name))) (eq? name 'true) (eq? name 'false))
(error (string "invalid function name \"" (deparse name) "\"")))
(let* ((iscall (is-call-name? name))
(name (if iscall #f name))
(types (llist-types argl))
(let* ((types (llist-types argl))
(body (method-lambda-expr argl body rett))
;; HACK: the typevars need to be bound to ssavalues, since this code
;; might be moved to a different scope by closure-convert.
Expand Down Expand Up @@ -364,13 +358,6 @@
types)))
(call (core svec) ,@temps)))
,body ,isstaged))))
(if (and iscall (not (null? argl)))
(let* ((n (arg-name (car argl)))
(n (if (hidden-name? n) "" n))
(t (deparse (arg-type (car argl)))))
(syntax-deprecation #f
(string "call(" n "::" t ", ...)")
(string "(" n "::" t ")(...)"))))
(if (symbol? name)
`(block (method ,name) ,mdef (unnecessary ,name)) ;; return the function
mdef)))))
Expand Down Expand Up @@ -554,7 +541,7 @@
(list `(... ,(arg-name (car vararg))))))))
#f)
;; return primary function
,(if (or (not (symbol? name)) (is-call-name? name))
,(if (not (symbol? name))
'(null) name)))))

;; prologue includes line number node and eventual meta nodes
Expand Down Expand Up @@ -1803,13 +1790,8 @@
(eq? (car (cadr e)) 'line))))
(expand-forms (cadr e)))
(else
`(block
,.(map (lambda (x)
(if (and (decl? x) (length= (cdr x) 2) (symbol? (cadr x)))
`(impl-decl ,@(map expand-forms (cdr x)))
(expand-forms x)))
(butlast (cdr e)))
,(expand-forms (last (cdr e)))))))
(cons 'block
(map expand-forms (cdr e))))))

'|.|
(lambda (e) ; e = (|.| f x)
Expand Down Expand Up @@ -2088,9 +2070,6 @@
(error "assignment not allowed inside tuple"))
(expand-forms `(call (core tuple) ,@(cdr e))))

'=>
(lambda (e) `(call => ,(expand-forms (cadr e)) ,(expand-forms (caddr e))))

'cell1d (lambda (e) (error "{ } vector syntax is discontinued"))
'cell2d (lambda (e) (error "{ } matrix syntax is discontinued"))

Expand Down Expand Up @@ -2302,17 +2281,7 @@
;; TODO: this is a hack to lower simple comprehensions to loops very
;; early, to greatly reduce the # of functions and load on the compiler
(lower-comprehension (cadr e) (cadr (caddr e)) ranges))))
`(call (top collect) ,(cadr e) ,(caddr e)))))

'dict_comprehension
(lambda (e)
(syntax-deprecation #f "[a=>b for (a,b) in c]" "Dict(a=>b for (a,b) in c)")
(expand-forms `(call (top Dict) ,(cadr e))))

'typed_dict_comprehension
(lambda (e) (expand-forms
`(call (call (core apply_type) (top Dict) ,@(cdr (cadr e)))
,(caddr e))))))
`(call (top collect) ,(cadr e) ,(caddr e)))))))

(define (lower-comprehension atype expr ranges)
(let ((result (make-ssavalue))
Expand Down Expand Up @@ -2644,7 +2613,7 @@
(vinfo:set-called! vi #t))
(for-each (lambda (x) (analyze-vars x env captvars sp))
(cdr e))))
((decl impl-decl)
((decl)
;; handle var::T declaration by storing the type in the var-info
;; record. for non-symbols or globals, emit a type assertion.
(let ((vi (var-info-for (cadr e) env)))
Expand Down Expand Up @@ -3182,21 +3151,15 @@ f(x) = yt(x)
(cl-convert `(call (core typeassert) ,@(cdr e)) fname lam namemap toplevel interp))
;; remaining `decl` expressions are only type assertions if the
;; argument is global or a non-symbol.
((impl-decl)
(if (or (assq (cadr e) (car (lam:vinfo lam)))
(assq (cadr e) (cadr (lam:vinfo lam))))
(let ((str-e (deparse `(|::| ,@(cdr e)))))
(syntax-deprecation #f str-e (string "local " str-e))
'(null))
(cl-convert `(call (core typeassert) ,@(cdr e)) fname lam namemap toplevel interp)))
((decl)
(cond ((not (symbol? (cadr e)))
(cl-convert `(call (core typeassert) ,@(cdr e)) fname lam namemap toplevel interp))
((or (assq (cadr e) (car (lam:vinfo lam)))
(assq (cadr e) (cadr (lam:vinfo lam))))
(cond ((and (symbol? (cadr e))
(or (assq (cadr e) (car (lam:vinfo lam)))
(assq (cadr e) (cadr (lam:vinfo lam)))))
'(null))
(else (syntax-deprecation #f (string "global " (deparse `(|::| ,@(cdr e)))) "typeassert")
(cl-convert `(call (core typeassert) ,@(cdr e)) fname lam namemap toplevel interp))))
(else
(if (or (symbol? (cadr e)) (and (pair? (cadr e)) (eq? (caadr e) 'outerref)))
(error "type declarations on global variables are not yet supported"))
(cl-convert `(call (core typeassert) ,@(cdr e)) fname lam namemap toplevel interp))))
;; `with-static-parameters` expressions can be removed now; used only by analyze-vars
((with-static-parameters)
(cl-convert (cadr e) fname lam namemap toplevel interp))
Expand Down
14 changes: 14 additions & 0 deletions test/core.jl
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,20 @@ end
z = convert(Complex{Float64},2)
@test z == Complex(2.0,0.0)

function typeassert_instead_of_decl()
local x
x = 1
x::Float64
return 0
end
@test_throws TypeError typeassert_instead_of_decl()

# type declarations on globals not implemented yet
@test_throws ErrorException eval(parse("global x20327::Int"))

y20327 = 1
@test_throws TypeError y20327::Float64

# misc
fib(n) = n < 2 ? n : fib(n-1) + fib(n-2)
@test fib(20) == 6765
Expand Down
Loading