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.4 syntax and Operators import deprecations #16693

Merged
merged 1 commit into from
Jun 3, 2016
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
2 changes: 0 additions & 2 deletions src/dump.c
Original file line number Diff line number Diff line change
Expand Up @@ -617,7 +617,6 @@ static void jl_serialize_module(ios_t *s, jl_module_t *m)
}
}
write_uint8(s, m->istopmod);
write_uint8(s, m->std_imports);
write_uint64(s, m->uuid);
write_int32(s, m->counter);
}
Expand Down Expand Up @@ -1564,7 +1563,6 @@ static jl_value_t *jl_deserialize_value_(ios_t *s, jl_value_t *vtag, jl_value_t
i++;
}
m->istopmod = read_uint8(s);
m->std_imports = read_uint8(s);
m->uuid = read_uint64(s);
m->counter = read_int32(s);
return (jl_value_t*)m;
Expand Down
94 changes: 10 additions & 84 deletions src/julia-parser.scm
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@
(define operator? (Set operators))

(define initial-reserved-words '(begin while if for try return break continue
stagedfunction function macro quote let local global const
function macro quote let local global const
abstract typealias type bitstype immutable ccall do
module baremodule using import export importall))

Expand Down Expand Up @@ -187,7 +187,7 @@
str))
str))))
(if (equal? str "--")
(syntax-deprecation port str ""))
(error "invalid operator \"--\""))
(string->symbol str))))

