Skip to content

Commit 283bcc1

Browse files
committed
Add the ability to disable deprecation warnings with a cmd line switch
The `--depwarn={yes|no}` flag turns on/off method warnings and deprecated syntax warnings in the parser. (unexported) `compileropts()` method added to retrieve the compileropts struct from libjulia. (unexported) `syntax_deprecation_warnings(::Bool)` method added to turn off syntax deprecation warnings in the parser at runtime. the method returns the previous syntax deprecation warning state. add NEWS entry and update docs for command line switches
1 parent e669ee3 commit 283bcc1

11 files changed

+83
-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+
* `--no-depwarn` command line flag added to turn off 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

+15
Original file line numberDiff line numberDiff line change
@@ -241,3 +241,18 @@ 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+
build_path::Ptr{Cchar}
248+
code_coverage::Int8
249+
malloc_log::Int8
250+
check_bounds::Int8
251+
dumpbitcode::Int8
252+
int_literals::Cint
253+
compile_enabled::Int8
254+
opt_level::Int8
255+
depwarn::Int8
256+
end
257+
258+
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
DLLEXPORT void jl_init_frontend(void)
118120
{
119121
fl_init(4*1024*1024);
@@ -136,6 +138,9 @@ DLLEXPORT 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
@@ -88,7 +88,8 @@ jl_compileropts_t jl_compileropts = { NULL, // build_path
8888
JL_COMPILEROPT_DUMPBITCODE_OFF,
8989
0, // int_literals
9090
JL_COMPILEROPT_COMPILE_DEFAULT,
91-
0 // opt_level
91+
0, // opt_level
92+
1, // depwarn
9293
};
9394

9495
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
@@ -872,6 +872,7 @@ void jl_init_restored_modules();
872872
// front end interface
873873
DLLEXPORT jl_value_t *jl_parse_input_line(const char *str);
874874
DLLEXPORT jl_value_t *jl_parse_string(const char *str, int pos0, int greedy);
875+
DLLEXPORT int jl_parse_depwarn(int warn);
875876
int jl_start_parsing_file(const char *fname);
876877
void jl_stop_parsing(void);
877878
jl_value_t *jl_parse_next(void);
@@ -1336,6 +1337,7 @@ typedef struct {
13361337
int int_literals;
13371338
int8_t compile_enabled;
13381339
int8_t opt_level;
1340+
int8_t depwarn;
13391341
} jl_compileropts_t;
13401342

13411343
extern DLLEXPORT jl_compileropts_t jl_compileropts;

ui/repl.c

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

9293
void parse_opts(int *argcp, char ***argvp)
9394
{
@@ -106,6 +107,7 @@ void parse_opts(int *argcp, char ***argvp)
106107
{ "int-literals", required_argument, 0, 301 },
107108
{ "dump-bitcode", required_argument, 0, 302 },
108109
{ "compile", required_argument, 0, 303 },
110+
{ "depwarn", required_argument, 0, 304 },
109111
{ 0, 0, 0, 0 }
110112
};
111113
int c;
@@ -198,6 +200,16 @@ void parse_opts(int *argcp, char ***argvp)
198200
exit(1);
199201
}
200202
break;
203+
case 304:
204+
if (!strcmp(optarg,"yes"))
205+
jl_compileropts.depwarn = 1;
206+
else if (!strcmp(optarg,"no"))
207+
jl_compileropts.depwarn = 0;
208+
else {
209+
ios_printf(ios_stderr, "julia: invalid argument to --depwarn (%s)\n", optarg);
210+
exit(1);
211+
}
212+
break;
201213
default:
202214
ios_printf(ios_stderr, "julia: unhandled option -- %c\n", c);
203215
ios_printf(ios_stderr, "This is a bug, please report it.\n");

0 commit comments

Comments
 (0)