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

RFC: add command option to remove method redefinition warnings #23002

Merged
merged 4 commits into from
Aug 14, 2017
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: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ define sysimg_builder
$$(build_private_libdir)/sys$1.o: $$(build_private_libdir)/inference.ji $$(JULIAHOME)/VERSION $$(BASE_SRCS)
@$$(call PRINT_JULIA, cd $$(JULIAHOME)/base && \
$$(call spawn,$3) $2 -C $$(JULIA_CPU_TARGET) --output-o $$(call cygpath_w,$$@) $$(JULIA_SYSIMG_BUILD_FLAGS) \
--startup-file=no --sysimage $$(call cygpath_w,$$<) sysimg.jl $$(RELBUILDROOT) \
--startup-file=no --warn-overwrite=yes --sysimage $$(call cygpath_w,$$<) sysimg.jl $$(RELBUILDROOT) \
|| { echo '*** This error is usually fixed by running `make clean`. If the error persists$$(COMMA) try `make cleanall`. ***' && false; } )
.SECONDARY: $(build_private_libdir)/sys$1.o
endef
Expand Down
6 changes: 6 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,12 @@ Deprecated or removed
* `Base.cpad` has been removed; use an appropriate combination of `rpad` and `lpad`
instead ([#23187]).

Command-line option changes
---------------------------

* New option `--warn-overwrite={yes|no}` to control the warning for overwriting method
definitions. The default is `no` ([#23002]).

Julia v0.6.0 Release Notes
==========================

Expand Down
2 changes: 1 addition & 1 deletion base/loading.jl
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@ function create_expr_cache(input::String, output::String, concrete_deps::Vector{
"""
io = open(pipeline(detach(`$(julia_cmd()) -O0
--output-ji $output --output-incremental=yes
--startup-file=no --history-file=no
--startup-file=no --history-file=no --warn-overwrite=yes
--color=$(have_color ? "yes" : "no")
--eval $code_object`), stderr=STDERR),
"w", STDOUT)
Expand Down
1 change: 1 addition & 0 deletions base/options.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ struct JLOptions
debug_level::Int8
check_bounds::Int8
depwarn::Int8
warn_overwrite::Int8
can_inline::Int8
polly::Int8
fast_math::Int8
Expand Down
1 change: 1 addition & 0 deletions base/pkg/entry.jl
Original file line number Diff line number Diff line change
Expand Up @@ -719,6 +719,7 @@ function test!(pkg::AbstractString,
--color=$(Base.have_color ? "yes" : "no")
--compilecache=$(Bool(Base.JLOptions().use_compilecache) ? "yes" : "no")
--check-bounds=yes
--warn-overwrite=yes
--startup-file=$(Base.JLOptions().startupfile != 2 ? "yes" : "no")
$test_path
```
Expand Down
4 changes: 4 additions & 0 deletions doc/man/julia.1
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,10 @@ or adhere to declarations in source code
--depwarn={yes|no|error}
Enable or disable syntax and method deprecation warnings ('error' turns warnings into errors)

.TP
--warn-overwrite={yes|no}
Enable or disable method overwrite warnings

.TP
--output-o <name>
Generate an object file (including system image data)
Expand Down
1 change: 1 addition & 0 deletions doc/src/manual/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ julia [switches] -- [programfile] [args...]
--math-mode={ieee,fast} Disallow or enable unsafe floating point optimizations (overrides @fastmath declaration)

--depwarn={yes|no|error} Enable or disable syntax and method deprecation warnings ("error" turns warnings into errors)
--warn-overwrite={yes|no} Enable or disable method overwrite warnings

--output-o name Generate an object file (including system image data)
--output-ji name Generate a system image data file (.ji)
Expand Down
2 changes: 1 addition & 1 deletion src/gf.c
Original file line number Diff line number Diff line change
Expand Up @@ -1223,7 +1223,7 @@ static void method_overwrite(jl_typemap_entry_t *newentry, jl_method_t *oldvalue
jl_method_t *method = (jl_method_t*)newentry->func.method;
jl_module_t *newmod = method->module;
jl_module_t *oldmod = oldvalue->module;
if (newmod != jl_main_module || oldmod != jl_main_module) {
if (jl_options.warn_overwrite == JL_OPTIONS_WARN_OVERWRITE_ON) {
JL_STREAM *s = JL_STDERR;
jl_printf(s, "WARNING: Method definition ");
jl_static_show_func_sig(s, (jl_value_t*)newentry->sig);
Expand Down
12 changes: 12 additions & 0 deletions src/jloptions.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ jl_options_t jl_options = { 0, // quiet
#endif
JL_OPTIONS_CHECK_BOUNDS_DEFAULT, // check_bounds
1, // deprecation warning
0, // method overwrite warning
1, // can_inline
JL_OPTIONS_POLLY_ON, // polly
JL_OPTIONS_FAST_MATH_DEFAULT,
Expand Down Expand Up @@ -123,6 +124,7 @@ static const char opts[] =

// error and warning options
" --depwarn={yes|no|error} Enable or disable syntax and method deprecation warnings (\"error\" turns warnings into errors)\n\n"
" --warn-overwrite={yes|no} Enable or disable method overwrite warnings"

// compiler output options
" --output-o name Generate an object file (including system image data)\n"
Expand Down Expand Up @@ -156,6 +158,7 @@ JL_DLLEXPORT void jl_parse_opts(int *argcp, char ***argvp)
opt_output_unopt_bc,
opt_output_bc,
opt_depwarn,
opt_warn_overwrite,
opt_inline,
opt_polly,
opt_math_mode,
Expand Down Expand Up @@ -201,6 +204,7 @@ JL_DLLEXPORT void jl_parse_opts(int *argcp, char ***argvp)
{ "output-ji", required_argument, 0, opt_output_ji },
{ "output-incremental",required_argument, 0, opt_incremental },
{ "depwarn", required_argument, 0, opt_depwarn },
{ "warn-overwrite", required_argument, 0, opt_warn_overwrite },
{ "inline", required_argument, 0, opt_inline },
{ "polly", required_argument, 0, opt_polly },
{ "math-mode", required_argument, 0, opt_math_mode },
Expand Down Expand Up @@ -478,6 +482,14 @@ JL_DLLEXPORT void jl_parse_opts(int *argcp, char ***argvp)
else
jl_errorf("julia: invalid argument to --depwarn={yes|no|error} (%s)", optarg);
break;
case opt_warn_overwrite:
if (!strcmp(optarg,"yes"))
jl_options.warn_overwrite = JL_OPTIONS_WARN_OVERWRITE_ON;
else if (!strcmp(optarg,"no"))
jl_options.warn_overwrite = JL_OPTIONS_WARN_OVERWRITE_OFF;
else
jl_errorf("julia: invalid argument to --warn-overwrite={yes|no|} (%s)", optarg);
break;
case opt_inline:
if (!strcmp(optarg,"yes"))
jl_options.can_inline = 1;
Expand Down
4 changes: 4 additions & 0 deletions src/julia.h
Original file line number Diff line number Diff line change
Expand Up @@ -1692,6 +1692,7 @@ typedef struct {
int8_t debug_level;
int8_t check_bounds;
int8_t depwarn;
int8_t warn_overwrite;
int8_t can_inline;
int8_t polly;
int8_t fast_math;
Expand Down Expand Up @@ -1752,6 +1753,9 @@ JL_DLLEXPORT int jl_generating_output(void);
#define JL_OPTIONS_DEPWARN_ON 1
#define JL_OPTIONS_DEPWARN_ERROR 2

#define JL_OPTIONS_WARN_OVERWRITE_OFF 0
#define JL_OPTIONS_WARN_OVERWRITE_ON 1

#define JL_OPTIONS_POLLY_ON 1
#define JL_OPTIONS_POLLY_OFF 0

Expand Down
27 changes: 27 additions & 0 deletions test/cmdlineargs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -429,3 +429,30 @@ for precomp in ("yes", "no")
@test length(lno.captures) == 1
@test parse(Int, lno.captures[1]) > 0
end

# PR #23002
let exename = `$(Base.julia_cmd()) --startup-file=no`
for (mac, flag, pfix, msg) in [("@test_nowarn", ``, "_1", ""),
("@test_warn", `--warn-overwrite=yes`, "_2", "\"WARNING: Method definition\"")]
str = """
using Base.Test
try
# issue #18725
$mac $msg @eval Main begin
f18725$(pfix)(x) = 1
f18725$(pfix)(x) = 2
end
@test Main.f18725$(pfix)(0) == 2
# PR #23030
$mac $msg @eval Main module Module23030$(pfix)
f23030$(pfix)(x) = 1
f23030$(pfix)(x) = 2
end
catch
exit(-1)
end
exit(0)
"""
run(`$exename $flag -e $str`)
end
end
11 changes: 0 additions & 11 deletions test/core.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4680,17 +4680,6 @@ end
@test f14893() == 14893
@test M14893.f14893() == 14893

# issue #18725
@test_nowarn @eval Main begin
f18725(x) = 1
f18725(x) = 2
end
@test Main.f18725(0) == 2
@test_warn "WARNING: Method definition f18725(Any) in module Module18725" @eval Main module Module18725
f18725(x) = 1
f18725(x) = 2
end

# issue #19599
f19599(x::((S)->Vector{S})(T)...) where {T} = 1
@test f19599([1],[1]) == 1
Expand Down
2 changes: 1 addition & 1 deletion test/misc.jl
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ let
redir_err = "redirect_stderr(STDOUT)"
exename = Base.julia_cmd()
script = "$redir_err; module A; f() = 1; end; A.f() = 1"
warning_str = read(`$exename --startup-file=no -e $script`, String)
warning_str = read(`$exename --warn-overwrite=yes --startup-file=no -e $script`, String)
@test contains(warning_str, "f()")
end

Expand Down