From 9f974bf8b47c781e5d89f43c4a278aa84c8c3c34 Mon Sep 17 00:00:00 2001 From: Kristoffer Carlsson Date: Fri, 28 Jul 2017 15:05:30 +0200 Subject: [PATCH 1/4] add command option for method redefinitions --- base/options.jl | 1 + src/gf.c | 2 +- src/jloptions.c | 12 ++++++++++++ src/julia.h | 4 ++++ 4 files changed, 18 insertions(+), 1 deletion(-) diff --git a/base/options.jl b/base/options.jl index 872fa771ec291..6277032c83e88 100644 --- a/base/options.jl +++ b/base/options.jl @@ -23,6 +23,7 @@ struct JLOptions debug_level::Int8 check_bounds::Int8 depwarn::Int8 + overwritewarn::Int8 can_inline::Int8 polly::Int8 fast_math::Int8 diff --git a/src/gf.c b/src/gf.c index 42c4d60fe7c52..fdcd07ebab070 100644 --- a/src/gf.c +++ b/src/gf.c @@ -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.overwritewarn == JL_OPTIONS_DEPWARN_ON && (newmod != jl_main_module || oldmod != jl_main_module)) { JL_STREAM *s = JL_STDERR; jl_printf(s, "WARNING: Method definition "); jl_static_show_func_sig(s, (jl_value_t*)newentry->sig); diff --git a/src/jloptions.c b/src/jloptions.c index 61698c7c38e3d..d508aa8e45b23 100644 --- a/src/jloptions.c +++ b/src/jloptions.c @@ -58,6 +58,7 @@ jl_options_t jl_options = { 0, // quiet #endif JL_OPTIONS_CHECK_BOUNDS_DEFAULT, // check_bounds 1, // deprecation warning + 1, // method overwrite warning 1, // can_inline JL_OPTIONS_POLLY_ON, // polly JL_OPTIONS_FAST_MATH_DEFAULT, @@ -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" + " --overwritewarn={yes|no} Enable or disable method overwrite warnings" // compiler output options " --output-o name Generate an object file (including system image data)\n" @@ -156,6 +158,7 @@ JL_DLLEXPORT void jl_parse_opts(int *argcp, char ***argvp) opt_output_unopt_bc, opt_output_bc, opt_depwarn, + opt_overwritewarn, opt_inline, opt_polly, opt_math_mode, @@ -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 }, + { "overwritewarn", required_argument, 0, opt_overwritewarn }, { "inline", required_argument, 0, opt_inline }, { "polly", required_argument, 0, opt_polly }, { "math-mode", required_argument, 0, opt_math_mode }, @@ -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_overwritewarn: + if (!strcmp(optarg,"yes")) + jl_options.overwritewarn = JL_OPTIONS_OVERWRITEWARN_ON; + else if (!strcmp(optarg,"no")) + jl_options.overwritewarn = JL_OPTIONS_OVERWRITEWARN_OFF; + else + jl_errorf("julia: invalid argument to --overwritewarn={yes|no|} (%s)", optarg); + break; case opt_inline: if (!strcmp(optarg,"yes")) jl_options.can_inline = 1; diff --git a/src/julia.h b/src/julia.h index 83a77a9126810..27dda02ad5fbd 100644 --- a/src/julia.h +++ b/src/julia.h @@ -1692,6 +1692,7 @@ typedef struct { int8_t debug_level; int8_t check_bounds; int8_t depwarn; + int8_t overwritewarn; int8_t can_inline; int8_t polly; int8_t fast_math; @@ -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_OVERWRITEWARN_OFF 0 +#define JL_OPTIONS_OVERWRITEWARN_ON 1 + #define JL_OPTIONS_POLLY_ON 1 #define JL_OPTIONS_POLLY_OFF 0 From 487a314d7c239f23aad21b02317e26436b1389d4 Mon Sep 17 00:00:00 2001 From: Kristoffer Carlsson Date: Fri, 11 Aug 2017 14:50:24 +0200 Subject: [PATCH 2/4] update + add test --- src/gf.c | 2 +- src/jloptions.c | 2 +- test/core.jl | 38 +++++++++++++++++++++++++++----------- 3 files changed, 29 insertions(+), 13 deletions(-) diff --git a/src/gf.c b/src/gf.c index fdcd07ebab070..84e1d388ec0a4 100644 --- a/src/gf.c +++ b/src/gf.c @@ -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 (jl_options.overwritewarn == JL_OPTIONS_DEPWARN_ON && (newmod != jl_main_module || oldmod != jl_main_module)) { + if (jl_options.overwritewarn == JL_OPTIONS_DEPWARN_ON) { JL_STREAM *s = JL_STDERR; jl_printf(s, "WARNING: Method definition "); jl_static_show_func_sig(s, (jl_value_t*)newentry->sig); diff --git a/src/jloptions.c b/src/jloptions.c index d508aa8e45b23..e72e325007d11 100644 --- a/src/jloptions.c +++ b/src/jloptions.c @@ -58,7 +58,7 @@ jl_options_t jl_options = { 0, // quiet #endif JL_OPTIONS_CHECK_BOUNDS_DEFAULT, // check_bounds 1, // deprecation warning - 1, // method overwrite warning + 0, // method overwrite warning 1, // can_inline JL_OPTIONS_POLLY_ON, // polly JL_OPTIONS_FAST_MATH_DEFAULT, diff --git a/test/core.jl b/test/core.jl index e760be057451d..134ec8373345a 100644 --- a/test/core.jl +++ b/test/core.jl @@ -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 @@ -5111,6 +5100,7 @@ m22929_2.x = m22929_1 @test isdefined_22929_1(m22929_2) @test isdefined_22929_x(m22929_2) +<<<<<<< 9f974bf8b47c781e5d89f43c4a278aa84c8c3c34 # Union type sorting for T in ( (Void, Int8), @@ -5185,3 +5175,29 @@ module GlobalDef18933 @test @isdefined sincos @test sincos === Base.sincos end + +let exename = `$(Base.julia_cmd()) --startup-file=no` + for (mac, flag, pfix, msg) in [("@test_nowarn", ``, "_1", ""), + ("@test_warn", `--overwritewarn=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 From ee99f7d59d333cf1d175a885bd659cffa06d4ea3 Mon Sep 17 00:00:00 2001 From: Jeff Bezanson Date: Fri, 11 Aug 2017 12:49:09 -0400 Subject: [PATCH 3/4] update, and enable overwrite warning for sysimg, Pkg.test, and precompile --- Makefile | 2 +- base/loading.jl | 2 +- base/options.jl | 2 +- base/pkg/entry.jl | 1 + src/gf.c | 2 +- src/jloptions.c | 14 +++++++------- src/julia.h | 6 +++--- test/cmdlineargs.jl | 27 +++++++++++++++++++++++++++ test/core.jl | 27 --------------------------- test/misc.jl | 2 +- 10 files changed, 43 insertions(+), 42 deletions(-) diff --git a/Makefile b/Makefile index 3ce18c5d0d42f..b15e234ae8391 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/base/loading.jl b/base/loading.jl index b366015918401..12c0ba917c728 100644 --- a/base/loading.jl +++ b/base/loading.jl @@ -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) diff --git a/base/options.jl b/base/options.jl index 6277032c83e88..32530a17be183 100644 --- a/base/options.jl +++ b/base/options.jl @@ -23,7 +23,7 @@ struct JLOptions debug_level::Int8 check_bounds::Int8 depwarn::Int8 - overwritewarn::Int8 + warn_overwrite::Int8 can_inline::Int8 polly::Int8 fast_math::Int8 diff --git a/base/pkg/entry.jl b/base/pkg/entry.jl index 58487eac71db1..6dc47473cd17b 100644 --- a/base/pkg/entry.jl +++ b/base/pkg/entry.jl @@ -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 ``` diff --git a/src/gf.c b/src/gf.c index 84e1d388ec0a4..210b6cef01ce9 100644 --- a/src/gf.c +++ b/src/gf.c @@ -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 (jl_options.overwritewarn == JL_OPTIONS_DEPWARN_ON) { + 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); diff --git a/src/jloptions.c b/src/jloptions.c index e72e325007d11..ece10e240904a 100644 --- a/src/jloptions.c +++ b/src/jloptions.c @@ -124,7 +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" - " --overwritewarn={yes|no} Enable or disable method overwrite warnings" + " --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" @@ -158,7 +158,7 @@ JL_DLLEXPORT void jl_parse_opts(int *argcp, char ***argvp) opt_output_unopt_bc, opt_output_bc, opt_depwarn, - opt_overwritewarn, + opt_warn_overwrite, opt_inline, opt_polly, opt_math_mode, @@ -204,7 +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 }, - { "overwritewarn", required_argument, 0, opt_overwritewarn }, + { "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 }, @@ -482,13 +482,13 @@ 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_overwritewarn: + case opt_warn_overwrite: if (!strcmp(optarg,"yes")) - jl_options.overwritewarn = JL_OPTIONS_OVERWRITEWARN_ON; + jl_options.warn_overwrite = JL_OPTIONS_WARN_OVERWRITE_ON; else if (!strcmp(optarg,"no")) - jl_options.overwritewarn = JL_OPTIONS_OVERWRITEWARN_OFF; + jl_options.warn_overwrite = JL_OPTIONS_WARN_OVERWRITE_OFF; else - jl_errorf("julia: invalid argument to --overwritewarn={yes|no|} (%s)", optarg); + jl_errorf("julia: invalid argument to --warn-overwrite={yes|no|} (%s)", optarg); break; case opt_inline: if (!strcmp(optarg,"yes")) diff --git a/src/julia.h b/src/julia.h index 27dda02ad5fbd..6a0768575e597 100644 --- a/src/julia.h +++ b/src/julia.h @@ -1692,7 +1692,7 @@ typedef struct { int8_t debug_level; int8_t check_bounds; int8_t depwarn; - int8_t overwritewarn; + int8_t warn_overwrite; int8_t can_inline; int8_t polly; int8_t fast_math; @@ -1753,8 +1753,8 @@ JL_DLLEXPORT int jl_generating_output(void); #define JL_OPTIONS_DEPWARN_ON 1 #define JL_OPTIONS_DEPWARN_ERROR 2 -#define JL_OPTIONS_OVERWRITEWARN_OFF 0 -#define JL_OPTIONS_OVERWRITEWARN_ON 1 +#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 diff --git a/test/cmdlineargs.jl b/test/cmdlineargs.jl index d60b44536bcc0..386504033579e 100644 --- a/test/cmdlineargs.jl +++ b/test/cmdlineargs.jl @@ -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 diff --git a/test/core.jl b/test/core.jl index 134ec8373345a..0818c8cccd80c 100644 --- a/test/core.jl +++ b/test/core.jl @@ -5100,7 +5100,6 @@ m22929_2.x = m22929_1 @test isdefined_22929_1(m22929_2) @test isdefined_22929_x(m22929_2) -<<<<<<< 9f974bf8b47c781e5d89f43c4a278aa84c8c3c34 # Union type sorting for T in ( (Void, Int8), @@ -5175,29 +5174,3 @@ module GlobalDef18933 @test @isdefined sincos @test sincos === Base.sincos end - -let exename = `$(Base.julia_cmd()) --startup-file=no` - for (mac, flag, pfix, msg) in [("@test_nowarn", ``, "_1", ""), - ("@test_warn", `--overwritewarn=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 diff --git a/test/misc.jl b/test/misc.jl index 7ca7084a9fd77..094e8dc0c9328 100644 --- a/test/misc.jl +++ b/test/misc.jl @@ -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 From 1d9d6fa21fc08e070a9622c48d46b13d02466cce Mon Sep 17 00:00:00 2001 From: Jeff Bezanson Date: Fri, 11 Aug 2017 14:04:44 -0400 Subject: [PATCH 4/4] NEWS and doc updates for --warn-overwrite --- NEWS.md | 6 ++++++ doc/man/julia.1 | 4 ++++ doc/src/manual/getting-started.md | 1 + 3 files changed, 11 insertions(+) diff --git a/NEWS.md b/NEWS.md index 81209168d808d..2ce2dacacb9e3 100644 --- a/NEWS.md +++ b/NEWS.md @@ -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 ========================== diff --git a/doc/man/julia.1 b/doc/man/julia.1 index cc77d36e07969..b1f40f9dabc37 100644 --- a/doc/man/julia.1 +++ b/doc/man/julia.1 @@ -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 Generate an object file (including system image data) diff --git a/doc/src/manual/getting-started.md b/doc/src/manual/getting-started.md index d41d6b1bdfa03..42dee20115868 100644 --- a/doc/src/manual/getting-started.md +++ b/doc/src/manual/getting-started.md @@ -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)