Skip to content

Commit 7aab89d

Browse files
authored
Merge pull request #20327 from JuliaLang/jb/rmsyntaxdeps
remove 0.5 syntax deprecation warnings
2 parents ebeddaa + ef7046d commit 7aab89d

File tree

7 files changed

+61
-121
lines changed

7 files changed

+61
-121
lines changed

NEWS.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,9 @@ This section lists changes that do not have deprecation warnings.
166166
that internally uses twice-precision arithmetic. These two
167167
outcomes exhibit differences in both precision and speed.
168168

169+
* `A=>B` expressions are now parsed as calls instead of using `=>` as the
170+
expression head ([#20327]).
171+
169172
* The `count` function no longer sums non-boolean values ([#20404])
170173

171174
Library improvements

base/show.jl

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,7 @@ const uni_ops = Set{Symbol}([:(+), :(-), :(!), :(¬), :(~), :(<:), :(>:), :(√)
443443
const expr_infix_wide = Set{Symbol}([
444444
:(=), :(+=), :(-=), :(*=), :(/=), :(\=), :(^=), :(&=), :(|=), :(÷=), :(%=), :(>>>=), :(>>=), :(<<=),
445445
:(.=), :(.+=), :(.-=), :(.*=), :(./=), :(.\=), :(.^=), :(.&=), :(.|=), :(.÷=), :(.%=), :(.>>>=), :(.>>=), :(.<<=),
446-
:(&&), :(||), :(<:), :(=>), :($=), :(⊻=)]) # `$=` should be removed after deprecation is removed, issue #18977
446+
:(&&), :(||), :(<:), :($=), :(⊻=)]) # `$=` should be removed after deprecation is removed, issue #18977
447447
const expr_infix = Set{Symbol}([:(:), :(->), Symbol("::")])
448448
const expr_infix_any = union(expr_infix, expr_infix_wide)
449449
const all_ops = union(quoted_syms, uni_ops, expr_infix_any)
@@ -800,16 +800,13 @@ function show_unquoted(io::IO, ex::Expr, indent::Int, prec::Int)
800800
show_call(io, head, ex.args[1], funcargslike, indent)
801801

802802
# comprehensions
803-
elseif (head === :typed_comprehension || head === :typed_dict_comprehension) && length(args) == 2
804-
isdict = (head === :typed_dict_comprehension)
805-
isdict && print(io, '(')
803+
elseif head === :typed_comprehension && length(args) == 2
806804
show_unquoted(io, args[1], indent)
807-
isdict && print(io, ')')
808805
print(io, '[')
809806
show_generator(io, args[2], indent)
810807
print(io, ']')
811808

812-
elseif (head === :comprehension || head === :dict_comprehension) && length(args) == 1
809+
elseif head === :comprehension && length(args) == 1
813810
print(io, '[')
814811
show_generator(io, args[1], indent)
815812
print(io, ']')

base/test.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -954,7 +954,7 @@ function parse_testset_args(args)
954954
elseif isa(arg, Expr) && arg.head == :(=)
955955
# we're building up a Dict literal here
956956
key = Expr(:quote, arg.args[1])
957-
push!(options.args, Expr(:(=>), key, arg.args[2]))
957+
push!(options.args, Expr(:call, :(=>), key, arg.args[2]))
958958
else
959959
error("Unexpected argument $arg to @testset")
960960
end

src/julia-parser.scm

Lines changed: 24 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@
7474
; operators that are special forms, not function names
7575
(define syntactic-operators
7676
(append! (add-dots '(= += -= *= /= //= |\\=| ^= ÷= %= <<= >>= >>>= |\|=| &= ⊻=))
77-
'(:= --> $= => && |\|\|| |.| ... ->)))
77+
'(:= --> $= && |\|\|| |.| ... ->)))
7878
(define syntactic-unary-operators '($ & |::|))
7979

8080
(define syntactic-op? (Set syntactic-operators))
@@ -123,9 +123,6 @@
123123

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

126-
(define (dict-literal? l)
127-
(and (length= l 3) (eq? (car l) '=>)))
128-
129126
;; Parser state variables
130127

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

760759
(define (parse-eq s)
761760
(let ((lno (input-port-line (ts:port s))))
@@ -895,9 +894,7 @@
895894
(else ex))))
896895

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

902899
(define (parse-unary s)
903900
(let ((t (require-token s)))
@@ -999,11 +996,6 @@
999996
(parse-where-chain s decl-sig)
1000997
decl-sig)))
1001998

1002-
(define (deprecated-dict-replacement ex)
1003-
(if (dict-literal? ex)
1004-
(string "Dict{" (deparse (cadr ex)) #\, (deparse (caddr ex)) "}")
1005-
"Dict"))
1006-
1007999
(define (disallowed-space ex t)
10081000
(error (string "space before \"" t "\" not allowed in \""
10091001
(deparse ex) " " (deparse t) "\"")))
@@ -1054,7 +1046,7 @@
10541046
;; ref is syntax, so we can distinguish
10551047
;; a[i] = x from
10561048
;; ref(a,i) = x
1057-
(let ((al (with-end-symbol (parse-cat s #\] (dict-literal? ex)))))
1049+
(let ((al (with-end-symbol (parse-cat s #\]))))
10581050
(if (null? al)
10591051
(loop (list 'ref ex))
10601052
(case (car al)
@@ -1064,11 +1056,6 @@
10641056
(loop (list* 'typed_vcat ex (cdr al))))
10651057
((comprehension)
10661058
(loop (list* 'typed_comprehension ex (cdr al))))
1067-
((dict_comprehension)
1068-
(syntax-deprecation
1069-
s (string #\( (deparse ex) #\) "[a=>b for (a,b) in c]")
1070-
(string (deprecated-dict-replacement ex) "(a=>b for (a,b) in c)"))
1071-
(loop (list* 'typed_dict_comprehension ex (cdr al))))
10721059
(else (error "unknown parse-cat result (internal error)"))))))
10731060
((|.|)
10741061
(if (ts:space? s) (disallowed-space ex t))
@@ -1177,8 +1164,7 @@
11771164

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

14631449
;; as above, but allows both "i=r" and "i in r"
14641450
(define (parse-iteration-spec s)
1465-
(let* ((paren? (eqv? (require-token s) #\())
1466-
(lhs (parse-pipes s))
1451+
(let* ((lhs (parse-pipes s))
14671452
(t (peek-token s)))
14681453
(cond ((memq t '(= in ∈))
14691454
(take-token s)
@@ -1476,13 +1461,6 @@
14761461
`(= ,lhs ,rhs)))
14771462
((and (eq? lhs ':) (closing-token? t))
14781463
':)
1479-
((and paren? (length= lhs 4) (eq? (car lhs) 'call)
1480-
(memq (cadr lhs) '(in ∈)))
1481-
(syntax-deprecation s "for (...)" "for ...")
1482-
`(= ,@(cddr lhs)))
1483-
((and paren? (length= lhs 3) (eq? (car lhs) '=))
1484-
(syntax-deprecation s "for (...)" "for ...")
1485-
lhs)
14861464
(else (error "invalid iteration specification")))))
14871465

14881466
(define (parse-comma-separated-iters s)
@@ -1602,12 +1580,6 @@
16021580
(take-token s))
16031581
`(comprehension ,gen))))
16041582

1605-
(define (parse-dict-comprehension s first closer)
1606-
(let ((c (parse-comprehension s first closer)))
1607-
(if (dict-literal? (cadr (cadr c)))
1608-
`(dict_comprehension ,@(cdr c))
1609-
(error "invalid dict comprehension"))))
1610-
16111583
(define (parse-matrix s first closer gotnewline)
16121584
(define (fix head v) (cons head (reverse v)))
16131585
(define (update-outer v outer)
@@ -1653,32 +1625,26 @@
16531625
(loop (peek-token s)))
16541626
t)))
16551627

1656-
(define (parse-cat s closer . isdict)
1628+
(define (parse-cat s closer)
16571629
(with-normal-ops
16581630
(with-inside-vec
16591631
(if (eqv? (require-token s) closer)
16601632
(begin (take-token s)
16611633
'())
1662-
(let ((first (parse-eq* s)))
1663-
(if (and (dict-literal? first)
1664-
(or (null? isdict) (car isdict))
1665-
(eq? (peek-non-newline-token s) 'for))
1666-
(begin
1667-
(take-token s)
1668-
(parse-dict-comprehension s first closer))
1669-
(let ((t (peek-token s)))
1670-
(cond ((or (eqv? t #\,) (eqv? t closer))
1671-
(parse-vect s first closer))
1672-
((eq? t 'for)
1673-
(take-token s)
1674-
(parse-comprehension s first closer))
1675-
((eqv? t #\newline)
1676-
(take-token s)
1677-
(if (memv (peek-token s) (list #\, closer))
1678-
(parse-vect s first closer)
1679-
(parse-matrix s first closer #t)))
1680-
(else
1681-
(parse-matrix s first closer #f))))))))))
1634+
(let* ((first (parse-eq* s))
1635+
(t (peek-token s)))
1636+
(cond ((or (eqv? t #\,) (eqv? t closer))
1637+
(parse-vect s first closer))
1638+
((eq? t 'for)
1639+
(take-token s)
1640+
(parse-comprehension s first closer))
1641+
((eqv? t #\newline)
1642+
(take-token s)
1643+
(if (memv (peek-token s) (list #\, closer))
1644+
(parse-vect s first closer)
1645+
(parse-matrix s first closer #t)))
1646+
(else
1647+
(parse-matrix s first closer #f))))))))
16821648

16831649
(define (kw-to-= e) (if (kwarg? e) (cons '= (cdr e)) e))
16841650
(define (=-to-kw e) (if (assignment? e) (cons 'kw (cdr e)) e))
@@ -2042,15 +2008,13 @@
20422008
(if (eqv? (require-token s) #\})
20432009
(begin (take-token s)
20442010
'(cell1d))
2045-
(let ((vex (parse-cat s #\} #t)))
2011+
(let ((vex (parse-cat s #\})))
20462012
(if (null? vex)
20472013
'(cell1d)
20482014
(case (car vex)
20492015
((vect) `(cell1d ,@(cdr vex)))
20502016
((hcat) `(cell2d 1 ,(length (cdr vex)) ,@(cdr vex)))
20512017
((comprehension) (error "{a for a in b} syntax is discontinued"))
2052-
((dict_comprehension) (error "{a=>b for (a,b) in c} syntax is discontinued"))
2053-
((dict) `(cell1d ,@(cdr vec)))
20542018
(else
20552019
(if (and (pair? (cadr vex)) (eq? (caadr vex) 'row))
20562020
(let ((nr (length (cdr vex)))

src/julia-syntax.scm

Lines changed: 13 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -275,10 +275,6 @@
275275
(and (symbol? s)
276276
(eqv? (string.char (string s) 0) #\#)))
277277

278-
(define (is-call-name? name)
279-
(or (eq? name 'call) (and (pair? name) (sym-ref? name)
280-
(equal? (caddr name) '(inert call)))))
281-
282278
(define (replace-vars e renames)
283279
(cond ((symbol? e) (lookup e renames e))
284280
((or (not (pair? e)) (quoted? e)) e)
@@ -331,9 +327,7 @@
331327
(error "function argument and static parameter names must be distinct")))
332328
(if (or (and name (not (sym-ref? name))) (eq? name 'true) (eq? name 'false))
333329
(error (string "invalid function name \"" (deparse name) "\"")))
334-
(let* ((iscall (is-call-name? name))
335-
(name (if iscall #f name))
336-
(types (llist-types argl))
330+
(let* ((types (llist-types argl))
337331
(body (method-lambda-expr argl body rett))
338332
;; HACK: the typevars need to be bound to ssavalues, since this code
339333
;; might be moved to a different scope by closure-convert.
@@ -364,13 +358,6 @@
364358
types)))
365359
(call (core svec) ,@temps)))
366360
,body ,isstaged))))
367-
(if (and iscall (not (null? argl)))
368-
(let* ((n (arg-name (car argl)))
369-
(n (if (hidden-name? n) "" n))
370-
(t (deparse (arg-type (car argl)))))
371-
(syntax-deprecation #f
372-
(string "call(" n "::" t ", ...)")
373-
(string "(" n "::" t ")(...)"))))
374361
(if (symbol? name)
375362
`(block (method ,name) ,mdef (unnecessary ,name)) ;; return the function
376363
mdef)))))
@@ -554,7 +541,7 @@
554541
(list `(... ,(arg-name (car vararg))))))))
555542
#f)
556543
;; return primary function
557-
,(if (or (not (symbol? name)) (is-call-name? name))
544+
,(if (not (symbol? name))
558545
'(null) name)))))
559546

560547
;; prologue includes line number node and eventual meta nodes
@@ -1803,13 +1790,8 @@
18031790
(eq? (car (cadr e)) 'line))))
18041791
(expand-forms (cadr e)))
18051792
(else
1806-
`(block
1807-
,.(map (lambda (x)
1808-
(if (and (decl? x) (length= (cdr x) 2) (symbol? (cadr x)))
1809-
`(impl-decl ,@(map expand-forms (cdr x)))
1810-
(expand-forms x)))
1811-
(butlast (cdr e)))
1812-
,(expand-forms (last (cdr e)))))))
1793+
(cons 'block
1794+
(map expand-forms (cdr e))))))
18131795

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

2091-
'=>
2092-
(lambda (e) `(call => ,(expand-forms (cadr e)) ,(expand-forms (caddr e))))
2093-
20942073
'cell1d (lambda (e) (error "{ } vector syntax is discontinued"))
20952074
'cell2d (lambda (e) (error "{ } matrix syntax is discontinued"))
20962075

@@ -2302,17 +2281,7 @@
23022281
;; TODO: this is a hack to lower simple comprehensions to loops very
23032282
;; early, to greatly reduce the # of functions and load on the compiler
23042283
(lower-comprehension (cadr e) (cadr (caddr e)) ranges))))
2305-
`(call (top collect) ,(cadr e) ,(caddr e)))))
2306-
2307-
'dict_comprehension
2308-
(lambda (e)
2309-
(syntax-deprecation #f "[a=>b for (a,b) in c]" "Dict(a=>b for (a,b) in c)")
2310-
(expand-forms `(call (top Dict) ,(cadr e))))
2311-
2312-
'typed_dict_comprehension
2313-
(lambda (e) (expand-forms
2314-
`(call (call (core apply_type) (top Dict) ,@(cdr (cadr e)))
2315-
,(caddr e))))))
2284+
`(call (top collect) ,(cadr e) ,(caddr e)))))))
23162285

23172286
(define (lower-comprehension atype expr ranges)
23182287
(let ((result (make-ssavalue))
@@ -2644,7 +2613,7 @@
26442613
(vinfo:set-called! vi #t))
26452614
(for-each (lambda (x) (analyze-vars x env captvars sp))
26462615
(cdr e))))
2647-
((decl impl-decl)
2616+
((decl)
26482617
;; handle var::T declaration by storing the type in the var-info
26492618
;; record. for non-symbols or globals, emit a type assertion.
26502619
(let ((vi (var-info-for (cadr e) env)))
@@ -3182,21 +3151,15 @@ f(x) = yt(x)
31823151
(cl-convert `(call (core typeassert) ,@(cdr e)) fname lam namemap toplevel interp))
31833152
;; remaining `decl` expressions are only type assertions if the
31843153
;; argument is global or a non-symbol.
3185-
((impl-decl)
3186-
(if (or (assq (cadr e) (car (lam:vinfo lam)))
3187-
(assq (cadr e) (cadr (lam:vinfo lam))))
3188-
(let ((str-e (deparse `(|::| ,@(cdr e)))))
3189-
(syntax-deprecation #f str-e (string "local " str-e))
3190-
'(null))
3191-
(cl-convert `(call (core typeassert) ,@(cdr e)) fname lam namemap toplevel interp)))
31923154
((decl)
3193-
(cond ((not (symbol? (cadr e)))
3194-
(cl-convert `(call (core typeassert) ,@(cdr e)) fname lam namemap toplevel interp))
3195-
((or (assq (cadr e) (car (lam:vinfo lam)))
3196-
(assq (cadr e) (cadr (lam:vinfo lam))))
3155+
(cond ((and (symbol? (cadr e))
3156+
(or (assq (cadr e) (car (lam:vinfo lam)))
3157+
(assq (cadr e) (cadr (lam:vinfo lam)))))
31973158
'(null))
3198-
(else (syntax-deprecation #f (string "global " (deparse `(|::| ,@(cdr e)))) "typeassert")
3199-
(cl-convert `(call (core typeassert) ,@(cdr e)) fname lam namemap toplevel interp))))
3159+
(else
3160+
(if (or (symbol? (cadr e)) (and (pair? (cadr e)) (eq? (caadr e) 'outerref)))
3161+
(error "type declarations on global variables are not yet supported"))
3162+
(cl-convert `(call (core typeassert) ,@(cdr e)) fname lam namemap toplevel interp))))
32003163
;; `with-static-parameters` expressions can be removed now; used only by analyze-vars
32013164
((with-static-parameters)
32023165
(cl-convert (cadr e) fname lam namemap toplevel interp))

test/core.jl

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,20 @@ end
255255
z = convert(Complex{Float64},2)
256256
@test z == Complex(2.0,0.0)
257257

258+
function typeassert_instead_of_decl()
259+
local x
260+
x = 1
261+
x::Float64
262+
return 0
263+
end
264+
@test_throws TypeError typeassert_instead_of_decl()
265+
266+
# type declarations on globals not implemented yet
267+
@test_throws ErrorException eval(parse("global x20327::Int"))
268+
269+
y20327 = 1
270+
@test_throws TypeError y20327::Float64
271+
258272
# misc
259273
fib(n) = n < 2 ? n : fib(n-1) + fib(n-2)
260274
@test fib(20) == 6765

0 commit comments

Comments
 (0)