(define (accum-digits c pred port lz)
Expand Down Expand Up @@ -1007,21 +1007,8 @@
;; ref(a,i) = x
(let ((al (with-end-symbol (parse-cat s #\] (dict-literal? ex)))))
(if (null? al)
(if (dict-literal? ex)
(begin
(syntax-deprecation
s (string #\( (deparse ex) #\) "[]")
(string (deprecated-dict-replacement ex) "()"))
(loop (list 'typed_dict ex)))
(loop (list 'ref ex)))
(loop (list 'ref ex))
(case (car al)
((dict)
(if (dict-literal? ex)
(begin (syntax-deprecation
s (string #\( (deparse ex) #\) "[a=>b, ...]")
(string (deprecated-dict-replacement ex) "(a=>b, ...)"))
(loop (list* 'typed_dict ex (cdr al))))
(loop (list* 'ref ex (cdr al)))))
((vect) (loop (list* 'ref ex (cdr al))))
((hcat) (loop (list* 'typed_hcat ex (cdr al))))
((vcat)
Expand Down Expand Up @@ -1177,8 +1164,7 @@
(if const
`(const ,expr)
expr)))
((stagedfunction function macro)
(if (eq? word 'stagedfunction) (syntax-deprecation s "stagedfunction" "@generated function"))
((function macro)
(let* ((paren (eqv? (require-token s) #\())
(sig (parse-def s (not (eq? word 'macro)))))
(if (and (eq? word 'function) (not paren) (symbol-or-interpolate? sig))
Expand Down Expand Up @@ -1525,13 +1511,6 @@
(else
(error "missing separator in array expression")))))))

(define (parse-dict s first closer)
(let ((v (parse-vect s first closer)))
(if (any dict-literal? (cdr v))
(if (every dict-literal? (cdr v))
`(dict ,@(cdr v))
(error "invalid dict literal")))))

(define (parse-comprehension s first closer)
(let ((r (parse-comma-separated-iters s)))
(if (not (eqv? (require-token s) closer))
Expand Down Expand Up @@ -1601,15 +1580,11 @@
'())
(let ((first (parse-eq* s)))
(if (and (dict-literal? first)
(or (null? isdict) (car isdict)))
(case (peek-non-newline-token s)
((for)
(take-token s)
(parse-dict-comprehension s first closer))
(else
(if (or (null? isdict) (not (car isdict)))
(syntax-deprecation s "[a=>b, ...]" "Dict(a=>b, ...)"))
(parse-dict s first closer)))
(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))
Expand Down Expand Up @@ -2000,56 +1975,7 @@
;; Array{Any} expression
((eqv? t #\{ )
(take-token s)
(if (eqv? (require-token s) #\})
(begin (syntax-deprecation s "{}" "[]")
(take-token s)
'(vectany))
(let ((vex (parse-cat s #\} #t)))
(if (null? vex)
(begin (syntax-deprecation s "{}" "[]")
'(vectany))
(case (car vex)
((vect)
(syntax-deprecation s "{a,b, ...}" "Any[a,b, ...]")
`(vectany ,@(cdr vex)))
((comprehension)
(syntax-deprecation s "{a for a in b}" "Any[a for a in b]")
`(typed_comprehension (top Any) ,@(cdr vex)))
((dict_comprehension)
(syntax-deprecation s "{a=>b for (a,b) in c}" "Dict{Any,Any}(a=>b for (a,b) in c)")
`(typed_dict_comprehension (=> (top Any) (top Any)) ,@(cdr vex)))
((dict)
(syntax-deprecation s "{a=>b, ...}" "Dict{Any,Any}(a=>b, ...)")
`(typed_dict (=> (top Any) (top Any)) ,@(cdr vex)))
((hcat)
(syntax-deprecation s "{a b ...}" "Any[a b ...]")
`(matrany 1 ,(length (cdr vex)) ,@(cdr vex)))
(else ; (vcat ...)
(if (and (pair? (cadr vex)) (eq? (caadr vex) 'row))
(let ((nr (length (cdr vex)))
(nc (length (cdadr vex))))
;; make sure all rows are the same length
(if (not (every
(lambda (x)
(and (pair? x)
(eq? (car x) 'row)
(length= (cdr x) nc)))
(cddr vex)))
(error "inconsistent shape in Array{Any} expression"))
(begin
(syntax-deprecation s "{a b; c d}" "Any[a b; c d]")
`(matrany ,nr ,nc
,@(apply append
;; transpose to storage order
(apply map list
(map cdr (cdr vex)))))))
(if (any (lambda (x) (and (pair? x)
(eq? (car x) 'row)))
(cddr vex))
(error "inconsistent shape in Array{Any} expression")
(begin
(syntax-deprecation s "{a,b, ...}" "Any[a,b, ...]")
`(vectany ,@(cdr vex)))))))))))
(error "discontinued syntax { ... }"))

;; string literal
((eqv? t #\")
Expand Down
19 changes: 0 additions & 19 deletions src/julia-syntax.scm
Original file line number Diff line number Diff line change
Expand Up @@ -1793,25 +1793,6 @@
(error "assignment not allowed inside tuple"))
(expand-forms `(call (core tuple) ,@(cdr e))))

'dict
(lambda (e)
;; TODO: deprecate
`(call (top Dict)
,.(map expand-forms (cdr e))))

'typed_dict
(lambda (e)
;; TODO: deprecate
(let ((atypes (cadr e))
(args (cddr e)))
(if (and (length= atypes 3)
(eq? (car atypes) '=>))
`(call (call (core apply_type) (top Dict)
,(expand-forms (cadr atypes))
,(expand-forms (caddr atypes)))
,.(map expand-forms args))
(error (string "invalid \"typed_dict\" syntax " (deparse atypes))))))

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

Expand Down
1 change: 0 additions & 1 deletion src/julia.h
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,6 @@ typedef struct _jl_module_t {
htable_t bindings;
arraylist_t usings; // modules with all bindings potentially imported
uint8_t istopmod;
uint8_t std_imports; // only for temporarily deprecating `importall Base.Operators`
uint64_t uuid;
uint32_t counter;
} jl_module_t;
Expand Down
23 changes: 0 additions & 23 deletions src/module.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ JL_DLLEXPORT jl_module_t *jl_new_module(jl_sym_t *name)
m->name = name;
m->parent = NULL;
m->istopmod = 0;
m->std_imports = 0;
m->uuid = uv_now(uv_default_loop());
m->counter = 0;
htable_new(&m->bindings, 0);
Expand Down Expand Up @@ -125,17 +124,6 @@ JL_DLLEXPORT jl_module_t *jl_get_module_of_binding(jl_module_t *m, jl_sym_t *var
// and overwriting.
JL_DLLEXPORT jl_binding_t *jl_get_binding_for_method_def(jl_module_t *m, jl_sym_t *var)
{
if (jl_base_module && m->std_imports && !jl_binding_resolved_p(m,var)) {
jl_module_t *opmod = (jl_module_t*)jl_get_global(jl_base_module, jl_symbol("Operators"));
if (opmod != NULL && jl_defines_or_exports_p(opmod, var)) {
jl_printf(JL_STDERR,
"WARNING: module %s should explicitly import %s from %s\n",
jl_symbol_name(m->name), jl_symbol_name(var),
jl_symbol_name(jl_base_module->name));
jl_module_import(m, opmod, var);
}
}

jl_binding_t **bp = (jl_binding_t**)ptrhash_bp(&m->bindings, var);
jl_binding_t *b = *bp;

Expand All @@ -146,17 +134,6 @@ JL_DLLEXPORT jl_binding_t *jl_get_binding_for_method_def(jl_module_t *m, jl_sym_
jl_errorf("invalid method definition: imported function %s.%s does not exist", jl_symbol_name(b->owner->name), jl_symbol_name(var));
// TODO: we might want to require explicitly importing types to add constructors
if (!b->imported && (b2->value == NULL || !jl_is_type(b2->value))) {
if (jl_base_module && m->std_imports && b->owner == jl_base_module) {
jl_module_t *opmod = (jl_module_t*)jl_get_global(jl_base_module, jl_symbol("Operators"));
if (opmod != NULL && jl_defines_or_exports_p(opmod, var)) {
jl_printf(JL_STDERR,
"WARNING: module %s should explicitly import %s from %s\n",
jl_symbol_name(m->name),
jl_symbol_name(var),
jl_symbol_name(b->owner->name));
return b2;
}
}
jl_errorf("error in method definition: function %s.%s must be explicitly imported to be extended", jl_symbol_name(b->owner->name),
jl_symbol_name(var));
}
Expand Down
1 change: 0 additions & 1 deletion src/toplevel.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ JL_DLLEXPORT void jl_add_standard_imports(jl_module_t *m)
assert(jl_base_module != NULL);
// using Base
jl_module_using(m, jl_base_module);
m->std_imports = 1;
}

JL_DLLEXPORT jl_module_t *jl_new_main_module(void)
Expand Down
8 changes: 4 additions & 4 deletions test/cmdlineargs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -255,10 +255,10 @@ let exename = `$(Base.julia_cmd()) --precompiled=yes`
# issue #12679
extrapath = is_windows() ? joinpath(JULIA_HOME, "..", "Git", "usr", "bin") * ";" : ""
withenv("PATH" => extrapath * ENV["PATH"]) do
@test readchomp(pipeline(ignorestatus(`$exename -f --compile=yes -foo`),stderr=`cat`)) == "ERROR: unknown option `-o`"
@test readchomp(pipeline(ignorestatus(`$exename -f -p`),stderr=`cat`)) == "ERROR: option `-p/--procs` is missing an argument"
@test readchomp(pipeline(ignorestatus(`$exename -f --inline`),stderr=`cat`)) == "ERROR: option `--inline` is missing an argument"
@test readchomp(pipeline(ignorestatus(`$exename -f -e "@show ARGS" -now -- julia RUN.jl`),stderr=`cat`)) == "ERROR: unknown option `-n`"
@test readchomp(pipeline(ignorestatus(`$exename --startup-file=no --compile=yes -foo`),stderr=`cat`)) == "ERROR: unknown option `-o`"
@test readchomp(pipeline(ignorestatus(`$exename --startup-file=no -p`),stderr=`cat`)) == "ERROR: option `-p/--procs` is missing an argument"
@test readchomp(pipeline(ignorestatus(`$exename --startup-file=no --inline`),stderr=`cat`)) == "ERROR: option `--inline` is missing an argument"
@test readchomp(pipeline(ignorestatus(`$exename --startup-file=no -e "@show ARGS" -now -- julia RUN.jl`),stderr=`cat`)) == "ERROR: unknown option `-n`"
end

# --compilecache={yes|no}
Expand Down
2 changes: 1 addition & 1 deletion test/misc.jl
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ let
redir_err = "redirect_stderr(STDOUT)"
exename = Base.julia_cmd()
script = "$redir_err; module A; f() = 1; end; A.f() = 1"
warning_str = readstring(`$exename -f -e $script`)
warning_str = readstring(`$exename --startup-file=no -e $script`)
@test contains(warning_str, "f()")
end

Expand Down
27 changes: 27 additions & 0 deletions test/parse.jl
Original file line number Diff line number Diff line change
Expand Up @@ -476,3 +476,30 @@ end
Expr(:call, :test),
Expr(:line, 3, :none),
:y))

# test that pre 0.5 deprecated syntax is a parse error
@test_throws ParseError parse("Int [1,2,3]")
@test_throws ParseError parse("Int [x for x in 1:10]")
@test_throws ParseError parse("foo (x) = x")
@test_throws ParseError parse("foo {T<:Int}(x::T) = x")

@test_throws ParseError parse("Foo .bar")

@test_throws ParseError parse("import x .y")
@test_throws ParseError parse("using x .y")

@test_throws ParseError parse("--x")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this probably needs the deprecation for -- to be removed in julia-parser

@test_throws ParseError parse("stagedfunction foo(x); end")

@test_throws ParseError parse("{1,2,3}")
@test_throws ParseError parse("{1 2 3 4}")
@test_throws ParseError parse("{1,2; 3,4}")
@test_throws ParseError parse("{x for x in 1:10}")
@test_throws ParseError parse("{x=>y for (x,y) in zip([1,2,3],[4,5,6])}")
@test_throws ParseError parse("{:a=>1, :b=>2}")

# this now is parsed as getindex(Pair{Any,Any}, ...)
@test_throws MethodError eval(parse("(Any=>Any)[]"))
@test_throws MethodError eval(parse("(Any=>Any)[:a=>1,:b=>2]"))
# to be removed post 0.5
#@test_throws MethodError eval(parse("(Any=>Any)[x=>y for (x,y) in zip([1,2,3],[4,5,6])]"))
10 changes: 5 additions & 5 deletions test/spawn.jl
Original file line number Diff line number Diff line change
Expand Up @@ -180,16 +180,16 @@ exename = Base.julia_cmd()
if valgrind_off
# If --trace-children=yes is passed to valgrind, we will get a
# valgrind banner here, not "Hello World\n".
@test readstring(pipeline(`$exename -f -e 'println(STDERR,"Hello World")'`, stderr=`cat`)) == "Hello World\n"
@test readstring(pipeline(`$exename --startup-file=no -e 'println(STDERR,"Hello World")'`, stderr=`cat`)) == "Hello World\n"
out = Pipe()
proc = spawn(pipeline(`$exename -f -e 'println(STDERR,"Hello World")'`, stderr = out))
proc = spawn(pipeline(`$exename --startup-file=no -e 'println(STDERR,"Hello World")'`, stderr = out))
close(out.in)
@test readstring(out) == "Hello World\n"
@test success(proc)
end

# issue #6310
@test readstring(pipeline(`echo "2+2"`, `$exename -f`)) == "4\n"
@test readstring(pipeline(`echo "2+2"`, `$exename --startup-file=no`)) == "4\n"

# issue #5904
@test run(pipeline(ignorestatus(`false`), `true`)) === nothing
Expand Down Expand Up @@ -238,7 +238,7 @@ let fname = tempname()
import Base.zzzInvalidIdentifier
"""
try
(in,p) = open(pipeline(`$exename -f`, stderr=STDERR), "w")
(in,p) = open(pipeline(`$exename --startup-file=no`, stderr=STDERR), "w")
write(in,cmd)
close(in)
wait(p)
Expand All @@ -258,7 +258,7 @@ let bad = "bad\0name"
end

# issue #12829
let out = Pipe(), echo = `$exename -f -e 'print(STDOUT, " 1\t", readstring(STDIN))'`, ready = Condition()
let out = Pipe(), echo = `$exename --startup-file=no -e 'print(STDOUT, " 1\t", readstring(STDIN))'`, ready = Condition()
@test_throws ArgumentError write(out, "not open error")
@async begin # spawn writer task
open(echo, "w", out) do in1
Expand Down
2 changes: 1 addition & 1 deletion test/workspace.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ show(io, Pair)
@assert !Base.inbase(LastMain)
"""
exename = Base.julia_cmd()
run(`$exename -f -e $script`)
run(`$exename --startup-file=no -e $script`)