Skip to content

Commit e93672d

Browse files
committed
Merge pull request #9294 from JuliaLang/jcb/nodepwarn
RFC: add the ability to disable syntax deprecation warnings
2 parents f17595d + 4d38dc3 commit e93672d

11 files changed

+87
-20
lines changed

NEWS.md

+2
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ Compiler improvements
6565

6666
* Accessing fields that are always initialized no longer produces undefined checks ([#8827]).
6767

68+
* `--depwarn={yes|no}` command line flag added to enable / disable syntax and method deprecation warnings ([#9294]).
69+
6870
Library improvements
6971
--------------------
7072

base/client.jl

+3
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,9 @@ end
129129

130130
_repl_start = Condition()
131131

132+
syntax_deprecation_warnings(warn::Bool) =
133+
bool(ccall(:jl_parse_depwarn, Cint, (Cint,), warn))
134+
132135
function parse_input_line(s::AbstractString)
133136
# s = bytestring(s)
134137
# (expr, pos) = parse(s, 1)

base/deprecated.jl

+5-3
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,11 @@ macro deprecate(old,new)
3636
end
3737

3838
function depwarn(msg, funcsym)
39-
bt = backtrace()
40-
caller = firstcaller(bt, funcsym)
41-
warn(msg, once=(caller!=C_NULL), key=caller, bt=bt)
39+
if bool(compileropts().depwarn)
40+
bt = backtrace()
41+
caller = firstcaller(bt, funcsym)
42+
warn(msg, once=(caller!=C_NULL), key=caller, bt=bt)
43+
end
4244
end
4345

4446
function firstcaller(bt::Array{Ptr{Void},1}, funcsym::Symbol)

base/util.jl

+19
Original file line numberDiff line numberDiff line change
@@ -241,3 +241,22 @@ end
241241

242242
warn(err::Exception; prefix="ERROR: ", kw...) =
243243
warn(sprint(io->showerror(io,err)), prefix=prefix; kw...)
244+
245+
# Julia compiler options struct (see jl_compileropts_t in src/julia.h)
246+
immutable JLCompilerOpts
247+
julia_home::Ptr{Cchar}
248+
julia_bin::Ptr{Cchar}
249+
build_path::Ptr{Cchar}
250+
image_file::Ptr{Cchar}
251+
cpu_target::Ptr{Cchar}
252+
code_coverage::Int8
253+
malloc_log::Int8
254+
check_bounds::Int8
255+
dumpbitcode::Int8
256+
int_literals::Cint
257+
compile_enabled::Int8
258+
opt_level::Int8
259+
depwarn::Int8
260+
end
261+
262+
compileropts() = unsafe_load(cglobal(:jl_compileropts, JLCompilerOpts))

doc/manual/getting-started.rst

+12-4
Original file line numberDiff line numberDiff line change
@@ -110,22 +110,30 @@ those available for the ``perl`` and ``ruby`` programs::
110110

111111
-e, --eval <expr> Evaluate <expr>
112112
-E, --print <expr> Evaluate and show <expr>
113-
-P, --post-boot <expr> Evaluate <expr> right after boot
114-
-L, --load <file> Load <file> right after boot on all processors
113+
-P, --post-boot <expr> Evaluate <expr>, but don't disable interactive mode
114+
-L, --load <file> Load <file> immediately on all processors
115115
-J, --sysimage <file> Start up with the given system image file
116116

117117
-p <n> Run n local processes
118118
--machinefile <file> Run processes on hosts listed in <file>
119-
119+
120120
-i Force isinteractive() to be true
121121
--no-history-file Don't load or save history
122122
-f, --no-startup Don't load ~/.juliarc.jl
123123
-F Load ~/.juliarc.jl, then handle remaining inputs
124124
--color={yes|no} Enable or disable color text
125125

126-
--code-coverage Count executions of source lines
126+
--compile={yes|no|all} Enable or disable compiler, or request exhaustive compilation
127+
128+
--code-coverage={none|user|all}, --code-coverage
129+
Count executions of source lines (omitting setting is equivalent to 'user')
130+
--track-allocation={none|user|all}
131+
Count bytes allocated by each source line
127132
--check-bounds={yes|no} Emit bounds checks always or never (ignoring declarations)
133+
-O, --optimize Run time-intensive code optimizations
128134
--int-literals={32|64} Select integer literal size independent of platform
135+
--dump-bitcode={yes|no} Dump bitcode for the system image (used with --build)
136+
--depwarn={yes|no} Enable or disable syntax and method deprecation warnings
129137

130138

131139
Resources

src/ast.c

+11
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,8 @@ static builtinspec_t julia_flisp_ast_ext[] = {
114114
{ NULL, NULL }
115115
};
116116

117+
extern int jl_parse_depwarn(int warn);
118+
117119
void jl_init_frontend(void)
118120
{
119121
fl_init(4*1024*1024);
@@ -136,6 +138,9 @@ void jl_init_frontend(void)
136138
false_sym = symbol("false");
137139
fl_error_sym = symbol("error");
138140
fl_null_sym = symbol("null");
141+
142+
// Enable / disable syntax deprecation warnings
143+
jl_parse_depwarn((int)jl_compileropts.depwarn);
139144
}
140145

141146
DLLEXPORT void jl_lisp_prompt(void)
@@ -507,6 +512,12 @@ void jl_stop_parsing(void)
507512
fl_applyn(0, symbol_value(symbol("jl-parser-close-stream")));
508513
}
509514

515+
DLLEXPORT int jl_parse_depwarn(int warn)
516+
{
517+
value_t prev = fl_applyn(1, symbol_value(symbol("jl-parser-depwarn")), warn? FL_T : FL_F);
518+
return prev == FL_T ? 1 : 0;
519+
}
520+
510521
extern int jl_lineno;
511522

512523
jl_value_t *jl_parse_next(void)

src/init.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,8 @@ jl_compileropts_t jl_compileropts = { NULL, // julia_home
9999
JL_COMPILEROPT_DUMPBITCODE_OFF,
100100
0, // int_literals
101101
JL_COMPILEROPT_COMPILE_DEFAULT,
102-
0 // opt_level
102+
0, // opt_level
103+
1, // depwarn
103104
};
104105

105106
int jl_boot_file_loaded = 0;

src/jlfrontend.scm

+6
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,12 @@
187187
(set! *filename-stack* (cdr *filename-stack*))
188188
(set! *ts-stack* (cdr *ts-stack*)))
189189

190+
(define *depwarn* #t)
191+
(define (jl-parser-depwarn w)
192+
(let ((prev *depwarn*))
193+
(set! *depwarn* (eq? w #t))
194+
prev))
195+
190196
(define (jl-parser-next)
191197
(let* ((err (parser-wrap
192198
(lambda ()

src/julia-parser.scm

+12-11
Original file line numberDiff line numberDiff line change
@@ -501,17 +501,18 @@
501501
;; --- misc ---
502502

503503
(define (syntax-deprecation-warning s what instead)
504-
(io.write
505-
*stderr*
506-
(string
507-
#\newline "WARNING: deprecated syntax \"" what "\""
508-
(if (eq? current-filename 'none)
509-
""
510-
(string " at " current-filename ":" (input-port-line (ts:port s))))
511-
"."
512-
(if (equal? instead "")
513-
""
514-
(string #\newline "Use \"" instead "\" instead." #\newline)))))
504+
(if *depwarn*
505+
(io.write
506+
*stderr*
507+
(string
508+
#\newline "WARNING: deprecated syntax \"" what "\""
509+
(if (eq? current-filename 'none)
510+
""
511+
(string " at " current-filename ":" (input-port-line (ts:port s))))
512+
"."
513+
(if (equal? instead "")
514+
""
515+
(string #\newline "Use \"" instead "\" instead." #\newline))))))
515516

516517
;; --- parser ---
517518

src/julia.h

+2
Original file line numberDiff line numberDiff line change
@@ -878,6 +878,7 @@ void jl_init_restored_modules();
878878
// front end interface
879879
DLLEXPORT jl_value_t *jl_parse_input_line(const char *str);
880880
DLLEXPORT jl_value_t *jl_parse_string(const char *str, int pos0, int greedy);
881+
DLLEXPORT int jl_parse_depwarn(int warn);
881882
int jl_start_parsing_file(const char *fname);
882883
void jl_stop_parsing(void);
883884
jl_value_t *jl_parse_next(void);
@@ -1329,6 +1330,7 @@ typedef struct {
13291330
int int_literals;
13301331
int8_t compile_enabled;
13311332
int8_t opt_level;
1333+
int8_t depwarn;
13321334
} jl_compileropts_t;
13331335

13341336
extern DLLEXPORT jl_compileropts_t jl_compileropts;

ui/repl.c

+13-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ static const char *opts =
7474
" --check-bounds={yes|no} Emit bounds checks always or never (ignoring declarations)\n"
7575
" -O, --optimize Run time-intensive code optimizations\n"
7676
" --int-literals={32|64} Select integer literal size independent of platform\n"
77-
" --dump-bitcode={yes|no} Dump bitcode for the system image (used with --build)\n";
77+
" --dump-bitcode={yes|no} Dump bitcode for the system image (used with --build)\n"
78+
" --depwarn={yes|no} Enable or disable syntax and method deprecation warnings\n";
7879

7980
void parse_opts(int *argcp, char ***argvp)
8081
{
@@ -93,6 +94,7 @@ void parse_opts(int *argcp, char ***argvp)
9394
{ "int-literals", required_argument, 0, 301 },
9495
{ "dump-bitcode", required_argument, 0, 302 },
9596
{ "compile", required_argument, 0, 303 },
97+
{ "depwarn", required_argument, 0, 304 },
9698
{ 0, 0, 0, 0 }
9799
};
98100
int c;
@@ -186,6 +188,16 @@ void parse_opts(int *argcp, char ***argvp)
186188
exit(1);
187189
}
188190
break;
191+
case 304:
192+
if (!strcmp(optarg,"yes"))
193+
jl_compileropts.depwarn = 1;
194+
else if (!strcmp(optarg,"no"))
195+
jl_compileropts.depwarn = 0;
196+
else {
197+
ios_printf(ios_stderr, "julia: invalid argument to --depwarn (%s)\n", optarg);
198+
exit(1);
199+
}
200+
break;
189201
default:
190202
ios_printf(ios_stderr, "julia: unhandled option -- %c\n", c);
191203
ios_printf(ios_stderr, "This is a bug, please report it.\n");

0 commit comments

Comments
 (0)