ruby-changes:64295
From: Jeremy <ko1@a...>
Date: Sat, 19 Dec 2020 02:54:33 +0900 (JST)
Subject: [ruby-changes:64295] 7e2dbbda35 (master): Use category: :experimental in warnings that are related to experimental features
https://git.ruby-lang.org/ruby.git/commit/?id=7e2dbbda35 From 7e2dbbda357b8c509358a3aa10ff6d588ed819e2 Mon Sep 17 00:00:00 2001 From: Jeremy Evans <code@j...> Date: Wed, 16 Dec 2020 09:02:23 -0800 Subject: Use category: :experimental in warnings that are related to experimental features This adds rb_category_compile_warn in order to emit compiler warnings with categories. Note that Ripper currently ignores the category for these warnings, but by default it ignores the warnings completely, so this shouldn't matter. diff --git a/error.c b/error.c index 7a7d562..ce3dc11 100644 --- a/error.c +++ b/error.c @@ -375,6 +375,20 @@ rb_compile_warning(const char *file, int line, const char *fmt, ...) https://github.com/ruby/ruby/blob/trunk/error.c#L375 rb_write_warning_str(str); } +void +rb_category_compile_warn(rb_warning_category_t category, const char *file, int line, const char *fmt, ...) +{ + VALUE str; + va_list args; + + if (NIL_P(ruby_verbose)) return; + + va_start(args, fmt); + str = warn_vsprintf(NULL, file, line, fmt, args); + va_end(args); + rb_warn_category(str, rb_hash_fetch(warning_category_t_map, INT2NUM(category))); +} + static VALUE warning_string(rb_encoding *enc, const char *fmt, va_list args) { diff --git a/include/ruby/internal/error.h b/include/ruby/internal/error.h index 72ee622..7e9d5c4 100644 --- a/include/ruby/internal/error.h +++ b/include/ruby/internal/error.h @@ -70,12 +70,13 @@ VALUE *rb_ruby_debug_ptr(void); https://github.com/ruby/ruby/blob/trunk/include/ruby/internal/error.h#L70 /* reports if `-W' specified */ PRINTF_ARGS(void rb_warning(const char*, ...), 1, 2); -PRINTF_ARGS(void rb_category_warning(rb_warning_category_t category, const char*, ...), 2, 3); +PRINTF_ARGS(void rb_category_warning(rb_warning_category_t, const char*, ...), 2, 3); PRINTF_ARGS(void rb_compile_warning(const char *, int, const char*, ...), 3, 4); +PRINTF_ARGS(void rb_category_compile_warn(rb_warning_category_t, const char *, int, const char*, ...), 4, 5); PRINTF_ARGS(void rb_sys_warning(const char*, ...), 1, 2); /* reports always */ COLDFUNC PRINTF_ARGS(void rb_warn(const char*, ...), 1, 2); -COLDFUNC PRINTF_ARGS(void rb_category_warn(rb_warning_category_t category, const char*, ...), 2, 3); +COLDFUNC PRINTF_ARGS(void rb_category_warn(rb_warning_category_t, const char*, ...), 2, 3); PRINTF_ARGS(void rb_compile_warn(const char *, int, const char*, ...), 3, 4); RBIMPL_SYMBOL_EXPORT_END() diff --git a/parse.y b/parse.y index 839f9c6..6144fd1 100644 --- a/parse.y +++ b/parse.y @@ -1034,6 +1034,7 @@ static ID id_warn, id_warning, id_gets, id_assoc; https://github.com/ruby/ruby/blob/trunk/parse.y#L1034 # define WARN_ID(i) rb_id2str(i) # define WARN_IVAL(i) i # define PRIsWARN "s" +# define rb_warn0L_experimental(l,fmt) WARN_CALL(WARN_ARGS_L(l, fmt, 1)) # define WARN_ARGS(fmt,n) p->value, id_warn, n, rb_usascii_str_new_lit(fmt) # define WARN_ARGS_L(l,fmt,n) WARN_ARGS(fmt,n) # ifdef HAVE_VA_ARGS_MACRO @@ -1060,6 +1061,7 @@ PRINTF_ARGS(static void ripper_compile_error(struct parser_params*, const char * https://github.com/ruby/ruby/blob/trunk/parse.y#L1061 # define WARN_ARGS(fmt,n) WARN_ARGS_L(p->ruby_sourceline,fmt,n) # define WARN_ARGS_L(l,fmt,n) p->ruby_sourcefile, (l), (fmt) # define WARN_CALL rb_compile_warn +# define rb_warn0L_experimental(l,fmt) rb_category_compile_warn(RB_WARN_CATEGORY_EXPERIMENTAL, WARN_ARGS_L(l, fmt, 1)) # define WARNING_ARGS(fmt,n) WARN_ARGS(fmt,n) # define WARNING_ARGS_L(l,fmt,n) WARN_ARGS_L(l,fmt,n) # define WARNING_CALL rb_compile_warning @@ -4229,7 +4231,7 @@ p_find : p_rest ',' p_args_post ',' p_rest https://github.com/ruby/ruby/blob/trunk/parse.y#L4231 $$ = new_find_pattern_tail(p, $1, $3, $5, &@$); if (rb_warning_category_enabled_p(RB_WARN_CATEGORY_EXPERIMENTAL)) - rb_warn0L(nd_line($$), "Find pattern is experimental, and the behavior may change in future versions of Ruby!"); + rb_warn0L_experimental(nd_line($$), "Find pattern is experimental, and the behavior may change in future versions of Ruby!"); } ; @@ -11955,7 +11957,7 @@ warn_one_line_pattern_matching(struct parser_params *p, NODE *node, NODE *patter https://github.com/ruby/ruby/blob/trunk/parse.y#L11957 if (rb_warning_category_enabled_p(RB_WARN_CATEGORY_EXPERIMENTAL) && !(right_assign && (type == NODE_LASGN || type == NODE_DASGN || type == NODE_DASGN_CURR))) - rb_warn0L(nd_line(node), "One-line pattern matching is experimental, and the behavior may change in future versions of Ruby!"); + rb_warn0L_experimental(nd_line(node), "One-line pattern matching is experimental, and the behavior may change in future versions of Ruby!"); } static NODE* diff --git a/ractor.c b/ractor.c index 0817a1b..89b4f68 100644 --- a/ractor.c +++ b/ractor.c @@ -1394,8 +1394,9 @@ cancel_single_ractor_mode(void) https://github.com/ruby/ruby/blob/trunk/ractor.c#L1394 rb_transient_heap_evacuate(); if (rb_warning_category_enabled_p(RB_WARN_CATEGORY_EXPERIMENTAL)) { - rb_warn("Ractor is experimental, and the behavior may change in future versions of Ruby! " - "Also there are many implementation issues."); + rb_category_warn(RB_WARN_CATEGORY_EXPERIMENTAL, + "Ractor is experimental, and the behavior may change in future versions of Ruby! " + "Also there are many implementation issues."); } ruby_single_main_ractor = NULL; -- cgit v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/