diff --git a/NEWS.md b/NEWS.md index 070211599df797..d04ad7bbce8831 100644 --- a/NEWS.md +++ b/NEWS.md @@ -65,6 +65,8 @@ Compiler improvements * Accessing fields that are always initialized no longer produces undefined checks ([#8827]). + * `--no-depwarn` command line flag added to turn off syntax and method deprecation warnings ([#9294]). + Library improvements -------------------- diff --git a/base/client.jl b/base/client.jl index 3518498795e839..e8907f4c61e1c7 100644 --- a/base/client.jl +++ b/base/client.jl @@ -129,6 +129,9 @@ end _repl_start = Condition() +syntax_deprecation_warnings(warn::Bool) = + bool(ccall(:jl_parse_depwarn, Cint, (Cint,), warn)) + function parse_input_line(s::AbstractString) # s = bytestring(s) # (expr, pos) = parse(s, 1) diff --git a/base/deprecated.jl b/base/deprecated.jl index 99bae237f34f49..f8b063704ed17d 100644 --- a/base/deprecated.jl +++ b/base/deprecated.jl @@ -36,9 +36,11 @@ macro deprecate(old,new) end function depwarn(msg, funcsym) - bt = backtrace() - caller = firstcaller(bt, funcsym) - warn(msg, once=(caller!=C_NULL), key=caller, bt=bt) + if bool(compileropts().depwarn) + bt = backtrace() + caller = firstcaller(bt, funcsym) + warn(msg, once=(caller!=C_NULL), key=caller, bt=bt) + end end function firstcaller(bt::Array{Ptr{Void},1}, funcsym::Symbol) diff --git a/base/util.jl b/base/util.jl index 2269303af4b855..2c88f9651dddd1 100644 --- a/base/util.jl +++ b/base/util.jl @@ -241,3 +241,18 @@ end warn(err::Exception; prefix="ERROR: ", kw...) = warn(sprint(io->showerror(io,err)), prefix=prefix; kw...) + +# Julia compiler options struct (see jl_compileropts_t in src/julia.h) +immutable JLCompilerOpts + build_path::Ptr{Cchar} + code_coverage::Int8 + malloc_log::Int8 + check_bounds::Int8 + dumpbitcode::Int8 + int_literals::Cint + compile_enabled::Int8 + opt_level::Int8 + depwarn::Int8 +end + +compileropts() = unsafe_load(cglobal(:jl_compileropts, JLCompilerOpts)) diff --git a/doc/manual/getting-started.rst b/doc/manual/getting-started.rst index e7cd8d12cf4d1b..533b3f5d7187a8 100644 --- a/doc/manual/getting-started.rst +++ b/doc/manual/getting-started.rst @@ -110,22 +110,30 @@ those available for the ``perl`` and ``ruby`` programs:: -e, --eval Evaluate -E, --print Evaluate and show - -P, --post-boot Evaluate right after boot - -L, --load Load right after boot on all processors + -P, --post-boot Evaluate , but don't disable interactive mode + -L, --load Load immediately on all processors -J, --sysimage Start up with the given system image file -p Run n local processes --machinefile Run processes on hosts listed in - + -i Force isinteractive() to be true --no-history-file Don't load or save history -f, --no-startup Don't load ~/.juliarc.jl -F Load ~/.juliarc.jl, then handle remaining inputs --color={yes|no} Enable or disable color text - --code-coverage Count executions of source lines + --compile={yes|no|all} Enable or disable compiler, or request exhaustive compilation + + --code-coverage={none|user|all}, --code-coverage + Count executions of source lines (omitting setting is equivalent to 'user') + --track-allocation={none|user|all} + Count bytes allocated by each source line --check-bounds={yes|no} Emit bounds checks always or never (ignoring declarations) + -O, --optimize Run time-intensive code optimizations --int-literals={32|64} Select integer literal size independent of platform + --dump-bitcode={yes|no} Dump bitcode for the system image (used with --build) + --depwarn={yes|no} Enable or disable syntax and method deprecation warnings Resources diff --git a/src/ast.c b/src/ast.c index f743641d1cf731..aa1245efa4ee67 100644 --- a/src/ast.c +++ b/src/ast.c @@ -114,6 +114,8 @@ static builtinspec_t julia_flisp_ast_ext[] = { { NULL, NULL } }; +extern int jl_parse_depwarn(int warn); + DLLEXPORT void jl_init_frontend(void) { fl_init(4*1024*1024); @@ -136,6 +138,9 @@ DLLEXPORT void jl_init_frontend(void) false_sym = symbol("false"); fl_error_sym = symbol("error"); fl_null_sym = symbol("null"); + + // Enable / disable syntax deprecation warnings + jl_parse_depwarn((int)jl_compileropts.depwarn); } DLLEXPORT void jl_lisp_prompt(void) @@ -507,6 +512,12 @@ void jl_stop_parsing(void) fl_applyn(0, symbol_value(symbol("jl-parser-close-stream"))); } +DLLEXPORT int jl_parse_depwarn(int warn) +{ + value_t prev = fl_applyn(1, symbol_value(symbol("jl-parser-depwarn")), warn? FL_T : FL_F); + return prev == FL_T ? 1 : 0; +} + extern int jl_lineno; jl_value_t *jl_parse_next(void) diff --git a/src/init.c b/src/init.c index 3b19d39f764b2c..c89911e6b51d80 100644 --- a/src/init.c +++ b/src/init.c @@ -88,7 +88,8 @@ jl_compileropts_t jl_compileropts = { NULL, // build_path JL_COMPILEROPT_DUMPBITCODE_OFF, 0, // int_literals JL_COMPILEROPT_COMPILE_DEFAULT, - 0 // opt_level + 0, // opt_level + 1, // depwarn }; int jl_boot_file_loaded = 0; diff --git a/src/jlfrontend.scm b/src/jlfrontend.scm index e32c05a35aa202..e5fbc42105e556 100644 --- a/src/jlfrontend.scm +++ b/src/jlfrontend.scm @@ -187,6 +187,12 @@ (set! *filename-stack* (cdr *filename-stack*)) (set! *ts-stack* (cdr *ts-stack*))) +(define *depwarn* #t) +(define (jl-parser-depwarn w) + (let ((prev *depwarn*)) + (set! *depwarn* (eq? w #t)) + prev)) + (define (jl-parser-next) (let* ((err (parser-wrap (lambda () diff --git a/src/julia-parser.scm b/src/julia-parser.scm index 72c5babc035ac5..006da6322394ec 100644 --- a/src/julia-parser.scm +++ b/src/julia-parser.scm @@ -501,17 +501,18 @@ ;; --- misc --- (define (syntax-deprecation-warning s what instead) - (io.write - *stderr* - (string - #\newline "WARNING: deprecated syntax \"" what "\"" - (if (eq? current-filename 'none) - "" - (string " at " current-filename ":" (input-port-line (ts:port s)))) - "." - (if (equal? instead "") - "" - (string #\newline "Use \"" instead "\" instead." #\newline))))) + (if *depwarn* + (io.write + *stderr* + (string + #\newline "WARNING: deprecated syntax \"" what "\"" + (if (eq? current-filename 'none) + "" + (string " at " current-filename ":" (input-port-line (ts:port s)))) + "." + (if (equal? instead "") + "" + (string #\newline "Use \"" instead "\" instead." #\newline)))))) ;; --- parser --- diff --git a/src/julia.h b/src/julia.h index 5311e5a3218932..a85fbdaef9484b 100644 --- a/src/julia.h +++ b/src/julia.h @@ -872,6 +872,7 @@ void jl_init_restored_modules(); // front end interface DLLEXPORT jl_value_t *jl_parse_input_line(const char *str); DLLEXPORT jl_value_t *jl_parse_string(const char *str, int pos0, int greedy); +DLLEXPORT int jl_parse_depwarn(int warn); int jl_start_parsing_file(const char *fname); void jl_stop_parsing(void); jl_value_t *jl_parse_next(void); @@ -1336,6 +1337,7 @@ typedef struct { int int_literals; int8_t compile_enabled; int8_t opt_level; + int8_t depwarn; } jl_compileropts_t; extern DLLEXPORT jl_compileropts_t jl_compileropts; diff --git a/ui/repl.c b/ui/repl.c index 31634902aacbc9..e8e317c2a6d33d 100644 --- a/ui/repl.c +++ b/ui/repl.c @@ -87,7 +87,8 @@ static const char *opts = " --check-bounds={yes|no} Emit bounds checks always or never (ignoring declarations)\n" " -O, --optimize Run time-intensive code optimizations\n" " --int-literals={32|64} Select integer literal size independent of platform\n" - " --dump-bitcode={yes|no} Dump bitcode for the system image (used with --build)\n"; + " --dump-bitcode={yes|no} Dump bitcode for the system image (used with --build)\n" + " --depwarn={yes|no} Enable or disable syntax and method deprecation warnings\n"; void parse_opts(int *argcp, char ***argvp) { @@ -106,6 +107,7 @@ void parse_opts(int *argcp, char ***argvp) { "int-literals", required_argument, 0, 301 }, { "dump-bitcode", required_argument, 0, 302 }, { "compile", required_argument, 0, 303 }, + { "depwarn", required_argument, 0, 304 }, { 0, 0, 0, 0 } }; int c; @@ -198,6 +200,16 @@ void parse_opts(int *argcp, char ***argvp) exit(1); } break; + case 304: + if (!strcmp(optarg,"yes")) + jl_compileropts.depwarn = 1; + else if (!strcmp(optarg,"no")) + jl_compileropts.depwarn = 0; + else { + ios_printf(ios_stderr, "julia: invalid argument to --depwarn (%s)\n", optarg); + exit(1); + } + break; default: ios_printf(ios_stderr, "julia: unhandled option -- %c\n", c); ios_printf(ios_stderr, "This is a bug, please report it.\n");