From c0bf4029e3ff0c53bcc8d25a3c881c997aee9209 Mon Sep 17 00:00:00 2001 From: Jemma Issroff Date: Fri, 1 Sep 2023 14:12:50 -0400 Subject: [PATCH 01/95] [ruby/yarp] Print information about type, flags on AST templated code (https://github.com/ruby/yarp/pull/1380) This commit adds the node type and the node flags as comments to the AST templated code. https://github.com/ruby/yarp/commit/f603f2037c --- yarp/templates/include/yarp/ast.h.erb | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/yarp/templates/include/yarp/ast.h.erb b/yarp/templates/include/yarp/ast.h.erb index 4325d403778da6..f7e1d0b503ac22 100644 --- a/yarp/templates/include/yarp/ast.h.erb +++ b/yarp/templates/include/yarp/ast.h.erb @@ -70,8 +70,7 @@ typedef struct yp_node { // existed in the original grammar and ripper, but it's not a 1:1 mapping. yp_node_type_t type; - // This represents any flags on the node. Currently, this is only a newline - // flag + // This represents any flags on the node yp_node_flags_t flags; // This is the location of the node in the source. It's a range of bytes @@ -81,6 +80,15 @@ typedef struct yp_node { <%- nodes.each do |node| -%> // <%= node.name %> +// +// Type: <%= node.type %> +<%- if (node_flags = node.fields.find { |field| field.is_a? YARP::FlagsField }) -%> +// Flags: +<%- found = flags.find { |flag| flag.name == node_flags.kind }.tap { |found| raise "Expected to find #{field.kind}" unless found } -%> +<%- found.values.each do |value| -%> +// YP_<%= found.human.upcase %>_<%= value.name %> +<%- end -%> +<%- end -%> typedef struct yp_<%= node.human %> { yp_node_t base; <%- node.fields.grep_v(YARP::FlagsField).each do |field| -%> From e8b646fe91abd48b68a470d71e3f7dbff6788cf0 Mon Sep 17 00:00:00 2001 From: Jemma Issroff Date: Fri, 1 Sep 2023 14:30:22 -0400 Subject: [PATCH 02/95] [YARP] Implement BackReferenceReadNode, NumberedReferenceReadNode (#8344) --- yarp/yarp_compiler.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/yarp/yarp_compiler.c b/yarp/yarp_compiler.c index cba528d2caaa44..da2206a5989185 100644 --- a/yarp/yarp_compiler.c +++ b/yarp/yarp_compiler.c @@ -472,6 +472,16 @@ yp_compile_node(rb_iseq_t *iseq, const yp_node_t *node, LINK_ANCHOR *const ret, } return; } + case YP_NODE_BACK_REFERENCE_READ_NODE: { + if (!popped) { + // Since a back reference is `$`, ruby represents the ID as the + // an rb_intern on the value after the `$`. + char *char_ptr = (char *)(node->location.start) + 1; + ID backref_val = INT2FIX(rb_intern2(char_ptr, 1)) << 1 | 1; + ADD_INSN2(ret, &dummy_line_node, getspecial, INT2FIX(1), backref_val); + } + return; + } case YP_NODE_BEGIN_NODE: { yp_begin_node_t *begin_node = (yp_begin_node_t *) node; if (begin_node->statements) { @@ -1019,6 +1029,13 @@ yp_compile_node(rb_iseq_t *iseq, const yp_node_t *node, LINK_ANCHOR *const ret, ADD_INSN(ret, &dummy_line_node, putnil); } return; + case YP_NODE_NUMBERED_REFERENCE_READ_NODE: { + if (!popped) { + uint32_t reference_number = ((yp_numbered_reference_read_node_t *)node)->number; + ADD_INSN2(ret, &dummy_line_node, getspecial, INT2FIX(1), INT2FIX(reference_number << 1)); + } + return; + } case YP_NODE_OR_NODE: { yp_or_node_t *or_node = (yp_or_node_t *) node; From 95def300d2202586dafea6cea8ebcc915f116b7a Mon Sep 17 00:00:00 2001 From: Peter Zhu Date: Fri, 1 Sep 2023 15:28:29 -0400 Subject: [PATCH 03/95] Fix flaky test for Process.warmup The test sometimes fails with: ``` 1) Failure: TestProcess#test_warmup_run_major_gc_and_compact [test/ruby/test_process.rb:2712]: <2> expected but was <3>. ``` --- test/ruby/test_process.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/test/ruby/test_process.rb b/test/ruby/test_process.rb index 095ab27f5d2c66..72cbb8072a9f1e 100644 --- a/test/ruby/test_process.rb +++ b/test/ruby/test_process.rb @@ -2706,6 +2706,9 @@ def test_warmup_promote_all_objects_to_oldgen def test_warmup_run_major_gc_and_compact assert_separately([], "#{<<~"begin;"}\n#{<<~'end;'}") begin; + # Run a GC to ensure that we are not in the middle of a GC run + GC.start + major_gc_count = GC.stat(:major_gc_count) compact_count = GC.stat(:compact_count) Process.warmup From 1c622a6b5818a92ba664c3d8292cf01b98083e4e Mon Sep 17 00:00:00 2001 From: Kevin Newton Date: Fri, 1 Sep 2023 16:42:37 -0400 Subject: [PATCH 04/95] [ruby/yarp] Bump to v0.10.0 https://github.com/ruby/yarp/commit/b6164a76d9 --- lib/yarp/yarp.gemspec | 2 +- yarp/extension.h | 2 +- yarp/templates/lib/yarp/serialize.rb.erb | 2 +- yarp/version.h | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/yarp/yarp.gemspec b/lib/yarp/yarp.gemspec index ceea5e8eb6e10b..9603f5b1cd02fa 100644 --- a/lib/yarp/yarp.gemspec +++ b/lib/yarp/yarp.gemspec @@ -2,7 +2,7 @@ Gem::Specification.new do |spec| spec.name = "yarp" - spec.version = "0.9.0" + spec.version = "0.10.0" spec.authors = ["Shopify"] spec.email = ["ruby@shopify.com"] diff --git a/yarp/extension.h b/yarp/extension.h index fc24add420f2f1..ae7db77ca02da3 100644 --- a/yarp/extension.h +++ b/yarp/extension.h @@ -1,7 +1,7 @@ #ifndef YARP_EXT_NODE_H #define YARP_EXT_NODE_H -#define EXPECTED_YARP_VERSION "0.9.0" +#define EXPECTED_YARP_VERSION "0.10.0" #include #include diff --git a/yarp/templates/lib/yarp/serialize.rb.erb b/yarp/templates/lib/yarp/serialize.rb.erb index d54c3119543d99..230522ae2bf9f4 100644 --- a/yarp/templates/lib/yarp/serialize.rb.erb +++ b/yarp/templates/lib/yarp/serialize.rb.erb @@ -14,7 +14,7 @@ end module YARP module Serialize MAJOR_VERSION = 0 - MINOR_VERSION = 9 + MINOR_VERSION = 10 PATCH_VERSION = 0 def self.load(input, serialized) diff --git a/yarp/version.h b/yarp/version.h index a364aec2474f03..60fd830ca7c14b 100644 --- a/yarp/version.h +++ b/yarp/version.h @@ -1,4 +1,4 @@ #define YP_VERSION_MAJOR 0 -#define YP_VERSION_MINOR 9 +#define YP_VERSION_MINOR 10 #define YP_VERSION_PATCH 0 -#define YP_VERSION "0.9.0" +#define YP_VERSION "0.10.0" From 570ebeaee2650d61887438a7f44844461dae1a2c Mon Sep 17 00:00:00 2001 From: git Date: Fri, 1 Sep 2023 20:57:36 +0000 Subject: [PATCH 05/95] Update default gems list at 1c622a6b5818a92ba664c3d8292cf0 [ci skip] --- NEWS.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NEWS.md b/NEWS.md index 3764db7df10cc1..de7591fb540a2d 100644 --- a/NEWS.md +++ b/NEWS.md @@ -96,7 +96,7 @@ The following default gems are updated. * time 0.2.2 * timeout 0.4.0 * uri 0.12.2 -* yarp 0.9.0 +* yarp 0.10.0 The following bundled gems are updated. From d617b1b6309ad974a2fb2169740f3a2969ededa0 Mon Sep 17 00:00:00 2001 From: HParker Date: Thu, 31 Aug 2023 15:36:57 -0700 Subject: [PATCH 06/95] [ruby/yarp] remove reallocs preparing for custom memory management https://github.com/ruby/yarp/commit/bd0b421504 --- yarp/util/yp_newline_list.c | 6 +++++- yarp/util/yp_string_list.c | 5 ++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/yarp/util/yp_newline_list.c b/yarp/util/yp_newline_list.c index 0a2050df059dd5..324d77de0b07b7 100644 --- a/yarp/util/yp_newline_list.c +++ b/yarp/util/yp_newline_list.c @@ -25,8 +25,12 @@ yp_newline_list_init(yp_newline_list_t *list, const uint8_t *start, size_t capac bool yp_newline_list_append(yp_newline_list_t *list, const uint8_t *cursor) { if (list->size == list->capacity) { + size_t * original_offsets = list->offsets; + list->capacity = (list->capacity * 3) / 2; - list->offsets = (size_t *) realloc(list->offsets, list->capacity * sizeof(size_t)); + list->offsets = (size_t *) calloc(list->capacity, sizeof(size_t)); + memcpy(list->offsets, original_offsets, list->size * sizeof(size_t)); + free(original_offsets); if (list->offsets == NULL) return false; } diff --git a/yarp/util/yp_string_list.c b/yarp/util/yp_string_list.c index b03a3d259b1d45..9f58d8a1862e76 100644 --- a/yarp/util/yp_string_list.c +++ b/yarp/util/yp_string_list.c @@ -12,8 +12,11 @@ yp_string_list_init(yp_string_list_t *string_list) { void yp_string_list_append(yp_string_list_t *string_list, yp_string_t *string) { if (string_list->length + 1 > string_list->capacity) { + yp_string_t * original_string = string_list->strings; string_list->capacity *= 2; - string_list->strings = (yp_string_t *) realloc(string_list->strings, string_list->capacity * sizeof(yp_string_t)); + string_list->strings = (yp_string_t *) malloc(string_list->capacity * sizeof(yp_string_t)); + memcpy(string_list->strings, original_string, (string_list->length) * sizeof(yp_string_t)); + free(original_string); } string_list->strings[string_list->length++] = *string; From d99db1199d4318e97a26687571b10f7629604018 Mon Sep 17 00:00:00 2001 From: Kevin Newton Date: Fri, 1 Sep 2023 12:47:37 -0400 Subject: [PATCH 07/95] [ruby/yarp] Update src/util/yp_newline_list.c style https://github.com/ruby/yarp/commit/bd7fc2c946 --- yarp/util/yp_newline_list.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/yarp/util/yp_newline_list.c b/yarp/util/yp_newline_list.c index 324d77de0b07b7..969b8845605019 100644 --- a/yarp/util/yp_newline_list.c +++ b/yarp/util/yp_newline_list.c @@ -25,7 +25,7 @@ yp_newline_list_init(yp_newline_list_t *list, const uint8_t *start, size_t capac bool yp_newline_list_append(yp_newline_list_t *list, const uint8_t *cursor) { if (list->size == list->capacity) { - size_t * original_offsets = list->offsets; + size_t *original_offsets = list->offsets; list->capacity = (list->capacity * 3) / 2; list->offsets = (size_t *) calloc(list->capacity, sizeof(size_t)); From 7f9a2df02bf3fe066788a0cf02803ab26d22c311 Mon Sep 17 00:00:00 2001 From: Kevin Newton Date: Fri, 1 Sep 2023 12:48:03 -0400 Subject: [PATCH 08/95] [ruby/yarp] Update src/util/yp_string_list.c style https://github.com/ruby/yarp/commit/e4af2b3bc2 --- yarp/util/yp_string_list.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/yarp/util/yp_string_list.c b/yarp/util/yp_string_list.c index 9f58d8a1862e76..3b2b4381c500e6 100644 --- a/yarp/util/yp_string_list.c +++ b/yarp/util/yp_string_list.c @@ -12,7 +12,7 @@ yp_string_list_init(yp_string_list_t *string_list) { void yp_string_list_append(yp_string_list_t *string_list, yp_string_t *string) { if (string_list->length + 1 > string_list->capacity) { - yp_string_t * original_string = string_list->strings; + yp_string_t *original_string = string_list->strings; string_list->capacity *= 2; string_list->strings = (yp_string_t *) malloc(string_list->capacity * sizeof(yp_string_t)); memcpy(string_list->strings, original_string, (string_list->length) * sizeof(yp_string_t)); From 95308988b6f70c04c43015a78c93b3f876da5958 Mon Sep 17 00:00:00 2001 From: Jemma Issroff Date: Fri, 1 Sep 2023 17:20:03 -0400 Subject: [PATCH 09/95] [YARP] Implement Compiling for And / Or / Operator Write Nodes (#8352) --- test/yarp/compiler_test.rb | 49 ++++ yarp/yarp_compiler.c | 466 +++++++++++++++++++++++++++++++++---- 2 files changed, 465 insertions(+), 50 deletions(-) diff --git a/test/yarp/compiler_test.rb b/test/yarp/compiler_test.rb index 668908d4230606..7188defa7f2c39 100644 --- a/test/yarp/compiler_test.rb +++ b/test/yarp/compiler_test.rb @@ -81,6 +81,19 @@ def test_ClassVariableWriteNode assert_equal 1, compile("class YARP::CompilerTest; @@yct = 1; end") end + def test_ClassVariableAndWriteNode + assert_equal 1, compile("class YARP::CompilerTest; @@yct = 0; @@yct &&= 1; end") + end + + def test_ClassVariableOrWriteNode + assert_equal 1, compile("class YARP::CompilerTest; @@yct = 1; @@yct ||= 0; end") + assert_equal 1, compile("class YARP::CompilerTest; @@yct = nil; @@yct ||= 1; end") + end + + def test_ClassVariableOperatorWriteNode + assert_equal 1, compile("class YARP::CompilerTest; @@yct = 0; @@yct += 1; end") + end + def test_ConstantWriteNode assert_equal 1, compile("YCT = 1") end @@ -93,14 +106,50 @@ def test_GlobalVariableWriteNode assert_equal 1, compile("$yct = 1") end + def test_GlobalVariableAndWriteNode + assert_equal 1, compile("$yct = 0; $yct &&= 1") + end + + def test_GlobalVariableOrWriteNode + assert_equal 1, compile("$yct ||= 1") + end + + def test_GlobalVariableOperatorWriteNode + assert_equal 1, compile("$yct = 0; $yct += 1") + end + def test_InstanceVariableWriteNode assert_equal 1, compile("class YARP::CompilerTest; @yct = 1; end") end + def test_InstanceVariableAndWriteNode + assert_equal 1, compile("@yct = 0; @yct &&= 1") + end + + def test_InstanceVariableOrWriteNode + assert_equal 1, compile("@yct ||= 1") + end + + def test_InstanceVariableOperatorWriteNode + assert_equal 1, compile("@yct = 0; @yct += 1") + end + def test_LocalVariableWriteNode assert_equal 1, compile("yct = 1") end + def test_LocalVariableAndWriteNode + assert_equal 1, compile("yct = 0; yct &&= 1") + end + + def test_LocalVariableOrWriteNode + assert_equal 1, compile("yct ||= 1") + end + + def test_LocalVariableOperatorWriteNode + assert_equal 1, compile("yct = 0; yct += 1") + end + ############################################################################ # String-likes # ############################################################################ diff --git a/yarp/yarp_compiler.c b/yarp/yarp_compiler.c index da2206a5989185..3ff95e8816c910 100644 --- a/yarp/yarp_compiler.c +++ b/yarp/yarp_compiler.c @@ -334,6 +334,31 @@ yp_compile_while(rb_iseq_t *iseq, int lineno, yp_node_flags_t flags, enum yp_nod return; } +static int +yp_lookup_local_index(rb_iseq_t *iseq, yp_compile_context_t *compile_context, yp_constant_id_t constant_id) +{ + st_data_t local_index; + + int num_params = ISEQ_BODY(iseq)->param.size; + + if (!st_lookup(compile_context->index_lookup_table, constant_id, &local_index)) { + rb_bug("This local does not exist"); + } + + return num_params - (int)local_index; +} + +static int +yp_lookup_local_index_with_depth(rb_iseq_t *iseq, yp_compile_context_t *compile_context, yp_constant_id_t constant_id, uint32_t depth) +{ + for(uint32_t i = 0; i < depth; i++) { + compile_context = compile_context->previous; + iseq = (rb_iseq_t *)ISEQ_BODY(iseq)->parent_iseq; + } + + return yp_lookup_local_index(iseq, compile_context, constant_id); +} + static rb_iseq_t * yp_new_child_iseq(rb_iseq_t *iseq, yp_scope_node_t * node, yp_parser_t *parser, VALUE name, const rb_iseq_t *parent, enum rb_iseq_type type, int line_no) @@ -586,18 +611,115 @@ yp_compile_node(rb_iseq_t *iseq, const yp_node_t *node, LINK_ANCHOR *const ret, } return; } - case YP_NODE_CLASS_VARIABLE_READ_NODE: - if (!popped) { - ID cvar_name = parse_node_symbol((yp_node_t *)node); - ADD_INSN2( - ret, - &dummy_line_node, - getclassvariable, - ID2SYM(cvar_name), - get_cvar_ic_value(iseq, cvar_name) - ); - } - return; + case YP_NODE_CLASS_VARIABLE_AND_WRITE_NODE: { + yp_class_variable_and_write_node_t *class_variable_and_write_node = (yp_class_variable_and_write_node_t*) node; + + LABEL *end_label = NEW_LABEL(lineno); + + ID class_variable_name_id = compile_context->constants[class_variable_and_write_node->name - 1]; + VALUE class_variable_name_val = ID2SYM(class_variable_name_id); + + ADD_INSN2(ret, &dummy_line_node, getclassvariable, + class_variable_name_val, + get_cvar_ic_value(iseq, class_variable_name_id)); + + if (!popped) { + ADD_INSN(ret, &dummy_line_node, dup); + } + + ADD_INSNL(ret, &dummy_line_node, branchunless, end_label); + + if (!popped) { + ADD_INSN(ret, &dummy_line_node, pop); + } + + yp_compile_node(iseq, class_variable_and_write_node->value, ret, src, false, compile_context); + + if (!popped) { + ADD_INSN(ret, &dummy_line_node, dup); + } + + ADD_INSN2(ret, &dummy_line_node, setclassvariable, + class_variable_name_val, + get_cvar_ic_value(iseq, class_variable_name_id)); + ADD_LABEL(ret, end_label); + + return; + } + case YP_NODE_CLASS_VARIABLE_OPERATOR_WRITE_NODE: { + yp_class_variable_operator_write_node_t *class_variable_operator_write_node = (yp_class_variable_operator_write_node_t*) node; + + ID class_variable_name_id = compile_context->constants[class_variable_operator_write_node->name - 1]; + VALUE class_variable_name_val = ID2SYM(class_variable_name_id); + + ADD_INSN2(ret, &dummy_line_node, getclassvariable, + class_variable_name_val, + get_cvar_ic_value(iseq, class_variable_name_id)); + + yp_compile_node(iseq, class_variable_operator_write_node->value, ret, src, false, compile_context); + ID method_id = compile_context->constants[class_variable_operator_write_node->operator - 1]; + + int flags = VM_CALL_ARGS_SIMPLE; + ADD_SEND_WITH_FLAG(ret, &dummy_line_node, method_id, INT2NUM(1), INT2FIX(flags)); + + if (!popped) { + ADD_INSN(ret, &dummy_line_node, dup); + } + + ADD_INSN2(ret, &dummy_line_node, setclassvariable, + class_variable_name_val, + get_cvar_ic_value(iseq, class_variable_name_id)); + + return; + } + case YP_NODE_CLASS_VARIABLE_OR_WRITE_NODE: { + yp_class_variable_or_write_node_t *class_variable_or_write_node = (yp_class_variable_or_write_node_t*) node; + + LABEL *end_label = NEW_LABEL(lineno); + + ID class_variable_name_id = compile_context->constants[class_variable_or_write_node->name - 1]; + VALUE class_variable_name_val = ID2SYM(class_variable_name_id); + + ADD_INSN2(ret, &dummy_line_node, getclassvariable, + class_variable_name_val, + get_cvar_ic_value(iseq, class_variable_name_id)); + + if (!popped) { + ADD_INSN(ret, &dummy_line_node, dup); + } + + ADD_INSNL(ret, &dummy_line_node, branchif, end_label); + + if (!popped) { + ADD_INSN(ret, &dummy_line_node, pop); + } + + yp_compile_node(iseq, class_variable_or_write_node->value, ret, src, false, compile_context); + + if (!popped) { + ADD_INSN(ret, &dummy_line_node, dup); + } + + ADD_INSN2(ret, &dummy_line_node, setclassvariable, + class_variable_name_val, + get_cvar_ic_value(iseq, class_variable_name_id)); + ADD_LABEL(ret, end_label); + + return; + } + case YP_NODE_CLASS_VARIABLE_READ_NODE: { + if (!popped) { + ID cvar_name = parse_node_symbol((yp_node_t *)node); + ADD_INSN2( + ret, + &dummy_line_node, + getclassvariable, + ID2SYM(cvar_name), + get_cvar_ic_value(iseq, cvar_name) + ); + } + return; + } case YP_NODE_CLASS_VARIABLE_WRITE_NODE: { yp_class_variable_write_node_t *write_node = (yp_class_variable_write_node_t *) node; yp_compile_node(iseq, write_node->value, ret, src, false, compile_context); @@ -675,9 +797,7 @@ yp_compile_node(rb_iseq_t *iseq, const yp_node_t *node, LINK_ANCHOR *const ret, yp_defined_node_t *defined_node = (yp_defined_node_t *)node; // TODO: Correct defined_type enum defined_type dtype = DEFINED_CONST; - VALUE sym; - - sym = parse_number(defined_node->value); + VALUE sym = parse_number(defined_node->value); ADD_INSN3(ret, &dummy_line_node, defined, INT2FIX(dtype), sym, rb_iseq_defined_string(dtype)); return; @@ -747,12 +867,101 @@ yp_compile_node(rb_iseq_t *iseq, const yp_node_t *node, LINK_ANCHOR *const ret, } return; } - case YP_NODE_GLOBAL_VARIABLE_READ_NODE: - if (!popped) { - ID gvar_name = parse_node_symbol((yp_node_t *)node); - ADD_INSN1(ret, &dummy_line_node, getglobal, ID2SYM(gvar_name)); - } - return; + case YP_NODE_GLOBAL_VARIABLE_AND_WRITE_NODE: { + yp_global_variable_and_write_node_t *global_variable_and_write_node = (yp_global_variable_and_write_node_t*) node; + + LABEL *end_label = NEW_LABEL(lineno); + + VALUE global_variable_name = ID2SYM(parse_location_symbol(&global_variable_and_write_node->name_loc)); + ADD_INSN1(ret, &dummy_line_node, getglobal, global_variable_name); + + if (!popped) { + ADD_INSN(ret, &dummy_line_node, dup); + } + + ADD_INSNL(ret, &dummy_line_node, branchunless, end_label); + + if (!popped) { + ADD_INSN(ret, &dummy_line_node, pop); + } + + yp_compile_node(iseq, global_variable_and_write_node->value, ret, src, false, compile_context); + + if (!popped) { + ADD_INSN(ret, &dummy_line_node, dup); + } + + ADD_INSN1(ret, &dummy_line_node, setglobal, global_variable_name); + ADD_LABEL(ret, end_label); + + return; + } + case YP_NODE_GLOBAL_VARIABLE_OPERATOR_WRITE_NODE: { + yp_global_variable_operator_write_node_t *global_variable_operator_write_node = (yp_global_variable_operator_write_node_t*) node; + + ID global_variable_name = parse_location_symbol(&global_variable_operator_write_node->name_loc); + ADD_INSN1(ret, &dummy_line_node, getglobal, ID2SYM(global_variable_name)); + + yp_compile_node(iseq, global_variable_operator_write_node->value, ret, src, false, compile_context); + ID method_id = compile_context->constants[global_variable_operator_write_node->operator - 1]; + + int flags = VM_CALL_ARGS_SIMPLE; + ADD_SEND_WITH_FLAG(ret, &dummy_line_node, method_id, INT2NUM(1), INT2FIX(flags)); + + + if (!popped) { + ADD_INSN(ret, &dummy_line_node, dup); + } + + ADD_INSN1(ret, &dummy_line_node, setglobal, ID2SYM(global_variable_name)); + + return; + } + case YP_NODE_GLOBAL_VARIABLE_OR_WRITE_NODE: { + yp_global_variable_or_write_node_t *global_variable_or_write_node = (yp_global_variable_or_write_node_t*) node; + + LABEL *set_label= NEW_LABEL(lineno); + LABEL *end_label = NEW_LABEL(lineno); + + ADD_INSN(ret, &dummy_line_node, putnil); + VALUE global_variable_name = ID2SYM(parse_location_symbol(&global_variable_or_write_node->name_loc)); + + ADD_INSN3(ret, &dummy_line_node, defined, INT2FIX(DEFINED_GVAR), global_variable_name, Qtrue); + + ADD_INSNL(ret, &dummy_line_node, branchunless, set_label); + + ADD_INSN1(ret, &dummy_line_node, getglobal, global_variable_name); + + if (!popped) { + ADD_INSN(ret, &dummy_line_node, dup); + } + + ADD_INSNL(ret, &dummy_line_node, branchif, end_label); + + if (!popped) { + ADD_INSN(ret, &dummy_line_node, pop); + } + + ADD_LABEL(ret, set_label); + yp_compile_node(iseq, global_variable_or_write_node->value, ret, src, false, compile_context); + + if (!popped) { + ADD_INSN(ret, &dummy_line_node, dup); + } + + ADD_INSN1(ret, &dummy_line_node, setglobal, global_variable_name); + ADD_LABEL(ret, end_label); + + return; + } + case YP_NODE_GLOBAL_VARIABLE_READ_NODE: { + VALUE global_variable_name = ID2SYM(parse_location_symbol((yp_location_t *)(&node->location))); + ADD_INSN1(ret, &dummy_line_node, getglobal, global_variable_name); + if (popped) { + ADD_INSN(ret, &dummy_line_node, pop); + } + return; + } case YP_NODE_GLOBAL_VARIABLE_WRITE_NODE: { yp_global_variable_write_node_t *write_node = (yp_global_variable_write_node_t *) node; yp_compile_node(iseq, write_node->value, ret, src, false, compile_context); @@ -806,6 +1015,103 @@ yp_compile_node(rb_iseq_t *iseq, const yp_node_t *node, LINK_ANCHOR *const ret, } return; } + case YP_NODE_INSTANCE_VARIABLE_AND_WRITE_NODE: { + yp_instance_variable_and_write_node_t *instance_variable_and_write_node = (yp_instance_variable_and_write_node_t*) node; + + LABEL *end_label = NEW_LABEL(lineno); + + ID instance_variable_name_id = compile_context->constants[instance_variable_and_write_node->name - 1]; + VALUE instance_variable_name_val = ID2SYM(instance_variable_name_id); + + ADD_INSN2(ret, &dummy_line_node, getinstancevariable, + instance_variable_name_val, + get_ivar_ic_value(iseq, instance_variable_name_id)); + + if (!popped) { + ADD_INSN(ret, &dummy_line_node, dup); + } + + ADD_INSNL(ret, &dummy_line_node, branchunless, end_label); + + if (!popped) { + ADD_INSN(ret, &dummy_line_node, pop); + } + + yp_compile_node(iseq, instance_variable_and_write_node->value, ret, src, false, compile_context); + + if (!popped) { + ADD_INSN(ret, &dummy_line_node, dup); + } + + ADD_INSN2(ret, &dummy_line_node, setinstancevariable, + instance_variable_name_val, + get_ivar_ic_value(iseq, instance_variable_name_id)); + ADD_LABEL(ret, end_label); + + return; + } + case YP_NODE_INSTANCE_VARIABLE_OPERATOR_WRITE_NODE: { + yp_instance_variable_operator_write_node_t *instance_variable_operator_write_node = (yp_instance_variable_operator_write_node_t*) node; + + ID instance_variable_name_id = compile_context->constants[instance_variable_operator_write_node->name - 1]; + VALUE instance_variable_name_val = ID2SYM(instance_variable_name_id); + + ADD_INSN2(ret, &dummy_line_node, getinstancevariable, + instance_variable_name_val, + get_ivar_ic_value(iseq, instance_variable_name_id)); + + yp_compile_node(iseq, instance_variable_operator_write_node->value, ret, src, false, compile_context); + ID method_id = compile_context->constants[instance_variable_operator_write_node->operator - 1]; + + int flags = VM_CALL_ARGS_SIMPLE; + ADD_SEND_WITH_FLAG(ret, &dummy_line_node, method_id, INT2NUM(1), INT2FIX(flags)); + + if (!popped) { + ADD_INSN(ret, &dummy_line_node, dup); + } + + ADD_INSN2(ret, &dummy_line_node, setinstancevariable, + instance_variable_name_val, + get_ivar_ic_value(iseq, instance_variable_name_id)); + + return; + } + case YP_NODE_INSTANCE_VARIABLE_OR_WRITE_NODE: { + yp_instance_variable_or_write_node_t *instance_variable_or_write_node = (yp_instance_variable_or_write_node_t*) node; + + LABEL *end_label = NEW_LABEL(lineno); + + ID instance_variable_name_id = compile_context->constants[instance_variable_or_write_node->name - 1]; + VALUE instance_variable_name_val = ID2SYM(instance_variable_name_id); + + ADD_INSN2(ret, &dummy_line_node, getinstancevariable, + instance_variable_name_val, + get_ivar_ic_value(iseq, instance_variable_name_id)); + + + if (!popped) { + ADD_INSN(ret, &dummy_line_node, dup); + } + + ADD_INSNL(ret, &dummy_line_node, branchif, end_label); + + if (!popped) { + ADD_INSN(ret, &dummy_line_node, pop); + } + + yp_compile_node(iseq, instance_variable_or_write_node->value, ret, src, false, compile_context); + + if (!popped) { + ADD_INSN(ret, &dummy_line_node, dup); + } + + ADD_INSN2(ret, &dummy_line_node, setinstancevariable, + instance_variable_name_val, + get_ivar_ic_value(iseq, instance_variable_name_id)); + ADD_LABEL(ret, end_label); + + return; + } case YP_NODE_INSTANCE_VARIABLE_READ_NODE: { if (!popped) { ID ivar_name = parse_node_symbol((yp_node_t *)node); @@ -922,26 +1228,101 @@ yp_compile_node(rb_iseq_t *iseq, const yp_node_t *node, LINK_ANCHOR *const ret, } return; } - case YP_NODE_LOCAL_VARIABLE_READ_NODE: { - yp_local_variable_read_node_t *local_read_node = (yp_local_variable_read_node_t *) node; + case YP_NODE_LOCAL_VARIABLE_AND_WRITE_NODE: { + yp_local_variable_and_write_node_t *local_variable_and_write_node = (yp_local_variable_and_write_node_t*) node; + + LABEL *end_label = NEW_LABEL(lineno); + + yp_constant_id_t constant_id = local_variable_and_write_node->name; + int depth = local_variable_and_write_node->depth; + int local_index = yp_lookup_local_index_with_depth(iseq, compile_context, constant_id, depth); + ADD_GETLOCAL(ret, &dummy_line_node, local_index, depth); + + if (!popped) { + ADD_INSN(ret, &dummy_line_node, dup); + } + + ADD_INSNL(ret, &dummy_line_node, branchunless, end_label); + + if (!popped) { + ADD_INSN(ret, &dummy_line_node, pop); + } + + yp_compile_node(iseq, local_variable_and_write_node->value, ret, src, false, compile_context); + + if (!popped) { + ADD_INSN(ret, &dummy_line_node, dup); + } + + ADD_SETLOCAL(ret, &dummy_line_node, local_index, depth); + ADD_LABEL(ret, end_label); + + return; + } + case YP_NODE_LOCAL_VARIABLE_OPERATOR_WRITE_NODE: { + yp_local_variable_operator_write_node_t *local_variable_operator_write_node = (yp_local_variable_operator_write_node_t*) node; + + yp_constant_id_t constant_id = local_variable_operator_write_node->name; + + int depth = local_variable_operator_write_node->depth; + int local_index = yp_lookup_local_index_with_depth(iseq, compile_context, constant_id, depth); + ADD_GETLOCAL(ret, &dummy_line_node, local_index, depth); + + yp_compile_node(iseq, local_variable_operator_write_node->value, ret, src, false, compile_context); + ID method_id = compile_context->constants[local_variable_operator_write_node->operator - 1]; + + int flags = VM_CALL_ARGS_SIMPLE | VM_CALL_FCALL | VM_CALL_VCALL; + ADD_SEND_WITH_FLAG(ret, &dummy_line_node, method_id, INT2NUM(1), INT2FIX(flags)); - yp_constant_id_t constant_id = local_read_node->name; - st_data_t local_index; + if (!popped) { + ADD_INSN(ret, &dummy_line_node, dup); + } + + ADD_SETLOCAL(ret, &dummy_line_node, local_index, depth); + + return; + } + case YP_NODE_LOCAL_VARIABLE_OR_WRITE_NODE: { + yp_local_variable_or_write_node_t *local_variable_or_write_node = (yp_local_variable_or_write_node_t*) node; + + LABEL *set_label= NEW_LABEL(lineno); + LABEL *end_label = NEW_LABEL(lineno); - for(uint32_t i = 0; i < local_read_node->depth; i++) { - compile_context = compile_context->previous; - iseq = (rb_iseq_t *)ISEQ_BODY(iseq)->parent_iseq; + ADD_INSN1(ret, &dummy_line_node, putobject, Qtrue); + ADD_INSNL(ret, &dummy_line_node, branchunless, set_label); + + yp_constant_id_t constant_id = local_variable_or_write_node->name; + int depth = local_variable_or_write_node->depth; + int local_index = yp_lookup_local_index_with_depth(iseq, compile_context, constant_id, depth); + ADD_GETLOCAL(ret, &dummy_line_node, local_index, depth); + + if (!popped) { + ADD_INSN(ret, &dummy_line_node, dup); } - int num_params = ISEQ_BODY(iseq)->param.size; + ADD_INSNL(ret, &dummy_line_node, branchif, end_label); - if (!st_lookup(compile_context->index_lookup_table, constant_id, &local_index)) { - rb_bug("This local does not exist"); + if (!popped) { + ADD_INSN(ret, &dummy_line_node, pop); } - int index = num_params - (int)local_index; + ADD_LABEL(ret, set_label); + yp_compile_node(iseq, local_variable_or_write_node->value, ret, src, false, compile_context); if (!popped) { + ADD_INSN(ret, &dummy_line_node, dup); + } + + ADD_SETLOCAL(ret, &dummy_line_node, local_index, depth); + ADD_LABEL(ret, end_label); + + return; + } + case YP_NODE_LOCAL_VARIABLE_READ_NODE: { + yp_local_variable_read_node_t *local_read_node = (yp_local_variable_read_node_t *) node; + + if (!popped) { + int index = yp_lookup_local_index(iseq, compile_context, local_read_node->name); ADD_GETLOCAL(ret, &dummy_line_node, index, local_read_node->depth); } return; @@ -955,14 +1336,7 @@ yp_compile_node(rb_iseq_t *iseq, const yp_node_t *node, LINK_ANCHOR *const ret, } yp_constant_id_t constant_id = local_write_node->name; - size_t stack_index; - - if (!st_lookup(compile_context->index_lookup_table, constant_id, &stack_index)) { - rb_bug("This local doesn't exist"); - } - - unsigned int num_params = ISEQ_BODY(iseq)->param.size; - size_t index = num_params - stack_index; + int index = yp_lookup_local_index(iseq, compile_context, constant_id); ADD_SETLOCAL(ret, &dummy_line_node, (int)index, local_write_node->depth); return; @@ -984,7 +1358,7 @@ yp_compile_node(rb_iseq_t *iseq, const yp_node_t *node, LINK_ANCHOR *const ret, const int flags = VM_DEFINECLASS_TYPE_MODULE | yp_compile_class_path(ret, iseq, module_node->constant_path, &dummy_line_node, src, popped, compile_context); - ADD_INSN (ret, &dummy_line_node, putnil); + ADD_INSN(ret, &dummy_line_node, putnil); ADD_INSN3(ret, &dummy_line_node, defineclass, ID2SYM(module_id), module_iseq, INT2FIX(flags)); RB_OBJ_WRITTEN(iseq, Qundef, (VALUE)module_iseq); @@ -1059,15 +1433,7 @@ yp_compile_node(rb_iseq_t *iseq, const yp_node_t *node, LINK_ANCHOR *const ret, yp_optional_parameter_node_t *optional_parameter_node = (yp_optional_parameter_node_t *)node; yp_compile_node(iseq, optional_parameter_node->value, ret, src, false, compile_context); - yp_constant_id_t constant_id = optional_parameter_node->name; - - size_t param_number; - if (!st_lookup(compile_context->index_lookup_table, constant_id, ¶m_number)) { - rb_bug("This local doesn't exist"); - } - - unsigned int num_params = ISEQ_BODY(iseq)->param.size; - int index = (int) (num_params - param_number); + int index = yp_lookup_local_index(iseq, compile_context, optional_parameter_node->name); ADD_SETLOCAL(ret, &dummy_line_node, index, 0); From d1f83c37f890e5345e68853c5e268975d4396ffc Mon Sep 17 00:00:00 2001 From: Peter Zhu Date: Fri, 1 Sep 2023 17:48:55 -0400 Subject: [PATCH 10/95] Try to fix flaky test for Process.warmup The test sometimes fails with: ``` 1) Failure: TestProcess#test_warmup_frees_pages [test/ruby/test_process.rb:2749]: <0> expected but was <1>. ``` I think there's a page with an object that needs finalization, so run GC to clear that object. --- test/ruby/test_process.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/ruby/test_process.rb b/test/ruby/test_process.rb index 72cbb8072a9f1e..9cef299b6660b1 100644 --- a/test/ruby/test_process.rb +++ b/test/ruby/test_process.rb @@ -2732,6 +2732,8 @@ def test_warmup_precompute_string_coderange def test_warmup_frees_pages assert_separately([{"RUBY_GC_HEAP_FREE_SLOTS_MAX_RATIO" => "1.0"}, "-W0"], "#{<<~"begin;"}\n#{<<~'end;'}") begin; + GC.start + TIMES = 10_000 ary = Array.new(TIMES) TIMES.times do |i| From c666077182e3408a6b8a3e83789f60d6cee30c70 Mon Sep 17 00:00:00 2001 From: Kevin Newton Date: Fri, 1 Sep 2023 09:40:08 -0400 Subject: [PATCH 11/95] [ruby/yarp] Add global variables to the constant pool https://github.com/ruby/yarp/commit/b48067b067 --- lib/yarp/desugar_visitor.rb | 6 +-- test/yarp/errors_test.rb | 4 +- test/yarp/snapshots/alias.txt | 6 +-- test/yarp/snapshots/global_variables.txt | 40 +++++++++---------- test/yarp/snapshots/methods.txt | 2 +- test/yarp/snapshots/patterns.txt | 2 +- test/yarp/snapshots/regex.txt | 2 +- .../seattlerb/alias_gvar_backref.txt | 2 +- test/yarp/snapshots/seattlerb/bug202.txt | 7 +++- test/yarp/snapshots/seattlerb/case_in.txt | 2 +- test/yarp/snapshots/strings.txt | 2 +- .../unparser/corpus/literal/alias.txt | 4 +- .../unparser/corpus/literal/assignment.txt | 11 +++-- .../unparser/corpus/literal/dstr.txt | 2 +- .../unparser/corpus/literal/literal.txt | 2 +- .../unparser/corpus/literal/variables.txt | 2 +- .../unparser/corpus/semantic/dstr.txt | 2 +- test/yarp/snapshots/variables.txt | 8 ++-- test/yarp/snapshots/whitequark/alias_gvar.txt | 6 +-- test/yarp/snapshots/whitequark/gvar.txt | 2 +- test/yarp/snapshots/whitequark/gvasgn.txt | 7 +++- .../yarp/snapshots/whitequark/string_dvar.txt | 2 +- yarp/config.yml | 14 +++++++ yarp/yarp.c | 39 ++++++++++++------ 24 files changed, 111 insertions(+), 65 deletions(-) diff --git a/lib/yarp/desugar_visitor.rb b/lib/yarp/desugar_visitor.rb index a988449dc07a78..9aabda5939d7f9 100644 --- a/lib/yarp/desugar_visitor.rb +++ b/lib/yarp/desugar_visitor.rb @@ -62,7 +62,7 @@ def visit_constant_operator_write_node(node) # # $foo && $foo = bar def visit_global_variable_and_write_node(node) - desugar_and_write_node(node, GlobalVariableReadNode, GlobalVariableWriteNode) + desugar_and_write_node(node, GlobalVariableReadNode, GlobalVariableWriteNode, arguments: [node.name]) end # $foo ||= bar @@ -71,7 +71,7 @@ def visit_global_variable_and_write_node(node) # # defined?($foo) ? $foo : $foo = bar def visit_global_variable_or_write_node(node) - desugar_or_write_defined_node(node, GlobalVariableReadNode, GlobalVariableWriteNode) + desugar_or_write_defined_node(node, GlobalVariableReadNode, GlobalVariableWriteNode, arguments: [node.name]) end # $foo += bar @@ -80,7 +80,7 @@ def visit_global_variable_or_write_node(node) # # $foo = $foo + bar def visit_global_variable_operator_write_node(node) - desugar_operator_write_node(node, GlobalVariableReadNode, GlobalVariableWriteNode) + desugar_operator_write_node(node, GlobalVariableReadNode, GlobalVariableWriteNode, arguments: [node.name]) end # @foo &&= bar diff --git a/test/yarp/errors_test.rb b/test/yarp/errors_test.rb index 2af3c605e4b4cf..e1c40e11cb297c 100644 --- a/test/yarp/errors_test.rb +++ b/test/yarp/errors_test.rb @@ -1006,8 +1006,8 @@ def test_dont_allow_setting_to_back_and_nth_reference expected = BeginNode( Location(), StatementsNode([ - GlobalVariableWriteNode(Location(), NilNode(), Location()), - GlobalVariableWriteNode(Location(), NilNode(), Location()) + GlobalVariableWriteNode(:$+, Location(), NilNode(), Location()), + GlobalVariableWriteNode(:$1466, Location(), NilNode(), Location()) ]), nil, nil, diff --git a/test/yarp/snapshots/alias.txt b/test/yarp/snapshots/alias.txt index 639311e64abb28..224c2069a58f35 100644 --- a/test/yarp/snapshots/alias.txt +++ b/test/yarp/snapshots/alias.txt @@ -31,7 +31,7 @@ ProgramNode(0...199)( (61...66) ), AliasNode(86...97)( - GlobalVariableReadNode(92...94)(), + GlobalVariableReadNode(92...94)(:$a), BackReferenceReadNode(95...97)(), (86...91) ), @@ -41,8 +41,8 @@ ProgramNode(0...199)( (99...104) ), AliasNode(114...129)( - GlobalVariableReadNode(120...124)(), - GlobalVariableReadNode(125...129)(), + GlobalVariableReadNode(120...124)(:$foo), + GlobalVariableReadNode(125...129)(:$bar), (114...119) ), AliasNode(131...143)( diff --git a/test/yarp/snapshots/global_variables.txt b/test/yarp/snapshots/global_variables.txt index d0a9f782e03726..578f02e9b81519 100644 --- a/test/yarp/snapshots/global_variables.txt +++ b/test/yarp/snapshots/global_variables.txt @@ -1,30 +1,30 @@ ProgramNode(0...349)( [], StatementsNode(0...349)( - [GlobalVariableReadNode(0...16)(), - GlobalVariableReadNode(18...20)(), - GlobalVariableReadNode(22...25)(), - GlobalVariableReadNode(27...37)(), - GlobalVariableReadNode(39...45)(), - GlobalVariableReadNode(47...54)(), - GlobalVariableReadNode(56...63)(), - GlobalVariableReadNode(65...67)(), - GlobalVariableReadNode(69...71)(), - GlobalVariableReadNode(73...75)(), + [GlobalVariableReadNode(0...16)(:$global_variable), + GlobalVariableReadNode(18...20)(:$_), + GlobalVariableReadNode(22...25)(:$-w), + GlobalVariableReadNode(27...37)(:$LOAD_PATH), + GlobalVariableReadNode(39...45)(:$stdin), + GlobalVariableReadNode(47...54)(:$stdout), + GlobalVariableReadNode(56...63)(:$stderr), + GlobalVariableReadNode(65...67)(:$!), + GlobalVariableReadNode(69...71)(:$?), + GlobalVariableReadNode(73...75)(:$~), BackReferenceReadNode(77...79)(), BackReferenceReadNode(81...83)(), BackReferenceReadNode(85...87)(), BackReferenceReadNode(89...91)(), - GlobalVariableReadNode(93...95)(), - GlobalVariableReadNode(97...99)(), - GlobalVariableReadNode(101...103)(), - GlobalVariableReadNode(105...111)(), - GlobalVariableReadNode(113...122)(), - GlobalVariableReadNode(124...126)(), - GlobalVariableReadNode(128...131)(), - GlobalVariableReadNode(133...149)(), - GlobalVariableReadNode(151...159)(), - GlobalVariableReadNode(161...164)(), + GlobalVariableReadNode(93...95)(:$:), + GlobalVariableReadNode(97...99)(:$;), + GlobalVariableReadNode(101...103)(:$,), + GlobalVariableReadNode(105...111)(:$DEBUG), + GlobalVariableReadNode(113...122)(:$FILENAME), + GlobalVariableReadNode(124...126)(:$0), + GlobalVariableReadNode(128...131)(:$-0), + GlobalVariableReadNode(133...149)(:$LOADED_FEATURES), + GlobalVariableReadNode(151...159)(:$VERBOSE), + GlobalVariableReadNode(161...164)(:$-K), SymbolNode(166...183)((166...167), (167...183), nil, "$global_variable"), SymbolNode(185...188)((185...186), (186...188), nil, "$_"), SymbolNode(190...194)((190...191), (191...194), nil, "$-w"), diff --git a/test/yarp/snapshots/methods.txt b/test/yarp/snapshots/methods.txt index 79d11f10381466..15042a2ce89b7e 100644 --- a/test/yarp/snapshots/methods.txt +++ b/test/yarp/snapshots/methods.txt @@ -173,7 +173,7 @@ ProgramNode(0...1194)( ), DefNode(161...175)( (170...171), - GlobalVariableReadNode(165...169)(), + GlobalVariableReadNode(165...169)(:$var), nil, nil, [], diff --git a/test/yarp/snapshots/patterns.txt b/test/yarp/snapshots/patterns.txt index 01292cbf3caabd..efcae6d0d49fd7 100644 --- a/test/yarp/snapshots/patterns.txt +++ b/test/yarp/snapshots/patterns.txt @@ -959,7 +959,7 @@ ProgramNode(0...3743)( "foo" ), PinnedVariableNode(988...993)( - GlobalVariableReadNode(989...993)(), + GlobalVariableReadNode(989...993)(:$bar), (988...989) ), (985...987) diff --git a/test/yarp/snapshots/regex.txt b/test/yarp/snapshots/regex.txt index 6ba394271aafce..37e32c4dd86f78 100644 --- a/test/yarp/snapshots/regex.txt +++ b/test/yarp/snapshots/regex.txt @@ -21,7 +21,7 @@ ProgramNode(0...293)( [StringNode(29...33)(nil, (29...33), nil, "aaa "), EmbeddedVariableNode(33...38)( (33...34), - GlobalVariableReadNode(34...38)() + GlobalVariableReadNode(34...38)(:$bbb) )], (38...39), 0 diff --git a/test/yarp/snapshots/seattlerb/alias_gvar_backref.txt b/test/yarp/snapshots/seattlerb/alias_gvar_backref.txt index c055a64925e75e..d4890ed587a599 100644 --- a/test/yarp/snapshots/seattlerb/alias_gvar_backref.txt +++ b/test/yarp/snapshots/seattlerb/alias_gvar_backref.txt @@ -2,7 +2,7 @@ ProgramNode(0...15)( [], StatementsNode(0...15)( [AliasNode(0...15)( - GlobalVariableReadNode(6...12)(), + GlobalVariableReadNode(6...12)(:$MATCH), BackReferenceReadNode(13...15)(), (0...5) )] diff --git a/test/yarp/snapshots/seattlerb/bug202.txt b/test/yarp/snapshots/seattlerb/bug202.txt index cbed9a6712f87e..08bcfd6b7d3395 100644 --- a/test/yarp/snapshots/seattlerb/bug202.txt +++ b/test/yarp/snapshots/seattlerb/bug202.txt @@ -1,7 +1,12 @@ ProgramNode(0...22)( [:测试], StatementsNode(0...22)( - [GlobalVariableWriteNode(0...11)((0...7), IntegerNode(10...11)(), (8...9)), + [GlobalVariableWriteNode(0...11)( + :$测试, + (0...7), + IntegerNode(10...11)(), + (8...9) + ), LocalVariableWriteNode(12...22)( :测试, 0, diff --git a/test/yarp/snapshots/seattlerb/case_in.txt b/test/yarp/snapshots/seattlerb/case_in.txt index aaee410ef325bd..1262e453c96a6a 100644 --- a/test/yarp/snapshots/seattlerb/case_in.txt +++ b/test/yarp/snapshots/seattlerb/case_in.txt @@ -498,7 +498,7 @@ ProgramNode(0...747)( (628...629) ), PinnedVariableNode(633...636)( - GlobalVariableReadNode(634...636)(), + GlobalVariableReadNode(634...636)(:$b), (633...634) ), PinnedVariableNode(638...642)( diff --git a/test/yarp/snapshots/strings.txt b/test/yarp/snapshots/strings.txt index 86a732d85d5fbe..ca98151c140183 100644 --- a/test/yarp/snapshots/strings.txt +++ b/test/yarp/snapshots/strings.txt @@ -177,7 +177,7 @@ ProgramNode(0...498)( (405...406), [EmbeddedVariableNode(406...411)( (406...407), - GlobalVariableReadNode(407...411)() + GlobalVariableReadNode(407...411)(:$foo) )], (411...412) ), diff --git a/test/yarp/snapshots/unparser/corpus/literal/alias.txt b/test/yarp/snapshots/unparser/corpus/literal/alias.txt index cf6c04cd2e4c7a..18e16e1dd949d5 100644 --- a/test/yarp/snapshots/unparser/corpus/literal/alias.txt +++ b/test/yarp/snapshots/unparser/corpus/literal/alias.txt @@ -2,8 +2,8 @@ ProgramNode(0...31)( [], StatementsNode(0...31)( [AliasNode(0...15)( - GlobalVariableReadNode(6...10)(), - GlobalVariableReadNode(11...15)(), + GlobalVariableReadNode(6...10)(:$foo), + GlobalVariableReadNode(11...15)(:$bar), (0...5) ), AliasNode(16...31)( diff --git a/test/yarp/snapshots/unparser/corpus/literal/assignment.txt b/test/yarp/snapshots/unparser/corpus/literal/assignment.txt index 7680b90f618165..c08204cf1620f2 100644 --- a/test/yarp/snapshots/unparser/corpus/literal/assignment.txt +++ b/test/yarp/snapshots/unparser/corpus/literal/assignment.txt @@ -1,10 +1,15 @@ ProgramNode(0...704)( [:a, :b, :foo, :c, :x], StatementsNode(0...704)( - [GlobalVariableWriteNode(0...6)((0...2), IntegerNode(5...6)(), (3...4)), + [GlobalVariableWriteNode(0...6)( + :$a, + (0...2), + IntegerNode(5...6)(), + (3...4) + ), MultiWriteNode(7...24)( - [GlobalVariableTargetNode(8...10)(), - GlobalVariableTargetNode(12...14)()], + [GlobalVariableTargetNode(8...10)(:$a), + GlobalVariableTargetNode(12...14)(:$b)], (16...17), ArrayNode(18...24)( [IntegerNode(19...20)(), IntegerNode(22...23)()], diff --git a/test/yarp/snapshots/unparser/corpus/literal/dstr.txt b/test/yarp/snapshots/unparser/corpus/literal/dstr.txt index 396ebcd3daf896..369e1491e524b0 100644 --- a/test/yarp/snapshots/unparser/corpus/literal/dstr.txt +++ b/test/yarp/snapshots/unparser/corpus/literal/dstr.txt @@ -66,7 +66,7 @@ ProgramNode(0...299)( [StringNode(153...154)(nil, (153...154), nil, "a"), EmbeddedVariableNode(154...157)( (154...155), - GlobalVariableReadNode(155...157)() + GlobalVariableReadNode(155...157)(:$a) )], (157...158) ), diff --git a/test/yarp/snapshots/unparser/corpus/literal/literal.txt b/test/yarp/snapshots/unparser/corpus/literal/literal.txt index 3b85d3e95fb34f..8af9ea3c5e0dce 100644 --- a/test/yarp/snapshots/unparser/corpus/literal/literal.txt +++ b/test/yarp/snapshots/unparser/corpus/literal/literal.txt @@ -163,7 +163,7 @@ ProgramNode(0...916)( StringNode(215...216)(nil, (215...216), nil, " "), EmbeddedVariableNode(216...219)( (216...217), - GlobalVariableReadNode(217...219)() + GlobalVariableReadNode(217...219)(:$a) )], (219...220) ), diff --git a/test/yarp/snapshots/unparser/corpus/literal/variables.txt b/test/yarp/snapshots/unparser/corpus/literal/variables.txt index fe98a8cd57f251..21738f74f0a5e5 100644 --- a/test/yarp/snapshots/unparser/corpus/literal/variables.txt +++ b/test/yarp/snapshots/unparser/corpus/literal/variables.txt @@ -4,7 +4,7 @@ ProgramNode(0...66)( [CallNode(0...1)(nil, nil, (0...1), nil, nil, nil, nil, 2, "a"), InstanceVariableReadNode(2...4)(:@a), ClassVariableReadNode(5...8)(:@@a), - GlobalVariableReadNode(9...11)(), + GlobalVariableReadNode(9...11)(:$a), NumberedReferenceReadNode(12...14)(1), BackReferenceReadNode(15...17)(), ConstantReadNode(18...23)(), diff --git a/test/yarp/snapshots/unparser/corpus/semantic/dstr.txt b/test/yarp/snapshots/unparser/corpus/semantic/dstr.txt index 8822eb53337c33..8edb0134b1c58f 100644 --- a/test/yarp/snapshots/unparser/corpus/semantic/dstr.txt +++ b/test/yarp/snapshots/unparser/corpus/semantic/dstr.txt @@ -234,7 +234,7 @@ ProgramNode(0...608)( [StringNode(587...588)(nil, (587...588), nil, "a"), EmbeddedVariableNode(588...591)( (588...589), - GlobalVariableReadNode(589...591)() + GlobalVariableReadNode(589...591)(:$a) )], (591...592) ), diff --git a/test/yarp/snapshots/variables.txt b/test/yarp/snapshots/variables.txt index edd27690a1a2ec..11e232c1cb2398 100644 --- a/test/yarp/snapshots/variables.txt +++ b/test/yarp/snapshots/variables.txt @@ -27,11 +27,12 @@ ProgramNode(0...293)( (42...43) ), GlobalVariableWriteNode(50...58)( + :$abc, (50...54), IntegerNode(57...58)(), (55...56) ), - GlobalVariableReadNode(60...64)(), + GlobalVariableReadNode(60...64)(:$abc), InstanceVariableReadNode(66...70)(:@abc), InstanceVariableWriteNode(72...80)( :@abc, @@ -48,14 +49,15 @@ ProgramNode(0...293)( (89...90) ), MultiWriteNode(94...108)( - [GlobalVariableTargetNode(94...98)(), - GlobalVariableTargetNode(100...104)()], + [GlobalVariableTargetNode(94...98)(:$foo), + GlobalVariableTargetNode(100...104)(:$bar)], (105...106), IntegerNode(107...108)(), nil, nil ), GlobalVariableWriteNode(110...121)( + :$foo, (110...114), ArrayNode(117...121)( [IntegerNode(117...118)(), IntegerNode(120...121)()], diff --git a/test/yarp/snapshots/whitequark/alias_gvar.txt b/test/yarp/snapshots/whitequark/alias_gvar.txt index c615e52655aee6..06482181f4b10e 100644 --- a/test/yarp/snapshots/whitequark/alias_gvar.txt +++ b/test/yarp/snapshots/whitequark/alias_gvar.txt @@ -2,13 +2,13 @@ ProgramNode(0...24)( [], StatementsNode(0...24)( [AliasNode(0...11)( - GlobalVariableReadNode(6...8)(), + GlobalVariableReadNode(6...8)(:$a), BackReferenceReadNode(9...11)(), (0...5) ), AliasNode(13...24)( - GlobalVariableReadNode(19...21)(), - GlobalVariableReadNode(22...24)(), + GlobalVariableReadNode(19...21)(:$a), + GlobalVariableReadNode(22...24)(:$b), (13...18) )] ) diff --git a/test/yarp/snapshots/whitequark/gvar.txt b/test/yarp/snapshots/whitequark/gvar.txt index 2ac61ed4f43830..dbc16e65d8409f 100644 --- a/test/yarp/snapshots/whitequark/gvar.txt +++ b/test/yarp/snapshots/whitequark/gvar.txt @@ -1,4 +1,4 @@ ProgramNode(0...4)( [], - StatementsNode(0...4)([GlobalVariableReadNode(0...4)()]) + StatementsNode(0...4)([GlobalVariableReadNode(0...4)(:$foo)]) ) diff --git a/test/yarp/snapshots/whitequark/gvasgn.txt b/test/yarp/snapshots/whitequark/gvasgn.txt index c4030831e3f3f5..b416ac55abb545 100644 --- a/test/yarp/snapshots/whitequark/gvasgn.txt +++ b/test/yarp/snapshots/whitequark/gvasgn.txt @@ -1,6 +1,11 @@ ProgramNode(0...9)( [], StatementsNode(0...9)( - [GlobalVariableWriteNode(0...9)((0...4), IntegerNode(7...9)(), (5...6))] + [GlobalVariableWriteNode(0...9)( + :$var, + (0...4), + IntegerNode(7...9)(), + (5...6) + )] ) ) diff --git a/test/yarp/snapshots/whitequark/string_dvar.txt b/test/yarp/snapshots/whitequark/string_dvar.txt index 12f083660bb8d7..66cd00b5cb34e7 100644 --- a/test/yarp/snapshots/whitequark/string_dvar.txt +++ b/test/yarp/snapshots/whitequark/string_dvar.txt @@ -15,7 +15,7 @@ ProgramNode(0...14)( StringNode(9...10)(nil, (9...10), nil, " "), EmbeddedVariableNode(10...13)( (10...11), - GlobalVariableReadNode(11...13)() + GlobalVariableReadNode(11...13)(:$a) )], (13...14) )] diff --git a/yarp/config.yml b/yarp/config.yml index e65177302f455b..f1df755d891476 100644 --- a/yarp/config.yml +++ b/yarp/config.yml @@ -1166,6 +1166,8 @@ nodes: ^^^^^ - name: GlobalVariableAndWriteNode fields: + - name: name + type: constant - name: name_loc type: location - name: operator_loc @@ -1179,6 +1181,8 @@ nodes: ^^^^^^^^^^^^^^^^^ - name: GlobalVariableOperatorWriteNode fields: + - name: name + type: constant - name: name_loc type: location - name: operator_loc @@ -1194,6 +1198,8 @@ nodes: ^^^^^^^^^^^^^^^^ - name: GlobalVariableOrWriteNode fields: + - name: name + type: constant - name: name_loc type: location - name: operator_loc @@ -1206,12 +1212,18 @@ nodes: $target ||= value ^^^^^^^^^^^^^^^^^ - name: GlobalVariableReadNode + fields: + - name: name + type: constant comment: | Represents referencing a global variable. $foo ^^^^ - name: GlobalVariableTargetNode + fields: + - name: name + type: constant comment: | Represents writing to a global variable in a context that doesn't have an explicit value. @@ -1219,6 +1231,8 @@ nodes: ^^^^ ^^^^ - name: GlobalVariableWriteNode fields: + - name: name + type: constant - name: name_loc type: location - name: value diff --git a/yarp/yarp.c b/yarp/yarp.c index 7e098daa48322c..45c26471bbb98e 100644 --- a/yarp/yarp.c +++ b/yarp/yarp.c @@ -2310,10 +2310,23 @@ yp_hash_pattern_node_node_list_create(yp_parser_t *parser, yp_node_list_t *assoc return node; } +// Retrieve the name from a node that will become a global variable write node. +static yp_constant_id_t +yp_global_variable_write_name(yp_parser_t *parser, yp_node_t *target) { + if (YP_NODE_TYPE_P(target, YP_NODE_GLOBAL_VARIABLE_READ_NODE)) { + return ((yp_global_variable_read_node_t *) target)->name; + } + + assert(YP_NODE_TYPE_P(target, YP_NODE_BACK_REFERENCE_READ_NODE) || YP_NODE_TYPE_P(target, YP_NODE_NUMBERED_REFERENCE_READ_NODE)); + + // This will only ever happen in the event of a syntax error, but we + // still need to provide something for the node. + return yp_parser_constant_id_location(parser, target->location.start, target->location.end); +} + // Allocate and initialize a new GlobalVariableAndWriteNode node. static yp_global_variable_and_write_node_t * yp_global_variable_and_write_node_create(yp_parser_t *parser, yp_node_t *target, const yp_token_t *operator, yp_node_t *value) { - assert(YP_NODE_TYPE_P(target, YP_NODE_GLOBAL_VARIABLE_READ_NODE) || YP_NODE_TYPE_P(target, YP_NODE_BACK_REFERENCE_READ_NODE) || YP_NODE_TYPE_P(target, YP_NODE_NUMBERED_REFERENCE_READ_NODE)); assert(operator->type == YP_TOKEN_AMPERSAND_AMPERSAND_EQUAL); yp_global_variable_and_write_node_t *node = YP_ALLOC_NODE(parser, yp_global_variable_and_write_node_t); @@ -2325,6 +2338,7 @@ yp_global_variable_and_write_node_create(yp_parser_t *parser, yp_node_t *target, .end = value->location.end } }, + .name = yp_global_variable_write_name(parser, target), .name_loc = target->location, .operator_loc = YP_LOCATION_TOKEN_VALUE(operator), .value = value @@ -2346,6 +2360,7 @@ yp_global_variable_operator_write_node_create(yp_parser_t *parser, yp_node_t *ta .end = value->location.end } }, + .name = yp_global_variable_write_name(parser, target), .name_loc = target->location, .operator_loc = YP_LOCATION_TOKEN_VALUE(operator), .value = value, @@ -2358,7 +2373,6 @@ yp_global_variable_operator_write_node_create(yp_parser_t *parser, yp_node_t *ta // Allocate and initialize a new GlobalVariableOrWriteNode node. static yp_global_variable_or_write_node_t * yp_global_variable_or_write_node_create(yp_parser_t *parser, yp_node_t *target, const yp_token_t *operator, yp_node_t *value) { - assert(YP_NODE_TYPE_P(target, YP_NODE_GLOBAL_VARIABLE_READ_NODE) || YP_NODE_TYPE_P(target, YP_NODE_BACK_REFERENCE_READ_NODE) || YP_NODE_TYPE_P(target, YP_NODE_NUMBERED_REFERENCE_READ_NODE)); assert(operator->type == YP_TOKEN_PIPE_PIPE_EQUAL); yp_global_variable_or_write_node_t *node = YP_ALLOC_NODE(parser, yp_global_variable_or_write_node_t); @@ -2370,6 +2384,7 @@ yp_global_variable_or_write_node_create(yp_parser_t *parser, yp_node_t *target, .end = value->location.end } }, + .name = yp_global_variable_write_name(parser, target), .name_loc = target->location, .operator_loc = YP_LOCATION_TOKEN_VALUE(operator), .value = value @@ -2387,7 +2402,8 @@ yp_global_variable_read_node_create(yp_parser_t *parser, const yp_token_t *name) { .type = YP_NODE_GLOBAL_VARIABLE_READ_NODE, .location = YP_LOCATION_TOKEN_VALUE(name), - } + }, + .name = yp_parser_constant_id_location(parser, name->start, name->end) }; return node; @@ -2395,18 +2411,19 @@ yp_global_variable_read_node_create(yp_parser_t *parser, const yp_token_t *name) // Allocate a new GlobalVariableWriteNode node. static yp_global_variable_write_node_t * -yp_global_variable_write_node_create(yp_parser_t *parser, const yp_location_t *name_loc, const yp_token_t *operator, yp_node_t *value) { +yp_global_variable_write_node_create(yp_parser_t *parser, yp_node_t *target, const yp_token_t *operator, yp_node_t *value) { yp_global_variable_write_node_t *node = YP_ALLOC_NODE(parser, yp_global_variable_write_node_t); *node = (yp_global_variable_write_node_t) { { .type = YP_NODE_GLOBAL_VARIABLE_WRITE_NODE, .location = { - .start = name_loc->start, + .start = target->location.start, .end = value->location.end }, }, - .name_loc = *name_loc, + .name = yp_global_variable_write_name(parser, target), + .name_loc = YP_LOCATION_NODE_VALUE(target), .operator_loc = YP_OPTIONAL_LOCATION_TOKEN_VALUE(operator), .value = value }; @@ -8068,16 +8085,15 @@ parse_write(yp_parser_t *parser, yp_node_t *target, yp_token_t *operator, yp_nod case YP_NODE_MISSING_NODE: return target; case YP_NODE_CLASS_VARIABLE_READ_NODE: { - yp_class_variable_write_node_t *write_node = yp_class_variable_write_node_create(parser, (yp_class_variable_read_node_t *) target, operator, value); + yp_class_variable_write_node_t *node = yp_class_variable_write_node_create(parser, (yp_class_variable_read_node_t *) target, operator, value); yp_node_destroy(parser, target); - return (yp_node_t *) write_node; + return (yp_node_t *) node; } case YP_NODE_CONSTANT_PATH_NODE: return (yp_node_t *) yp_constant_path_write_node_create(parser, (yp_constant_path_node_t *) target, operator, value); case YP_NODE_CONSTANT_READ_NODE: { yp_constant_write_node_t *node = yp_constant_write_node_create(parser, &target->location, operator, value); yp_node_destroy(parser, target); - return (yp_node_t *) node; } case YP_NODE_BACK_REFERENCE_READ_NODE: @@ -8085,10 +8101,9 @@ parse_write(yp_parser_t *parser, yp_node_t *target, yp_token_t *operator, yp_nod yp_diagnostic_list_append(&parser->error_list, target->location.start, target->location.end, "Can't set variable"); /* fallthrough */ case YP_NODE_GLOBAL_VARIABLE_READ_NODE: { - yp_global_variable_write_node_t *result = yp_global_variable_write_node_create(parser, &target->location, operator, value); + yp_global_variable_write_node_t *node = yp_global_variable_write_node_create(parser, target, operator, value); yp_node_destroy(parser, target); - - return (yp_node_t *) result; + return (yp_node_t *) node; } case YP_NODE_LOCAL_VARIABLE_READ_NODE: { yp_local_variable_read_node_t *local_read = (yp_local_variable_read_node_t *) target; From 00f263e6c4cc709e5bdcce2c903c12f5d76f8a37 Mon Sep 17 00:00:00 2001 From: Takashi Kokubun Date: Fri, 1 Sep 2023 16:02:23 -0700 Subject: [PATCH 12/95] sync_default_gems.rb: Deal with conflicts on ignored files that do not exist in the ruby/ruby side. This resurrects a line that had existed prior to #8329. --- tool/sync_default_gems.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/tool/sync_default_gems.rb b/tool/sync_default_gems.rb index 2879ff60812380..fcfb06047e7b60 100755 --- a/tool/sync_default_gems.rb +++ b/tool/sync_default_gems.rb @@ -602,6 +602,7 @@ def pickup_files(gem, changed, picked) unless ignore.empty? puts "Reset ignored files: #{ignore.join(', ')}" + system(*%W"git rm -r --", *ignore) system(*%W"git checkout -f", base, "--", *ignore) end From e8ef5b1281b9dce518902b3451096164c30bca5c Mon Sep 17 00:00:00 2001 From: Kevin Newton Date: Fri, 1 Sep 2023 14:51:50 -0400 Subject: [PATCH 13/95] [ruby/yarp] Provide a better inspect https://github.com/ruby/yarp/commit/ef14ae66e4 --- lib/yarp.rb | 78 ++++++++++++++++++++++++++++- yarp/templates/lib/yarp/node.rb.erb | 33 ++++++++++++ 2 files changed, 110 insertions(+), 1 deletion(-) diff --git a/lib/yarp.rb b/lib/yarp.rb index 316918b2db406d..a77292d26de644 100644 --- a/lib/yarp.rb +++ b/lib/yarp.rb @@ -141,6 +141,10 @@ def initialize(type, location) def deconstruct_keys(keys) { type: type, location: location } end + + def inspect + "#" + end end # This represents an error that was encountered during parsing. @@ -155,6 +159,10 @@ def initialize(message, location) def deconstruct_keys(keys) { message: message, location: location } end + + def inspect + "#" + end end # This represents a warning that was encountered during parsing. @@ -169,6 +177,10 @@ def initialize(message, location) def deconstruct_keys(keys) { message: message, location: location } end + + def inspect + "#" + end end # A class that knows how to walk down the tree. None of the individual visit @@ -323,7 +335,6 @@ def pretty_print(q) q.nest(2) do deconstructed = deconstruct_keys([]) deconstructed.delete(:location) - q.breakable("") q.seplist(deconstructed, lambda { q.comma_breakable }, :each_value) { |value| q.pp(value) } end @@ -333,6 +344,71 @@ def pretty_print(q) end end + # This object is responsible for generating the output for the inspect method + # implementations of child nodes. + class NodeInspector + attr_reader :prefix, :output + + def initialize(prefix = "") + @prefix = prefix + @output = +"" + end + + # Appends a line to the output with the current prefix. + def <<(line) + output << "#{prefix}#{line}" + end + + # This generates a string that is used as the header of the inspect output + # for any given node. + def header(node) + output = +"@ #{node.class.name.split("::").last} (" + output << "location: (#{node.location.start_offset}...#{node.location.end_offset})" + output << ", newline: true" if node.newline? + output << ")\n" + output + end + + # Generates a string that represents a list of nodes. It handles properly + # using the box drawing characters to make the output look nice. + def list(prefix, nodes) + output = +"(length: #{nodes.length})\n" + last_index = nodes.length - 1 + + nodes.each_with_index do |node, index| + pointer, preadd = (index == last_index) ? ["└── ", " "] : ["├── ", "│ "] + node_prefix = "#{prefix}#{preadd}" + output << node.inspect(NodeInspector.new(node_prefix)).sub(node_prefix, "#{prefix}#{pointer}") + end + + output + end + + # Generates a string that represents a location field on a node. + def location(value) + if value + "(#{value.start_offset}...#{value.end_offset}) = #{value.slice.inspect}" + else + "∅" + end + end + + # Generates a string that represents a child node. + def child_node(node, append) + node.inspect(child_inspector(append)).delete_prefix(prefix) + end + + # Returns a new inspector that can be used to inspect a child node. + def child_inspector(append) + NodeInspector.new("#{prefix}#{append}") + end + + # Returns the output as a string. + def to_str + output + end + end + class FloatNode < Node def value Float(slice) diff --git a/yarp/templates/lib/yarp/node.rb.erb b/yarp/templates/lib/yarp/node.rb.erb index 6241eabd12bd0a..8919cb7ad091c6 100644 --- a/yarp/templates/lib/yarp/node.rb.erb +++ b/yarp/templates/lib/yarp/node.rb.erb @@ -92,6 +92,39 @@ module YARP <%- end -%> <%- end -%> <%- end -%> + + def inspect(inspector = NodeInspector.new) + inspector << inspector.header(self) + <%- node.fields.each_with_index do |field, index| -%> + <%- pointer, preadd = index == node.fields.length - 1 ? ["└── ", " "] : ["├── ", "│ "] -%> + <%- case field -%> + <%- when YARP::NodeListField -%> + inspector << "<%= pointer %><%= field.name %>: #{inspector.list("#{inspector.prefix}<%= preadd %>", <%= field.name %>)}" + <%- when YARP::LocationListField, YARP::ConstantListField -%> + inspector << "<%= pointer %><%= field.name %>: #{<%= field.name %>.inspect}\n" + <%- when YARP::NodeField -%> + inspector << "<%= pointer %><%= field.name %>:\n" + inspector << inspector.child_node(<%= field.name %>, "<%= preadd %>") + <%- when YARP::OptionalNodeField -%> + if (<%= field.name %> = self.<%= field.name %>).nil? + inspector << "<%= pointer %><%= field.name %>: ∅\n" + else + inspector << "<%= pointer %><%= field.name %>:\n" + inspector << <%= field.name %>.inspect(inspector.child_inspector("<%= preadd %>")).delete_prefix(inspector.prefix) + end + <%- when YARP::ConstantField, YARP::StringField, YARP::UInt32Field -%> + inspector << "<%= pointer %><%= field.name %>: #{<%= field.name %>.inspect}\n" + <%- when YARP::FlagsField -%> + <%- flag = flags.find { |flag| flag.name == field.kind }.tap { |flag| raise unless flag } -%> + inspector << "<%= pointer %><%= field.name %>: #{[<%= flag.values.map { |value| "(\"#{value.name.downcase}\" if #{value.name.downcase}?)" }.join(", ") %>].compact.join(", ")}\n" + <%- when YARP::LocationField, YARP::OptionalLocationField -%> + inspector << "<%= pointer %><%= field.name %>: #{inspector.location(<%= field.name %>)}\n" + <%- else -%> + <%- raise -%> + <%- end -%> + <%- end -%> + inspector.to_str + end end <%- end -%> From 2ca0f01015d076d966ab1b0f28700a4424b86da6 Mon Sep 17 00:00:00 2001 From: ywenc Date: Thu, 31 Aug 2023 17:52:50 -0400 Subject: [PATCH 14/95] Add regression tests for start_with?/delete_prefix --- test/ruby/test_string.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/test/ruby/test_string.rb b/test/ruby/test_string.rb index 1d8902baf1c738..22bec09855f8c4 100644 --- a/test/ruby/test_string.rb +++ b/test/ruby/test_string.rb @@ -1939,6 +1939,7 @@ def test_start_with? assert_not_send([S("hello"), :start_with?, S("el")]) assert_send([S("hello"), :start_with?, S("el"), S("he")]) assert_send([S("\xFF\xFE"), :start_with?, S("\xFF")]) + assert_send([S("hello\xBE"), :start_with?, S("hello")]) assert_not_send([S("\u{c4}"), :start_with?, S("\xC3")]) bug5536 = '[ruby-core:40623]' @@ -2933,6 +2934,8 @@ def test_delete_prefix_broken_encoding assert_equal("\x95\x5c".force_encoding("Shift_JIS"), s) assert_equal("\xFE", S("\xFF\xFE").delete_prefix("\xFF")) + assert_equal("\xBE", S("hello\xBE").delete_prefix("hello")) + assert_equal("\xBE", S("\xFFhello\xBE").delete_prefix("\xFFhello")) end def test_delete_prefix_clear_coderange From d89b15cdce8a2fa36fc2a150551f0dd8e58814d7 Mon Sep 17 00:00:00 2001 From: John Hawthorn Date: Thu, 31 Aug 2023 15:12:47 -0700 Subject: [PATCH 15/95] Use end of char boundary in start_with? Previously we used the next character following the found prefix to determine if the match ended on a broken character. This had caused surprising behaviour when a valid character was followed by a UTF-8 continuation byte. This commit changes the behaviour to instead look for the end of the last character in the prefix. [Bug #19784] Co-authored-by: ywenc Co-authored-by: Nobuyoshi Nakada --- internal/string.h | 9 +++++++++ string.c | 4 ++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/internal/string.h b/internal/string.h index cfaf628e02140d..abb0a536ade040 100644 --- a/internal/string.h +++ b/internal/string.h @@ -125,6 +125,15 @@ at_char_boundary(const char *s, const char *p, const char *e, rb_encoding *enc) return rb_enc_left_char_head(s, p, e, enc) == p; } +static inline bool +at_char_right_boundary(const char *s, const char *p, const char *e, rb_encoding *enc) +{ + RUBY_ASSERT(s <= p); + RUBY_ASSERT(p <= e); + + return rb_enc_right_char_head(s, p, e, enc) == p; +} + /* expect tail call optimization */ // YJIT needs this function to never allocate and never raise static inline VALUE diff --git a/string.c b/string.c index 5af5fc4a402156..deeed4a12a48ea 100644 --- a/string.c +++ b/string.c @@ -10472,7 +10472,7 @@ rb_str_start_with(int argc, VALUE *argv, VALUE str) p = RSTRING_PTR(str); e = p + slen; s = p + tlen; - if (!at_char_boundary(p, s, e, enc)) + if (!at_char_right_boundary(p, s, e, enc)) continue; if (memcmp(p, RSTRING_PTR(tmp), tlen) == 0) return Qtrue; @@ -10554,7 +10554,7 @@ deleted_prefix_length(VALUE str, VALUE prefix) } const char *strend = strptr + olen; const char *after_prefix = strptr + prefixlen; - if (!at_char_boundary(strptr, after_prefix, strend, enc)) { + if (!at_char_right_boundary(strptr, after_prefix, strend, enc)) { /* prefix does not end at char-boundary */ return 0; } From 3c41ef4749dc5df78c6d500c7e16fef384b53b15 Mon Sep 17 00:00:00 2001 From: Takashi Kokubun Date: Fri, 1 Sep 2023 16:33:22 -0700 Subject: [PATCH 16/95] [ruby/yarp] Support LANG=C environments in template.rb https://github.com/ruby/yarp/commit/885d731cf5 --- yarp/templates/template.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/yarp/templates/template.rb b/yarp/templates/template.rb index 3969645643e581..eea3938e9cd27b 100755 --- a/yarp/templates/template.rb +++ b/yarp/templates/template.rb @@ -339,7 +339,10 @@ def locals if __FILE__ == $0 if ARGV.empty? YARP::TEMPLATES.each { |filepath| YARP.template(filepath) } - else + else # ruby/ruby + if ENV["LANG"] == "C" + Encoding.default_external = Encoding::UTF_8 + end name, write_to = ARGV YARP.template(name, write_to: write_to) end From c86497340f80f4bf5cd689e1468566b88e1a0ef2 Mon Sep 17 00:00:00 2001 From: Takashi Kokubun Date: Fri, 1 Sep 2023 16:38:33 -0700 Subject: [PATCH 17/95] [ruby/yarp] Try ignoring $LANG because the previous commit did not fix it. https://github.com/ruby/ruby/actions/runs/6054915979/job/16433070185#step:9:155 https://github.com/ruby/yarp/commit/8c9e4c1f15 --- yarp/templates/template.rb | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/yarp/templates/template.rb b/yarp/templates/template.rb index eea3938e9cd27b..680ab82620bc24 100755 --- a/yarp/templates/template.rb +++ b/yarp/templates/template.rb @@ -340,9 +340,7 @@ def locals if ARGV.empty? YARP::TEMPLATES.each { |filepath| YARP.template(filepath) } else # ruby/ruby - if ENV["LANG"] == "C" - Encoding.default_external = Encoding::UTF_8 - end + Encoding.default_external = Encoding::UTF_8 name, write_to = ARGV YARP.template(name, write_to: write_to) end From cfcb4a4e2609963900a2628471c1a3162ec20451 Mon Sep 17 00:00:00 2001 From: Burdette Lamar Date: Sat, 2 Sep 2023 08:04:04 -0500 Subject: [PATCH 18/95] [DOC] RDoc for process.c (#8353) --- process.c | 260 +++++++++++++++++++++++++++++------------------------- 1 file changed, 138 insertions(+), 122 deletions(-) diff --git a/process.c b/process.c index 47db4fa6265341..e81b7e69f58b80 100644 --- a/process.c +++ b/process.c @@ -5017,22 +5017,18 @@ rb_f_spawn(int argc, VALUE *argv, VALUE _) /* * call-seq: - * sleep([duration]) -> integer - * - * Suspends the current thread for _duration_ seconds (which may be any number, - * including a +Float+ with fractional seconds). Returns the actual number of - * seconds slept (rounded), which may be less than that asked for if another - * thread calls Thread#run. Called without an argument, sleep() - * will sleep forever. - * - * If the +duration+ is not supplied, or is +nil+, the thread sleeps forever. - * Threads in this state may still be interrupted by other threads. - * - * Time.new #=> 2008-03-08 19:56:19 +0900 - * sleep 1.2 #=> 1 - * Time.new #=> 2008-03-08 19:56:20 +0900 - * sleep 1.9 #=> 2 - * Time.new #=> 2008-03-08 19:56:22 +0900 + * sleep(secs = nil) -> slept_secs + * + * Suspends execution of the current thread for the number of seconds + * specified by numeric argument +secs+, or forever if +secs+ is +nil+; + * returns the integer number of seconds suspended (rounded). + * + * Time.new # => 2008-03-08 19:56:19 +0900 + * sleep 1.2 # => 1 + * Time.new # => 2008-03-08 19:56:20 +0900 + * sleep 1.9 # => 2 + * Time.new # => 2008-03-08 19:56:22 +0900 + * */ static VALUE @@ -5063,13 +5059,13 @@ rb_f_sleep(int argc, VALUE *argv, VALUE _) #if (defined(HAVE_GETPGRP) && defined(GETPGRP_VOID)) || defined(HAVE_GETPGID) /* * call-seq: - * Process.getpgrp -> integer + * Process.getpgrp -> integer * - * Returns the process group ID for this process. Not available on - * all platforms. + * Returns the process group ID for the current process: + * + * Process.getpgid(0) # => 25527 + * Process.getpgrp # => 25527 * - * Process.getpgid(0) #=> 25527 - * Process.getpgrp #=> 25527 */ static VALUE @@ -5095,10 +5091,11 @@ proc_getpgrp(VALUE _) #if defined(HAVE_SETPGID) || (defined(HAVE_SETPGRP) && defined(SETPGRP_VOID)) /* * call-seq: - * Process.setpgrp -> 0 + * Process.setpgrp -> 0 * - * Equivalent to setpgid(0,0). Not available on all - * platforms. + * Equivalent to setpgid(0, 0). + * + * Not available on all platforms. */ static VALUE @@ -5123,12 +5120,13 @@ proc_setpgrp(VALUE _) #if defined(HAVE_GETPGID) /* * call-seq: - * Process.getpgid(pid) -> integer + * Process.getpgid(pid) -> integer * - * Returns the process group ID for the given process id. Not - * available on all platforms. + * Returns the process group ID for the given process ID +pid+: + * + * Process.getpgid(Process.ppid) # => 25527 * - * Process.getpgid(Process.ppid()) #=> 25527 + * Not available on all platforms. */ static VALUE @@ -5148,10 +5146,12 @@ proc_getpgid(VALUE obj, VALUE pid) #ifdef HAVE_SETPGID /* * call-seq: - * Process.setpgid(pid, integer) -> 0 + * Process.setpgid(pid, pgid) -> 0 * - * Sets the process group ID of _pid_ (0 indicates this - * process) to integer. Not available on all platforms. + * Sets the process group ID for the process given by process ID +pid+ + * to +pgid+. + * + * Not available on all platforms. */ static VALUE @@ -5173,15 +5173,16 @@ proc_setpgid(VALUE obj, VALUE pid, VALUE pgrp) #ifdef HAVE_GETSID /* * call-seq: - * Process.getsid() -> integer - * Process.getsid(pid) -> integer + * Process.getsid(pid = nil) -> integer + * + * Returns the session ID of the given process ID +pid+, + * or of the current process if not given: * - * Returns the session ID for the given process id. If not given, - * return current process sid. Not available on all platforms. + * Process.getsid # => 27422 + * Process.getsid(0) # => 27422 + * Process.getsid(Process.pid()) # => 27422 * - * Process.getsid() #=> 27422 - * Process.getsid(0) #=> 27422 - * Process.getsid(Process.pid()) #=> 27422 + * Not available on all platforms. */ static VALUE proc_getsid(int argc, VALUE *argv, VALUE _) @@ -5208,13 +5209,15 @@ static rb_pid_t ruby_setsid(void); #endif /* * call-seq: - * Process.setsid -> integer + * Process.setsid -> integer * - * Establishes this process as a new session and process group - * leader, with no controlling tty. Returns the session id. Not - * available on all platforms. + * Establishes the current process as a new session and process group leader, + * with no controlling tty; + * returns the session ID: * - * Process.setsid #=> 27422 + * Process.setsid # => 27422 + * + * Not available on all platforms. */ static VALUE @@ -5262,19 +5265,26 @@ ruby_setsid(void) #ifdef HAVE_GETPRIORITY /* * call-seq: - * Process.getpriority(kind, integer) -> integer - * - * Gets the scheduling priority for specified process, process group, - * or user. kind indicates the kind of entity to find: one - * of Process::PRIO_PGRP, - * Process::PRIO_USER, or - * Process::PRIO_PROCESS. _integer_ is an id - * indicating the particular process, process group, or user (an id - * of 0 means _current_). Lower priorities are more favorable - * for scheduling. Not available on all platforms. - * - * Process.getpriority(Process::PRIO_USER, 0) #=> 19 - * Process.getpriority(Process::PRIO_PROCESS, 0) #=> 19 + * Process.getpriority(kind, id) -> integer + * + * Returns the scheduling priority for specified process, process group, + * or user. + * + * Argument +kind+ is one of: + * + * - Process::PRIO_PROCESS: return priority for process. + * - Process::PRIO_PGRP: return priority for process group. + * - Process::PRIO_USER: return priority for user. + * + * Argument +id+ is the ID for the process, process group, or user; + * zero specified the current ID for +kind+. + * + * Examples: + * + * Process.getpriority(Process::PRIO_USER, 0) # => 19 + * Process.getpriority(Process::PRIO_PROCESS, 0) # => 19 + * + * Not available on all platforms. */ static VALUE @@ -5298,14 +5308,18 @@ proc_getpriority(VALUE obj, VALUE which, VALUE who) #ifdef HAVE_GETPRIORITY /* * call-seq: - * Process.setpriority(kind, integer, priority) -> 0 + * Process.setpriority(kind, integer, priority) -> 0 * * See Process.getpriority. * - * Process.setpriority(Process::PRIO_USER, 0, 19) #=> 0 - * Process.setpriority(Process::PRIO_PROCESS, 0, 19) #=> 0 - * Process.getpriority(Process::PRIO_USER, 0) #=> 19 - * Process.getpriority(Process::PRIO_PROCESS, 0) #=> 19 + * Examples: + * + * Process.setpriority(Process::PRIO_USER, 0, 19) # => 0 + * Process.setpriority(Process::PRIO_PROCESS, 0, 19) # => 0 + * Process.getpriority(Process::PRIO_USER, 0) # => 19 + * Process.getpriority(Process::PRIO_PROCESS, 0) # => 19 + * + * Not available on all platforms. */ static VALUE @@ -5553,22 +5567,24 @@ rlimit_resource_value(VALUE rval) #if defined(HAVE_GETRLIMIT) && defined(RLIM2NUM) /* * call-seq: - * Process.getrlimit(resource) -> [cur_limit, max_limit] - * - * Gets the resource limit of the process. - * _cur_limit_ means current (soft) limit and - * _max_limit_ means maximum (hard) limit. - * - * _resource_ indicates the kind of resource to limit. - * It is specified as a symbol such as :CORE, - * a string such as "CORE" or - * a constant such as Process::RLIMIT_CORE. - * See Process.setrlimit for details. - * - * _cur_limit_ and _max_limit_ may be Process::RLIM_INFINITY, - * Process::RLIM_SAVED_MAX or - * Process::RLIM_SAVED_CUR. - * See Process.setrlimit and the system getrlimit(2) manual for details. + * Process.getrlimit(resource) -> [cur_limit, max_limit] + * + * Returns a 2-element array of the current (soft) limit + * and maximum (hard) limit for the given +resource+. + * + * Argument +resource+ specifies the resource whose limits are to be returned; + * see Process.setrlimit. + * + * Each of the returned values +cur_limit+ and +max_limit+ is an integer; + * see Process.setrlimit. + * + * Example: + * + * Process.getrlimit(:CORE) # => [0, 18446744073709551615] + * + * See Process.setrlimit. + * + * Not available on all platforms. */ static VALUE @@ -5588,54 +5604,54 @@ proc_getrlimit(VALUE obj, VALUE resource) #if defined(HAVE_SETRLIMIT) && defined(NUM2RLIM) /* * call-seq: - * Process.setrlimit(resource, cur_limit, max_limit) -> nil - * Process.setrlimit(resource, cur_limit) -> nil - * - * Sets the resource limit of the process. - * _cur_limit_ means current (soft) limit and - * _max_limit_ means maximum (hard) limit. - * - * If _max_limit_ is not given, _cur_limit_ is used. - * - * _resource_ indicates the kind of resource to limit. - * It should be a symbol such as :CORE, - * a string such as "CORE" or - * a constant such as Process::RLIMIT_CORE. - * The available resources are OS dependent. - * Ruby may support following resources. - * - * [AS] total available memory (bytes) (SUSv3, NetBSD, FreeBSD, OpenBSD but 4.4BSD-Lite) - * [CORE] core size (bytes) (SUSv3) - * [CPU] CPU time (seconds) (SUSv3) - * [DATA] data segment (bytes) (SUSv3) - * [FSIZE] file size (bytes) (SUSv3) - * [MEMLOCK] total size for mlock(2) (bytes) (4.4BSD, GNU/Linux) - * [MSGQUEUE] allocation for POSIX message queues (bytes) (GNU/Linux) - * [NICE] ceiling on process's nice(2) value (number) (GNU/Linux) - * [NOFILE] file descriptors (number) (SUSv3) - * [NPROC] number of processes for the user (number) (4.4BSD, GNU/Linux) - * [NPTS] number of pseudo terminals (number) (FreeBSD) - * [RSS] resident memory size (bytes) (4.2BSD, GNU/Linux) - * [RTPRIO] ceiling on the process's real-time priority (number) (GNU/Linux) - * [RTTIME] CPU time for real-time process (us) (GNU/Linux) - * [SBSIZE] all socket buffers (bytes) (NetBSD, FreeBSD) - * [SIGPENDING] number of queued signals allowed (signals) (GNU/Linux) - * [STACK] stack size (bytes) (SUSv3) - * - * _cur_limit_ and _max_limit_ may be - * :INFINITY, "INFINITY" or - * Process::RLIM_INFINITY, - * which means that the resource is not limited. - * They may be Process::RLIM_SAVED_MAX, - * Process::RLIM_SAVED_CUR and - * corresponding symbols and strings too. - * See system setrlimit(2) manual for details. - * - * The following example raises the soft limit of core size to - * the hard limit to try to make core dump possible. + * Process.setrlimit(resource, cur_limit, max_limit = cur_limit) -> nil + * + * Sets limits for the current process for the given +resource+ + * to +cur_limit+ (soft limit) and +max_limit+ (hard limit); + * returns +nil+. + * + * Argument +resource+ specifies the resource whose limits are to be set; + * the argument may be given as a symbol, as a string, or as a constant + * beginning with Process::RLIMIT_ + * (e.g., +:CORE+, 'CORE', or Process::RLIMIT_CORE. + * + * The resources available and supported are system-dependent, + * and may include (here expressed as symbols): + * + * - +:AS+: Total available memory (bytes) (SUSv3, NetBSD, FreeBSD, OpenBSD except 4.4BSD-Lite). + * - +:CORE+: Core size (bytes) (SUSv3). + * - +:CPU+: CPU time (seconds) (SUSv3). + * - +:DATA+: Data segment (bytes) (SUSv3). + * - +:FSIZE+: File size (bytes) (SUSv3). + * - +:MEMLOCK+: Total size for mlock(2) (bytes) (4.4BSD, GNU/Linux). + * - +:MSGQUEUE+: Allocation for POSIX message queues (bytes) (GNU/Linux). + * - +:NICE+: Ceiling on process's nice(2) value (number) (GNU/Linux). + * - +:NOFILE+: File descriptors (number) (SUSv3). + * - +:NPROC+: Number of processes for the user (number) (4.4BSD, GNU/Linux). + * - +:NPTS+: Number of pseudo terminals (number) (FreeBSD). + * - +:RSS+: Resident memory size (bytes) (4.2BSD, GNU/Linux). + * - +:RTPRIO+: Ceiling on the process's real-time priority (number) (GNU/Linux). + * - +:RTTIME+: CPU time for real-time process (us) (GNU/Linux). + * - +:SBSIZE+: All socket buffers (bytes) (NetBSD, FreeBSD). + * - +:SIGPENDING+: Number of queued signals allowed (signals) (GNU/Linux). + * - +:STACK+: Stack size (bytes) (SUSv3). + * + * Arguments +cur_limit+ and +max_limit+ may be: + * + * - Integers (+max_limit+ should not be smaller than +cur_limit+). + * - Symbol +:SAVED_MAX+, string 'SAVED_MAX', + * or constant Process::RLIM_SAVED_MAX: saved maximum limit. + * - Symbol +:SAVED_CUR+, string 'SAVED_CUR', + * or constant Process::RLIM_SAVED_CUR: saved current limit. + * - Symbol +:INFINITY+, string 'INFINITY', + * or constant Process::RLIM_INFINITY: no limit on resource. + * + * This example raises the soft limit of core size to + * the hard limit to try to make core dump possible: * * Process.setrlimit(:CORE, Process.getrlimit(:CORE)[1]) * + * Not available on all platforms. */ static VALUE From 678112c57c54688013c41b6f0faaeca9d997e106 Mon Sep 17 00:00:00 2001 From: Kevin Newton Date: Sat, 2 Sep 2023 09:23:13 -0400 Subject: [PATCH 19/95] [ruby/yarp] Fix up template reading with LANG=C https://github.com/ruby/yarp/commit/1ce1817e84 --- yarp/templates/template.rb | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/yarp/templates/template.rb b/yarp/templates/template.rb index 680ab82620bc24..6534205004ffa1 100755 --- a/yarp/templates/template.rb +++ b/yarp/templates/template.rb @@ -264,13 +264,8 @@ class << self def template(name, write_to: nil) filepath = "templates/#{name}.erb" template = File.expand_path("../#{filepath}", __dir__) - write_to ||= File.expand_path("../#{name}", __dir__) - if ERB.instance_method(:initialize).parameters.assoc(:key) # Ruby 2.6+ - erb = ERB.new(File.read(template), trim_mode: "-") - else - erb = ERB.new(File.read(template), nil, "-") - end + erb = read_template(template) erb.filename = template non_ruby_heading = <<~HEADING @@ -299,13 +294,34 @@ def template(name, write_to: nil) non_ruby_heading end + write_to ||= File.expand_path("../#{name}", __dir__) contents = heading + erb.result_with_hash(locals) + FileUtils.mkdir_p(File.dirname(write_to)) File.write(write_to, contents) end private + def read_template(filepath) + previous_verbosity = $VERBOSE + previous_default_external = Encoding.default_external + $VERBOSE = nil + + begin + Encoding.default_external = Encoding::UTF_8 + + if ERB.instance_method(:initialize).parameters.assoc(:key) # Ruby 2.6+ + ERB.new(File.read(filepath), trim_mode: "-") + else + ERB.new(File.read(filepath), nil, "-") + end + ensure + Encoding.default_external = previous_default_external + $VERBOSE = previous_verbosity + end + end + def locals @locals ||= begin @@ -340,7 +356,6 @@ def locals if ARGV.empty? YARP::TEMPLATES.each { |filepath| YARP.template(filepath) } else # ruby/ruby - Encoding.default_external = Encoding::UTF_8 name, write_to = ARGV YARP.template(name, write_to: write_to) end From ef4dab6983267d6c6719629693baa59eb9c24543 Mon Sep 17 00:00:00 2001 From: Burdette Lamar Date: Sat, 2 Sep 2023 10:43:10 -0500 Subject: [PATCH 20/95] [DOC] RDoc for process.c (#8358) --- process.c | 112 +++++++++++++++++++++++++++++------------------------- 1 file changed, 60 insertions(+), 52 deletions(-) diff --git a/process.c b/process.c index e81b7e69f58b80..bb908e30b5c03f 100644 --- a/process.c +++ b/process.c @@ -6230,13 +6230,14 @@ p_sys_setresuid(VALUE obj, VALUE rid, VALUE eid, VALUE sid) /* * call-seq: - * Process.uid -> integer - * Process::UID.rid -> integer - * Process::Sys.getuid -> integer + * Process.uid -> integer + * Process::UID.rid -> integer + * Process::Sys.getuid -> integer * - * Returns the (real) user ID of this process. + * Returns the (real) user ID of the current process. + * + * Process.uid # => 1000 * - * Process.uid #=> 501 */ static VALUE @@ -6250,10 +6251,13 @@ proc_getuid(VALUE obj) #if defined(HAVE_SETRESUID) || defined(HAVE_SETREUID) || defined(HAVE_SETRUID) || defined(HAVE_SETUID) /* * call-seq: - * Process.uid= user -> numeric + * Process.uid = new_uid -> new_uid * - * Sets the (user) user ID for this process. Not available on all - * platforms. + * Sets the (user) user ID for the current process to +new_uid+: + * + * Process.uid = 1000 # => 1000 + * + * Not available on all platforms. */ static VALUE @@ -6628,13 +6632,14 @@ p_sys_issetugid(VALUE obj) /* * call-seq: - * Process.gid -> integer - * Process::GID.rid -> integer - * Process::Sys.getgid -> integer + * Process.gid -> integer + * Process::GID.rid -> integer + * Process::Sys.getgid -> integer + * + * Returns the (real) group ID for the current process: * - * Returns the (real) group ID for this process. + * Process.gid # => 1000 * - * Process.gid #=> 500 */ static VALUE @@ -6648,9 +6653,12 @@ proc_getgid(VALUE obj) #if defined(HAVE_SETRESGID) || defined(HAVE_SETREGID) || defined(HAVE_SETRGID) || defined(HAVE_SETGID) /* * call-seq: - * Process.gid= integer -> integer + * Process.gid = new_gid -> new_gid + * + * Sets the group ID for the current process to +new_gid+: + * + * Process.gid = 1000 # => 1000 * - * Sets the group ID for this process. */ static VALUE @@ -6734,26 +6742,23 @@ maxgroups(void) #ifdef HAVE_GETGROUPS /* * call-seq: - * Process.groups -> array + * Process.groups -> array * - * Get an Array of the group IDs in the - * supplemental group access list for this process. + * Returns an array of the group IDs + * in the supplemental group access list for the current process: * - * Process.groups #=> [27, 6, 10, 11] + * Process.groups # => [4, 24, 27, 30, 46, 122, 135, 136, 1000] * - * Note that this method is just a wrapper of getgroups(2). - * This means that the following characteristics of - * the result completely depend on your system: + * These properties of the returned array are system-dependent: * - * - the result is sorted - * - the result includes effective GIDs - * - the result does not include duplicated GIDs - * - the result size does not exceed the value of Process.maxgroups + * - Whether (and how) the array is sorted. + * - Whether the array includes effective group IDs. + * - Whether the array includes duplicate group IDs. + * - Whether the array size exceeds the value of Process.maxgroups. * - * You can make sure to get a sorted unique GID list of - * the current process by this expression: + * Use this call to get a sorted and unique array: * - * Process.groups.uniq.sort + * Process.groups.uniq.sort * */ @@ -6790,14 +6795,14 @@ proc_getgroups(VALUE obj) #ifdef HAVE_SETGROUPS /* * call-seq: - * Process.groups= array -> array + * Process.groups = new_groups -> new_groups * - * Set the supplemental group access list to the given - * Array of group IDs. + * Sets the supplemental group access list to the given + * array of group IDs. * - * Process.groups #=> [0, 1, 2, 3, 4, 6, 10, 11, 20, 26, 27] - * Process.groups = [27, 6, 10, 11] #=> [27, 6, 10, 11] - * Process.groups #=> [27, 6, 10, 11] + * Process.groups # => [0, 1, 2, 3, 4, 6, 10, 11, 20, 26, 27] + * Process.groups = [27, 6, 10, 11] # => [27, 6, 10, 11] + * Process.groups # => [27, 6, 10, 11] * */ @@ -6839,19 +6844,21 @@ proc_setgroups(VALUE obj, VALUE ary) #ifdef HAVE_INITGROUPS /* * call-seq: - * Process.initgroups(username, gid) -> array + * Process.initgroups(username, gid) -> array * - * Initializes the supplemental group access list by reading the - * system group database and using all groups of which the given user - * is a member. The group with the specified _gid_ is also added to - * the list. Returns the resulting Array of the GIDs of all the - * groups in the supplementary group access list. Not available on - * all platforms. + * Sets the supplemental group access list; + * the new list includes: * - * Process.groups #=> [0, 1, 2, 3, 4, 6, 10, 11, 20, 26, 27] - * Process.initgroups( "mgranger", 30 ) #=> [30, 6, 10, 11] - * Process.groups #=> [30, 6, 10, 11] + * - The group IDs of those groups to which the user given by +username+ belongs. + * - The group ID +gid+. + * + * Example: * + * Process.groups # => [0, 1, 2, 3, 4, 6, 10, 11, 20, 26, 27] + * Process.initgroups('me', 30) # => [30, 6, 10, 11] + * Process.groups # => [30, 6, 10, 11] + * + * Not available on all platforms. */ static VALUE @@ -6869,12 +6876,13 @@ proc_initgroups(VALUE obj, VALUE uname, VALUE base_grp) #if defined(_SC_NGROUPS_MAX) || defined(NGROUPS_MAX) /* * call-seq: - * Process.maxgroups -> integer + * Process.maxgroups -> integer + * + * Returns the maximum number of group IDs allowed + * in the supplemental group access list: * - * Returns the maximum number of GIDs allowed in the supplemental - * group access list. + * Process.maxgroups # => 32 * - * Process.maxgroups #=> 32 */ static VALUE @@ -6889,10 +6897,10 @@ proc_getmaxgroups(VALUE obj) #ifdef HAVE_SETGROUPS /* * call-seq: - * Process.maxgroups= integer -> integer + * Process.maxgroups = new_max -> new_max * - * Sets the maximum number of GIDs allowed in the supplemental group - * access list. + * Sets the maximum number of group IDs allowed + * in the supplemental group access list. */ static VALUE From 3887b45f47c32cf0171046bc23efc3887d8b58fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dorian=20Mari=C3=A9=20=28perso=29?= Date: Sat, 2 Sep 2023 18:46:33 +0200 Subject: [PATCH 21/95] [DOC] FIx typo in description of Hash#hash (regardless or/of order) --- hash.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hash.c b/hash.c index c445ca55664e78..4039e0851f980f 100644 --- a/hash.c +++ b/hash.c @@ -3772,7 +3772,7 @@ hash_i(VALUE key, VALUE val, VALUE arg) * Returns the Integer hash-code for the hash. * * Two \Hash objects have the same hash-code if their content is the same - * (regardless or order): + * (regardless of order): * h1 = {foo: 0, bar: 1, baz: 2} * h2 = {baz: 2, bar: 1, foo: 0} * h2.hash == h1.hash # => true From 8cd62fbc174beae65d5670ea92611cc7a9c34d7d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dorian=20Mari=C3=A9=20=28perso=29?= Date: Sat, 2 Sep 2023 18:47:50 +0200 Subject: [PATCH 22/95] [DOC] Typo in Hash#key description "so/no such value" --- hash.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hash.c b/hash.c index 4039e0851f980f..8c595e4595de7a 100644 --- a/hash.c +++ b/hash.c @@ -2287,7 +2287,7 @@ key_i(VALUE key, VALUE value, VALUE arg) * h.key(0) # => :foo * h.key(2) # => :bar * - * Returns +nil+ if so such value is found. + * Returns +nil+ if no such value is found. */ static VALUE From f867e936a98b320c4609d631d2f3046d463e7fc4 Mon Sep 17 00:00:00 2001 From: Herwin Date: Sat, 2 Sep 2023 18:49:40 +0200 Subject: [PATCH 23/95] [DOC] Fix layout in documentation of IO#fcntl --- io.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/io.c b/io.c index 433ec75b27f5e3..f0432142d38db9 100644 --- a/io.c +++ b/io.c @@ -11372,7 +11372,7 @@ rb_fcntl(VALUE io, VALUE req, VALUE arg) * a file-oriented I/O stream. Arguments and results are platform * dependent. * - * If +argument is a number, its value is passed directly; + * If +argument+ is a number, its value is passed directly; * if it is a string, it is interpreted as a binary sequence of bytes. * (Array#pack might be a useful way to build this string.) * From 3602e253e79b796661168b458e22ba1694ec06e5 Mon Sep 17 00:00:00 2001 From: BurdetteLamar Date: Sat, 2 Sep 2023 12:13:57 -0500 Subject: [PATCH 24/95] [DOC] RDoc for process.c --- process.c | 75 +++++++++++++++++++++++++++++++------------------------ 1 file changed, 43 insertions(+), 32 deletions(-) diff --git a/process.c b/process.c index bb908e30b5c03f..0c7191f72ccef7 100644 --- a/process.c +++ b/process.c @@ -6931,15 +6931,22 @@ static int rb_daemon(int nochdir, int noclose); /* * call-seq: - * Process.daemon() -> 0 - * Process.daemon(nochdir=nil,noclose=nil) -> 0 - * - * Detach the process from controlling terminal and run in the - * background as system daemon. Unless the argument _nochdir_ is - * +true+, it changes the current working directory to the root - * ("/"). Unless the argument _noclose_ is +true+, daemon() will - * redirect standard input, standard output and standard error to - * null device. Return zero on success, or raise one of Errno::*. + * Process.daemon(nochdir = nil, noclose = nil) -> 0 + * + * Detaches the current process from its controlling terminal + * and runs it in the background as system daemon; + * returns zero. + * + * By default: + * + * - Changes the current working directory to the root directory. + * - Redirects $stdin, $stdout, and $stderr to the null device. + * + * If optional argument +nochdir+ is +true+, + * does not change the current working directory. + * + * If optional argument +noclose+ is +true+, + * does not redirect $stdin, $stdout, or $stderr. */ static VALUE @@ -7196,13 +7203,14 @@ p_gid_change_privilege(VALUE obj, VALUE id) /* * call-seq: - * Process.euid -> integer - * Process::UID.eid -> integer - * Process::Sys.geteuid -> integer + * Process.euid -> integer + * Process::UID.eid -> integer + * Process::Sys.geteuid -> integer + * + * Returns the effective user ID for the current process. * - * Returns the effective user ID for this process. + * Process.euid # => 501 * - * Process.euid #=> 501 */ static VALUE @@ -7238,10 +7246,11 @@ proc_seteuid(rb_uid_t uid) #if defined(HAVE_SETRESUID) || defined(HAVE_SETREUID) || defined(HAVE_SETEUID) || defined(HAVE_SETUID) /* * call-seq: - * Process.euid= user + * Process.euid = new_euid -> new_euid + * + * Sets the effective user ID for the current process. * - * Sets the effective user ID for this process. Not available on all - * platforms. + * Not available on all platforms. */ static VALUE @@ -7319,14 +7328,15 @@ p_uid_grant_privilege(VALUE obj, VALUE id) /* * call-seq: - * Process.egid -> integer - * Process::GID.eid -> integer - * Process::Sys.geteid -> integer + * Process.egid -> integer + * Process::GID.eid -> integer + * Process::Sys.geteid -> integer + * + * Returns the effective group ID for the current process: * - * Returns the effective group ID for this process. Not available on - * all platforms. + * Process.egid # => 500 * - * Process.egid #=> 500 + * Not available on all platforms. */ static VALUE @@ -7340,10 +7350,11 @@ proc_getegid(VALUE obj) #if defined(HAVE_SETRESGID) || defined(HAVE_SETREGID) || defined(HAVE_SETEGID) || defined(HAVE_SETGID) || defined(_POSIX_SAVED_IDS) /* * call-seq: - * Process.egid = integer -> integer + * Process.egid = new_egid -> new_egid * - * Sets the effective group ID for this process. Not available on all - * platforms. + * Sets the effective group ID for the current process. + * + * Not available on all platforms. */ static VALUE @@ -7816,14 +7827,14 @@ get_clk_tck(void) /* * call-seq: - * Process.times -> aProcessTms + * Process.times -> process_tms + * + * Returns a Process::Tms structure that contains user and system CPU times + * for the current process, and for its children processes: * - * Returns a Tms structure (see Process::Tms) - * that contains user and system CPU times for this process, - * and also for children processes. + * Process.times + * # => # * - * t = Process.times - * [ t.utime, t.stime, t.cutime, t.cstime ] #=> [0.0, 0.02, 0.00, 0.00] */ VALUE From 40ab77eb3dd075536bcc3a6c225a7c245c247db8 Mon Sep 17 00:00:00 2001 From: Burdette Lamar Date: Sun, 3 Sep 2023 14:36:51 -0500 Subject: [PATCH 25/95] [DOC] Process doc (#8363) --- process.c | 329 +++++++++++++++++++++++++++++------------------------- 1 file changed, 180 insertions(+), 149 deletions(-) diff --git a/process.c b/process.c index 0c7191f72ccef7..77f38e1d98990a 100644 --- a/process.c +++ b/process.c @@ -8096,130 +8096,167 @@ ruby_real_ms_time(void) /* * call-seq: - * Process.clock_gettime(clock_id [, unit]) -> number - * - * Returns a time returned by POSIX clock_gettime() function. - * - * p Process.clock_gettime(Process::CLOCK_MONOTONIC) - * #=> 896053.968060096 - * - * +clock_id+ specifies a kind of clock. - * It is specified as a constant which begins with Process::CLOCK_ - * such as Process::CLOCK_REALTIME and Process::CLOCK_MONOTONIC. - * - * The supported constants depends on OS and version. - * Ruby provides following types of +clock_id+ if available. - * - * [CLOCK_REALTIME] SUSv2 to 4, Linux 2.5.63, FreeBSD 3.0, NetBSD 2.0, OpenBSD 2.1, macOS 10.12, Windows-8/Server-2012 - * [CLOCK_MONOTONIC] SUSv3 to 4, Linux 2.5.63, FreeBSD 3.0, NetBSD 2.0, OpenBSD 3.4, macOS 10.12, Windows-2000 - * [CLOCK_PROCESS_CPUTIME_ID] SUSv3 to 4, Linux 2.5.63, FreeBSD 9.3, OpenBSD 5.4, macOS 10.12 - * [CLOCK_THREAD_CPUTIME_ID] SUSv3 to 4, Linux 2.5.63, FreeBSD 7.1, OpenBSD 5.4, macOS 10.12 - * [CLOCK_VIRTUAL] FreeBSD 3.0, OpenBSD 2.1 - * [CLOCK_PROF] FreeBSD 3.0, OpenBSD 2.1 - * [CLOCK_REALTIME_FAST] FreeBSD 8.1 - * [CLOCK_REALTIME_PRECISE] FreeBSD 8.1 - * [CLOCK_REALTIME_COARSE] Linux 2.6.32 - * [CLOCK_REALTIME_ALARM] Linux 3.0 - * [CLOCK_MONOTONIC_FAST] FreeBSD 8.1 - * [CLOCK_MONOTONIC_PRECISE] FreeBSD 8.1 - * [CLOCK_MONOTONIC_COARSE] Linux 2.6.32 - * [CLOCK_MONOTONIC_RAW] Linux 2.6.28, macOS 10.12 - * [CLOCK_MONOTONIC_RAW_APPROX] macOS 10.12 - * [CLOCK_BOOTTIME] Linux 2.6.39 - * [CLOCK_BOOTTIME_ALARM] Linux 3.0 - * [CLOCK_UPTIME] FreeBSD 7.0, OpenBSD 5.5 - * [CLOCK_UPTIME_FAST] FreeBSD 8.1 - * [CLOCK_UPTIME_RAW] macOS 10.12 - * [CLOCK_UPTIME_RAW_APPROX] macOS 10.12 - * [CLOCK_UPTIME_PRECISE] FreeBSD 8.1 - * [CLOCK_SECOND] FreeBSD 8.1 - * [CLOCK_TAI] Linux 3.10 + * Process.clock_gettime(clock_id, unit = :float_second) -> number + * + * Returns a clock time as determined by POSIX function + * {clock_gettime()}[https://man7.org/linux/man-pages/man3/clock_gettime.3.html]: + * + * Process.clock_gettime(:CLOCK_PROCESS_CPUTIME_ID) # => 198.650379677 + * + * Argument +clock_id+ should be a symbol or a constant that specifies + * the clock whose time is to be returned; + * see below. + * + * Optional argument +unit+ should be a symbol that specifies + * the unit to be used in the returned clock time; + * see below. + * + * Argument +clock_id+ + * + * Argument +clock_id+ specifies the clock whose time is to be returned; + * it may be a constant such as Process::CLOCK_REALTIME, + * or a symbol shorthand such as +:CLOCK_REALTIME+. + * + * The supported clocks depend on the underlying operating system; + * this method supports the following clocks on the indicated platforms + * (raises Errno::EINVAL if called with an unsupported clock): + * + * - +:CLOCK_BOOTTIME+: Linux 2.6.39. + * - +:CLOCK_BOOTTIME_ALARM+: Linux 3.0. + * - +:CLOCK_MONOTONIC+: SUSv3 to 4, Linux 2.5.63, FreeBSD 3.0, NetBSD 2.0, OpenBSD 3.4, macOS 10.12, Windows-2000. + * - +:CLOCK_MONOTONIC_COARSE+: Linux 2.6.32. + * - +:CLOCK_MONOTONIC_FAST+: FreeBSD 8.1. + * - +:CLOCK_MONOTONIC_PRECISE+: FreeBSD 8.1. + * - +:CLOCK_MONOTONIC_RAW+: Linux 2.6.28, macOS 10.12. + * - +:CLOCK_MONOTONIC_RAW_APPROX+: macOS 10.12. + * - +:CLOCK_PROCESS_CPUTIME_ID+: SUSv3 to 4, Linux 2.5.63, FreeBSD 9.3, OpenBSD 5.4, macOS 10.12. + * - +:CLOCK_PROF+: FreeBSD 3.0, OpenBSD 2.1. + * - +:CLOCK_REALTIME+: SUSv2 to 4, Linux 2.5.63, FreeBSD 3.0, NetBSD 2.0, OpenBSD 2.1, macOS 10.12, Windows-8/Server-2012. + * Time.now is recommended over +:CLOCK_REALTIME:. + * - +:CLOCK_REALTIME_ALARM+: Linux 3.0. + * - +:CLOCK_REALTIME_COARSE+: Linux 2.6.32. + * - +:CLOCK_REALTIME_FAST+: FreeBSD 8.1. + * - +:CLOCK_REALTIME_PRECISE+: FreeBSD 8.1. + * - +:CLOCK_SECOND+: FreeBSD 8.1. + * - +:CLOCK_TAI+: Linux 3.10. + * - +:CLOCK_THREAD_CPUTIME_ID+: SUSv3 to 4, Linux 2.5.63, FreeBSD 7.1, OpenBSD 5.4, macOS 10.12. + * - +:CLOCK_UPTIME+: FreeBSD 7.0, OpenBSD 5.5. + * - +:CLOCK_UPTIME_FAST+: FreeBSD 8.1. + * - +:CLOCK_UPTIME_PRECISE+: FreeBSD 8.1. + * - +:CLOCK_UPTIME_RAW+: macOS 10.12. + * - +:CLOCK_UPTIME_RAW_APPROX+: macOS 10.12. + * - +:CLOCK_VIRTUAL+: FreeBSD 3.0, OpenBSD 2.1. * * Note that SUS stands for Single Unix Specification. * SUS contains POSIX and clock_gettime is defined in the POSIX part. - * SUS defines CLOCK_REALTIME mandatory but - * CLOCK_MONOTONIC, CLOCK_PROCESS_CPUTIME_ID and CLOCK_THREAD_CPUTIME_ID are optional. - * - * Also, several symbols are accepted as +clock_id+. - * There are emulations for clock_gettime(). - * - * For example, Process::CLOCK_REALTIME is defined as - * +:GETTIMEOFDAY_BASED_CLOCK_REALTIME+ when clock_gettime() is not available. - * - * Emulations for +CLOCK_REALTIME+: - * [:GETTIMEOFDAY_BASED_CLOCK_REALTIME] - * Use gettimeofday() defined by SUS. - * (SUSv4 obsoleted it, though.) - * The resolution is 1 microsecond. - * [:TIME_BASED_CLOCK_REALTIME] - * Use time() defined by ISO C. - * The resolution is 1 second. - * - * Emulations for +CLOCK_MONOTONIC+: - * [:MACH_ABSOLUTE_TIME_BASED_CLOCK_MONOTONIC] - * Use mach_absolute_time(), available on Darwin. - * The resolution is CPU dependent. - * [:TIMES_BASED_CLOCK_MONOTONIC] - * Use the result value of times() defined by POSIX. - * POSIX defines it as "times() shall return the elapsed real time, in clock ticks, since an arbitrary point in the past (for example, system start-up time)". - * For example, GNU/Linux returns a value based on jiffies and it is monotonic. - * However, 4.4BSD uses gettimeofday() and it is not monotonic. - * (FreeBSD uses clock_gettime(CLOCK_MONOTONIC) instead, though.) - * The resolution is the clock tick. - * "getconf CLK_TCK" command shows the clock ticks per second. - * (The clock ticks per second is defined by HZ macro in older systems.) - * If it is 100 and clock_t is 32 bits integer type, the resolution is 10 millisecond and - * cannot represent over 497 days. - * - * Emulations for +CLOCK_PROCESS_CPUTIME_ID+: - * [:GETRUSAGE_BASED_CLOCK_PROCESS_CPUTIME_ID] - * Use getrusage() defined by SUS. - * getrusage() is used with RUSAGE_SELF to obtain the time only for - * the calling process (excluding the time for child processes). - * The result is addition of user time (ru_utime) and system time (ru_stime). - * The resolution is 1 microsecond. - * [:TIMES_BASED_CLOCK_PROCESS_CPUTIME_ID] - * Use times() defined by POSIX. - * The result is addition of user time (tms_utime) and system time (tms_stime). - * tms_cutime and tms_cstime are ignored to exclude the time for child processes. - * The resolution is the clock tick. - * "getconf CLK_TCK" command shows the clock ticks per second. - * (The clock ticks per second is defined by HZ macro in older systems.) - * If it is 100, the resolution is 10 millisecond. - * [:CLOCK_BASED_CLOCK_PROCESS_CPUTIME_ID] - * Use clock() defined by ISO C. - * The resolution is 1/CLOCKS_PER_SEC. - * CLOCKS_PER_SEC is the C-level macro defined by time.h. - * SUS defines CLOCKS_PER_SEC is 1000000. - * Non-Unix systems may define it a different value, though. - * If CLOCKS_PER_SEC is 1000000 as SUS, the resolution is 1 microsecond. - * If CLOCKS_PER_SEC is 1000000 and clock_t is 32 bits integer type, it cannot represent over 72 minutes. - * - * If the given +clock_id+ is not supported, Errno::EINVAL is raised. - * - * +unit+ specifies a type of the return value. - * - * [:float_second] number of seconds as a float (default) - * [:float_millisecond] number of milliseconds as a float - * [:float_microsecond] number of microseconds as a float - * [:second] number of seconds as an integer - * [:millisecond] number of milliseconds as an integer - * [:microsecond] number of microseconds as an integer - * [:nanosecond] number of nanoseconds as an integer + * SUS defines +:CLOCK_REALTIME+ as mandatory but + * +:CLOCK_MONOTONIC+, +:CLOCK_PROCESS_CPUTIME_ID+, + * and +:CLOCK_THREAD_CPUTIME_ID+ are optional. + * + * Certain emulations are used when the given +clock_id+ + * is not supported directly: + * + * - Emulations for +:CLOCK_REALTIME+: + * + * - +:GETTIMEOFDAY_BASED_CLOCK_REALTIME+: + * Use gettimeofday() defined by SUS (deprecated in SUSv4). + * The resolution is 1 microsecond. + * - +:TIME_BASED_CLOCK_REALTIME+: + * Use time() defined by ISO C. + * The resolution is 1 second. + * + * - Emulations for +:CLOCK_MONOTONIC+: + * + * - +:MACH_ABSOLUTE_TIME_BASED_CLOCK_MONOTONIC+: + * Use mach_absolute_time(), available on Darwin. + * The resolution is CPU dependent. + * - +:TIMES_BASED_CLOCK_MONOTONIC+: + * Use the result value of times() defined by POSIX, thus: + * >>> + * Upon successful completion, times() shall return the elapsed real time, + * in clock ticks, since an arbitrary point in the past + * (for example, system start-up time). + * + * For example, GNU/Linux returns a value based on jiffies and it is monotonic. + * However, 4.4BSD uses gettimeofday() and it is not monotonic. + * (FreeBSD uses +:CLOCK_MONOTONIC+ instead, though.) + * + * The resolution is the clock tick. + * "getconf CLK_TCK" command shows the clock ticks per second. + * (The clock ticks-per-second is defined by HZ macro in older systems.) + * If it is 100 and clock_t is 32 bits integer type, + * the resolution is 10 millisecond and cannot represent over 497 days. + * + * - Emulations for +:CLOCK_PROCESS_CPUTIME_ID+: + * + * - +:GETRUSAGE_BASED_CLOCK_PROCESS_CPUTIME_ID+: + * Use getrusage() defined by SUS. + * getrusage() is used with RUSAGE_SELF to obtain the time only for + * the calling process (excluding the time for child processes). + * The result is addition of user time (ru_utime) and system time (ru_stime). + * The resolution is 1 microsecond. + * - +:TIMES_BASED_CLOCK_PROCESS_CPUTIME_ID+: + * Use times() defined by POSIX. + * The result is addition of user time (tms_utime) and system time (tms_stime). + * tms_cutime and tms_cstime are ignored to exclude the time for child processes. + * The resolution is the clock tick. + * "getconf CLK_TCK" command shows the clock ticks per second. + * (The clock ticks per second is defined by HZ macro in older systems.) + * If it is 100, the resolution is 10 millisecond. + * - +:CLOCK_BASED_CLOCK_PROCESS_CPUTIME_ID+: + * Use clock() defined by ISO C. + * The resolution is 1/CLOCKS_PER_SEC. + * +CLOCKS_PER_SEC+ is the C-level macro defined by time.h. + * SUS defines +CLOCKS_PER_SEC+ as 1000000; + * other systems may define it differently. + * If +CLOCKS_PER_SEC+ is 1000000 (as in SUS), + * the resolution is 1 microsecond. + * If +CLOCKS_PER_SEC+ is 1000000 and clock_t is a 32-bit integer type, + * it cannot represent over 72 minutes. + * + * Argument +unit+ + * + * Optional argument +unit+ (default +:float_second+) + * specifies the unit for the returned value. + * + * - +:float_microsecond+: Number of microseconds as a float. + * - +:float_millisecond+: Number of milliseconds as a float. + * - +:float_second+: Number of seconds as a float. + * - +:microsecond+: Number of microseconds as an integer. + * - +:millisecond+: Number of milliseconds as an integer. + * - +:nanosecond+: Number of nanoseconds as an integer. + * - +::second+: Number of seconds as an integer. + * + * Examples: + * + * Process.clock_gettime(:CLOCK_PROCESS_CPUTIME_ID, :float_microsecond) + * # => 203605054.825 + * Process.clock_gettime(:CLOCK_PROCESS_CPUTIME_ID, :float_millisecond) + * # => 203643.696848 + * Process.clock_gettime(:CLOCK_PROCESS_CPUTIME_ID, :float_second) + * # => 203.762181929 + * Process.clock_gettime(:CLOCK_PROCESS_CPUTIME_ID, :microsecond) + * # => 204123212 + * Process.clock_gettime(:CLOCK_PROCESS_CPUTIME_ID, :millisecond) + * # => 204298 + * Process.clock_gettime(:CLOCK_PROCESS_CPUTIME_ID, :nanosecond) + * # => 204602286036 + * Process.clock_gettime(:CLOCK_PROCESS_CPUTIME_ID, :second) + * # => 204 * * The underlying function, clock_gettime(), returns a number of nanoseconds. * Float object (IEEE 754 double) is not enough to represent - * the return value for CLOCK_REALTIME. + * the return value for +:CLOCK_REALTIME+. * If the exact nanoseconds value is required, use +:nanosecond+ as the +unit+. * - * The origin (zero) of the returned value varies. - * For example, system start up time, process start up time, the Epoch, etc. + * The origin (time zero) of the returned value is system-dependent, + * and may be, for example, system start up time, + * process start up time, the Epoch, etc. * - * The origin in CLOCK_REALTIME is defined as the Epoch - * (1970-01-01 00:00:00 UTC). - * But some systems count leap seconds and others doesn't. - * So the result can be interpreted differently across systems. - * Time.now is recommended over CLOCK_REALTIME. + * The origin in +:CLOCK_REALTIME+ is defined as the Epoch: + * 1970-01-01 00:00:00 UTC; + * some systems count leap seconds and others don't, + * so the result may vary across systems. */ static VALUE rb_clock_gettime(int argc, VALUE *argv, VALUE _) @@ -8414,45 +8451,39 @@ rb_clock_gettime(int argc, VALUE *argv, VALUE _) /* * call-seq: - * Process.clock_getres(clock_id [, unit]) -> number - * - * Returns an estimate of the resolution of a +clock_id+ using the POSIX - * clock_getres() function. - * - * Note the reported resolution is often inaccurate on most platforms due to - * underlying bugs for this function and therefore the reported resolution - * often differs from the actual resolution of the clock in practice. - * Inaccurate reported resolutions have been observed for various clocks including - * CLOCK_MONOTONIC and CLOCK_MONOTONIC_RAW when using Linux, macOS, BSD or AIX - * platforms, when using ARM processors, or when using virtualization. + * Process.clock_getres(clock_id, unit = :float_second) -> number * - * +clock_id+ specifies a kind of clock. - * See the document of +Process.clock_gettime+ for details. - * +clock_id+ can be a symbol as for +Process.clock_gettime+. + * Returns a clock resolution as determined by POSIX function + * {clock_getres()}[https://man7.org/linux/man-pages/man3/clock_getres.3.html]: * - * If the given +clock_id+ is not supported, Errno::EINVAL is raised. + * Process.clock_getres(:CLOCK_REALTIME) # => 1.0e-09 * - * +unit+ specifies the type of the return value. - * +Process.clock_getres+ accepts +unit+ as +Process.clock_gettime+. - * The default value, +:float_second+, is also the same as - * +Process.clock_gettime+. + * See Process.clock_gettime for the values of +clock_id+ and +unit+. * - * +Process.clock_getres+ also accepts +:hertz+ as +unit+. - * +:hertz+ means the reciprocal of +:float_second+. - * - * +:hertz+ can be used to obtain the exact value of - * the clock ticks per second for the times() function and - * CLOCKS_PER_SEC for the clock() function. - * - * Process.clock_getres(:TIMES_BASED_CLOCK_PROCESS_CPUTIME_ID, :hertz) - * returns the clock ticks per second. - * - * Process.clock_getres(:CLOCK_BASED_CLOCK_PROCESS_CPUTIME_ID, :hertz) - * returns CLOCKS_PER_SEC. - * - * p Process.clock_getres(Process::CLOCK_MONOTONIC) - * #=> 1.0e-09 + * Examples: * + * Process.clock_getres(:CLOCK_PROCESS_CPUTIME_ID, :float_microsecond) # => 0.001 + * Process.clock_getres(:CLOCK_PROCESS_CPUTIME_ID, :float_millisecond) # => 1.0e-06 + * Process.clock_getres(:CLOCK_PROCESS_CPUTIME_ID, :float_second) # => 1.0e-09 + * Process.clock_getres(:CLOCK_PROCESS_CPUTIME_ID, :microsecond) # => 0 + * Process.clock_getres(:CLOCK_PROCESS_CPUTIME_ID, :millisecond) # => 0 + * Process.clock_getres(:CLOCK_PROCESS_CPUTIME_ID, :nanosecond) # => 1 + * Process.clock_getres(:CLOCK_PROCESS_CPUTIME_ID, :second) # => 0 + * + * In addition to the values for +unit+ supported in Process.clock_gettime, + * this method supports +:hertz+, the integer number of clock ticks per second + * (which is the reciprocal of +:float_second+): + * + * Process.clock_getres(:TIMES_BASED_CLOCK_PROCESS_CPUTIME_ID, :hertz) # => 100.0 + * Process.clock_getres(:TIMES_BASED_CLOCK_PROCESS_CPUTIME_ID, :float_second) # => 0.01 + * + * Accuracy: + * Note that the returned resolution may be inaccurate on some platforms + * due to underlying bugs. + * Inaccurate resolutions have been reported for various clocks including + * +:CLOCK_MONOTONIC+ and +:CLOCK_MONOTONIC_RAW+ + * on Linux, macOS, BSD or AIX platforms, when using ARM processors, + * or when using virtualization. */ static VALUE rb_clock_getres(int argc, VALUE *argv, VALUE _) From 7e0f5df2f99693267d61636d23da47f79924e9d5 Mon Sep 17 00:00:00 2001 From: Samuel Williams Date: Mon, 4 Sep 2023 13:31:25 +1200 Subject: [PATCH 26/95] Don't reset line coverage for evaled code. (#8330) * Add failing test. --- compile.c | 3 ++- test/coverage/test_coverage.rb | 12 ++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/compile.c b/compile.c index 4d344fff9c6aca..ba78040048556a 100644 --- a/compile.c +++ b/compile.c @@ -2336,7 +2336,8 @@ iseq_set_sequence(rb_iseq_t *iseq, LINK_ANCHOR *const anchor) !(rb_get_coverage_mode() & COVERAGE_TARGET_ONESHOT_LINES)) { int line = iobj->insn_info.line_no - 1; if (line >= 0 && line < RARRAY_LEN(ISEQ_LINE_COVERAGE(iseq))) { - RARRAY_ASET(ISEQ_LINE_COVERAGE(iseq), line, INT2FIX(0)); + if (RARRAY_AREF(ISEQ_LINE_COVERAGE(iseq), line) == Qnil) + RARRAY_ASET(ISEQ_LINE_COVERAGE(iseq), line, INT2FIX(0)); } } if (ISEQ_BRANCH_COVERAGE(iseq) && (events & RUBY_EVENT_COVERAGE_BRANCH)) { diff --git a/test/coverage/test_coverage.rb b/test/coverage/test_coverage.rb index 6afef8ce1bc156..e4655119b72d12 100644 --- a/test/coverage/test_coverage.rb +++ b/test/coverage/test_coverage.rb @@ -181,6 +181,18 @@ def test_eval_coverage end; end + def test_eval_coverage_repeated + assert_in_out_err(%w[-rcoverage], <<-"end;", ["[3]"], []) + Coverage.start(eval: true, lines: true) + + 3.times do + eval("Object.new", nil, "test.rb") + end + + p Coverage.result["test.rb"][:lines] + end; + end + def test_coverage_supported assert Coverage.supported?(:lines) assert Coverage.supported?(:oneshot_lines) From 3b7c8e90da5c27c9355c9890b333585b45ae67eb Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada Date: Mon, 4 Sep 2023 09:23:31 +0900 Subject: [PATCH 27/95] [DOC] Fix indent of `set_trace_func` document --- vm_trace.c | 92 ++++++++++++++++++++++++++++-------------------------- 1 file changed, 47 insertions(+), 45 deletions(-) diff --git a/vm_trace.c b/vm_trace.c index 30e2112a640ac8..b7ccc26455f62d 100644 --- a/vm_trace.c +++ b/vm_trace.c @@ -510,62 +510,64 @@ static void call_trace_func(rb_event_flag_t, VALUE data, VALUE self, ID id, VALU /* (2-1) set_trace_func (old API) */ /* - * call-seq: - * set_trace_func(proc) -> proc - * set_trace_func(nil) -> nil + * call-seq: + * set_trace_func(proc) -> proc + * set_trace_func(nil) -> nil + * + * Establishes _proc_ as the handler for tracing, or disables + * tracing if the parameter is +nil+. * - * Establishes _proc_ as the handler for tracing, or disables - * tracing if the parameter is +nil+. + * *Note:* this method is obsolete, please use TracePoint instead. * - * *Note:* this method is obsolete, please use TracePoint instead. + * _proc_ takes up to six parameters: * - * _proc_ takes up to six parameters: + * * an event name + * * a filename + * * a line number + * * an object id + * * a binding + * * the name of a class * - * * an event name - * * a filename - * * a line number - * * an object id - * * a binding - * * the name of a class + * _proc_ is invoked whenever an event occurs. * - * _proc_ is invoked whenever an event occurs. + * Events are: * - * Events are: + * +c-call+:: call a C-language routine + * +c-return+:: return from a C-language routine + * +call+:: call a Ruby method + * +class+:: start a class or module definition + * +end+:: finish a class or module definition + * +line+:: execute code on a new line + * +raise+:: raise an exception + * +return+:: return from a Ruby method * - * +c-call+:: call a C-language routine - * +c-return+:: return from a C-language routine - * +call+:: call a Ruby method - * +class+:: start a class or module definition - * +end+:: finish a class or module definition - * +line+:: execute code on a new line - * +raise+:: raise an exception - * +return+:: return from a Ruby method + * Tracing is disabled within the context of _proc_. * - * Tracing is disabled within the context of _proc_. + * class Test + * def test + * a = 1 + * b = 2 + * end + * end * - * class Test - * def test - * a = 1 - * b = 2 - * end - * end + * set_trace_func proc { |event, file, line, id, binding, classname| + * printf "%8s %s:%-2d %10s %8s\n", event, file, line, id, classname + * } + * t = Test.new + * t.test * - * set_trace_func proc { |event, file, line, id, binding, classname| - * printf "%8s %s:%-2d %10s %8s\n", event, file, line, id, classname - * } - * t = Test.new - * t.test + * Produces: * - * line prog.rb:11 false - * c-call prog.rb:11 new Class - * c-call prog.rb:11 initialize Object - * c-return prog.rb:11 initialize Object - * c-return prog.rb:11 new Class - * line prog.rb:12 false - * call prog.rb:2 test Test - * line prog.rb:3 test Test - * line prog.rb:4 test Test - * return prog.rb:4 test Test + * line prog.rb:11 false + * c-call prog.rb:11 new Class + * c-call prog.rb:11 initialize Object + * c-return prog.rb:11 initialize Object + * c-return prog.rb:11 new Class + * line prog.rb:12 false + * call prog.rb:2 test Test + * line prog.rb:3 test Test + * line prog.rb:4 test Test + * return prog.rb:4 test Test * * Note that for +c-call+ and +c-return+ events, the binding returned is the * binding of the nearest Ruby method calling the C method, since C methods From ba8a7ab8a8afdd2160a22b34477920f4db00db8f Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada Date: Mon, 4 Sep 2023 10:20:04 +0900 Subject: [PATCH 28/95] [DOC] Update `set_trace_func` document - Clarify the class of event parameters - Represent event names as strings - Update the example to show the above --- vm_trace.c | 51 ++++++++++++++++++++++++++------------------------- 1 file changed, 26 insertions(+), 25 deletions(-) diff --git a/vm_trace.c b/vm_trace.c index b7ccc26455f62d..4b7d1d305dde74 100644 --- a/vm_trace.c +++ b/vm_trace.c @@ -521,25 +521,25 @@ static void call_trace_func(rb_event_flag_t, VALUE data, VALUE self, ID id, VALU * * _proc_ takes up to six parameters: * - * * an event name - * * a filename + * * an event name string + * * a filename string * * a line number - * * an object id - * * a binding - * * the name of a class + * * a method name symbol, or nil + * * a binding, or nil + * * the class, module, or nil * * _proc_ is invoked whenever an event occurs. * * Events are: * - * +c-call+:: call a C-language routine - * +c-return+:: return from a C-language routine - * +call+:: call a Ruby method - * +class+:: start a class or module definition - * +end+:: finish a class or module definition - * +line+:: execute code on a new line - * +raise+:: raise an exception - * +return+:: return from a Ruby method + * "c-call":: call a C-language routine + * "c-return":: return from a C-language routine + * "call":: call a Ruby method + * "class":: start a class or module definition + * "end":: finish a class or module definition + * "line":: execute code on a new line + * "raise":: raise an exception + * "return":: return from a Ruby method * * Tracing is disabled within the context of _proc_. * @@ -550,24 +550,25 @@ static void call_trace_func(rb_event_flag_t, VALUE data, VALUE self, ID id, VALU * end * end * - * set_trace_func proc { |event, file, line, id, binding, classname| - * printf "%8s %s:%-2d %10s %8s\n", event, file, line, id, classname + * set_trace_func proc { |event, file, line, id, binding, class_or_module| + * printf "%8s %s:%-2d %16p %14p\n", event, file, line, id, class_or_module * } * t = Test.new * t.test * * Produces: * - * line prog.rb:11 false - * c-call prog.rb:11 new Class - * c-call prog.rb:11 initialize Object - * c-return prog.rb:11 initialize Object - * c-return prog.rb:11 new Class - * line prog.rb:12 false - * call prog.rb:2 test Test - * line prog.rb:3 test Test - * line prog.rb:4 test Test - * return prog.rb:4 test Test + * c-return prog.rb:8 :set_trace_func Kernel + * line prog.rb:11 nil nil + * c-call prog.rb:11 :new Class + * c-call prog.rb:11 :initialize BasicObject + * c-return prog.rb:11 :initialize BasicObject + * c-return prog.rb:11 :new Class + * line prog.rb:12 nil nil + * call prog.rb:2 :test Test + * line prog.rb:3 :test Test + * line prog.rb:4 :test Test + * return prog.rb:5 :test Test * * Note that for +c-call+ and +c-return+ events, the binding returned is the * binding of the nearest Ruby method calling the C method, since C methods From 2ac3e9abe98579261a21a2e33df16f1bff1ebc1d Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada Date: Mon, 4 Sep 2023 10:30:57 +0900 Subject: [PATCH 29/95] [Bug #18487] [DOC] Remove stale note in `set_trace_func` document `c-call` and `c-return events no longer pass the nearest Ruby method binding. --- vm_trace.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/vm_trace.c b/vm_trace.c index 4b7d1d305dde74..3e11131bddacc0 100644 --- a/vm_trace.c +++ b/vm_trace.c @@ -569,10 +569,6 @@ static void call_trace_func(rb_event_flag_t, VALUE data, VALUE self, ID id, VALU * line prog.rb:3 :test Test * line prog.rb:4 :test Test * return prog.rb:5 :test Test - * - * Note that for +c-call+ and +c-return+ events, the binding returned is the - * binding of the nearest Ruby method calling the C method, since C methods - * themselves do not have bindings. */ static VALUE From 4cc56592932d36c202b2366ffe7ad71db2f5ea0b Mon Sep 17 00:00:00 2001 From: Peter Zhu Date: Fri, 1 Sep 2023 10:07:32 -0400 Subject: [PATCH 30/95] Keep write-barrier status after splicing array We don't need to remove the write-barrier protected status after splicing an array. We can simply add it to the rememberset for marking during the next GC. The benchmark illustrates the performance impact on minor GC: ``` require "benchmark" arys = 1_000_000.times.map do ary = Array.new(50) ary.insert(1, 3) ary end 4.times { GC.start } puts(Benchmark.measure do 1000.times do GC.start(full_mark: false) end end) ``` This branch: ``` 1.309910 0.004342 1.314252 ( 1.314580) ``` Master branch: ``` 54.376091 0.219037 54.595128 ( 54.742996) ``` --- array.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/array.c b/array.c index 65041c9365f359..103269630839a4 100644 --- a/array.c +++ b/array.c @@ -2176,9 +2176,14 @@ rb_ary_splice(VALUE ary, long beg, long len, const VALUE *rptr, long rlen) ARY_SET_LEN(ary, alen); } if (rlen > 0) { - if (rofs != -1) rptr = RARRAY_CONST_PTR(ary) + rofs; - /* give up wb-protected ary */ - RB_OBJ_WB_UNPROTECT_FOR(ARRAY, ary); + if (rofs == -1) { + rb_gc_writebarrier_remember(ary); + } + else { + /* In this case, we're copying from a region in this array, so + * we don't need to fire the write barrier. */ + rptr = RARRAY_CONST_PTR(ary) + rofs; + } /* do not use RARRAY_PTR() because it can causes GC. * ary can contain T_NONE object because it is not cleared. From 4f4c1170bc988104f3bd3321558099af7ea19c18 Mon Sep 17 00:00:00 2001 From: Yusuke Endoh Date: Mon, 4 Sep 2023 19:51:40 +0900 Subject: [PATCH 31/95] Revert "Don't reset line coverage for evaled code. (#8330)" This reverts commit 7e0f5df2f99693267d61636d23da47f79924e9d5. https://bugs.ruby-lang.org/issues/19857#note-7 --- compile.c | 3 +-- test/coverage/test_coverage.rb | 12 ------------ 2 files changed, 1 insertion(+), 14 deletions(-) diff --git a/compile.c b/compile.c index ba78040048556a..4d344fff9c6aca 100644 --- a/compile.c +++ b/compile.c @@ -2336,8 +2336,7 @@ iseq_set_sequence(rb_iseq_t *iseq, LINK_ANCHOR *const anchor) !(rb_get_coverage_mode() & COVERAGE_TARGET_ONESHOT_LINES)) { int line = iobj->insn_info.line_no - 1; if (line >= 0 && line < RARRAY_LEN(ISEQ_LINE_COVERAGE(iseq))) { - if (RARRAY_AREF(ISEQ_LINE_COVERAGE(iseq), line) == Qnil) - RARRAY_ASET(ISEQ_LINE_COVERAGE(iseq), line, INT2FIX(0)); + RARRAY_ASET(ISEQ_LINE_COVERAGE(iseq), line, INT2FIX(0)); } } if (ISEQ_BRANCH_COVERAGE(iseq) && (events & RUBY_EVENT_COVERAGE_BRANCH)) { diff --git a/test/coverage/test_coverage.rb b/test/coverage/test_coverage.rb index e4655119b72d12..6afef8ce1bc156 100644 --- a/test/coverage/test_coverage.rb +++ b/test/coverage/test_coverage.rb @@ -181,18 +181,6 @@ def test_eval_coverage end; end - def test_eval_coverage_repeated - assert_in_out_err(%w[-rcoverage], <<-"end;", ["[3]"], []) - Coverage.start(eval: true, lines: true) - - 3.times do - eval("Object.new", nil, "test.rb") - end - - p Coverage.result["test.rb"][:lines] - end; - end - def test_coverage_supported assert Coverage.supported?(:lines) assert Coverage.supported?(:oneshot_lines) From 3504f928dfb60b763e7b66149ca45cdbb45df78a Mon Sep 17 00:00:00 2001 From: Benoit Daloze Date: Mon, 4 Sep 2023 16:07:44 +0200 Subject: [PATCH 32/95] Update to ruby/mspec@55d1a62 --- spec/mspec/lib/mspec/utils/options.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/mspec/lib/mspec/utils/options.rb b/spec/mspec/lib/mspec/utils/options.rb index 612caf6771ef34..3b5962dbe6e751 100644 --- a/spec/mspec/lib/mspec/utils/options.rb +++ b/spec/mspec/lib/mspec/utils/options.rb @@ -477,7 +477,7 @@ def actions def debug on("-d", "--debug", - "Set MSpec debugging flag for more verbose output") do + "Disable MSpec backtrace filtering") do $MSPEC_DEBUG = true end end From 0b5c61494eb30c8c1867b9e6a52ad678e3f47901 Mon Sep 17 00:00:00 2001 From: Benoit Daloze Date: Mon, 4 Sep 2023 16:07:46 +0200 Subject: [PATCH 33/95] Update to ruby/spec@96d1072 --- spec/ruby/core/class/dup_spec.rb | 3 + spec/ruby/core/data/fixtures/classes.rb | 2 +- spec/ruby/core/dir/exist_spec.rb | 8 ++ spec/ruby/core/dir/shared/chroot.rb | 4 +- spec/ruby/core/dir/shared/exist.rb | 8 +- .../core/enumerator/chain/initialize_spec.rb | 4 +- spec/ruby/core/enumerator/each_spec.rb | 18 ++-- .../enumerator/generator/initialize_spec.rb | 4 +- spec/ruby/core/enumerator/initialize_spec.rb | 4 +- .../core/enumerator/lazy/initialize_spec.rb | 4 +- .../ruby/core/enumerator/product/each_spec.rb | 73 +++++++++++++++ .../product/initialize_copy_spec.rb | 54 +++++++++++ .../enumerator/product/initialize_spec.rb | 33 +++++++ .../core/enumerator/product/inspect_spec.rb | 22 +++++ .../core/enumerator/product/rewind_spec.rb | 64 +++++++++++++ .../ruby/core/enumerator/product/size_spec.rb | 64 +++++++++++++ spec/ruby/core/enumerator/product_spec.rb | 5 + spec/ruby/core/enumerator/rewind_spec.rb | 4 +- spec/ruby/core/env/delete_spec.rb | 8 ++ spec/ruby/core/env/key_spec.rb | 32 ++++++- spec/ruby/core/env/shared/include.rb | 7 ++ spec/ruby/core/env/shared/key.rb | 31 ------- spec/ruby/core/env/shared/value.rb | 7 ++ spec/ruby/core/env/slice_spec.rb | 10 ++ spec/ruby/core/exception/equal_value_spec.rb | 14 +-- spec/ruby/core/false/singleton_method_spec.rb | 6 +- spec/ruby/core/fiber/storage_spec.rb | 92 +++++++++++++------ spec/ruby/core/file/absolute_path_spec.rb | 2 +- spec/ruby/core/file/exist_spec.rb | 8 ++ spec/ruby/core/file/open_spec.rb | 2 +- spec/ruby/core/file/realpath_spec.rb | 4 + spec/ruby/core/io/eof_spec.rb | 2 +- spec/ruby/core/io/getbyte_spec.rb | 16 ++++ spec/ruby/core/io/new_spec.rb | 2 +- spec/ruby/core/io/select_spec.rb | 15 ++- spec/ruby/core/io/shared/new.rb | 2 +- spec/ruby/core/kernel/initialize_copy_spec.rb | 9 +- .../ruby/core/kernel/require_relative_spec.rb | 8 +- spec/ruby/core/kernel/shared/sprintf.rb | 4 +- spec/ruby/core/kernel/test_spec.rb | 4 +- spec/ruby/core/marshal/dump_spec.rb | 15 ++- spec/ruby/core/marshal/shared/load.rb | 8 +- spec/ruby/core/method/source_location_spec.rb | 2 +- spec/ruby/core/module/const_added_spec.rb | 35 +++++++ spec/ruby/core/module/define_method_spec.rb | 27 ++++++ spec/ruby/core/mutex/lock_spec.rb | 4 - spec/ruby/core/nil/singleton_method_spec.rb | 6 +- spec/ruby/core/numeric/clone_spec.rb | 2 +- spec/ruby/core/proc/source_location_spec.rb | 8 +- spec/ruby/core/process/argv0_spec.rb | 2 +- spec/ruby/core/process/exec_spec.rb | 2 +- spec/ruby/core/process/spawn_spec.rb | 2 +- spec/ruby/core/random/bytes_spec.rb | 1 - spec/ruby/core/range/cover_spec.rb | 4 + spec/ruby/core/range/include_spec.rb | 4 + .../core/range/shared/cover_and_include.rb | 1 - .../core/refinement/extend_object_spec.rb | 6 +- spec/ruby/core/struct/constants_spec.rb | 15 +++ .../thread/backtrace/location/path_spec.rb | 2 +- spec/ruby/core/true/singleton_method_spec.rb | 6 +- .../unboundmethod/source_location_spec.rb | 2 +- .../core/warning/element_reference_spec.rb | 4 +- spec/ruby/core/warning/element_set_spec.rb | 12 +++ spec/ruby/language/method_spec.rb | 40 ++++++-- spec/ruby/language/predefined_spec.rb | 2 +- spec/ruby/library/bigdecimal/add_spec.rb | 2 +- .../library/date/deconstruct_keys_spec.rb | 3 +- spec/ruby/library/date/strftime_spec.rb | 5 +- .../library/datetime/deconstruct_keys_spec.rb | 3 +- spec/ruby/library/datetime/strftime_spec.rb | 5 +- spec/ruby/library/datetime/to_time_spec.rb | 3 +- .../library/net/ftp/shared/getbinaryfile.rb | 2 +- .../library/net/ftp/shared/putbinaryfile.rb | 2 +- .../library/net/ftp/shared/puttextfile.rb | 2 +- spec/ruby/library/net/ftp/storbinary_spec.rb | 2 +- spec/ruby/library/net/ftp/storlines_spec.rb | 2 +- spec/ruby/library/set/divide_spec.rb | 35 ++++++- spec/ruby/library/set/shared/inspect.rb | 10 +- spec/ruby/library/time/to_datetime_spec.rb | 4 +- spec/ruby/library/yaml/fixtures/common.rb | 2 +- spec/ruby/optional/capi/kernel_spec.rb | 5 + spec/ruby/optional/capi/object_spec.rb | 2 +- spec/ruby/shared/file/exist.rb | 5 - spec/ruby/spec_helper.rb | 2 +- 84 files changed, 787 insertions(+), 184 deletions(-) create mode 100644 spec/ruby/core/enumerator/product/each_spec.rb create mode 100644 spec/ruby/core/enumerator/product/initialize_copy_spec.rb create mode 100644 spec/ruby/core/enumerator/product/initialize_spec.rb create mode 100644 spec/ruby/core/enumerator/product/inspect_spec.rb create mode 100644 spec/ruby/core/enumerator/product/rewind_spec.rb create mode 100644 spec/ruby/core/enumerator/product/size_spec.rb delete mode 100644 spec/ruby/core/env/shared/key.rb create mode 100644 spec/ruby/core/struct/constants_spec.rb diff --git a/spec/ruby/core/class/dup_spec.rb b/spec/ruby/core/class/dup_spec.rb index 701fd72e19c058..c09ed71b311527 100644 --- a/spec/ruby/core/class/dup_spec.rb +++ b/spec/ruby/core/class/dup_spec.rb @@ -61,4 +61,7 @@ def self.message CoreClassSpecs::RecordCopy.name.should == "CoreClassSpecs::RecordCopy" end + it "raises TypeError if called on BasicObject" do + -> { BasicObject.dup }.should raise_error(TypeError, "can't copy the root class") + end end diff --git a/spec/ruby/core/data/fixtures/classes.rb b/spec/ruby/core/data/fixtures/classes.rb index d1e10e02edb597..46a6b48bb21d75 100644 --- a/spec/ruby/core/data/fixtures/classes.rb +++ b/spec/ruby/core/data/fixtures/classes.rb @@ -1,5 +1,5 @@ module DataSpecs - ruby_version_is "3.2" do + guard -> { ruby_version_is "3.2" and Data.respond_to?(:define) } do Measure = Data.define(:amount, :unit) end end diff --git a/spec/ruby/core/dir/exist_spec.rb b/spec/ruby/core/dir/exist_spec.rb index 43987b0f324082..9023de533fd3ff 100644 --- a/spec/ruby/core/dir/exist_spec.rb +++ b/spec/ruby/core/dir/exist_spec.rb @@ -13,3 +13,11 @@ it_behaves_like :dir_exist, :exist? end + +ruby_version_is "3.2" do + describe "Dir.exists?" do + it "has been removed" do + Dir.should_not.respond_to?(:exists?) + end + end +end diff --git a/spec/ruby/core/dir/shared/chroot.rb b/spec/ruby/core/dir/shared/chroot.rb index 8c0599fe3f175d..a8f7c10a199a0f 100644 --- a/spec/ruby/core/dir/shared/chroot.rb +++ b/spec/ruby/core/dir/shared/chroot.rb @@ -2,7 +2,7 @@ before :all do DirSpecs.create_mock_dirs - @real_root = "../" * (File.dirname(__FILE__).count('/') - 1) + @real_root = "../" * (__dir__.count('/') - 1) @ref_dir = File.join("/", File.basename(Dir["/*"].first)) end @@ -18,7 +18,7 @@ compilations_ci = ENV["GITHUB_WORKFLOW"] == "Compilations" it "can be used to change the process' root directory" do - -> { Dir.send(@method, File.dirname(__FILE__)) }.should_not raise_error + -> { Dir.send(@method, __dir__) }.should_not raise_error File.should.exist?("/#{File.basename(__FILE__)}") end unless compilations_ci diff --git a/spec/ruby/core/dir/shared/exist.rb b/spec/ruby/core/dir/shared/exist.rb index 765d1b656c59fa..2ea4f88a80f1c2 100644 --- a/spec/ruby/core/dir/shared/exist.rb +++ b/spec/ruby/core/dir/shared/exist.rb @@ -1,6 +1,6 @@ describe :dir_exist, shared: true do it "returns true if the given directory exists" do - Dir.send(@method, File.dirname(__FILE__)).should be_true + Dir.send(@method, __dir__).should be_true end it "returns true for '.'" do @@ -20,7 +20,7 @@ end it "understands relative paths" do - Dir.send(@method, File.dirname(__FILE__) + '/../').should be_true + Dir.send(@method, __dir__ + '/../').should be_true end it "returns false if the given directory doesn't exist" do @@ -28,7 +28,7 @@ end it "doesn't require the name to have a trailing slash" do - dir = File.dirname(__FILE__) + dir = __dir__ dir.sub!(/\/$/,'') Dir.send(@method, dir).should be_true end @@ -50,7 +50,7 @@ it "calls #to_path on non String arguments" do p = mock('path') - p.should_receive(:to_path).and_return(File.dirname(__FILE__)) + p.should_receive(:to_path).and_return(__dir__) Dir.send(@method, p) end end diff --git a/spec/ruby/core/enumerator/chain/initialize_spec.rb b/spec/ruby/core/enumerator/chain/initialize_spec.rb index 69484dfcb462b8..daa30351d7847c 100644 --- a/spec/ruby/core/enumerator/chain/initialize_spec.rb +++ b/spec/ruby/core/enumerator/chain/initialize_spec.rb @@ -22,10 +22,10 @@ end describe "on frozen instance" do - it "raises a RuntimeError" do + it "raises a FrozenError" do -> { @uninitialized.freeze.send(:initialize) - }.should raise_error(RuntimeError) + }.should raise_error(FrozenError) end end end diff --git a/spec/ruby/core/enumerator/each_spec.rb b/spec/ruby/core/enumerator/each_spec.rb index 99ac3120afbbe1..3af16e5587e466 100644 --- a/spec/ruby/core/enumerator/each_spec.rb +++ b/spec/ruby/core/enumerator/each_spec.rb @@ -10,41 +10,41 @@ def object_each_with_arguments.each_with_arguments(arg, *args) @enum_with_arguments = object_each_with_arguments.to_enum(:each_with_arguments, :arg0, :arg1, :arg2) - @enum_with_yielder = Enumerator.new {|y| y.yield :ok} + @enum_with_yielder = Enumerator.new { |y| y.yield :ok } end it "yields each element of self to the given block" do acc = [] - [1,2,3].to_enum.each {|e| acc << e } - acc.should == [1,2,3] + [1, 2, 3].to_enum.each { |e| acc << e } + acc.should == [1, 2, 3] end it "calls #each on the object given in the constructor by default" do each = mock('each') each.should_receive(:each) - each.to_enum.each {|e| e } + each.to_enum.each { |e| e } end it "calls #each on the underlying object until it's exhausted" do each = mock('each') each.should_receive(:each).and_yield(1).and_yield(2).and_yield(3) acc = [] - each.to_enum.each {|e| acc << e } - acc.should == [1,2,3] + each.to_enum.each { |e| acc << e } + acc.should == [1, 2, 3] end it "calls the method given in the constructor instead of #each" do each = mock('peach') each.should_receive(:peach) - each.to_enum(:peach).each {|e| e } + each.to_enum(:peach).each { |e| e } end it "calls the method given in the constructor until it's exhausted" do each = mock('peach') each.should_receive(:peach).and_yield(1).and_yield(2).and_yield(3) acc = [] - each.to_enum(:peach).each {|e| acc << e } - acc.should == [1,2,3] + each.to_enum(:peach).each { |e| acc << e } + acc.should == [1, 2, 3] end it "raises a NoMethodError if the object doesn't respond to #each" do diff --git a/spec/ruby/core/enumerator/generator/initialize_spec.rb b/spec/ruby/core/enumerator/generator/initialize_spec.rb index f75c7d6f269220..acc1174253344c 100644 --- a/spec/ruby/core/enumerator/generator/initialize_spec.rb +++ b/spec/ruby/core/enumerator/generator/initialize_spec.rb @@ -17,10 +17,10 @@ end describe "on frozen instance" do - it "raises a RuntimeError" do + it "raises a FrozenError" do -> { @uninitialized.freeze.send(:initialize) {} - }.should raise_error(RuntimeError) + }.should raise_error(FrozenError) end end end diff --git a/spec/ruby/core/enumerator/initialize_spec.rb b/spec/ruby/core/enumerator/initialize_spec.rb index 5e937aff2be300..5e0256ca4688f9 100644 --- a/spec/ruby/core/enumerator/initialize_spec.rb +++ b/spec/ruby/core/enumerator/initialize_spec.rb @@ -48,10 +48,10 @@ end describe "on frozen instance" do - it "raises a RuntimeError" do + it "raises a FrozenError" do -> { @uninitialized.freeze.send(:initialize) {} - }.should raise_error(RuntimeError) + }.should raise_error(FrozenError) end end end diff --git a/spec/ruby/core/enumerator/lazy/initialize_spec.rb b/spec/ruby/core/enumerator/lazy/initialize_spec.rb index f23018d010d038..e1e0b1d608363d 100644 --- a/spec/ruby/core/enumerator/lazy/initialize_spec.rb +++ b/spec/ruby/core/enumerator/lazy/initialize_spec.rb @@ -56,8 +56,8 @@ def receiver.each end describe "on frozen instance" do - it "raises a RuntimeError" do - -> { @uninitialized.freeze.send(:initialize, @receiver) {} }.should raise_error(RuntimeError) + it "raises a FrozenError" do + -> { @uninitialized.freeze.send(:initialize, @receiver) {} }.should raise_error(FrozenError) end end end diff --git a/spec/ruby/core/enumerator/product/each_spec.rb b/spec/ruby/core/enumerator/product/each_spec.rb new file mode 100644 index 00000000000000..868a1ea6bf498e --- /dev/null +++ b/spec/ruby/core/enumerator/product/each_spec.rb @@ -0,0 +1,73 @@ +require_relative '../../../spec_helper' +require_relative '../../enumerable/shared/enumeratorized' + +ruby_version_is "3.2" do + describe "Enumerator::Product#each" do + it_behaves_like :enumeratorized_with_origin_size, :each, Enumerator::Product.new([1, 2], [:a, :b]) + + it "yields each element of Cartesian product of enumerators" do + enum = Enumerator::Product.new([1, 2], [:a, :b]) + acc = [] + enum.each { |e| acc << e } + acc.should == [[1, :a], [1, :b], [2, :a], [2, :b]] + end + + it "calls #each_entry method on enumerators" do + object1 = Object.new + def object1.each_entry + yield 1 + yield 2 + end + + object2 = Object.new + def object2.each_entry + yield :a + yield :b + end + + enum = Enumerator::Product.new(object1, object2) + acc = [] + enum.each { |e| acc << e } + acc.should == [[1, :a], [1, :b], [2, :a], [2, :b]] + end + + it "raises a NoMethodError if the object doesn't respond to #each_entry" do + -> { + Enumerator::Product.new(Object.new).each {} + }.should raise_error(NoMethodError, /undefined method `each_entry' for/) + end + + it "returns enumerator if not given a block" do + enum = Enumerator::Product.new([1, 2], [:a, :b]) + enum.each.should.kind_of?(Enumerator) + + enum = Enumerator::Product.new([1, 2], [:a, :b]) + enum.each.to_a.should == [[1, :a], [1, :b], [2, :a], [2, :b]] + end + + it "returns self if given a block" do + enum = Enumerator::Product.new([1, 2], [:a, :b]) + enum.each {}.should.equal?(enum) + end + + it "doesn't accept arguments" do + Enumerator::Product.instance_method(:each).arity.should == 0 + end + + it "yields each element to a block that takes multiple arguments" do + enum = Enumerator::Product.new([1, 2], [:a, :b]) + + acc = [] + enum.each { |x, y| acc << x } + acc.should == [1, 1, 2, 2] + + acc = [] + enum.each { |x, y| acc << y } + acc.should == [:a, :b, :a, :b] + + acc = [] + enum.each { |x, y, z| acc << z } + acc.should == [nil, nil, nil, nil] + end + end +end diff --git a/spec/ruby/core/enumerator/product/initialize_copy_spec.rb b/spec/ruby/core/enumerator/product/initialize_copy_spec.rb new file mode 100644 index 00000000000000..46e8421322a563 --- /dev/null +++ b/spec/ruby/core/enumerator/product/initialize_copy_spec.rb @@ -0,0 +1,54 @@ +require_relative '../../../spec_helper' + +ruby_version_is "3.2" do + describe "Enumerator::Product#initialize_copy" do + it "replaces content of the receiver with content of the other object" do + enum = Enumerator::Product.new([true, false]) + enum2 = Enumerator::Product.new([1, 2], [:a, :b]) + + enum.send(:initialize_copy, enum2) + enum.each.to_a.should == [[1, :a], [1, :b], [2, :a], [2, :b]] + end + + it "returns self" do + enum = Enumerator::Product.new([true, false]) + enum2 = Enumerator::Product.new([1, 2], [:a, :b]) + + enum.send(:initialize_copy, enum2).should.equal?(enum) + end + + it "is a private method" do + Enumerator::Product.should have_private_instance_method(:initialize_copy, false) + end + + it "does nothing if the argument is the same as the receiver" do + enum = Enumerator::Product.new(1..2) + enum.send(:initialize_copy, enum).should.equal?(enum) + + enum.freeze + enum.send(:initialize_copy, enum).should.equal?(enum) + end + + it "raises FrozenError if the receiver is frozen" do + enum = Enumerator::Product.new(1..2) + enum2 = Enumerator::Product.new(3..4) + + -> { enum.freeze.send(:initialize_copy, enum2) }.should raise_error(FrozenError) + end + + it "raises TypeError if the objects are of different class" do + enum = Enumerator::Product.new(1..2) + enum2 = Class.new(Enumerator::Product).new(3..4) + + -> { enum.send(:initialize_copy, enum2) }.should raise_error(TypeError, 'initialize_copy should take same class object') + -> { enum2.send(:initialize_copy, enum) }.should raise_error(TypeError, 'initialize_copy should take same class object') + end + + it "raises ArgumentError if the argument is not initialized yet" do + enum = Enumerator::Product.new(1..2) + enum2 = Enumerator::Product.allocate + + -> { enum.send(:initialize_copy, enum2) }.should raise_error(ArgumentError, 'uninitialized product') + end + end +end diff --git a/spec/ruby/core/enumerator/product/initialize_spec.rb b/spec/ruby/core/enumerator/product/initialize_spec.rb new file mode 100644 index 00000000000000..4b60564240436b --- /dev/null +++ b/spec/ruby/core/enumerator/product/initialize_spec.rb @@ -0,0 +1,33 @@ +require_relative '../../../spec_helper' + +ruby_version_is "3.2" do + describe "Enumerator::Product#initialize" do + before :each do + @uninitialized = Enumerator::Product.allocate + end + + it "is a private method" do + Enumerator::Product.should have_private_instance_method(:initialize, false) + end + + it "returns self" do + @uninitialized.send(:initialize).should equal(@uninitialized) + end + + it "accepts many arguments" do + @uninitialized.send(:initialize, 0..1, 2..3, 4..5).should equal(@uninitialized) + end + + it "accepts arguments that are not Enumerable nor responding to :each_entry" do + @uninitialized.send(:initialize, Object.new).should equal(@uninitialized) + end + + describe "on frozen instance" do + it "raises a FrozenError" do + -> { + @uninitialized.freeze.send(:initialize, 0..1) + }.should raise_error(FrozenError) + end + end + end +end diff --git a/spec/ruby/core/enumerator/product/inspect_spec.rb b/spec/ruby/core/enumerator/product/inspect_spec.rb new file mode 100644 index 00000000000000..1ea8e9c49b6f43 --- /dev/null +++ b/spec/ruby/core/enumerator/product/inspect_spec.rb @@ -0,0 +1,22 @@ +require_relative '../../../spec_helper' + +ruby_version_is "3.2" do + describe "Enumerator::Product#inspect" do + it "returns a String including enumerators" do + enum = Enumerator::Product.new([1, 2], [:a, :b]) + enum.inspect.should == "#" + end + + it "represents a recursive element with '[...]'" do + enum = [1, 2] + enum_recursive = Enumerator::Product.new(enum) + + enum << enum_recursive + enum_recursive.inspect.should == "#]]>" + end + + it "returns a not initialized representation if #initialized is not called yet" do + Enumerator::Product.allocate.inspect.should == "#" + end + end +end diff --git a/spec/ruby/core/enumerator/product/rewind_spec.rb b/spec/ruby/core/enumerator/product/rewind_spec.rb new file mode 100644 index 00000000000000..e8ee7302397cb0 --- /dev/null +++ b/spec/ruby/core/enumerator/product/rewind_spec.rb @@ -0,0 +1,64 @@ +require_relative '../../../spec_helper' + +ruby_version_is "3.2" do + describe "Enumerator::Product#rewind" do + before :each do + @enum = Enumerator::Product.new([1, 2].each.to_enum, [:a, :b].each.to_enum) + end + + it "resets the enumerator to its initial state" do + @enum.each.to_a.should == [[1, :a], [1, :b], [2, :a], [2, :b]] + @enum.rewind + @enum.each.to_a.should == [[1, :a], [1, :b], [2, :a], [2, :b]] + end + + it "returns self" do + @enum.rewind.should.equal? @enum + end + + it "has no effect on a new enumerator" do + @enum.rewind + @enum.each.to_a.should == [[1, :a], [1, :b], [2, :a], [2, :b]] + end + + it "has no effect if called multiple, consecutive times" do + @enum.each.to_a.should == [[1, :a], [1, :b], [2, :a], [2, :b]] + @enum.rewind + @enum.rewind + @enum.each.to_a.should == [[1, :a], [1, :b], [2, :a], [2, :b]] + end + + it "calls the enclosed object's rewind method if one exists" do + obj = mock('rewinder') + enum = Enumerator::Product.new(obj.to_enum) + + obj.should_receive(:rewind) + enum.rewind + end + + it "does nothing if the object doesn't have a #rewind method" do + obj = mock('rewinder') + enum = Enumerator::Product.new(obj.to_enum) + + enum.rewind.should == enum + end + + it "calls a rewind method on each enumerable in direct order" do + ScratchPad.record [] + + object1 = Object.new + def object1.rewind; ScratchPad << :object1; end + + object2 = Object.new + def object2.rewind; ScratchPad << :object2; end + + object3 = Object.new + def object3.rewind; ScratchPad << :object3; end + + enum = Enumerator::Product.new(object1, object2, object3) + enum.rewind + + ScratchPad.recorded.should == [:object1, :object2, :object3] + end + end +end diff --git a/spec/ruby/core/enumerator/product/size_spec.rb b/spec/ruby/core/enumerator/product/size_spec.rb new file mode 100644 index 00000000000000..fb0efdf748243f --- /dev/null +++ b/spec/ruby/core/enumerator/product/size_spec.rb @@ -0,0 +1,64 @@ +require_relative '../../../spec_helper' + +ruby_version_is "3.2" do + describe "Enumerator::Product#size" do + it "returns the total size of the enumerator product calculated by multiplying the sizes of enumerables in the product" do + product = Enumerator::Product.new(1..2, 1..3, 1..4) + product.size.should == 24 # 2 * 3 * 4 + end + + it "returns nil if any enumerable reports its size as nil" do + enum = Object.new + def enum.size; nil; end + + product = Enumerator::Product.new(1..2, enum) + product.size.should == nil + end + + it "returns Float::INFINITY if any enumerable reports its size as Float::INFINITY" do + enum = Object.new + def enum.size; Float::INFINITY; end + + product = Enumerator::Product.new(1..2, enum) + product.size.should == Float::INFINITY + end + + it "returns -Float::INFINITY if any enumerable reports its size as -Float::INFINITY" do + enum = Object.new + def enum.size; -Float::INFINITY; end + + product = Enumerator::Product.new(1..2, enum) + product.size.should == -Float::INFINITY + end + + it "returns nil if any enumerable reports its size as Float::NAN" do + enum = Object.new + def enum.size; Float::NAN; end + + product = Enumerator::Product.new(1..2, enum) + product.size.should == nil + end + + it "returns nil if any enumerable doesn't respond to #size" do + enum = Object.new + product = Enumerator::Product.new(1..2, enum) + product.size.should == nil + end + + it "returns nil if any enumerable reports a not-convertible to Integer" do + enum = Object.new + def enum.size; :symbol; end + + product = Enumerator::Product.new(1..2, enum) + product.size.should == nil + end + + it "returns nil if any enumerable reports a non-Integer but convertible to Integer size" do + enum = Object.new + def enum.size; 1.0; end + + product = Enumerator::Product.new(1..2, enum) + product.size.should == nil + end + end +end diff --git a/spec/ruby/core/enumerator/product_spec.rb b/spec/ruby/core/enumerator/product_spec.rb index 44fc6441e12774..0fb00fc7ee84fc 100644 --- a/spec/ruby/core/enumerator/product_spec.rb +++ b/spec/ruby/core/enumerator/product_spec.rb @@ -44,6 +44,11 @@ elems.should == [[1, "X"], [1, "Y"], [2, "X"], [2, "Y"]] end + it "returns nil when a block passed" do + Enumerator.product(1..2) {}.should == nil + end + + # https://bugs.ruby-lang.org/issues/19829 it "reject keyword arguments" do -> { Enumerator.product(1..3, foo: 1, bar: 2) diff --git a/spec/ruby/core/enumerator/rewind_spec.rb b/spec/ruby/core/enumerator/rewind_spec.rb index a105f2c6193b09..6ba0edf1745e83 100644 --- a/spec/ruby/core/enumerator/rewind_spec.rb +++ b/spec/ruby/core/enumerator/rewind_spec.rb @@ -14,7 +14,7 @@ end it "returns self" do - @enum.rewind.should == @enum + @enum.rewind.should.equal? @enum end it "has no effect on a new enumerator" do @@ -49,7 +49,7 @@ obj = mock('rewinder') enum = obj.to_enum obj.should_receive(:each).at_most(1) - -> { enum.rewind.should == enum }.should_not raise_error + enum.rewind.should == enum end end diff --git a/spec/ruby/core/env/delete_spec.rb b/spec/ruby/core/env/delete_spec.rb index 3d69e4b0223649..f28ac97911126f 100644 --- a/spec/ruby/core/env/delete_spec.rb +++ b/spec/ruby/core/env/delete_spec.rb @@ -41,6 +41,14 @@ ENV["foo"].should == nil end + it "removes the variable coerced with #to_str" do + ENV["foo"] = "bar" + k = mock('key') + k.should_receive(:to_str).and_return("foo") + ENV.delete(k) + ENV["foo"].should == nil + end + it "raises TypeError if the argument is not a String and does not respond to #to_str" do -> { ENV.delete(Object.new) }.should raise_error(TypeError, "no implicit conversion of Object into String") end diff --git a/spec/ruby/core/env/key_spec.rb b/spec/ruby/core/env/key_spec.rb index 82cfbefa392421..cf7028640908c4 100644 --- a/spec/ruby/core/env/key_spec.rb +++ b/spec/ruby/core/env/key_spec.rb @@ -1,11 +1,39 @@ require_relative '../../spec_helper' require_relative 'shared/include' -require_relative 'shared/key' describe "ENV.key?" do it_behaves_like :env_include, :key? end describe "ENV.key" do - it_behaves_like :env_key, :key + before :each do + @saved_foo = ENV["foo"] + end + + after :each do + ENV["foo"] = @saved_foo + end + + it "returns the index associated with the passed value" do + ENV["foo"] = "bar" + ENV.key("bar").should == "foo" + end + + it "returns nil if the passed value is not found" do + ENV.delete("foo") + ENV.key("foo").should be_nil + end + + it "coerces the key element with #to_str" do + ENV["foo"] = "bar" + k = mock('key') + k.should_receive(:to_str).and_return("bar") + ENV.key(k).should == "foo" + end + + it "raises TypeError if the argument is not a String and does not respond to #to_str" do + -> { + ENV.key(Object.new) + }.should raise_error(TypeError, "no implicit conversion of Object into String") + end end diff --git a/spec/ruby/core/env/shared/include.rb b/spec/ruby/core/env/shared/include.rb index 3efcd523d645d2..70aa5553017ea6 100644 --- a/spec/ruby/core/env/shared/include.rb +++ b/spec/ruby/core/env/shared/include.rb @@ -17,6 +17,13 @@ ENV.send(@method, "foo").should == false end + it "coerces the key with #to_str" do + ENV["foo"] = "bar" + k = mock('key') + k.should_receive(:to_str).and_return("foo") + ENV.send(@method, k).should == true + end + it "raises TypeError if the argument is not a String and does not respond to #to_str" do -> { ENV.send(@method, Object.new) }.should raise_error(TypeError, "no implicit conversion of Object into String") end diff --git a/spec/ruby/core/env/shared/key.rb b/spec/ruby/core/env/shared/key.rb deleted file mode 100644 index 93396d2aca3645..00000000000000 --- a/spec/ruby/core/env/shared/key.rb +++ /dev/null @@ -1,31 +0,0 @@ -describe :env_key, shared: true do - before :each do - @saved_foo = ENV["foo"] - end - - after :each do - ENV["foo"] = @saved_foo - end - - it "returns the index associated with the passed value" do - ENV["foo"] = "bar" - suppress_warning { - ENV.send(@method, "bar").should == "foo" - } - end - - it "returns nil if the passed value is not found" do - ENV.delete("foo") - suppress_warning { - ENV.send(@method, "foo").should be_nil - } - end - - it "raises TypeError if the argument is not a String and does not respond to #to_str" do - -> { - suppress_warning { - ENV.send(@method, Object.new) - } - }.should raise_error(TypeError, "no implicit conversion of Object into String") - end -end diff --git a/spec/ruby/core/env/shared/value.rb b/spec/ruby/core/env/shared/value.rb index bef96b5fef00e5..c2b5025465e258 100644 --- a/spec/ruby/core/env/shared/value.rb +++ b/spec/ruby/core/env/shared/value.rb @@ -16,6 +16,13 @@ ENV.send(@method, "foo").should == false end + it "coerces the value element with #to_str" do + ENV["foo"] = "bar" + v = mock('value') + v.should_receive(:to_str).and_return("bar") + ENV.send(@method, v).should == true + end + it "returns nil if the argument is not a String and does not respond to #to_str" do ENV.send(@method, Object.new).should == nil end diff --git a/spec/ruby/core/env/slice_spec.rb b/spec/ruby/core/env/slice_spec.rb index e3b60203915987..959239d2b2fb8c 100644 --- a/spec/ruby/core/env/slice_spec.rb +++ b/spec/ruby/core/env/slice_spec.rb @@ -21,6 +21,16 @@ ENV.slice("foo", "boo", "bar").should == {"foo" => "0", "bar" => "1"} end + it "returns the values for the keys coerced with #to_str, but keeps the original objects as result keys" do + foo = mock('key 1') + foo.should_receive(:to_str).and_return("foo") + boo = mock('key 2') + boo.should_receive(:to_str).and_return("boo") + bar = mock('key 3') + bar.should_receive(:to_str).and_return("bar") + ENV.slice(foo, boo, bar).should == {foo => "0", bar => "1"} + end + it "raises TypeError if any argument is not a String and does not respond to #to_str" do -> { ENV.slice(Object.new) }.should raise_error(TypeError, "no implicit conversion of Object into String") end diff --git a/spec/ruby/core/exception/equal_value_spec.rb b/spec/ruby/core/exception/equal_value_spec.rb index 7f2065511adff0..e8f3ce0f8d7c9d 100644 --- a/spec/ruby/core/exception/equal_value_spec.rb +++ b/spec/ruby/core/exception/equal_value_spec.rb @@ -22,18 +22,18 @@ it "returns true if both exceptions have the same class, the same message, and the same backtrace" do one = TypeError.new("message") - one.set_backtrace [File.dirname(__FILE__)] + one.set_backtrace [__dir__] two = TypeError.new("message") - two.set_backtrace [File.dirname(__FILE__)] + two.set_backtrace [__dir__] one.should == two end it "returns false if the two exceptions inherit from Exception but have different classes" do one = RuntimeError.new("message") - one.set_backtrace [File.dirname(__FILE__)] + one.set_backtrace [__dir__] one.should be_kind_of(Exception) two = TypeError.new("message") - two.set_backtrace [File.dirname(__FILE__)] + two.set_backtrace [__dir__] two.should be_kind_of(Exception) one.should_not == two end @@ -52,7 +52,7 @@ it "returns false if the two exceptions differ only in their backtrace" do one = RuntimeError.new("message") - one.set_backtrace [File.dirname(__FILE__)] + one.set_backtrace [__dir__] two = RuntimeError.new("message") two.set_backtrace nil one.should_not == two @@ -60,9 +60,9 @@ it "returns false if the two exceptions differ only in their message" do one = RuntimeError.new("message") - one.set_backtrace [File.dirname(__FILE__)] + one.set_backtrace [__dir__] two = RuntimeError.new("message2") - two.set_backtrace [File.dirname(__FILE__)] + two.set_backtrace [__dir__] one.should_not == two end end diff --git a/spec/ruby/core/false/singleton_method_spec.rb b/spec/ruby/core/false/singleton_method_spec.rb index 6cf29af411bdef..738794b46c26f8 100644 --- a/spec/ruby/core/false/singleton_method_spec.rb +++ b/spec/ruby/core/false/singleton_method_spec.rb @@ -3,10 +3,10 @@ describe "FalseClass#singleton_method" do ruby_version_is '3.3' do it "raises regardless of whether FalseClass defines the method" do - proc{false.singleton_method(:foo)}.should raise_error(NameError) + -> { false.singleton_method(:foo) }.should raise_error(NameError) begin - def false.foo; end - proc{false.singleton_method(:foo)}.should raise_error(NameError) + def (false).foo; end + -> { false.singleton_method(:foo) }.should raise_error(NameError) ensure FalseClass.send(:remove_method, :foo) end diff --git a/spec/ruby/core/fiber/storage_spec.rb b/spec/ruby/core/fiber/storage_spec.rb index e5232c8894a9c6..5c87ed5d41d560 100644 --- a/spec/ruby/core/fiber/storage_spec.rb +++ b/spec/ruby/core/fiber/storage_spec.rb @@ -1,9 +1,7 @@ require_relative '../../spec_helper' -require 'fiber' - -describe "Fiber.new(storage:)" do - ruby_version_is "3.2" do +ruby_version_is "3.2" do + describe "Fiber.new(storage:)" do it "creates a Fiber with the given storage" do storage = {life: 42} fiber = Fiber.new(storage: storage) { Fiber.current.storage } @@ -24,11 +22,26 @@ it "cannot create a fiber with non-hash storage" do -> { Fiber.new(storage: 42) {} }.should raise_error(TypeError) end + + it "cannot create a fiber with a frozen hash as storage" do + -> { Fiber.new(storage: {life: 43}.freeze) {} }.should raise_error(FrozenError) + end + + it "cannot create a fiber with a storage hash with non-symbol keys" do + -> { Fiber.new(storage: {life: 43, Object.new => 44}) {} }.should raise_error(TypeError) + end end -end -describe "Fiber#storage=" do - ruby_version_is "3.2" do + describe "Fiber#storage" do + it "cannot be accessed from a different fiber" do + f = Fiber.new(storage: {life: 42}) { nil } + -> { + f.storage + }.should raise_error(ArgumentError, /Fiber storage can only be accessed from the Fiber it belongs to/) + end + end + + describe "Fiber#storage=" do it "can clear the storage of the fiber" do fiber = Fiber.new(storage: {life: 42}) do Fiber.current.storage = nil @@ -58,10 +71,8 @@ -> { Fiber.current.storage = {life: 43, Object.new => 44} }.should raise_error(TypeError) end end -end -describe "Fiber.[]" do - ruby_version_is "3.2" do + describe "Fiber.[]" do it "returns the value of the given key in the storage of the current fiber" do Fiber.new(storage: {life: 42}) { Fiber[:life] }.resume.should == 42 end @@ -73,25 +84,34 @@ it "returns nil if the current fiber has no storage" do Fiber.new { Fiber[:life] }.resume.should be_nil end - end - ruby_version_is "3.2.3" do - it "can use dynamically defined keys" do - key = :"#{self.class.name}#.#{self.object_id}" - Fiber.new { Fiber[key] = 42; Fiber[key] }.resume.should == 42 + ruby_version_is "3.2.3" do + it "can use dynamically defined keys" do + key = :"#{self.class.name}#.#{self.object_id}" + Fiber.new { Fiber[key] = 42; Fiber[key] }.resume.should == 42 + end + + it "can't use invalid keys" do + invalid_keys = [Object.new, "Foo", 12] + invalid_keys.each do |key| + -> { Fiber[key] }.should raise_error(TypeError) + end + end end - it "can't use invalid keys" do - invalid_keys = [Object.new, "Foo", 12] - invalid_keys.each do |key| - -> { Fiber[key] }.should raise_error(TypeError) + it "can access the storage of the parent fiber" do + f = Fiber.new(storage: {life: 42}) do + Fiber.new { Fiber[:life] }.resume end + f.resume.should == 42 + end + + it "can't access the storage of the fiber with non-symbol keys" do + -> { Fiber[Object.new] }.should raise_error(TypeError) end end -end -describe "Fiber.[]=" do - ruby_version_is "3.2" do + describe "Fiber.[]=" do it "sets the value of the given key in the storage of the current fiber" do Fiber.new(storage: {life: 42}) { Fiber[:life] = 43; Fiber[:life] }.resume.should == 43 end @@ -103,17 +123,31 @@ it "sets the value of the given key in the storage of the current fiber" do Fiber.new { Fiber[:life] = 43; Fiber[:life] }.resume.should == 43 end - end - ruby_version_is "3.3" do - it "deletes the fiber storage key when assigning nil" do - Fiber.new(storage: {life: 42}) { Fiber[:life] = nil; Fiber.current.storage }.resume.should == {} + it "does not overwrite the storage of the parent fiber" do + f = Fiber.new(storage: {life: 42}) do + Fiber.yield Fiber.new { Fiber[:life] = 43; Fiber[:life] }.resume + Fiber[:life] + end + f.resume.should == 43 # Value of the inner fiber + f.resume.should == 42 # Value of the outer fiber + end + + it "can't access the storage of the fiber with non-symbol keys" do + -> { Fiber[Object.new] = 44 }.should raise_error(TypeError) + end + + ruby_version_is "3.3" do + it "deletes the fiber storage key when assigning nil" do + Fiber.new(storage: {life: 42}) { + Fiber[:life] = nil + Fiber.current.storage + }.resume.should == {} + end end end -end -describe "Thread.new" do - ruby_version_is "3.2" do + describe "Thread.new" do it "creates a thread with the storage of the current fiber" do fiber = Fiber.new(storage: {life: 42}) do Thread.new { Fiber.current.storage }.value diff --git a/spec/ruby/core/file/absolute_path_spec.rb b/spec/ruby/core/file/absolute_path_spec.rb index e35c80ec3c5cea..315eead34fe934 100644 --- a/spec/ruby/core/file/absolute_path_spec.rb +++ b/spec/ruby/core/file/absolute_path_spec.rb @@ -85,7 +85,7 @@ end it "accepts a second argument of a directory from which to resolve the path" do - File.absolute_path(__FILE__, File.dirname(__FILE__)).should == @abs + File.absolute_path(__FILE__, __dir__).should == @abs end it "calls #to_path on its argument" do diff --git a/spec/ruby/core/file/exist_spec.rb b/spec/ruby/core/file/exist_spec.rb index ddb5febcba0b7f..2633376880b91d 100644 --- a/spec/ruby/core/file/exist_spec.rb +++ b/spec/ruby/core/file/exist_spec.rb @@ -4,3 +4,11 @@ describe "File.exist?" do it_behaves_like :file_exist, :exist?, File end + +ruby_version_is "3.2" do + describe "File.exists?" do + it "has been removed" do + File.should_not.respond_to?(:exists?) + end + end +end diff --git a/spec/ruby/core/file/open_spec.rb b/spec/ruby/core/file/open_spec.rb index 0346224b93fc29..4c41f70e12b3f0 100644 --- a/spec/ruby/core/file/open_spec.rb +++ b/spec/ruby/core/file/open_spec.rb @@ -314,7 +314,7 @@ end end - it "raises an IOError when read in a block opened with File::RDONLY|File::APPEND mode" do + it "raises an IOError when write in a block opened with File::RDONLY|File::APPEND mode" do -> { File.open(@file, File::RDONLY|File::APPEND ) do |f| f.puts("writing") diff --git a/spec/ruby/core/file/realpath_spec.rb b/spec/ruby/core/file/realpath_spec.rb index bd27e09da68c24..bd25bfdecf9ea1 100644 --- a/spec/ruby/core/file/realpath_spec.rb +++ b/spec/ruby/core/file/realpath_spec.rb @@ -54,6 +54,10 @@ File.realpath(@relative_symlink).should == @file end + it "removes the file element when going one level up" do + File.realpath('../', @file).should == @real_dir + end + it "raises an Errno::ELOOP if the symlink points to itself" do File.unlink @link File.symlink(@link, @link) diff --git a/spec/ruby/core/io/eof_spec.rb b/spec/ruby/core/io/eof_spec.rb index 315345d942ab27..b4850df437e351 100644 --- a/spec/ruby/core/io/eof_spec.rb +++ b/spec/ruby/core/io/eof_spec.rb @@ -76,7 +76,7 @@ end it "returns true on one-byte stream after single-byte read" do - File.open(File.dirname(__FILE__) + '/fixtures/one_byte.txt') { |one_byte| + File.open(__dir__ + '/fixtures/one_byte.txt') { |one_byte| one_byte.read(1) one_byte.should.eof? } diff --git a/spec/ruby/core/io/getbyte_spec.rb b/spec/ruby/core/io/getbyte_spec.rb index 6ba8f0a3e0434d..b4351160e6b2f8 100644 --- a/spec/ruby/core/io/getbyte_spec.rb +++ b/spec/ruby/core/io/getbyte_spec.rb @@ -40,3 +40,19 @@ @io.getbyte.should == nil end end + +describe "IO#getbyte" do + before :each do + @name = tmp("io_getbyte.txt") + @io = new_io(@name, 'w') + end + + after :each do + @io.close if @io + rm_r @name if @name + end + + it "raises an IOError if the stream is not readable" do + -> { @io.getbyte }.should raise_error(IOError) + end +end diff --git a/spec/ruby/core/io/new_spec.rb b/spec/ruby/core/io/new_spec.rb index 0ef30991fd1548..9d14ec18ad4099 100644 --- a/spec/ruby/core/io/new_spec.rb +++ b/spec/ruby/core/io/new_spec.rb @@ -1,7 +1,7 @@ require_relative '../../spec_helper' require_relative 'shared/new' -# NOTE: should be syncronized with library/stringio/initialize_spec.rb +# NOTE: should be synchronized with library/stringio/initialize_spec.rb describe "IO.new" do it_behaves_like :io_new, :new diff --git a/spec/ruby/core/io/select_spec.rb b/spec/ruby/core/io/select_spec.rb index 4603c1fbbca0b8..1e4e50a81b7a3c 100644 --- a/spec/ruby/core/io/select_spec.rb +++ b/spec/ruby/core/io/select_spec.rb @@ -55,8 +55,8 @@ end end - it "returns supplied objects correctly even when monitoring the same object in different arrays" do - filename = tmp("IO_select_pipe_file") + $$.to_s + it "returns supplied objects correctly when monitoring the same object in different arrays" do + filename = tmp("IO_select_pipe_file") io = File.open(filename, 'w+') result = IO.select [io], [io], nil, 0 result.should == [[io], [io], []] @@ -64,6 +64,17 @@ rm_r filename end + it "returns the pipe read end in read set if the pipe write end is closed concurrently" do + main = Thread.current + t = Thread.new { + Thread.pass until main.stop? + @wr.close + } + IO.select([@rd]).should == [[@rd], [], []] + ensure + t.join + end + it "invokes to_io on supplied objects that are not IO and returns the supplied objects" do # make some data available @wr.write("foobar") diff --git a/spec/ruby/core/io/shared/new.rb b/spec/ruby/core/io/shared/new.rb index 99b19e6a1b12d7..cba5f33ebfc1f2 100644 --- a/spec/ruby/core/io/shared/new.rb +++ b/spec/ruby/core/io/shared/new.rb @@ -1,6 +1,6 @@ require_relative '../fixtures/classes' -# NOTE: should be syncronized with library/stringio/initialize_spec.rb +# NOTE: should be synchronized with library/stringio/initialize_spec.rb # This group of specs may ONLY contain specs that do successfully create # an IO instance from the file descriptor returned by #new_fd helper. diff --git a/spec/ruby/core/kernel/initialize_copy_spec.rb b/spec/ruby/core/kernel/initialize_copy_spec.rb index fe08d184ad2024..d71ca9f60f682b 100644 --- a/spec/ruby/core/kernel/initialize_copy_spec.rb +++ b/spec/ruby/core/kernel/initialize_copy_spec.rb @@ -1,11 +1,18 @@ require_relative '../../spec_helper' describe "Kernel#initialize_copy" do + it "returns self" do + obj = Object.new + obj.send(:initialize_copy, obj).should.equal?(obj) + end + it "does nothing if the argument is the same as the receiver" do obj = Object.new obj.send(:initialize_copy, obj).should.equal?(obj) - obj.freeze + + obj = Object.new.freeze obj.send(:initialize_copy, obj).should.equal?(obj) + 1.send(:initialize_copy, 1).should.equal?(1) end diff --git a/spec/ruby/core/kernel/require_relative_spec.rb b/spec/ruby/core/kernel/require_relative_spec.rb index 5999855de64459..6188d13a4e4219 100644 --- a/spec/ruby/core/kernel/require_relative_spec.rb +++ b/spec/ruby/core/kernel/require_relative_spec.rb @@ -5,9 +5,9 @@ before :each do CodeLoadingSpecs.spec_setup @dir = "../../fixtures/code" - @abs_dir = File.realpath(@dir, File.dirname(__FILE__)) + @abs_dir = File.realpath(@dir, __dir__) @path = "#{@dir}/load_fixture.rb" - @abs_path = File.realpath(@path, File.dirname(__FILE__)) + @abs_path = File.realpath(@path, __dir__) end after :each do @@ -92,7 +92,7 @@ it "raises a LoadError that includes the missing path" do missing_path = "#{@dir}/nonexistent.rb" - expanded_missing_path = File.expand_path(missing_path, File.dirname(__FILE__)) + expanded_missing_path = File.expand_path(missing_path, __dir__) -> { require_relative(missing_path) }.should raise_error(LoadError) { |e| e.message.should include(expanded_missing_path) e.path.should == expanded_missing_path @@ -277,7 +277,7 @@ describe "Kernel#require_relative with an absolute path" do before :each do CodeLoadingSpecs.spec_setup - @dir = File.expand_path "../../fixtures/code", File.dirname(__FILE__) + @dir = File.expand_path "../../fixtures/code", __dir__ @abs_dir = @dir @path = File.join @dir, "load_fixture.rb" @abs_path = @path diff --git a/spec/ruby/core/kernel/shared/sprintf.rb b/spec/ruby/core/kernel/shared/sprintf.rb index 2db50bd686878a..13dc6e97f0f03d 100644 --- a/spec/ruby/core/kernel/shared/sprintf.rb +++ b/spec/ruby/core/kernel/shared/sprintf.rb @@ -356,13 +356,13 @@ def obj.to_str it "raises TypeError if converting to Integer with to_int returns non-Integer" do obj = BasicObject.new - def obj.to_str + def obj.to_int :foo end -> { @method.call("%c", obj) - }.should raise_error(TypeError, /can't convert BasicObject to String/) + }.should raise_error(TypeError, /can't convert BasicObject to Integer/) end end diff --git a/spec/ruby/core/kernel/test_spec.rb b/spec/ruby/core/kernel/test_spec.rb index abb365aed283d1..d26dc06361b43b 100644 --- a/spec/ruby/core/kernel/test_spec.rb +++ b/spec/ruby/core/kernel/test_spec.rb @@ -3,8 +3,8 @@ describe "Kernel#test" do before :all do - @file = File.dirname(__FILE__) + '/fixtures/classes.rb' - @dir = File.dirname(__FILE__) + '/fixtures' + @file = __dir__ + '/fixtures/classes.rb' + @dir = __dir__ + '/fixtures' end it "is a private method" do diff --git a/spec/ruby/core/marshal/dump_spec.rb b/spec/ruby/core/marshal/dump_spec.rb index c694b48babf11f..eaf238bbd93a85 100644 --- a/spec/ruby/core/marshal/dump_spec.rb +++ b/spec/ruby/core/marshal/dump_spec.rb @@ -271,6 +271,18 @@ def _dump(level) end end + describe "with a Rational" do + it "dumps a Rational" do + Marshal.dump(Rational(2, 3)).should == "\x04\bU:\rRational[\ai\ai\b" + end + end + + describe "with a Complex" do + it "dumps a Complex" do + Marshal.dump(Complex(2, 3)).should == "\x04\bU:\fComplex[\ai\ai\b" + end + end + describe "with a String" do it "dumps a blank String" do Marshal.dump("".force_encoding("binary")).should == "\004\b\"\000" @@ -769,7 +781,6 @@ def finalizer.noop(_) end describe "when passed an IO" do - it "writes the serialized data to the IO-Object" do (obj = mock('test')).should_receive(:write).at_least(1) Marshal.dump("test", obj) @@ -792,8 +803,6 @@ def finalizer.noop(_) obj.should_receive(:binmode).at_least(1) Marshal.dump("test", obj) end - - end describe "when passed a StringIO" do diff --git a/spec/ruby/core/marshal/shared/load.rb b/spec/ruby/core/marshal/shared/load.rb index b37e65071d401a..b70fb7a974c02c 100644 --- a/spec/ruby/core/marshal/shared/load.rb +++ b/spec/ruby/core/marshal/shared/load.rb @@ -1034,13 +1034,17 @@ def io.binmode; raise "binmode"; end describe "for a Rational" do it "loads" do - Marshal.send(@method, Marshal.dump(Rational(1, 3))).should == Rational(1, 3) + r = Marshal.send(@method, Marshal.dump(Rational(1, 3))) + r.should == Rational(1, 3) + r.should.frozen? end end describe "for a Complex" do it "loads" do - Marshal.send(@method, Marshal.dump(Complex(4, 3))).should == Complex(4, 3) + c = Marshal.send(@method, Marshal.dump(Complex(4, 3))) + c.should == Complex(4, 3) + c.should.frozen? end end diff --git a/spec/ruby/core/method/source_location_spec.rb b/spec/ruby/core/method/source_location_spec.rb index 4cfb21c5d09153..c5b296f6e2a7b0 100644 --- a/spec/ruby/core/method/source_location_spec.rb +++ b/spec/ruby/core/method/source_location_spec.rb @@ -13,7 +13,7 @@ it "sets the first value to the path of the file in which the method was defined" do file = @method.source_location.first file.should be_an_instance_of(String) - file.should == File.realpath('../fixtures/classes.rb', __FILE__) + file.should == File.realpath('fixtures/classes.rb', __dir__) end it "sets the last value to an Integer representing the line on which the method was defined" do diff --git a/spec/ruby/core/module/const_added_spec.rb b/spec/ruby/core/module/const_added_spec.rb index 31ac6eb10590bb..f9edda3a074d3d 100644 --- a/spec/ruby/core/module/const_added_spec.rb +++ b/spec/ruby/core/module/const_added_spec.rb @@ -121,5 +121,40 @@ class SubClass ScratchPad.recorded.should == [line + 2, line + 4, line + 7, line + 11] end + + it "is called when the constant is already assigned a value" do + ScratchPad.record [] + + mod = Module.new do + def self.const_added(name) + ScratchPad.record const_get(name) + end + end + + mod.module_eval(<<-RUBY, __FILE__, __LINE__ + 1) + TEST = 123 + RUBY + + ScratchPad.recorded.should == 123 + end + + it "records re-definition of existing constants" do + ScratchPad.record [] + + mod = Module.new do + def self.const_added(name) + ScratchPad << const_get(name) + end + end + + -> { + mod.module_eval(<<-RUBY, __FILE__, __LINE__ + 1) + TEST = 123 + TEST = 456 + RUBY + }.should complain(/warning: already initialized constant .+::TEST/) + + ScratchPad.recorded.should == [123, 456] + end end end diff --git a/spec/ruby/core/module/define_method_spec.rb b/spec/ruby/core/module/define_method_spec.rb index 381aacadb7f550..d742ece6bc6121 100644 --- a/spec/ruby/core/module/define_method_spec.rb +++ b/spec/ruby/core/module/define_method_spec.rb @@ -499,6 +499,33 @@ def foo Class.new { define_method :bar, m } }.should raise_error(TypeError, /can't bind singleton method to a different class/) end + + it "defines a new method with public visibility when a Method passed and the class/module of the context isn't equal to the receiver of #define_method" do + c = Class.new do + private def foo + "public" + end + end + + object = c.new + object.singleton_class.define_method(:bar, object.method(:foo)) + + object.bar.should == "public" + end + + it "defines the new method according to the scope visibility when a Method passed and the class/module of the context is equal to the receiver of #define_method" do + c = Class.new do + def foo; end + end + + object = c.new + object.singleton_class.class_eval do + private + define_method(:bar, c.new.method(:foo)) + end + + -> { object.bar }.should raise_error(NoMethodError) + end end describe "Module#define_method" do diff --git a/spec/ruby/core/mutex/lock_spec.rb b/spec/ruby/core/mutex/lock_spec.rb index 7a39817b11c220..e9d33f5fd940d9 100644 --- a/spec/ruby/core/mutex/lock_spec.rb +++ b/spec/ruby/core/mutex/lock_spec.rb @@ -1,10 +1,6 @@ require_relative '../../spec_helper' describe "Mutex#lock" do - before :each do - ScratchPad.clear - end - it "returns self" do m = Mutex.new m.lock.should == m diff --git a/spec/ruby/core/nil/singleton_method_spec.rb b/spec/ruby/core/nil/singleton_method_spec.rb index f9163da3f15393..8d898b1cc94d70 100644 --- a/spec/ruby/core/nil/singleton_method_spec.rb +++ b/spec/ruby/core/nil/singleton_method_spec.rb @@ -3,10 +3,10 @@ describe "NilClass#singleton_method" do ruby_version_is '3.3' do it "raises regardless of whether NilClass defines the method" do - proc{nil.singleton_method(:foo)}.should raise_error(NameError) + -> { nil.singleton_method(:foo) }.should raise_error(NameError) begin - def nil.foo; end - proc{nil.singleton_method(:foo)}.should raise_error(NameError) + def (nil).foo; end + -> { nil.singleton_method(:foo) }.should raise_error(NameError) ensure NilClass.send(:remove_method, :foo) end diff --git a/spec/ruby/core/numeric/clone_spec.rb b/spec/ruby/core/numeric/clone_spec.rb index 5834b17089e779..423cec85dddacd 100644 --- a/spec/ruby/core/numeric/clone_spec.rb +++ b/spec/ruby/core/numeric/clone_spec.rb @@ -14,7 +14,7 @@ 1.clone.frozen?.should == true end - it "accepts optonal keyword argument :freeze" do + it "accepts optional keyword argument :freeze" do value = 1 value.clone(freeze: true).should equal(value) end diff --git a/spec/ruby/core/proc/source_location_spec.rb b/spec/ruby/core/proc/source_location_spec.rb index a5895a7fcb3b53..a8b99287d5c380 100644 --- a/spec/ruby/core/proc/source_location_spec.rb +++ b/spec/ruby/core/proc/source_location_spec.rb @@ -19,19 +19,19 @@ it "sets the first value to the path of the file in which the proc was defined" do file = @proc.source_location.first file.should be_an_instance_of(String) - file.should == File.realpath('../fixtures/source_location.rb', __FILE__) + file.should == File.realpath('fixtures/source_location.rb', __dir__) file = @proc_new.source_location.first file.should be_an_instance_of(String) - file.should == File.realpath('../fixtures/source_location.rb', __FILE__) + file.should == File.realpath('fixtures/source_location.rb', __dir__) file = @lambda.source_location.first file.should be_an_instance_of(String) - file.should == File.realpath('../fixtures/source_location.rb', __FILE__) + file.should == File.realpath('fixtures/source_location.rb', __dir__) file = @method.source_location.first file.should be_an_instance_of(String) - file.should == File.realpath('../fixtures/source_location.rb', __FILE__) + file.should == File.realpath('fixtures/source_location.rb', __dir__) end it "sets the last value to an Integer representing the line on which the proc was defined" do diff --git a/spec/ruby/core/process/argv0_spec.rb b/spec/ruby/core/process/argv0_spec.rb index 7c2342f9598f2e..f5aba719e96a73 100644 --- a/spec/ruby/core/process/argv0_spec.rb +++ b/spec/ruby/core/process/argv0_spec.rb @@ -8,7 +8,7 @@ it "is the path given as the main script and the same as __FILE__" do script = "fixtures/argv0.rb" - Dir.chdir(File.dirname(__FILE__)) do + Dir.chdir(__dir__) do ruby_exe(script).should == "#{script}\n#{script}\nOK" end end diff --git a/spec/ruby/core/process/exec_spec.rb b/spec/ruby/core/process/exec_spec.rb index deb8913b6bcf55..2fa8b089750bb7 100644 --- a/spec/ruby/core/process/exec_spec.rb +++ b/spec/ruby/core/process/exec_spec.rb @@ -30,7 +30,7 @@ end it "raises Errno::EACCES when passed a directory" do - -> { Process.exec File.dirname(__FILE__) }.should raise_error(Errno::EACCES) + -> { Process.exec __dir__ }.should raise_error(Errno::EACCES) end it "runs the specified command, replacing current process" do diff --git a/spec/ruby/core/process/spawn_spec.rb b/spec/ruby/core/process/spawn_spec.rb index c8a58c4d041125..283a7f033dcf18 100644 --- a/spec/ruby/core/process/spawn_spec.rb +++ b/spec/ruby/core/process/spawn_spec.rb @@ -714,7 +714,7 @@ def child_pids(pid) end it "raises an Errno::EACCES or Errno::EISDIR when passed a directory" do - -> { Process.spawn File.dirname(__FILE__) }.should raise_error(SystemCallError) { |e| + -> { Process.spawn __dir__ }.should raise_error(SystemCallError) { |e| [Errno::EACCES, Errno::EISDIR].should include(e.class) } end diff --git a/spec/ruby/core/random/bytes_spec.rb b/spec/ruby/core/random/bytes_spec.rb index ed1b3a7b41d39d..b42dc61234d174 100644 --- a/spec/ruby/core/random/bytes_spec.rb +++ b/spec/ruby/core/random/bytes_spec.rb @@ -9,7 +9,6 @@ Random.new(33).bytes(2).should == Random.new(33).bytes(2) end - # Should double check this is official spec it "returns the same numeric output for a given seed across all implementations and platforms" do rnd = Random.new(33) rnd.bytes(2).should == "\x14\\" diff --git a/spec/ruby/core/range/cover_spec.rb b/spec/ruby/core/range/cover_spec.rb index fa881607e936c0..eb7cddc9673f2f 100644 --- a/spec/ruby/core/range/cover_spec.rb +++ b/spec/ruby/core/range/cover_spec.rb @@ -7,4 +7,8 @@ it_behaves_like :range_cover_and_include, :cover? it_behaves_like :range_cover, :cover? it_behaves_like :range_cover_subrange, :cover? + + it "covers U+9995 in the range U+0999..U+9999" do + ("\u{999}".."\u{9999}").cover?("\u{9995}").should be_true + end end diff --git a/spec/ruby/core/range/include_spec.rb b/spec/ruby/core/range/include_spec.rb index b2c7a54545c054..277de205d10521 100644 --- a/spec/ruby/core/range/include_spec.rb +++ b/spec/ruby/core/range/include_spec.rb @@ -7,4 +7,8 @@ describe "Range#include?" do it_behaves_like :range_cover_and_include, :include? it_behaves_like :range_include, :include? + + it "does not include U+9995 in the range U+0999..U+9999" do + ("\u{999}".."\u{9999}").include?("\u{9995}").should be_false + end end diff --git a/spec/ruby/core/range/shared/cover_and_include.rb b/spec/ruby/core/range/shared/cover_and_include.rb index 7028afaa89d43d..f36a2cef8b500a 100644 --- a/spec/ruby/core/range/shared/cover_and_include.rb +++ b/spec/ruby/core/range/shared/cover_and_include.rb @@ -57,7 +57,6 @@ it "returns true if argument is less than the last value of the range and greater than the first value" do (20..30).send(@method, 28).should be_true ('e'..'h').send(@method, 'g').should be_true - ("\u{999}".."\u{9999}").send @method, "\u{9995}" end it "returns true if argument is sole element in the range" do diff --git a/spec/ruby/core/refinement/extend_object_spec.rb b/spec/ruby/core/refinement/extend_object_spec.rb index e44e9f46d8ea95..6c2a0af4f3e623 100644 --- a/spec/ruby/core/refinement/extend_object_spec.rb +++ b/spec/ruby/core/refinement/extend_object_spec.rb @@ -11,8 +11,10 @@ Module.new do refine c do called = false - define_method(:extend_object){called = true} - proc{c.extend(self)}.should raise_error(TypeError) + define_method(:extend_object) { called = true } + -> { + c.extend(self) + }.should raise_error(TypeError) called.should == false end end diff --git a/spec/ruby/core/struct/constants_spec.rb b/spec/ruby/core/struct/constants_spec.rb new file mode 100644 index 00000000000000..fa61a4b9120896 --- /dev/null +++ b/spec/ruby/core/struct/constants_spec.rb @@ -0,0 +1,15 @@ +require_relative '../../spec_helper' + +ruby_version_is "3.2" do + describe "Struct::Group" do + it "is no longer defined" do + Struct.should_not.const_defined?(:Group) + end + end + + describe "Struct::Passwd" do + it "is no longer defined" do + Struct.should_not.const_defined?(:Passwd) + end + end +end diff --git a/spec/ruby/core/thread/backtrace/location/path_spec.rb b/spec/ruby/core/thread/backtrace/location/path_spec.rb index 7863c055d31daa..75f76833a961e4 100644 --- a/spec/ruby/core/thread/backtrace/location/path_spec.rb +++ b/spec/ruby/core/thread/backtrace/location/path_spec.rb @@ -41,7 +41,7 @@ context 'when using a relative script path' do it 'returns a path relative to the working directory' do path = 'fixtures/main.rb' - directory = File.dirname(__FILE__) + directory = __dir__ Dir.chdir(directory) { ruby_exe(path) }.should == path diff --git a/spec/ruby/core/true/singleton_method_spec.rb b/spec/ruby/core/true/singleton_method_spec.rb index f765054c5f38fb..c06793850fa87a 100644 --- a/spec/ruby/core/true/singleton_method_spec.rb +++ b/spec/ruby/core/true/singleton_method_spec.rb @@ -3,10 +3,10 @@ describe "TrueClass#singleton_method" do ruby_version_is '3.3' do it "raises regardless of whether TrueClass defines the method" do - proc{true.singleton_method(:foo)}.should raise_error(NameError) + -> { true.singleton_method(:foo) }.should raise_error(NameError) begin - def true.foo; end - proc{true.singleton_method(:foo)}.should raise_error(NameError) + def (true).foo; end + -> { true.singleton_method(:foo) }.should raise_error(NameError) ensure TrueClass.send(:remove_method, :foo) end diff --git a/spec/ruby/core/unboundmethod/source_location_spec.rb b/spec/ruby/core/unboundmethod/source_location_spec.rb index c6823aa84bac98..5c2f14362c40b4 100644 --- a/spec/ruby/core/unboundmethod/source_location_spec.rb +++ b/spec/ruby/core/unboundmethod/source_location_spec.rb @@ -9,7 +9,7 @@ it "sets the first value to the path of the file in which the method was defined" do file = @method.source_location.first file.should be_an_instance_of(String) - file.should == File.realpath('../fixtures/classes.rb', __FILE__) + file.should == File.realpath('fixtures/classes.rb', __dir__) end it "sets the last value to an Integer representing the line on which the method was defined" do diff --git a/spec/ruby/core/warning/element_reference_spec.rb b/spec/ruby/core/warning/element_reference_spec.rb index 41129e533abb1c..bd024d19b49cb6 100644 --- a/spec/ruby/core/warning/element_reference_spec.rb +++ b/spec/ruby/core/warning/element_reference_spec.rb @@ -3,8 +3,8 @@ describe "Warning.[]" do ruby_version_is '2.7.2' do it "returns default values for categories :deprecated and :experimental" do - ruby_exe('p Warning[:deprecated]').chomp.should == "false" - ruby_exe('p Warning[:experimental]').chomp.should == "true" + ruby_exe('p [Warning[:deprecated], Warning[:experimental]]').chomp.should == "[false, true]" + ruby_exe('p [Warning[:deprecated], Warning[:experimental]]', options: "-w").chomp.should == "[true, true]" end end diff --git a/spec/ruby/core/warning/element_set_spec.rb b/spec/ruby/core/warning/element_set_spec.rb index f439ffde0a13ae..d59a7d4c9e13c8 100644 --- a/spec/ruby/core/warning/element_set_spec.rb +++ b/spec/ruby/core/warning/element_set_spec.rb @@ -17,6 +17,18 @@ end end + ruby_version_is '3.3' do + it "enables or disables performance warnings" do + original = Warning[:performance] + begin + Warning[:performance] = !original + Warning[:performance].should == !original + ensure + Warning[:performance] = original + end + end + end + it "raises for unknown category" do -> { Warning[:noop] = false }.should raise_error(ArgumentError, /unknown category: noop/) end diff --git a/spec/ruby/language/method_spec.rb b/spec/ruby/language/method_spec.rb index b1d169aba8da71..5f42c523413f57 100644 --- a/spec/ruby/language/method_spec.rb +++ b/spec/ruby/language/method_spec.rb @@ -1107,9 +1107,9 @@ def m(a, **nil); a end; m({a: 1}).should == {a: 1} m({"a" => 1}).should == {"a" => 1} - -> { m(a: 1) }.should raise_error(ArgumentError) - -> { m(**{a: 1}) }.should raise_error(ArgumentError) - -> { m("a" => 1) }.should raise_error(ArgumentError) + -> { m(a: 1) }.should raise_error(ArgumentError, 'no keywords accepted') + -> { m(**{a: 1}) }.should raise_error(ArgumentError, 'no keywords accepted') + -> { m("a" => 1) }.should raise_error(ArgumentError, 'no keywords accepted') end evaluate <<-ruby do @@ -1193,14 +1193,42 @@ def n(value, &block) end end - context "when a single argument provided" do - it "assigns it" do + context "when a single argument is provided" do + it "assigns a simple expression" do + args = m (1) + args.should == [1] + end + + it "assigns an expression consisting of multiple statements" do + args = m ((0; 1)) + args.should == [1] + end + + it "assigns one single statement, without the need of parentheses" do args = m (1 == 1 ? true : false) args.should == [true] end + + ruby_version_is "3.3" do + it "supports multiple statements" do + eval("m (1; 2)").should == [2] + end + end + end + + context "when multiple arguments are provided" do + it "assigns simple expressions" do + args = m (1), (2) + args.should == [1, 2] + end + + it "assigns expressions consisting of multiple statements" do + args = m ((0; 1)), ((2; 3)) + args.should == [1, 3] + end end - context "when 2+ arguments provided" do + context "when the argument looks like an argument list" do it "raises a syntax error" do -> { eval("m (1, 2)") diff --git a/spec/ruby/language/predefined_spec.rb b/spec/ruby/language/predefined_spec.rb index 6f779b55f531a4..fe865cc3252f17 100644 --- a/spec/ruby/language/predefined_spec.rb +++ b/spec/ruby/language/predefined_spec.rb @@ -1037,7 +1037,7 @@ def obj.foo2; yield; end it "is the path given as the main script and the same as __FILE__" do script = "fixtures/dollar_zero.rb" - Dir.chdir(File.dirname(__FILE__)) do + Dir.chdir(__dir__) do ruby_exe(script).should == "#{script}\n#{script}\nOK" end end diff --git a/spec/ruby/library/bigdecimal/add_spec.rb b/spec/ruby/library/bigdecimal/add_spec.rb index 169a071aa63ace..542713011d6a93 100644 --- a/spec/ruby/library/bigdecimal/add_spec.rb +++ b/spec/ruby/library/bigdecimal/add_spec.rb @@ -24,7 +24,7 @@ end it "returns a + b with given precision" do - # documentation states, that precision ist optional, but it ain't, + # documentation states that precision is optional, but it ain't, @two.add(@one, 1).should == @three @one .add(@two, 1).should == @three @one.add(@one_minus, 1).should == @zero diff --git a/spec/ruby/library/date/deconstruct_keys_spec.rb b/spec/ruby/library/date/deconstruct_keys_spec.rb index 94b528099fd0de..92579e35c7c8e4 100644 --- a/spec/ruby/library/date/deconstruct_keys_spec.rb +++ b/spec/ruby/library/date/deconstruct_keys_spec.rb @@ -1,7 +1,8 @@ require_relative '../../spec_helper' require 'date' +date_version = defined?(Date::VERSION) ? Date::VERSION : '3.1.0' -version_is Date::VERSION, "3.3" do #ruby_version_is "3.2" do +version_is date_version, "3.3" do #ruby_version_is "3.2" do describe "Date#deconstruct_keys" do it "returns whole hash for nil as an argument" do d = Date.new(2022, 10, 5) diff --git a/spec/ruby/library/date/strftime_spec.rb b/spec/ruby/library/date/strftime_spec.rb index fc6c1dae8d6f51..b5232a2073fa6f 100644 --- a/spec/ruby/library/date/strftime_spec.rb +++ b/spec/ruby/library/date/strftime_spec.rb @@ -1,6 +1,7 @@ require_relative "../../spec_helper" require 'date' require_relative '../../shared/time/strftime_for_date' +date_version = defined?(Date::VERSION) ? Date::VERSION : '3.1.0' describe "Date#strftime" do before :all do @@ -23,14 +24,14 @@ end # %v is %e-%b-%Y for Date/DateTime - version_is Date::VERSION, ""..."3.2" do #ruby_version_is ""..."3.1" do + version_is date_version, ""..."3.2" do #ruby_version_is ""..."3.1" do it "should be able to show the commercial week" do @date.strftime("%v").should == " 9-Apr-2000" @date.strftime("%v").should == @date.strftime('%e-%b-%Y') end end - version_is Date::VERSION, "3.2" do #ruby_version_is "3.1" do + version_is date_version, "3.2" do #ruby_version_is "3.1" do it "should be able to show the commercial week" do @date.strftime("%v").should == " 9-APR-2000" @date.strftime("%v").should != @date.strftime('%e-%b-%Y') diff --git a/spec/ruby/library/datetime/deconstruct_keys_spec.rb b/spec/ruby/library/datetime/deconstruct_keys_spec.rb index 95a391cdd8b317..77ceaa51c4b9bd 100644 --- a/spec/ruby/library/datetime/deconstruct_keys_spec.rb +++ b/spec/ruby/library/datetime/deconstruct_keys_spec.rb @@ -1,7 +1,8 @@ require_relative '../../spec_helper' require 'date' +date_version = defined?(Date::VERSION) ? Date::VERSION : '3.1.0' -version_is Date::VERSION, "3.3" do #ruby_version_is "3.2" do +version_is date_version, "3.3" do #ruby_version_is "3.2" do describe "DateTime#deconstruct_keys" do it "returns whole hash for nil as an argument" do d = DateTime.new(2022, 10, 5, 13, 30) diff --git a/spec/ruby/library/datetime/strftime_spec.rb b/spec/ruby/library/datetime/strftime_spec.rb index 847098cb502751..abb0838e8e84d6 100644 --- a/spec/ruby/library/datetime/strftime_spec.rb +++ b/spec/ruby/library/datetime/strftime_spec.rb @@ -2,6 +2,7 @@ require 'date' require_relative '../../shared/time/strftime_for_date' require_relative '../../shared/time/strftime_for_time' +date_version = defined?(Date::VERSION) ? Date::VERSION : '3.1.0' describe "DateTime#strftime" do before :all do @@ -33,14 +34,14 @@ end # %v is %e-%b-%Y for Date/DateTime - version_is Date::VERSION, ""..."3.2" do #ruby_version_is ""..."3.1" do + version_is date_version, ""..."3.2" do #ruby_version_is ""..."3.1" do it "should be able to show the commercial week" do @time.strftime("%v").should == " 3-Feb-2001" @time.strftime("%v").should == @time.strftime('%e-%b-%Y') end end - version_is Date::VERSION, "3.2" do #ruby_version_is "3.1" do + version_is date_version, "3.2" do #ruby_version_is "3.1" do it "should be able to show the commercial week" do @time.strftime("%v").should == " 3-FEB-2001" @time.strftime("%v").should != @time.strftime('%e-%b-%Y') diff --git a/spec/ruby/library/datetime/to_time_spec.rb b/spec/ruby/library/datetime/to_time_spec.rb index 84990d511c7bc3..09e6192e7faab0 100644 --- a/spec/ruby/library/datetime/to_time_spec.rb +++ b/spec/ruby/library/datetime/to_time_spec.rb @@ -1,5 +1,6 @@ require_relative '../../spec_helper' require 'date' +date_version = defined?(Date::VERSION) ? Date::VERSION : '3.1.0' describe "DateTime#to_time" do it "yields a new Time object" do @@ -18,7 +19,7 @@ time.sec.should == 59 end - version_is(Date::VERSION, '3.2.3') do #ruby_version_is "3.2" do + version_is date_version, '3.2.3' do #ruby_version_is "3.2" do it "returns a Time representing the same instant before Gregorian" do datetime = DateTime.civil(1582, 10, 4, 23, 58, 59) time = datetime.to_time.utc diff --git a/spec/ruby/library/net/ftp/shared/getbinaryfile.rb b/spec/ruby/library/net/ftp/shared/getbinaryfile.rb index 71f226089d503a..ceec8e7cd5804c 100644 --- a/spec/ruby/library/net/ftp/shared/getbinaryfile.rb +++ b/spec/ruby/library/net/ftp/shared/getbinaryfile.rb @@ -1,6 +1,6 @@ describe :net_ftp_getbinaryfile, shared: true do before :each do - @fixture_file = File.dirname(__FILE__) + "/../fixtures/getbinaryfile" + @fixture_file = __dir__ + "/../fixtures/getbinaryfile" @tmp_file = tmp("getbinaryfile") @server = NetFTPSpecs::DummyFTP.new diff --git a/spec/ruby/library/net/ftp/shared/putbinaryfile.rb b/spec/ruby/library/net/ftp/shared/putbinaryfile.rb index 7dddcbc26b148c..45f53adc2a6868 100644 --- a/spec/ruby/library/net/ftp/shared/putbinaryfile.rb +++ b/spec/ruby/library/net/ftp/shared/putbinaryfile.rb @@ -3,7 +3,7 @@ @server = NetFTPSpecs::DummyFTP.new @server.serve_once - @local_fixture_file = File.dirname(__FILE__) + "/../fixtures/putbinaryfile" + @local_fixture_file = __dir__ + "/../fixtures/putbinaryfile" @remote_tmp_file = tmp("binaryfile", false) @ftp = Net::FTP.new diff --git a/spec/ruby/library/net/ftp/shared/puttextfile.rb b/spec/ruby/library/net/ftp/shared/puttextfile.rb index 50e8de28e637b2..3836e954b8072f 100644 --- a/spec/ruby/library/net/ftp/shared/puttextfile.rb +++ b/spec/ruby/library/net/ftp/shared/puttextfile.rb @@ -3,7 +3,7 @@ @server = NetFTPSpecs::DummyFTP.new @server.serve_once - @local_fixture_file = File.dirname(__FILE__) + "/../fixtures/puttextfile" + @local_fixture_file = __dir__ + "/../fixtures/puttextfile" @remote_tmp_file = tmp("textfile", false) @ftp = Net::FTP.new diff --git a/spec/ruby/library/net/ftp/storbinary_spec.rb b/spec/ruby/library/net/ftp/storbinary_spec.rb index 64c9090760cb1a..6f7334461201c1 100644 --- a/spec/ruby/library/net/ftp/storbinary_spec.rb +++ b/spec/ruby/library/net/ftp/storbinary_spec.rb @@ -9,7 +9,7 @@ @server = NetFTPSpecs::DummyFTP.new @server.serve_once - @local_fixture_file = File.dirname(__FILE__) + "/fixtures/putbinaryfile" + @local_fixture_file = __dir__ + "/fixtures/putbinaryfile" @tmp_file = tmp("binaryfile", false) @ftp = Net::FTP.new diff --git a/spec/ruby/library/net/ftp/storlines_spec.rb b/spec/ruby/library/net/ftp/storlines_spec.rb index a4bb7af7991657..32b9448732b4b0 100644 --- a/spec/ruby/library/net/ftp/storlines_spec.rb +++ b/spec/ruby/library/net/ftp/storlines_spec.rb @@ -9,7 +9,7 @@ @server = NetFTPSpecs::DummyFTP.new @server.serve_once - @local_fixture_file = File.dirname(__FILE__) + "/fixtures/puttextfile" + @local_fixture_file = __dir__ + "/fixtures/puttextfile" @tmp_file = tmp("textfile", false) @ftp = Net::FTP.new diff --git a/spec/ruby/library/set/divide_spec.rb b/spec/ruby/library/set/divide_spec.rb index fdd8cd962292a2..998a1b292c0fd3 100644 --- a/spec/ruby/library/set/divide_spec.rb +++ b/spec/ruby/library/set/divide_spec.rb @@ -13,11 +13,11 @@ ret.sort.should == ["five", "four", "one", "three", "two"] end - # BUG: Does not raise a LocalJumpError, but a NoMethodError - # - # it "raises a LocalJumpError when not passed a block" do - # lambda { Set[1].divide }.should raise_error(LocalJumpError) - # end + it "returns an enumerator when not passed a block" do + ret = Set[1, 2, 3, 4].divide + ret.should be_kind_of(Enumerator) + ret.each(&:even?).should == Set[Set[1, 3], Set[2, 4]] + end end describe "Set#divide when passed a block with an arity of 2" do @@ -31,4 +31,29 @@ Set[1, 2].divide { |x, y| ret << [x, y] } ret.sort.should == [[1, 1], [1, 2], [2, 1], [2, 2]] end + + it "returns an enumerator when not passed a block" do + ret = Set[1, 2, 3, 4].divide + ret.should be_kind_of(Enumerator) + ret.each { |a, b| (a + b).even? }.should == Set[Set[1, 3], Set[2, 4]] + end +end + +describe "Set#divide when passed a block with an arity of > 2" do + it "only uses the first element if the arity > 2" do + set = Set["one", "two", "three", "four", "five"].divide do |x, y, z| + y.should be_nil + z.should be_nil + x.length + end + set.map { |x| x.to_a.sort }.sort.should == [["five", "four"], ["one", "two"], ["three"]] + end + + it "only uses the first element if the arity = -1" do + set = Set["one", "two", "three", "four", "five"].divide do |*xs| + xs.size.should == 1 + xs.first.length + end + set.map { |x| x.to_a.sort }.sort.should == [["five", "four"], ["one", "two"], ["three"]] + end end diff --git a/spec/ruby/library/set/shared/inspect.rb b/spec/ruby/library/set/shared/inspect.rb index 1999b7b5538e44..adb6ddb4c9f2c1 100644 --- a/spec/ruby/library/set/shared/inspect.rb +++ b/spec/ruby/library/set/shared/inspect.rb @@ -15,9 +15,11 @@ Set["1", "2"].send(@method).should include('", "') end - it "correctly handles self-references" do - (set = Set[]) << set - set.send(@method).should be_kind_of(String) - set.send(@method).should include("#") + it "correctly handles cyclic-references" do + set1 = Set[] + set2 = Set[set1] + set1 << set2 + set1.send(@method).should be_kind_of(String) + set1.send(@method).should include("#") end end diff --git a/spec/ruby/library/time/to_datetime_spec.rb b/spec/ruby/library/time/to_datetime_spec.rb index 6e4d67eb53087c..9c44f38e5c2ff1 100644 --- a/spec/ruby/library/time/to_datetime_spec.rb +++ b/spec/ruby/library/time/to_datetime_spec.rb @@ -1,5 +1,7 @@ require_relative '../../spec_helper' require 'time' +require 'date' +date_version = defined?(Date::VERSION) ? Date::VERSION : '3.1.0' describe "Time#to_datetime" do it "returns a DateTime representing the same instant" do @@ -13,7 +15,7 @@ datetime.sec.should == 59 end - version_is(Date::VERSION, '3.2.3') do #ruby_version_is '3.2' do + version_is date_version, '3.2.3' do #ruby_version_is '3.2' do it "returns a DateTime representing the same instant before Gregorian" do time = Time.utc(1582, 10, 14, 23, 58, 59) datetime = time.to_datetime diff --git a/spec/ruby/library/yaml/fixtures/common.rb b/spec/ruby/library/yaml/fixtures/common.rb index f7fb4037e7c446..895213b844f087 100644 --- a/spec/ruby/library/yaml/fixtures/common.rb +++ b/spec/ruby/library/yaml/fixtures/common.rb @@ -1,4 +1,4 @@ require 'yaml' $test_file = tmp("yaml_test_file") -$test_parse_file = File.dirname(__FILE__) + "/test_yaml.yml" +$test_parse_file = __dir__ + "/test_yaml.yml" diff --git a/spec/ruby/optional/capi/kernel_spec.rb b/spec/ruby/optional/capi/kernel_spec.rb index 0890cc2d5c5bea..17c49b21555eac 100644 --- a/spec/ruby/optional/capi/kernel_spec.rb +++ b/spec/ruby/optional/capi/kernel_spec.rb @@ -503,6 +503,11 @@ def proc_caller it "evaluates a string of ruby code" do @s.rb_eval_string("1+1").should == 2 end + + it "captures local variables when called within a method" do + a = 2 + @s.rb_eval_string("a+1").should == 3 + end end describe "rb_eval_cmd_kw" do diff --git a/spec/ruby/optional/capi/object_spec.rb b/spec/ruby/optional/capi/object_spec.rb index 9efc892202fbb7..6ee6d65680f52e 100644 --- a/spec/ruby/optional/capi/object_spec.rb +++ b/spec/ruby/optional/capi/object_spec.rb @@ -219,7 +219,7 @@ def six(a, b, *c, &d); end end it "requires a ruby file" do - $:.unshift File.dirname(__FILE__) + $:.unshift __dir__ @o.rb_require() $foo.should == 7 end diff --git a/spec/ruby/shared/file/exist.rb b/spec/ruby/shared/file/exist.rb index 3bd97711b427ae..67424146c58134 100644 --- a/spec/ruby/shared/file/exist.rb +++ b/spec/ruby/shared/file/exist.rb @@ -4,11 +4,6 @@ @object.send(@method, 'a_fake_file').should == false end - it "returns true if the file exist using the alias exists?" do - @object.send(@method, __FILE__).should == true - @object.send(@method, 'a_fake_file').should == false - end - it "raises an ArgumentError if not passed one argument" do -> { @object.send(@method) }.should raise_error(ArgumentError) -> { @object.send(@method, __FILE__, __FILE__) }.should raise_error(ArgumentError) diff --git a/spec/ruby/spec_helper.rb b/spec/ruby/spec_helper.rb index 3404521c032ad4..af1c3858780b90 100644 --- a/spec/ruby/spec_helper.rb +++ b/spec/ruby/spec_helper.rb @@ -1,5 +1,5 @@ use_realpath = File.respond_to?(:realpath) -root = File.dirname(__FILE__) +root = __dir__ dir = "fixtures/code" CODE_LOADING_DIR = use_realpath ? File.realpath(dir, root) : File.expand_path(dir, root) From db3b814cb0ff6ffe83fe0c4f66cd6ce8951c3ca7 Mon Sep 17 00:00:00 2001 From: Peter Zhu Date: Mon, 4 Sep 2023 14:01:33 -0400 Subject: [PATCH 34/95] Add debug info for flaky test_warmup_frees_pages This test sometimes fails with: ``` 1) Failure: TestProcess#test_warmup_frees_pages [test/ruby/test_process.rb:2751]: <0> expected but was <1>. ``` I'm not sure why, so add some debug info. --- test/ruby/test_process.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/ruby/test_process.rb b/test/ruby/test_process.rb index 9cef299b6660b1..d7910e5acf5178 100644 --- a/test/ruby/test_process.rb +++ b/test/ruby/test_process.rb @@ -2748,7 +2748,7 @@ def test_warmup_frees_pages # Number of pages freed should cause equal increase in number of allocatable pages. assert_equal(total_pages_before, GC.stat(:heap_eden_pages) + GC.stat(:heap_allocatable_pages)) - assert_equal(0, GC.stat(:heap_tomb_pages)) + assert_equal(0, GC.stat(:heap_tomb_pages), GC.stat) assert_operator(GC.stat(:total_freed_pages), :>, 0) end; end From a14ba622da01c7774d0fb285b183097d19e3675e Mon Sep 17 00:00:00 2001 From: theo-squadracer <92919588+theo-squadracer@users.noreply.github.com> Date: Tue, 5 Sep 2023 02:37:26 +0200 Subject: [PATCH 35/95] [ruby/rdoc] handle symbols declared with `%s` https://github.com/ruby/rdoc/commit/ed91c4b784 --- lib/rdoc/parser/ripper_state_lex.rb | 2 +- test/rdoc/test_rdoc_parser_ruby.rb | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/rdoc/parser/ripper_state_lex.rb b/lib/rdoc/parser/ripper_state_lex.rb index 5492f08726aeca..27d73732707041 100644 --- a/lib/rdoc/parser/ripper_state_lex.rb +++ b/lib/rdoc/parser/ripper_state_lex.rb @@ -368,7 +368,7 @@ def get_squashed_tk private def get_symbol_tk(tk) is_symbol = true symbol_tk = Token.new(tk.line_no, tk.char_no, :on_symbol) - if ":'" == tk[:text] or ':"' == tk[:text] + if ":'" == tk[:text] or ':"' == tk[:text] or tk[:text].start_with?('%s') tk1 = get_string_tk(tk) symbol_tk[:text] = tk1[:text] symbol_tk[:state] = tk1[:state] diff --git a/test/rdoc/test_rdoc_parser_ruby.rb b/test/rdoc/test_rdoc_parser_ruby.rb index aea923765ce791..1f75ba7c6ef2b4 100644 --- a/test/rdoc/test_rdoc_parser_ruby.rb +++ b/test/rdoc/test_rdoc_parser_ruby.rb @@ -3205,6 +3205,14 @@ def test_parse_symbol_in_arg assert_nil @parser.parse_symbol_in_arg end + def test_parse_percent_symbol + content = '%s[foo bar]' + util_parser content + tk = @parser.get_tk + assert_equal :on_symbol, tk[:kind] + assert_equal content, tk[:text] + end + def test_parse_statements_alias_method content = <<-CONTENT class A From 3f6c92e9d592a2b122fb2260fccee7a7dd850cb8 Mon Sep 17 00:00:00 2001 From: Jeremy Evans Date: Sun, 19 Feb 2023 14:46:13 -0800 Subject: [PATCH 36/95] [ruby/rdoc] Omit descriptions and parameter lists for methods defined in C not mentioned in call-seq This allows RDoc to better generate documentation for methods following the Ruby core documentation guide (which omits aliases in call-seq in most cases). This makes documentation for methods defined in C more similar to methods defined in Ruby. For methods defined in Ruby, the method description of the aliased method is already not used (you have to explicitly document the alias to use it). Internally, this adds AnyMethod#has_call_seq? and #skip_description?, and updates Darkfish to: * only show the method name if there is a call-seq for the method, but the call-seq omits the method * to omit the method description if the method is an alias or has aliases and has a call-seq that does not include the method See discussion in https://github.com/ruby/ruby/pull/7316 for details. https://github.com/ruby/rdoc/commit/e3688de49b --- lib/rdoc/any_method.rb | 15 ++++++++ .../generator/template/darkfish/class.rhtml | 6 +++ test/rdoc/test_rdoc_any_method.rb | 38 +++++++++++++++++++ 3 files changed, 59 insertions(+) diff --git a/lib/rdoc/any_method.rb b/lib/rdoc/any_method.rb index 051f946a1048f7..465c4a4fb2d7ef 100644 --- a/lib/rdoc/any_method.rb +++ b/lib/rdoc/any_method.rb @@ -115,6 +115,13 @@ def call_seq= call_seq @call_seq = call_seq end + ## + # Whether the method has a call-seq. + + def has_call_seq? + !!(@call_seq || is_alias_for&._call_seq) + end + ## # Loads is_alias_for from the internal name. Returns nil if the alias # cannot be found. @@ -296,6 +303,14 @@ def param_seq params end + ## + # Whether to skip the method description, true for methods that have + # aliases with a call-seq that doesn't include the method name. + + def skip_description? + has_call_seq? && call_seq.nil? && !!(is_alias_for || !aliases.empty?) + end + ## # Sets the store for this method and its referenced code objects. diff --git a/lib/rdoc/generator/template/darkfish/class.rhtml b/lib/rdoc/generator/template/darkfish/class.rhtml index 97d175dddc4903..d6510336dfa110 100644 --- a/lib/rdoc/generator/template/darkfish/class.rhtml +++ b/lib/rdoc/generator/template/darkfish/class.rhtml @@ -112,6 +112,10 @@ <%- end -%> <%- end -%> + <%- elsif method.has_call_seq? then -%> +
+ <%= h method.name %> +
<%- else -%>
<%= h method.name %>
+ <%- unless method.skip_description? then -%>
<%- if method.comment then -%> <%= method.description.strip %> @@ -145,6 +150,7 @@
<%- end -%> + <%- end -%> <%- unless method.aliases.empty? then -%>
diff --git a/test/rdoc/test_rdoc_any_method.rb b/test/rdoc/test_rdoc_any_method.rb index 6915b466f0e147..b11c15420c2c58 100644 --- a/test/rdoc/test_rdoc_any_method.rb +++ b/test/rdoc/test_rdoc_any_method.rb @@ -69,6 +69,20 @@ def test_full_name assert_equal 'C1::m', @c1.method_list.first.full_name end + def test_has_call_seq? + m = RDoc::AnyMethod.new nil, "each_line" + m2 = RDoc::AnyMethod.new nil, "each" + assert_equal false, m.has_call_seq? + m.call_seq = "each_line()" + assert_equal true, m.has_call_seq? + + m = RDoc::AnyMethod.new nil, "each_line" + m.is_alias_for = m2 + assert_equal false, m.has_call_seq? + m2.call_seq = "each_line()" + assert_equal true, m.has_call_seq? + end + def test_is_alias_for assert_equal @c2_b, @c2_a.is_alias_for @@ -515,6 +529,30 @@ def test_parent_name assert_equal 'C1', @c1.method_list.last.parent_name end + def test_skip_description? + m = RDoc::AnyMethod.new nil, "each_line" + m2 = RDoc::AnyMethod.new nil, "each" + assert_equal false, m.skip_description? + assert_equal false, m2.skip_description? + + m.is_alias_for = m2 + m2.aliases << m + assert_equal false, m.skip_description? + assert_equal false, m2.skip_description? + + m2.call_seq = "each()" + assert_equal true, m.skip_description? + assert_equal false, m2.skip_description? + + m2.call_seq = "each_line()" + assert_equal false, m.skip_description? + assert_equal true, m2.skip_description? + + m2.call_seq = "each()\neach_line()" + assert_equal false, m.skip_description? + assert_equal false, m2.skip_description? + end + def test_store_equals loaded = Marshal.load Marshal.dump(@c1.method_list.last) From 736092ec11c4a3e4aa643434a54b135a648765ea Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada Date: Tue, 5 Sep 2023 09:48:11 +0900 Subject: [PATCH 37/95] [ruby/rdoc] Remove code for versions older than Ruby 2.3 https://github.com/ruby/rdoc/commit/a61b777df0 --- lib/rdoc/comment.rb | 7 +------ lib/rdoc/encoding.rb | 7 +------ 2 files changed, 2 insertions(+), 12 deletions(-) diff --git a/lib/rdoc/comment.rb b/lib/rdoc/comment.rb index 63197492c47c6a..fecdcac7820b39 100644 --- a/lib/rdoc/comment.rb +++ b/lib/rdoc/comment.rb @@ -133,12 +133,7 @@ def empty? # HACK dubious def encode! encoding - # TODO: Remove this condition after Ruby 2.2 EOL - if RUBY_VERSION < '2.3.0' - @text = @text.force_encoding encoding - else - @text = String.new @text, encoding: encoding - end + @text = String.new @text, encoding: encoding self end diff --git a/lib/rdoc/encoding.rb b/lib/rdoc/encoding.rb index cf60badd245541..8a921c7011fa42 100644 --- a/lib/rdoc/encoding.rb +++ b/lib/rdoc/encoding.rb @@ -124,12 +124,7 @@ def self.change_encoding text, encoding if text.kind_of? RDoc::Comment text.encode! encoding else - # TODO: Remove this condition after Ruby 2.2 EOL - if RUBY_VERSION < '2.3.0' - text.force_encoding encoding - else - String.new text, encoding: encoding - end + String.new text, encoding: encoding end end From dab6d55db115448680968da1f46194886e5eac84 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada Date: Tue, 5 Sep 2023 09:49:27 +0900 Subject: [PATCH 38/95] [ruby/rdoc] Remove code for versions older than Ruby 2.6 https://github.com/ruby/rdoc/commit/0d10f460eb --- lib/rdoc/erbio.rb | 8 ++------ lib/rdoc/generator/darkfish.rb | 6 +----- 2 files changed, 3 insertions(+), 11 deletions(-) diff --git a/lib/rdoc/erbio.rb b/lib/rdoc/erbio.rb index 56c0511a3d25ea..0f98eaedeef313 100644 --- a/lib/rdoc/erbio.rb +++ b/lib/rdoc/erbio.rb @@ -20,12 +20,8 @@ class RDoc::ERBIO < ERB ## # Defaults +eoutvar+ to 'io', otherwise is identical to ERB's initialize - def initialize str, safe_level = nil, legacy_trim_mode = nil, legacy_eoutvar = 'io', trim_mode: nil, eoutvar: 'io' - if RUBY_VERSION >= '2.6' - super(str, trim_mode: trim_mode, eoutvar: eoutvar) - else - super(str, safe_level, legacy_trim_mode, legacy_eoutvar) - end + def initialize str, trim_mode: nil, eoutvar: 'io' + super(str, trim_mode: trim_mode, eoutvar: eoutvar) end ## diff --git a/lib/rdoc/generator/darkfish.rb b/lib/rdoc/generator/darkfish.rb index 7a7a95a9b95696..1b408a6f8ee59e 100644 --- a/lib/rdoc/generator/darkfish.rb +++ b/lib/rdoc/generator/darkfish.rb @@ -778,11 +778,7 @@ def template_for file, page = true, klass = ERB erbout = "_erbout_#{file_var}" end - if RUBY_VERSION >= '2.6' - template = klass.new template, trim_mode: '-', eoutvar: erbout - else - template = klass.new template, nil, '-', erbout - end + template = klass.new template, trim_mode: '-', eoutvar: erbout @template_cache[file] = template template end From c9af91148997d8a7d1dbcf5503fd5c46cbba0670 Mon Sep 17 00:00:00 2001 From: Burdette Lamar Date: Mon, 4 Sep 2023 20:16:48 -0500 Subject: [PATCH 39/95] [DOC] RDoc for process.c (#8366) --- process.c | 124 ++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 97 insertions(+), 27 deletions(-) diff --git a/process.c b/process.c index 77f38e1d98990a..2e1c894eeba1f3 100644 --- a/process.c +++ b/process.c @@ -8639,38 +8639,108 @@ get_PROCESS_ID(ID _x, VALUE *_y) /* * call-seq: - * Process.kill(signal, pid, *pids) -> integer - * - * Sends the given signal to the specified process id(s) if _pid_ is positive. - * If _pid_ is zero, _signal_ is sent to all processes whose group ID is equal - * to the group ID of the process. If _pid_ is negative, results are dependent - * on the operating system. _signal_ may be an integer signal number or - * a POSIX signal name (either with or without a +SIG+ prefix). If _signal_ is - * negative (or starts with a minus sign), kills process groups instead of - * processes. Not all signals are available on all platforms. - * The keys and values of Signal.list are known signal names and numbers, - * respectively. - * - * pid = fork do - * Signal.trap("HUP") { puts "Ouch!"; exit } - * # ... do some work ... - * end - * # ... - * Process.kill("HUP", pid) - * Process.wait + * Process.kill(signal, *ids) -> count + * + * Sends a signal to each process specified by +ids+ + * (which must specify at least one ID); + * returns the count of signals sent. + * + * For each given +id+, if +id+ is: + * + * - Positive, sends the signal to the process whose process ID is +id+. + * - Zero, send the signal to all processes in the current process group. + * - Negative, sends the signal to a system-dependent collection of processes. + * + * Argument +signal+ specifies the signal to be sent; + * the argument may be: + * + * - An integer signal number: e.g., +-29+, +0+, +29+. + * - A signal name (string), with or without leading 'SIG', + * and with or without a further prefixed minus sign ('-'): + * e.g.: + * + * - 'SIGPOLL'. + * - 'POLL', + * - '-SIGPOLL'. + * - '-POLL'. + * + * - A signal symbol, with or without leading 'SIG', + * and with or without a further prefixed minus sign ('-'): + * e.g.: + * + * - +:SIGPOLL+. + * - +:POLL+. + * - :'-SIGPOLL'. + * - :'-POLL'. + * + * If +signal+ is: + * + * - A non-negative integer, or a signal name or symbol + * without prefixed '-', + * each process with process ID +id+ is signalled. + * - A negative integer, or a signal name or symbol + * with prefixed '-', + * each process group with group ID +id+ is signalled. + * + * The signal non-negative integers and strings are: + * + * - +0+ ('SIGEXIT'): Exit the current process. + * - +1+ ('SIGHUP'): Hang up controlling terminal or process. + * - +2+ ('SIGINT'): \Interrupt from keyboard, Ctrl-C. + * - +3+ ('SIGQUIT'): Quit from keyboard, Ctrl-\. + * - +4+ ('SIGILL'): Illegal instruction. + * - +5+ ('SIGTRAP'): Breakpoint for debugging. + * - +6+ ('SIGIOT'): Abnormal termination. + * - +7+ ('SIGBUS'): Bus error. + * - +8+ ('SIGFPE'): Floating-point exception. + * - +9+ ('SIGKILL'): Forced-process termination. + * - +10+ ('SIGUSR1'): Available to processes. + * - +11+ ('SIGSEGV'): Invalid memory reference. + * - +12+ ('SIGUSR2'): Available to processes. + * - +13+ ('SIGPIPE'): Write to pipe with no readers. + * - +14+ ('SIGALRM'): Real-timer clock. + * - +15+ ('SIGTERM'): \Process termination. + * - +17+ ('SIGCHLD'): Child process stopped or terminated + or got a signal if traced. + * - +18+ ('SIGCONT'): Resume execution, if stopped. + * - +19+ ('SIGSTOP'): Stop process execution, Ctrl-Z. + * - +20+ ('SIGTSTP'): Stop process issued from tty. + * - +21+ ('SIGTTIN'): Background process requires input. + * - +22+ ('SIGTTOU'): Background process requires output. + * - +23+ ('SIGURG'): Urgent condition on socket. + * - +24+ ('SIGXCPU'): CPU time limit exceeded. + * - +25+ ('SIGXFSZ'): File size limit exceeded. + * - +26+ ('SIGVTALRM'): Virtual timer clock. + * - +27+ ('SIGPROF'): Profile timer clock. + * - +28+ ('SIGWINCH'): Window resizing. + * - +29+ ('SIGPOLL'): I/O now possible. + * - +30+ ('SIGPWR'): Power supply failure. + * - +31+ ('SIGSYS', 'SIGUNUSED'): Bad system call. + * + * Example: + * + * pid = fork do + * Signal.trap("HUP") { puts "Ouch!"; exit } + * # ... do some work ... + * end + * # ... + * Process.kill("HUP", pid) + * Process.wait * - * produces: + * Output: * * Ouch! * - * If _signal_ is an integer but wrong for signal, Errno::EINVAL or - * RangeError will be raised. Otherwise unless _signal_ is a String - * or a Symbol, and a known signal name, ArgumentError will be - * raised. + * Exceptions: + * + * - Raises Errno::EINVAL or RangeError if +signal+ is an integer + * but invalid. + * - Raises ArgumentError if +signal+ is a string or symbol + * but invalid. + * - Raises Errno::ESRCH or RangeError if one of +ids+ is invalid. + * - Raises Errno::EPERM if needed permissions are not in force. * - * Also, Errno::ESRCH or RangeError for invalid _pid_, Errno::EPERM - * when failed because of no privilege, will be raised. In these - * cases, signals may have been sent to preceding processes. + * In the last two cases, signals may have been sent to some processes. */ static VALUE From 4a90c934278a0b1de11389dbbc208ee044117119 Mon Sep 17 00:00:00 2001 From: yui-knk Date: Sat, 2 Sep 2023 21:50:17 +0900 Subject: [PATCH 40/95] Pattern matching has not been experimental --- test/ruby/test_pattern_matching.rb | 4 ---- 1 file changed, 4 deletions(-) diff --git a/test/ruby/test_pattern_matching.rb b/test/ruby/test_pattern_matching.rb index 5e27593f25e20f..b761909913d0fa 100644 --- a/test/ruby/test_pattern_matching.rb +++ b/test/ruby/test_pattern_matching.rb @@ -109,16 +109,12 @@ def test_basic end assert_block do - # suppress "warning: Pattern matching is experimental, and the behavior may change in future versions of Ruby!" - experimental, Warning[:experimental] = Warning[:experimental], false eval(%q{ case true in a a end }) - ensure - Warning[:experimental] = experimental end assert_block do From 923d3517f145d9cb30bbc7d680aac32531de14ed Mon Sep 17 00:00:00 2001 From: Hiroshi SHIBATA Date: Tue, 5 Sep 2023 11:51:42 +0900 Subject: [PATCH 41/95] [flori/json] Removed code for Ruby 1.8 https://github.com/flori/json/commit/7f9c29038d --- test/json/json_encoding_test.rb | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/test/json/json_encoding_test.rb b/test/json/json_encoding_test.rb index 7e7e5341b02cb6..68a058f7d06e94 100644 --- a/test/json/json_encoding_test.rb +++ b/test/json/json_encoding_test.rb @@ -86,9 +86,7 @@ def test_unicode def test_chars (0..0x7f).each do |i| json = '["\u%04x"]' % i - if RUBY_VERSION >= "1.9." - i = i.chr - end + i = i.chr assert_equal i, parse(json).first[0] if i == ?\b generated = generate(["" << i]) From 77db0ca6c881b6fc705873f471fe4c52bffc0d50 Mon Sep 17 00:00:00 2001 From: Yusuke Endoh Date: Tue, 5 Sep 2023 17:29:53 +0900 Subject: [PATCH 42/95] Prevent a warning: method redefined; discarding old included ``` [ 3463/25719] JSONGeneratorTest#test_string_ext_included_calls_super/home/chkbuild/chkbuild/tmp/build/20230905T063003Z/ruby/test/json/json_generator_test.rb:411: warning: method redefined; discarding old included /home/chkbuild/chkbuild/tmp/build/20230905T063003Z/ruby/test/json/json_generator_test.rb:399: warning: previous definition of included was here ``` http://rubyci.s3.amazonaws.com/debian10/ruby-master/log/20230905T063003Z.log.html.gz --- test/json/json_generator_test.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/json/json_generator_test.rb b/test/json/json_generator_test.rb index 3c4aad6528b80a..5f0101d5f68e82 100755 --- a/test/json/json_generator_test.rb +++ b/test/json/json_generator_test.rb @@ -396,6 +396,7 @@ def test_string_ext_included_calls_super included = false Module.alias_method(:included_orig, :included) + Module.remove_method(:included) Module.define_method(:included) do |base| included_orig(base) included = true @@ -408,6 +409,7 @@ def test_string_ext_included_calls_super assert included ensure if Module.private_method_defined?(:included_orig) + Module.remove_method(:included) if Module.method_defined?(:included) Module.alias_method(:included, :included_orig) Module.remove_method(:included_orig) end From 5b146eb5a15cce4c7a6ce279bd53e75a61d4a1f5 Mon Sep 17 00:00:00 2001 From: Yusuke Endoh Date: Tue, 5 Sep 2023 17:35:28 +0900 Subject: [PATCH 43/95] Prevent "ambiguous first argument" warnings ``` /home/chkbuild/chkbuild/tmp/build/20230905T063003Z/ruby/test/yarp/compiler_test.rb:16: warning: ambiguous first argument; put parentheses or a space even after `+' operator /home/chkbuild/chkbuild/tmp/build/20230905T063003Z/ruby/test/yarp/compiler_test.rb:17: warning: ambiguous first argument; put parentheses or a space even after `-' operator /home/chkbuild/chkbuild/tmp/build/20230905T063003Z/ruby/test/yarp/compiler_test.rb:28: warning: ambiguous first argument; put parentheses or a space even after `+' operator /home/chkbuild/chkbuild/tmp/build/20230905T063003Z/ruby/test/yarp/compiler_test.rb:29: warning: ambiguous first argument; put parentheses or a space even after `-' operator ``` http://rubyci.s3.amazonaws.com/debian10/ruby-master/log/20230905T063003Z.log.html.gz --- test/yarp/compiler_test.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/yarp/compiler_test.rb b/test/yarp/compiler_test.rb index 7188defa7f2c39..b601ea585d8dfa 100644 --- a/test/yarp/compiler_test.rb +++ b/test/yarp/compiler_test.rb @@ -13,8 +13,8 @@ def test_FalseNode def test_FloatNode assert_equal 1.0, compile("1.0") assert_equal 1.0e0, compile("1.0e0") - assert_equal +1.0e+0, compile("+1.0e+0") - assert_equal -1.0e-0, compile("-1.0e-0") + assert_equal(+1.0e+0, compile("+1.0e+0")) + assert_equal(-1.0e-0, compile("-1.0e-0")) end def test_ImaginaryNode @@ -25,8 +25,8 @@ def test_ImaginaryNode def test_IntegerNode assert_equal 1, compile("1") - assert_equal +1, compile("+1") - assert_equal -1, compile("-1") + assert_equal(+1, compile("+1")) + assert_equal(-1, compile("-1")) # assert_equal 0x10, compile("0x10") # assert_equal 0b10, compile("0b10") # assert_equal 0o10, compile("0o10") From 7c8932365f043a4b6f44c55c432ceb6e028c1f2c Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada Date: Tue, 5 Sep 2023 20:36:45 +0900 Subject: [PATCH 44/95] [DOC] Fix signal list - Signal names can be symbols, as stated above. - Supported signals and those values are platform dependent. - Key sequences to send signal are configurable. - Fix description of signal 0. Co-authored-by: Peter Zhu --- process.c | 72 +++++++++++++++++++++++++++++-------------------------- 1 file changed, 38 insertions(+), 34 deletions(-) diff --git a/process.c b/process.c index 2e1c894eeba1f3..20f2f89de27816 100644 --- a/process.c +++ b/process.c @@ -8682,40 +8682,44 @@ get_PROCESS_ID(ID _x, VALUE *_y) * with prefixed '-', * each process group with group ID +id+ is signalled. * - * The signal non-negative integers and strings are: - * - * - +0+ ('SIGEXIT'): Exit the current process. - * - +1+ ('SIGHUP'): Hang up controlling terminal or process. - * - +2+ ('SIGINT'): \Interrupt from keyboard, Ctrl-C. - * - +3+ ('SIGQUIT'): Quit from keyboard, Ctrl-\. - * - +4+ ('SIGILL'): Illegal instruction. - * - +5+ ('SIGTRAP'): Breakpoint for debugging. - * - +6+ ('SIGIOT'): Abnormal termination. - * - +7+ ('SIGBUS'): Bus error. - * - +8+ ('SIGFPE'): Floating-point exception. - * - +9+ ('SIGKILL'): Forced-process termination. - * - +10+ ('SIGUSR1'): Available to processes. - * - +11+ ('SIGSEGV'): Invalid memory reference. - * - +12+ ('SIGUSR2'): Available to processes. - * - +13+ ('SIGPIPE'): Write to pipe with no readers. - * - +14+ ('SIGALRM'): Real-timer clock. - * - +15+ ('SIGTERM'): \Process termination. - * - +17+ ('SIGCHLD'): Child process stopped or terminated - or got a signal if traced. - * - +18+ ('SIGCONT'): Resume execution, if stopped. - * - +19+ ('SIGSTOP'): Stop process execution, Ctrl-Z. - * - +20+ ('SIGTSTP'): Stop process issued from tty. - * - +21+ ('SIGTTIN'): Background process requires input. - * - +22+ ('SIGTTOU'): Background process requires output. - * - +23+ ('SIGURG'): Urgent condition on socket. - * - +24+ ('SIGXCPU'): CPU time limit exceeded. - * - +25+ ('SIGXFSZ'): File size limit exceeded. - * - +26+ ('SIGVTALRM'): Virtual timer clock. - * - +27+ ('SIGPROF'): Profile timer clock. - * - +28+ ('SIGWINCH'): Window resizing. - * - +29+ ('SIGPOLL'): I/O now possible. - * - +30+ ('SIGPWR'): Power supply failure. - * - +31+ ('SIGSYS', 'SIGUNUSED'): Bad system call. + * The actual signal values are platform dependent, an example of + * signal names which are supported on many platforms are: + * + * - +SIGHUP+: Hang up controlling terminal or process. + * - +SIGINT+: \Interrupt from keyboard, Ctrl-C by default in general. + * - +SIGQUIT+: Quit from keyboard, Ctrl-\ by default in general. + * - +SIGILL+: Illegal instruction. + * - +SIGTRAP+: Breakpoint for debugging. + * - +SIGIOT+: Abnormal termination. + * - +SIGBUS+: Bus error. + * - +SIGFPE+: Floating-point exception. + * - +SIGKILL+: Forced-process termination. + * - +SIGUSR1+: Available to processes. + * - +SIGSEGV+: Invalid memory reference. + * - +SIGUSR2+: Available to processes. + * - +SIGPIPE+: Write to pipe with no readers. + * - +SIGALRM+: Real-timer clock. + * - +SIGTERM+: \Process termination. + * - +SIGCHLD+: Child process stopped or terminated or got a signal if traced. + * - +SIGCONT+: Resume execution, if stopped. + * - +SIGSTOP+: Stop process execution, Ctrl-Z by default in general. + * - +SIGTSTP+: Stop process issued from tty. + * - +SIGTTIN+: Background process requires input. + * - +SIGTTOU+: Background process requires output. + * - +SIGURG+: Urgent condition on socket. + * - +SIGXCPU+: CPU time limit exceeded. + * - +SIGXFSZ+: File size limit exceeded. + * - +SIGVTALRM+: Virtual timer clock. + * - +SIGPROF+: Profile timer clock. + * - +SIGWINCH+: Window resizing. + * - +SIGPOLL+: I/O now possible. + * - +SIGPWR+: Power supply failure. + * - +SIGSYS+, +SIGUNUSED+: Bad system call. + * + * Use `Signal.list` to see which signals are supported, and the + * actual values. + * + * Additionally, signal +0+ is useful to determine if the process exists. * * Example: * From 5b157997e29ee41dd9c94861dde38d148bca941d Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada Date: Tue, 5 Sep 2023 21:09:41 +0900 Subject: [PATCH 45/95] [DOC] Fix up markup --- process.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/process.c b/process.c index 20f2f89de27816..1360d5757309af 100644 --- a/process.c +++ b/process.c @@ -8716,8 +8716,8 @@ get_PROCESS_ID(ID _x, VALUE *_y) * - +SIGPWR+: Power supply failure. * - +SIGSYS+, +SIGUNUSED+: Bad system call. * - * Use `Signal.list` to see which signals are supported, and the - * actual values. + * Use Signal.list to see which signals are supported, and the actual + * values. * * Additionally, signal +0+ is useful to determine if the process exists. * From ef65183692789f80dc1c1ad569a449edfdd46120 Mon Sep 17 00:00:00 2001 From: Peter Zhu Date: Tue, 5 Sep 2023 09:27:11 -0400 Subject: [PATCH 46/95] Add check for T_NONE in rb_gc_mark_weak This commit adds a check for T_NONE in rb_gc_mark_weak, just like gc_mark_ptr. This will help debugging. --- gc.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/gc.c b/gc.c index 2863240aa6e578..b529a472ad7557 100644 --- a/gc.c +++ b/gc.c @@ -6903,6 +6903,11 @@ rb_gc_mark_weak(VALUE *ptr) GC_ASSERT(objspace->rgengc.parent_object == 0 || FL_TEST(objspace->rgengc.parent_object, FL_WB_PROTECTED)); + if (UNLIKELY(RB_TYPE_P(obj, T_NONE))) { + rp(obj); + rb_bug("try to mark T_NONE object"); + } + /* If we are in a minor GC and the other object is old, then obj should * already be marked and cannot be reclaimed in this GC cycle so we don't * need to add it to the weak refences list. */ From d83b5ea09d537431ff39d68de8832d5d7baf2db0 Mon Sep 17 00:00:00 2001 From: Stan Lo Date: Tue, 5 Sep 2023 14:42:15 +0100 Subject: [PATCH 47/95] [ruby/irb] Bump version to 1.8.1 (https://github.com/ruby/irb/pull/706) https://github.com/ruby/irb/commit/c7c838a4bf --- lib/irb/version.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/irb/version.rb b/lib/irb/version.rb index 04a9ccfe292c12..6cb2f1965c5112 100644 --- a/lib/irb/version.rb +++ b/lib/irb/version.rb @@ -5,7 +5,7 @@ # module IRB # :nodoc: - VERSION = "1.8.0" + VERSION = "1.8.1" @RELEASE_VERSION = VERSION - @LAST_UPDATE_DATE = "2023-08-30" + @LAST_UPDATE_DATE = "2023-09-04" end From dbe9b8520f284963da9c7d1c7fb9171629584a42 Mon Sep 17 00:00:00 2001 From: git Date: Tue, 5 Sep 2023 13:43:51 +0000 Subject: [PATCH 48/95] Update default gems list at d83b5ea09d537431ff39d68de8832d [ci skip] --- NEWS.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NEWS.md b/NEWS.md index de7591fb540a2d..f424808bf2d203 100644 --- a/NEWS.md +++ b/NEWS.md @@ -85,7 +85,7 @@ The following default gems are updated. * erb 4.0.3 * fiddle 1.1.2 * fileutils 1.7.1 -* irb 1.8.0 +* irb 1.8.1 * nkf 0.1.3 * optparse 0.4.0.pre.1 * psych 5.1.0 From 6110f415cd761fbfa3b6215b47dc81640032aa55 Mon Sep 17 00:00:00 2001 From: Benoit Daloze Date: Mon, 4 Sep 2023 12:46:06 +0200 Subject: [PATCH 49/95] [ruby/yarp] The value field of ClassVariableWriteNode is never null/nil https://github.com/ruby/yarp/commit/2ddd2eff94 --- yarp/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/yarp/config.yml b/yarp/config.yml index f1df755d891476..a7fb8651ad3bd7 100644 --- a/yarp/config.yml +++ b/yarp/config.yml @@ -797,7 +797,7 @@ nodes: - name: name_loc type: location - name: value - type: node? + type: node - name: operator_loc type: location? comment: | From e1713fa6a32070210322455d79ac4d3769aa6414 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada Date: Mon, 4 Sep 2023 21:57:34 +0900 Subject: [PATCH 50/95] [ruby/yarp] Read template in UTF-8 https://github.com/ruby/yarp/commit/864b4ce99f --- yarp/templates/template.rb | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) diff --git a/yarp/templates/template.rb b/yarp/templates/template.rb index 6534205004ffa1..c661dd04e73f44 100755 --- a/yarp/templates/template.rb +++ b/yarp/templates/template.rb @@ -304,21 +304,11 @@ def template(name, write_to: nil) private def read_template(filepath) - previous_verbosity = $VERBOSE - previous_default_external = Encoding.default_external - $VERBOSE = nil - - begin - Encoding.default_external = Encoding::UTF_8 - - if ERB.instance_method(:initialize).parameters.assoc(:key) # Ruby 2.6+ - ERB.new(File.read(filepath), trim_mode: "-") - else - ERB.new(File.read(filepath), nil, "-") - end - ensure - Encoding.default_external = previous_default_external - $VERBOSE = previous_verbosity + template = File.read(filepath, encoding: Encoding::UTF_8) + if ERB.instance_method(:initialize).parameters.assoc(:key) # Ruby 2.6+ + ERB.new(template, trim_mode: "-") + else + ERB.new(template, nil, "-") end end From 89a4fd67453b33b7c709c715f01cfeff8efb2f9d Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada Date: Mon, 4 Sep 2023 23:50:10 +0900 Subject: [PATCH 51/95] [ruby/yarp] Switch `ERB.new` at startup https://github.com/ruby/yarp/commit/b87b4450cc --- yarp/templates/template.rb | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/yarp/templates/template.rb b/yarp/templates/template.rb index c661dd04e73f44..5880f11957bb9a 100755 --- a/yarp/templates/template.rb +++ b/yarp/templates/template.rb @@ -266,7 +266,6 @@ def template(name, write_to: nil) template = File.expand_path("../#{filepath}", __dir__) erb = read_template(template) - erb.filename = template non_ruby_heading = <<~HEADING /******************************************************************************/ @@ -305,9 +304,17 @@ def template(name, write_to: nil) def read_template(filepath) template = File.read(filepath, encoding: Encoding::UTF_8) - if ERB.instance_method(:initialize).parameters.assoc(:key) # Ruby 2.6+ + erb = erb(template) + erb.filename = filepath + erb + end + + if ERB.instance_method(:initialize).parameters.assoc(:key) # Ruby 2.6+ + def erb(template) ERB.new(template, trim_mode: "-") - else + end + else + def erb ERB.new(template, nil, "-") end end From 790df7d3837af6554b26664d6de9a4d167cea1c7 Mon Sep 17 00:00:00 2001 From: Kevin Newton Date: Tue, 5 Sep 2023 10:23:54 -0400 Subject: [PATCH 52/95] [ruby/yarp] Fix up CI for Ruby 2.5 https://github.com/ruby/yarp/commit/462cb561a9 --- yarp/templates/template.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/yarp/templates/template.rb b/yarp/templates/template.rb index 5880f11957bb9a..64f1d75f85efb0 100755 --- a/yarp/templates/template.rb +++ b/yarp/templates/template.rb @@ -314,7 +314,7 @@ def erb(template) ERB.new(template, trim_mode: "-") end else - def erb + def erb(template) ERB.new(template, nil, "-") end end From 7a930cf0e4ff4bf7d70ef927d6f20d3189edcd21 Mon Sep 17 00:00:00 2001 From: Peter Zhu Date: Fri, 18 Aug 2023 09:56:46 -0400 Subject: [PATCH 53/95] Pool more slots for large size pools We always sweep at least 2048 slots per sweep step, but only pool one page. For large size pools, 2048 slots is many pages but one page is very few slots. This commit changes it so that at least 1024 slots are placed in the pooled pages per sweep step. --- gc.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/gc.c b/gc.c index b529a472ad7557..fb2d209466700a 100644 --- a/gc.c +++ b/gc.c @@ -1233,6 +1233,7 @@ total_freed_objects(rb_objspace_t *objspace) #define is_incremental_marking(objspace) ((objspace)->flags.during_incremental_marking != FALSE) #define will_be_incremental_marking(objspace) ((objspace)->rgengc.need_major_gc != GPR_FLAG_NONE) #define GC_INCREMENTAL_SWEEP_SLOT_COUNT 2048 +#define GC_INCREMENTAL_SWEEP_POOL_SLOT_COUT 1024 #define is_lazy_sweeping(objspace) (GC_ENABLE_LAZY_SWEEP && has_sweeping_pages(objspace)) #if SIZEOF_LONG == SIZEOF_VOIDP @@ -5781,9 +5782,7 @@ gc_sweep_step(rb_objspace_t *objspace, rb_size_pool_t *size_pool, rb_heap_t *hea struct heap_page *sweep_page = heap->sweeping_page; int unlink_limit = GC_SWEEP_PAGES_FREEABLE_PER_STEP; int swept_slots = 0; - bool need_pool = TRUE; - - gc_report(2, objspace, "gc_sweep_step (need_pool: %d)\n", need_pool); + int pooled_slots = 0; if (sweep_page == NULL) return FALSE; @@ -5818,9 +5817,9 @@ gc_sweep_step(rb_objspace_t *objspace, rb_size_pool_t *size_pool, rb_heap_t *hea size_pool->freed_slots += ctx.freed_slots; size_pool->empty_slots += ctx.empty_slots; - if (need_pool) { + if (pooled_slots < GC_INCREMENTAL_SWEEP_POOL_SLOT_COUT) { heap_add_poolpage(objspace, heap, sweep_page); - need_pool = FALSE; + pooled_slots += free_slots; } else { heap_add_freepage(heap, sweep_page); From e3210177e3d5d431543e66257d78564901e34611 Mon Sep 17 00:00:00 2001 From: Jemma Issroff Date: Tue, 5 Sep 2023 10:54:21 -0400 Subject: [PATCH 54/95] [YARP] Implemented Compiler for Constant(Or/Operator/And)Nodes (#8355) --- yarp/yarp_compiler.c | 96 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) diff --git a/yarp/yarp_compiler.c b/yarp/yarp_compiler.c index 3ff95e8816c910..317c6aa1c6398d 100644 --- a/yarp/yarp_compiler.c +++ b/yarp/yarp_compiler.c @@ -764,6 +764,102 @@ yp_compile_node(rb_iseq_t *iseq, const yp_node_t *node, LINK_ANCHOR *const ret, } return; } + case YP_NODE_CONSTANT_AND_WRITE_NODE: { + yp_constant_and_write_node_t *constant_and_write_node = (yp_constant_and_write_node_t*) node; + + LABEL *end_label = NEW_LABEL(lineno); + + VALUE constant_name = ID2SYM(parse_location_symbol(&constant_and_write_node->name_loc)); + + ADD_INSN(ret, &dummy_line_node, putnil); + ADD_INSN1(ret, &dummy_line_node, putobject, Qtrue); + ADD_INSN1(ret, &dummy_line_node, getconstant, constant_name); + if (!popped) { + ADD_INSN(ret, &dummy_line_node, dup); + } + + ADD_INSNL(ret, &dummy_line_node, branchunless, end_label); + + if (!popped) { + ADD_INSN(ret, &dummy_line_node, pop); + } + + yp_compile_node(iseq, constant_and_write_node->value, ret, src, false, compile_context); + + if (!popped) { + ADD_INSN(ret, &dummy_line_node, dup); + } + + ADD_INSN1(ret, &dummy_line_node, putspecialobject, INT2FIX(VM_SPECIAL_OBJECT_CONST_BASE)); + ADD_INSN1(ret, &dummy_line_node, setconstant, constant_name); + ADD_LABEL(ret, end_label); + + return; + } + case YP_NODE_CONSTANT_OPERATOR_WRITE_NODE: { + yp_constant_operator_write_node_t *constant_operator_write_node = (yp_constant_operator_write_node_t*) node; + + ID constant_name = parse_location_symbol(&constant_operator_write_node->name_loc); + ADD_INSN(ret, &dummy_line_node, putnil); + ADD_INSN1(ret, &dummy_line_node, putobject, Qtrue); + ADD_INSN1(ret, &dummy_line_node, getconstant, ID2SYM(constant_name)); + + yp_compile_node(iseq, constant_operator_write_node->value, ret, src, false, compile_context); + ID method_id = compile_context->constants[constant_operator_write_node->operator - 1]; + + int flags = VM_CALL_ARGS_SIMPLE; + ADD_SEND_WITH_FLAG(ret, &dummy_line_node, method_id, INT2NUM(1), INT2FIX(flags)); + + + if (!popped) { + ADD_INSN(ret, &dummy_line_node, dup); + } + + ADD_INSN1(ret, &dummy_line_node, putspecialobject, INT2FIX(VM_SPECIAL_OBJECT_CONST_BASE)); + ADD_INSN1(ret, &dummy_line_node, setconstant, ID2SYM(constant_name)); + + return; + } + case YP_NODE_CONSTANT_OR_WRITE_NODE: { + yp_constant_or_write_node_t *constant_or_write_node = (yp_constant_or_write_node_t*) node; + + LABEL *set_label= NEW_LABEL(lineno); + LABEL *end_label = NEW_LABEL(lineno); + + ADD_INSN(ret, &dummy_line_node, putnil); + VALUE constant_name = ID2SYM(parse_location_symbol(&constant_or_write_node->name_loc)); + + ADD_INSN3(ret, &dummy_line_node, defined, INT2FIX(DEFINED_CONST), constant_name, Qtrue); + + ADD_INSNL(ret, &dummy_line_node, branchunless, set_label); + + ADD_INSN(ret, &dummy_line_node, putnil); + ADD_INSN1(ret, &dummy_line_node, putobject, Qtrue); + ADD_INSN1(ret, &dummy_line_node, getconstant, constant_name); + + if (!popped) { + ADD_INSN(ret, &dummy_line_node, dup); + } + + ADD_INSNL(ret, &dummy_line_node, branchif, end_label); + + if (!popped) { + ADD_INSN(ret, &dummy_line_node, pop); + } + + ADD_LABEL(ret, set_label); + yp_compile_node(iseq, constant_or_write_node->value, ret, src, false, compile_context); + + if (!popped) { + ADD_INSN(ret, &dummy_line_node, dup); + } + + ADD_INSN1(ret, &dummy_line_node, putspecialobject, INT2FIX(VM_SPECIAL_OBJECT_CONST_BASE)); + ADD_INSN1(ret, &dummy_line_node, setconstant, constant_name); + ADD_LABEL(ret, end_label); + + return; + } case YP_NODE_CONSTANT_WRITE_NODE: { yp_constant_write_node_t *constant_write_node = (yp_constant_write_node_t *) node; yp_compile_node(iseq, constant_write_node->value, ret, src, false, compile_context); From ab9d1910ef2071589e4915e738b0a8abc97e2b6a Mon Sep 17 00:00:00 2001 From: Peter Zhu Date: Fri, 1 Sep 2023 13:22:37 -0400 Subject: [PATCH 55/95] Rename shady to uncollectible_wb_unprotected The term "shady object" was renamed to "uncollectible write barrier unprotected object", so rename `has_uncollectible_shady_objects` to `has_uncollectible_wb_unprotected_objects` for consistency. --- gc.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/gc.c b/gc.c index fb2d209466700a..8bb9fbbecf982d 100644 --- a/gc.c +++ b/gc.c @@ -955,7 +955,7 @@ struct heap_page { struct { unsigned int before_sweep : 1; unsigned int has_remembered_objects : 1; - unsigned int has_uncollectible_shady_objects : 1; + unsigned int has_uncollectible_wb_unprotected_objects : 1; unsigned int in_tomb : 1; } flags; @@ -6733,7 +6733,7 @@ gc_remember_unprotected(rb_objspace_t *objspace, VALUE obj) bits_t *uncollectible_bits = &page->uncollectible_bits[0]; if (!MARKED_IN_BITMAP(uncollectible_bits, obj)) { - page->flags.has_uncollectible_shady_objects = TRUE; + page->flags.has_uncollectible_wb_unprotected_objects = TRUE; MARK_IN_BITMAP(uncollectible_bits, obj); objspace->rgengc.uncollectible_wb_unprotected_objects++; @@ -7851,7 +7851,7 @@ gc_verify_heap_page(rb_objspace_t *objspace, struct heap_page *page, VALUE obj) (void *)page, remembered_old_objects, obj ? obj_info(obj) : ""); } - if (page->flags.has_uncollectible_shady_objects == FALSE && has_remembered_shady == TRUE) { + if (page->flags.has_uncollectible_wb_unprotected_objects == FALSE && has_remembered_shady == TRUE) { rb_bug("page %p's has_remembered_shady should be false, but there are remembered shady objects. %s", (void *)page, obj ? obj_info(obj) : ""); } @@ -8713,16 +8713,16 @@ rgengc_rememberset_mark(rb_objspace_t *objspace, rb_heap_t *heap) gc_report(1, objspace, "rgengc_rememberset_mark: start\n"); ccan_list_for_each(&heap->pages, page, page_node) { - if (page->flags.has_remembered_objects | page->flags.has_uncollectible_shady_objects) { + if (page->flags.has_remembered_objects | page->flags.has_uncollectible_wb_unprotected_objects) { uintptr_t p = page->start; bits_t bitset, bits[HEAP_PAGE_BITMAP_LIMIT]; bits_t *remembered_bits = page->remembered_bits; bits_t *uncollectible_bits = page->uncollectible_bits; bits_t *wb_unprotected_bits = page->wb_unprotected_bits; #if PROFILE_REMEMBERSET_MARK - if (page->flags.has_remembered_objects && page->flags.has_uncollectible_shady_objects) has_both++; + if (page->flags.has_remembered_objects && page->flags.has_uncollectible_wb_unprotected_objects) has_both++; else if (page->flags.has_remembered_objects) has_old++; - else if (page->flags.has_uncollectible_shady_objects) has_shady++; + else if (page->flags.has_uncollectible_wb_unprotected_objects) has_shady++; #endif for (j=0; jmarking_bits[0], 0, HEAP_PAGE_BITMAP_SIZE); memset(&page->remembered_bits[0], 0, HEAP_PAGE_BITMAP_SIZE); memset(&page->pinned_bits[0], 0, HEAP_PAGE_BITMAP_SIZE); - page->flags.has_uncollectible_shady_objects = FALSE; + page->flags.has_uncollectible_wb_unprotected_objects = FALSE; page->flags.has_remembered_objects = FALSE; } } @@ -10616,7 +10616,7 @@ gc_ref_update(void *vstart, void *vend, size_t stride, rb_objspace_t * objspace, VALUE v = (VALUE)vstart; asan_unlock_freelist(page); asan_lock_freelist(page); - page->flags.has_uncollectible_shady_objects = FALSE; + page->flags.has_uncollectible_wb_unprotected_objects = FALSE; page->flags.has_remembered_objects = FALSE; /* For each object on the page */ @@ -10630,7 +10630,7 @@ gc_ref_update(void *vstart, void *vend, size_t stride, rb_objspace_t * objspace, break; default: if (RVALUE_WB_UNPROTECTED(v)) { - page->flags.has_uncollectible_shady_objects = TRUE; + page->flags.has_uncollectible_wb_unprotected_objects = TRUE; } if (RVALUE_REMEMBERED(v)) { page->flags.has_remembered_objects = TRUE; From 88b25294b0e8d75f7901444bc5b2dc9e79411bdf Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada Date: Wed, 6 Sep 2023 01:23:35 +0900 Subject: [PATCH 56/95] Suppress macro redefinition warnings When building with ruby, `snprintf` is replaced with `ruby_snprintf`. --- yarp/defines.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/yarp/defines.h b/yarp/defines.h index 5fe3530d914fe4..24d33b5e091d84 100644 --- a/yarp/defines.h +++ b/yarp/defines.h @@ -36,7 +36,7 @@ #endif // Windows versions before 2015 use _snprintf -#if defined(_MSC_VER) && (_MSC_VER < 1900) +#if !defined(snprintf) && defined(_MSC_VER) && (_MSC_VER < 1900) # define snprintf _snprintf #endif From a17a1cd53573048ef3574fd105c297fadef9e934 Mon Sep 17 00:00:00 2001 From: Burdette Lamar Date: Tue, 5 Sep 2023 11:53:11 -0500 Subject: [PATCH 57/95] [DOC] Fix for RDoc for Process.kill (#8370) --- process.c | 46 ++++++++-------------------------------------- 1 file changed, 8 insertions(+), 38 deletions(-) diff --git a/process.c b/process.c index 1360d5757309af..acb74c2d47b167 100644 --- a/process.c +++ b/process.c @@ -8682,53 +8682,23 @@ get_PROCESS_ID(ID _x, VALUE *_y) * with prefixed '-', * each process group with group ID +id+ is signalled. * - * The actual signal values are platform dependent, an example of - * signal names which are supported on many platforms are: - * - * - +SIGHUP+: Hang up controlling terminal or process. - * - +SIGINT+: \Interrupt from keyboard, Ctrl-C by default in general. - * - +SIGQUIT+: Quit from keyboard, Ctrl-\ by default in general. - * - +SIGILL+: Illegal instruction. - * - +SIGTRAP+: Breakpoint for debugging. - * - +SIGIOT+: Abnormal termination. - * - +SIGBUS+: Bus error. - * - +SIGFPE+: Floating-point exception. - * - +SIGKILL+: Forced-process termination. - * - +SIGUSR1+: Available to processes. - * - +SIGSEGV+: Invalid memory reference. - * - +SIGUSR2+: Available to processes. - * - +SIGPIPE+: Write to pipe with no readers. - * - +SIGALRM+: Real-timer clock. - * - +SIGTERM+: \Process termination. - * - +SIGCHLD+: Child process stopped or terminated or got a signal if traced. - * - +SIGCONT+: Resume execution, if stopped. - * - +SIGSTOP+: Stop process execution, Ctrl-Z by default in general. - * - +SIGTSTP+: Stop process issued from tty. - * - +SIGTTIN+: Background process requires input. - * - +SIGTTOU+: Background process requires output. - * - +SIGURG+: Urgent condition on socket. - * - +SIGXCPU+: CPU time limit exceeded. - * - +SIGXFSZ+: File size limit exceeded. - * - +SIGVTALRM+: Virtual timer clock. - * - +SIGPROF+: Profile timer clock. - * - +SIGWINCH+: Window resizing. - * - +SIGPOLL+: I/O now possible. - * - +SIGPWR+: Power supply failure. - * - +SIGSYS+, +SIGUNUSED+: Bad system call. - * - * Use Signal.list to see which signals are supported, and the actual - * values. + * Use method Signal.list to see which signals are supported + * by Ruby on the underlying platform; + * the method returns a hash of the string names + * and non-negative integer values of the supported signals. + * The size and content of the returned hash varies widely + * among platforms. * * Additionally, signal +0+ is useful to determine if the process exists. * * Example: * * pid = fork do - * Signal.trap("HUP") { puts "Ouch!"; exit } + * Signal.trap('HUP') { puts 'Ouch!'; exit } * # ... do some work ... * end * # ... - * Process.kill("HUP", pid) + * Process.kill('HUP', pid) * Process.wait * * Output: From bdfa885f87b291dac8d0d390ba06b7f69f48da34 Mon Sep 17 00:00:00 2001 From: Jemma Issroff Date: Tue, 5 Sep 2023 13:58:16 -0400 Subject: [PATCH 58/95] [YARP] Fix aliasing instructions to use INT2FIX (#8373) --- yarp/yarp_compiler.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/yarp/yarp_compiler.c b/yarp/yarp_compiler.c index 317c6aa1c6398d..59a1444f654305 100644 --- a/yarp/yarp_compiler.c +++ b/yarp/yarp_compiler.c @@ -421,8 +421,8 @@ yp_compile_node(rb_iseq_t *iseq, const yp_node_t *node, LINK_ANCHOR *const ret, case YP_NODE_ALIAS_NODE: { yp_alias_node_t *alias_node = (yp_alias_node_t *) node; - ADD_INSN1(ret, &dummy_line_node, putspecialobject, VM_SPECIAL_OBJECT_VMCORE); - ADD_INSN1(ret, &dummy_line_node, putspecialobject, VM_SPECIAL_OBJECT_CBASE); + ADD_INSN1(ret, &dummy_line_node, putspecialobject, INT2FIX(VM_SPECIAL_OBJECT_VMCORE)); + ADD_INSN1(ret, &dummy_line_node, putspecialobject, INT2FIX(VM_SPECIAL_OBJECT_CBASE)); yp_compile_node(iseq, alias_node->new_name, ret, src, popped, compile_context); yp_compile_node(iseq, alias_node->old_name, ret, src, popped, compile_context); From 06a1d16dc2108c54090a0fca8b356f39ef353a99 Mon Sep 17 00:00:00 2001 From: Peter Zhu Date: Tue, 5 Sep 2023 13:34:41 -0400 Subject: [PATCH 59/95] Reuse allocated buffer in WeakMap If the key exists in WeakMap and WeakKeyMap, then we can reuse the buffer and we can avoid an allocation. --- weakmap.c | 37 ++++++++++++++++++------------------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/weakmap.c b/weakmap.c index 7763a9b2b1789d..92aed105b12d82 100644 --- a/weakmap.c +++ b/weakmap.c @@ -374,17 +374,23 @@ nonspecial_obj_id(VALUE obj) } static int -wmap_aset_replace(st_data_t *key, st_data_t *val, st_data_t new_key, int existing) +wmap_aset_replace(st_data_t *key, st_data_t *val, st_data_t new_key_ptr, int existing) { + VALUE new_key = *(VALUE *)new_key_ptr; + VALUE new_val = *(((VALUE *)new_key_ptr) + 1); + if (existing) { - VALUE *orig_pair = ((VALUE *)*key); assert(orig_pair[0] == *(VALUE *)new_key); + } + else { + VALUE *pair = xmalloc(sizeof(VALUE) * 2); - wmap_free_entry(orig_pair, orig_pair + 1); + *key = (st_data_t)pair; + *val = (st_data_t)(pair + 1); } - *key = new_key; - *val = (st_data_t)(((VALUE *)new_key) + 1); + *(VALUE *)*key = new_key; + *(VALUE *)*val = new_val; return ST_CONTINUE; } @@ -396,9 +402,7 @@ wmap_aset(VALUE self, VALUE key, VALUE val) struct weakmap *w; TypedData_Get_Struct(self, struct weakmap, &weakmap_type, w); - VALUE *pair = xmalloc(sizeof(VALUE) * 2); - pair[0] = key; - pair[1] = val; + VALUE pair[2] = { key, val }; st_update(w->table, (st_data_t)pair, wmap_aset_replace, (st_data_t)pair); @@ -678,7 +682,7 @@ wkmap_aref(VALUE self, VALUE key) } struct wkmap_aset_args { - VALUE *new_key; + VALUE new_key; VALUE new_val; }; @@ -687,13 +691,11 @@ wkmap_aset_replace(st_data_t *key, st_data_t *val, st_data_t data_args, int exis { struct wkmap_aset_args *args = (struct wkmap_aset_args *)data_args; - if (existing) { - VALUE *orig_key_ptr = ((VALUE *)*key); - - ruby_sized_xfree(orig_key_ptr, sizeof(VALUE)); + if (!existing) { + *key = (st_data_t)xmalloc(sizeof(VALUE)); } - *key = (st_data_t)args->new_key; + *(VALUE *)*key = args->new_key; *val = (st_data_t)args->new_val; return ST_CONTINUE; @@ -722,15 +724,12 @@ wkmap_aset(VALUE self, VALUE key, VALUE val) UNREACHABLE_RETURN(Qnil); } - VALUE *key_ptr = xmalloc(sizeof(VALUE)); - *key_ptr = key; - struct wkmap_aset_args args = { - .new_key = key_ptr, + .new_key = key, .new_val = val, }; - st_update(w->table, (st_data_t)key_ptr, wkmap_aset_replace, (st_data_t)&args); + st_update(w->table, (st_data_t)&key, wkmap_aset_replace, (st_data_t)&args); RB_OBJ_WRITTEN(self, Qundef, key); RB_OBJ_WRITTEN(self, Qundef, val); From 9a8398a18f364d3bcfc8d2744162d3572d9491e4 Mon Sep 17 00:00:00 2001 From: Peter Zhu Date: Tue, 5 Sep 2023 13:34:46 -0400 Subject: [PATCH 60/95] Introduce rb_gc_remove_weak If we're during incremental marking, then Ruby code can execute that deallocates certain memory buffers that have been called with rb_gc_mark_weak, which can cause use-after-free bugs. --- gc.c | 23 +++++++++++++++++++++++ internal/gc.h | 1 + weakmap.c | 7 ++++++- 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/gc.c b/gc.c index 8bb9fbbecf982d..cf53cf5270cb5a 100644 --- a/gc.c +++ b/gc.c @@ -6924,6 +6924,27 @@ rb_gc_mark_weak(VALUE *ptr) objspace->profile.weak_references_count++; } +void +rb_gc_remove_weak(VALUE parent_obj, VALUE *ptr) +{ + rb_objspace_t *objspace = &rb_objspace; + + /* If we're not incremental marking, then the state of the objects can't + * change so we don't need to do anything. */ + if (!is_incremental_marking(objspace)) return; + /* If parent_obj has not been marked, then ptr has not yet been marked + * weak, so we don't need to do anything. */ + if (!RVALUE_MARKED(parent_obj)) return; + + VALUE **ptr_ptr; + rb_darray_foreach(objspace->weak_references, i, ptr_ptr) { + if (*ptr_ptr == ptr) { + *ptr_ptr = NULL; + break; + } + } +} + /* CAUTION: THIS FUNCTION ENABLE *ONLY BEFORE* SWEEPING. * This function is only for GC_END_MARK timing. */ @@ -8151,6 +8172,8 @@ gc_update_weak_references(rb_objspace_t *objspace) size_t retained_weak_references_count = 0; VALUE **ptr_ptr; rb_darray_foreach(objspace->weak_references, i, ptr_ptr) { + if (!ptr_ptr) continue; + VALUE obj = **ptr_ptr; if (RB_SPECIAL_CONST_P(obj)) continue; diff --git a/internal/gc.h b/internal/gc.h index be40a7a2f7e3e9..28b82f4196edf6 100644 --- a/internal/gc.h +++ b/internal/gc.h @@ -236,6 +236,7 @@ VALUE rb_define_finalizer_no_check(VALUE obj, VALUE block); void rb_gc_mark_and_move(VALUE *ptr); void rb_gc_mark_weak(VALUE *ptr); +void rb_gc_remove_weak(VALUE parent_obj, VALUE *ptr); #define rb_gc_mark_and_move_ptr(ptr) do { \ VALUE _obj = (VALUE)*(ptr); \ diff --git a/weakmap.c b/weakmap.c index 92aed105b12d82..d79f5b3f941615 100644 --- a/weakmap.c +++ b/weakmap.c @@ -380,7 +380,7 @@ wmap_aset_replace(st_data_t *key, st_data_t *val, st_data_t new_key_ptr, int exi VALUE new_val = *(((VALUE *)new_key_ptr) + 1); if (existing) { - assert(orig_pair[0] == *(VALUE *)new_key); + assert(*(VALUE *)*key == new_key); } else { VALUE *pair = xmalloc(sizeof(VALUE) * 2); @@ -450,6 +450,9 @@ wmap_delete(VALUE self, VALUE key) if (st_delete(w->table, &orig_key_data, &orig_val_data)) { VALUE orig_val = *(VALUE *)orig_val_data; + rb_gc_remove_weak(self, (VALUE *)orig_key_data); + rb_gc_remove_weak(self, (VALUE *)orig_val_data); + wmap_free_entry((VALUE *)orig_key_data, (VALUE *)orig_val_data); if (wmap_live_p(orig_val)) { @@ -776,6 +779,8 @@ wkmap_delete(VALUE self, VALUE key) if (st_delete(w->table, &orig_key_data, &orig_val_data)) { VALUE orig_val = (VALUE)orig_val_data; + rb_gc_remove_weak(self, (VALUE *)orig_key_data); + ruby_sized_xfree((VALUE *)orig_key_data, sizeof(VALUE)); return orig_val; From c384ef07991d08dc378bf6450363aaa654099813 Mon Sep 17 00:00:00 2001 From: Kevin Newton Date: Tue, 5 Sep 2023 12:34:16 -0400 Subject: [PATCH 61/95] [ruby/yarp] Introduce a BlockLocalVariableNode This is a tradeoff that I think is worth it. Right now we have a location list that tracks the location of each of the block locals. Instead, I'd like to make that a node list that has a proper node in each spot in the list. In doing so, we eliminate the need to have a location list at all, making it simpler on all of the various consumers as we have one fewer field type. There should be minimal memory implications here since this syntax is exceedingly rare. https://github.com/ruby/yarp/commit/04d329ddf0 --- test/yarp/location_test.rb | 6 ++++ test/yarp/snapshots/procs.txt | 4 ++- .../snapshots/seattlerb/block_arg_scope.txt | 2 +- .../snapshots/seattlerb/block_arg_scope2.txt | 3 +- test/yarp/snapshots/seattlerb/block_scope.txt | 7 +++- .../snapshots/seattlerb/pipe_semicolon.txt | 7 +++- .../snapshots/seattlerb/stabby_proc_scope.txt | 2 +- .../unparser/corpus/literal/block.txt | 9 +++--- .../unparser/corpus/literal/lambda.txt | 2 +- test/yarp/snapshots/whitequark/arg_scope.txt | 7 +++- test/yarp/snapshots/whitequark/blockargs.txt | 4 +-- .../whitequark/send_lambda_args_shadow.txt | 3 +- yarp/config.yml | 11 ++++++- yarp/node.h | 4 --- yarp/templates/ext/yarp/api_node.c.erb | 6 ---- yarp/templates/include/yarp/ast.h.erb | 7 ---- yarp/templates/lib/yarp/node.rb.erb | 2 +- yarp/templates/lib/yarp/serialize.rb.erb | 1 - yarp/templates/src/node.c.erb | 28 ---------------- yarp/templates/src/prettyprint.c.erb | 7 ---- yarp/templates/src/serialize.c.erb | 6 ---- yarp/templates/template.rb | 12 ------- yarp/yarp.c | 32 +++++++++++++++---- 23 files changed, 77 insertions(+), 95 deletions(-) diff --git a/test/yarp/location_test.rb b/test/yarp/location_test.rb index 192cfdd716cdb4..6e544e86b011eb 100644 --- a/test/yarp/location_test.rb +++ b/test/yarp/location_test.rb @@ -67,6 +67,12 @@ def test_BlockArgumentNode assert_location(BlockArgumentNode, "foo(&bar)", 4...8) { |node| node.arguments.arguments.last } end + def test_BlockLocalVariableNode + assert_location(BlockLocalVariableNode, "foo { |;bar| }", 8...11) do |node| + node.block.parameters.locals.first + end + end + def test_BlockNode assert_location(BlockNode, "foo {}", 4...6, &:block) assert_location(BlockNode, "foo do end", 4...10, &:block) diff --git a/test/yarp/snapshots/procs.txt b/test/yarp/snapshots/procs.txt index adfb0637079532..4510160c44178a 100644 --- a/test/yarp/snapshots/procs.txt +++ b/test/yarp/snapshots/procs.txt @@ -16,7 +16,9 @@ ProgramNode(0...266)( nil, nil ), - [(7...8), (10...11), (13...14)], + [BlockLocalVariableNode(7...8)(:b), + BlockLocalVariableNode(10...11)(:c), + BlockLocalVariableNode(13...14)(:d)], (3...4), (14...15) ), diff --git a/test/yarp/snapshots/seattlerb/block_arg_scope.txt b/test/yarp/snapshots/seattlerb/block_arg_scope.txt index 498d41cbe39aa3..be99e78eecc891 100644 --- a/test/yarp/snapshots/seattlerb/block_arg_scope.txt +++ b/test/yarp/snapshots/seattlerb/block_arg_scope.txt @@ -20,7 +20,7 @@ ProgramNode(0...12)( nil, nil ), - [(8...9)], + [BlockLocalVariableNode(8...9)(:c)], (4...5), (9...10) ), diff --git a/test/yarp/snapshots/seattlerb/block_arg_scope2.txt b/test/yarp/snapshots/seattlerb/block_arg_scope2.txt index 787e8cb10a7437..fcee4898aa00a2 100644 --- a/test/yarp/snapshots/seattlerb/block_arg_scope2.txt +++ b/test/yarp/snapshots/seattlerb/block_arg_scope2.txt @@ -20,7 +20,8 @@ ProgramNode(0...14)( nil, nil ), - [(7...8), (10...11)], + [BlockLocalVariableNode(7...8)(:c), + BlockLocalVariableNode(10...11)(:d)], (3...4), (11...12) ), diff --git a/test/yarp/snapshots/seattlerb/block_scope.txt b/test/yarp/snapshots/seattlerb/block_scope.txt index 223268c471d574..bcdb26caa70706 100644 --- a/test/yarp/snapshots/seattlerb/block_scope.txt +++ b/test/yarp/snapshots/seattlerb/block_scope.txt @@ -10,7 +10,12 @@ ProgramNode(0...10)( nil, BlockNode(2...10)( [:b], - BlockParametersNode(4...8)(nil, [(6...7)], (4...5), (7...8)), + BlockParametersNode(4...8)( + nil, + [BlockLocalVariableNode(6...7)(:b)], + (4...5), + (7...8) + ), nil, (2...3), (9...10) diff --git a/test/yarp/snapshots/seattlerb/pipe_semicolon.txt b/test/yarp/snapshots/seattlerb/pipe_semicolon.txt index cd40d9ac0b18b4..14dc672e1c2339 100644 --- a/test/yarp/snapshots/seattlerb/pipe_semicolon.txt +++ b/test/yarp/snapshots/seattlerb/pipe_semicolon.txt @@ -10,7 +10,12 @@ ProgramNode(0...18)( nil, BlockNode(4...18)( [:c], - BlockParametersNode(7...14)(nil, [(11...12)], (7...8), (13...14)), + BlockParametersNode(7...14)( + nil, + [BlockLocalVariableNode(11...12)(:c)], + (7...8), + (13...14) + ), nil, (4...6), (15...18) diff --git a/test/yarp/snapshots/seattlerb/stabby_proc_scope.txt b/test/yarp/snapshots/seattlerb/stabby_proc_scope.txt index c4594997ebd59e..d8e06afa0fadec 100644 --- a/test/yarp/snapshots/seattlerb/stabby_proc_scope.txt +++ b/test/yarp/snapshots/seattlerb/stabby_proc_scope.txt @@ -16,7 +16,7 @@ ProgramNode(0...11)( nil, nil ), - [(6...7)], + [BlockLocalVariableNode(6...7)(:b)], (2...3), (7...8) ), diff --git a/test/yarp/snapshots/unparser/corpus/literal/block.txt b/test/yarp/snapshots/unparser/corpus/literal/block.txt index a115e84135b5f9..6ee2fbb1fa8803 100644 --- a/test/yarp/snapshots/unparser/corpus/literal/block.txt +++ b/test/yarp/snapshots/unparser/corpus/literal/block.txt @@ -91,7 +91,7 @@ ProgramNode(0...737)( nil, nil ), - [(44...45)], + [BlockLocalVariableNode(44...45)(:x)], (39...40), (45...46) ), @@ -326,7 +326,7 @@ ProgramNode(0...737)( nil, nil ), - [(181...182)], + [BlockLocalVariableNode(181...182)(:b)], (176...177), (182...183) ), @@ -366,7 +366,7 @@ ProgramNode(0...737)( nil, nil ), - [(200...201)], + [BlockLocalVariableNode(200...201)(:b)], (196...197), (201...202) ), @@ -398,7 +398,8 @@ ProgramNode(0...737)( [:a, :b], BlockParametersNode(215...223)( nil, - [(218...219), (221...222)], + [BlockLocalVariableNode(218...219)(:a), + BlockLocalVariableNode(221...222)(:b)], (215...216), (222...223) ), diff --git a/test/yarp/snapshots/unparser/corpus/literal/lambda.txt b/test/yarp/snapshots/unparser/corpus/literal/lambda.txt index 13161f9c881262..8c036bd70dfe60 100644 --- a/test/yarp/snapshots/unparser/corpus/literal/lambda.txt +++ b/test/yarp/snapshots/unparser/corpus/literal/lambda.txt @@ -110,7 +110,7 @@ ProgramNode(0...80)( nil, nil ), - [(74...75)], + [BlockLocalVariableNode(74...75)(:c)], (67...68), (75...76) ), diff --git a/test/yarp/snapshots/whitequark/arg_scope.txt b/test/yarp/snapshots/whitequark/arg_scope.txt index fd5ae0f61d51fe..baa33596becad9 100644 --- a/test/yarp/snapshots/whitequark/arg_scope.txt +++ b/test/yarp/snapshots/whitequark/arg_scope.txt @@ -10,7 +10,12 @@ ProgramNode(0...13)( nil, BlockNode(6...13)( [:a], - BlockParametersNode(7...11)(nil, [(9...10)], (7...8), (10...11)), + BlockParametersNode(7...11)( + nil, + [BlockLocalVariableNode(9...10)(:a)], + (7...8), + (10...11) + ), StatementsNode(11...12)([LocalVariableReadNode(11...12)(:a, 0)]), (6...7), (12...13) diff --git a/test/yarp/snapshots/whitequark/blockargs.txt b/test/yarp/snapshots/whitequark/blockargs.txt index 3115c58df12ff9..76f9dd4c5183cf 100644 --- a/test/yarp/snapshots/whitequark/blockargs.txt +++ b/test/yarp/snapshots/whitequark/blockargs.txt @@ -250,7 +250,7 @@ ProgramNode(0...550)( [:a], BlockParametersNode(117...123)( nil, - [(120...121)], + [BlockLocalVariableNode(120...121)(:a)], (117...118), (122...123) ), @@ -272,7 +272,7 @@ ProgramNode(0...550)( [:a], BlockParametersNode(130...134)( nil, - [(132...133)], + [BlockLocalVariableNode(132...133)(:a)], (130...131), (133...134) ), diff --git a/test/yarp/snapshots/whitequark/send_lambda_args_shadow.txt b/test/yarp/snapshots/whitequark/send_lambda_args_shadow.txt index 9a6c888a930c90..cee0016fa79d2c 100644 --- a/test/yarp/snapshots/whitequark/send_lambda_args_shadow.txt +++ b/test/yarp/snapshots/whitequark/send_lambda_args_shadow.txt @@ -16,7 +16,8 @@ ProgramNode(0...19)( nil, nil ), - [(6...9), (11...14)], + [BlockLocalVariableNode(6...9)(:foo), + BlockLocalVariableNode(11...14)(:bar)], (2...3), (14...15) ), diff --git a/yarp/config.yml b/yarp/config.yml index a7fb8651ad3bd7..b9e03b5fbacbfa 100644 --- a/yarp/config.yml +++ b/yarp/config.yml @@ -520,6 +520,15 @@ nodes: bar(&args) ^^^^^^^^^^ + - name: BlockLocalVariableNode + fields: + - name: name + type: constant + comment: | + Represents a block local variable. + + a { |; b| } + ^ - name: BlockNode fields: - name: locals @@ -556,7 +565,7 @@ nodes: type: node? kind: ParametersNode - name: locals - type: location[] + type: node[] - name: opening_loc type: location? - name: closing_loc diff --git a/yarp/node.h b/yarp/node.h index f2d5be8bf22e91..1b546f086f0004 100644 --- a/yarp/node.h +++ b/yarp/node.h @@ -4,9 +4,6 @@ #include "yarp/defines.h" #include "yarp/parser.h" -// Append a token to the given list. -void yp_location_list_append(yp_location_list_t *list, const yp_token_t *token); - // Append a new node onto the end of the node list. void yp_node_list_append(yp_node_list_t *list, yp_node_t *node); @@ -31,7 +28,6 @@ YP_EXPORTED_FUNCTION void yp_node_memsize(yp_node_t *node, yp_memsize_t *memsize YP_EXPORTED_FUNCTION const char * yp_node_type_to_str(yp_node_type_t node_type); #define YP_EMPTY_NODE_LIST ((yp_node_list_t) { .nodes = NULL, .size = 0, .capacity = 0 }) -#define YP_EMPTY_LOCATION_LIST ((yp_location_list_t) { .locations = NULL, .size = 0, .capacity = 0 }) #endif // YARP_NODE_H diff --git a/yarp/templates/ext/yarp/api_node.c.erb b/yarp/templates/ext/yarp/api_node.c.erb index b8407350589711..c3a232ec5fa468 100644 --- a/yarp/templates/ext/yarp/api_node.c.erb +++ b/yarp/templates/ext/yarp/api_node.c.erb @@ -152,12 +152,6 @@ yp_ast_new(yp_parser_t *parser, yp_node_t *node, rb_encoding *encoding) { } <%- when YARP::StringField -%> argv[<%= index %>] = yp_string_new(&cast-><%= field.name %>, encoding); - <%- when YARP::LocationListField -%> - argv[<%= index %>] = rb_ary_new_capa(cast-><%= field.name %>.size); - for (size_t index = 0; index < cast-><%= field.name %>.size; index++) { - yp_location_t location = cast-><%= field.name %>.locations[index]; - rb_ary_push(argv[<%= index %>], yp_location_new(parser, location.start, location.end, source)); - } <%- when YARP::ConstantField -%> argv[<%= index %>] = rb_id2sym(constants[cast-><%= field.name %> - 1]); <%- when YARP::ConstantListField -%> diff --git a/yarp/templates/include/yarp/ast.h.erb b/yarp/templates/include/yarp/ast.h.erb index f7e1d0b503ac22..48eaefda2447ad 100644 --- a/yarp/templates/include/yarp/ast.h.erb +++ b/yarp/templates/include/yarp/ast.h.erb @@ -32,12 +32,6 @@ typedef struct { const uint8_t *end; } yp_location_t; -typedef struct { - yp_location_t *locations; - size_t size; - size_t capacity; -} yp_location_list_t; - struct yp_node; typedef struct yp_node_list { @@ -95,7 +89,6 @@ typedef struct yp_<%= node.human %> { <%= case field when YARP::NodeField, YARP::OptionalNodeField then "struct #{field.c_type} *#{field.name}" when YARP::NodeListField then "struct yp_node_list #{field.name}" - when YARP::LocationListField then "yp_location_list_t #{field.name}" when YARP::ConstantField then "yp_constant_id_t #{field.name}" when YARP::ConstantListField then "yp_constant_id_list_t #{field.name}" when YARP::StringField then "yp_string_t #{field.name}" diff --git a/yarp/templates/lib/yarp/node.rb.erb b/yarp/templates/lib/yarp/node.rb.erb index 8919cb7ad091c6..105830836f8a1d 100644 --- a/yarp/templates/lib/yarp/node.rb.erb +++ b/yarp/templates/lib/yarp/node.rb.erb @@ -100,7 +100,7 @@ module YARP <%- case field -%> <%- when YARP::NodeListField -%> inspector << "<%= pointer %><%= field.name %>: #{inspector.list("#{inspector.prefix}<%= preadd %>", <%= field.name %>)}" - <%- when YARP::LocationListField, YARP::ConstantListField -%> + <%- when YARP::ConstantListField -%> inspector << "<%= pointer %><%= field.name %>: #{<%= field.name %>.inspect}\n" <%- when YARP::NodeField -%> inspector << "<%= pointer %><%= field.name %>:\n" diff --git a/yarp/templates/lib/yarp/serialize.rb.erb b/yarp/templates/lib/yarp/serialize.rb.erb index 230522ae2bf9f4..ee0b8666bfd3e7 100644 --- a/yarp/templates/lib/yarp/serialize.rb.erb +++ b/yarp/templates/lib/yarp/serialize.rb.erb @@ -185,7 +185,6 @@ module YARP when YARP::OptionalNodeField then "load_optional_node" when YARP::StringField then "load_string" when YARP::NodeListField then "Array.new(load_varint) { load_node }" - when YARP::LocationListField then "Array.new(load_varint) { load_location }" when YARP::ConstantField then "load_constant" when YARP::ConstantListField then "Array.new(load_varint) { load_constant }" when YARP::LocationField then "load_location" diff --git a/yarp/templates/src/node.c.erb b/yarp/templates/src/node.c.erb index aa756ed4f9a81f..647950d5824048 100644 --- a/yarp/templates/src/node.c.erb +++ b/yarp/templates/src/node.c.erb @@ -8,30 +8,6 @@ void yp_node_clear(yp_node_t *node) { node->location = location; } -// Calculate the size of the token list in bytes. -static size_t -yp_location_list_memsize(yp_location_list_t *list) { - return sizeof(yp_location_list_t) + (list->capacity * sizeof(yp_location_t)); -} - -// Append a token to the given list. -void -yp_location_list_append(yp_location_list_t *list, const yp_token_t *token) { - if (list->size == list->capacity) { - list->capacity = list->capacity == 0 ? 2 : list->capacity * 2; - list->locations = (yp_location_t *) realloc(list->locations, sizeof(yp_location_t) * list->capacity); - } - list->locations[list->size++] = (yp_location_t) { .start = token->start, .end = token->end }; -} - -// Free the memory associated with the token list. -static void -yp_location_list_free(yp_location_list_t *list) { - if (list->locations != NULL) { - free(list->locations); - } -} - static void yp_node_memsize_node(yp_node_t *node, yp_memsize_t *memsize); @@ -95,8 +71,6 @@ yp_node_destroy(yp_parser_t *parser, yp_node_t *node) { yp_string_free(&cast-><%= field.name %>); <%- when YARP::NodeListField -%> yp_node_list_free(parser, &cast-><%= field.name %>); - <%- when YARP::LocationListField -%> - yp_location_list_free(&cast-><%= field.name %>); <%- when YARP::ConstantListField -%> yp_constant_id_list_free(&cast-><%= field.name %>); <%- else -%> @@ -141,8 +115,6 @@ yp_node_memsize_node(yp_node_t *node, yp_memsize_t *memsize) { memsize->memsize += yp_string_memsize(&cast-><%= field.name %>); <%- when YARP::NodeListField -%> yp_node_list_memsize(&cast-><%= field.name %>, memsize); - <%- when YARP::LocationListField -%> - memsize->memsize += yp_location_list_memsize(&cast-><%= field.name %>); <%- when YARP::ConstantListField -%> memsize->memsize += yp_constant_id_list_memsize(&cast-><%= field.name %>); <%- else -%> diff --git a/yarp/templates/src/prettyprint.c.erb b/yarp/templates/src/prettyprint.c.erb index 4c1f49fdd2f017..793519a1acede9 100644 --- a/yarp/templates/src/prettyprint.c.erb +++ b/yarp/templates/src/prettyprint.c.erb @@ -45,13 +45,6 @@ prettyprint_node(yp_buffer_t *buffer, yp_parser_t *parser, yp_node_t *node) { prettyprint_node(buffer, parser, (yp_node_t *) ((yp_<%= node.human %>_t *) node)-><%= field.name %>.nodes[index]); } yp_buffer_append_str(buffer, "]", 1); - <%- when YARP::LocationListField -%> - yp_buffer_append_str(buffer, "[", 1); - for (uint32_t index = 0; index < ((yp_<%= node.human %>_t *)node)-><%= field.name %>.size; index++) { - if (index != 0) yp_buffer_append_str(buffer, ", ", 2); - prettyprint_location(buffer, parser, &((yp_<%= node.human %>_t *)node)-><%= field.name %>.locations[index]); - } - yp_buffer_append_str(buffer, "]", 1); <%- when YARP::ConstantField -%> char <%= field.name %>_buffer[12]; snprintf(<%= field.name %>_buffer, sizeof(<%= field.name %>_buffer), "%u", ((yp_<%= node.human %>_t *)node)-><%= field.name %>); diff --git a/yarp/templates/src/serialize.c.erb b/yarp/templates/src/serialize.c.erb index b1049ba11668bf..a6411baaf3a4ff 100644 --- a/yarp/templates/src/serialize.c.erb +++ b/yarp/templates/src/serialize.c.erb @@ -86,12 +86,6 @@ yp_serialize_node(yp_parser_t *parser, yp_node_t *node, yp_buffer_t *buffer) { for (uint32_t index = 0; index < <%= field.name %>_size; index++) { yp_serialize_node(parser, (yp_node_t *) ((yp_<%= node.human %>_t *)node)-><%= field.name %>.nodes[index], buffer); } - <%- when YARP::LocationListField -%> - uint32_t <%= field.name %>_size = yp_sizet_to_u32(((yp_<%= node.human %>_t *)node)-><%= field.name %>.size); - yp_buffer_append_u32(buffer, <%= field.name %>_size); - for (uint32_t index = 0; index < <%= field.name %>_size; index++) { - yp_serialize_location(parser, &((yp_<%= node.human %>_t *)node)-><%= field.name %>.locations[index], buffer); - } <%- when YARP::ConstantField -%> yp_buffer_append_u32(buffer, yp_sizet_to_u32(((yp_<%= node.human %>_t *)node)-><%= field.name %>)); <%- when YARP::ConstantListField -%> diff --git a/yarp/templates/template.rb b/yarp/templates/template.rb index 64f1d75f85efb0..428f3d5b3769f7 100755 --- a/yarp/templates/template.rb +++ b/yarp/templates/template.rb @@ -73,17 +73,6 @@ def java_type end end - # This represents a field on a node that is a list of locations. - class LocationListField < Field - def rbs_class - "Array[Location]" - end - - def java_type - "Location[]" - end - end - # This represents a field on a node that is the ID of a string interned # through the parser's constant pool. class ConstantField < Field @@ -205,7 +194,6 @@ def field_type_for(name) when "node?" then OptionalNodeField when "node[]" then NodeListField when "string" then StringField - when "location[]" then LocationListField when "constant" then ConstantField when "constant[]" then ConstantListField when "location" then LocationField diff --git a/yarp/yarp.c b/yarp/yarp.c index 45c26471bbb98e..a820751b42f1ff 100644 --- a/yarp/yarp.c +++ b/yarp/yarp.c @@ -1175,7 +1175,7 @@ yp_block_parameters_node_create(yp_parser_t *parser, yp_parameters_node_t *param .parameters = parameters, .opening_loc = YP_OPTIONAL_LOCATION_TOKEN_VALUE(opening), .closing_loc = { .start = NULL, .end = NULL }, - .locals = YP_EMPTY_LOCATION_LIST + .locals = YP_EMPTY_NODE_LIST }; return node; @@ -1190,14 +1190,30 @@ yp_block_parameters_node_closing_set(yp_block_parameters_node_t *node, const yp_ node->closing_loc = YP_LOCATION_TOKEN_VALUE(closing); } +// Allocate and initialize a new BlockLocalVariableNode node. +static yp_block_local_variable_node_t * +yp_block_local_variable_node_create(yp_parser_t *parser, const yp_token_t *name) { + assert(name->type == YP_TOKEN_IDENTIFIER || name->type == YP_TOKEN_MISSING); + yp_block_local_variable_node_t *node = YP_ALLOC_NODE(parser, yp_block_local_variable_node_t); + + *node = (yp_block_local_variable_node_t) { + { + .type = YP_NODE_BLOCK_LOCAL_VARIABLE_NODE, + .location = YP_LOCATION_TOKEN_VALUE(name), + }, + .name = yp_parser_constant_id_token(parser, name) + }; + + return node; +} + // Append a new block-local variable to a BlockParametersNode node. static void -yp_block_parameters_node_append_local(yp_block_parameters_node_t *node, const yp_token_t *local) { - assert(local->type == YP_TOKEN_IDENTIFIER || local->type == YP_TOKEN_MISSING); +yp_block_parameters_node_append_local(yp_block_parameters_node_t *node, const yp_block_local_variable_node_t *local) { + yp_node_list_append(&node->locals, (yp_node_t *) local); - yp_location_list_append(&node->locals, local); - if (node->base.location.start == NULL) node->base.location.start = local->start; - node->base.location.end = local->end; + if (node->base.location.start == NULL) node->base.location.start = local->base.location.start; + node->base.location.end = local->base.location.end; } // Allocate and initialize a new BreakNode node. @@ -9283,7 +9299,9 @@ parse_block_parameters( do { expect(parser, YP_TOKEN_IDENTIFIER, "Expected a local variable name."); yp_parser_local_add_token(parser, &parser->previous); - yp_block_parameters_node_append_local(block_parameters, &parser->previous); + + yp_block_local_variable_node_t *local = yp_block_local_variable_node_create(parser, &parser->previous); + yp_block_parameters_node_append_local(block_parameters, local); } while (accept(parser, YP_TOKEN_COMMA)); } From 6c4df555fd879570cec152f7b378995e782dcd4f Mon Sep 17 00:00:00 2001 From: Alan Wu Date: Tue, 5 Sep 2023 14:46:44 -0400 Subject: [PATCH 62/95] YJIT: Silence Clippy for bindgen generated code New Clippy lint in 1.72.0 is breaking our build as GitHub has updated their image. No point hearing about lints from generated code we don't manually write. --- yjit/src/cruby.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/yjit/src/cruby.rs b/yjit/src/cruby.rs index 254bdb1896d713..a8234e744aeae8 100644 --- a/yjit/src/cruby.rs +++ b/yjit/src/cruby.rs @@ -96,7 +96,7 @@ pub type size_t = u64; pub type RedefinitionFlag = u32; #[allow(dead_code)] -#[allow(clippy::useless_transmute)] +#[allow(clippy::all)] mod autogened { use super::*; // Textually include output from rust-bindgen as suggested by its user guide. From 95e4bdcd6263a8106eac25458a48517aaa4456f8 Mon Sep 17 00:00:00 2001 From: Kevin Newton Date: Tue, 5 Sep 2023 13:58:48 -0400 Subject: [PATCH 63/95] [ruby/yarp] Rename CallNode#operator_loc to CallNode#call_operator_loc https://github.com/ruby/yarp/commit/fbcd307a54 --- yarp/config.yml | 2 +- yarp/yarp.c | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/yarp/config.yml b/yarp/config.yml index b9e03b5fbacbfa..4c4ac81ac35eca 100644 --- a/yarp/config.yml +++ b/yarp/config.yml @@ -595,7 +595,7 @@ nodes: fields: - name: receiver type: node? - - name: operator_loc + - name: call_operator_loc type: location? - name: message_loc type: location? diff --git a/yarp/yarp.c b/yarp/yarp.c index a820751b42f1ff..2d609c79221ee5 100644 --- a/yarp/yarp.c +++ b/yarp/yarp.c @@ -1250,7 +1250,7 @@ yp_call_node_create(yp_parser_t *parser) { .location = YP_LOCATION_NULL_VALUE(parser), }, .receiver = NULL, - .operator_loc = YP_OPTIONAL_LOCATION_NOT_PROVIDED_VALUE, + .call_operator_loc = YP_OPTIONAL_LOCATION_NOT_PROVIDED_VALUE, .message_loc = YP_OPTIONAL_LOCATION_NOT_PROVIDED_VALUE, .opening_loc = YP_OPTIONAL_LOCATION_NOT_PROVIDED_VALUE, .arguments = NULL, @@ -1323,7 +1323,7 @@ yp_call_node_call_create(yp_parser_t *parser, yp_node_t *receiver, yp_token_t *o } node->receiver = receiver; - node->operator_loc = YP_OPTIONAL_LOCATION_TOKEN_VALUE(operator); + node->call_operator_loc = YP_OPTIONAL_LOCATION_TOKEN_VALUE(operator); node->message_loc = YP_OPTIONAL_LOCATION_TOKEN_VALUE(message); node->opening_loc = arguments->opening_loc; node->arguments = arguments->arguments; @@ -1400,7 +1400,7 @@ yp_call_node_shorthand_create(yp_parser_t *parser, yp_node_t *receiver, yp_token } node->receiver = receiver; - node->operator_loc = YP_OPTIONAL_LOCATION_TOKEN_VALUE(operator); + node->call_operator_loc = YP_OPTIONAL_LOCATION_TOKEN_VALUE(operator); node->opening_loc = arguments->opening_loc; node->arguments = arguments->arguments; node->closing_loc = arguments->closing_loc; @@ -8073,7 +8073,7 @@ parse_target(yp_parser_t *parser, yp_node_t *target) { // an aref expression, and we can transform it into an aset // expression. if ( - (call->operator_loc.start == NULL) && + (call->call_operator_loc.start == NULL) && (call->message_loc.start[0] == '[') && (call->message_loc.end[-1] == ']') && (call->block == NULL) @@ -8229,7 +8229,7 @@ parse_write(yp_parser_t *parser, yp_node_t *target, yp_token_t *operator, yp_nod // an aref expression, and we can transform it into an aset // expression. if ( - (call->operator_loc.start == NULL) && + (call->call_operator_loc.start == NULL) && (call->message_loc.start[0] == '[') && (call->message_loc.end[-1] == ']') && (call->block == NULL) From 767f984017ca264262d9ef04d1db78c6f361e65a Mon Sep 17 00:00:00 2001 From: Kevin Newton Date: Tue, 5 Sep 2023 14:16:33 -0400 Subject: [PATCH 64/95] [ruby/yarp] Flatten CallAndWriteNode, CallOrWriteNode, and CallOperatorWriteNode https://github.com/ruby/yarp/commit/8f26ffa0b2 --- test/yarp/location_test.rb | 12 +- .../snapshots/seattlerb/index_0_opasgn.txt | 24 +- .../op_asgn_dot_ident_command_call.txt | 26 +- .../seattlerb/op_asgn_index_command_call.txt | 26 +- .../op_asgn_primary_colon_identifier1.txt | 24 +- ..._primary_colon_identifier_command_call.txt | 24 +- .../op_asgn_val_dot_ident_command_call.txt | 26 +- .../yarp/snapshots/seattlerb/safe_op_asgn.txt | 24 +- .../snapshots/seattlerb/safe_op_asgn2.txt | 26 +- .../unparser/corpus/literal/assignment.txt | 92 ++- .../unparser/corpus/literal/opasgn.txt | 524 +++++++++--------- test/yarp/snapshots/whitequark/and_asgn.txt | 46 +- test/yarp/snapshots/whitequark/op_asgn.txt | 72 ++- .../yarp/snapshots/whitequark/op_asgn_cmd.txt | 72 ++- .../snapshots/whitequark/op_asgn_index.txt | 24 +- .../whitequark/op_asgn_index_cmd.txt | 24 +- test/yarp/snapshots/whitequark/or_asgn.txt | 54 +- .../snapshots/whitequark/ruby_bug_12402.txt | 192 +++---- .../whitequark/send_op_asgn_conditional.txt | 22 +- yarp/config.yml | 109 +++- yarp/yarp.c | 95 +++- 21 files changed, 766 insertions(+), 772 deletions(-) diff --git a/test/yarp/location_test.rb b/test/yarp/location_test.rb index 6e544e86b011eb..4509fc0cf5d9d2 100644 --- a/test/yarp/location_test.rb +++ b/test/yarp/location_test.rb @@ -172,9 +172,9 @@ def test_CallNode assert_location(CallNode, "foo bar('baz')") end - def test_CallOperatorAndWriteNode - assert_location(CallOperatorAndWriteNode, "foo.foo &&= bar") - assert_location(CallOperatorAndWriteNode, "foo[foo] &&= bar") + def test_CallAndWriteNode + assert_location(CallAndWriteNode, "foo.foo &&= bar") + assert_location(CallAndWriteNode, "foo[foo] &&= bar") end def test_CallOperatorWriteNode @@ -182,9 +182,9 @@ def test_CallOperatorWriteNode assert_location(CallOperatorWriteNode, "foo[foo] += bar") end - def test_CallOperatorOrWriteNode - assert_location(CallOperatorOrWriteNode, "foo.foo ||= bar") - assert_location(CallOperatorOrWriteNode, "foo[foo] ||= bar") + def test_CallOrWriteNode + assert_location(CallOrWriteNode, "foo.foo ||= bar") + assert_location(CallOrWriteNode, "foo[foo] ||= bar") end def test_CapturePatternNode diff --git a/test/yarp/snapshots/seattlerb/index_0_opasgn.txt b/test/yarp/snapshots/seattlerb/index_0_opasgn.txt index 1f6d27974ed588..60c76d0d005ecb 100644 --- a/test/yarp/snapshots/seattlerb/index_0_opasgn.txt +++ b/test/yarp/snapshots/seattlerb/index_0_opasgn.txt @@ -2,20 +2,18 @@ ProgramNode(0...8)( [], StatementsNode(0...8)( [CallOperatorWriteNode(0...8)( - CallNode(0...3)( - CallNode(0...1)(nil, nil, (0...1), nil, nil, nil, nil, 2, "a"), - nil, - (1...3), - (1...2), - nil, - (2...3), - nil, - 0, - "[]=" - ), + CallNode(0...1)(nil, nil, (0...1), nil, nil, nil, nil, 2, "a"), + nil, + (1...3), + (1...2), + nil, + (2...3), + 0, + "[]", + "[]=", + :+, (4...6), - CallNode(7...8)(nil, nil, (7...8), nil, nil, nil, nil, 2, "b"), - :+ + CallNode(7...8)(nil, nil, (7...8), nil, nil, nil, nil, 2, "b") )] ) ) diff --git a/test/yarp/snapshots/seattlerb/op_asgn_dot_ident_command_call.txt b/test/yarp/snapshots/seattlerb/op_asgn_dot_ident_command_call.txt index 0bb9c07eba91fa..a33ceae8ee257e 100644 --- a/test/yarp/snapshots/seattlerb/op_asgn_dot_ident_command_call.txt +++ b/test/yarp/snapshots/seattlerb/op_asgn_dot_ident_command_call.txt @@ -1,18 +1,17 @@ ProgramNode(0...11)( [], StatementsNode(0...11)( - [CallOperatorOrWriteNode(0...11)( - CallNode(0...3)( - ConstantReadNode(0...1)(), - (1...2), - (2...3), - nil, - nil, - nil, - nil, - 0, - "B=" - ), + [CallOrWriteNode(0...11)( + ConstantReadNode(0...1)(), + (1...2), + (2...3), + nil, + nil, + nil, + 0, + "B", + "B=", + (4...7), CallNode(8...11)( nil, nil, @@ -23,8 +22,7 @@ ProgramNode(0...11)( nil, 0, "c" - ), - (4...7) + ) )] ) ) diff --git a/test/yarp/snapshots/seattlerb/op_asgn_index_command_call.txt b/test/yarp/snapshots/seattlerb/op_asgn_index_command_call.txt index 5ae2a48469e3d9..e166f958a4f78c 100644 --- a/test/yarp/snapshots/seattlerb/op_asgn_index_command_call.txt +++ b/test/yarp/snapshots/seattlerb/op_asgn_index_command_call.txt @@ -1,18 +1,17 @@ ProgramNode(0...16)( [], StatementsNode(0...16)( - [CallOperatorOrWriteNode(0...16)( - CallNode(0...5)( - CallNode(0...1)(nil, nil, (0...1), nil, nil, nil, nil, 2, "a"), - nil, - (1...5), - (1...2), - ArgumentsNode(2...4)([SymbolNode(2...4)((2...3), (3...4), nil, "b")]), - (4...5), - nil, - 0, - "[]=" - ), + [CallOrWriteNode(0...16)( + CallNode(0...1)(nil, nil, (0...1), nil, nil, nil, nil, 2, "a"), + nil, + (1...5), + (1...2), + ArgumentsNode(2...4)([SymbolNode(2...4)((2...3), (3...4), nil, "b")]), + (4...5), + 0, + "[]", + "[]=", + (6...9), CallNode(10...16)( nil, nil, @@ -25,8 +24,7 @@ ProgramNode(0...16)( nil, 0, "c" - ), - (6...9) + ) )] ) ) diff --git a/test/yarp/snapshots/seattlerb/op_asgn_primary_colon_identifier1.txt b/test/yarp/snapshots/seattlerb/op_asgn_primary_colon_identifier1.txt index 88847480eef38a..85673bab52aca8 100644 --- a/test/yarp/snapshots/seattlerb/op_asgn_primary_colon_identifier1.txt +++ b/test/yarp/snapshots/seattlerb/op_asgn_primary_colon_identifier1.txt @@ -2,20 +2,18 @@ ProgramNode(0...9)( [], StatementsNode(0...9)( [CallOperatorWriteNode(0...9)( - CallNode(0...4)( - ConstantReadNode(0...1)(), - (1...3), - (3...4), - nil, - nil, - nil, - nil, - 0, - "b=" - ), + ConstantReadNode(0...1)(), + (1...3), + (3...4), + nil, + nil, + nil, + 0, + "b", + "b=", + :+, (5...7), - IntegerNode(8...9)(), - :+ + IntegerNode(8...9)() )] ) ) diff --git a/test/yarp/snapshots/seattlerb/op_asgn_primary_colon_identifier_command_call.txt b/test/yarp/snapshots/seattlerb/op_asgn_primary_colon_identifier_command_call.txt index 5f369122ffa0b4..741620d847afed 100644 --- a/test/yarp/snapshots/seattlerb/op_asgn_primary_colon_identifier_command_call.txt +++ b/test/yarp/snapshots/seattlerb/op_asgn_primary_colon_identifier_command_call.txt @@ -2,17 +2,16 @@ ProgramNode(0...11)( [], StatementsNode(0...11)( [CallOperatorWriteNode(0...11)( - CallNode(0...4)( - ConstantReadNode(0...1)(), - (1...3), - (3...4), - nil, - nil, - nil, - nil, - 0, - "b=" - ), + ConstantReadNode(0...1)(), + (1...3), + (3...4), + nil, + nil, + nil, + 0, + "b", + "b=", + :*, (5...7), CallNode(8...11)( nil, @@ -26,8 +25,7 @@ ProgramNode(0...11)( nil, 0, "c" - ), - :* + ) )] ) ) diff --git a/test/yarp/snapshots/seattlerb/op_asgn_val_dot_ident_command_call.txt b/test/yarp/snapshots/seattlerb/op_asgn_val_dot_ident_command_call.txt index 2d5ef0f0df205f..f075b4bb95f0ff 100644 --- a/test/yarp/snapshots/seattlerb/op_asgn_val_dot_ident_command_call.txt +++ b/test/yarp/snapshots/seattlerb/op_asgn_val_dot_ident_command_call.txt @@ -1,18 +1,17 @@ ProgramNode(0...11)( [], StatementsNode(0...11)( - [CallOperatorOrWriteNode(0...11)( - CallNode(0...3)( - CallNode(0...1)(nil, nil, (0...1), nil, nil, nil, nil, 2, "a"), - (1...2), - (2...3), - nil, - nil, - nil, - nil, - 0, - "b=" - ), + [CallOrWriteNode(0...11)( + CallNode(0...1)(nil, nil, (0...1), nil, nil, nil, nil, 2, "a"), + (1...2), + (2...3), + nil, + nil, + nil, + 0, + "b", + "b=", + (4...7), CallNode(8...11)( nil, nil, @@ -23,8 +22,7 @@ ProgramNode(0...11)( nil, 0, "c" - ), - (4...7) + ) )] ) ) diff --git a/test/yarp/snapshots/seattlerb/safe_op_asgn.txt b/test/yarp/snapshots/seattlerb/safe_op_asgn.txt index 50e03a150c4f5c..e5bc617610354b 100644 --- a/test/yarp/snapshots/seattlerb/safe_op_asgn.txt +++ b/test/yarp/snapshots/seattlerb/safe_op_asgn.txt @@ -2,17 +2,16 @@ ProgramNode(0...11)( [], StatementsNode(0...11)( [CallOperatorWriteNode(0...11)( - CallNode(0...4)( - CallNode(0...1)(nil, nil, (0...1), nil, nil, nil, nil, 2, "a"), - (1...3), - (3...4), - nil, - nil, - nil, - nil, - 1, - "b=" - ), + CallNode(0...1)(nil, nil, (0...1), nil, nil, nil, nil, 2, "a"), + (1...3), + (3...4), + nil, + nil, + nil, + 1, + "b", + "b=", + :+, (5...7), CallNode(8...11)( nil, @@ -24,8 +23,7 @@ ProgramNode(0...11)( nil, 0, "x" - ), - :+ + ) )] ) ) diff --git a/test/yarp/snapshots/seattlerb/safe_op_asgn2.txt b/test/yarp/snapshots/seattlerb/safe_op_asgn2.txt index 2b02d02caa81b8..c1175989aec8bd 100644 --- a/test/yarp/snapshots/seattlerb/safe_op_asgn2.txt +++ b/test/yarp/snapshots/seattlerb/safe_op_asgn2.txt @@ -1,20 +1,18 @@ ProgramNode(0...10)( [], StatementsNode(0...10)( - [CallOperatorOrWriteNode(0...10)( - CallNode(0...4)( - CallNode(0...1)(nil, nil, (0...1), nil, nil, nil, nil, 2, "a"), - (1...3), - (3...4), - nil, - nil, - nil, - nil, - 1, - "b=" - ), - CallNode(9...10)(nil, nil, (9...10), nil, nil, nil, nil, 2, "x"), - (5...8) + [CallOrWriteNode(0...10)( + CallNode(0...1)(nil, nil, (0...1), nil, nil, nil, nil, 2, "a"), + (1...3), + (3...4), + nil, + nil, + nil, + 1, + "b", + "b=", + (5...8), + CallNode(9...10)(nil, nil, (9...10), nil, nil, nil, nil, 2, "x") )] ) ) diff --git a/test/yarp/snapshots/unparser/corpus/literal/assignment.txt b/test/yarp/snapshots/unparser/corpus/literal/assignment.txt index c08204cf1620f2..ab443e43889f7c 100644 --- a/test/yarp/snapshots/unparser/corpus/literal/assignment.txt +++ b/test/yarp/snapshots/unparser/corpus/literal/assignment.txt @@ -584,32 +584,20 @@ ProgramNode(0...704)( 0, "[]=" ), - CallOperatorOrWriteNode(536...550)( - CallNode(536...542)( - LocalVariableReadNode(536...537)(:a, 0), - nil, - (537...542), - (537...538), - ArgumentsNode(538...541)( - [StringNode(538...541)((538...540), (540...540), (540...541), "")] - ), - (541...542), - nil, - 0, - "[]=" - ), - CallNode(547...550)( - nil, - nil, - (547...550), - nil, - nil, - nil, - nil, - 2, - "bar" + CallOrWriteNode(536...550)( + LocalVariableReadNode(536...537)(:a, 0), + nil, + (537...542), + (537...538), + ArgumentsNode(538...541)( + [StringNode(538...541)((538...540), (540...540), (540...541), "")] ), - (543...546) + (541...542), + 0, + "[]", + "[]=", + (543...546), + CallNode(547...550)(nil, nil, (547...550), nil, nil, nil, nil, 2, "bar") ), InstanceVariableOrWriteNode(551...561)( :@a, @@ -668,42 +656,26 @@ ProgramNode(0...704)( 0, "[]=" ), - CallOperatorOrWriteNode(651...672)( - CallNode(651...664)( - LocalVariableReadNode(651...652)(:a, 0), - nil, - (652...664), - (652...653), - ArgumentsNode(653...663)( - [InterpolatedStringNode(653...663)( - (653...663), - [StringNode(673...675)(nil, (673...675), nil, " "), - EmbeddedStatementsNode(675...678)( - (675...677), - nil, - (677...678) - ), - StringNode(678...679)(nil, (678...679), nil, "\n")], - (679...687) - )] - ), - (663...664), - nil, - 0, - "[]=" - ), - CallNode(669...672)( - nil, - nil, - (669...672), - nil, - nil, - nil, - nil, - 2, - "bar" + CallOrWriteNode(651...672)( + LocalVariableReadNode(651...652)(:a, 0), + nil, + (652...664), + (652...653), + ArgumentsNode(653...663)( + [InterpolatedStringNode(653...663)( + (653...663), + [StringNode(673...675)(nil, (673...675), nil, " "), + EmbeddedStatementsNode(675...678)((675...677), nil, (677...678)), + StringNode(678...679)(nil, (678...679), nil, "\n")], + (679...687) + )] ), - (665...668) + (663...664), + 0, + "[]", + "[]=", + (665...668), + CallNode(669...672)(nil, nil, (669...672), nil, nil, nil, nil, 2, "bar") ), InstanceVariableOrWriteNode(687...704)( :@a, diff --git a/test/yarp/snapshots/unparser/corpus/literal/opasgn.txt b/test/yarp/snapshots/unparser/corpus/literal/opasgn.txt index 15d621cbf6de63..149bbc8b04f029 100644 --- a/test/yarp/snapshots/unparser/corpus/literal/opasgn.txt +++ b/test/yarp/snapshots/unparser/corpus/literal/opasgn.txt @@ -105,334 +105,304 @@ ProgramNode(0...233)( "[]=" ), CallOperatorWriteNode(84...92)( - CallNode(84...87)( - LocalVariableReadNode(84...85)(:a, 0), - (85...86), - (86...87), - nil, - nil, - nil, - nil, - 0, - "b=" - ), + LocalVariableReadNode(84...85)(:a, 0), + (85...86), + (86...87), + nil, + nil, + nil, + 0, + "b", + "b=", + :+, (88...90), - IntegerNode(91...92)(), - :+ + IntegerNode(91...92)() ), CallOperatorWriteNode(93...101)( - CallNode(93...96)( - LocalVariableReadNode(93...94)(:a, 0), - (94...95), - (95...96), - nil, - nil, - nil, - nil, - 0, - "b=" - ), + LocalVariableReadNode(93...94)(:a, 0), + (94...95), + (95...96), + nil, + nil, + nil, + 0, + "b", + "b=", + :-, (97...99), - IntegerNode(100...101)(), - :- + IntegerNode(100...101)() ), CallOperatorWriteNode(102...111)( - CallNode(102...105)( - LocalVariableReadNode(102...103)(:a, 0), - (103...104), - (104...105), - nil, - nil, - nil, - nil, - 0, - "b=" - ), + LocalVariableReadNode(102...103)(:a, 0), + (103...104), + (104...105), + nil, + nil, + nil, + 0, + "b", + "b=", + :**, (106...109), - IntegerNode(110...111)(), - :** + IntegerNode(110...111)() ), CallOperatorWriteNode(112...120)( - CallNode(112...115)( - LocalVariableReadNode(112...113)(:a, 0), - (113...114), - (114...115), - nil, - nil, - nil, - nil, - 0, - "b=" - ), + LocalVariableReadNode(112...113)(:a, 0), + (113...114), + (114...115), + nil, + nil, + nil, + 0, + "b", + "b=", + :*, (116...118), - IntegerNode(119...120)(), - :* + IntegerNode(119...120)() ), CallOperatorWriteNode(121...129)( - CallNode(121...124)( - LocalVariableReadNode(121...122)(:a, 0), - (122...123), - (123...124), - nil, - nil, - nil, - nil, - 0, - "b=" - ), + LocalVariableReadNode(121...122)(:a, 0), + (122...123), + (123...124), + nil, + nil, + nil, + 0, + "b", + "b=", + :/, (125...127), - IntegerNode(128...129)(), - :/ + IntegerNode(128...129)() ), - CallOperatorAndWriteNode(130...139)( - CallNode(130...133)( - LocalVariableReadNode(130...131)(:a, 0), - (131...132), - (132...133), - nil, - nil, - nil, - nil, - 0, - "b=" - ), + CallAndWriteNode(130...139)( + LocalVariableReadNode(130...131)(:a, 0), + (131...132), + (132...133), + nil, + nil, + nil, + 0, + "b", + "b=", (134...137), CallNode(138...139)(nil, nil, (138...139), nil, nil, nil, nil, 2, "b") ), - CallOperatorOrWriteNode(140...149)( - CallNode(140...143)( - LocalVariableReadNode(140...141)(:a, 0), - (141...142), - (142...143), - nil, - nil, - nil, - nil, - 0, - "b=" - ), - IntegerNode(148...149)(), - (144...147) + CallOrWriteNode(140...149)( + LocalVariableReadNode(140...141)(:a, 0), + (141...142), + (142...143), + nil, + nil, + nil, + 0, + "b", + "b=", + (144...147), + IntegerNode(148...149)() ), CallOperatorWriteNode(150...159)( - CallNode(150...154)( - LocalVariableReadNode(150...151)(:a, 0), - nil, - (151...154), - (151...152), - ArgumentsNode(152...153)( - [CallNode(152...153)( - nil, - nil, - (152...153), - nil, - nil, - nil, - nil, - 2, - "b" - )] - ), - (153...154), - nil, - 0, - "[]=" + LocalVariableReadNode(150...151)(:a, 0), + nil, + (151...154), + (151...152), + ArgumentsNode(152...153)( + [CallNode(152...153)( + nil, + nil, + (152...153), + nil, + nil, + nil, + nil, + 2, + "b" + )] ), + (153...154), + 0, + "[]", + "[]=", + :+, (155...157), - IntegerNode(158...159)(), - :+ + IntegerNode(158...159)() ), CallOperatorWriteNode(160...169)( - CallNode(160...164)( - LocalVariableReadNode(160...161)(:a, 0), - nil, - (161...164), - (161...162), - ArgumentsNode(162...163)( - [CallNode(162...163)( - nil, - nil, - (162...163), - nil, - nil, - nil, - nil, - 2, - "b" - )] - ), - (163...164), - nil, - 0, - "[]=" + LocalVariableReadNode(160...161)(:a, 0), + nil, + (161...164), + (161...162), + ArgumentsNode(162...163)( + [CallNode(162...163)( + nil, + nil, + (162...163), + nil, + nil, + nil, + nil, + 2, + "b" + )] ), + (163...164), + 0, + "[]", + "[]=", + :-, (165...167), - IntegerNode(168...169)(), - :- + IntegerNode(168...169)() ), CallOperatorWriteNode(170...180)( - CallNode(170...174)( - LocalVariableReadNode(170...171)(:a, 0), - nil, - (171...174), - (171...172), - ArgumentsNode(172...173)( - [CallNode(172...173)( - nil, - nil, - (172...173), - nil, - nil, - nil, - nil, - 2, - "b" - )] - ), - (173...174), - nil, - 0, - "[]=" + LocalVariableReadNode(170...171)(:a, 0), + nil, + (171...174), + (171...172), + ArgumentsNode(172...173)( + [CallNode(172...173)( + nil, + nil, + (172...173), + nil, + nil, + nil, + nil, + 2, + "b" + )] ), + (173...174), + 0, + "[]", + "[]=", + :**, (175...178), - IntegerNode(179...180)(), - :** + IntegerNode(179...180)() ), CallOperatorWriteNode(181...190)( - CallNode(181...185)( - LocalVariableReadNode(181...182)(:a, 0), - nil, - (182...185), - (182...183), - ArgumentsNode(183...184)( - [CallNode(183...184)( - nil, - nil, - (183...184), - nil, - nil, - nil, - nil, - 2, - "b" - )] - ), - (184...185), - nil, - 0, - "[]=" + LocalVariableReadNode(181...182)(:a, 0), + nil, + (182...185), + (182...183), + ArgumentsNode(183...184)( + [CallNode(183...184)( + nil, + nil, + (183...184), + nil, + nil, + nil, + nil, + 2, + "b" + )] ), + (184...185), + 0, + "[]", + "[]=", + :*, (186...188), - IntegerNode(189...190)(), - :* + IntegerNode(189...190)() ), CallOperatorWriteNode(191...200)( - CallNode(191...195)( - LocalVariableReadNode(191...192)(:a, 0), - nil, - (192...195), - (192...193), - ArgumentsNode(193...194)( - [CallNode(193...194)( - nil, - nil, - (193...194), - nil, - nil, - nil, - nil, - 2, - "b" - )] - ), - (194...195), - nil, - 0, - "[]=" + LocalVariableReadNode(191...192)(:a, 0), + nil, + (192...195), + (192...193), + ArgumentsNode(193...194)( + [CallNode(193...194)( + nil, + nil, + (193...194), + nil, + nil, + nil, + nil, + 2, + "b" + )] ), + (194...195), + 0, + "[]", + "[]=", + :/, (196...198), - IntegerNode(199...200)(), - :/ + IntegerNode(199...200)() ), - CallOperatorAndWriteNode(201...211)( - CallNode(201...205)( - LocalVariableReadNode(201...202)(:a, 0), - nil, - (202...205), - (202...203), - ArgumentsNode(203...204)( - [CallNode(203...204)( - nil, - nil, - (203...204), - nil, - nil, - nil, - nil, - 2, - "b" - )] - ), - (204...205), - nil, - 0, - "[]=" + CallAndWriteNode(201...211)( + LocalVariableReadNode(201...202)(:a, 0), + nil, + (202...205), + (202...203), + ArgumentsNode(203...204)( + [CallNode(203...204)( + nil, + nil, + (203...204), + nil, + nil, + nil, + nil, + 2, + "b" + )] ), + (204...205), + 0, + "[]", + "[]=", (206...209), CallNode(210...211)(nil, nil, (210...211), nil, nil, nil, nil, 2, "b") ), - CallOperatorOrWriteNode(212...222)( - CallNode(212...216)( - LocalVariableReadNode(212...213)(:a, 0), - nil, - (213...216), - (213...214), - ArgumentsNode(214...215)( - [CallNode(214...215)( - nil, - nil, - (214...215), - nil, - nil, - nil, - nil, - 2, - "b" - )] - ), - (215...216), - nil, - 0, - "[]=" + CallOrWriteNode(212...222)( + LocalVariableReadNode(212...213)(:a, 0), + nil, + (213...216), + (213...214), + ArgumentsNode(214...215)( + [CallNode(214...215)( + nil, + nil, + (214...215), + nil, + nil, + nil, + nil, + 2, + "b" + )] ), - IntegerNode(221...222)(), - (217...220) + (215...216), + 0, + "[]", + "[]=", + (217...220), + IntegerNode(221...222)() ), CallOperatorWriteNode(223...233)( - CallNode(223...228)( - CallNode(223...226)( - nil, - nil, - (223...226), - nil, - nil, - nil, - nil, - 2, - "foo" - ), - (226...227), - (227...228), + CallNode(223...226)( nil, nil, + (223...226), nil, nil, - 0, - "A=" + nil, + nil, + 2, + "foo" ), + (226...227), + (227...228), + nil, + nil, + nil, + 0, + "A", + "A=", + :+, (229...231), - IntegerNode(232...233)(), - :+ + IntegerNode(232...233)() )] ) ) diff --git a/test/yarp/snapshots/whitequark/and_asgn.txt b/test/yarp/snapshots/whitequark/and_asgn.txt index d42bcc35f3e9d6..fab12349c28e75 100644 --- a/test/yarp/snapshots/whitequark/and_asgn.txt +++ b/test/yarp/snapshots/whitequark/and_asgn.txt @@ -1,35 +1,31 @@ ProgramNode(0...28)( [], StatementsNode(0...28)( - [CallOperatorAndWriteNode(0...11)( - CallNode(0...5)( - CallNode(0...3)(nil, nil, (0...3), nil, nil, nil, nil, 2, "foo"), - (3...4), - (4...5), - nil, - nil, - nil, - nil, - 0, - "a=" - ), + [CallAndWriteNode(0...11)( + CallNode(0...3)(nil, nil, (0...3), nil, nil, nil, nil, 2, "foo"), + (3...4), + (4...5), + nil, + nil, + nil, + 0, + "a", + "a=", (6...9), IntegerNode(10...11)() ), - CallOperatorAndWriteNode(13...28)( - CallNode(13...22)( - CallNode(13...16)(nil, nil, (13...16), nil, nil, nil, nil, 2, "foo"), - nil, - (16...22), - (16...17), - ArgumentsNode(17...21)( - [IntegerNode(17...18)(), IntegerNode(20...21)()] - ), - (21...22), - nil, - 0, - "[]=" + CallAndWriteNode(13...28)( + CallNode(13...16)(nil, nil, (13...16), nil, nil, nil, nil, 2, "foo"), + nil, + (16...22), + (16...17), + ArgumentsNode(17...21)( + [IntegerNode(17...18)(), IntegerNode(20...21)()] ), + (21...22), + 0, + "[]", + "[]=", (23...26), IntegerNode(27...28)() )] diff --git a/test/yarp/snapshots/whitequark/op_asgn.txt b/test/yarp/snapshots/whitequark/op_asgn.txt index c0a4e0471fa30b..44e3694392afb3 100644 --- a/test/yarp/snapshots/whitequark/op_asgn.txt +++ b/test/yarp/snapshots/whitequark/op_asgn.txt @@ -2,52 +2,46 @@ ProgramNode(0...35)( [], StatementsNode(0...35)( [CallOperatorWriteNode(0...10)( - CallNode(0...5)( - CallNode(0...3)(nil, nil, (0...3), nil, nil, nil, nil, 2, "foo"), - (3...4), - (4...5), - nil, - nil, - nil, - nil, - 0, - "A=" - ), + CallNode(0...3)(nil, nil, (0...3), nil, nil, nil, nil, 2, "foo"), + (3...4), + (4...5), + nil, + nil, + nil, + 0, + "A", + "A=", + :+, (6...8), - IntegerNode(9...10)(), - :+ + IntegerNode(9...10)() ), CallOperatorWriteNode(12...22)( - CallNode(12...17)( - CallNode(12...15)(nil, nil, (12...15), nil, nil, nil, nil, 2, "foo"), - (15...16), - (16...17), - nil, - nil, - nil, - nil, - 0, - "a=" - ), + CallNode(12...15)(nil, nil, (12...15), nil, nil, nil, nil, 2, "foo"), + (15...16), + (16...17), + nil, + nil, + nil, + 0, + "a", + "a=", + :+, (18...20), - IntegerNode(21...22)(), - :+ + IntegerNode(21...22)() ), CallOperatorWriteNode(24...35)( - CallNode(24...30)( - CallNode(24...27)(nil, nil, (24...27), nil, nil, nil, nil, 2, "foo"), - (27...29), - (29...30), - nil, - nil, - nil, - nil, - 0, - "a=" - ), + CallNode(24...27)(nil, nil, (24...27), nil, nil, nil, nil, 2, "foo"), + (27...29), + (29...30), + nil, + nil, + nil, + 0, + "a", + "a=", + :+, (31...33), - IntegerNode(34...35)(), - :+ + IntegerNode(34...35)() )] ) ) diff --git a/test/yarp/snapshots/whitequark/op_asgn_cmd.txt b/test/yarp/snapshots/whitequark/op_asgn_cmd.txt index 409aa26ee25c84..9bf83ad959a3ce 100644 --- a/test/yarp/snapshots/whitequark/op_asgn_cmd.txt +++ b/test/yarp/snapshots/whitequark/op_asgn_cmd.txt @@ -2,17 +2,16 @@ ProgramNode(0...64)( [], StatementsNode(0...64)( [CallOperatorWriteNode(0...14)( - CallNode(0...5)( - CallNode(0...3)(nil, nil, (0...3), nil, nil, nil, nil, 2, "foo"), - (3...4), - (4...5), - nil, - nil, - nil, - nil, - 0, - "A=" - ), + CallNode(0...3)(nil, nil, (0...3), nil, nil, nil, nil, 2, "foo"), + (3...4), + (4...5), + nil, + nil, + nil, + 0, + "A", + "A=", + :+, (6...8), CallNode(9...14)( nil, @@ -36,21 +35,19 @@ ProgramNode(0...64)( nil, 0, "m" - ), - :+ + ) ), CallOperatorWriteNode(16...30)( - CallNode(16...21)( - CallNode(16...19)(nil, nil, (16...19), nil, nil, nil, nil, 2, "foo"), - (19...20), - (20...21), - nil, - nil, - nil, - nil, - 0, - "a=" - ), + CallNode(16...19)(nil, nil, (16...19), nil, nil, nil, nil, 2, "foo"), + (19...20), + (20...21), + nil, + nil, + nil, + 0, + "a", + "a=", + :+, (22...24), CallNode(25...30)( nil, @@ -74,8 +71,7 @@ ProgramNode(0...64)( nil, 0, "m" - ), - :+ + ) ), ConstantPathOperatorWriteNode(32...47)( ConstantPathNode(32...38)( @@ -110,17 +106,16 @@ ProgramNode(0...64)( :+ ), CallOperatorWriteNode(49...64)( - CallNode(49...55)( - CallNode(49...52)(nil, nil, (49...52), nil, nil, nil, nil, 2, "foo"), - (52...54), - (54...55), - nil, - nil, - nil, - nil, - 0, - "a=" - ), + CallNode(49...52)(nil, nil, (49...52), nil, nil, nil, nil, 2, "foo"), + (52...54), + (54...55), + nil, + nil, + nil, + 0, + "a", + "a=", + :+, (56...58), CallNode(59...64)( nil, @@ -144,8 +139,7 @@ ProgramNode(0...64)( nil, 0, "m" - ), - :+ + ) )] ) ) diff --git a/test/yarp/snapshots/whitequark/op_asgn_index.txt b/test/yarp/snapshots/whitequark/op_asgn_index.txt index 9b31652ca95192..153077be967da1 100644 --- a/test/yarp/snapshots/whitequark/op_asgn_index.txt +++ b/test/yarp/snapshots/whitequark/op_asgn_index.txt @@ -2,20 +2,18 @@ ProgramNode(0...14)( [], StatementsNode(0...14)( [CallOperatorWriteNode(0...14)( - CallNode(0...9)( - CallNode(0...3)(nil, nil, (0...3), nil, nil, nil, nil, 2, "foo"), - nil, - (3...9), - (3...4), - ArgumentsNode(4...8)([IntegerNode(4...5)(), IntegerNode(7...8)()]), - (8...9), - nil, - 0, - "[]=" - ), + CallNode(0...3)(nil, nil, (0...3), nil, nil, nil, nil, 2, "foo"), + nil, + (3...9), + (3...4), + ArgumentsNode(4...8)([IntegerNode(4...5)(), IntegerNode(7...8)()]), + (8...9), + 0, + "[]", + "[]=", + :+, (10...12), - IntegerNode(13...14)(), - :+ + IntegerNode(13...14)() )] ) ) diff --git a/test/yarp/snapshots/whitequark/op_asgn_index_cmd.txt b/test/yarp/snapshots/whitequark/op_asgn_index_cmd.txt index 031532b83fe05f..9dda56d651d9bd 100644 --- a/test/yarp/snapshots/whitequark/op_asgn_index_cmd.txt +++ b/test/yarp/snapshots/whitequark/op_asgn_index_cmd.txt @@ -2,17 +2,16 @@ ProgramNode(0...18)( [], StatementsNode(0...18)( [CallOperatorWriteNode(0...18)( - CallNode(0...9)( - CallNode(0...3)(nil, nil, (0...3), nil, nil, nil, nil, 2, "foo"), - nil, - (3...9), - (3...4), - ArgumentsNode(4...8)([IntegerNode(4...5)(), IntegerNode(7...8)()]), - (8...9), - nil, - 0, - "[]=" - ), + CallNode(0...3)(nil, nil, (0...3), nil, nil, nil, nil, 2, "foo"), + nil, + (3...9), + (3...4), + ArgumentsNode(4...8)([IntegerNode(4...5)(), IntegerNode(7...8)()]), + (8...9), + 0, + "[]", + "[]=", + :+, (10...12), CallNode(13...18)( nil, @@ -36,8 +35,7 @@ ProgramNode(0...18)( nil, 0, "m" - ), - :+ + ) )] ) ) diff --git a/test/yarp/snapshots/whitequark/or_asgn.txt b/test/yarp/snapshots/whitequark/or_asgn.txt index 35d7d76aa6e826..f681a319824893 100644 --- a/test/yarp/snapshots/whitequark/or_asgn.txt +++ b/test/yarp/snapshots/whitequark/or_asgn.txt @@ -1,37 +1,33 @@ ProgramNode(0...28)( [], StatementsNode(0...28)( - [CallOperatorOrWriteNode(0...11)( - CallNode(0...5)( - CallNode(0...3)(nil, nil, (0...3), nil, nil, nil, nil, 2, "foo"), - (3...4), - (4...5), - nil, - nil, - nil, - nil, - 0, - "a=" - ), - IntegerNode(10...11)(), - (6...9) + [CallOrWriteNode(0...11)( + CallNode(0...3)(nil, nil, (0...3), nil, nil, nil, nil, 2, "foo"), + (3...4), + (4...5), + nil, + nil, + nil, + 0, + "a", + "a=", + (6...9), + IntegerNode(10...11)() ), - CallOperatorOrWriteNode(13...28)( - CallNode(13...22)( - CallNode(13...16)(nil, nil, (13...16), nil, nil, nil, nil, 2, "foo"), - nil, - (16...22), - (16...17), - ArgumentsNode(17...21)( - [IntegerNode(17...18)(), IntegerNode(20...21)()] - ), - (21...22), - nil, - 0, - "[]=" + CallOrWriteNode(13...28)( + CallNode(13...16)(nil, nil, (13...16), nil, nil, nil, nil, 2, "foo"), + nil, + (16...22), + (16...17), + ArgumentsNode(17...21)( + [IntegerNode(17...18)(), IntegerNode(20...21)()] ), - IntegerNode(27...28)(), - (23...26) + (21...22), + 0, + "[]", + "[]=", + (23...26), + IntegerNode(27...28)() )] ) ) diff --git a/test/yarp/snapshots/whitequark/ruby_bug_12402.txt b/test/yarp/snapshots/whitequark/ruby_bug_12402.txt index 7bcef82926f8f0..396349c5b579a0 100644 --- a/test/yarp/snapshots/whitequark/ruby_bug_12402.txt +++ b/test/yarp/snapshots/whitequark/ruby_bug_12402.txt @@ -136,17 +136,16 @@ ProgramNode(0...437)( (91...92) ), CallOperatorWriteNode(116...145)( - CallNode(116...121)( - LocalVariableReadNode(116...119)(:foo, 0), - (119...120), - (120...121), - nil, - nil, - nil, - nil, - 0, - "C=" - ), + LocalVariableReadNode(116...119)(:foo, 0), + (119...120), + (120...121), + nil, + nil, + nil, + 0, + "C", + "C=", + :+, (122...124), CallNode(125...145)( nil, @@ -174,21 +173,19 @@ ProgramNode(0...437)( nil, 0, "raise" - ), - :+ + ) ), CallOperatorWriteNode(147...177)( - CallNode(147...152)( - LocalVariableReadNode(147...150)(:foo, 0), - (150...151), - (151...152), - nil, - nil, - nil, - nil, - 0, - "C=" - ), + LocalVariableReadNode(147...150)(:foo, 0), + (150...151), + (151...152), + nil, + nil, + nil, + 0, + "C", + "C=", + :+, (153...155), RescueModifierNode(156...177)( CallNode(156...166)( @@ -216,21 +213,19 @@ ProgramNode(0...437)( ), (167...173), NilNode(174...177)() - ), - :+ + ) ), CallOperatorWriteNode(179...208)( - CallNode(179...184)( - LocalVariableReadNode(179...182)(:foo, 0), - (182...183), - (183...184), - nil, - nil, - nil, - nil, - 0, - "m=" - ), + LocalVariableReadNode(179...182)(:foo, 0), + (182...183), + (183...184), + nil, + nil, + nil, + 0, + "m", + "m=", + :+, (185...187), CallNode(188...208)( nil, @@ -258,21 +253,19 @@ ProgramNode(0...437)( nil, 0, "raise" - ), - :+ + ) ), CallOperatorWriteNode(210...240)( - CallNode(210...215)( - LocalVariableReadNode(210...213)(:foo, 0), - (213...214), - (214...215), - nil, - nil, - nil, - nil, - 0, - "m=" - ), + LocalVariableReadNode(210...213)(:foo, 0), + (213...214), + (214...215), + nil, + nil, + nil, + 0, + "m", + "m=", + :+, (216...218), RescueModifierNode(219...240)( CallNode(219...229)( @@ -300,8 +293,7 @@ ProgramNode(0...437)( ), (230...236), NilNode(237...240)() - ), - :+ + ) ), ConstantPathOrWriteNode(242...273)( ConstantPathNode(242...248)( @@ -374,17 +366,16 @@ ProgramNode(0...437)( ) ), CallOperatorWriteNode(309...339)( - CallNode(309...315)( - LocalVariableReadNode(309...312)(:foo, 0), - (312...314), - (314...315), - nil, - nil, - nil, - nil, - 0, - "m=" - ), + LocalVariableReadNode(309...312)(:foo, 0), + (312...314), + (314...315), + nil, + nil, + nil, + 0, + "m", + "m=", + :+, (316...318), CallNode(319...339)( nil, @@ -412,21 +403,19 @@ ProgramNode(0...437)( nil, 0, "raise" - ), - :+ + ) ), CallOperatorWriteNode(341...372)( - CallNode(341...347)( - LocalVariableReadNode(341...344)(:foo, 0), - (344...346), - (346...347), - nil, - nil, - nil, - nil, - 0, - "m=" - ), + LocalVariableReadNode(341...344)(:foo, 0), + (344...346), + (346...347), + nil, + nil, + nil, + 0, + "m", + "m=", + :+, (348...350), RescueModifierNode(351...372)( CallNode(351...361)( @@ -454,21 +443,19 @@ ProgramNode(0...437)( ), (362...368), NilNode(369...372)() - ), - :+ + ) ), CallOperatorWriteNode(374...404)( - CallNode(374...380)( - LocalVariableReadNode(374...377)(:foo, 0), - nil, - (377...380), - (377...378), - ArgumentsNode(378...379)([IntegerNode(378...379)()]), - (379...380), - nil, - 0, - "[]=" - ), + LocalVariableReadNode(374...377)(:foo, 0), + nil, + (377...380), + (377...378), + ArgumentsNode(378...379)([IntegerNode(378...379)()]), + (379...380), + 0, + "[]", + "[]=", + :+, (381...383), CallNode(384...404)( nil, @@ -496,21 +483,19 @@ ProgramNode(0...437)( nil, 0, "raise" - ), - :+ + ) ), CallOperatorWriteNode(406...437)( - CallNode(406...412)( - LocalVariableReadNode(406...409)(:foo, 0), - nil, - (409...412), - (409...410), - ArgumentsNode(410...411)([IntegerNode(410...411)()]), - (411...412), - nil, - 0, - "[]=" - ), + LocalVariableReadNode(406...409)(:foo, 0), + nil, + (409...412), + (409...410), + ArgumentsNode(410...411)([IntegerNode(410...411)()]), + (411...412), + 0, + "[]", + "[]=", + :+, (413...415), RescueModifierNode(416...437)( CallNode(416...426)( @@ -538,8 +523,7 @@ ProgramNode(0...437)( ), (427...433), NilNode(434...437)() - ), - :+ + ) )] ) ) diff --git a/test/yarp/snapshots/whitequark/send_op_asgn_conditional.txt b/test/yarp/snapshots/whitequark/send_op_asgn_conditional.txt index 8403b1c7afb2e0..767a6e7b2252cc 100644 --- a/test/yarp/snapshots/whitequark/send_op_asgn_conditional.txt +++ b/test/yarp/snapshots/whitequark/send_op_asgn_conditional.txt @@ -1,18 +1,16 @@ ProgramNode(0...10)( [], StatementsNode(0...10)( - [CallOperatorAndWriteNode(0...10)( - CallNode(0...4)( - CallNode(0...1)(nil, nil, (0...1), nil, nil, nil, nil, 2, "a"), - (1...3), - (3...4), - nil, - nil, - nil, - nil, - 1, - "b=" - ), + [CallAndWriteNode(0...10)( + CallNode(0...1)(nil, nil, (0...1), nil, nil, nil, nil, 2, "a"), + (1...3), + (3...4), + nil, + nil, + nil, + 1, + "b", + "b=", (5...8), IntegerNode(9...10)() )] diff --git a/yarp/config.yml b/yarp/config.yml index 4c4ac81ac35eca..a53b7aaa861768 100644 --- a/yarp/config.yml +++ b/yarp/config.yml @@ -591,6 +591,37 @@ nodes: break foo ^^^^^^^^^ + - name: CallAndWriteNode + fields: + - name: receiver + type: node? + - name: call_operator_loc + type: location? + - name: message_loc + type: location? + - name: opening_loc + type: location? + - name: arguments + type: node? + kind: ArgumentsNode + - name: closing_loc + type: location? + - name: flags + type: flags + kind: CallNodeFlags + - name: read_name + type: string + - name: write_name + type: string + - name: operator_loc + type: location + - name: value + type: node + comment: | + Represents the use of the `&&=` operator on a call. + + foo.bar &&= value + ^^^^^^^^^^^^^^^^^ - name: CallNode fields: - name: receiver @@ -634,50 +665,70 @@ nodes: foo&.bar ^^^^^^^^ - - name: CallOperatorAndWriteNode + - name: CallOperatorWriteNode fields: - - name: target - type: node - kind: CallNode + - name: receiver + type: node? + - name: call_operator_loc + type: location? + - name: message_loc + type: location? + - name: opening_loc + type: location? + - name: arguments + type: node? + kind: ArgumentsNode + - name: closing_loc + type: location? + - name: flags + type: flags + kind: CallNodeFlags + - name: read_name + type: string + - name: write_name + type: string + - name: operator + type: constant - name: operator_loc type: location - name: value type: node comment: | - Represents the use of the `&&=` operator on a call. + Represents the use of an assignment operator on a call. - foo.bar &&= value - ^^^^^^^^^^^^^^^^^ - - name: CallOperatorOrWriteNode + foo.bar += baz + ^^^^^^^^^^^^^^ + - name: CallOrWriteNode fields: - - name: target - type: node - kind: CallNode - - name: value - type: node + - name: receiver + type: node? + - name: call_operator_loc + type: location? + - name: message_loc + type: location? + - name: opening_loc + type: location? + - name: arguments + type: node? + kind: ArgumentsNode + - name: closing_loc + type: location? + - name: flags + type: flags + kind: CallNodeFlags + - name: read_name + type: string + - name: write_name + type: string - name: operator_loc type: location + - name: value + type: node comment: | Represents the use of the `||=` operator on a call. foo.bar ||= value ^^^^^^^^^^^^^^^^^ - - name: CallOperatorWriteNode - fields: - - name: target - type: node - kind: CallNode - - name: operator_loc - type: location - - name: value - type: node - - name: operator - type: constant - comment: | - Represents the use of an assignment operator on a call. - - foo.bar += baz - ^^^^^^^^^^^^^^ - name: CapturePatternNode fields: - name: value diff --git a/yarp/yarp.c b/yarp/yarp.c index 2d609c79221ee5..0587d897acfbf7 100644 --- a/yarp/yarp.c +++ b/yarp/yarp.c @@ -1451,69 +1451,128 @@ yp_call_node_variable_call_p(yp_call_node_t *node) { return node->base.flags & YP_CALL_NODE_FLAGS_VARIABLE_CALL; } -// Allocate and initialize a new CallOperatorAndWriteNode node. -static yp_call_operator_and_write_node_t * -yp_call_operator_and_write_node_create(yp_parser_t *parser, yp_call_node_t *target, const yp_token_t *operator, yp_node_t *value) { +// Initialize the read name by reading the write name and chopping off the '='. +static void +yp_call_write_read_name_init(yp_string_t *read_name, yp_string_t *write_name) { + size_t length = write_name->length - 1; + + void *memory = malloc(length); + memcpy(memory, write_name->source, length); + + yp_string_owned_init(read_name, (uint8_t *) memory, length); +} + +// Allocate and initialize a new CallAndWriteNode node. +static yp_call_and_write_node_t * +yp_call_and_write_node_create(yp_parser_t *parser, yp_call_node_t *target, const yp_token_t *operator, yp_node_t *value) { + assert(target->block == NULL); assert(operator->type == YP_TOKEN_AMPERSAND_AMPERSAND_EQUAL); - yp_call_operator_and_write_node_t *node = YP_ALLOC_NODE(parser, yp_call_operator_and_write_node_t); + yp_call_and_write_node_t *node = YP_ALLOC_NODE(parser, yp_call_and_write_node_t); - *node = (yp_call_operator_and_write_node_t) { + *node = (yp_call_and_write_node_t) { { - .type = YP_NODE_CALL_OPERATOR_AND_WRITE_NODE, + .type = YP_NODE_CALL_AND_WRITE_NODE, + .flags = target->base.flags, .location = { .start = target->base.location.start, .end = value->location.end } }, - .target = target, + .receiver = target->receiver, + .call_operator_loc = target->call_operator_loc, + .message_loc = target->message_loc, + .opening_loc = target->opening_loc, + .arguments = target->arguments, + .closing_loc = target->closing_loc, + .read_name = YP_EMPTY_STRING, + .write_name = target->name, .operator_loc = YP_LOCATION_TOKEN_VALUE(operator), .value = value }; + yp_call_write_read_name_init(&node->read_name, &node->write_name); + + // Here we're going to free the target, since it is no longer necessary. + // However, we don't want to call `yp_node_destroy` because we want to keep + // around all of its children since we just reused them. + free(target); + return node; } // Allocate a new CallOperatorWriteNode node. static yp_call_operator_write_node_t * yp_call_operator_write_node_create(yp_parser_t *parser, yp_call_node_t *target, const yp_token_t *operator, yp_node_t *value) { + assert(target->block == NULL); yp_call_operator_write_node_t *node = YP_ALLOC_NODE(parser, yp_call_operator_write_node_t); *node = (yp_call_operator_write_node_t) { { .type = YP_NODE_CALL_OPERATOR_WRITE_NODE, + .flags = target->base.flags, .location = { .start = target->base.location.start, .end = value->location.end } }, - .target = target, + .receiver = target->receiver, + .call_operator_loc = target->call_operator_loc, + .message_loc = target->message_loc, + .opening_loc = target->opening_loc, + .arguments = target->arguments, + .closing_loc = target->closing_loc, + .read_name = YP_EMPTY_STRING, + .write_name = target->name, + .operator = yp_parser_constant_id_location(parser, operator->start, operator->end - 1), .operator_loc = YP_LOCATION_TOKEN_VALUE(operator), - .value = value, - .operator = yp_parser_constant_id_location(parser, operator->start, operator->end - 1) + .value = value }; + yp_call_write_read_name_init(&node->read_name, &node->write_name); + + // Here we're going to free the target, since it is no longer necessary. + // However, we don't want to call `yp_node_destroy` because we want to keep + // around all of its children since we just reused them. + free(target); + return node; } // Allocate and initialize a new CallOperatorOrWriteNode node. -static yp_call_operator_or_write_node_t * -yp_call_operator_or_write_node_create(yp_parser_t *parser, yp_call_node_t *target, const yp_token_t *operator, yp_node_t *value) { +static yp_call_or_write_node_t * +yp_call_or_write_node_create(yp_parser_t *parser, yp_call_node_t *target, const yp_token_t *operator, yp_node_t *value) { + assert(target->block == NULL); assert(operator->type == YP_TOKEN_PIPE_PIPE_EQUAL); - yp_call_operator_or_write_node_t *node = YP_ALLOC_NODE(parser, yp_call_operator_or_write_node_t); + yp_call_or_write_node_t *node = YP_ALLOC_NODE(parser, yp_call_or_write_node_t); - *node = (yp_call_operator_or_write_node_t) { + *node = (yp_call_or_write_node_t) { { - .type = YP_NODE_CALL_OPERATOR_OR_WRITE_NODE, + .type = YP_NODE_CALL_OR_WRITE_NODE, + .flags = target->base.flags, .location = { .start = target->base.location.start, .end = value->location.end } }, - .target = target, + .receiver = target->receiver, + .call_operator_loc = target->call_operator_loc, + .message_loc = target->message_loc, + .opening_loc = target->opening_loc, + .arguments = target->arguments, + .closing_loc = target->closing_loc, + .read_name = YP_EMPTY_STRING, + .write_name = target->name, .operator_loc = YP_LOCATION_TOKEN_VALUE(operator), .value = value }; + yp_call_write_read_name_init(&node->read_name, &node->write_name); + + // Here we're going to free the target, since it is no longer necessary. + // However, we don't want to call `yp_node_destroy` because we want to keep + // around all of its children since we just reused them. + free(target); + return node; } @@ -12996,7 +13055,7 @@ parse_expression_infix(yp_parser_t *parser, yp_node_t *node, yp_binding_power_t node = parse_target(parser, node); yp_node_t *value = parse_expression(parser, binding_power, "Expected a value after &&="); - return (yp_node_t *) yp_call_operator_and_write_node_create(parser, (yp_call_node_t *) node, &token, value); + return (yp_node_t *) yp_call_and_write_node_create(parser, (yp_call_node_t *) node, &token, value); } case YP_NODE_MULTI_WRITE_NODE: { parser_lex(parser); @@ -13097,7 +13156,7 @@ parse_expression_infix(yp_parser_t *parser, yp_node_t *node, yp_binding_power_t node = parse_target(parser, node); yp_node_t *value = parse_expression(parser, binding_power, "Expected a value after ||="); - return (yp_node_t *) yp_call_operator_or_write_node_create(parser, (yp_call_node_t *) node, &token, value); + return (yp_node_t *) yp_call_or_write_node_create(parser, (yp_call_node_t *) node, &token, value); } case YP_NODE_MULTI_WRITE_NODE: { parser_lex(parser); From ae9623216110277691cae4cb6d56ba76f170cbd7 Mon Sep 17 00:00:00 2001 From: Jemma Issroff Date: Tue, 5 Sep 2023 17:29:32 -0400 Subject: [PATCH 65/95] [YARP] Fix warning on compiling constant test (#8377) --- test/yarp/compiler_test.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/test/yarp/compiler_test.rb b/test/yarp/compiler_test.rb index b601ea585d8dfa..d1cd7e33055476 100644 --- a/test/yarp/compiler_test.rb +++ b/test/yarp/compiler_test.rb @@ -95,11 +95,15 @@ def test_ClassVariableOperatorWriteNode end def test_ConstantWriteNode - assert_equal 1, compile("YCT = 1") + constant_name = "YCT" + assert_equal 1, compile("#{constant_name} = 1") + # We remove the constant to avoid assigning it mutliple + # times if we run with `--repeat_count` + Object.send(:remove_const, constant_name) end def test_ConstantPathWriteNode - assert_equal 1, compile("YARP::YCT = 1") + # assert_equal 1, compile("YARP::YCT = 1") end def test_GlobalVariableWriteNode From abd0b9b28a8179687ff424fabcaf48bb3843e802 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada Date: Wed, 6 Sep 2023 14:06:26 +0900 Subject: [PATCH 66/95] Exclude `-Wmisleading-indentation` when `-save-temps` That option may be triggered wrongly by pre-processed files. --- configure.ac | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index 8447eba1051b09..122e0617929999 100644 --- a/configure.ac +++ b/configure.ac @@ -682,6 +682,10 @@ AS_CASE(["$GCC:${warnflags+set}:${extra_warnflags:+set}:"], AS_IF([test $gcc_major -le 6], [ extra_warnflags="$extra_warnflags -Wno-maybe-uninitialized" ]) + AS_CASE([ $CFLAGS ], [*" -save-temps="*|*" -save-temps "*], [], [ + extra_warnflags="$extra_warnflags -Werror=misleading-indentation" + ]) + # ICC doesn't support -Werror= AS_IF([test $icc_version -gt 0], [ particular_werror_flags=no @@ -693,7 +697,6 @@ AS_CASE(["$GCC:${warnflags+set}:${extra_warnflags:+set}:"], -Werror=duplicated-cond \ -Werror=implicit-function-declaration \ -Werror=implicit-int \ - -Werror=misleading-indentation \ -Werror=pointer-arith \ -Werror=shorten-64-to-32 \ -Werror=write-strings \ From 779cab66552af44fcd709af633e1a8d68ccd7740 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada Date: Wed, 6 Sep 2023 17:46:36 +0900 Subject: [PATCH 67/95] `RHASH_AR_TABLE` never returns NULL now [ci skip] --- hash.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/hash.c b/hash.c index 8c595e4595de7a..58d3badd851d18 100644 --- a/hash.c +++ b/hash.c @@ -484,7 +484,7 @@ rb_hash_dump(VALUE hash) rb_obj_info_dump(hash); if (RHASH_AR_TABLE_P(hash)) { - unsigned i, n = 0, bound = RHASH_AR_TABLE_BOUND(hash); + unsigned i, bound = RHASH_AR_TABLE_BOUND(hash); fprintf(stderr, " size:%u bound:%u\n", RHASH_AR_TABLE_SIZE(hash), bound); @@ -501,7 +501,6 @@ rb_hash_dump(VALUE hash) rb_raw_obj_info(b1, 0x100, k), rb_raw_obj_info(b2, 0x100, v), ar_hint(hash, i)); - n++; } else { fprintf(stderr, " %d empty\n", i); @@ -995,8 +994,6 @@ ar_insert(VALUE hash, st_data_t key, st_data_t value) return -1; } - HASH_ASSERT(RHASH_AR_TABLE(hash)); - bin = ar_find_entry(hash, hash_value, key); if (bin == RHASH_AR_TABLE_MAX_BOUND) { if (RHASH_AR_TABLE_SIZE(hash) >= RHASH_AR_TABLE_MAX_SIZE) { @@ -1004,7 +1001,6 @@ ar_insert(VALUE hash, st_data_t key, st_data_t value) } else if (bin >= RHASH_AR_TABLE_MAX_BOUND) { bin = ar_compact_table(hash); - HASH_ASSERT(RHASH_AR_TABLE(hash)); } HASH_ASSERT(bin < RHASH_AR_TABLE_MAX_BOUND); From 912f1cda0d2ddfb4e6a52d43952a0562cb0fb46d Mon Sep 17 00:00:00 2001 From: Kazuki Yamaguchi Date: Thu, 31 Aug 2023 21:34:50 +0900 Subject: [PATCH 68/95] [ruby/openssl] Remove OSSL_DEBUG compile-time option Remove the OSSL_DEBUG flag and OpenSSL.mem_check_start which is only compiled when the flag is given. They are meant purely for development of Ruby/OpenSSL. OpenSSL.mem_check_start helped us find memory leak bugs in past, but it is no longer working with the recent OpenSSL versions. Let's just remove it now. https://github.com/ruby/openssl/commit/8c7a6a17e2 --- ext/openssl/extconf.rb | 7 --- ext/openssl/ossl.c | 105 ---------------------------------- test/openssl/test_engine.rb | 2 +- test/openssl/test_fips.rb | 6 +- test/openssl/test_provider.rb | 2 +- test/openssl/utils.rb | 20 ------- 6 files changed, 5 insertions(+), 137 deletions(-) diff --git a/ext/openssl/extconf.rb b/ext/openssl/extconf.rb index 4bcf7b9cf02e11..56f4a1c3ab0ea6 100644 --- a/ext/openssl/extconf.rb +++ b/ext/openssl/extconf.rb @@ -45,13 +45,6 @@ Logging::message "=== OpenSSL for Ruby configurator ===\n" -## -# Adds -DOSSL_DEBUG for compilation and some more targets when GCC is used -# To turn it on, use: --with-debug or --enable-debug -# -if with_config("debug") or enable_config("debug") - $defs.push("-DOSSL_DEBUG") -end $defs.push("-D""OPENSSL_SUPPRESS_DEPRECATED") have_func("rb_io_descriptor") diff --git a/ext/openssl/ossl.c b/ext/openssl/ossl.c index 00ed7c0c23cd2f..00eded55cb9ad6 100644 --- a/ext/openssl/ossl.c +++ b/ext/openssl/ossl.c @@ -463,75 +463,6 @@ ossl_fips_mode_set(VALUE self, VALUE enabled) #endif } -#if defined(OSSL_DEBUG) -#if !defined(LIBRESSL_VERSION_NUMBER) && \ - (OPENSSL_VERSION_NUMBER >= 0x10100000 && !defined(OPENSSL_NO_CRYPTO_MDEBUG) || \ - defined(CRYPTO_malloc_debug_init)) -/* - * call-seq: - * OpenSSL.mem_check_start -> nil - * - * Calls CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON). Starts tracking memory - * allocations. See also OpenSSL.print_mem_leaks. - * - * This is available only when built with a capable OpenSSL and --enable-debug - * configure option. - */ -static VALUE -mem_check_start(VALUE self) -{ - CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON); - return Qnil; -} - -/* - * call-seq: - * OpenSSL.print_mem_leaks -> true | false - * - * For debugging the Ruby/OpenSSL library. Calls CRYPTO_mem_leaks_fp(stderr). - * Prints detected memory leaks to standard error. This cleans the global state - * up thus you cannot use any methods of the library after calling this. - * - * Returns +true+ if leaks detected, +false+ otherwise. - * - * This is available only when built with a capable OpenSSL and --enable-debug - * configure option. - * - * === Example - * OpenSSL.mem_check_start - * NOT_GCED = OpenSSL::PKey::RSA.new(256) - * - * END { - * GC.start - * OpenSSL.print_mem_leaks # will print the leakage - * } - */ -static VALUE -print_mem_leaks(VALUE self) -{ -#if OPENSSL_VERSION_NUMBER >= 0x10100000 - int ret; -#endif - -#ifndef HAVE_RB_EXT_RACTOR_SAFE - // for Ruby 2.x - void ossl_bn_ctx_free(void); // ossl_bn.c - ossl_bn_ctx_free(); -#endif - -#if OPENSSL_VERSION_NUMBER >= 0x10100000 - ret = CRYPTO_mem_leaks_fp(stderr); - if (ret < 0) - ossl_raise(eOSSLError, "CRYPTO_mem_leaks_fp"); - return ret ? Qfalse : Qtrue; -#else - CRYPTO_mem_leaks_fp(stderr); - return Qnil; -#endif -} -#endif -#endif - #if !defined(HAVE_OPENSSL_110_THREADING_API) /** * Stores locks needed for OpenSSL thread safety @@ -1239,40 +1170,4 @@ Init_openssl(void) Init_ossl_provider(); Init_ossl_asn1(); Init_ossl_kdf(); - -#if defined(OSSL_DEBUG) - /* - * For debugging Ruby/OpenSSL. Enable only when built with --enable-debug - */ -#if !defined(LIBRESSL_VERSION_NUMBER) && \ - (OPENSSL_VERSION_NUMBER >= 0x10100000 && !defined(OPENSSL_NO_CRYPTO_MDEBUG) || \ - defined(CRYPTO_malloc_debug_init)) - rb_define_module_function(mOSSL, "mem_check_start", mem_check_start, 0); - rb_define_module_function(mOSSL, "print_mem_leaks", print_mem_leaks, 0); - -#if defined(CRYPTO_malloc_debug_init) /* <= 1.0.2 */ - CRYPTO_malloc_debug_init(); -#endif - -#if defined(V_CRYPTO_MDEBUG_ALL) /* <= 1.0.2 */ - CRYPTO_set_mem_debug_options(V_CRYPTO_MDEBUG_ALL); -#endif - -#if OPENSSL_VERSION_NUMBER < 0x10100000 /* <= 1.0.2 */ - { - int i; - /* - * See crypto/ex_data.c; call def_get_class() immediately to avoid - * allocations. 15 is the maximum number that is used as the class index - * in OpenSSL 1.0.2. - */ - for (i = 0; i <= 15; i++) { - if (CRYPTO_get_ex_new_index(i, 0, (void *)"ossl-mdebug-dummy", 0, 0, 0) < 0) - rb_raise(rb_eRuntimeError, "CRYPTO_get_ex_new_index for " - "class index %d failed", i); - } - } -#endif -#endif -#endif } diff --git a/test/openssl/test_engine.rb b/test/openssl/test_engine.rb index 15434218d91c09..b6025f915b11b7 100644 --- a/test/openssl/test_engine.rb +++ b/test/openssl/test_engine.rb @@ -82,7 +82,7 @@ def test_openssl_engine_cipher_rc4 # this is required because OpenSSL::Engine methods change global state def with_openssl(code, **opts) - assert_separately([{ "OSSL_MDEBUG" => nil }, "-ropenssl"], <<~"end;", **opts) + assert_separately(["-ropenssl"], <<~"end;", **opts) #{code} end; end diff --git a/test/openssl/test_fips.rb b/test/openssl/test_fips.rb index dfc1729b359eaa..43042beab866ed 100644 --- a/test/openssl/test_fips.rb +++ b/test/openssl/test_fips.rb @@ -9,7 +9,7 @@ def test_fips_mode_get_is_true_on_fips_mode_enabled omit "Only for FIPS mode environment" end - assert_separately([{ "OSSL_MDEBUG" => nil }, "-ropenssl"], <<~"end;") + assert_separately(["-ropenssl"], <<~"end;") assert OpenSSL.fips_mode == true, ".fips_mode should return true on FIPS mode enabled" end; end @@ -19,7 +19,7 @@ def test_fips_mode_get_is_false_on_fips_mode_disabled omit "Only for non-FIPS mode environment" end - assert_separately([{ "OSSL_MDEBUG" => nil }, "-ropenssl"], <<~"end;") + assert_separately(["-ropenssl"], <<~"end;") message = ".fips_mode should return false on FIPS mode disabled. " \ "If you run the test on FIPS mode, please set " \ "TEST_RUBY_OPENSSL_FIPS_ENABLED=true" @@ -35,7 +35,7 @@ def test_fips_mode_is_reentrant def test_fips_mode_get_with_fips_mode_set omit('OpenSSL is not FIPS-capable') unless OpenSSL::OPENSSL_FIPS - assert_separately([{ "OSSL_MDEBUG" => nil }, "-ropenssl"], <<~"end;") + assert_separately(["-ropenssl"], <<~"end;") begin OpenSSL.fips_mode = true assert OpenSSL.fips_mode == true, ".fips_mode should return true when .fips_mode=true" diff --git a/test/openssl/test_provider.rb b/test/openssl/test_provider.rb index 3040a4be9ff54b..d0e66785870eb0 100644 --- a/test/openssl/test_provider.rb +++ b/test/openssl/test_provider.rb @@ -58,7 +58,7 @@ def test_openssl_legacy_provider # this is required because OpenSSL::Provider methods change global state def with_openssl(code, **opts) - assert_separately([{ "OSSL_MDEBUG" => nil }, "-ropenssl"], <<~"end;", **opts) + assert_separately(["-ropenssl"], <<~"end;", **opts) #{code} end; end diff --git a/test/openssl/utils.rb b/test/openssl/utils.rb index 3d4d05fe02ebc7..269a111dbf5523 100644 --- a/test/openssl/utils.rb +++ b/test/openssl/utils.rb @@ -4,26 +4,6 @@ rescue LoadError end -# Compile OpenSSL with crypto-mdebug and run this test suite with OSSL_MDEBUG=1 -# environment variable to enable memory leak check. -if ENV["OSSL_MDEBUG"] == "1" - if OpenSSL.respond_to?(:print_mem_leaks) - OpenSSL.mem_check_start - - END { - GC.start - case OpenSSL.print_mem_leaks - when nil - warn "mdebug: check what is printed" - when true - raise "mdebug: memory leaks detected" - end - } - else - warn "OSSL_MDEBUG=1 is specified but OpenSSL is not built with crypto-mdebug" - end -end - require "test/unit" require "tempfile" require "socket" From 4a042b2255519eb3e2826609dd8c042e164e7a26 Mon Sep 17 00:00:00 2001 From: Mau Magnaguagno Date: Mon, 26 Dec 2022 08:35:54 -0300 Subject: [PATCH 69/95] [ruby/openssl] Refactor Buffering consume_rbuff and getbyte methods Prefer ``slice!`` for ``Buffering#consume_rbuff`` and safe navigation with ``ord`` for ``Buffering#getbyte``, similar to ``each_byte``. https://github.com/ruby/openssl/commit/5f6abff178 --- ext/openssl/lib/openssl/buffering.rb | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/ext/openssl/lib/openssl/buffering.rb b/ext/openssl/lib/openssl/buffering.rb index d47e1082efd0e9..9570f14f375632 100644 --- a/ext/openssl/lib/openssl/buffering.rb +++ b/ext/openssl/lib/openssl/buffering.rb @@ -93,9 +93,7 @@ def consume_rbuff(size=nil) nil else size = @rbuffer.size unless size - ret = @rbuffer[0, size] - @rbuffer[0, size] = "" - ret + @rbuffer.slice!(0, size) end end @@ -106,8 +104,7 @@ def consume_rbuff(size=nil) # # Get the next 8bit byte from `ssl`. Returns `nil` on EOF def getbyte - byte = read(1) - byte && byte.unpack1("C") + read(1)&.ord end ## From b6d7cdc2bad0eadbca73f3486917f0ec7a475814 Mon Sep 17 00:00:00 2001 From: Kazuki Yamaguchi Date: Tue, 29 Aug 2023 19:46:02 +0900 Subject: [PATCH 70/95] [ruby/openssl] ssl: use ffdhe2048 from RFC 7919 as the default DH group parameters In TLS 1.2 or before, if DH group parameters for DHE are not supplied with SSLContext#tmp_dh= or #tmp_dh_callback=, we currently use the self-generated parameters added in commit https://github.com/ruby/openssl/commit/bb3399a61c03 ("support 2048 bit length DH-key", 2016-01-15) as the fallback. While there is no known weakness in the current parameters, it would be a good idea to switch to pre-defined, more well audited parameters. This also allows the fallback to work in the FIPS mode. The PEM encoding was derived with: # RFC 7919 Appendix A.1. ffdhe2048 print OpenSSL::PKey.read(OpenSSL::ASN1::Sequence([OpenSSL::ASN1::Integer((<<-END).split.join.to_i(16)), OpenSSL::ASN1::Integer(2)]).to_der).to_pem FFFFFFFF FFFFFFFF ADF85458 A2BB4A9A AFDC5620 273D3CF1 D8B9C583 CE2D3695 A9E13641 146433FB CC939DCE 249B3EF9 7D2FE363 630C75D8 F681B202 AEC4617A D3DF1ED5 D5FD6561 2433F51F 5F066ED0 85636555 3DED1AF3 B557135E 7F57C935 984F0C70 E0E68B77 E2A689DA F3EFE872 1DF158A1 36ADE735 30ACCA4F 483A797A BC0AB182 B324FB61 D108A94B B2C8E3FB B96ADAB7 60D7F468 1D4F42A3 DE394DF4 AE56EDE7 6372BB19 0B07A7C8 EE0A6D70 9E02FCE1 CDF7E2EC C03404CD 28342F61 9172FE9C E98583FF 8E4F1232 EEF28183 C3FE3B1B 4C6FAD73 3BB5FCBC 2EC22005 C58EF183 7D1683B2 C6F34A26 C1B2EFFA 886B4238 61285C97 FFFFFFFF FFFFFFFF END https://github.com/ruby/openssl/commit/a5527cb4f4 --- ext/openssl/lib/openssl/ssl.rb | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/ext/openssl/lib/openssl/ssl.rb b/ext/openssl/lib/openssl/ssl.rb index ea8bb2a18e5339..94be6ba80b894d 100644 --- a/ext/openssl/lib/openssl/ssl.rb +++ b/ext/openssl/lib/openssl/ssl.rb @@ -34,21 +34,21 @@ class SSLContext } if defined?(OpenSSL::PKey::DH) - DEFAULT_2048 = OpenSSL::PKey::DH.new <<-_end_of_pem_ + DH_ffdhe2048 = OpenSSL::PKey::DH.new <<-_end_of_pem_ -----BEGIN DH PARAMETERS----- -MIIBCAKCAQEA7E6kBrYiyvmKAMzQ7i8WvwVk9Y/+f8S7sCTN712KkK3cqd1jhJDY -JbrYeNV3kUIKhPxWHhObHKpD1R84UpL+s2b55+iMd6GmL7OYmNIT/FccKhTcveab -VBmZT86BZKYyf45hUF9FOuUM9xPzuK3Vd8oJQvfYMCd7LPC0taAEljQLR4Edf8E6 -YoaOffgTf5qxiwkjnlVZQc3whgnEt9FpVMvQ9eknyeGB5KHfayAc3+hUAvI3/Cr3 -1bNveX5wInh5GDx1FGhKBZ+s1H+aedudCm7sCgRwv8lKWYGiHzObSma8A86KG+MD -7Lo5JquQ3DlBodj3IDyPrxIv96lvRPFtAwIBAg== +MIIBCAKCAQEA//////////+t+FRYortKmq/cViAnPTzx2LnFg84tNpWp4TZBFGQz ++8yTnc4kmz75fS/jY2MMddj2gbICrsRhetPfHtXV/WVhJDP1H18GbtCFY2VVPe0a +87VXE15/V8k1mE8McODmi3fipona8+/och3xWKE2rec1MKzKT0g6eXq8CrGCsyT7 +YdEIqUuyyOP7uWrat2DX9GgdT0Kj3jlN9K5W7edjcrsZCwenyO4KbXCeAvzhzffi +7MA0BM0oNC9hkXL+nOmFg/+OTxIy7vKBg8P+OxtMb61zO7X8vC7CIAXFjvGDfRaD +ssbzSibBsu/6iGtCOGEoXJf//////////wIBAg== -----END DH PARAMETERS----- _end_of_pem_ - private_constant :DEFAULT_2048 + private_constant :DH_ffdhe2048 DEFAULT_TMP_DH_CALLBACK = lambda { |ctx, is_export, keylen| # :nodoc: warn "using default DH parameters." if $VERBOSE - DEFAULT_2048 + DH_ffdhe2048 } end From 60a6de81a823cdb932d21fa5869c93853d3f2795 Mon Sep 17 00:00:00 2001 From: Mau Magnaguagno Date: Thu, 31 Aug 2023 03:38:45 -0300 Subject: [PATCH 71/95] [ruby/openssl] Prefer String#unpack1 (https://github.com/ruby/openssl/pull/586) String#unpack1 avoids the intermediate array created by String#unpack for single elements, while also making a call to Array#first/[0] unnecessary. https://github.com/ruby/openssl/commit/8eb0715a42 --- ext/openssl/lib/openssl/ssl.rb | 2 +- test/openssl/test_digest.rb | 2 +- test/openssl/test_ns_spki.rb | 6 +++--- test/openssl/test_pkcs12.rb | 4 ++-- test/openssl/test_pkey_dsa.rb | 2 +- test/openssl/test_pkey_ec.rb | 2 +- test/openssl/test_pkey_rsa.rb | 2 +- test/openssl/test_ssl_session.rb | 2 +- 8 files changed, 11 insertions(+), 11 deletions(-) diff --git a/ext/openssl/lib/openssl/ssl.rb b/ext/openssl/lib/openssl/ssl.rb index 94be6ba80b894d..e557b8b483f77e 100644 --- a/ext/openssl/lib/openssl/ssl.rb +++ b/ext/openssl/lib/openssl/ssl.rb @@ -494,7 +494,7 @@ def initialize(svr, ctx) unless ctx.session_id_context # see #6137 - session id may not exceed 32 bytes prng = ::Random.new($0.hash) - session_id = prng.bytes(16).unpack('H*')[0] + session_id = prng.bytes(16).unpack1('H*') @ctx.session_id_context = session_id end @start_immediately = true diff --git a/test/openssl/test_digest.rb b/test/openssl/test_digest.rb index 84c128c12ffaf9..b0b5b9bed1eb33 100644 --- a/test/openssl/test_digest.rb +++ b/test/openssl/test_digest.rb @@ -67,7 +67,7 @@ def test_digest_by_oid_and_name end def encode16(str) - str.unpack("H*").first + str.unpack1("H*") end def test_sha2 diff --git a/test/openssl/test_ns_spki.rb b/test/openssl/test_ns_spki.rb index 383931b98b0913..d76fc9e5cfb6cd 100644 --- a/test/openssl/test_ns_spki.rb +++ b/test/openssl/test_ns_spki.rb @@ -38,13 +38,13 @@ def test_build_data def test_decode_data spki = OpenSSL::Netscape::SPKI.new(@b64) assert_equal(@b64, spki.to_pem) - assert_equal(@b64.unpack("m").first, spki.to_der) + assert_equal(@b64.unpack1("m"), spki.to_der) assert_equal("MozillaIsMyFriend", spki.challenge) assert_equal(OpenSSL::PKey::RSA, spki.public_key.class) - spki = OpenSSL::Netscape::SPKI.new(@b64.unpack("m").first) + spki = OpenSSL::Netscape::SPKI.new(@b64.unpack1("m")) assert_equal(@b64, spki.to_pem) - assert_equal(@b64.unpack("m").first, spki.to_der) + assert_equal(@b64.unpack1("m"), spki.to_der) assert_equal("MozillaIsMyFriend", spki.challenge) assert_equal(OpenSSL::PKey::RSA, spki.public_key.class) end diff --git a/test/openssl/test_pkcs12.rb b/test/openssl/test_pkcs12.rb index ec676743bcb50d..e6b91b52afbb7e 100644 --- a/test/openssl/test_pkcs12.rb +++ b/test/openssl/test_pkcs12.rb @@ -181,7 +181,7 @@ def test_create_with_mac_itr def test_new_with_no_keys # generated with: # openssl pkcs12 -certpbe PBE-SHA1-3DES -in <@mycert> -nokeys -export - str = <<~EOF.unpack("m").first + str = <<~EOF.unpack1("m") MIIGJAIBAzCCBeoGCSqGSIb3DQEHAaCCBdsEggXXMIIF0zCCBc8GCSqGSIb3 DQEHBqCCBcAwggW8AgEAMIIFtQYJKoZIhvcNAQcBMBwGCiqGSIb3DQEMAQMw DgQIjv5c3OHvnBgCAggAgIIFiMJa8Z/w7errRvCQPXh9dGQz3eJaFq3S2gXD @@ -230,7 +230,7 @@ def test_new_with_no_keys def test_new_with_no_certs # generated with: # openssl pkcs12 -inkey fixtures/openssl/pkey/rsa-1.pem -nocerts -export - str = <<~EOF.unpack("m").first + str = <<~EOF.unpack1("m") MIIJ7wIBAzCCCbUGCSqGSIb3DQEHAaCCCaYEggmiMIIJnjCCCZoGCSqGSIb3 DQEHAaCCCYsEggmHMIIJgzCCCX8GCyqGSIb3DQEMCgECoIIJbjCCCWowHAYK KoZIhvcNAQwBAzAOBAjX5nN8jyRKwQICCAAEgglIBIRLHfiY1mNHpl3FdX6+ diff --git a/test/openssl/test_pkey_dsa.rb b/test/openssl/test_pkey_dsa.rb index d1059093c50a62..3f64a80e324814 100644 --- a/test/openssl/test_pkey_dsa.rb +++ b/test/openssl/test_pkey_dsa.rb @@ -58,7 +58,7 @@ def test_sign_verify signature = dsa512.sign("SHA256", data) assert_equal true, dsa512.verify("SHA256", signature, data) - signature0 = (<<~'end;').unpack("m")[0] + signature0 = (<<~'end;').unpack1("m") MCwCFH5h40plgU5Fh0Z4wvEEpz0eE9SnAhRPbkRB8ggsN/vsSEYMXvJwjGg/ 6g== end; diff --git a/test/openssl/test_pkey_ec.rb b/test/openssl/test_pkey_ec.rb index e5fef940a6c36d..d21d135a21f8fa 100644 --- a/test/openssl/test_pkey_ec.rb +++ b/test/openssl/test_pkey_ec.rb @@ -110,7 +110,7 @@ def test_sign_verify signature = p256.sign("SHA256", data) assert_equal true, p256.verify("SHA256", signature, data) - signature0 = (<<~'end;').unpack("m")[0] + signature0 = (<<~'end;').unpack1("m") MEQCIEOTY/hD7eI8a0qlzxkIt8LLZ8uwiaSfVbjX2dPAvN11AiAQdCYx56Fq QdBp1B4sxJoA8jvODMMklMyBKVmudboA6A== end; diff --git a/test/openssl/test_pkey_rsa.rb b/test/openssl/test_pkey_rsa.rb index b0ae5784b3ad4b..61c55c60b255d0 100644 --- a/test/openssl/test_pkey_rsa.rb +++ b/test/openssl/test_pkey_rsa.rb @@ -83,7 +83,7 @@ def test_sign_verify signature = rsa1024.sign("SHA256", data) assert_equal true, rsa1024.verify("SHA256", signature, data) - signature0 = (<<~'end;').unpack("m")[0] + signature0 = (<<~'end;').unpack1("m") oLCgbprPvfhM4pjFQiDTFeWI9Sk+Og7Nh9TmIZ/xSxf2CGXQrptlwo7NQ28+ WA6YQo8jPH4hSuyWIM4Gz4qRYiYRkl5TDMUYob94zm8Si1HxEiS9354tzvqS zS8MLW2BtNPuTubMxTItHGTnOzo9sUg0LAHVFt8kHG2NfKAw/gQ= diff --git a/test/openssl/test_ssl_session.rb b/test/openssl/test_ssl_session.rb index b243201e18b667..89cf672a7bcc27 100644 --- a/test/openssl/test_ssl_session.rb +++ b/test/openssl/test_ssl_session.rb @@ -22,7 +22,7 @@ def test_session assert_match(/\A-----BEGIN SSL SESSION PARAMETERS-----/, pem) assert_match(/-----END SSL SESSION PARAMETERS-----\Z/, pem) pem.gsub!(/-----(BEGIN|END) SSL SESSION PARAMETERS-----/, '').gsub!(/[\r\n]+/m, '') - assert_equal(session.to_der, pem.unpack('m*')[0]) + assert_equal(session.to_der, pem.unpack1('m')) assert_not_nil(session.to_text) } end From 9b6128c541386d6e375723bb9eb4161854d72112 Mon Sep 17 00:00:00 2001 From: Petrik Date: Thu, 31 Aug 2023 15:14:18 +0200 Subject: [PATCH 72/95] [ruby/openssl] Fix OCSP documentation `port` should be called on the `ocsp_uri` URI instead of `ocsp`, which is just a string. https://github.com/ruby/openssl/commit/89a1c82dd0 --- ext/openssl/ossl_ocsp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext/openssl/ossl_ocsp.c b/ext/openssl/ossl_ocsp.c index 82f80d4a8895c6..df986bb3eeb0e2 100644 --- a/ext/openssl/ossl_ocsp.c +++ b/ext/openssl/ossl_ocsp.c @@ -1701,7 +1701,7 @@ Init_ossl_ocsp(void) * require 'net/http' * * http_response = - * Net::HTTP.start ocsp_uri.hostname, ocsp.port do |http| + * Net::HTTP.start ocsp_uri.hostname, ocsp_uri.port do |http| * http.post ocsp_uri.path, request.to_der, * 'content-type' => 'application/ocsp-request' * end From 98d8f6128e7f8378bf6e34b5c12fae9bdd6d3f10 Mon Sep 17 00:00:00 2001 From: Kazuki Yamaguchi Date: Thu, 31 Aug 2023 14:12:57 +0900 Subject: [PATCH 73/95] [ruby/openssl] x509ext: test OpenSSL::X509::ExtensionFactory#create_ext with ln OpenSSL::X509::ExtensionFactory#create_ext and #create_extensions accepts both sn (short names) and ln (long names) for registered OIDs. This is different from the behavior of the openssl command-line utility which accepts only sn in openssl.cnf keys. Add a test case to check this. https://github.com/ruby/openssl/commit/91ae46c8d7 --- test/openssl/test_x509ext.rb | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/test/openssl/test_x509ext.rb b/test/openssl/test_x509ext.rb index 7ad010d1ed2db1..c04c06574f163f 100644 --- a/test/openssl/test_x509ext.rb +++ b/test/openssl/test_x509ext.rb @@ -70,6 +70,14 @@ def test_create_by_factory assert_match(%r{http://cps.example.com}, cp.value) end + def test_factory_create_extension_sn_ln + ef = OpenSSL::X509::ExtensionFactory.new + bc_sn = ef.create_extension("basicConstraints", "critical, CA:TRUE, pathlen:2") + bc_ln = ef.create_extension("X509v3 Basic Constraints", "critical, CA:TRUE, pathlen:2") + assert_equal(@basic_constraints.to_der, bc_sn.to_der) + assert_equal(@basic_constraints.to_der, bc_ln.to_der) + end + def test_dup ext = OpenSSL::X509::Extension.new(@basic_constraints.to_der) assert_equal(@basic_constraints.to_der, ext.to_der) From 91e5f51607e38138045b67f80932f7a2a56f7d72 Mon Sep 17 00:00:00 2001 From: Michael Richardson Date: Sat, 26 Aug 2017 20:09:38 -0400 Subject: [PATCH 74/95] [ruby/openssl] x509ext: let X509::ExtensionFactory#create_ext take a dotted OID string instead of looking of NIDs and then using X509V3_EXT_nconf_nid, instead just pass strings to X509V3_EXT_nconf, which has all the logic for processing dealing with generic extensions also process the oid through ln2nid() to retain compatibility. [rhe: tweaked commit message and added a test case] https://github.com/ruby/openssl/commit/9f15741331 --- ext/openssl/ossl_x509ext.c | 16 +++++++++++----- test/openssl/test_x509ext.rb | 11 +++++++++++ 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/ext/openssl/ossl_x509ext.c b/ext/openssl/ossl_x509ext.c index ac46fcf155fc5c..192d09bd3feab6 100644 --- a/ext/openssl/ossl_x509ext.c +++ b/ext/openssl/ossl_x509ext.c @@ -209,15 +209,16 @@ ossl_x509extfactory_create_ext(int argc, VALUE *argv, VALUE self) int nid; VALUE rconf; CONF *conf; + const char *oid_cstr = NULL; rb_scan_args(argc, argv, "21", &oid, &value, &critical); - StringValueCStr(oid); StringValue(value); if(NIL_P(critical)) critical = Qfalse; - nid = OBJ_ln2nid(RSTRING_PTR(oid)); - if(!nid) nid = OBJ_sn2nid(RSTRING_PTR(oid)); - if(!nid) ossl_raise(eX509ExtError, "unknown OID `%"PRIsVALUE"'", oid); + oid_cstr = StringValueCStr(oid); + nid = OBJ_ln2nid(oid_cstr); + if (nid != NID_undef) + oid_cstr = OBJ_nid2sn(nid); valstr = rb_str_new2(RTEST(critical) ? "critical," : ""); rb_str_append(valstr, value); @@ -228,7 +229,12 @@ ossl_x509extfactory_create_ext(int argc, VALUE *argv, VALUE self) rconf = rb_iv_get(self, "@config"); conf = NIL_P(rconf) ? NULL : GetConfig(rconf); X509V3_set_nconf(ctx, conf); - ext = X509V3_EXT_nconf_nid(conf, ctx, nid, RSTRING_PTR(valstr)); + +#if OSSL_OPENSSL_PREREQ(1, 1, 0) || OSSL_IS_LIBRESSL + ext = X509V3_EXT_nconf(conf, ctx, oid_cstr, RSTRING_PTR(valstr)); +#else + ext = X509V3_EXT_nconf(conf, ctx, (char *)oid_cstr, RSTRING_PTR(valstr)); +#endif X509V3_set_ctx_nodb(ctx); if (!ext){ ossl_raise(eX509ExtError, "%"PRIsVALUE" = %"PRIsVALUE, oid, valstr); diff --git a/test/openssl/test_x509ext.rb b/test/openssl/test_x509ext.rb index c04c06574f163f..838780d3250478 100644 --- a/test/openssl/test_x509ext.rb +++ b/test/openssl/test_x509ext.rb @@ -78,6 +78,17 @@ def test_factory_create_extension_sn_ln assert_equal(@basic_constraints.to_der, bc_ln.to_der) end + def test_factory_create_extension_oid + ef = OpenSSL::X509::ExtensionFactory.new + ef.config = OpenSSL::Config.parse(<<~_end_of_cnf_) + [basic_constraints] + cA = BOOLEAN:TRUE + pathLenConstraint = INTEGER:2 + _end_of_cnf_ + bc_oid = ef.create_extension("2.5.29.19", "ASN1:SEQUENCE:basic_constraints", true) + assert_equal(@basic_constraints.to_der, bc_oid.to_der) + end + def test_dup ext = OpenSSL::X509::Extension.new(@basic_constraints.to_der) assert_equal(@basic_constraints.to_der, ext.to_der) From 1d4a43e7b09d0c90be6bef839b0616fe6a9008cd Mon Sep 17 00:00:00 2001 From: Kazuki Yamaguchi Date: Thu, 31 Aug 2023 14:58:14 +0900 Subject: [PATCH 75/95] [ruby/openssl] test/openssl/test_ossl.rb: relax assertion for error messages The test case test_error_data utilizes the error message generated by X509V3_EXT_nconf_nid(). The next commit will use X509V3_EXT_nconf(), which generates a slightly different error message. Let's adapt the check to it. https://github.com/ruby/openssl/commit/9cdfa3a4d1 --- test/openssl/test_ossl.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/openssl/test_ossl.rb b/test/openssl/test_ossl.rb index 5759c75b81d469..979669a00394e1 100644 --- a/test/openssl/test_ossl.rb +++ b/test/openssl/test_ossl.rb @@ -67,8 +67,9 @@ def test_error_data # # The generated message should look like: # "subjectAltName = IP:not.a.valid.ip.address: bad ip address (value=not.a.valid.ip.address)" + # "subjectAltName = IP:not.a.valid.ip.address: error in extension (name=subjectAltName, value=IP:not.a.valid.ip.address)" ef = OpenSSL::X509::ExtensionFactory.new - assert_raise_with_message(OpenSSL::X509::ExtensionError, /\(value=not.a.valid.ip.address\)/) { + assert_raise_with_message(OpenSSL::X509::ExtensionError, /value=(IP:)?not.a.valid.ip.address\)/) { ef.create_ext("subjectAltName", "IP:not.a.valid.ip.address") } end From 3fd90c0158f8170ad11c8a99354bb3347c7cc121 Mon Sep 17 00:00:00 2001 From: Kazuki Yamaguchi Date: Wed, 30 Aug 2023 00:02:37 +0900 Subject: [PATCH 76/95] [ruby/openssl] test/openssl/test_pkey_ec.rb: refactor tests for EC.builtin_curves Check that OpenSSL::PKey::EC.builtin_curves returns an array in the expected format. Similarly to OpenSSL::Cipher.ciphers, OpenSSL::PKey::EC.builtin_curves returns a list of known named curves rather than actually usable ones. https://github.com/ruby/openssl/issues/671 found that the list may include unapproved (and thus unusable) curves when the FIPS module is loaded. https://github.com/ruby/openssl/commit/c53cbabe00 --- test/openssl/test_pkey_ec.rb | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/test/openssl/test_pkey_ec.rb b/test/openssl/test_pkey_ec.rb index d21d135a21f8fa..126c1347cf22c9 100644 --- a/test/openssl/test_pkey_ec.rb +++ b/test/openssl/test_pkey_ec.rb @@ -5,20 +5,6 @@ class OpenSSL::TestEC < OpenSSL::PKeyTestCase def test_ec_key - builtin_curves = OpenSSL::PKey::EC.builtin_curves - assert_not_empty builtin_curves - - builtin_curves.each do |curve_name, comment| - # Oakley curves and X25519 are not suitable for signing and causes - # FIPS-selftest failure on some environment, so skip for now. - next if ["Oakley", "X25519"].any? { |n| curve_name.start_with?(n) } - - key = OpenSSL::PKey::EC.generate(curve_name) - assert_predicate key, :private? - assert_predicate key, :public? - assert_nothing_raised { key.check_key } - end - key1 = OpenSSL::PKey::EC.generate("prime256v1") # PKey is immutable in OpenSSL >= 3.0; constructing an empty EC object is @@ -49,6 +35,17 @@ def test_ec_key end end + def test_builtin_curves + builtin_curves = OpenSSL::PKey::EC.builtin_curves + assert_not_empty builtin_curves + assert_equal 2, builtin_curves[0].size + assert_kind_of String, builtin_curves[0][0] + assert_kind_of String, builtin_curves[0][1] + + builtin_curve_names = builtin_curves.map { |name, comment| name } + assert_include builtin_curve_names, "prime256v1" + end + def test_generate assert_raise(OpenSSL::PKey::ECError) { OpenSSL::PKey::EC.generate("non-existent") } g = OpenSSL::PKey::EC::Group.new("prime256v1") From 5ba480e4eab7f0660a11bb21044aa4077aedf7d1 Mon Sep 17 00:00:00 2001 From: Kazuki Yamaguchi Date: Tue, 29 Aug 2023 18:26:19 +0900 Subject: [PATCH 77/95] Use the test-unit-ruby-core gem for Test::Unit::CoreAssertions test/lib/core_assertions.rb and its dependencies are now packaged in the gem test-unit-ruby-core. Let's use it instead. --- test/openssl/utils.rb | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/test/openssl/utils.rb b/test/openssl/utils.rb index 269a111dbf5523..3856bea875d5e7 100644 --- a/test/openssl/utils.rb +++ b/test/openssl/utils.rb @@ -5,15 +5,10 @@ end require "test/unit" +require "core_assertions" require "tempfile" require "socket" -begin - require_relative "../lib/core_assertions" -rescue LoadError - # for ruby/ruby repository -end - if defined?(OpenSSL) module OpenSSL::TestUtils From 6356f6d3cd4a8bd470176d80bd880882bf40beb8 Mon Sep 17 00:00:00 2001 From: Benoit Daloze Date: Mon, 4 Sep 2023 11:33:14 +0200 Subject: [PATCH 78/95] [ruby/yarp] Rename YP_NODE_*_NODE to YP_*_NODE https://github.com/ruby/yarp/commit/d93b93f342 --- yarp/templates/include/yarp/ast.h.erb | 2 +- yarp/templates/src/node.c.erb | 2 +- yarp/templates/src/prettyprint.c.erb | 2 +- yarp/templates/src/serialize.c.erb | 2 +- yarp/templates/template.rb | 2 +- yarp/yarp.c | 610 +++++++++++++------------- 6 files changed, 310 insertions(+), 310 deletions(-) diff --git a/yarp/templates/include/yarp/ast.h.erb b/yarp/templates/include/yarp/ast.h.erb index 48eaefda2447ad..cc631568ede7e8 100644 --- a/yarp/templates/include/yarp/ast.h.erb +++ b/yarp/templates/include/yarp/ast.h.erb @@ -44,7 +44,7 @@ enum yp_node_type { <%- nodes.each_with_index do |node, index| -%> <%= node.type %> = <%= index + 1 %>, <%- end -%> - YP_NODE_SCOPE_NODE + YP_SCOPE_NODE }; typedef uint16_t yp_node_type_t; diff --git a/yarp/templates/src/node.c.erb b/yarp/templates/src/node.c.erb index 647950d5824048..732749394a72ec 100644 --- a/yarp/templates/src/node.c.erb +++ b/yarp/templates/src/node.c.erb @@ -95,7 +95,7 @@ yp_node_memsize_node(yp_node_t *node, yp_memsize_t *memsize) { switch (YP_NODE_TYPE(node)) { // We do not calculate memsize of a ScopeNode // as it should never be generated - case YP_NODE_SCOPE_NODE: + case YP_SCOPE_NODE: return; <%- nodes.each do |node| -%> #line <%= __LINE__ + 1 %> "<%= File.basename(__FILE__) %>" diff --git a/yarp/templates/src/prettyprint.c.erb b/yarp/templates/src/prettyprint.c.erb index 793519a1acede9..774720a24502b9 100644 --- a/yarp/templates/src/prettyprint.c.erb +++ b/yarp/templates/src/prettyprint.c.erb @@ -18,7 +18,7 @@ prettyprint_node(yp_buffer_t *buffer, yp_parser_t *parser, yp_node_t *node) { switch (YP_NODE_TYPE(node)) { // We do not need to print a ScopeNode as it's not part // of the AST - case YP_NODE_SCOPE_NODE: + case YP_SCOPE_NODE: return; <%- nodes.each do |node| -%> case <%= node.type %>: { diff --git a/yarp/templates/src/serialize.c.erb b/yarp/templates/src/serialize.c.erb index a6411baaf3a4ff..4816f154ba1ef7 100644 --- a/yarp/templates/src/serialize.c.erb +++ b/yarp/templates/src/serialize.c.erb @@ -58,7 +58,7 @@ yp_serialize_node(yp_parser_t *parser, yp_node_t *node, yp_buffer_t *buffer) { switch (YP_NODE_TYPE(node)) { // We do not need to serialize a ScopeNode ever as // it is not part of the AST - case YP_NODE_SCOPE_NODE: + case YP_SCOPE_NODE: return; <%- nodes.each do |node| -%> case <%= node.type %>: { diff --git a/yarp/templates/template.rb b/yarp/templates/template.rb index 428f3d5b3769f7..d73951cb538c5d 100755 --- a/yarp/templates/template.rb +++ b/yarp/templates/template.rb @@ -168,7 +168,7 @@ def initialize(config) @name = config.fetch("name") type = @name.gsub(/(?<=.)[A-Z]/, "_\\0") - @type = "YP_NODE_#{type.upcase}" + @type = "YP_#{type.upcase}" @human = type.downcase @fields = diff --git a/yarp/yarp.c b/yarp/yarp.c index 0587d897acfbf7..8079bb55f67543 100644 --- a/yarp/yarp.c +++ b/yarp/yarp.c @@ -441,29 +441,29 @@ yp_parser_constant_id_token(yp_parser_t *parser, const yp_token_t *token) { static void yp_flip_flop(yp_node_t *node) { switch (YP_NODE_TYPE(node)) { - case YP_NODE_AND_NODE: { + case YP_AND_NODE: { yp_and_node_t *cast = (yp_and_node_t *) node; yp_flip_flop(cast->left); yp_flip_flop(cast->right); break; } - case YP_NODE_OR_NODE: { + case YP_OR_NODE: { yp_or_node_t *cast = (yp_or_node_t *) node; yp_flip_flop(cast->left); yp_flip_flop(cast->right); break; } - case YP_NODE_PARENTHESES_NODE: { + case YP_PARENTHESES_NODE: { yp_parentheses_node_t *cast = (yp_parentheses_node_t *) node; - if ((cast->body != NULL) && YP_NODE_TYPE_P(cast->body, YP_NODE_STATEMENTS_NODE)) { + if ((cast->body != NULL) && YP_NODE_TYPE_P(cast->body, YP_STATEMENTS_NODE)) { yp_statements_node_t *statements = (yp_statements_node_t *) cast->body; if (statements->body.size == 1) yp_flip_flop(statements->body.nodes[0]); } break; } - case YP_NODE_RANGE_NODE: { + case YP_RANGE_NODE: { yp_range_node_t *cast = (yp_range_node_t *) node; if (cast->left) { yp_flip_flop(cast->left); @@ -475,7 +475,7 @@ yp_flip_flop(yp_node_t *node) { // Here we change the range node into a flip flop node. We can do // this since the nodes are exactly the same except for the type. assert(sizeof(yp_range_node_t) == sizeof(yp_flip_flop_node_t)); - node->type = YP_NODE_FLIP_FLOP_NODE; + node->type = YP_FLIP_FLOP_NODE; break; } @@ -549,7 +549,7 @@ yp_arguments_validate(yp_parser_t *parser, yp_arguments_t *arguments) { // Generate a scope node from the given node. void yp_scope_node_init(yp_node_t *node, yp_scope_node_t *scope) { - scope->base.type = YP_NODE_SCOPE_NODE; + scope->base.type = YP_SCOPE_NODE; scope->base.location.start = node->location.start; scope->base.location.end = node->location.end; @@ -558,46 +558,46 @@ yp_scope_node_init(yp_node_t *node, yp_scope_node_t *scope) { yp_constant_id_list_init(&scope->locals); switch (YP_NODE_TYPE(node)) { - case YP_NODE_BLOCK_NODE: { + case YP_BLOCK_NODE: { yp_block_node_t *cast = (yp_block_node_t *) node; if (cast->parameters) scope->parameters = cast->parameters->parameters; scope->body = cast->body; scope->locals = cast->locals; break; } - case YP_NODE_CLASS_NODE: { + case YP_CLASS_NODE: { yp_class_node_t *cast = (yp_class_node_t *) node; scope->body = cast->body; scope->locals = cast->locals; break; } - case YP_NODE_DEF_NODE: { + case YP_DEF_NODE: { yp_def_node_t *cast = (yp_def_node_t *) node; scope->parameters = cast->parameters; scope->body = cast->body; scope->locals = cast->locals; break; } - case YP_NODE_LAMBDA_NODE: { + case YP_LAMBDA_NODE: { yp_lambda_node_t *cast = (yp_lambda_node_t *) node; if (cast->parameters) scope->parameters = cast->parameters->parameters; scope->body = cast->body; scope->locals = cast->locals; break; } - case YP_NODE_MODULE_NODE: { + case YP_MODULE_NODE: { yp_module_node_t *cast = (yp_module_node_t *) node; scope->body = cast->body; scope->locals = cast->locals; break; } - case YP_NODE_PROGRAM_NODE: { + case YP_PROGRAM_NODE: { yp_program_node_t *cast = (yp_program_node_t *) node; scope->body = (yp_node_t *) cast->statements; scope->locals = cast->locals; break; } - case YP_NODE_SINGLETON_CLASS_NODE: { + case YP_SINGLETON_CLASS_NODE: { yp_singleton_class_node_t *cast = (yp_singleton_class_node_t *) node; scope->body = cast->body; scope->locals = cast->locals; @@ -695,7 +695,7 @@ yp_alloc_node(YP_ATTRIBUTE_UNUSED yp_parser_t *parser, size_t size) { static yp_missing_node_t * yp_missing_node_create(yp_parser_t *parser, const uint8_t *start, const uint8_t *end) { yp_missing_node_t *node = YP_ALLOC_NODE(parser, yp_missing_node_t); - *node = (yp_missing_node_t) {{ .type = YP_NODE_MISSING_NODE, .location = { .start = start, .end = end } }}; + *node = (yp_missing_node_t) {{ .type = YP_MISSING_NODE, .location = { .start = start, .end = end } }}; return node; } @@ -707,7 +707,7 @@ yp_alias_node_create(yp_parser_t *parser, const yp_token_t *keyword, yp_node_t * *node = (yp_alias_node_t) { { - .type = YP_NODE_ALIAS_NODE, + .type = YP_ALIAS_NODE, .location = { .start = keyword->start, .end = old_name->location.end @@ -728,7 +728,7 @@ yp_alternation_pattern_node_create(yp_parser_t *parser, yp_node_t *left, yp_node *node = (yp_alternation_pattern_node_t) { { - .type = YP_NODE_ALTERNATION_PATTERN_NODE, + .type = YP_ALTERNATION_PATTERN_NODE, .location = { .start = left->location.start, .end = right->location.end @@ -749,7 +749,7 @@ yp_and_node_create(yp_parser_t *parser, yp_node_t *left, const yp_token_t *opera *node = (yp_and_node_t) { { - .type = YP_NODE_AND_NODE, + .type = YP_AND_NODE, .location = { .start = left->location.start, .end = right->location.end @@ -770,7 +770,7 @@ yp_arguments_node_create(yp_parser_t *parser) { *node = (yp_arguments_node_t) { { - .type = YP_NODE_ARGUMENTS_NODE, + .type = YP_ARGUMENTS_NODE, .location = YP_LOCATION_NULL_VALUE(parser) }, .arguments = YP_EMPTY_NODE_LIST @@ -803,7 +803,7 @@ yp_array_node_create(yp_parser_t *parser, const yp_token_t *opening) { *node = (yp_array_node_t) { { - .type = YP_NODE_ARRAY_NODE, + .type = YP_ARRAY_NODE, .location = { .start = opening->start, .end = opening->end @@ -849,7 +849,7 @@ yp_array_pattern_node_node_list_create(yp_parser_t *parser, yp_node_list_t *node *node = (yp_array_pattern_node_t) { { - .type = YP_NODE_ARRAY_PATTERN_NODE, + .type = YP_ARRAY_PATTERN_NODE, .location = { .start = nodes->nodes[0]->location.start, .end = nodes->nodes[nodes->size - 1]->location.end @@ -869,7 +869,7 @@ yp_array_pattern_node_node_list_create(yp_parser_t *parser, yp_node_list_t *node for (size_t index = 0; index < nodes->size; index++) { yp_node_t *child = nodes->nodes[index]; - if (!found_rest && YP_NODE_TYPE_P(child, YP_NODE_SPLAT_NODE)) { + if (!found_rest && YP_NODE_TYPE_P(child, YP_SPLAT_NODE)) { node->rest = child; found_rest = true; } else if (found_rest) { @@ -889,7 +889,7 @@ yp_array_pattern_node_rest_create(yp_parser_t *parser, yp_node_t *rest) { *node = (yp_array_pattern_node_t) { { - .type = YP_NODE_ARRAY_PATTERN_NODE, + .type = YP_ARRAY_PATTERN_NODE, .location = rest->location, }, .constant = NULL, @@ -911,7 +911,7 @@ yp_array_pattern_node_constant_create(yp_parser_t *parser, yp_node_t *constant, *node = (yp_array_pattern_node_t) { { - .type = YP_NODE_ARRAY_PATTERN_NODE, + .type = YP_ARRAY_PATTERN_NODE, .location = { .start = constant->location.start, .end = closing->end @@ -936,7 +936,7 @@ yp_array_pattern_node_empty_create(yp_parser_t *parser, const yp_token_t *openin *node = (yp_array_pattern_node_t) { { - .type = YP_NODE_ARRAY_PATTERN_NODE, + .type = YP_ARRAY_PATTERN_NODE, .location = { .start = opening->start, .end = closing->end @@ -974,7 +974,7 @@ yp_assoc_node_create(yp_parser_t *parser, yp_node_t *key, const yp_token_t *oper *node = (yp_assoc_node_t) { { - .type = YP_NODE_ASSOC_NODE, + .type = YP_ASSOC_NODE, .location = { .start = key->location.start, .end = end @@ -996,7 +996,7 @@ yp_assoc_splat_node_create(yp_parser_t *parser, yp_node_t *value, const yp_token *node = (yp_assoc_splat_node_t) { { - .type = YP_NODE_ASSOC_SPLAT_NODE, + .type = YP_ASSOC_SPLAT_NODE, .location = { .start = operator->start, .end = value == NULL ? operator->end : value->location.end @@ -1017,7 +1017,7 @@ yp_back_reference_read_node_create(yp_parser_t *parser, const yp_token_t *name) *node = (yp_back_reference_read_node_t) { { - .type = YP_NODE_BACK_REFERENCE_READ_NODE, + .type = YP_BACK_REFERENCE_READ_NODE, .location = YP_LOCATION_TOKEN_VALUE(name), } }; @@ -1032,7 +1032,7 @@ yp_begin_node_create(yp_parser_t *parser, const yp_token_t *begin_keyword, yp_st *node = (yp_begin_node_t) { { - .type = YP_NODE_BEGIN_NODE, + .type = YP_BEGIN_NODE, .location = { .start = begin_keyword->start, .end = statements == NULL ? begin_keyword->end : statements->base.location.end @@ -1087,7 +1087,7 @@ yp_block_argument_node_create(yp_parser_t *parser, const yp_token_t *operator, y *node = (yp_block_argument_node_t) { { - .type = YP_NODE_BLOCK_ARGUMENT_NODE, + .type = YP_BLOCK_ARGUMENT_NODE, .location = { .start = operator->start, .end = expression == NULL ? operator->end : expression->location.end @@ -1107,7 +1107,7 @@ yp_block_node_create(yp_parser_t *parser, yp_constant_id_list_t *locals, const y *node = (yp_block_node_t) { { - .type = YP_NODE_BLOCK_NODE, + .type = YP_BLOCK_NODE, .location = { .start = opening->start, .end = closing->end }, }, .locals = *locals, @@ -1128,7 +1128,7 @@ yp_block_parameter_node_create(yp_parser_t *parser, const yp_token_t *name, cons *node = (yp_block_parameter_node_t) { { - .type = YP_NODE_BLOCK_PARAMETER_NODE, + .type = YP_BLOCK_PARAMETER_NODE, .location = { .start = operator->start, .end = (name->type == YP_TOKEN_NOT_PROVIDED ? operator->end : name->end) @@ -1166,7 +1166,7 @@ yp_block_parameters_node_create(yp_parser_t *parser, yp_parameters_node_t *param *node = (yp_block_parameters_node_t) { { - .type = YP_NODE_BLOCK_PARAMETERS_NODE, + .type = YP_BLOCK_PARAMETERS_NODE, .location = { .start = start, .end = end @@ -1198,7 +1198,7 @@ yp_block_local_variable_node_create(yp_parser_t *parser, const yp_token_t *name) *node = (yp_block_local_variable_node_t) { { - .type = YP_NODE_BLOCK_LOCAL_VARIABLE_NODE, + .type = YP_BLOCK_LOCAL_VARIABLE_NODE, .location = YP_LOCATION_TOKEN_VALUE(name), }, .name = yp_parser_constant_id_token(parser, name) @@ -1224,7 +1224,7 @@ yp_break_node_create(yp_parser_t *parser, const yp_token_t *keyword, yp_argument *node = (yp_break_node_t) { { - .type = YP_NODE_BREAK_NODE, + .type = YP_BREAK_NODE, .location = { .start = keyword->start, .end = (arguments == NULL ? keyword->end : arguments->base.location.end) @@ -1246,7 +1246,7 @@ yp_call_node_create(yp_parser_t *parser) { *node = (yp_call_node_t) { { - .type = YP_NODE_CALL_NODE, + .type = YP_CALL_NODE, .location = YP_LOCATION_NULL_VALUE(parser), }, .receiver = NULL, @@ -1471,7 +1471,7 @@ yp_call_and_write_node_create(yp_parser_t *parser, yp_call_node_t *target, const *node = (yp_call_and_write_node_t) { { - .type = YP_NODE_CALL_AND_WRITE_NODE, + .type = YP_CALL_AND_WRITE_NODE, .flags = target->base.flags, .location = { .start = target->base.location.start, @@ -1508,7 +1508,7 @@ yp_call_operator_write_node_create(yp_parser_t *parser, yp_call_node_t *target, *node = (yp_call_operator_write_node_t) { { - .type = YP_NODE_CALL_OPERATOR_WRITE_NODE, + .type = YP_CALL_OPERATOR_WRITE_NODE, .flags = target->base.flags, .location = { .start = target->base.location.start, @@ -1547,7 +1547,7 @@ yp_call_or_write_node_create(yp_parser_t *parser, yp_call_node_t *target, const *node = (yp_call_or_write_node_t) { { - .type = YP_NODE_CALL_OR_WRITE_NODE, + .type = YP_CALL_OR_WRITE_NODE, .flags = target->base.flags, .location = { .start = target->base.location.start, @@ -1583,7 +1583,7 @@ yp_capture_pattern_node_create(yp_parser_t *parser, yp_node_t *value, yp_node_t *node = (yp_capture_pattern_node_t) { { - .type = YP_NODE_CAPTURE_PATTERN_NODE, + .type = YP_CAPTURE_PATTERN_NODE, .location = { .start = value->location.start, .end = target->location.end @@ -1604,7 +1604,7 @@ yp_case_node_create(yp_parser_t *parser, const yp_token_t *case_keyword, yp_node *node = (yp_case_node_t) { { - .type = YP_NODE_CASE_NODE, + .type = YP_CASE_NODE, .location = { .start = case_keyword->start, .end = end_keyword->end @@ -1623,7 +1623,7 @@ yp_case_node_create(yp_parser_t *parser, const yp_token_t *case_keyword, yp_node // Append a new condition to a CaseNode node. static void yp_case_node_condition_append(yp_case_node_t *node, yp_node_t *condition) { - assert(YP_NODE_TYPE_P(condition, YP_NODE_WHEN_NODE) || YP_NODE_TYPE_P(condition, YP_NODE_IN_NODE)); + assert(YP_NODE_TYPE_P(condition, YP_WHEN_NODE) || YP_NODE_TYPE_P(condition, YP_IN_NODE)); yp_node_list_append(&node->conditions, condition); node->base.location.end = condition->location.end; @@ -1650,7 +1650,7 @@ yp_class_node_create(yp_parser_t *parser, yp_constant_id_list_t *locals, const y *node = (yp_class_node_t) { { - .type = YP_NODE_CLASS_NODE, + .type = YP_CLASS_NODE, .location = { .start = class_keyword->start, .end = end_keyword->end }, }, .locals = *locals, @@ -1675,7 +1675,7 @@ yp_class_variable_and_write_node_create(yp_parser_t *parser, yp_class_variable_r *node = (yp_class_variable_and_write_node_t) { { - .type = YP_NODE_CLASS_VARIABLE_AND_WRITE_NODE, + .type = YP_CLASS_VARIABLE_AND_WRITE_NODE, .location = { .start = target->base.location.start, .end = value->location.end @@ -1697,7 +1697,7 @@ yp_class_variable_operator_write_node_create(yp_parser_t *parser, yp_class_varia *node = (yp_class_variable_operator_write_node_t) { { - .type = YP_NODE_CLASS_VARIABLE_OPERATOR_WRITE_NODE, + .type = YP_CLASS_VARIABLE_OPERATOR_WRITE_NODE, .location = { .start = target->base.location.start, .end = value->location.end @@ -1721,7 +1721,7 @@ yp_class_variable_or_write_node_create(yp_parser_t *parser, yp_class_variable_re *node = (yp_class_variable_or_write_node_t) { { - .type = YP_NODE_CLASS_VARIABLE_OR_WRITE_NODE, + .type = YP_CLASS_VARIABLE_OR_WRITE_NODE, .location = { .start = target->base.location.start, .end = value->location.end @@ -1744,7 +1744,7 @@ yp_class_variable_read_node_create(yp_parser_t *parser, const yp_token_t *token) *node = (yp_class_variable_read_node_t) { { - .type = YP_NODE_CLASS_VARIABLE_READ_NODE, + .type = YP_CLASS_VARIABLE_READ_NODE, .location = YP_LOCATION_TOKEN_VALUE(token) }, .name = yp_parser_constant_id_location(parser, token->start, token->end) @@ -1760,7 +1760,7 @@ yp_class_variable_write_node_create(yp_parser_t *parser, yp_class_variable_read_ *node = (yp_class_variable_write_node_t) { { - .type = YP_NODE_CLASS_VARIABLE_WRITE_NODE, + .type = YP_CLASS_VARIABLE_WRITE_NODE, .location = { .start = read_node->base.location.start, .end = value->location.end @@ -1783,7 +1783,7 @@ yp_constant_path_and_write_node_create(yp_parser_t *parser, yp_constant_path_nod *node = (yp_constant_path_and_write_node_t) { { - .type = YP_NODE_CONSTANT_PATH_AND_WRITE_NODE, + .type = YP_CONSTANT_PATH_AND_WRITE_NODE, .location = { .start = target->base.location.start, .end = value->location.end @@ -1804,7 +1804,7 @@ yp_constant_path_operator_write_node_create(yp_parser_t *parser, yp_constant_pat *node = (yp_constant_path_operator_write_node_t) { { - .type = YP_NODE_CONSTANT_PATH_OPERATOR_WRITE_NODE, + .type = YP_CONSTANT_PATH_OPERATOR_WRITE_NODE, .location = { .start = target->base.location.start, .end = value->location.end @@ -1827,7 +1827,7 @@ yp_constant_path_or_write_node_create(yp_parser_t *parser, yp_constant_path_node *node = (yp_constant_path_or_write_node_t) { { - .type = YP_NODE_CONSTANT_PATH_OR_WRITE_NODE, + .type = YP_CONSTANT_PATH_OR_WRITE_NODE, .location = { .start = target->base.location.start, .end = value->location.end @@ -1848,7 +1848,7 @@ yp_constant_path_node_create(yp_parser_t *parser, yp_node_t *parent, const yp_to *node = (yp_constant_path_node_t) { { - .type = YP_NODE_CONSTANT_PATH_NODE, + .type = YP_CONSTANT_PATH_NODE, .location = { .start = parent == NULL ? delimiter->start : parent->location.start, .end = child->location.end @@ -1869,7 +1869,7 @@ yp_constant_path_write_node_create(yp_parser_t *parser, yp_constant_path_node_t *node = (yp_constant_path_write_node_t) { { - .type = YP_NODE_CONSTANT_PATH_WRITE_NODE, + .type = YP_CONSTANT_PATH_WRITE_NODE, .location = { .start = target->base.location.start, .end = value->location.end @@ -1886,13 +1886,13 @@ yp_constant_path_write_node_create(yp_parser_t *parser, yp_constant_path_node_t // Allocate and initialize a new ConstantAndWriteNode node. static yp_constant_and_write_node_t * yp_constant_and_write_node_create(yp_parser_t *parser, yp_node_t *target, const yp_token_t *operator, yp_node_t *value) { - assert(YP_NODE_TYPE_P(target, YP_NODE_CONSTANT_READ_NODE)); + assert(YP_NODE_TYPE_P(target, YP_CONSTANT_READ_NODE)); assert(operator->type == YP_TOKEN_AMPERSAND_AMPERSAND_EQUAL); yp_constant_and_write_node_t *node = YP_ALLOC_NODE(parser, yp_constant_and_write_node_t); *node = (yp_constant_and_write_node_t) { { - .type = YP_NODE_CONSTANT_AND_WRITE_NODE, + .type = YP_CONSTANT_AND_WRITE_NODE, .location = { .start = target->location.start, .end = value->location.end @@ -1913,7 +1913,7 @@ yp_constant_operator_write_node_create(yp_parser_t *parser, yp_node_t *target, c *node = (yp_constant_operator_write_node_t) { { - .type = YP_NODE_CONSTANT_OPERATOR_WRITE_NODE, + .type = YP_CONSTANT_OPERATOR_WRITE_NODE, .location = { .start = target->location.start, .end = value->location.end @@ -1931,13 +1931,13 @@ yp_constant_operator_write_node_create(yp_parser_t *parser, yp_node_t *target, c // Allocate and initialize a new ConstantOrWriteNode node. static yp_constant_or_write_node_t * yp_constant_or_write_node_create(yp_parser_t *parser, yp_node_t *target, const yp_token_t *operator, yp_node_t *value) { - assert(YP_NODE_TYPE_P(target, YP_NODE_CONSTANT_READ_NODE)); + assert(YP_NODE_TYPE_P(target, YP_CONSTANT_READ_NODE)); assert(operator->type == YP_TOKEN_PIPE_PIPE_EQUAL); yp_constant_or_write_node_t *node = YP_ALLOC_NODE(parser, yp_constant_or_write_node_t); *node = (yp_constant_or_write_node_t) { { - .type = YP_NODE_CONSTANT_OR_WRITE_NODE, + .type = YP_CONSTANT_OR_WRITE_NODE, .location = { .start = target->location.start, .end = value->location.end @@ -1957,7 +1957,7 @@ yp_constant_read_node_create(yp_parser_t *parser, const yp_token_t *name) { assert(name->type == YP_TOKEN_CONSTANT || name->type == YP_TOKEN_MISSING); yp_constant_read_node_t *node = YP_ALLOC_NODE(parser, yp_constant_read_node_t); - *node = (yp_constant_read_node_t) {{ .type = YP_NODE_CONSTANT_READ_NODE, .location = YP_LOCATION_TOKEN_VALUE(name) }}; + *node = (yp_constant_read_node_t) {{ .type = YP_CONSTANT_READ_NODE, .location = YP_LOCATION_TOKEN_VALUE(name) }}; return node; } @@ -1968,7 +1968,7 @@ yp_constant_write_node_create(yp_parser_t *parser, yp_location_t *name_loc, cons *node = (yp_constant_write_node_t) { { - .type = YP_NODE_CONSTANT_WRITE_NODE, + .type = YP_CONSTANT_WRITE_NODE, .location = { .start = name_loc->start, .end = value->location.end @@ -2009,7 +2009,7 @@ yp_def_node_create( *node = (yp_def_node_t) { { - .type = YP_NODE_DEF_NODE, + .type = YP_DEF_NODE, .location = { .start = def_keyword->start, .end = end }, }, .name_loc = YP_LOCATION_TOKEN_VALUE(name), @@ -2035,7 +2035,7 @@ yp_defined_node_create(yp_parser_t *parser, const yp_token_t *lparen, yp_node_t *node = (yp_defined_node_t) { { - .type = YP_NODE_DEFINED_NODE, + .type = YP_DEFINED_NODE, .location = { .start = keyword_loc->start, .end = (rparen->type == YP_TOKEN_NOT_PROVIDED ? value->location.end : rparen->end) @@ -2063,7 +2063,7 @@ yp_else_node_create(yp_parser_t *parser, const yp_token_t *else_keyword, yp_stat *node = (yp_else_node_t) { { - .type = YP_NODE_ELSE_NODE, + .type = YP_ELSE_NODE, .location = { .start = else_keyword->start, .end = end, @@ -2084,7 +2084,7 @@ yp_embedded_statements_node_create(yp_parser_t *parser, const yp_token_t *openin *node = (yp_embedded_statements_node_t) { { - .type = YP_NODE_EMBEDDED_STATEMENTS_NODE, + .type = YP_EMBEDDED_STATEMENTS_NODE, .location = { .start = opening->start, .end = closing->end @@ -2105,7 +2105,7 @@ yp_embedded_variable_node_create(yp_parser_t *parser, const yp_token_t *operator *node = (yp_embedded_variable_node_t) { { - .type = YP_NODE_EMBEDDED_VARIABLE_NODE, + .type = YP_EMBEDDED_VARIABLE_NODE, .location = { .start = operator->start, .end = variable->location.end @@ -2125,7 +2125,7 @@ yp_ensure_node_create(yp_parser_t *parser, const yp_token_t *ensure_keyword, yp_ *node = (yp_ensure_node_t) { { - .type = YP_NODE_ENSURE_NODE, + .type = YP_ENSURE_NODE, .location = { .start = ensure_keyword->start, .end = end_keyword->end @@ -2144,7 +2144,7 @@ static yp_false_node_t * yp_false_node_create(yp_parser_t *parser, const yp_token_t *token) { assert(token->type == YP_TOKEN_KEYWORD_FALSE); yp_false_node_t *node = YP_ALLOC_NODE(parser, yp_false_node_t); - *node = (yp_false_node_t) {{ .type = YP_NODE_FALSE_NODE, .location = YP_LOCATION_TOKEN_VALUE(token) }}; + *node = (yp_false_node_t) {{ .type = YP_FALSE_NODE, .location = YP_LOCATION_TOKEN_VALUE(token) }}; return node; } @@ -2165,7 +2165,7 @@ yp_find_pattern_node_create(yp_parser_t *parser, yp_node_list_t *nodes) { *node = (yp_find_pattern_node_t) { { - .type = YP_NODE_FIND_PATTERN_NODE, + .type = YP_FIND_PATTERN_NODE, .location = { .start = left->location.start, .end = right->location.end, @@ -2194,7 +2194,7 @@ static yp_float_node_t * yp_float_node_create(yp_parser_t *parser, const yp_token_t *token) { assert(token->type == YP_TOKEN_FLOAT); yp_float_node_t *node = YP_ALLOC_NODE(parser, yp_float_node_t); - *node = (yp_float_node_t) {{ .type = YP_NODE_FLOAT_NODE, .location = YP_LOCATION_TOKEN_VALUE(token) }}; + *node = (yp_float_node_t) {{ .type = YP_FLOAT_NODE, .location = YP_LOCATION_TOKEN_VALUE(token) }}; return node; } @@ -2206,7 +2206,7 @@ yp_float_node_imaginary_create(yp_parser_t *parser, const yp_token_t *token) { yp_imaginary_node_t *node = YP_ALLOC_NODE(parser, yp_imaginary_node_t); *node = (yp_imaginary_node_t) { { - .type = YP_NODE_IMAGINARY_NODE, + .type = YP_IMAGINARY_NODE, .location = YP_LOCATION_TOKEN_VALUE(token) }, .numeric = (yp_node_t *) yp_float_node_create(parser, &((yp_token_t) { @@ -2227,7 +2227,7 @@ yp_float_node_rational_create(yp_parser_t *parser, const yp_token_t *token) { yp_rational_node_t *node = YP_ALLOC_NODE(parser, yp_rational_node_t); *node = (yp_rational_node_t) { { - .type = YP_NODE_RATIONAL_NODE, + .type = YP_RATIONAL_NODE, .location = YP_LOCATION_TOKEN_VALUE(token) }, .numeric = (yp_node_t *) yp_float_node_create(parser, &((yp_token_t) { @@ -2248,7 +2248,7 @@ yp_float_node_rational_imaginary_create(yp_parser_t *parser, const yp_token_t *t yp_imaginary_node_t *node = YP_ALLOC_NODE(parser, yp_imaginary_node_t); *node = (yp_imaginary_node_t) { { - .type = YP_NODE_IMAGINARY_NODE, + .type = YP_IMAGINARY_NODE, .location = YP_LOCATION_TOKEN_VALUE(token) }, .numeric = (yp_node_t *) yp_float_node_rational_create(parser, &((yp_token_t) { @@ -2277,7 +2277,7 @@ yp_for_node_create( *node = (yp_for_node_t) { { - .type = YP_NODE_FOR_NODE, + .type = YP_FOR_NODE, .location = { .start = for_keyword->start, .end = end_keyword->end @@ -2300,7 +2300,7 @@ static yp_forwarding_arguments_node_t * yp_forwarding_arguments_node_create(yp_parser_t *parser, const yp_token_t *token) { assert(token->type == YP_TOKEN_UDOT_DOT_DOT); yp_forwarding_arguments_node_t *node = YP_ALLOC_NODE(parser, yp_forwarding_arguments_node_t); - *node = (yp_forwarding_arguments_node_t) {{ .type = YP_NODE_FORWARDING_ARGUMENTS_NODE, .location = YP_LOCATION_TOKEN_VALUE(token) }}; + *node = (yp_forwarding_arguments_node_t) {{ .type = YP_FORWARDING_ARGUMENTS_NODE, .location = YP_LOCATION_TOKEN_VALUE(token) }}; return node; } @@ -2309,7 +2309,7 @@ static yp_forwarding_parameter_node_t * yp_forwarding_parameter_node_create(yp_parser_t *parser, const yp_token_t *token) { assert(token->type == YP_TOKEN_UDOT_DOT_DOT); yp_forwarding_parameter_node_t *node = YP_ALLOC_NODE(parser, yp_forwarding_parameter_node_t); - *node = (yp_forwarding_parameter_node_t) {{ .type = YP_NODE_FORWARDING_PARAMETER_NODE, .location = YP_LOCATION_TOKEN_VALUE(token) }}; + *node = (yp_forwarding_parameter_node_t) {{ .type = YP_FORWARDING_PARAMETER_NODE, .location = YP_LOCATION_TOKEN_VALUE(token) }}; return node; } @@ -2321,7 +2321,7 @@ yp_forwarding_super_node_create(yp_parser_t *parser, const yp_token_t *token, yp *node = (yp_forwarding_super_node_t) { { - .type = YP_NODE_FORWARDING_SUPER_NODE, + .type = YP_FORWARDING_SUPER_NODE, .location = { .start = token->start, .end = arguments->block != NULL ? arguments->block->base.location.end : token->end @@ -2341,7 +2341,7 @@ yp_hash_pattern_node_empty_create(yp_parser_t *parser, const yp_token_t *opening *node = (yp_hash_pattern_node_t) { { - .type = YP_NODE_HASH_PATTERN_NODE, + .type = YP_HASH_PATTERN_NODE, .location = { .start = opening->start, .end = closing->end @@ -2364,7 +2364,7 @@ yp_hash_pattern_node_node_list_create(yp_parser_t *parser, yp_node_list_t *assoc *node = (yp_hash_pattern_node_t) { { - .type = YP_NODE_HASH_PATTERN_NODE, + .type = YP_HASH_PATTERN_NODE, .location = { .start = assocs->nodes[0]->location.start, .end = assocs->nodes[assocs->size - 1]->location.end @@ -2388,11 +2388,11 @@ yp_hash_pattern_node_node_list_create(yp_parser_t *parser, yp_node_list_t *assoc // Retrieve the name from a node that will become a global variable write node. static yp_constant_id_t yp_global_variable_write_name(yp_parser_t *parser, yp_node_t *target) { - if (YP_NODE_TYPE_P(target, YP_NODE_GLOBAL_VARIABLE_READ_NODE)) { + if (YP_NODE_TYPE_P(target, YP_GLOBAL_VARIABLE_READ_NODE)) { return ((yp_global_variable_read_node_t *) target)->name; } - assert(YP_NODE_TYPE_P(target, YP_NODE_BACK_REFERENCE_READ_NODE) || YP_NODE_TYPE_P(target, YP_NODE_NUMBERED_REFERENCE_READ_NODE)); + assert(YP_NODE_TYPE_P(target, YP_BACK_REFERENCE_READ_NODE) || YP_NODE_TYPE_P(target, YP_NUMBERED_REFERENCE_READ_NODE)); // This will only ever happen in the event of a syntax error, but we // still need to provide something for the node. @@ -2407,7 +2407,7 @@ yp_global_variable_and_write_node_create(yp_parser_t *parser, yp_node_t *target, *node = (yp_global_variable_and_write_node_t) { { - .type = YP_NODE_GLOBAL_VARIABLE_AND_WRITE_NODE, + .type = YP_GLOBAL_VARIABLE_AND_WRITE_NODE, .location = { .start = target->location.start, .end = value->location.end @@ -2429,7 +2429,7 @@ yp_global_variable_operator_write_node_create(yp_parser_t *parser, yp_node_t *ta *node = (yp_global_variable_operator_write_node_t) { { - .type = YP_NODE_GLOBAL_VARIABLE_OPERATOR_WRITE_NODE, + .type = YP_GLOBAL_VARIABLE_OPERATOR_WRITE_NODE, .location = { .start = target->location.start, .end = value->location.end @@ -2453,7 +2453,7 @@ yp_global_variable_or_write_node_create(yp_parser_t *parser, yp_node_t *target, *node = (yp_global_variable_or_write_node_t) { { - .type = YP_NODE_GLOBAL_VARIABLE_OR_WRITE_NODE, + .type = YP_GLOBAL_VARIABLE_OR_WRITE_NODE, .location = { .start = target->location.start, .end = value->location.end @@ -2475,7 +2475,7 @@ yp_global_variable_read_node_create(yp_parser_t *parser, const yp_token_t *name) *node = (yp_global_variable_read_node_t) { { - .type = YP_NODE_GLOBAL_VARIABLE_READ_NODE, + .type = YP_GLOBAL_VARIABLE_READ_NODE, .location = YP_LOCATION_TOKEN_VALUE(name), }, .name = yp_parser_constant_id_location(parser, name->start, name->end) @@ -2491,7 +2491,7 @@ yp_global_variable_write_node_create(yp_parser_t *parser, yp_node_t *target, con *node = (yp_global_variable_write_node_t) { { - .type = YP_NODE_GLOBAL_VARIABLE_WRITE_NODE, + .type = YP_GLOBAL_VARIABLE_WRITE_NODE, .location = { .start = target->location.start, .end = value->location.end @@ -2514,7 +2514,7 @@ yp_hash_node_create(yp_parser_t *parser, const yp_token_t *opening) { *node = (yp_hash_node_t) { { - .type = YP_NODE_HASH_NODE, + .type = YP_HASH_NODE, .location = { .start = opening->start, .end = opening->end @@ -2564,7 +2564,7 @@ yp_if_node_create(yp_parser_t *parser, *node = (yp_if_node_t) { { - .type = YP_NODE_IF_NODE, + .type = YP_IF_NODE, .flags = YP_NODE_FLAG_NEWLINE, .location = { .start = if_keyword->start, @@ -2592,7 +2592,7 @@ yp_if_node_modifier_create(yp_parser_t *parser, yp_node_t *statement, const yp_t *node = (yp_if_node_t) { { - .type = YP_NODE_IF_NODE, + .type = YP_IF_NODE, .flags = YP_NODE_FLAG_NEWLINE, .location = { .start = statement->location.start, @@ -2627,7 +2627,7 @@ yp_if_node_ternary_create(yp_parser_t *parser, yp_node_t *predicate, yp_node_t * *node = (yp_if_node_t) { { - .type = YP_NODE_IF_NODE, + .type = YP_IF_NODE, .flags = YP_NODE_FLAG_NEWLINE, .location = { .start = predicate->location.start, @@ -2662,7 +2662,7 @@ static yp_integer_node_t * yp_integer_node_create(yp_parser_t *parser, const yp_token_t *token) { assert(token->type == YP_TOKEN_INTEGER); yp_integer_node_t *node = YP_ALLOC_NODE(parser, yp_integer_node_t); - *node = (yp_integer_node_t) {{ .type = YP_NODE_INTEGER_NODE, .location = YP_LOCATION_TOKEN_VALUE(token) }}; + *node = (yp_integer_node_t) {{ .type = YP_INTEGER_NODE, .location = YP_LOCATION_TOKEN_VALUE(token) }}; return node; } @@ -2674,7 +2674,7 @@ yp_integer_node_imaginary_create(yp_parser_t *parser, const yp_token_t *token) { yp_imaginary_node_t *node = YP_ALLOC_NODE(parser, yp_imaginary_node_t); *node = (yp_imaginary_node_t) { { - .type = YP_NODE_IMAGINARY_NODE, + .type = YP_IMAGINARY_NODE, .location = YP_LOCATION_TOKEN_VALUE(token) }, .numeric = (yp_node_t *) yp_integer_node_create(parser, &((yp_token_t) { @@ -2695,7 +2695,7 @@ yp_integer_node_rational_create(yp_parser_t *parser, const yp_token_t *token) { yp_rational_node_t *node = YP_ALLOC_NODE(parser, yp_rational_node_t); *node = (yp_rational_node_t) { { - .type = YP_NODE_RATIONAL_NODE, + .type = YP_RATIONAL_NODE, .location = YP_LOCATION_TOKEN_VALUE(token) }, .numeric = (yp_node_t *) yp_integer_node_create(parser, &((yp_token_t) { @@ -2716,7 +2716,7 @@ yp_integer_node_rational_imaginary_create(yp_parser_t *parser, const yp_token_t yp_imaginary_node_t *node = YP_ALLOC_NODE(parser, yp_imaginary_node_t); *node = (yp_imaginary_node_t) { { - .type = YP_NODE_IMAGINARY_NODE, + .type = YP_IMAGINARY_NODE, .location = YP_LOCATION_TOKEN_VALUE(token) }, .numeric = (yp_node_t *) yp_integer_node_rational_create(parser, &((yp_token_t) { @@ -2745,7 +2745,7 @@ yp_in_node_create(yp_parser_t *parser, yp_node_t *pattern, yp_statements_node_t *node = (yp_in_node_t) { { - .type = YP_NODE_IN_NODE, + .type = YP_IN_NODE, .location = { .start = in_keyword->start, .end = end @@ -2768,7 +2768,7 @@ yp_instance_variable_and_write_node_create(yp_parser_t *parser, yp_instance_vari *node = (yp_instance_variable_and_write_node_t) { { - .type = YP_NODE_INSTANCE_VARIABLE_AND_WRITE_NODE, + .type = YP_INSTANCE_VARIABLE_AND_WRITE_NODE, .location = { .start = target->base.location.start, .end = value->location.end @@ -2790,7 +2790,7 @@ yp_instance_variable_operator_write_node_create(yp_parser_t *parser, yp_instance *node = (yp_instance_variable_operator_write_node_t) { { - .type = YP_NODE_INSTANCE_VARIABLE_OPERATOR_WRITE_NODE, + .type = YP_INSTANCE_VARIABLE_OPERATOR_WRITE_NODE, .location = { .start = target->base.location.start, .end = value->location.end @@ -2814,7 +2814,7 @@ yp_instance_variable_or_write_node_create(yp_parser_t *parser, yp_instance_varia *node = (yp_instance_variable_or_write_node_t) { { - .type = YP_NODE_INSTANCE_VARIABLE_OR_WRITE_NODE, + .type = YP_INSTANCE_VARIABLE_OR_WRITE_NODE, .location = { .start = target->base.location.start, .end = value->location.end @@ -2837,7 +2837,7 @@ yp_instance_variable_read_node_create(yp_parser_t *parser, const yp_token_t *tok *node = (yp_instance_variable_read_node_t) { { - .type = YP_NODE_INSTANCE_VARIABLE_READ_NODE, + .type = YP_INSTANCE_VARIABLE_READ_NODE, .location = YP_LOCATION_TOKEN_VALUE(token) }, .name = yp_parser_constant_id_location(parser, token->start, token->end) @@ -2852,7 +2852,7 @@ yp_instance_variable_write_node_create(yp_parser_t *parser, yp_instance_variable yp_instance_variable_write_node_t *node = YP_ALLOC_NODE(parser, yp_instance_variable_write_node_t); *node = (yp_instance_variable_write_node_t) { { - .type = YP_NODE_INSTANCE_VARIABLE_WRITE_NODE, + .type = YP_INSTANCE_VARIABLE_WRITE_NODE, .location = { .start = read_node->base.location.start, .end = value->location.end @@ -2874,7 +2874,7 @@ yp_interpolated_regular_expression_node_create(yp_parser_t *parser, const yp_tok *node = (yp_interpolated_regular_expression_node_t) { { - .type = YP_NODE_INTERPOLATED_REGULAR_EXPRESSION_NODE, + .type = YP_INTERPOLATED_REGULAR_EXPRESSION_NODE, .location = { .start = opening->start, .end = NULL, @@ -2913,7 +2913,7 @@ yp_interpolated_string_node_create(yp_parser_t *parser, const yp_token_t *openin *node = (yp_interpolated_string_node_t) { { - .type = YP_NODE_INTERPOLATED_STRING_NODE, + .type = YP_INTERPOLATED_STRING_NODE, .location = { .start = opening->start, .end = closing->end, @@ -2952,7 +2952,7 @@ yp_interpolated_symbol_node_create(yp_parser_t *parser, const yp_token_t *openin *node = (yp_interpolated_symbol_node_t) { { - .type = YP_NODE_INTERPOLATED_SYMBOL_NODE, + .type = YP_INTERPOLATED_SYMBOL_NODE, .location = { .start = opening->start, .end = closing->end, @@ -2983,7 +2983,7 @@ yp_interpolated_xstring_node_create(yp_parser_t *parser, const yp_token_t *openi *node = (yp_interpolated_x_string_node_t) { { - .type = YP_NODE_INTERPOLATED_X_STRING_NODE, + .type = YP_INTERPOLATED_X_STRING_NODE, .location = { .start = opening->start, .end = closing->end @@ -3016,7 +3016,7 @@ yp_keyword_hash_node_create(yp_parser_t *parser) { *node = (yp_keyword_hash_node_t) { .base = { - .type = YP_NODE_KEYWORD_HASH_NODE, + .type = YP_KEYWORD_HASH_NODE, .location = { .start = NULL, .end = NULL @@ -3045,7 +3045,7 @@ yp_keyword_parameter_node_create(yp_parser_t *parser, const yp_token_t *name, yp *node = (yp_keyword_parameter_node_t) { { - .type = YP_NODE_KEYWORD_PARAMETER_NODE, + .type = YP_KEYWORD_PARAMETER_NODE, .location = { .start = name->start, .end = value == NULL ? name->end : value->location.end @@ -3065,7 +3065,7 @@ yp_keyword_rest_parameter_node_create(yp_parser_t *parser, const yp_token_t *ope *node = (yp_keyword_rest_parameter_node_t) { { - .type = YP_NODE_KEYWORD_REST_PARAMETER_NODE, + .type = YP_KEYWORD_REST_PARAMETER_NODE, .location = { .start = operator->start, .end = (name->type == YP_TOKEN_NOT_PROVIDED ? operator->end : name->end) @@ -3093,7 +3093,7 @@ yp_lambda_node_create( *node = (yp_lambda_node_t) { { - .type = YP_NODE_LAMBDA_NODE, + .type = YP_LAMBDA_NODE, .location = { .start = operator->start, .end = closing->end @@ -3113,13 +3113,13 @@ yp_lambda_node_create( // Allocate and initialize a new LocalVariableAndWriteNode node. static yp_local_variable_and_write_node_t * yp_local_variable_and_write_node_create(yp_parser_t *parser, yp_node_t *target, const yp_token_t *operator, yp_node_t *value, yp_constant_id_t name, uint32_t depth) { - assert(YP_NODE_TYPE_P(target, YP_NODE_LOCAL_VARIABLE_READ_NODE) || YP_NODE_TYPE_P(target, YP_NODE_CALL_NODE)); + assert(YP_NODE_TYPE_P(target, YP_LOCAL_VARIABLE_READ_NODE) || YP_NODE_TYPE_P(target, YP_CALL_NODE)); assert(operator->type == YP_TOKEN_AMPERSAND_AMPERSAND_EQUAL); yp_local_variable_and_write_node_t *node = YP_ALLOC_NODE(parser, yp_local_variable_and_write_node_t); *node = (yp_local_variable_and_write_node_t) { { - .type = YP_NODE_LOCAL_VARIABLE_AND_WRITE_NODE, + .type = YP_LOCAL_VARIABLE_AND_WRITE_NODE, .location = { .start = target->location.start, .end = value->location.end @@ -3142,7 +3142,7 @@ yp_local_variable_operator_write_node_create(yp_parser_t *parser, yp_node_t *tar *node = (yp_local_variable_operator_write_node_t) { { - .type = YP_NODE_LOCAL_VARIABLE_OPERATOR_WRITE_NODE, + .type = YP_LOCAL_VARIABLE_OPERATOR_WRITE_NODE, .location = { .start = target->location.start, .end = value->location.end @@ -3162,13 +3162,13 @@ yp_local_variable_operator_write_node_create(yp_parser_t *parser, yp_node_t *tar // Allocate and initialize a new LocalVariableOrWriteNode node. static yp_local_variable_or_write_node_t * yp_local_variable_or_write_node_create(yp_parser_t *parser, yp_node_t *target, const yp_token_t *operator, yp_node_t *value, yp_constant_id_t name, uint32_t depth) { - assert(YP_NODE_TYPE_P(target, YP_NODE_LOCAL_VARIABLE_READ_NODE) || YP_NODE_TYPE_P(target, YP_NODE_CALL_NODE)); + assert(YP_NODE_TYPE_P(target, YP_LOCAL_VARIABLE_READ_NODE) || YP_NODE_TYPE_P(target, YP_CALL_NODE)); assert(operator->type == YP_TOKEN_PIPE_PIPE_EQUAL); yp_local_variable_or_write_node_t *node = YP_ALLOC_NODE(parser, yp_local_variable_or_write_node_t); *node = (yp_local_variable_or_write_node_t) { { - .type = YP_NODE_LOCAL_VARIABLE_OR_WRITE_NODE, + .type = YP_LOCAL_VARIABLE_OR_WRITE_NODE, .location = { .start = target->location.start, .end = value->location.end @@ -3191,7 +3191,7 @@ yp_local_variable_read_node_create(yp_parser_t *parser, const yp_token_t *name, *node = (yp_local_variable_read_node_t) { { - .type = YP_NODE_LOCAL_VARIABLE_READ_NODE, + .type = YP_LOCAL_VARIABLE_READ_NODE, .location = YP_LOCATION_TOKEN_VALUE(name) }, .name = yp_parser_constant_id_token(parser, name), @@ -3208,7 +3208,7 @@ yp_local_variable_write_node_create(yp_parser_t *parser, yp_constant_id_t name, *node = (yp_local_variable_write_node_t) { { - .type = YP_NODE_LOCAL_VARIABLE_WRITE_NODE, + .type = YP_LOCAL_VARIABLE_WRITE_NODE, .location = { .start = name_loc->start, .end = value->location.end @@ -3231,7 +3231,7 @@ yp_local_variable_target_node_create(yp_parser_t *parser, const yp_token_t *name *node = (yp_local_variable_target_node_t) { { - .type = YP_NODE_LOCAL_VARIABLE_TARGET_NODE, + .type = YP_LOCAL_VARIABLE_TARGET_NODE, .location = YP_LOCATION_TOKEN_VALUE(name) }, .name = yp_parser_constant_id_token(parser, name), @@ -3248,7 +3248,7 @@ yp_match_predicate_node_create(yp_parser_t *parser, yp_node_t *value, yp_node_t *node = (yp_match_predicate_node_t) { { - .type = YP_NODE_MATCH_PREDICATE_NODE, + .type = YP_MATCH_PREDICATE_NODE, .location = { .start = value->location.start, .end = pattern->location.end @@ -3269,7 +3269,7 @@ yp_match_required_node_create(yp_parser_t *parser, yp_node_t *value, yp_node_t * *node = (yp_match_required_node_t) { { - .type = YP_NODE_MATCH_REQUIRED_NODE, + .type = YP_MATCH_REQUIRED_NODE, .location = { .start = value->location.start, .end = pattern->location.end @@ -3290,7 +3290,7 @@ yp_module_node_create(yp_parser_t *parser, yp_constant_id_list_t *locals, const *node = (yp_module_node_t) { { - .type = YP_NODE_MODULE_NODE, + .type = YP_MODULE_NODE, .location = { .start = module_keyword->start, .end = end_keyword->end @@ -3315,7 +3315,7 @@ yp_multi_write_node_create(yp_parser_t *parser, const yp_token_t *operator, yp_n *node = (yp_multi_write_node_t) { { - .type = YP_NODE_MULTI_WRITE_NODE, + .type = YP_MULTI_WRITE_NODE, .location = { .start = lparen_loc->start, .end = value == NULL ? rparen_loc->end : value->location.end @@ -3358,7 +3358,7 @@ yp_next_node_create(yp_parser_t *parser, const yp_token_t *keyword, yp_arguments *node = (yp_next_node_t) { { - .type = YP_NODE_NEXT_NODE, + .type = YP_NEXT_NODE, .location = { .start = keyword->start, .end = (arguments == NULL ? keyword->end : arguments->base.location.end) @@ -3377,7 +3377,7 @@ yp_nil_node_create(yp_parser_t *parser, const yp_token_t *token) { assert(token->type == YP_TOKEN_KEYWORD_NIL); yp_nil_node_t *node = YP_ALLOC_NODE(parser, yp_nil_node_t); - *node = (yp_nil_node_t) {{ .type = YP_NODE_NIL_NODE, .location = YP_LOCATION_TOKEN_VALUE(token) }}; + *node = (yp_nil_node_t) {{ .type = YP_NIL_NODE, .location = YP_LOCATION_TOKEN_VALUE(token) }}; return node; } @@ -3390,7 +3390,7 @@ yp_no_keywords_parameter_node_create(yp_parser_t *parser, const yp_token_t *oper *node = (yp_no_keywords_parameter_node_t) { { - .type = YP_NODE_NO_KEYWORDS_PARAMETER_NODE, + .type = YP_NO_KEYWORDS_PARAMETER_NODE, .location = { .start = operator->start, .end = keyword->end @@ -3411,7 +3411,7 @@ yp_numbered_reference_read_node_create(yp_parser_t *parser, const yp_token_t *na *node = (yp_numbered_reference_read_node_t) { { - .type = YP_NODE_NUMBERED_REFERENCE_READ_NODE, + .type = YP_NUMBERED_REFERENCE_READ_NODE, .location = YP_LOCATION_TOKEN_VALUE(name), }, .number = parse_decimal_number(parser, name->start + 1, name->end) @@ -3427,7 +3427,7 @@ yp_optional_parameter_node_create(yp_parser_t *parser, const yp_token_t *name, c *node = (yp_optional_parameter_node_t) { { - .type = YP_NODE_OPTIONAL_PARAMETER_NODE, + .type = YP_OPTIONAL_PARAMETER_NODE, .location = { .start = name->start, .end = value->location.end @@ -3449,7 +3449,7 @@ yp_or_node_create(yp_parser_t *parser, yp_node_t *left, const yp_token_t *operat *node = (yp_or_node_t) { { - .type = YP_NODE_OR_NODE, + .type = YP_OR_NODE, .location = { .start = left->location.start, .end = right->location.end @@ -3470,7 +3470,7 @@ yp_parameters_node_create(yp_parser_t *parser) { *node = (yp_parameters_node_t) { { - .type = YP_NODE_PARAMETERS_NODE, + .type = YP_PARAMETERS_NODE, .location = { .start = parser->current.start, .end = parser->current.start }, }, .rest = NULL, @@ -3560,7 +3560,7 @@ yp_program_node_create(yp_parser_t *parser, yp_constant_id_list_t *locals, yp_st *node = (yp_program_node_t) { { - .type = YP_NODE_PROGRAM_NODE, + .type = YP_PROGRAM_NODE, .location = { .start = statements == NULL ? parser->start : statements->base.location.start, .end = statements == NULL ? parser->end : statements->base.location.end @@ -3580,7 +3580,7 @@ yp_parentheses_node_create(yp_parser_t *parser, const yp_token_t *opening, yp_no *node = (yp_parentheses_node_t) { { - .type = YP_NODE_PARENTHESES_NODE, + .type = YP_PARENTHESES_NODE, .location = { .start = opening->start, .end = closing->end @@ -3601,7 +3601,7 @@ yp_pinned_expression_node_create(yp_parser_t *parser, yp_node_t *expression, con *node = (yp_pinned_expression_node_t) { { - .type = YP_NODE_PINNED_EXPRESSION_NODE, + .type = YP_PINNED_EXPRESSION_NODE, .location = { .start = operator->start, .end = rparen->end @@ -3623,7 +3623,7 @@ yp_pinned_variable_node_create(yp_parser_t *parser, const yp_token_t *operator, *node = (yp_pinned_variable_node_t) { { - .type = YP_NODE_PINNED_VARIABLE_NODE, + .type = YP_PINNED_VARIABLE_NODE, .location = { .start = operator->start, .end = variable->location.end @@ -3643,7 +3643,7 @@ yp_post_execution_node_create(yp_parser_t *parser, const yp_token_t *keyword, co *node = (yp_post_execution_node_t) { { - .type = YP_NODE_POST_EXECUTION_NODE, + .type = YP_POST_EXECUTION_NODE, .location = { .start = keyword->start, .end = closing->end @@ -3665,7 +3665,7 @@ yp_pre_execution_node_create(yp_parser_t *parser, const yp_token_t *keyword, con *node = (yp_pre_execution_node_t) { { - .type = YP_NODE_PRE_EXECUTION_NODE, + .type = YP_PRE_EXECUTION_NODE, .location = { .start = keyword->start, .end = closing->end @@ -3687,7 +3687,7 @@ yp_range_node_create(yp_parser_t *parser, yp_node_t *left, const yp_token_t *ope *node = (yp_range_node_t) { { - .type = YP_NODE_RANGE_NODE, + .type = YP_RANGE_NODE, .location = { .start = (left == NULL ? operator->start : left->location.start), .end = (right == NULL ? operator->end : right->location.end) @@ -3716,7 +3716,7 @@ yp_redo_node_create(yp_parser_t *parser, const yp_token_t *token) { assert(token->type == YP_TOKEN_KEYWORD_REDO); yp_redo_node_t *node = YP_ALLOC_NODE(parser, yp_redo_node_t); - *node = (yp_redo_node_t) {{ .type = YP_NODE_REDO_NODE, .location = YP_LOCATION_TOKEN_VALUE(token) }}; + *node = (yp_redo_node_t) {{ .type = YP_REDO_NODE, .location = YP_LOCATION_TOKEN_VALUE(token) }}; return node; } @@ -3727,7 +3727,7 @@ yp_regular_expression_node_create(yp_parser_t *parser, const yp_token_t *opening *node = (yp_regular_expression_node_t) { { - .type = YP_NODE_REGULAR_EXPRESSION_NODE, + .type = YP_REGULAR_EXPRESSION_NODE, .flags = yp_regular_expression_flags_create(closing), .location = { .start = MIN(opening->start, closing->start), @@ -3750,7 +3750,7 @@ yp_required_destructured_parameter_node_create(yp_parser_t *parser, const yp_tok *node = (yp_required_destructured_parameter_node_t) { { - .type = YP_NODE_REQUIRED_DESTRUCTURED_PARAMETER_NODE, + .type = YP_REQUIRED_DESTRUCTURED_PARAMETER_NODE, .location = YP_LOCATION_TOKEN_VALUE(opening) }, .opening_loc = YP_LOCATION_TOKEN_VALUE(opening), @@ -3781,7 +3781,7 @@ yp_required_parameter_node_create(yp_parser_t *parser, const yp_token_t *token) *node = (yp_required_parameter_node_t) { { - .type = YP_NODE_REQUIRED_PARAMETER_NODE, + .type = YP_REQUIRED_PARAMETER_NODE, .location = YP_LOCATION_TOKEN_VALUE(token) }, .name = yp_parser_constant_id_token(parser, token) @@ -3797,7 +3797,7 @@ yp_rescue_modifier_node_create(yp_parser_t *parser, yp_node_t *expression, const *node = (yp_rescue_modifier_node_t) { { - .type = YP_NODE_RESCUE_MODIFIER_NODE, + .type = YP_RESCUE_MODIFIER_NODE, .location = { .start = expression->location.start, .end = rescue_expression->location.end @@ -3818,7 +3818,7 @@ yp_rescue_node_create(yp_parser_t *parser, const yp_token_t *keyword) { *node = (yp_rescue_node_t) { { - .type = YP_NODE_RESCUE_NODE, + .type = YP_RESCUE_NODE, .location = { .start = keyword->start, .end = keyword->end @@ -3877,7 +3877,7 @@ yp_rest_parameter_node_create(yp_parser_t *parser, const yp_token_t *operator, c *node = (yp_rest_parameter_node_t) { { - .type = YP_NODE_REST_PARAMETER_NODE, + .type = YP_REST_PARAMETER_NODE, .location = { .start = operator->start, .end = (name->type == YP_TOKEN_NOT_PROVIDED ? operator->end : name->end) @@ -3896,7 +3896,7 @@ yp_retry_node_create(yp_parser_t *parser, const yp_token_t *token) { assert(token->type == YP_TOKEN_KEYWORD_RETRY); yp_retry_node_t *node = YP_ALLOC_NODE(parser, yp_retry_node_t); - *node = (yp_retry_node_t) {{ .type = YP_NODE_RETRY_NODE, .location = YP_LOCATION_TOKEN_VALUE(token) }}; + *node = (yp_retry_node_t) {{ .type = YP_RETRY_NODE, .location = YP_LOCATION_TOKEN_VALUE(token) }}; return node; } @@ -3907,7 +3907,7 @@ yp_return_node_create(yp_parser_t *parser, const yp_token_t *keyword, yp_argumen *node = (yp_return_node_t) { { - .type = YP_NODE_RETURN_NODE, + .type = YP_RETURN_NODE, .location = { .start = keyword->start, .end = (arguments == NULL ? keyword->end : arguments->base.location.end) @@ -3926,7 +3926,7 @@ yp_self_node_create(yp_parser_t *parser, const yp_token_t *token) { assert(token->type == YP_TOKEN_KEYWORD_SELF); yp_self_node_t *node = YP_ALLOC_NODE(parser, yp_self_node_t); - *node = (yp_self_node_t) {{ .type = YP_NODE_SELF_NODE, .location = YP_LOCATION_TOKEN_VALUE(token) }}; + *node = (yp_self_node_t) {{ .type = YP_SELF_NODE, .location = YP_LOCATION_TOKEN_VALUE(token) }}; return node; } @@ -3937,7 +3937,7 @@ yp_singleton_class_node_create(yp_parser_t *parser, yp_constant_id_list_t *local *node = (yp_singleton_class_node_t) { { - .type = YP_NODE_SINGLETON_CLASS_NODE, + .type = YP_SINGLETON_CLASS_NODE, .location = { .start = class_keyword->start, .end = end_keyword->end @@ -3960,7 +3960,7 @@ yp_source_encoding_node_create(yp_parser_t *parser, const yp_token_t *token) { assert(token->type == YP_TOKEN_KEYWORD___ENCODING__); yp_source_encoding_node_t *node = YP_ALLOC_NODE(parser, yp_source_encoding_node_t); - *node = (yp_source_encoding_node_t) {{ .type = YP_NODE_SOURCE_ENCODING_NODE, .location = YP_LOCATION_TOKEN_VALUE(token) }}; + *node = (yp_source_encoding_node_t) {{ .type = YP_SOURCE_ENCODING_NODE, .location = YP_LOCATION_TOKEN_VALUE(token) }}; return node; } @@ -3972,7 +3972,7 @@ yp_source_file_node_create(yp_parser_t *parser, const yp_token_t *file_keyword) *node = (yp_source_file_node_t) { { - .type = YP_NODE_SOURCE_FILE_NODE, + .type = YP_SOURCE_FILE_NODE, .location = YP_LOCATION_TOKEN_VALUE(file_keyword), }, .filepath = parser->filepath_string, @@ -3987,7 +3987,7 @@ yp_source_line_node_create(yp_parser_t *parser, const yp_token_t *token) { assert(token->type == YP_TOKEN_KEYWORD___LINE__); yp_source_line_node_t *node = YP_ALLOC_NODE(parser, yp_source_line_node_t); - *node = (yp_source_line_node_t) {{ .type = YP_NODE_SOURCE_LINE_NODE, .location = YP_LOCATION_TOKEN_VALUE(token) }}; + *node = (yp_source_line_node_t) {{ .type = YP_SOURCE_LINE_NODE, .location = YP_LOCATION_TOKEN_VALUE(token) }}; return node; } @@ -3998,7 +3998,7 @@ yp_splat_node_create(yp_parser_t *parser, const yp_token_t *operator, yp_node_t *node = (yp_splat_node_t) { { - .type = YP_NODE_SPLAT_NODE, + .type = YP_SPLAT_NODE, .location = { .start = operator->start, .end = (expression == NULL ? operator->end : expression->location.end) @@ -4018,7 +4018,7 @@ yp_statements_node_create(yp_parser_t *parser) { *node = (yp_statements_node_t) { { - .type = YP_NODE_STATEMENTS_NODE, + .type = YP_STATEMENTS_NODE, .location = YP_LOCATION_NULL_VALUE(parser) }, .body = YP_EMPTY_NODE_LIST @@ -4062,7 +4062,7 @@ yp_string_concat_node_create(yp_parser_t *parser, yp_node_t *left, yp_node_t *ri *node = (yp_string_concat_node_t) { { - .type = YP_NODE_STRING_CONCAT_NODE, + .type = YP_STRING_CONCAT_NODE, .location = { .start = left->location.start, .end = right->location.end @@ -4082,7 +4082,7 @@ yp_string_node_create(yp_parser_t *parser, const yp_token_t *opening, const yp_t *node = (yp_string_node_t) { { - .type = YP_NODE_STRING_NODE, + .type = YP_STRING_NODE, .location = { .start = (opening->type == YP_TOKEN_NOT_PROVIDED ? content->start : opening->start), .end = (closing->type == YP_TOKEN_NOT_PROVIDED ? content->end : closing->end) @@ -4117,7 +4117,7 @@ yp_super_node_create(yp_parser_t *parser, const yp_token_t *keyword, yp_argument *node = (yp_super_node_t) { { - .type = YP_NODE_SUPER_NODE, + .type = YP_SUPER_NODE, .location = { .start = keyword->start, .end = end, @@ -4140,7 +4140,7 @@ yp_symbol_node_create(yp_parser_t *parser, const yp_token_t *opening, const yp_t *node = (yp_symbol_node_t) { { - .type = YP_NODE_SYMBOL_NODE, + .type = YP_SYMBOL_NODE, .location = { .start = (opening->type == YP_TOKEN_NOT_PROVIDED ? value->start : opening->start), .end = (closing->type == YP_TOKEN_NOT_PROVIDED ? value->end : closing->end) @@ -4197,10 +4197,10 @@ yp_symbol_node_label_p(yp_node_t *node) { const uint8_t *end = NULL; switch (YP_NODE_TYPE(node)) { - case YP_NODE_SYMBOL_NODE: + case YP_SYMBOL_NODE: end = ((yp_symbol_node_t *) node)->closing_loc.end; break; - case YP_NODE_INTERPOLATED_SYMBOL_NODE: + case YP_INTERPOLATED_SYMBOL_NODE: end = ((yp_interpolated_symbol_node_t *) node)->closing_loc.end; break; default: @@ -4217,7 +4217,7 @@ yp_string_node_to_symbol_node(yp_parser_t *parser, yp_string_node_t *node, const *new_node = (yp_symbol_node_t) { { - .type = YP_NODE_SYMBOL_NODE, + .type = YP_SYMBOL_NODE, .location = { .start = opening->start, .end = closing->end @@ -4244,7 +4244,7 @@ yp_symbol_node_to_string_node(yp_parser_t *parser, yp_symbol_node_t *node) { *new_node = (yp_string_node_t) { { - .type = YP_NODE_STRING_NODE, + .type = YP_STRING_NODE, .location = node->base.location }, .opening_loc = node->opening_loc, @@ -4267,7 +4267,7 @@ yp_true_node_create(yp_parser_t *parser, const yp_token_t *token) { assert(token->type == YP_TOKEN_KEYWORD_TRUE); yp_true_node_t *node = YP_ALLOC_NODE(parser, yp_true_node_t); - *node = (yp_true_node_t) {{ .type = YP_NODE_TRUE_NODE, .location = YP_LOCATION_TOKEN_VALUE(token) }}; + *node = (yp_true_node_t) {{ .type = YP_TRUE_NODE, .location = YP_LOCATION_TOKEN_VALUE(token) }}; return node; } @@ -4279,7 +4279,7 @@ yp_undef_node_create(yp_parser_t *parser, const yp_token_t *token) { *node = (yp_undef_node_t) { { - .type = YP_NODE_UNDEF_NODE, + .type = YP_UNDEF_NODE, .location = YP_LOCATION_TOKEN_VALUE(token), }, .keyword_loc = YP_LOCATION_TOKEN_VALUE(token), @@ -4311,7 +4311,7 @@ yp_unless_node_create(yp_parser_t *parser, const yp_token_t *keyword, yp_node_t *node = (yp_unless_node_t) { { - .type = YP_NODE_UNLESS_NODE, + .type = YP_UNLESS_NODE, .flags = YP_NODE_FLAG_NEWLINE, .location = { .start = keyword->start, @@ -4339,7 +4339,7 @@ yp_unless_node_modifier_create(yp_parser_t *parser, yp_node_t *statement, const *node = (yp_unless_node_t) { { - .type = YP_NODE_UNLESS_NODE, + .type = YP_UNLESS_NODE, .flags = YP_NODE_FLAG_NEWLINE, .location = { .start = statement->location.start, @@ -4369,7 +4369,7 @@ yp_until_node_create(yp_parser_t *parser, const yp_token_t *keyword, const yp_to *node = (yp_until_node_t) { { - .type = YP_NODE_UNTIL_NODE, + .type = YP_UNTIL_NODE, .flags = flags, .location = { .start = keyword->start, @@ -4392,7 +4392,7 @@ yp_until_node_modifier_create(yp_parser_t *parser, const yp_token_t *keyword, yp *node = (yp_until_node_t) { { - .type = YP_NODE_UNTIL_NODE, + .type = YP_UNTIL_NODE, .flags = flags, .location = { .start = statements->base.location.start, @@ -4415,7 +4415,7 @@ yp_when_node_create(yp_parser_t *parser, const yp_token_t *keyword) { *node = (yp_when_node_t) { { - .type = YP_NODE_WHEN_NODE, + .type = YP_WHEN_NODE, .location = { .start = keyword->start, .end = NULL @@ -4453,7 +4453,7 @@ yp_while_node_create(yp_parser_t *parser, const yp_token_t *keyword, const yp_to *node = (yp_while_node_t) { { - .type = YP_NODE_WHILE_NODE, + .type = YP_WHILE_NODE, .flags = flags, .location = { .start = keyword->start, @@ -4476,7 +4476,7 @@ yp_while_node_modifier_create(yp_parser_t *parser, const yp_token_t *keyword, yp *node = (yp_while_node_t) { { - .type = YP_NODE_WHILE_NODE, + .type = YP_WHILE_NODE, .flags = flags, .location = { .start = statements->base.location.start, @@ -4499,7 +4499,7 @@ yp_xstring_node_create(yp_parser_t *parser, const yp_token_t *opening, const yp_ *node = (yp_x_string_node_t) { { - .type = YP_NODE_X_STRING_NODE, + .type = YP_X_STRING_NODE, .location = { .start = opening->start, .end = closing->end @@ -4532,7 +4532,7 @@ yp_yield_node_create(yp_parser_t *parser, const yp_token_t *keyword, const yp_lo *node = (yp_yield_node_t) { { - .type = YP_NODE_YIELD_NODE, + .type = YP_YIELD_NODE, .location = { .start = keyword->start, .end = end @@ -8022,42 +8022,42 @@ parse_starred_expression(yp_parser_t *parser, yp_binding_power_t binding_power, static yp_node_t * parse_target(yp_parser_t *parser, yp_node_t *target) { switch (YP_NODE_TYPE(target)) { - case YP_NODE_MISSING_NODE: + case YP_MISSING_NODE: return target; - case YP_NODE_CLASS_VARIABLE_READ_NODE: + case YP_CLASS_VARIABLE_READ_NODE: assert(sizeof(yp_class_variable_target_node_t) == sizeof(yp_class_variable_read_node_t)); - target->type = YP_NODE_CLASS_VARIABLE_TARGET_NODE; + target->type = YP_CLASS_VARIABLE_TARGET_NODE; return target; - case YP_NODE_CONSTANT_PATH_NODE: + case YP_CONSTANT_PATH_NODE: assert(sizeof(yp_constant_path_target_node_t) == sizeof(yp_constant_path_node_t)); - target->type = YP_NODE_CONSTANT_PATH_TARGET_NODE; + target->type = YP_CONSTANT_PATH_TARGET_NODE; return target; - case YP_NODE_CONSTANT_READ_NODE: + case YP_CONSTANT_READ_NODE: assert(sizeof(yp_constant_target_node_t) == sizeof(yp_constant_read_node_t)); - target->type = YP_NODE_CONSTANT_TARGET_NODE; + target->type = YP_CONSTANT_TARGET_NODE; return target; - case YP_NODE_BACK_REFERENCE_READ_NODE: + case YP_BACK_REFERENCE_READ_NODE: assert(sizeof(yp_global_variable_target_node_t) == sizeof(yp_back_reference_read_node_t)); /* fallthrough */ - case YP_NODE_NUMBERED_REFERENCE_READ_NODE: + case YP_NUMBERED_REFERENCE_READ_NODE: assert(sizeof(yp_global_variable_target_node_t) == sizeof(yp_numbered_reference_read_node_t)); yp_diagnostic_list_append(&parser->error_list, target->location.start, target->location.end, "Can't set variable"); /* fallthrough */ - case YP_NODE_GLOBAL_VARIABLE_READ_NODE: + case YP_GLOBAL_VARIABLE_READ_NODE: assert(sizeof(yp_global_variable_target_node_t) == sizeof(yp_global_variable_read_node_t)); - target->type = YP_NODE_GLOBAL_VARIABLE_TARGET_NODE; + target->type = YP_GLOBAL_VARIABLE_TARGET_NODE; return target; - case YP_NODE_LOCAL_VARIABLE_READ_NODE: + case YP_LOCAL_VARIABLE_READ_NODE: assert(sizeof(yp_local_variable_target_node_t) == sizeof(yp_local_variable_read_node_t)); - target->type = YP_NODE_LOCAL_VARIABLE_TARGET_NODE; + target->type = YP_LOCAL_VARIABLE_TARGET_NODE; return target; - case YP_NODE_INSTANCE_VARIABLE_READ_NODE: + case YP_INSTANCE_VARIABLE_READ_NODE: assert(sizeof(yp_instance_variable_target_node_t) == sizeof(yp_instance_variable_read_node_t)); - target->type = YP_NODE_INSTANCE_VARIABLE_TARGET_NODE; + target->type = YP_INSTANCE_VARIABLE_TARGET_NODE; return target; - case YP_NODE_MULTI_WRITE_NODE: + case YP_MULTI_WRITE_NODE: return target; - case YP_NODE_SPLAT_NODE: { + case YP_SPLAT_NODE: { yp_splat_node_t *splat = (yp_splat_node_t *) target; if (splat->expression != NULL) { @@ -8072,7 +8072,7 @@ parse_target(yp_parser_t *parser, yp_node_t *target) { return (yp_node_t *) multi_write; } - case YP_NODE_CALL_NODE: { + case YP_CALL_NODE: { yp_call_node_t *call = (yp_call_node_t *) target; // If we have no arguments to the call node and we need this to be a @@ -8101,7 +8101,7 @@ parse_target(yp_parser_t *parser, yp_node_t *target) { target = (yp_node_t *) yp_local_variable_read_node_create(parser, &name, 0); assert(sizeof(yp_local_variable_target_node_t) == sizeof(yp_local_variable_read_node_t)); - target->type = YP_NODE_LOCAL_VARIABLE_TARGET_NODE; + target->type = YP_LOCAL_VARIABLE_TARGET_NODE; if (token_is_numbered_parameter(message.start, message.end)) { yp_diagnostic_list_append(&parser->error_list, message.start, message.end, "reserved for numbered parameter"); @@ -8157,30 +8157,30 @@ parse_target(yp_parser_t *parser, yp_node_t *target) { static yp_node_t * parse_write(yp_parser_t *parser, yp_node_t *target, yp_token_t *operator, yp_node_t *value) { switch (YP_NODE_TYPE(target)) { - case YP_NODE_MISSING_NODE: + case YP_MISSING_NODE: return target; - case YP_NODE_CLASS_VARIABLE_READ_NODE: { + case YP_CLASS_VARIABLE_READ_NODE: { yp_class_variable_write_node_t *node = yp_class_variable_write_node_create(parser, (yp_class_variable_read_node_t *) target, operator, value); yp_node_destroy(parser, target); return (yp_node_t *) node; } - case YP_NODE_CONSTANT_PATH_NODE: + case YP_CONSTANT_PATH_NODE: return (yp_node_t *) yp_constant_path_write_node_create(parser, (yp_constant_path_node_t *) target, operator, value); - case YP_NODE_CONSTANT_READ_NODE: { + case YP_CONSTANT_READ_NODE: { yp_constant_write_node_t *node = yp_constant_write_node_create(parser, &target->location, operator, value); yp_node_destroy(parser, target); return (yp_node_t *) node; } - case YP_NODE_BACK_REFERENCE_READ_NODE: - case YP_NODE_NUMBERED_REFERENCE_READ_NODE: + case YP_BACK_REFERENCE_READ_NODE: + case YP_NUMBERED_REFERENCE_READ_NODE: yp_diagnostic_list_append(&parser->error_list, target->location.start, target->location.end, "Can't set variable"); /* fallthrough */ - case YP_NODE_GLOBAL_VARIABLE_READ_NODE: { + case YP_GLOBAL_VARIABLE_READ_NODE: { yp_global_variable_write_node_t *node = yp_global_variable_write_node_create(parser, target, operator, value); yp_node_destroy(parser, target); return (yp_node_t *) node; } - case YP_NODE_LOCAL_VARIABLE_READ_NODE: { + case YP_LOCAL_VARIABLE_READ_NODE: { yp_local_variable_read_node_t *local_read = (yp_local_variable_read_node_t *) target; yp_constant_id_t constant_id = local_read->name; @@ -8191,12 +8191,12 @@ parse_write(yp_parser_t *parser, yp_node_t *target, yp_token_t *operator, yp_nod return (yp_node_t *) yp_local_variable_write_node_create(parser, constant_id, depth, value, &name_loc, operator); } - case YP_NODE_INSTANCE_VARIABLE_READ_NODE: { + case YP_INSTANCE_VARIABLE_READ_NODE: { yp_node_t *write_node = (yp_node_t *) yp_instance_variable_write_node_create(parser, (yp_instance_variable_read_node_t *) target, operator, value); yp_node_destroy(parser, target); return write_node; } - case YP_NODE_MULTI_WRITE_NODE: { + case YP_MULTI_WRITE_NODE: { yp_multi_write_node_t *multi_write = (yp_multi_write_node_t *) target; yp_multi_write_node_operator_loc_set(multi_write, operator); @@ -8204,7 +8204,7 @@ parse_write(yp_parser_t *parser, yp_node_t *target, yp_token_t *operator, yp_nod multi_write->base.location.end = value->location.end; return (yp_node_t *) multi_write; } - case YP_NODE_SPLAT_NODE: { + case YP_SPLAT_NODE: { yp_splat_node_t *splat = (yp_splat_node_t *) target; if (splat->expression != NULL) { @@ -8217,7 +8217,7 @@ parse_write(yp_parser_t *parser, yp_node_t *target, yp_token_t *operator, yp_nod return (yp_node_t *) multi_write; } - case YP_NODE_CALL_NODE: { + case YP_CALL_NODE: { yp_call_node_t *call = (yp_call_node_t *) target; // If we have no arguments to the call node and we need this to be a // target then this is either a method call or a local variable write. @@ -8389,7 +8389,7 @@ parse_targets(yp_parser_t *parser, yp_node_t *first_target, yp_binding_power_t b expect(parser, YP_TOKEN_PARENTHESIS_RIGHT, "Expected an ')' after multi-assignment."); yp_token_t rparen = parser->previous; - if (YP_NODE_TYPE_P(child_target, YP_NODE_MULTI_WRITE_NODE) && first_target == NULL && result->targets.size == 0) { + if (YP_NODE_TYPE_P(child_target, YP_MULTI_WRITE_NODE) && first_target == NULL && result->targets.size == 0) { yp_node_destroy(parser, (yp_node_t *) result); result = (yp_multi_write_node_t *) child_target; result->base.location.start = lparen.start; @@ -8399,7 +8399,7 @@ parse_targets(yp_parser_t *parser, yp_node_t *first_target, yp_binding_power_t b } else { yp_multi_write_node_t *target; - if (YP_NODE_TYPE_P(child_target, YP_NODE_MULTI_WRITE_NODE)) { + if (YP_NODE_TYPE_P(child_target, YP_MULTI_WRITE_NODE)) { target = (yp_multi_write_node_t *) child_target; target->base.location.start = lparen.start; target->base.location.end = rparen.end; @@ -8508,7 +8508,7 @@ parse_statements(yp_parser_t *parser, yp_context_t context) { // were unable to parse an expression, then we will skip past this token and // continue parsing the statements list. Otherwise we'll add an error and // continue parsing the statements list. - if (YP_NODE_TYPE_P(node, YP_NODE_MISSING_NODE)) { + if (YP_NODE_TYPE_P(node, YP_MISSING_NODE)) { parser_lex(parser); while (accept_any(parser, 2, YP_TOKEN_NEWLINE, YP_TOKEN_SEMICOLON)); @@ -8525,7 +8525,7 @@ parse_statements(yp_parser_t *parser, yp_context_t context) { // Parse all of the elements of a hash. static void parse_assocs(yp_parser_t *parser, yp_node_t *node) { - assert(YP_NODE_TYPE_P(node, YP_NODE_HASH_NODE) || YP_NODE_TYPE_P(node, YP_NODE_KEYWORD_HASH_NODE)); + assert(YP_NODE_TYPE_P(node, YP_HASH_NODE) || YP_NODE_TYPE_P(node, YP_KEYWORD_HASH_NODE)); while (true) { yp_node_t *element; @@ -8576,7 +8576,7 @@ parse_assocs(yp_parser_t *parser, yp_node_t *node) { } } - if (YP_NODE_TYPE_P(node, YP_NODE_HASH_NODE)) { + if (YP_NODE_TYPE_P(node, YP_HASH_NODE)) { yp_hash_node_elements_append((yp_hash_node_t *) node, element); } else { yp_keyword_hash_node_elements_append((yp_keyword_hash_node_t *) node, element); @@ -8743,7 +8743,7 @@ parse_arguments(yp_parser_t *parser, yp_arguments_t *arguments, bool accepts_for yp_arguments_node_arguments_append(arguments->arguments, argument); // If parsing the argument failed, we need to stop parsing arguments. - if (YP_NODE_TYPE_P(argument, YP_NODE_MISSING_NODE) || parser->recovering) break; + if (YP_NODE_TYPE_P(argument, YP_MISSING_NODE) || parser->recovering) break; // If the terminator of these arguments is not EOF, then we have a specific // token we're looking for. In that case we can accept a newline here @@ -9412,7 +9412,7 @@ parse_block(yp_parser_t *parser) { } if (match_any_type_p(parser, 2, YP_TOKEN_KEYWORD_RESCUE, YP_TOKEN_KEYWORD_ENSURE)) { - assert(statements == NULL || YP_NODE_TYPE_P(statements, YP_NODE_STATEMENTS_NODE)); + assert(statements == NULL || YP_NODE_TYPE_P(statements, YP_STATEMENTS_NODE)); statements = (yp_node_t *) parse_rescues_as_begin(parser, (yp_statements_node_t *) statements); } } @@ -9576,12 +9576,12 @@ parse_conditional(yp_parser_t *parser, yp_context_t context) { while (recursing) { switch (YP_NODE_TYPE(current)) { - case YP_NODE_IF_NODE: + case YP_IF_NODE: yp_if_node_end_keyword_loc_set((yp_if_node_t *) current, &parser->previous); current = ((yp_if_node_t *) current)->consequent; recursing = current != NULL; break; - case YP_NODE_ELSE_NODE: + case YP_ELSE_NODE: yp_else_node_end_keyword_loc_set((yp_else_node_t *) current, &parser->previous); recursing = false; break; @@ -9652,10 +9652,10 @@ parse_conditional(yp_parser_t *parser, yp_context_t context) { // This macro allows you to define a case statement for all of the nodes that // can be transformed into write targets. -#define YP_CASE_WRITABLE YP_NODE_CLASS_VARIABLE_READ_NODE: case YP_NODE_CONSTANT_PATH_NODE: \ - case YP_NODE_CONSTANT_READ_NODE: case YP_NODE_GLOBAL_VARIABLE_READ_NODE: case YP_NODE_LOCAL_VARIABLE_READ_NODE: \ - case YP_NODE_INSTANCE_VARIABLE_READ_NODE: case YP_NODE_MULTI_WRITE_NODE: case YP_NODE_BACK_REFERENCE_READ_NODE: \ - case YP_NODE_NUMBERED_REFERENCE_READ_NODE +#define YP_CASE_WRITABLE YP_CLASS_VARIABLE_READ_NODE: case YP_CONSTANT_PATH_NODE: \ + case YP_CONSTANT_READ_NODE: case YP_GLOBAL_VARIABLE_READ_NODE: case YP_LOCAL_VARIABLE_READ_NODE: \ + case YP_INSTANCE_VARIABLE_READ_NODE: case YP_MULTI_WRITE_NODE: case YP_BACK_REFERENCE_READ_NODE: \ + case YP_NUMBERED_REFERENCE_READ_NODE // Parse a node that is part of a string. If the subsequent tokens cannot be // parsed as a string part, then NULL is returned. @@ -9834,7 +9834,7 @@ parse_symbol(yp_parser_t *parser, yp_lex_mode_t *lex_mode, yp_lex_state_t next_s // If we got a string part, then it's possible that we could transform // what looks like an interpolated symbol into a regular symbol. - if (part && YP_NODE_TYPE_P(part, YP_NODE_STRING_NODE) && match_any_type_p(parser, 2, YP_TOKEN_STRING_END, YP_TOKEN_EOF)) { + if (part && YP_NODE_TYPE_P(part, YP_STRING_NODE) && match_any_type_p(parser, 2, YP_TOKEN_STRING_END, YP_TOKEN_EOF)) { if (next_state != YP_LEX_STATE_NONE) lex_state_set(parser, next_state); parser_lex(parser); @@ -9988,13 +9988,13 @@ parse_heredoc_common_whitespace(yp_parser_t *parser, yp_node_list_t *nodes) { for (size_t index = 0; index < nodes->size; index++) { yp_node_t *node = nodes->nodes[index]; - if (!YP_NODE_TYPE_P(node, YP_NODE_STRING_NODE)) continue; + if (!YP_NODE_TYPE_P(node, YP_STRING_NODE)) continue; const yp_location_t *content_loc = &((yp_string_node_t *) node)->content_loc; // If the previous node wasn't a string node, we don't want to trim // whitespace. This could happen after an interpolated expression or // variable. - if (index == 0 || YP_NODE_TYPE_P(nodes->nodes[index - 1], YP_NODE_STRING_NODE)) { + if (index == 0 || YP_NODE_TYPE_P(nodes->nodes[index - 1], YP_STRING_NODE)) { int cur_whitespace; const uint8_t *cur_char = content_loc->start; @@ -10072,7 +10072,7 @@ parse_heredoc_dedent(yp_parser_t *parser, yp_node_t *node, yp_heredoc_quote_t qu // We're not manipulating child nodes that aren't strings. In this case // we'll skip past it and indicate that the subsequent node should not // be dedented. - if (!YP_NODE_TYPE_P(node, YP_NODE_STRING_NODE)) { + if (!YP_NODE_TYPE_P(node, YP_STRING_NODE)) { nodes->nodes[write_index++] = node; dedent_next = false; continue; @@ -10217,7 +10217,7 @@ parse_pattern_constant_path(yp_parser_t *parser, yp_node_t *node) { // it doesn't already have a constant. If it's not one of those node types // or it does have a constant, then we'll create an array pattern. switch (YP_NODE_TYPE(inner)) { - case YP_NODE_ARRAY_PATTERN_NODE: { + case YP_ARRAY_PATTERN_NODE: { yp_array_pattern_node_t *pattern_node = (yp_array_pattern_node_t *) inner; if (pattern_node->constant == NULL) { @@ -10233,7 +10233,7 @@ parse_pattern_constant_path(yp_parser_t *parser, yp_node_t *node) { break; } - case YP_NODE_FIND_PATTERN_NODE: { + case YP_FIND_PATTERN_NODE: { yp_find_pattern_node_t *pattern_node = (yp_find_pattern_node_t *) inner; if (pattern_node->constant == NULL) { @@ -10249,7 +10249,7 @@ parse_pattern_constant_path(yp_parser_t *parser, yp_node_t *node) { break; } - case YP_NODE_HASH_PATTERN_NODE: { + case YP_HASH_PATTERN_NODE: { yp_hash_pattern_node_t *pattern_node = (yp_hash_pattern_node_t *) inner; if (pattern_node->constant == NULL) { @@ -10321,7 +10321,7 @@ parse_pattern_keyword_rest(yp_parser_t *parser) { // Parse a hash pattern. static yp_hash_pattern_node_t * parse_pattern_hash(yp_parser_t *parser, yp_node_t *first_assoc) { - if (YP_NODE_TYPE_P(first_assoc, YP_NODE_ASSOC_NODE)) { + if (YP_NODE_TYPE_P(first_assoc, YP_ASSOC_NODE)) { if (!match_any_type_p(parser, 7, YP_TOKEN_COMMA, YP_TOKEN_KEYWORD_THEN, YP_TOKEN_BRACE_RIGHT, YP_TOKEN_BRACKET_RIGHT, YP_TOKEN_PARENTHESIS_RIGHT, YP_TOKEN_NEWLINE, YP_TOKEN_SEMICOLON)) { // Here we have a value for the first assoc in the list, so we will parse it // now and update the first assoc. @@ -10333,7 +10333,7 @@ parse_pattern_hash(yp_parser_t *parser, yp_node_t *first_assoc) { } else { yp_node_t *key = ((yp_assoc_node_t *) first_assoc)->key; - if (YP_NODE_TYPE_P(key, YP_NODE_SYMBOL_NODE)) { + if (YP_NODE_TYPE_P(key, YP_SYMBOL_NODE)) { const yp_location_t *value_loc = &((yp_symbol_node_t *) key)->value_loc; yp_parser_local_add_location(parser, value_loc->start, value_loc->end); } @@ -10408,7 +10408,7 @@ parse_pattern_primitive(yp_parser_t *parser, const char *message) { yp_token_t closing = parser->previous; switch (YP_NODE_TYPE(inner)) { - case YP_NODE_ARRAY_PATTERN_NODE: { + case YP_ARRAY_PATTERN_NODE: { yp_array_pattern_node_t *pattern_node = (yp_array_pattern_node_t *) inner; if (pattern_node->opening_loc.start == NULL) { pattern_node->base.location.start = opening.start; @@ -10422,7 +10422,7 @@ parse_pattern_primitive(yp_parser_t *parser, const char *message) { break; } - case YP_NODE_FIND_PATTERN_NODE: { + case YP_FIND_PATTERN_NODE: { yp_find_pattern_node_t *pattern_node = (yp_find_pattern_node_t *) inner; if (pattern_node->opening_loc.start == NULL) { pattern_node->base.location.start = opening.start; @@ -10774,7 +10774,7 @@ parse_pattern(yp_parser_t *parser, bool top_pattern, const char *message) { // call this a find pattern, regardless of how many rest patterns are in // between because we know we already added the appropriate errors. // Otherwise we will create an array pattern. - if (YP_NODE_TYPE_P(nodes.nodes[0], YP_NODE_SPLAT_NODE) && YP_NODE_TYPE_P(nodes.nodes[nodes.size - 1], YP_NODE_SPLAT_NODE)) { + if (YP_NODE_TYPE_P(nodes.nodes[0], YP_SPLAT_NODE) && YP_NODE_TYPE_P(nodes.nodes[nodes.size - 1], YP_SPLAT_NODE)) { node = (yp_node_t *) yp_find_pattern_node_create(parser, &nodes); } else { node = (yp_node_t *) yp_array_pattern_node_node_list_create(parser, &nodes); @@ -10796,15 +10796,15 @@ parse_pattern(yp_parser_t *parser, bool top_pattern, const char *message) { static inline void parse_negative_numeric(yp_node_t *node) { switch (YP_NODE_TYPE(node)) { - case YP_NODE_INTEGER_NODE: - case YP_NODE_FLOAT_NODE: + case YP_INTEGER_NODE: + case YP_FLOAT_NODE: node->location.start--; break; - case YP_NODE_RATIONAL_NODE: + case YP_RATIONAL_NODE: node->location.start--; parse_negative_numeric(((yp_rational_node_t *) node)->numeric); break; - case YP_NODE_IMAGINARY_NODE: + case YP_IMAGINARY_NODE: node->location.start--; parse_negative_numeric(((yp_imaginary_node_t *) node)->numeric); break; @@ -10890,7 +10890,7 @@ parse_expression_prefix(yp_parser_t *parser, yp_binding_power_t binding_power) { } yp_array_node_elements_append(array, element); - if (YP_NODE_TYPE_P(element, YP_NODE_MISSING_NODE)) break; + if (YP_NODE_TYPE_P(element, YP_MISSING_NODE)) break; } accept(parser, YP_TOKEN_NEWLINE); @@ -10930,7 +10930,7 @@ parse_expression_prefix(yp_parser_t *parser, yp_binding_power_t binding_power) { // If we have a single statement and are ending on a right parenthesis, // then we need to check if this is possibly a multiple assignment node. - if (binding_power == YP_BINDING_POWER_STATEMENT && YP_NODE_TYPE_P(statement, YP_NODE_MULTI_WRITE_NODE)) { + if (binding_power == YP_BINDING_POWER_STATEMENT && YP_NODE_TYPE_P(statement, YP_MULTI_WRITE_NODE)) { yp_multi_write_node_t *multi_statement = (yp_multi_write_node_t *) statement; if (multi_statement->value == NULL) { @@ -11132,7 +11132,7 @@ parse_expression_prefix(yp_parser_t *parser, yp_binding_power_t binding_power) { yp_token_t identifier = parser->previous; yp_node_t *node = parse_variable_call(parser); - if (YP_NODE_TYPE_P(node, YP_NODE_CALL_NODE)) { + if (YP_NODE_TYPE_P(node, YP_CALL_NODE)) { // If parse_variable_call returned with a call node, then we // know the identifier is not in the local table. In that case // we need to check if there are arguments following the @@ -11214,11 +11214,11 @@ parse_expression_prefix(yp_parser_t *parser, yp_binding_power_t binding_power) { expect(parser, YP_TOKEN_HEREDOC_END, "Expected a closing delimiter for heredoc."); if (quote == YP_HEREDOC_QUOTE_BACKTICK) { - assert(YP_NODE_TYPE_P(node, YP_NODE_INTERPOLATED_X_STRING_NODE)); + assert(YP_NODE_TYPE_P(node, YP_INTERPOLATED_X_STRING_NODE)); yp_interpolated_xstring_node_closing_set(((yp_interpolated_x_string_node_t *) node), &parser->previous); node->location = ((yp_interpolated_x_string_node_t *) node)->opening_loc; } else { - assert(YP_NODE_TYPE_P(node, YP_NODE_INTERPOLATED_STRING_NODE)); + assert(YP_NODE_TYPE_P(node, YP_INTERPOLATED_STRING_NODE)); yp_interpolated_string_node_closing_set((yp_interpolated_string_node_t *) node, &parser->previous); node->location = ((yp_interpolated_string_node_t *) node)->opening_loc; } @@ -11281,18 +11281,18 @@ parse_expression_prefix(yp_parser_t *parser, yp_binding_power_t binding_power) { yp_node_t *old_name = parse_alias_argument(parser, false); switch (YP_NODE_TYPE(new_name)) { - case YP_NODE_SYMBOL_NODE: - case YP_NODE_INTERPOLATED_SYMBOL_NODE: { - if (!YP_NODE_TYPE_P(old_name, YP_NODE_SYMBOL_NODE) && !YP_NODE_TYPE_P(old_name, YP_NODE_INTERPOLATED_SYMBOL_NODE)) { + case YP_SYMBOL_NODE: + case YP_INTERPOLATED_SYMBOL_NODE: { + if (!YP_NODE_TYPE_P(old_name, YP_SYMBOL_NODE) && !YP_NODE_TYPE_P(old_name, YP_INTERPOLATED_SYMBOL_NODE)) { yp_diagnostic_list_append(&parser->error_list, old_name->location.start, old_name->location.end, "Expected a bare word or symbol argument."); } break; } - case YP_NODE_BACK_REFERENCE_READ_NODE: - case YP_NODE_NUMBERED_REFERENCE_READ_NODE: - case YP_NODE_GLOBAL_VARIABLE_READ_NODE: { - if (YP_NODE_TYPE_P(old_name, YP_NODE_BACK_REFERENCE_READ_NODE) || YP_NODE_TYPE_P(old_name, YP_NODE_NUMBERED_REFERENCE_READ_NODE) || YP_NODE_TYPE_P(old_name, YP_NODE_GLOBAL_VARIABLE_READ_NODE)) { - if (YP_NODE_TYPE_P(old_name, YP_NODE_NUMBERED_REFERENCE_READ_NODE)) { + case YP_BACK_REFERENCE_READ_NODE: + case YP_NUMBERED_REFERENCE_READ_NODE: + case YP_GLOBAL_VARIABLE_READ_NODE: { + if (YP_NODE_TYPE_P(old_name, YP_BACK_REFERENCE_READ_NODE) || YP_NODE_TYPE_P(old_name, YP_NUMBERED_REFERENCE_READ_NODE) || YP_NODE_TYPE_P(old_name, YP_GLOBAL_VARIABLE_READ_NODE)) { + if (YP_NODE_TYPE_P(old_name, YP_NUMBERED_REFERENCE_READ_NODE)) { yp_diagnostic_list_append(&parser->error_list, old_name->location.start, old_name->location.end, "Can't make alias for number variables."); } } else { @@ -11347,12 +11347,12 @@ parse_expression_prefix(yp_parser_t *parser, yp_binding_power_t binding_power) { yp_splat_node_t *splat_node = yp_splat_node_create(parser, &operator, expression); yp_when_node_conditions_append(when_node, (yp_node_t *) splat_node); - if (YP_NODE_TYPE_P(expression, YP_NODE_MISSING_NODE)) break; + if (YP_NODE_TYPE_P(expression, YP_MISSING_NODE)) break; } else { yp_node_t *condition = parse_expression(parser, YP_BINDING_POWER_DEFINED, "Expected a value after when keyword."); yp_when_node_conditions_append(when_node, condition); - if (YP_NODE_TYPE_P(condition, YP_NODE_MISSING_NODE)) break; + if (YP_NODE_TYPE_P(condition, YP_MISSING_NODE)) break; } } while (accept(parser, YP_TOKEN_COMMA)); @@ -11575,7 +11575,7 @@ parse_expression_prefix(yp_parser_t *parser, yp_binding_power_t binding_power) { } if (match_any_type_p(parser, 2, YP_TOKEN_KEYWORD_RESCUE, YP_TOKEN_KEYWORD_ENSURE)) { - assert(statements == NULL || YP_NODE_TYPE_P(statements, YP_NODE_STATEMENTS_NODE)); + assert(statements == NULL || YP_NODE_TYPE_P(statements, YP_STATEMENTS_NODE)); statements = (yp_node_t *) parse_rescues_as_begin(parser, (yp_statements_node_t *) statements); } @@ -11620,7 +11620,7 @@ parse_expression_prefix(yp_parser_t *parser, yp_binding_power_t binding_power) { } if (match_any_type_p(parser, 2, YP_TOKEN_KEYWORD_RESCUE, YP_TOKEN_KEYWORD_ENSURE)) { - assert(statements == NULL || YP_NODE_TYPE_P(statements, YP_NODE_STATEMENTS_NODE)); + assert(statements == NULL || YP_NODE_TYPE_P(statements, YP_STATEMENTS_NODE)); statements = (yp_node_t *) parse_rescues_as_begin(parser, (yp_statements_node_t *) statements); } @@ -11858,7 +11858,7 @@ parse_expression_prefix(yp_parser_t *parser, yp_binding_power_t binding_power) { } if (match_any_type_p(parser, 2, YP_TOKEN_KEYWORD_RESCUE, YP_TOKEN_KEYWORD_ENSURE)) { - assert(statements == NULL || YP_NODE_TYPE_P(statements, YP_NODE_STATEMENTS_NODE)); + assert(statements == NULL || YP_NODE_TYPE_P(statements, YP_STATEMENTS_NODE)); statements = (yp_node_t *) parse_rescues_as_begin(parser, (yp_statements_node_t *) statements); } @@ -11970,7 +11970,7 @@ parse_expression_prefix(yp_parser_t *parser, yp_binding_power_t binding_power) { yp_undef_node_t *undef = yp_undef_node_create(parser, &parser->previous); yp_node_t *name = parse_undef_argument(parser); - if (YP_NODE_TYPE_P(name, YP_NODE_MISSING_NODE)) { + if (YP_NODE_TYPE_P(name, YP_MISSING_NODE)) { yp_node_destroy(parser, name); } else { yp_undef_node_append(undef, name); @@ -11980,7 +11980,7 @@ parse_expression_prefix(yp_parser_t *parser, yp_binding_power_t binding_power) { parser_lex(parser); name = parse_undef_argument(parser); - if (YP_NODE_TYPE_P(name, YP_NODE_MISSING_NODE)) { + if (YP_NODE_TYPE_P(name, YP_MISSING_NODE)) { yp_node_destroy(parser, name); break; } @@ -12034,7 +12034,7 @@ parse_expression_prefix(yp_parser_t *parser, yp_binding_power_t binding_power) { // If we can recover from a syntax error that occurred while parsing // the name of the module, then we'll handle that here. - if (YP_NODE_TYPE_P(constant_path, YP_NODE_MISSING_NODE)) { + if (YP_NODE_TYPE_P(constant_path, YP_MISSING_NODE)) { yp_token_t missing = (yp_token_t) { .type = YP_TOKEN_MISSING, .start = parser->previous.end, .end = parser->previous.end }; return (yp_node_t *) yp_module_node_create(parser, NULL, &module_keyword, constant_path, &missing, NULL, &missing); } @@ -12067,7 +12067,7 @@ parse_expression_prefix(yp_parser_t *parser, yp_binding_power_t binding_power) { } if (match_any_type_p(parser, 2, YP_TOKEN_KEYWORD_RESCUE, YP_TOKEN_KEYWORD_ENSURE)) { - assert(statements == NULL || YP_NODE_TYPE_P(statements, YP_NODE_STATEMENTS_NODE)); + assert(statements == NULL || YP_NODE_TYPE_P(statements, YP_STATEMENTS_NODE)); statements = (yp_node_t *) parse_rescues_as_begin(parser, (yp_statements_node_t *) statements); } @@ -12195,13 +12195,13 @@ parse_expression_prefix(yp_parser_t *parser, yp_binding_power_t binding_power) { // to create a new string node and set that to the current. parser_lex(parser); current = (yp_node_t *) yp_symbol_node_create_and_unescape(parser, &opening, &parser->previous, &closing, YP_UNESCAPE_ALL); - } else if (YP_NODE_TYPE_P(current, YP_NODE_INTERPOLATED_SYMBOL_NODE)) { + } else if (YP_NODE_TYPE_P(current, YP_INTERPOLATED_SYMBOL_NODE)) { // If we hit string content and the current node is an // interpolated string, then we need to append the string content // to the list of child nodes. yp_node_t *part = parse_string_part(parser); yp_interpolated_symbol_node_append((yp_interpolated_symbol_node_t *) current, part); - } else if (YP_NODE_TYPE_P(current, YP_NODE_SYMBOL_NODE)) { + } else if (YP_NODE_TYPE_P(current, YP_SYMBOL_NODE)) { // If we hit string content and the current node is a string node, // then we need to convert the current node into an interpolated // string and add the string content to the list of child nodes. @@ -12229,7 +12229,7 @@ parse_expression_prefix(yp_parser_t *parser, yp_binding_power_t binding_power) { yp_token_t opening = not_provided(parser); yp_token_t closing = not_provided(parser); current = (yp_node_t *) yp_interpolated_symbol_node_create(parser, &opening, NULL, &closing); - } else if (YP_NODE_TYPE_P(current, YP_NODE_SYMBOL_NODE)) { + } else if (YP_NODE_TYPE_P(current, YP_SYMBOL_NODE)) { // If we hit an embedded variable and the current node is a string // node, then we'll convert the current into an interpolated // string and add the string node to the list of parts. @@ -12263,7 +12263,7 @@ parse_expression_prefix(yp_parser_t *parser, yp_binding_power_t binding_power) { yp_token_t opening = not_provided(parser); yp_token_t closing = not_provided(parser); current = (yp_node_t *) yp_interpolated_symbol_node_create(parser, &opening, NULL, &closing); - } else if (YP_NODE_TYPE_P(current, YP_NODE_SYMBOL_NODE)) { + } else if (YP_NODE_TYPE_P(current, YP_SYMBOL_NODE)) { // If we hit an embedded expression and the current node is a // string node, then we'll convert the current into an // interpolated string and add the string node to the list of @@ -12277,7 +12277,7 @@ parse_expression_prefix(yp_parser_t *parser, yp_binding_power_t binding_power) { interpolated->base.location.start = current->location.start; start_location_set = true; current = (yp_node_t *) interpolated; - } else if (YP_NODE_TYPE_P(current, YP_NODE_INTERPOLATED_SYMBOL_NODE)) { + } else if (YP_NODE_TYPE_P(current, YP_INTERPOLATED_SYMBOL_NODE)) { // If we hit an embedded expression and the current node is an // interpolated string, then we'll just continue on. } else { @@ -12362,13 +12362,13 @@ parse_expression_prefix(yp_parser_t *parser, yp_binding_power_t binding_power) { // the first string content we've seen. In that case we're going // to create a new string node and set that to the current. current = parse_string_part(parser); - } else if (YP_NODE_TYPE_P(current, YP_NODE_INTERPOLATED_STRING_NODE)) { + } else if (YP_NODE_TYPE_P(current, YP_INTERPOLATED_STRING_NODE)) { // If we hit string content and the current node is an // interpolated string, then we need to append the string content // to the list of child nodes. yp_node_t *part = parse_string_part(parser); yp_interpolated_string_node_append((yp_interpolated_string_node_t *) current, part); - } else if (YP_NODE_TYPE_P(current, YP_NODE_STRING_NODE)) { + } else if (YP_NODE_TYPE_P(current, YP_STRING_NODE)) { // If we hit string content and the current node is a string node, // then we need to convert the current node into an interpolated // string and add the string content to the list of child nodes. @@ -12395,7 +12395,7 @@ parse_expression_prefix(yp_parser_t *parser, yp_binding_power_t binding_power) { yp_token_t opening = not_provided(parser); yp_token_t closing = not_provided(parser); current = (yp_node_t *) yp_interpolated_string_node_create(parser, &opening, NULL, &closing); - } else if (YP_NODE_TYPE_P(current, YP_NODE_STRING_NODE)) { + } else if (YP_NODE_TYPE_P(current, YP_STRING_NODE)) { // If we hit an embedded variable and the current node is a string // node, then we'll convert the current into an interpolated // string and add the string node to the list of parts. @@ -12421,7 +12421,7 @@ parse_expression_prefix(yp_parser_t *parser, yp_binding_power_t binding_power) { yp_token_t opening = not_provided(parser); yp_token_t closing = not_provided(parser); current = (yp_node_t *) yp_interpolated_string_node_create(parser, &opening, NULL, &closing); - } else if (YP_NODE_TYPE_P(current, YP_NODE_STRING_NODE)) { + } else if (YP_NODE_TYPE_P(current, YP_STRING_NODE)) { // If we hit an embedded expression and the current node is a // string node, then we'll convert the current into an // interpolated string and add the string node to the list of @@ -12431,7 +12431,7 @@ parse_expression_prefix(yp_parser_t *parser, yp_binding_power_t binding_power) { yp_interpolated_string_node_t *interpolated = yp_interpolated_string_node_create(parser, &opening, NULL, &closing); yp_interpolated_string_node_append(interpolated, current); current = (yp_node_t *) interpolated; - } else if (YP_NODE_TYPE_P(current, YP_NODE_INTERPOLATED_STRING_NODE)) { + } else if (YP_NODE_TYPE_P(current, YP_INTERPOLATED_STRING_NODE)) { // If we hit an embedded expression and the current node is an // interpolated string, then we'll just continue on. } else { @@ -12641,10 +12641,10 @@ parse_expression_prefix(yp_parser_t *parser, yp_binding_power_t binding_power) { yp_node_t *node = parse_expression(parser, yp_binding_powers[parser->previous.type].right, "Expected a receiver after unary -."); switch (YP_NODE_TYPE(node)) { - case YP_NODE_INTEGER_NODE: - case YP_NODE_FLOAT_NODE: - case YP_NODE_RATIONAL_NODE: - case YP_NODE_IMAGINARY_NODE: + case YP_INTEGER_NODE: + case YP_FLOAT_NODE: + case YP_RATIONAL_NODE: + case YP_IMAGINARY_NODE: parse_negative_numeric(node); break; default: @@ -12717,7 +12717,7 @@ parse_expression_prefix(yp_parser_t *parser, yp_binding_power_t binding_power) { } if (match_any_type_p(parser, 2, YP_TOKEN_KEYWORD_RESCUE, YP_TOKEN_KEYWORD_ENSURE)) { - assert(body == NULL || YP_NODE_TYPE_P(body, YP_NODE_STATEMENTS_NODE)); + assert(body == NULL || YP_NODE_TYPE_P(body, YP_STATEMENTS_NODE)); body = (yp_node_t *) parse_rescues_as_begin(parser, (yp_statements_node_t *) body); } @@ -12866,7 +12866,7 @@ parse_expression_prefix(yp_parser_t *parser, yp_binding_power_t binding_power) { // If the node we just parsed is a symbol node, then we // can't concatenate it with anything else, so we can now // return that node. - if (YP_NODE_TYPE_P(node, YP_NODE_SYMBOL_NODE) || YP_NODE_TYPE_P(node, YP_NODE_INTERPOLATED_SYMBOL_NODE)) { + if (YP_NODE_TYPE_P(node, YP_SYMBOL_NODE) || YP_NODE_TYPE_P(node, YP_INTERPOLATED_SYMBOL_NODE)) { return node; } @@ -12877,7 +12877,7 @@ parse_expression_prefix(yp_parser_t *parser, yp_binding_power_t binding_power) { // Otherwise we need to check the type of the node we just // parsed. If it cannot be concatenated with the previous // node, then we'll need to add a syntax error. - if (!YP_NODE_TYPE_P(node, YP_NODE_STRING_NODE) && !YP_NODE_TYPE_P(node, YP_NODE_INTERPOLATED_STRING_NODE)) { + if (!YP_NODE_TYPE_P(node, YP_STRING_NODE) && !YP_NODE_TYPE_P(node, YP_INTERPOLATED_STRING_NODE)) { yp_diagnostic_list_append(&parser->error_list, node->location.start, node->location.end, "Unexpected string concatenation."); } @@ -12908,7 +12908,7 @@ static inline yp_node_t * parse_assignment_value(yp_parser_t *parser, yp_binding_power_t previous_binding_power, yp_binding_power_t binding_power, const char *message) { yp_node_t *value = parse_starred_expression(parser, binding_power, message); - if (previous_binding_power == YP_BINDING_POWER_STATEMENT && (YP_NODE_TYPE_P(value, YP_NODE_SPLAT_NODE) || match_type_p(parser, YP_TOKEN_COMMA))) { + if (previous_binding_power == YP_BINDING_POWER_STATEMENT && (YP_NODE_TYPE_P(value, YP_SPLAT_NODE) || match_type_p(parser, YP_TOKEN_COMMA))) { yp_token_t opening = not_provided(parser); yp_array_node_t *array = yp_array_node_create(parser, &opening); @@ -12918,7 +12918,7 @@ parse_assignment_value(yp_parser_t *parser, yp_binding_power_t previous_binding_ while (accept(parser, YP_TOKEN_COMMA)) { yp_node_t *element = parse_starred_expression(parser, binding_power, "Expected an element for the array."); yp_array_node_elements_append(array, element); - if (YP_NODE_TYPE_P(element, YP_NODE_MISSING_NODE)) break; + if (YP_NODE_TYPE_P(element, YP_MISSING_NODE)) break; } } @@ -12932,7 +12932,7 @@ parse_expression_infix(yp_parser_t *parser, yp_node_t *node, yp_binding_power_t switch (token.type) { case YP_TOKEN_EQUAL: { switch (YP_NODE_TYPE(node)) { - case YP_NODE_CALL_NODE: { + case YP_CALL_NODE: { // If we have no arguments to the call node and we need this // to be a target then this is either a method call or a // local variable write. This _must_ happen before the value @@ -12948,7 +12948,7 @@ parse_expression_infix(yp_parser_t *parser, yp_node_t *node, yp_binding_power_t yp_node_t *value = parse_assignment_value(parser, previous_binding_power, binding_power, "Expected a value after =."); return parse_write(parser, node, &token, value); } - case YP_NODE_SPLAT_NODE: { + case YP_SPLAT_NODE: { yp_splat_node_t *splat_node = (yp_splat_node_t *) node; switch (YP_NODE_TYPE(splat_node->expression)) { @@ -12973,11 +12973,11 @@ parse_expression_infix(yp_parser_t *parser, yp_node_t *node, yp_binding_power_t } case YP_TOKEN_AMPERSAND_AMPERSAND_EQUAL: { switch (YP_NODE_TYPE(node)) { - case YP_NODE_BACK_REFERENCE_READ_NODE: - case YP_NODE_NUMBERED_REFERENCE_READ_NODE: + case YP_BACK_REFERENCE_READ_NODE: + case YP_NUMBERED_REFERENCE_READ_NODE: yp_diagnostic_list_append(&parser->error_list, node->location.start, node->location.end, "Can't set variable"); /* fallthrough */ - case YP_NODE_GLOBAL_VARIABLE_READ_NODE: { + case YP_GLOBAL_VARIABLE_READ_NODE: { parser_lex(parser); yp_node_t *value = parse_expression(parser, binding_power, "Expected a value after &&="); @@ -12986,7 +12986,7 @@ parse_expression_infix(yp_parser_t *parser, yp_node_t *node, yp_binding_power_t yp_node_destroy(parser, node); return result; } - case YP_NODE_CLASS_VARIABLE_READ_NODE: { + case YP_CLASS_VARIABLE_READ_NODE: { parser_lex(parser); yp_node_t *value = parse_expression(parser, binding_power, "Expected a value after &&="); @@ -12995,13 +12995,13 @@ parse_expression_infix(yp_parser_t *parser, yp_node_t *node, yp_binding_power_t yp_node_destroy(parser, node); return result; } - case YP_NODE_CONSTANT_PATH_NODE: { + case YP_CONSTANT_PATH_NODE: { parser_lex(parser); yp_node_t *value = parse_expression(parser, binding_power, "Expected a value after &&="); return (yp_node_t *) yp_constant_path_and_write_node_create(parser, (yp_constant_path_node_t *) node, &token, value); } - case YP_NODE_CONSTANT_READ_NODE: { + case YP_CONSTANT_READ_NODE: { parser_lex(parser); yp_node_t *value = parse_expression(parser, binding_power, "Expected a value after &&="); @@ -13010,7 +13010,7 @@ parse_expression_infix(yp_parser_t *parser, yp_node_t *node, yp_binding_power_t yp_node_destroy(parser, node); return result; } - case YP_NODE_INSTANCE_VARIABLE_READ_NODE: { + case YP_INSTANCE_VARIABLE_READ_NODE: { parser_lex(parser); yp_node_t *value = parse_expression(parser, binding_power, "Expected a value after &&="); @@ -13019,7 +13019,7 @@ parse_expression_infix(yp_parser_t *parser, yp_node_t *node, yp_binding_power_t yp_node_destroy(parser, node); return result; } - case YP_NODE_LOCAL_VARIABLE_READ_NODE: { + case YP_LOCAL_VARIABLE_READ_NODE: { yp_local_variable_read_node_t *cast = (yp_local_variable_read_node_t *) node; parser_lex(parser); @@ -13029,7 +13029,7 @@ parse_expression_infix(yp_parser_t *parser, yp_node_t *node, yp_binding_power_t yp_node_destroy(parser, node); return result; } - case YP_NODE_CALL_NODE: { + case YP_CALL_NODE: { yp_call_node_t *call_node = (yp_call_node_t *) node; // If we have a vcall (a method with no arguments and no @@ -13057,7 +13057,7 @@ parse_expression_infix(yp_parser_t *parser, yp_node_t *node, yp_binding_power_t yp_node_t *value = parse_expression(parser, binding_power, "Expected a value after &&="); return (yp_node_t *) yp_call_and_write_node_create(parser, (yp_call_node_t *) node, &token, value); } - case YP_NODE_MULTI_WRITE_NODE: { + case YP_MULTI_WRITE_NODE: { parser_lex(parser); yp_diagnostic_list_append(&parser->error_list, token.start, token.end, "Cannot use `&&=' on a multi-write."); return node; @@ -13074,11 +13074,11 @@ parse_expression_infix(yp_parser_t *parser, yp_node_t *node, yp_binding_power_t } case YP_TOKEN_PIPE_PIPE_EQUAL: { switch (YP_NODE_TYPE(node)) { - case YP_NODE_BACK_REFERENCE_READ_NODE: - case YP_NODE_NUMBERED_REFERENCE_READ_NODE: + case YP_BACK_REFERENCE_READ_NODE: + case YP_NUMBERED_REFERENCE_READ_NODE: yp_diagnostic_list_append(&parser->error_list, node->location.start, node->location.end, "Can't set variable"); /* fallthrough */ - case YP_NODE_GLOBAL_VARIABLE_READ_NODE: { + case YP_GLOBAL_VARIABLE_READ_NODE: { parser_lex(parser); yp_node_t *value = parse_expression(parser, binding_power, "Expected a value after ||="); @@ -13087,7 +13087,7 @@ parse_expression_infix(yp_parser_t *parser, yp_node_t *node, yp_binding_power_t yp_node_destroy(parser, node); return result; } - case YP_NODE_CLASS_VARIABLE_READ_NODE: { + case YP_CLASS_VARIABLE_READ_NODE: { parser_lex(parser); yp_node_t *value = parse_expression(parser, binding_power, "Expected a value after ||="); @@ -13096,13 +13096,13 @@ parse_expression_infix(yp_parser_t *parser, yp_node_t *node, yp_binding_power_t yp_node_destroy(parser, node); return result; } - case YP_NODE_CONSTANT_PATH_NODE: { + case YP_CONSTANT_PATH_NODE: { parser_lex(parser); yp_node_t *value = parse_expression(parser, binding_power, "Expected a value after ||="); return (yp_node_t *) yp_constant_path_or_write_node_create(parser, (yp_constant_path_node_t *) node, &token, value); } - case YP_NODE_CONSTANT_READ_NODE: { + case YP_CONSTANT_READ_NODE: { parser_lex(parser); yp_node_t *value = parse_expression(parser, binding_power, "Expected a value after ||="); @@ -13111,7 +13111,7 @@ parse_expression_infix(yp_parser_t *parser, yp_node_t *node, yp_binding_power_t yp_node_destroy(parser, node); return result; } - case YP_NODE_INSTANCE_VARIABLE_READ_NODE: { + case YP_INSTANCE_VARIABLE_READ_NODE: { parser_lex(parser); yp_node_t *value = parse_expression(parser, binding_power, "Expected a value after ||="); @@ -13120,7 +13120,7 @@ parse_expression_infix(yp_parser_t *parser, yp_node_t *node, yp_binding_power_t yp_node_destroy(parser, node); return result; } - case YP_NODE_LOCAL_VARIABLE_READ_NODE: { + case YP_LOCAL_VARIABLE_READ_NODE: { yp_local_variable_read_node_t *cast = (yp_local_variable_read_node_t *) node; parser_lex(parser); @@ -13130,7 +13130,7 @@ parse_expression_infix(yp_parser_t *parser, yp_node_t *node, yp_binding_power_t yp_node_destroy(parser, node); return result; } - case YP_NODE_CALL_NODE: { + case YP_CALL_NODE: { yp_call_node_t *call_node = (yp_call_node_t *) node; // If we have a vcall (a method with no arguments and no @@ -13158,7 +13158,7 @@ parse_expression_infix(yp_parser_t *parser, yp_node_t *node, yp_binding_power_t yp_node_t *value = parse_expression(parser, binding_power, "Expected a value after ||="); return (yp_node_t *) yp_call_or_write_node_create(parser, (yp_call_node_t *) node, &token, value); } - case YP_NODE_MULTI_WRITE_NODE: { + case YP_MULTI_WRITE_NODE: { parser_lex(parser); yp_diagnostic_list_append(&parser->error_list, token.start, token.end, "Cannot use `||=' on a multi-write."); return node; @@ -13185,11 +13185,11 @@ parse_expression_infix(yp_parser_t *parser, yp_node_t *node, yp_binding_power_t case YP_TOKEN_STAR_EQUAL: case YP_TOKEN_STAR_STAR_EQUAL: { switch (YP_NODE_TYPE(node)) { - case YP_NODE_BACK_REFERENCE_READ_NODE: - case YP_NODE_NUMBERED_REFERENCE_READ_NODE: + case YP_BACK_REFERENCE_READ_NODE: + case YP_NUMBERED_REFERENCE_READ_NODE: yp_diagnostic_list_append(&parser->error_list, node->location.start, node->location.end, "Can't set variable"); /* fallthrough */ - case YP_NODE_GLOBAL_VARIABLE_READ_NODE: { + case YP_GLOBAL_VARIABLE_READ_NODE: { parser_lex(parser); yp_node_t *value = parse_expression(parser, binding_power, "Expected a value after the operator."); @@ -13198,7 +13198,7 @@ parse_expression_infix(yp_parser_t *parser, yp_node_t *node, yp_binding_power_t yp_node_destroy(parser, node); return result; } - case YP_NODE_CLASS_VARIABLE_READ_NODE: { + case YP_CLASS_VARIABLE_READ_NODE: { parser_lex(parser); yp_node_t *value = parse_expression(parser, binding_power, "Expected a value after the operator."); @@ -13207,13 +13207,13 @@ parse_expression_infix(yp_parser_t *parser, yp_node_t *node, yp_binding_power_t yp_node_destroy(parser, node); return result; } - case YP_NODE_CONSTANT_PATH_NODE: { + case YP_CONSTANT_PATH_NODE: { parser_lex(parser); yp_node_t *value = parse_expression(parser, binding_power, "Expected a value after the operator."); return (yp_node_t *) yp_constant_path_operator_write_node_create(parser, (yp_constant_path_node_t *) node, &token, value); } - case YP_NODE_CONSTANT_READ_NODE: { + case YP_CONSTANT_READ_NODE: { parser_lex(parser); yp_node_t *value = parse_expression(parser, binding_power, "Expected a value after the operator."); @@ -13222,7 +13222,7 @@ parse_expression_infix(yp_parser_t *parser, yp_node_t *node, yp_binding_power_t yp_node_destroy(parser, node); return result; } - case YP_NODE_INSTANCE_VARIABLE_READ_NODE: { + case YP_INSTANCE_VARIABLE_READ_NODE: { parser_lex(parser); yp_node_t *value = parse_expression(parser, binding_power, "Expected a value after the operator."); @@ -13231,7 +13231,7 @@ parse_expression_infix(yp_parser_t *parser, yp_node_t *node, yp_binding_power_t yp_node_destroy(parser, node); return result; } - case YP_NODE_LOCAL_VARIABLE_READ_NODE: { + case YP_LOCAL_VARIABLE_READ_NODE: { yp_local_variable_read_node_t *cast = (yp_local_variable_read_node_t *) node; parser_lex(parser); @@ -13241,7 +13241,7 @@ parse_expression_infix(yp_parser_t *parser, yp_node_t *node, yp_binding_power_t yp_node_destroy(parser, node); return result; } - case YP_NODE_CALL_NODE: { + case YP_CALL_NODE: { yp_call_node_t *call_node = (yp_call_node_t *) node; // If we have a vcall (a method with no arguments and no @@ -13269,7 +13269,7 @@ parse_expression_infix(yp_parser_t *parser, yp_node_t *node, yp_binding_power_t yp_node_t *value = parse_expression(parser, binding_power, "Expected a value after the operator."); return (yp_node_t *) yp_call_operator_write_node_create(parser, (yp_call_node_t *) node, &token, value); } - case YP_NODE_MULTI_WRITE_NODE: { + case YP_MULTI_WRITE_NODE: { parser_lex(parser); yp_diagnostic_list_append(&parser->error_list, token.start, token.end, "Unexpected operator."); return node; @@ -13310,7 +13310,7 @@ parse_expression_infix(yp_parser_t *parser, yp_node_t *node, yp_binding_power_t // If the receiver of this =~ is a regular expression node, then we need // to introduce local variables for it based on its named capture groups. - if (YP_NODE_TYPE_P(node, YP_NODE_REGULAR_EXPRESSION_NODE)) { + if (YP_NODE_TYPE_P(node, YP_REGULAR_EXPRESSION_NODE)) { yp_string_list_t named_captures; yp_string_list_init(&named_captures); @@ -13434,7 +13434,7 @@ parse_expression_infix(yp_parser_t *parser, yp_node_t *node, yp_binding_power_t yp_statements_node_body_append(statements, node); yp_node_t *predicate = parse_expression(parser, binding_power, "Expected a predicate after 'until'"); - return (yp_node_t *) yp_until_node_modifier_create(parser, &token, predicate, statements, YP_NODE_TYPE_P(node, YP_NODE_BEGIN_NODE) ? YP_LOOP_FLAGS_BEGIN_MODIFIER : 0); + return (yp_node_t *) yp_until_node_modifier_create(parser, &token, predicate, statements, YP_NODE_TYPE_P(node, YP_BEGIN_NODE) ? YP_LOOP_FLAGS_BEGIN_MODIFIER : 0); } case YP_TOKEN_KEYWORD_WHILE_MODIFIER: { parser_lex(parser); @@ -13442,7 +13442,7 @@ parse_expression_infix(yp_parser_t *parser, yp_node_t *node, yp_binding_power_t yp_statements_node_body_append(statements, node); yp_node_t *predicate = parse_expression(parser, binding_power, "Expected a predicate after 'while'"); - return (yp_node_t *) yp_while_node_modifier_create(parser, &token, predicate, statements, YP_NODE_TYPE_P(node, YP_NODE_BEGIN_NODE) ? YP_LOOP_FLAGS_BEGIN_MODIFIER : 0); + return (yp_node_t *) yp_while_node_modifier_create(parser, &token, predicate, statements, YP_NODE_TYPE_P(node, YP_BEGIN_NODE) ? YP_LOOP_FLAGS_BEGIN_MODIFIER : 0); } case YP_TOKEN_QUESTION_MARK: { parser_lex(parser); @@ -13634,7 +13634,7 @@ parse_expression(yp_parser_t *parser, yp_binding_power_t binding_power, const ch // If we found a syntax error, then the type of node returned by // parse_expression_prefix is going to be a missing node. In that case we need // to add the error message to the parser's error list. - if (YP_NODE_TYPE_P(node, YP_NODE_MISSING_NODE)) { + if (YP_NODE_TYPE_P(node, YP_MISSING_NODE)) { yp_diagnostic_list_append(&parser->error_list, recovery.end, recovery.end, message); return node; } From 6408da70b036de1d0f158f29051eadf4040ab471 Mon Sep 17 00:00:00 2001 From: Benoit Daloze Date: Tue, 5 Sep 2023 21:43:40 +0200 Subject: [PATCH 79/95] [ruby/yarp] Add deprecated aliases of the form YP_NODE__NODE https://github.com/ruby/yarp/commit/ae1f45ff52 --- yarp/templates/include/yarp/ast.h.erb | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/yarp/templates/include/yarp/ast.h.erb b/yarp/templates/include/yarp/ast.h.erb index cc631568ede7e8..82fb7584406370 100644 --- a/yarp/templates/include/yarp/ast.h.erb +++ b/yarp/templates/include/yarp/ast.h.erb @@ -47,6 +47,12 @@ enum yp_node_type { YP_SCOPE_NODE }; +// Deprecated aliases +#define YP_NODE_SCOPE_NODE YP_SCOPE_NODE +<%- nodes.each do |node| -%> +#define <%= node.type.sub(/^YP_/, 'YP_NODE_') %> <%= node.type %> +<%- end -%> + typedef uint16_t yp_node_type_t; typedef uint16_t yp_node_flags_t; From 6778d2c582d8f17b81b9a8894bd3b2c152050bd3 Mon Sep 17 00:00:00 2001 From: Peter Zhu Date: Tue, 5 Sep 2023 10:25:59 -0400 Subject: [PATCH 80/95] Support freeing the lowest memory address page This should help fix the following flaky test: ``` 1) Failure: TestProcess#test_warmup_frees_pages [test/ruby/test_process.rb:2751]: <0> expected but was <1>. ``` --- gc.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/gc.c b/gc.c index cf53cf5270cb5a..c8f570940cf040 100644 --- a/gc.c +++ b/gc.c @@ -2058,7 +2058,7 @@ heap_pages_free_unused_pages(rb_objspace_t *objspace) } if (has_pages_in_tomb_heap) { - for (i = j = 1; j < heap_allocated_pages; i++) { + for (i = j = 0; j < heap_allocated_pages; i++) { struct heap_page *page = heap_pages_sorted[i]; if (page->flags.in_tomb && page->free_slots == page->total_slots) { @@ -2078,6 +2078,11 @@ heap_pages_free_unused_pages(rb_objspace_t *objspace) GC_ASSERT(himem <= heap_pages_himem); heap_pages_himem = himem; + struct heap_page *lopage = heap_pages_sorted[0]; + uintptr_t lomem = (uintptr_t)lopage->start; + GC_ASSERT(lomem >= heap_pages_lomem); + heap_pages_lomem = lomem; + GC_ASSERT(j == heap_allocated_pages); } } From 4c9a036606afff049b1184b7a7c6d9d8a3a50307 Mon Sep 17 00:00:00 2001 From: Kevin Newton Date: Tue, 5 Sep 2023 13:53:37 -0400 Subject: [PATCH 81/95] [ruby/yarp] Add constants and constants https://github.com/ruby/yarp/commit/d7eaa89bc3 --- lib/yarp/desugar_visitor.rb | 38 ++-- test/yarp/errors_test.rb | 12 +- test/yarp/snapshots/begin_ensure.txt | 6 +- test/yarp/snapshots/begin_rescue.txt | 17 +- test/yarp/snapshots/case.txt | 3 +- test/yarp/snapshots/classes.txt | 18 +- test/yarp/snapshots/constants.txt | 205 +++++++++--------- test/yarp/snapshots/if.txt | 2 +- test/yarp/snapshots/method_calls.txt | 18 +- test/yarp/snapshots/methods.txt | 3 +- test/yarp/snapshots/modules.txt | 20 +- test/yarp/snapshots/patterns.txt | 52 ++--- .../seattlerb/TestRubyParserShared.txt | 17 +- .../seattlerb/attr_asgn_colon_id.txt | 2 +- test/yarp/snapshots/seattlerb/bug_249.txt | 2 +- test/yarp/snapshots/seattlerb/call_colon2.txt | 2 +- test/yarp/snapshots/seattlerb/case_in.txt | 10 +- test/yarp/snapshots/seattlerb/case_in_37.txt | 2 +- .../yarp/snapshots/seattlerb/case_in_42_2.txt | 2 +- test/yarp/snapshots/seattlerb/case_in_86.txt | 2 +- .../yarp/snapshots/seattlerb/case_in_86_2.txt | 2 +- .../seattlerb/case_in_array_pat_const.txt | 2 +- .../seattlerb/case_in_array_pat_const2.txt | 4 +- .../case_in_array_pat_paren_assign.txt | 4 +- .../snapshots/seattlerb/case_in_const.txt | 4 +- .../yarp/snapshots/seattlerb/case_in_else.txt | 4 +- .../seattlerb/case_in_hash_pat_assign.txt | 2 +- .../case_in_hash_pat_paren_assign.txt | 2 +- .../seattlerb/case_in_if_unless_post_mod.txt | 4 +- .../snapshots/seattlerb/case_in_multiple.txt | 8 +- test/yarp/snapshots/seattlerb/case_in_or.txt | 4 +- .../snapshots/seattlerb/class_comments.txt | 2 +- .../seattlerb/const_2_op_asgn_or2.txt | 4 +- .../seattlerb/const_3_op_asgn_or.txt | 2 +- .../seattlerb/const_op_asgn_and1.txt | 2 +- .../seattlerb/const_op_asgn_and2.txt | 2 +- .../snapshots/seattlerb/const_op_asgn_or.txt | 4 +- test/yarp/snapshots/seattlerb/dasgn_icky2.txt | 2 +- .../snapshots/seattlerb/defn_oneliner_eq2.txt | 2 +- .../snapshots/seattlerb/defs_oneliner_eq2.txt | 2 +- .../snapshots/seattlerb/in_expr_no_case.txt | 2 +- .../seattlerb/magic_encoding_comment.txt | 2 +- .../yarp/snapshots/seattlerb/masgn_colon2.txt | 2 +- .../yarp/snapshots/seattlerb/masgn_colon3.txt | 8 +- .../seattlerb/messy_op_asgn_lineno.txt | 4 +- .../snapshots/seattlerb/module_comments.txt | 2 +- .../op_asgn_dot_ident_command_call.txt | 2 +- ..._asgn_primary_colon_const_command_call.txt | 4 +- .../op_asgn_primary_colon_identifier1.txt | 2 +- ..._primary_colon_identifier_command_call.txt | 2 +- .../parse_line_heredoc_hardnewline.txt | 2 +- .../snapshots/seattlerb/parse_pattern_044.txt | 2 +- .../snapshots/seattlerb/parse_pattern_069.txt | 2 +- .../unparser/corpus/literal/assignment.txt | 11 +- .../unparser/corpus/literal/block.txt | 10 +- .../unparser/corpus/literal/class.txt | 36 +-- .../unparser/corpus/literal/defined.txt | 2 +- .../unparser/corpus/literal/defs.txt | 12 +- .../snapshots/unparser/corpus/literal/if.txt | 4 +- .../unparser/corpus/literal/kwbegin.txt | 19 +- .../unparser/corpus/literal/module.txt | 16 +- .../unparser/corpus/literal/pattern.txt | 8 +- .../unparser/corpus/literal/send.txt | 10 +- .../unparser/corpus/literal/variables.txt | 20 +- .../unparser/corpus/literal/while.txt | 12 +- .../unparser/corpus/semantic/def.txt | 2 +- .../unparser/corpus/semantic/kwbegin.txt | 8 +- .../unparser/corpus/semantic/while.txt | 2 +- test/yarp/snapshots/variables.txt | 1 + test/yarp/snapshots/while.txt | 2 +- .../whitequark/bug_rescue_empty_else.txt | 2 +- .../snapshots/whitequark/casgn_scoped.txt | 4 +- .../snapshots/whitequark/casgn_toplevel.txt | 2 +- .../snapshots/whitequark/casgn_unscoped.txt | 2 +- test/yarp/snapshots/whitequark/class.txt | 4 +- .../class_definition_in_while_cond.txt | 4 +- .../yarp/snapshots/whitequark/class_super.txt | 4 +- .../whitequark/class_super_label.txt | 2 +- .../snapshots/whitequark/const_op_asgn.txt | 11 +- .../snapshots/whitequark/const_scoped.txt | 4 +- .../snapshots/whitequark/const_toplevel.txt | 2 +- .../snapshots/whitequark/const_unscoped.txt | 2 +- test/yarp/snapshots/whitequark/cpath.txt | 6 +- test/yarp/snapshots/whitequark/defs.txt | 4 +- .../if_while_after_class__since_32.txt | 18 +- .../yarp/snapshots/whitequark/masgn_const.txt | 8 +- test/yarp/snapshots/whitequark/module.txt | 2 +- .../whitequark/numparam_outside_block.txt | 4 +- .../yarp/snapshots/whitequark/op_asgn_cmd.txt | 2 +- .../snapshots/whitequark/parser_bug_490.txt | 5 +- .../snapshots/whitequark/parser_bug_518.txt | 4 +- .../snapshots/whitequark/resbody_list.txt | 2 +- .../whitequark/resbody_list_mrhs.txt | 2 +- .../snapshots/whitequark/ruby_bug_12073.txt | 4 +- .../snapshots/whitequark/ruby_bug_12402.txt | 4 +- .../snapshots/whitequark/send_attr_asgn.txt | 2 +- .../whitequark/ternary_ambiguous_symbol.txt | 2 +- yarp/config.yml | 14 ++ yarp/yarp.c | 57 +++-- 99 files changed, 478 insertions(+), 411 deletions(-) diff --git a/lib/yarp/desugar_visitor.rb b/lib/yarp/desugar_visitor.rb index 9aabda5939d7f9..6ee5861ac8b390 100644 --- a/lib/yarp/desugar_visitor.rb +++ b/lib/yarp/desugar_visitor.rb @@ -8,7 +8,7 @@ class DesugarVisitor < MutationVisitor # # @@foo && @@foo = bar def visit_class_variable_and_write_node(node) - desugar_and_write_node(node, ClassVariableReadNode, ClassVariableWriteNode, arguments: [node.name]) + desugar_and_write_node(node, ClassVariableReadNode, ClassVariableWriteNode, node.name) end # @@foo ||= bar @@ -17,7 +17,7 @@ def visit_class_variable_and_write_node(node) # # defined?(@@foo) ? @@foo : @@foo = bar def visit_class_variable_or_write_node(node) - desugar_or_write_defined_node(node, ClassVariableReadNode, ClassVariableWriteNode, arguments: [node.name]) + desugar_or_write_defined_node(node, ClassVariableReadNode, ClassVariableWriteNode, node.name) end # @@foo += bar @@ -26,7 +26,7 @@ def visit_class_variable_or_write_node(node) # # @@foo = @@foo + bar def visit_class_variable_operator_write_node(node) - desugar_operator_write_node(node, ClassVariableReadNode, ClassVariableWriteNode, arguments: [node.name]) + desugar_operator_write_node(node, ClassVariableReadNode, ClassVariableWriteNode, node.name) end # Foo &&= bar @@ -35,7 +35,7 @@ def visit_class_variable_operator_write_node(node) # # Foo && Foo = bar def visit_constant_and_write_node(node) - desugar_and_write_node(node, ConstantReadNode, ConstantWriteNode) + desugar_and_write_node(node, ConstantReadNode, ConstantWriteNode, node.name) end # Foo ||= bar @@ -44,7 +44,7 @@ def visit_constant_and_write_node(node) # # defined?(Foo) ? Foo : Foo = bar def visit_constant_or_write_node(node) - desugar_or_write_defined_node(node, ConstantReadNode, ConstantWriteNode) + desugar_or_write_defined_node(node, ConstantReadNode, ConstantWriteNode, node.name) end # Foo += bar @@ -53,7 +53,7 @@ def visit_constant_or_write_node(node) # # Foo = Foo + bar def visit_constant_operator_write_node(node) - desugar_operator_write_node(node, ConstantReadNode, ConstantWriteNode) + desugar_operator_write_node(node, ConstantReadNode, ConstantWriteNode, node.name) end # $foo &&= bar @@ -62,7 +62,7 @@ def visit_constant_operator_write_node(node) # # $foo && $foo = bar def visit_global_variable_and_write_node(node) - desugar_and_write_node(node, GlobalVariableReadNode, GlobalVariableWriteNode, arguments: [node.name]) + desugar_and_write_node(node, GlobalVariableReadNode, GlobalVariableWriteNode, node.name) end # $foo ||= bar @@ -71,7 +71,7 @@ def visit_global_variable_and_write_node(node) # # defined?($foo) ? $foo : $foo = bar def visit_global_variable_or_write_node(node) - desugar_or_write_defined_node(node, GlobalVariableReadNode, GlobalVariableWriteNode, arguments: [node.name]) + desugar_or_write_defined_node(node, GlobalVariableReadNode, GlobalVariableWriteNode, node.name) end # $foo += bar @@ -80,7 +80,7 @@ def visit_global_variable_or_write_node(node) # # $foo = $foo + bar def visit_global_variable_operator_write_node(node) - desugar_operator_write_node(node, GlobalVariableReadNode, GlobalVariableWriteNode, arguments: [node.name]) + desugar_operator_write_node(node, GlobalVariableReadNode, GlobalVariableWriteNode, node.name) end # @foo &&= bar @@ -89,7 +89,7 @@ def visit_global_variable_operator_write_node(node) # # @foo && @foo = bar def visit_instance_variable_and_write_node(node) - desugar_and_write_node(node, InstanceVariableReadNode, InstanceVariableWriteNode, arguments: [node.name]) + desugar_and_write_node(node, InstanceVariableReadNode, InstanceVariableWriteNode, node.name) end # @foo ||= bar @@ -98,7 +98,7 @@ def visit_instance_variable_and_write_node(node) # # @foo || @foo = bar def visit_instance_variable_or_write_node(node) - desugar_or_write_node(node, InstanceVariableReadNode, InstanceVariableWriteNode, arguments: [node.name]) + desugar_or_write_node(node, InstanceVariableReadNode, InstanceVariableWriteNode, node.name) end # @foo += bar @@ -107,7 +107,7 @@ def visit_instance_variable_or_write_node(node) # # @foo = @foo + bar def visit_instance_variable_operator_write_node(node) - desugar_operator_write_node(node, InstanceVariableReadNode, InstanceVariableWriteNode, arguments: [node.name]) + desugar_operator_write_node(node, InstanceVariableReadNode, InstanceVariableWriteNode, node.name) end # foo &&= bar @@ -116,7 +116,7 @@ def visit_instance_variable_operator_write_node(node) # # foo && foo = bar def visit_local_variable_and_write_node(node) - desugar_and_write_node(node, LocalVariableReadNode, LocalVariableWriteNode, arguments: [node.name, node.depth]) + desugar_and_write_node(node, LocalVariableReadNode, LocalVariableWriteNode, node.name, node.depth) end # foo ||= bar @@ -125,7 +125,7 @@ def visit_local_variable_and_write_node(node) # # foo || foo = bar def visit_local_variable_or_write_node(node) - desugar_or_write_node(node, LocalVariableReadNode, LocalVariableWriteNode, arguments: [node.name, node.depth]) + desugar_or_write_node(node, LocalVariableReadNode, LocalVariableWriteNode, node.name, node.depth) end # foo += bar @@ -134,13 +134,13 @@ def visit_local_variable_or_write_node(node) # # foo = foo + bar def visit_local_variable_operator_write_node(node) - desugar_operator_write_node(node, LocalVariableReadNode, LocalVariableWriteNode, arguments: [node.name, node.depth]) + desugar_operator_write_node(node, LocalVariableReadNode, LocalVariableWriteNode, node.name, node.depth) end private # Desugar `x &&= y` to `x && x = y` - def desugar_and_write_node(node, read_class, write_class, arguments: []) + def desugar_and_write_node(node, read_class, write_class, *arguments) AndNode.new( read_class.new(*arguments, node.name_loc), write_class.new(*arguments, node.name_loc, node.value, node.operator_loc, node.location), @@ -150,7 +150,7 @@ def desugar_and_write_node(node, read_class, write_class, arguments: []) end # Desugar `x += y` to `x = x + y` - def desugar_operator_write_node(node, read_class, write_class, arguments: []) + def desugar_operator_write_node(node, read_class, write_class, *arguments) write_class.new( *arguments, node.name_loc, @@ -172,7 +172,7 @@ def desugar_operator_write_node(node, read_class, write_class, arguments: []) end # Desugar `x ||= y` to `x || x = y` - def desugar_or_write_node(node, read_class, write_class, arguments: []) + def desugar_or_write_node(node, read_class, write_class, *arguments) OrNode.new( read_class.new(*arguments, node.name_loc), write_class.new(*arguments, node.name_loc, node.value, node.operator_loc, node.location), @@ -182,7 +182,7 @@ def desugar_or_write_node(node, read_class, write_class, arguments: []) end # Desugar `x ||= y` to `defined?(x) ? x : x = y` - def desugar_or_write_defined_node(node, read_class, write_class, arguments: []) + def desugar_or_write_defined_node(node, read_class, write_class, *arguments) IfNode.new( node.operator_loc, DefinedNode.new(nil, read_class.new(*arguments, node.name_loc), nil, node.operator_loc, node.name_loc), diff --git a/test/yarp/errors_test.rb b/test/yarp/errors_test.rb index e1c40e11cb297c..90be76ab5b72fa 100644 --- a/test/yarp/errors_test.rb +++ b/test/yarp/errors_test.rb @@ -17,7 +17,7 @@ def test_module_name_recoverable expected = ModuleNode( [], Location(), - ConstantReadNode(), + ConstantReadNode(:Parent), StatementsNode( [ModuleNode([], Location(), MissingNode(), nil, Location(), "")] ), @@ -393,7 +393,7 @@ def test_module_definition_in_method_body Location(), nil, nil, - StatementsNode([ModuleNode([], Location(), ConstantReadNode(), nil, Location(), "A")]), + StatementsNode([ModuleNode([], Location(), ConstantReadNode(:A), nil, Location(), "A")]), [], Location(), nil, @@ -424,7 +424,7 @@ def test_module_definition_in_method_body_within_block BlockNode( [], nil, - StatementsNode([ModuleNode([], Location(), ConstantReadNode(), nil, Location(), "Foo")]), + StatementsNode([ModuleNode([], Location(), ConstantReadNode(:Foo), nil, Location(), "Foo")]), Location(), Location() ), @@ -459,7 +459,7 @@ def test_class_definition_in_method_body [ClassNode( [], Location(), - ConstantReadNode(), + ConstantReadNode(:A), nil, nil, nil, @@ -974,7 +974,7 @@ def test_dont_allow_return_inside_class_body expected = ClassNode( [], Location(), - ConstantReadNode(), + ConstantReadNode(:A), nil, nil, StatementsNode([ReturnNode(Location(), nil)]), @@ -991,7 +991,7 @@ def test_dont_allow_return_inside_module_body expected = ModuleNode( [], Location(), - ConstantReadNode(), + ConstantReadNode(:A), StatementsNode([ReturnNode(Location(), nil)]), Location(), "A" diff --git a/test/yarp/snapshots/begin_ensure.txt b/test/yarp/snapshots/begin_ensure.txt index 8e9873122bb589..a842d8f07ffef6 100644 --- a/test/yarp/snapshots/begin_ensure.txt +++ b/test/yarp/snapshots/begin_ensure.txt @@ -86,7 +86,7 @@ ProgramNode(0...211)( (118...124), StatementsNode(125...199)( [CallNode(125...199)( - ConstantReadNode(125...131)(), + ConstantReadNode(125...131)(:Module), (131...132), (132...135), nil, @@ -107,7 +107,9 @@ ProgramNode(0...211)( (161...167), StatementsNode(168...189)( [CallNode(168...189)( - ConstantReadNode(168...174)(), + ConstantReadNode(168...174)( + :Module + ), (174...175), (175...178), nil, diff --git a/test/yarp/snapshots/begin_rescue.txt b/test/yarp/snapshots/begin_rescue.txt index 4c902e53509898..ac0592054a0c9d 100644 --- a/test/yarp/snapshots/begin_rescue.txt +++ b/test/yarp/snapshots/begin_rescue.txt @@ -221,7 +221,7 @@ ProgramNode(0...578)( ), RescueNode(187...265)( (187...193), - [ConstantReadNode(194...203)()], + [ConstantReadNode(194...203)(:Exception)], (204...206), LocalVariableTargetNode(207...209)(:ex, 0), StatementsNode(212...213)( @@ -239,7 +239,8 @@ ProgramNode(0...578)( ), RescueNode(214...265)( (214...220), - [ConstantReadNode(221...237)(), ConstantReadNode(239...255)()], + [ConstantReadNode(221...237)(:AnotherException), + ConstantReadNode(239...255)(:OneMoreException)], (256...258), LocalVariableTargetNode(259...261)(:ex, 0), StatementsNode(264...265)( @@ -279,7 +280,7 @@ ProgramNode(0...578)( ), RescueNode(281...307)( (281...287), - [ConstantReadNode(288...297)()], + [ConstantReadNode(288...297)(:Exception)], (298...300), LocalVariableTargetNode(301...303)(:ex, 0), StatementsNode(306...307)( @@ -452,7 +453,7 @@ ProgramNode(0...578)( ), RescueNode(406...424)( (406...412), - [ConstantReadNode(413...422)()], + [ConstantReadNode(413...422)(:Exception)], nil, nil, StatementsNode(423...424)( @@ -491,7 +492,8 @@ ProgramNode(0...578)( ), RescueNode(438...473)( (438...444), - [ConstantReadNode(445...454)(), ConstantReadNode(456...471)()], + [ConstantReadNode(445...454)(:Exception), + ConstantReadNode(456...471)(:CustomException)], nil, nil, StatementsNode(472...473)( @@ -530,7 +532,8 @@ ProgramNode(0...578)( ), RescueNode(489...532)( (489...495), - [ConstantReadNode(496...505)(), ConstantReadNode(507...522)()], + [ConstantReadNode(496...505)(:Exception), + ConstantReadNode(507...522)(:CustomException)], (523...525), LocalVariableTargetNode(526...528)(:ex, 0), StatementsNode(531...532)( @@ -569,7 +572,7 @@ ProgramNode(0...578)( ), RescueNode(548...574)( (548...554), - [ConstantReadNode(555...564)()], + [ConstantReadNode(555...564)(:Exception)], (565...567), LocalVariableTargetNode(568...570)(:ex, 0), StatementsNode(573...574)( diff --git a/test/yarp/snapshots/case.txt b/test/yarp/snapshots/case.txt index f041410e3ce108..346b466a5e2d37 100644 --- a/test/yarp/snapshots/case.txt +++ b/test/yarp/snapshots/case.txt @@ -111,7 +111,8 @@ ProgramNode(0...272)( ), [WhenNode(147...167)( (147...151), - [ConstantReadNode(152...158)(), ConstantReadNode(160...167)()], + [ConstantReadNode(152...158)(:FooBar), + ConstantReadNode(160...167)(:BazBonk)], nil )], nil, diff --git a/test/yarp/snapshots/classes.txt b/test/yarp/snapshots/classes.txt index 1d8813f40e342f..4f4bc5513df818 100644 --- a/test/yarp/snapshots/classes.txt +++ b/test/yarp/snapshots/classes.txt @@ -4,7 +4,7 @@ ProgramNode(0...370)( [ClassNode(0...17)( [:a], (0...5), - ConstantReadNode(6...7)(), + ConstantReadNode(6...7)(:A), nil, nil, StatementsNode(8...13)( @@ -22,7 +22,7 @@ ProgramNode(0...370)( ClassNode(19...39)( [], (19...24), - ConstantReadNode(25...26)(), + ConstantReadNode(25...26)(:A), nil, nil, BeginNode(28...39)( @@ -39,7 +39,7 @@ ProgramNode(0...370)( ClassNode(41...75)( [], (41...46), - ConstantReadNode(47...48)(), + ConstantReadNode(47...48)(:A), nil, nil, BeginNode(50...75)( @@ -56,9 +56,9 @@ ProgramNode(0...370)( ClassNode(77...98)( [:a], (77...82), - ConstantReadNode(83...84)(), + ConstantReadNode(83...84)(:A), (85...86), - ConstantReadNode(87...88)(), + ConstantReadNode(87...88)(:B), StatementsNode(89...94)( [LocalVariableWriteNode(89...94)( :a, @@ -102,7 +102,7 @@ ProgramNode(0...370)( ClassNode(122...162)( [], (122...127), - ConstantReadNode(128...129)(), + ConstantReadNode(128...129)(:A), nil, nil, StatementsNode(131...157)( @@ -128,7 +128,7 @@ ProgramNode(0...370)( ClassNode(164...218)( [], (164...169), - ConstantReadNode(170...171)(), + ConstantReadNode(170...171)(:A), nil, nil, StatementsNode(173...213)( @@ -266,10 +266,10 @@ ProgramNode(0...370)( ClassNode(352...370)( [], (352...357), - ConstantReadNode(358...359)(), + ConstantReadNode(358...359)(:A), (360...361), CallNode(362...366)( - ConstantReadNode(362...363)(), + ConstantReadNode(362...363)(:B), nil, (363...366), (363...364), diff --git a/test/yarp/snapshots/constants.txt b/test/yarp/snapshots/constants.txt index 05529a2bc84c62..bf4564c46d02fa 100644 --- a/test/yarp/snapshots/constants.txt +++ b/test/yarp/snapshots/constants.txt @@ -2,35 +2,40 @@ ProgramNode(0...792)( [], StatementsNode(0...792)( [ConstantPathNode(0...4)( - ConstantReadNode(0...1)(), - ConstantReadNode(3...4)(), + ConstantReadNode(0...1)(:A), + ConstantReadNode(3...4)(:B), (1...3) ), ConstantPathNode(6...13)( ConstantPathNode(6...10)( - ConstantReadNode(6...7)(), - ConstantReadNode(9...10)(), + ConstantReadNode(6...7)(:A), + ConstantReadNode(9...10)(:B), (7...9) ), - ConstantReadNode(12...13)(), + ConstantReadNode(12...13)(:C), (10...12) ), ConstantPathNode(15...19)( CallNode(15...16)(nil, nil, (15...16), nil, nil, nil, nil, 2, "a"), - ConstantReadNode(18...19)(), + ConstantReadNode(18...19)(:B), (16...18) ), ConstantPathWriteNode(21...29)( ConstantPathNode(21...25)( - ConstantReadNode(21...22)(), - ConstantReadNode(24...25)(), + ConstantReadNode(21...22)(:A), + ConstantReadNode(24...25)(:B), (22...24) ), (26...27), IntegerNode(28...29)() ), - ConstantWriteNode(31...36)((31...32), IntegerNode(35...36)(), (33...34)), - ConstantReadNode(38...41)(), + ConstantWriteNode(31...36)( + :A, + (31...32), + IntegerNode(35...36)(), + (33...34) + ), + ConstantReadNode(38...41)(:ABC), CallNode(43...48)( nil, nil, @@ -123,7 +128,7 @@ ProgramNode(0...792)( "Foo" ), CallNode(81...94)( - ConstantReadNode(81...84)(), + ConstantReadNode(81...84)(:Foo), (84...86), (86...89), nil, @@ -149,7 +154,7 @@ ProgramNode(0...792)( "Bar" ), CallNode(96...110)( - ConstantReadNode(96...99)(), + ConstantReadNode(96...99)(:Foo), (99...101), (101...104), nil, @@ -177,7 +182,7 @@ ProgramNode(0...792)( "Bar" ), CallNode(112...125)( - ConstantReadNode(112...115)(), + ConstantReadNode(112...115)(:Foo), (115...117), (117...120), nil, @@ -205,7 +210,7 @@ ProgramNode(0...792)( CallNode(127...135)( ConstantPathNode(127...130)( nil, - ConstantReadNode(129...130)(), + ConstantReadNode(129...130)(:A), (127...129) ), (130...132), @@ -220,7 +225,7 @@ ProgramNode(0...792)( ConstantPathWriteNode(137...144)( ConstantPathNode(137...140)( nil, - ConstantReadNode(139...140)(), + ConstantReadNode(139...140)(:A), (137...139) ), (141...142), @@ -230,10 +235,10 @@ ProgramNode(0...792)( ConstantPathNode(146...152)( ConstantPathNode(146...149)( nil, - ConstantReadNode(148...149)(), + ConstantReadNode(148...149)(:A), (146...148) ), - ConstantReadNode(151...152)(), + ConstantReadNode(151...152)(:B), (149...151) ), (153...154), @@ -242,19 +247,19 @@ ProgramNode(0...792)( ConstantPathNode(158...164)( ConstantPathNode(158...161)( nil, - ConstantReadNode(160...161)(), + ConstantReadNode(160...161)(:A), (158...160) ), - ConstantReadNode(163...164)(), + ConstantReadNode(163...164)(:B), (161...163) ), ConstantPathNode(166...169)( nil, - ConstantReadNode(168...169)(), + ConstantReadNode(168...169)(:A), (166...168) ), CallNode(171...179)( - ConstantReadNode(171...172)(), + ConstantReadNode(171...172)(:A), (172...174), (174...179), nil, @@ -266,8 +271,8 @@ ProgramNode(0...792)( ), CallNode(181...191)( ConstantPathNode(181...185)( - ConstantReadNode(181...182)(), - ConstantReadNode(184...185)(), + ConstantReadNode(181...182)(:A), + ConstantReadNode(184...185)(:B), (182...184) ), (185...187), @@ -280,7 +285,7 @@ ProgramNode(0...792)( "true" ), CallNode(193...197)( - ConstantReadNode(193...194)(), + ConstantReadNode(193...194)(:A), (194...196), (196...197), nil, @@ -291,7 +296,7 @@ ProgramNode(0...792)( "&" ), CallNode(199...203)( - ConstantReadNode(199...200)(), + ConstantReadNode(199...200)(:A), (200...202), (202...203), nil, @@ -302,7 +307,7 @@ ProgramNode(0...792)( "`" ), CallNode(205...209)( - ConstantReadNode(205...206)(), + ConstantReadNode(205...206)(:A), (206...208), (208...209), nil, @@ -313,7 +318,7 @@ ProgramNode(0...792)( "!" ), CallNode(211...216)( - ConstantReadNode(211...212)(), + ConstantReadNode(211...212)(:A), (212...214), (214...216), nil, @@ -324,7 +329,7 @@ ProgramNode(0...792)( "!=" ), CallNode(218...222)( - ConstantReadNode(218...219)(), + ConstantReadNode(218...219)(:A), (219...221), (221...222), nil, @@ -335,7 +340,7 @@ ProgramNode(0...792)( "^" ), CallNode(224...229)( - ConstantReadNode(224...225)(), + ConstantReadNode(224...225)(:A), (225...227), (227...229), nil, @@ -346,7 +351,7 @@ ProgramNode(0...792)( "==" ), CallNode(231...237)( - ConstantReadNode(231...232)(), + ConstantReadNode(231...232)(:A), (232...234), (234...237), nil, @@ -357,7 +362,7 @@ ProgramNode(0...792)( "===" ), CallNode(239...244)( - ConstantReadNode(239...240)(), + ConstantReadNode(239...240)(:A), (240...242), (242...244), nil, @@ -368,7 +373,7 @@ ProgramNode(0...792)( "=~" ), CallNode(246...250)( - ConstantReadNode(246...247)(), + ConstantReadNode(246...247)(:A), (247...249), (249...250), nil, @@ -379,7 +384,7 @@ ProgramNode(0...792)( ">" ), CallNode(252...257)( - ConstantReadNode(252...253)(), + ConstantReadNode(252...253)(:A), (253...255), (255...257), nil, @@ -390,7 +395,7 @@ ProgramNode(0...792)( ">=" ), CallNode(259...264)( - ConstantReadNode(259...260)(), + ConstantReadNode(259...260)(:A), (260...262), (262...264), nil, @@ -401,7 +406,7 @@ ProgramNode(0...792)( ">>" ), CallNode(266...271)( - ConstantReadNode(266...267)(), + ConstantReadNode(266...267)(:A), (267...269), (269...271), nil, @@ -412,12 +417,12 @@ ProgramNode(0...792)( "<<" ), ConstantPathNode(273...281)( - ConstantReadNode(273...274)(), - ConstantReadNode(280...281)(), + ConstantReadNode(273...274)(:A), + ConstantReadNode(280...281)(:C), (274...276) ), CallNode(283...291)( - ConstantReadNode(283...284)(), + ConstantReadNode(283...284)(:A), (284...286), (286...291), nil, @@ -428,7 +433,7 @@ ProgramNode(0...792)( "alias" ), CallNode(293...299)( - ConstantReadNode(293...294)(), + ConstantReadNode(293...294)(:A), (294...296), (296...299), nil, @@ -439,7 +444,7 @@ ProgramNode(0...792)( "and" ), CallNode(301...309)( - ConstantReadNode(301...302)(), + ConstantReadNode(301...302)(:A), (302...304), (304...309), nil, @@ -450,12 +455,12 @@ ProgramNode(0...792)( "begin" ), ConstantPathNode(311...319)( - ConstantReadNode(311...312)(), - ConstantReadNode(314...319)(), + ConstantReadNode(311...312)(:A), + ConstantReadNode(314...319)(:BEGIN), (312...314) ), CallNode(321...329)( - ConstantReadNode(321...322)(), + ConstantReadNode(321...322)(:A), (322...324), (324...329), nil, @@ -466,7 +471,7 @@ ProgramNode(0...792)( "break" ), CallNode(331...339)( - ConstantReadNode(331...332)(), + ConstantReadNode(331...332)(:A), (332...334), (334...339), nil, @@ -477,7 +482,7 @@ ProgramNode(0...792)( "class" ), CallNode(341...347)( - ConstantReadNode(341...342)(), + ConstantReadNode(341...342)(:A), (342...344), (344...347), nil, @@ -488,7 +493,7 @@ ProgramNode(0...792)( "def" ), CallNode(349...359)( - ConstantReadNode(349...350)(), + ConstantReadNode(349...350)(:A), (350...352), (352...359), nil, @@ -499,7 +504,7 @@ ProgramNode(0...792)( "defined" ), CallNode(361...366)( - ConstantReadNode(361...362)(), + ConstantReadNode(361...362)(:A), (362...364), (364...366), nil, @@ -510,7 +515,7 @@ ProgramNode(0...792)( "do" ), CallNode(368...375)( - ConstantReadNode(368...369)(), + ConstantReadNode(368...369)(:A), (369...371), (371...375), nil, @@ -521,7 +526,7 @@ ProgramNode(0...792)( "else" ), CallNode(377...385)( - ConstantReadNode(377...378)(), + ConstantReadNode(377...378)(:A), (378...380), (380...385), nil, @@ -532,7 +537,7 @@ ProgramNode(0...792)( "elsif" ), CallNode(387...393)( - ConstantReadNode(387...388)(), + ConstantReadNode(387...388)(:A), (388...390), (390...393), nil, @@ -543,12 +548,12 @@ ProgramNode(0...792)( "end" ), ConstantPathNode(395...401)( - ConstantReadNode(395...396)(), - ConstantReadNode(398...401)(), + ConstantReadNode(395...396)(:A), + ConstantReadNode(398...401)(:END), (396...398) ), CallNode(403...412)( - ConstantReadNode(403...404)(), + ConstantReadNode(403...404)(:A), (404...406), (406...412), nil, @@ -559,7 +564,7 @@ ProgramNode(0...792)( "ensure" ), CallNode(414...422)( - ConstantReadNode(414...415)(), + ConstantReadNode(414...415)(:A), (415...417), (417...422), nil, @@ -570,7 +575,7 @@ ProgramNode(0...792)( "false" ), CallNode(424...430)( - ConstantReadNode(424...425)(), + ConstantReadNode(424...425)(:A), (425...427), (427...430), nil, @@ -581,7 +586,7 @@ ProgramNode(0...792)( "for" ), CallNode(432...437)( - ConstantReadNode(432...433)(), + ConstantReadNode(432...433)(:A), (433...435), (435...437), nil, @@ -592,7 +597,7 @@ ProgramNode(0...792)( "if" ), CallNode(439...444)( - ConstantReadNode(439...440)(), + ConstantReadNode(439...440)(:A), (440...442), (442...444), nil, @@ -603,7 +608,7 @@ ProgramNode(0...792)( "in" ), CallNode(446...453)( - ConstantReadNode(446...447)(), + ConstantReadNode(446...447)(:A), (447...449), (449...453), nil, @@ -614,7 +619,7 @@ ProgramNode(0...792)( "next" ), CallNode(455...461)( - ConstantReadNode(455...456)(), + ConstantReadNode(455...456)(:A), (456...458), (458...461), nil, @@ -625,7 +630,7 @@ ProgramNode(0...792)( "nil" ), CallNode(463...469)( - ConstantReadNode(463...464)(), + ConstantReadNode(463...464)(:A), (464...466), (466...469), nil, @@ -636,7 +641,7 @@ ProgramNode(0...792)( "not" ), CallNode(471...476)( - ConstantReadNode(471...472)(), + ConstantReadNode(471...472)(:A), (472...474), (474...476), nil, @@ -647,7 +652,7 @@ ProgramNode(0...792)( "or" ), CallNode(478...485)( - ConstantReadNode(478...479)(), + ConstantReadNode(478...479)(:A), (479...481), (481...485), nil, @@ -658,7 +663,7 @@ ProgramNode(0...792)( "redo" ), CallNode(487...496)( - ConstantReadNode(487...488)(), + ConstantReadNode(487...488)(:A), (488...490), (490...496), nil, @@ -669,7 +674,7 @@ ProgramNode(0...792)( "rescue" ), CallNode(498...506)( - ConstantReadNode(498...499)(), + ConstantReadNode(498...499)(:A), (499...501), (501...506), nil, @@ -680,7 +685,7 @@ ProgramNode(0...792)( "retry" ), CallNode(508...517)( - ConstantReadNode(508...509)(), + ConstantReadNode(508...509)(:A), (509...511), (511...517), nil, @@ -691,7 +696,7 @@ ProgramNode(0...792)( "return" ), CallNode(519...526)( - ConstantReadNode(519...520)(), + ConstantReadNode(519...520)(:A), (520...522), (522...526), nil, @@ -702,7 +707,7 @@ ProgramNode(0...792)( "self" ), CallNode(528...536)( - ConstantReadNode(528...529)(), + ConstantReadNode(528...529)(:A), (529...531), (531...536), nil, @@ -713,7 +718,7 @@ ProgramNode(0...792)( "super" ), CallNode(538...545)( - ConstantReadNode(538...539)(), + ConstantReadNode(538...539)(:A), (539...541), (541...545), nil, @@ -724,7 +729,7 @@ ProgramNode(0...792)( "then" ), CallNode(547...554)( - ConstantReadNode(547...548)(), + ConstantReadNode(547...548)(:A), (548...550), (550...554), nil, @@ -735,7 +740,7 @@ ProgramNode(0...792)( "true" ), CallNode(556...564)( - ConstantReadNode(556...557)(), + ConstantReadNode(556...557)(:A), (557...559), (559...564), nil, @@ -746,7 +751,7 @@ ProgramNode(0...792)( "undef" ), CallNode(566...575)( - ConstantReadNode(566...567)(), + ConstantReadNode(566...567)(:A), (567...569), (569...575), nil, @@ -757,7 +762,7 @@ ProgramNode(0...792)( "unless" ), CallNode(577...585)( - ConstantReadNode(577...578)(), + ConstantReadNode(577...578)(:A), (578...580), (580...585), nil, @@ -768,7 +773,7 @@ ProgramNode(0...792)( "until" ), CallNode(587...594)( - ConstantReadNode(587...588)(), + ConstantReadNode(587...588)(:A), (588...590), (590...594), nil, @@ -779,7 +784,7 @@ ProgramNode(0...792)( "when" ), CallNode(596...604)( - ConstantReadNode(596...597)(), + ConstantReadNode(596...597)(:A), (597...599), (599...604), nil, @@ -790,7 +795,7 @@ ProgramNode(0...792)( "while" ), CallNode(606...614)( - ConstantReadNode(606...607)(), + ConstantReadNode(606...607)(:A), (607...609), (609...614), nil, @@ -801,7 +806,7 @@ ProgramNode(0...792)( "yield" ), CallNode(616...631)( - ConstantReadNode(616...617)(), + ConstantReadNode(616...617)(:A), (617...619), (619...631), nil, @@ -812,7 +817,7 @@ ProgramNode(0...792)( "__ENCODING__" ), CallNode(633...644)( - ConstantReadNode(633...634)(), + ConstantReadNode(633...634)(:A), (634...636), (636...644), nil, @@ -823,7 +828,7 @@ ProgramNode(0...792)( "__FILE__" ), CallNode(646...657)( - ConstantReadNode(646...647)(), + ConstantReadNode(646...647)(:A), (647...649), (649...657), nil, @@ -834,7 +839,7 @@ ProgramNode(0...792)( "__LINE__" ), CallNode(659...663)( - ConstantReadNode(659...660)(), + ConstantReadNode(659...660)(:A), (660...662), (662...663), nil, @@ -845,7 +850,7 @@ ProgramNode(0...792)( "<" ), CallNode(665...671)( - ConstantReadNode(665...666)(), + ConstantReadNode(665...666)(:A), (666...668), (668...671), nil, @@ -856,7 +861,7 @@ ProgramNode(0...792)( "<=>" ), CallNode(673...678)( - ConstantReadNode(673...674)(), + ConstantReadNode(673...674)(:A), (674...676), (676...678), nil, @@ -867,7 +872,7 @@ ProgramNode(0...792)( "<<" ), CallNode(680...684)( - ConstantReadNode(680...681)(), + ConstantReadNode(680...681)(:A), (681...683), (683...684), nil, @@ -878,7 +883,7 @@ ProgramNode(0...792)( "-" ), CallNode(686...690)( - ConstantReadNode(686...687)(), + ConstantReadNode(686...687)(:A), (687...689), (689...690), nil, @@ -889,7 +894,7 @@ ProgramNode(0...792)( "%" ), CallNode(692...697)( - ConstantReadNode(692...693)(), + ConstantReadNode(692...693)(:A), (693...695), (695...696), nil, @@ -912,7 +917,7 @@ ProgramNode(0...792)( "%" ), CallNode(699...704)( - ConstantReadNode(699...700)(), + ConstantReadNode(699...700)(:A), (700...702), (702...703), nil, @@ -935,7 +940,7 @@ ProgramNode(0...792)( "%" ), CallNode(706...711)( - ConstantReadNode(706...707)(), + ConstantReadNode(706...707)(:A), (707...709), (709...710), nil, @@ -958,29 +963,29 @@ ProgramNode(0...792)( "%" ), CallNode(713...718)( - ConstantReadNode(713...714)(), + ConstantReadNode(713...714)(:A), (714...716), (716...717), nil, - ArgumentsNode(717...718)([ConstantReadNode(717...718)()]), + ArgumentsNode(717...718)([ConstantReadNode(717...718)(:I)]), nil, nil, 0, "%" ), CallNode(720...725)( - ConstantReadNode(720...721)(), + ConstantReadNode(720...721)(:A), (721...723), (723...724), nil, - ArgumentsNode(724...725)([ConstantReadNode(724...725)()]), + ArgumentsNode(724...725)([ConstantReadNode(724...725)(:W)]), nil, nil, 0, "%" ), CallNode(727...731)( - ConstantReadNode(727...728)(), + ConstantReadNode(727...728)(:A), (728...730), (730...731), nil, @@ -991,7 +996,7 @@ ProgramNode(0...792)( "|" ), CallNode(733...737)( - ConstantReadNode(733...734)(), + ConstantReadNode(733...734)(:A), (734...736), (736...737), nil, @@ -1002,7 +1007,7 @@ ProgramNode(0...792)( "+" ), CallNode(739...743)( - ConstantReadNode(739...740)(), + ConstantReadNode(739...740)(:A), (740...742), (742...743), nil, @@ -1013,7 +1018,7 @@ ProgramNode(0...792)( "/" ), CallNode(745...749)( - ConstantReadNode(745...746)(), + ConstantReadNode(745...746)(:A), (746...748), (748...749), nil, @@ -1024,7 +1029,7 @@ ProgramNode(0...792)( "*" ), CallNode(751...756)( - ConstantReadNode(751...752)(), + ConstantReadNode(751...752)(:A), (752...754), (754...756), nil, @@ -1035,7 +1040,7 @@ ProgramNode(0...792)( "**" ), CallNode(758...762)( - ConstantReadNode(758...759)(), + ConstantReadNode(758...759)(:A), (759...761), (761...762), nil, @@ -1047,7 +1052,7 @@ ProgramNode(0...792)( ), ConstantPathNode(764...772)( CallNode(764...768)( - ConstantReadNode(764...765)(), + ConstantReadNode(764...765)(:A), (765...767), (767...768), nil, @@ -1057,12 +1062,12 @@ ProgramNode(0...792)( 0, "_" ), - ConstantReadNode(771...772)(), + ConstantReadNode(771...772)(:C), (768...770) ), RangeNode(774...792)( CallNode(774...778)( - ConstantReadNode(774...775)(), + ConstantReadNode(774...775)(:A), (775...777), (777...778), nil, @@ -1073,7 +1078,7 @@ ProgramNode(0...792)( "_" ), CallNode(782...792)( - ConstantReadNode(782...783)(), + ConstantReadNode(782...783)(:A), (783...785), (785...792), nil, diff --git a/test/yarp/snapshots/if.txt b/test/yarp/snapshots/if.txt index d151d6b5471d97..07c8f714a33030 100644 --- a/test/yarp/snapshots/if.txt +++ b/test/yarp/snapshots/if.txt @@ -217,7 +217,7 @@ ProgramNode(0...382)( 2, "type" ), - ConstantReadNode(288...289)(), + ConstantReadNode(288...289)(:B), (285...287) ), nil, diff --git a/test/yarp/snapshots/method_calls.txt b/test/yarp/snapshots/method_calls.txt index cfbb0784711b44..6f11633de29b28 100644 --- a/test/yarp/snapshots/method_calls.txt +++ b/test/yarp/snapshots/method_calls.txt @@ -897,7 +897,7 @@ ProgramNode(0...1237)( "some_func" ), CallNode(697...715)( - ConstantReadNode(697...703)(), + ConstantReadNode(697...703)(:Kernel), (703...704), (704...711), (711...712), @@ -947,8 +947,8 @@ ProgramNode(0...1237)( ), CallNode(745...757)( ConstantPathNode(745...749)( - ConstantReadNode(745...746)(), - ConstantReadNode(748...749)(), + ConstantReadNode(745...746)(:A), + ConstantReadNode(748...749)(:B), (746...748) ), (749...751), @@ -964,8 +964,8 @@ ProgramNode(0...1237)( ), CallNode(759...772)( ConstantPathNode(759...763)( - ConstantReadNode(759...760)(), - ConstantReadNode(762...763)(), + ConstantReadNode(759...760)(:A), + ConstantReadNode(762...763)(:B), (760...762) ), (763...765), @@ -981,8 +981,8 @@ ProgramNode(0...1237)( ), CallNode(774...791)( ConstantPathNode(774...778)( - ConstantReadNode(774...775)(), - ConstantReadNode(777...778)(), + ConstantReadNode(774...775)(:A), + ConstantReadNode(777...778)(:B), (775...777) ), (778...780), @@ -1175,7 +1175,7 @@ ProgramNode(0...1237)( [ClassNode(905...929)( [], (905...910), - ConstantReadNode(911...914)(), + ConstantReadNode(911...914)(:Bar), nil, nil, StatementsNode(915...925)( @@ -1209,7 +1209,7 @@ ProgramNode(0...1237)( [ModuleNode(935...960)( [], (935...941), - ConstantReadNode(942...945)(), + ConstantReadNode(942...945)(:Bar), StatementsNode(946...956)( [CallNode(946...956)( nil, diff --git a/test/yarp/snapshots/methods.txt b/test/yarp/snapshots/methods.txt index 15042a2ce89b7e..a822d44199d462 100644 --- a/test/yarp/snapshots/methods.txt +++ b/test/yarp/snapshots/methods.txt @@ -968,13 +968,14 @@ ProgramNode(0...1194)( (872...875) ), ConstantWriteNode(877...886)( + :Const, (877...882), IntegerNode(885...886)(), (883...884) ), DefNode(888...903)( (898...899), - ConstantReadNode(892...897)(), + ConstantReadNode(892...897)(:Const), nil, nil, [], diff --git a/test/yarp/snapshots/modules.txt b/test/yarp/snapshots/modules.txt index aa8c1a743d749b..9ed5c89fe10450 100644 --- a/test/yarp/snapshots/modules.txt +++ b/test/yarp/snapshots/modules.txt @@ -4,7 +4,7 @@ ProgramNode(0...140)( [ModuleNode(0...18)( [:a], (0...6), - ConstantReadNode(7...8)(), + ConstantReadNode(7...8)(:A), StatementsNode(9...14)( [LocalVariableWriteNode(9...14)( :a, @@ -45,7 +45,7 @@ ProgramNode(0...140)( (40...46), ConstantPathNode(47...51)( CallNode(47...48)(nil, nil, (47...48), nil, nil, nil, nil, 2, "m"), - ConstantReadNode(50...51)(), + ConstantReadNode(50...51)(:M), (48...50) ), nil, @@ -55,7 +55,7 @@ ProgramNode(0...140)( ModuleNode(57...85)( [:x], (57...63), - ConstantReadNode(64...65)(), + ConstantReadNode(64...65)(:A), BeginNode(67...85)( nil, StatementsNode(67...72)( @@ -78,7 +78,11 @@ ProgramNode(0...140)( ModuleNode(87...101)( [], (87...93), - ConstantPathNode(94...97)(nil, ConstantReadNode(96...97)(), (94...96)), + ConstantPathNode(94...97)( + nil, + ConstantReadNode(96...97)(:A), + (94...96) + ), nil, (98...101), "A" @@ -88,7 +92,7 @@ ProgramNode(0...140)( (103...109), ConstantPathNode(110...116)( CallNode(110...113)( - ConstantReadNode(110...111)(), + ConstantReadNode(110...111)(:A), nil, (111...113), (111...112), @@ -98,7 +102,7 @@ ProgramNode(0...140)( 0, "[]" ), - ConstantReadNode(115...116)(), + ConstantReadNode(115...116)(:B), (113...115) ), nil, @@ -110,7 +114,7 @@ ProgramNode(0...140)( (122...128), ConstantPathNode(129...136)( CallNode(129...133)( - ConstantReadNode(129...130)(), + ConstantReadNode(129...130)(:A), nil, (130...133), (130...131), @@ -120,7 +124,7 @@ ProgramNode(0...140)( 0, "[]" ), - ConstantReadNode(135...136)(), + ConstantReadNode(135...136)(:B), (133...135) ), nil, diff --git a/test/yarp/snapshots/patterns.txt b/test/yarp/snapshots/patterns.txt index efcae6d0d49fd7..b2f03f6b6836df 100644 --- a/test/yarp/snapshots/patterns.txt +++ b/test/yarp/snapshots/patterns.txt @@ -1058,7 +1058,7 @@ ProgramNode(0...3743)( 2, "foo" ), - ConstantReadNode(1053...1056)(), + ConstantReadNode(1053...1056)(:Foo), (1050...1052) ), MatchRequiredNode(1057...1077)( @@ -1075,11 +1075,11 @@ ProgramNode(0...3743)( ), ConstantPathNode(1064...1077)( ConstantPathNode(1064...1072)( - ConstantReadNode(1064...1067)(), - ConstantReadNode(1069...1072)(), + ConstantReadNode(1064...1067)(:Foo), + ConstantReadNode(1069...1072)(:Bar), (1067...1069) ), - ConstantReadNode(1074...1077)(), + ConstantReadNode(1074...1077)(:Baz), (1072...1074) ), (1061...1063) @@ -1098,7 +1098,7 @@ ProgramNode(0...3743)( ), ConstantPathNode(1085...1090)( nil, - ConstantReadNode(1087...1090)(), + ConstantReadNode(1087...1090)(:Foo), (1085...1087) ), (1082...1084) @@ -1119,13 +1119,13 @@ ProgramNode(0...3743)( ConstantPathNode(1098...1108)( ConstantPathNode(1098...1103)( nil, - ConstantReadNode(1100...1103)(), + ConstantReadNode(1100...1103)(:Foo), (1098...1100) ), - ConstantReadNode(1105...1108)(), + ConstantReadNode(1105...1108)(:Bar), (1103...1105) ), - ConstantReadNode(1110...1113)(), + ConstantReadNode(1110...1113)(:Baz), (1108...1110) ), (1095...1097) @@ -1143,7 +1143,7 @@ ProgramNode(0...3743)( "foo" ), ArrayPatternNode(1122...1127)( - ConstantReadNode(1122...1125)(), + ConstantReadNode(1122...1125)(:Foo), [], nil, [], @@ -1165,7 +1165,7 @@ ProgramNode(0...3743)( "foo" ), ArrayPatternNode(1135...1141)( - ConstantReadNode(1135...1138)(), + ConstantReadNode(1135...1138)(:Foo), [IntegerNode(1139...1140)()], nil, [], @@ -1187,7 +1187,7 @@ ProgramNode(0...3743)( "foo" ), ArrayPatternNode(1149...1161)( - ConstantReadNode(1149...1152)(), + ConstantReadNode(1149...1152)(:Foo), [IntegerNode(1153...1154)(), IntegerNode(1156...1157)(), IntegerNode(1159...1160)()], @@ -1211,7 +1211,7 @@ ProgramNode(0...3743)( "foo" ), ArrayPatternNode(1169...1177)( - ConstantReadNode(1169...1172)(), + ConstantReadNode(1169...1172)(:Foo), [LocalVariableTargetNode(1173...1176)(:bar, 0)], nil, [], @@ -1233,7 +1233,7 @@ ProgramNode(0...3743)( "foo" ), ArrayPatternNode(1185...1199)( - ConstantReadNode(1185...1188)(), + ConstantReadNode(1185...1188)(:Foo), [], SplatNode(1189...1193)( (1189...1190), @@ -1258,7 +1258,7 @@ ProgramNode(0...3743)( "foo" ), ArrayPatternNode(1207...1221)( - ConstantReadNode(1207...1210)(), + ConstantReadNode(1207...1210)(:Foo), [LocalVariableTargetNode(1211...1214)(:bar, 0)], SplatNode(1216...1220)( (1216...1217), @@ -1283,7 +1283,7 @@ ProgramNode(0...3743)( "foo" ), FindPatternNode(1229...1249)( - ConstantReadNode(1229...1232)(), + ConstantReadNode(1229...1232)(:Foo), SplatNode(1233...1237)( (1233...1234), LocalVariableTargetNode(1234...1237)(:bar, 0) @@ -1311,7 +1311,7 @@ ProgramNode(0...3743)( "foo" ), ArrayPatternNode(1258...1263)( - ConstantReadNode(1258...1261)(), + ConstantReadNode(1258...1261)(:Foo), [], nil, [], @@ -1333,7 +1333,7 @@ ProgramNode(0...3743)( "foo" ), ArrayPatternNode(1271...1277)( - ConstantReadNode(1271...1274)(), + ConstantReadNode(1271...1274)(:Foo), [IntegerNode(1275...1276)()], nil, [], @@ -1355,7 +1355,7 @@ ProgramNode(0...3743)( "foo" ), ArrayPatternNode(1285...1297)( - ConstantReadNode(1285...1288)(), + ConstantReadNode(1285...1288)(:Foo), [IntegerNode(1289...1290)(), IntegerNode(1292...1293)(), IntegerNode(1295...1296)()], @@ -1379,9 +1379,9 @@ ProgramNode(0...3743)( "foo" ), ArrayPatternNode(1305...1315)( - ConstantReadNode(1305...1308)(), + ConstantReadNode(1305...1308)(:Foo), [ArrayPatternNode(1309...1314)( - ConstantReadNode(1309...1312)(), + ConstantReadNode(1309...1312)(:Foo), [], nil, [], @@ -1408,7 +1408,7 @@ ProgramNode(0...3743)( "foo" ), ArrayPatternNode(1323...1331)( - ConstantReadNode(1323...1326)(), + ConstantReadNode(1323...1326)(:Foo), [LocalVariableTargetNode(1327...1330)(:bar, 0)], nil, [], @@ -1430,7 +1430,7 @@ ProgramNode(0...3743)( "foo" ), ArrayPatternNode(1339...1353)( - ConstantReadNode(1339...1342)(), + ConstantReadNode(1339...1342)(:Foo), [], SplatNode(1343...1347)( (1343...1344), @@ -1455,7 +1455,7 @@ ProgramNode(0...3743)( "foo" ), ArrayPatternNode(1361...1375)( - ConstantReadNode(1361...1364)(), + ConstantReadNode(1361...1364)(:Foo), [LocalVariableTargetNode(1365...1368)(:bar, 0)], SplatNode(1370...1374)( (1370...1371), @@ -1480,7 +1480,7 @@ ProgramNode(0...3743)( "foo" ), FindPatternNode(1383...1403)( - ConstantReadNode(1383...1386)(), + ConstantReadNode(1383...1386)(:Foo), SplatNode(1387...1391)( (1387...1388), LocalVariableTargetNode(1388...1391)(:bar, 0) @@ -3819,11 +3819,11 @@ ProgramNode(0...3743)( "foo" ), HashPatternNode(3712...3743)( - ConstantReadNode(3712...3713)(), + ConstantReadNode(3712...3713)(:A), [AssocNode(3717...3741)( SymbolNode(3717...3721)(nil, (3717...3720), (3720...3721), "bar"), HashPatternNode(3722...3741)( - ConstantReadNode(3722...3723)(), + ConstantReadNode(3722...3723)(:B), [AssocNode(3729...3737)( SymbolNode(3729...3735)( nil, diff --git a/test/yarp/snapshots/seattlerb/TestRubyParserShared.txt b/test/yarp/snapshots/seattlerb/TestRubyParserShared.txt index 0eee2a39d7d165..32b444a2fc83fe 100644 --- a/test/yarp/snapshots/seattlerb/TestRubyParserShared.txt +++ b/test/yarp/snapshots/seattlerb/TestRubyParserShared.txt @@ -45,7 +45,7 @@ ProgramNode(0...689)( ClassNode(141...269)( [], (141...146), - ConstantReadNode(147...148)(), + ConstantReadNode(147...148)(:X), nil, nil, StatementsNode(168...246)( @@ -92,18 +92,19 @@ ProgramNode(0...689)( ClassNode(293...376)( [], (293...298), - ConstantReadNode(299...300)(), + ConstantReadNode(299...300)(:X), nil, nil, StatementsNode(315...358)( [ClassNode(315...358)( [], (315...320), - ConstantReadNode(321...322)(), + ConstantReadNode(321...322)(:Y), nil, nil, StatementsNode(337...343)( [ConstantWriteNode(337...343)( + :Z, (337...338), IntegerNode(341...343)(), (339...340) @@ -119,7 +120,7 @@ ProgramNode(0...689)( ClassNode(395...498)( [], (395...400), - ConstantReadNode(401...402)(), + ConstantReadNode(401...402)(:X), nil, nil, StatementsNode(417...480)( @@ -166,9 +167,10 @@ ProgramNode(0...689)( ModuleNode(517...565)( [], (517...523), - ConstantReadNode(524...525)(), + ConstantReadNode(524...525)(:X), StatementsNode(528...561)( [ConstantWriteNode(528...561)( + :X, (528...529), ArrayNode(532...561)( [SymbolNode(538...544)((538...539), (539...544), nil, "line3"), @@ -185,14 +187,15 @@ ProgramNode(0...689)( ModuleNode(568...651)( [], (568...574), - ConstantReadNode(575...576)(), + ConstantReadNode(575...576)(:X), StatementsNode(590...633)( [ModuleNode(590...633)( [], (590...596), - ConstantReadNode(597...598)(), + ConstantReadNode(597...598)(:Y), StatementsNode(612...618)( [ConstantWriteNode(612...618)( + :Z, (612...613), IntegerNode(616...618)(), (614...615) diff --git a/test/yarp/snapshots/seattlerb/attr_asgn_colon_id.txt b/test/yarp/snapshots/seattlerb/attr_asgn_colon_id.txt index 20cff2a0865a2f..b9f459e5f1e192 100644 --- a/test/yarp/snapshots/seattlerb/attr_asgn_colon_id.txt +++ b/test/yarp/snapshots/seattlerb/attr_asgn_colon_id.txt @@ -2,7 +2,7 @@ ProgramNode(0...8)( [], StatementsNode(0...8)( [CallNode(0...8)( - ConstantReadNode(0...1)(), + ConstantReadNode(0...1)(:A), (1...3), (3...4), nil, diff --git a/test/yarp/snapshots/seattlerb/bug_249.txt b/test/yarp/snapshots/seattlerb/bug_249.txt index 08a99c73b90f35..26e918c4f7a857 100644 --- a/test/yarp/snapshots/seattlerb/bug_249.txt +++ b/test/yarp/snapshots/seattlerb/bug_249.txt @@ -11,7 +11,7 @@ ProgramNode(0...67)( ParenthesesNode(6...44)( StatementsNode(7...43)( [CallNode(7...43)( - ConstantReadNode(7...12)(), + ConstantReadNode(7...12)(:Class), (12...13), (13...16), nil, diff --git a/test/yarp/snapshots/seattlerb/call_colon2.txt b/test/yarp/snapshots/seattlerb/call_colon2.txt index 36955f3b23061b..66b8a4a0177982 100644 --- a/test/yarp/snapshots/seattlerb/call_colon2.txt +++ b/test/yarp/snapshots/seattlerb/call_colon2.txt @@ -2,7 +2,7 @@ ProgramNode(0...4)( [], StatementsNode(0...4)( [CallNode(0...4)( - ConstantReadNode(0...1)(), + ConstantReadNode(0...1)(:A), (1...3), (3...4), nil, diff --git a/test/yarp/snapshots/seattlerb/case_in.txt b/test/yarp/snapshots/seattlerb/case_in.txt index 1262e453c96a6a..a1e26410133a8f 100644 --- a/test/yarp/snapshots/seattlerb/case_in.txt +++ b/test/yarp/snapshots/seattlerb/case_in.txt @@ -240,7 +240,7 @@ ProgramNode(0...747)( SymbolNode(338...340)((338...339), (339...340), nil, "a"), [InNode(341...352)( ArrayPatternNode(344...352)( - ConstantReadNode(344...350)(), + ConstantReadNode(344...350)(:Symbol), [], nil, [], @@ -259,7 +259,7 @@ ProgramNode(0...747)( SymbolNode(363...365)((363...364), (364...365), nil, "a"), [InNode(366...390)( FindPatternNode(369...390)( - ConstantReadNode(369...375)(), + ConstantReadNode(369...375)(:Symbol), SplatNode(376...380)( (376...377), LocalVariableTargetNode(377...380)(:lhs, 0) @@ -284,7 +284,7 @@ ProgramNode(0...747)( SymbolNode(401...403)((401...402), (402...403), nil, "a"), [InNode(404...428)( FindPatternNode(407...428)( - ConstantReadNode(407...413)(), + ConstantReadNode(407...413)(:Symbol), SplatNode(414...418)( (414...415), LocalVariableTargetNode(415...418)(:lhs, 0) @@ -382,9 +382,9 @@ ProgramNode(0...747)( [InNode(520...532)( ArrayPatternNode(523...532)( nil, - [ConstantReadNode(524...525)()], + [ConstantReadNode(524...525)(:A)], SplatNode(527...528)((527...528), nil), - [ConstantReadNode(530...531)()], + [ConstantReadNode(530...531)(:B)], (523...524), (531...532) ), diff --git a/test/yarp/snapshots/seattlerb/case_in_37.txt b/test/yarp/snapshots/seattlerb/case_in_37.txt index 721c6173d574c4..47137d795d177e 100644 --- a/test/yarp/snapshots/seattlerb/case_in_37.txt +++ b/test/yarp/snapshots/seattlerb/case_in_37.txt @@ -10,7 +10,7 @@ ProgramNode(0...36)( SymbolNode(13...15)(nil, (13...14), (14...15), "b"), ArrayPatternNode(16...25)( nil, - [ConstantReadNode(17...21)()], + [ConstantReadNode(17...21)(:Hash)], SplatNode(23...24)((23...24), nil), [], (16...17), diff --git a/test/yarp/snapshots/seattlerb/case_in_42_2.txt b/test/yarp/snapshots/seattlerb/case_in_42_2.txt index 945be4ddcf574a..5d7fc68646462a 100644 --- a/test/yarp/snapshots/seattlerb/case_in_42_2.txt +++ b/test/yarp/snapshots/seattlerb/case_in_42_2.txt @@ -5,7 +5,7 @@ ProgramNode(0...32)( SymbolNode(5...7)((5...6), (6...7), nil, "a"), [InNode(8...28)( ArrayPatternNode(11...19)( - ConstantReadNode(11...12)(), + ConstantReadNode(11...12)(:A), [], SplatNode(13...18)( (13...14), diff --git a/test/yarp/snapshots/seattlerb/case_in_86.txt b/test/yarp/snapshots/seattlerb/case_in_86.txt index 0475e9ef9abe74..c6287b9c3efb60 100644 --- a/test/yarp/snapshots/seattlerb/case_in_86.txt +++ b/test/yarp/snapshots/seattlerb/case_in_86.txt @@ -13,7 +13,7 @@ ProgramNode(0...43)( nil, [ConstantPathNode(17...27)( nil, - ConstantReadNode(19...27)(), + ConstantReadNode(19...27)(:NilClass), (17...19) )], SplatNode(29...30)((29...30), nil), diff --git a/test/yarp/snapshots/seattlerb/case_in_86_2.txt b/test/yarp/snapshots/seattlerb/case_in_86_2.txt index 067835c5be7ea1..16fdad3d3c8c31 100644 --- a/test/yarp/snapshots/seattlerb/case_in_86_2.txt +++ b/test/yarp/snapshots/seattlerb/case_in_86_2.txt @@ -15,7 +15,7 @@ ProgramNode(0...43)( SplatNode(17...18)((17...18), nil), [ConstantPathNode(20...30)( nil, - ConstantReadNode(22...30)(), + ConstantReadNode(22...30)(:NilClass), (20...22) )], nil, diff --git a/test/yarp/snapshots/seattlerb/case_in_array_pat_const.txt b/test/yarp/snapshots/seattlerb/case_in_array_pat_const.txt index d503434f7e5ec7..bf332c3d5d3ae6 100644 --- a/test/yarp/snapshots/seattlerb/case_in_array_pat_const.txt +++ b/test/yarp/snapshots/seattlerb/case_in_array_pat_const.txt @@ -5,7 +5,7 @@ ProgramNode(0...24)( SymbolNode(5...7)((5...6), (6...7), nil, "a"), [InNode(8...20)( ArrayPatternNode(11...15)( - ConstantReadNode(11...12)(), + ConstantReadNode(11...12)(:B), [LocalVariableTargetNode(13...14)(:c, 0)], nil, [], diff --git a/test/yarp/snapshots/seattlerb/case_in_array_pat_const2.txt b/test/yarp/snapshots/seattlerb/case_in_array_pat_const2.txt index 828d83dd52dc92..382db335d54664 100644 --- a/test/yarp/snapshots/seattlerb/case_in_array_pat_const2.txt +++ b/test/yarp/snapshots/seattlerb/case_in_array_pat_const2.txt @@ -6,8 +6,8 @@ ProgramNode(0...27)( [InNode(8...23)( ArrayPatternNode(11...18)( ConstantPathNode(11...15)( - ConstantReadNode(11...12)(), - ConstantReadNode(14...15)(), + ConstantReadNode(11...12)(:B), + ConstantReadNode(14...15)(:C), (12...14) ), [LocalVariableTargetNode(16...17)(:d, 0)], diff --git a/test/yarp/snapshots/seattlerb/case_in_array_pat_paren_assign.txt b/test/yarp/snapshots/seattlerb/case_in_array_pat_paren_assign.txt index c4e1380f7b1748..c2a74beaabb08c 100644 --- a/test/yarp/snapshots/seattlerb/case_in_array_pat_paren_assign.txt +++ b/test/yarp/snapshots/seattlerb/case_in_array_pat_paren_assign.txt @@ -5,9 +5,9 @@ ProgramNode(0...29)( SymbolNode(5...7)((5...6), (6...7), nil, "a"), [InNode(8...25)( ArrayPatternNode(11...20)( - ConstantReadNode(11...12)(), + ConstantReadNode(11...12)(:B), [CapturePatternNode(13...19)( - ConstantReadNode(13...14)(), + ConstantReadNode(13...14)(:C), LocalVariableTargetNode(18...19)(:d, 0), (15...17) )], diff --git a/test/yarp/snapshots/seattlerb/case_in_const.txt b/test/yarp/snapshots/seattlerb/case_in_const.txt index 3f8dde74fd21ea..b2312a5d7ad67f 100644 --- a/test/yarp/snapshots/seattlerb/case_in_const.txt +++ b/test/yarp/snapshots/seattlerb/case_in_const.txt @@ -2,9 +2,9 @@ ProgramNode(0...28)( [], StatementsNode(0...28)( [CaseNode(0...28)( - ConstantReadNode(5...10)(), + ConstantReadNode(5...10)(:Array), [InNode(11...24)( - ConstantReadNode(14...19)(), + ConstantReadNode(14...19)(:Class), StatementsNode(22...24)( [SymbolNode(22...24)((22...23), (23...24), nil, "b")] ), diff --git a/test/yarp/snapshots/seattlerb/case_in_else.txt b/test/yarp/snapshots/seattlerb/case_in_else.txt index fe2e6e7ee93cbf..edbcff9af85694 100644 --- a/test/yarp/snapshots/seattlerb/case_in_else.txt +++ b/test/yarp/snapshots/seattlerb/case_in_else.txt @@ -2,9 +2,9 @@ ProgramNode(0...38)( [], StatementsNode(0...38)( [CaseNode(0...38)( - ConstantReadNode(5...10)(), + ConstantReadNode(5...10)(:Array), [InNode(11...24)( - ConstantReadNode(14...19)(), + ConstantReadNode(14...19)(:Class), StatementsNode(22...24)( [SymbolNode(22...24)((22...23), (23...24), nil, "b")] ), diff --git a/test/yarp/snapshots/seattlerb/case_in_hash_pat_assign.txt b/test/yarp/snapshots/seattlerb/case_in_hash_pat_assign.txt index 6c6c9e8b675c2b..bac4076d27c9db 100644 --- a/test/yarp/snapshots/seattlerb/case_in_hash_pat_assign.txt +++ b/test/yarp/snapshots/seattlerb/case_in_hash_pat_assign.txt @@ -9,7 +9,7 @@ ProgramNode(0...56)( [AssocNode(13...28)( SymbolNode(13...15)(nil, (13...14), (14...15), "b"), CapturePatternNode(16...28)( - ConstantReadNode(16...23)(), + ConstantReadNode(16...23)(:Integer), LocalVariableTargetNode(27...28)(:x, 0), (24...26) ), diff --git a/test/yarp/snapshots/seattlerb/case_in_hash_pat_paren_assign.txt b/test/yarp/snapshots/seattlerb/case_in_hash_pat_paren_assign.txt index 2b822fdd440bcb..352da8ab8bb602 100644 --- a/test/yarp/snapshots/seattlerb/case_in_hash_pat_paren_assign.txt +++ b/test/yarp/snapshots/seattlerb/case_in_hash_pat_paren_assign.txt @@ -5,7 +5,7 @@ ProgramNode(0...28)( SymbolNode(5...7)((5...6), (6...7), nil, "a"), [InNode(8...24)( HashPatternNode(11...19)( - ConstantReadNode(11...12)(), + ConstantReadNode(11...12)(:B), [AssocNode(13...18)( SymbolNode(13...15)(nil, (13...14), (14...15), "a"), IntegerNode(16...18)(), diff --git a/test/yarp/snapshots/seattlerb/case_in_if_unless_post_mod.txt b/test/yarp/snapshots/seattlerb/case_in_if_unless_post_mod.txt index 5091c3d7f92395..d4869db8ede315 100644 --- a/test/yarp/snapshots/seattlerb/case_in_if_unless_post_mod.txt +++ b/test/yarp/snapshots/seattlerb/case_in_if_unless_post_mod.txt @@ -7,7 +7,7 @@ ProgramNode(0...52)( IfNode(11...20)( (13...15), TrueNode(16...20)(), - StatementsNode(11...12)([ConstantReadNode(11...12)()]), + StatementsNode(11...12)([ConstantReadNode(11...12)(:A)]), nil, nil ), @@ -21,7 +21,7 @@ ProgramNode(0...52)( UnlessNode(29...43)( (31...37), FalseNode(38...43)(), - StatementsNode(29...30)([ConstantReadNode(29...30)()]), + StatementsNode(29...30)([ConstantReadNode(29...30)(:D)]), nil, nil ), diff --git a/test/yarp/snapshots/seattlerb/case_in_multiple.txt b/test/yarp/snapshots/seattlerb/case_in_multiple.txt index e35b87ff5cb584..2210570cb9eb37 100644 --- a/test/yarp/snapshots/seattlerb/case_in_multiple.txt +++ b/test/yarp/snapshots/seattlerb/case_in_multiple.txt @@ -5,8 +5,8 @@ ProgramNode(0...37)( SymbolNode(5...7)((5...6), (6...7), nil, "a"), [InNode(8...20)( ConstantPathNode(11...15)( - ConstantReadNode(11...12)(), - ConstantReadNode(14...15)(), + ConstantReadNode(11...12)(:A), + ConstantReadNode(14...15)(:B), (12...14) ), StatementsNode(18...20)( @@ -17,8 +17,8 @@ ProgramNode(0...37)( ), InNode(21...33)( ConstantPathNode(24...28)( - ConstantReadNode(24...25)(), - ConstantReadNode(27...28)(), + ConstantReadNode(24...25)(:D), + ConstantReadNode(27...28)(:E), (25...27) ), StatementsNode(31...33)( diff --git a/test/yarp/snapshots/seattlerb/case_in_or.txt b/test/yarp/snapshots/seattlerb/case_in_or.txt index a8c251b414457f..2a5ec39441819f 100644 --- a/test/yarp/snapshots/seattlerb/case_in_or.txt +++ b/test/yarp/snapshots/seattlerb/case_in_or.txt @@ -5,8 +5,8 @@ ProgramNode(0...25)( SymbolNode(5...7)((5...6), (6...7), nil, "a"), [InNode(8...21)( AlternationPatternNode(11...16)( - ConstantReadNode(11...12)(), - ConstantReadNode(15...16)(), + ConstantReadNode(11...12)(:B), + ConstantReadNode(15...16)(:C), (13...14) ), StatementsNode(19...21)( diff --git a/test/yarp/snapshots/seattlerb/class_comments.txt b/test/yarp/snapshots/seattlerb/class_comments.txt index b96c5d6367ea0e..c7a36379fbc0fc 100644 --- a/test/yarp/snapshots/seattlerb/class_comments.txt +++ b/test/yarp/snapshots/seattlerb/class_comments.txt @@ -4,7 +4,7 @@ ProgramNode(19...71)( [ClassNode(19...71)( [], (19...24), - ConstantReadNode(25...26)(), + ConstantReadNode(25...26)(:X), nil, nil, StatementsNode(40...67)( diff --git a/test/yarp/snapshots/seattlerb/const_2_op_asgn_or2.txt b/test/yarp/snapshots/seattlerb/const_2_op_asgn_or2.txt index 48a4d61f5247b7..ea0d0bc196524b 100644 --- a/test/yarp/snapshots/seattlerb/const_2_op_asgn_or2.txt +++ b/test/yarp/snapshots/seattlerb/const_2_op_asgn_or2.txt @@ -3,8 +3,8 @@ ProgramNode(0...12)( StatementsNode(0...12)( [ConstantPathOrWriteNode(0...12)( ConstantPathNode(0...6)( - ConstantPathNode(0...3)(nil, ConstantReadNode(2...3)(), (0...2)), - ConstantReadNode(5...6)(), + ConstantPathNode(0...3)(nil, ConstantReadNode(2...3)(:X), (0...2)), + ConstantReadNode(5...6)(:Y), (3...5) ), (7...10), diff --git a/test/yarp/snapshots/seattlerb/const_3_op_asgn_or.txt b/test/yarp/snapshots/seattlerb/const_3_op_asgn_or.txt index 327e0a96431f1a..99bbb930cf882d 100644 --- a/test/yarp/snapshots/seattlerb/const_3_op_asgn_or.txt +++ b/test/yarp/snapshots/seattlerb/const_3_op_asgn_or.txt @@ -2,7 +2,7 @@ ProgramNode(0...9)( [], StatementsNode(0...9)( [ConstantPathOrWriteNode(0...9)( - ConstantPathNode(0...3)(nil, ConstantReadNode(2...3)(), (0...2)), + ConstantPathNode(0...3)(nil, ConstantReadNode(2...3)(:X), (0...2)), (4...7), IntegerNode(8...9)() )] diff --git a/test/yarp/snapshots/seattlerb/const_op_asgn_and1.txt b/test/yarp/snapshots/seattlerb/const_op_asgn_and1.txt index 1e7dce022689a5..53fed283e1d288 100644 --- a/test/yarp/snapshots/seattlerb/const_op_asgn_and1.txt +++ b/test/yarp/snapshots/seattlerb/const_op_asgn_and1.txt @@ -2,7 +2,7 @@ ProgramNode(0...8)( [], StatementsNode(0...8)( [ConstantPathOperatorWriteNode(0...8)( - ConstantPathNode(0...3)(nil, ConstantReadNode(2...3)(), (0...2)), + ConstantPathNode(0...3)(nil, ConstantReadNode(2...3)(:X), (0...2)), (4...6), IntegerNode(7...8)(), :& diff --git a/test/yarp/snapshots/seattlerb/const_op_asgn_and2.txt b/test/yarp/snapshots/seattlerb/const_op_asgn_and2.txt index 8c9d3ac353a61a..cd13c1f5a73e13 100644 --- a/test/yarp/snapshots/seattlerb/const_op_asgn_and2.txt +++ b/test/yarp/snapshots/seattlerb/const_op_asgn_and2.txt @@ -2,7 +2,7 @@ ProgramNode(0...9)( [], StatementsNode(0...9)( [ConstantPathAndWriteNode(0...9)( - ConstantPathNode(0...3)(nil, ConstantReadNode(2...3)(), (0...2)), + ConstantPathNode(0...3)(nil, ConstantReadNode(2...3)(:X), (0...2)), (4...7), IntegerNode(8...9)() )] diff --git a/test/yarp/snapshots/seattlerb/const_op_asgn_or.txt b/test/yarp/snapshots/seattlerb/const_op_asgn_or.txt index d812fe5a55e675..1b8fdf986e5710 100644 --- a/test/yarp/snapshots/seattlerb/const_op_asgn_or.txt +++ b/test/yarp/snapshots/seattlerb/const_op_asgn_or.txt @@ -3,8 +3,8 @@ ProgramNode(0...10)( StatementsNode(0...10)( [ConstantPathOrWriteNode(0...10)( ConstantPathNode(0...4)( - ConstantReadNode(0...1)(), - ConstantReadNode(3...4)(), + ConstantReadNode(0...1)(:X), + ConstantReadNode(3...4)(:Y), (1...3) ), (5...8), diff --git a/test/yarp/snapshots/seattlerb/dasgn_icky2.txt b/test/yarp/snapshots/seattlerb/dasgn_icky2.txt index 8fbbf8ec0ab0e3..d37ac900b2630f 100644 --- a/test/yarp/snapshots/seattlerb/dasgn_icky2.txt +++ b/test/yarp/snapshots/seattlerb/dasgn_icky2.txt @@ -26,7 +26,7 @@ ProgramNode(0...76)( ), RescueNode(35...66)( (35...41), - [ConstantReadNode(42...51)()], + [ConstantReadNode(42...51)(:Exception)], (52...54), LocalVariableTargetNode(55...56)(:v, 0), StatementsNode(61...66)([BreakNode(61...66)(nil, (61...66))]), diff --git a/test/yarp/snapshots/seattlerb/defn_oneliner_eq2.txt b/test/yarp/snapshots/seattlerb/defn_oneliner_eq2.txt index d5798209244334..db684a0b1049c1 100644 --- a/test/yarp/snapshots/seattlerb/defn_oneliner_eq2.txt +++ b/test/yarp/snapshots/seattlerb/defn_oneliner_eq2.txt @@ -4,7 +4,7 @@ ProgramNode(0...28)( [ClassNode(0...28)( [], (0...5), - ConstantReadNode(6...7)(), + ConstantReadNode(6...7)(:X), nil, nil, StatementsNode(10...24)( diff --git a/test/yarp/snapshots/seattlerb/defs_oneliner_eq2.txt b/test/yarp/snapshots/seattlerb/defs_oneliner_eq2.txt index 2ec8dc867263f3..793139ed5ef3e5 100644 --- a/test/yarp/snapshots/seattlerb/defs_oneliner_eq2.txt +++ b/test/yarp/snapshots/seattlerb/defs_oneliner_eq2.txt @@ -4,7 +4,7 @@ ProgramNode(0...33)( [ClassNode(0...33)( [], (0...5), - ConstantReadNode(6...7)(), + ConstantReadNode(6...7)(:X), nil, nil, StatementsNode(10...29)( diff --git a/test/yarp/snapshots/seattlerb/in_expr_no_case.txt b/test/yarp/snapshots/seattlerb/in_expr_no_case.txt index 093b2a65f8b44b..a4249f6414c37a 100644 --- a/test/yarp/snapshots/seattlerb/in_expr_no_case.txt +++ b/test/yarp/snapshots/seattlerb/in_expr_no_case.txt @@ -3,7 +3,7 @@ ProgramNode(0...16)( StatementsNode(0...16)( [MatchPredicateNode(0...16)( StringNode(0...6)((0...1), (1...5), (5...6), "woot"), - ConstantReadNode(10...16)(), + ConstantReadNode(10...16)(:String), (7...9) )] ) diff --git a/test/yarp/snapshots/seattlerb/magic_encoding_comment.txt b/test/yarp/snapshots/seattlerb/magic_encoding_comment.txt index b8b1ec343d09c9..b183b39ead718a 100644 --- a/test/yarp/snapshots/seattlerb/magic_encoding_comment.txt +++ b/test/yarp/snapshots/seattlerb/magic_encoding_comment.txt @@ -4,7 +4,7 @@ ProgramNode(18...90)( [ClassNode(18...90)( [], (18...23), - ConstantReadNode(24...52)(), + ConstantReadNode(24...52)(:ExampleUTF8ClassNameVarietà), nil, nil, StatementsNode(54...86)( diff --git a/test/yarp/snapshots/seattlerb/masgn_colon2.txt b/test/yarp/snapshots/seattlerb/masgn_colon2.txt index 99288bf229f285..cf85e7d1ed0540 100644 --- a/test/yarp/snapshots/seattlerb/masgn_colon2.txt +++ b/test/yarp/snapshots/seattlerb/masgn_colon2.txt @@ -5,7 +5,7 @@ ProgramNode(0...14)( [LocalVariableTargetNode(0...1)(:a, 0), ConstantPathTargetNode(3...7)( CallNode(3...4)(nil, nil, (3...4), nil, nil, nil, nil, 2, "b"), - ConstantReadNode(6...7)(), + ConstantReadNode(6...7)(:C), (4...6) )], (8...9), diff --git a/test/yarp/snapshots/seattlerb/masgn_colon3.txt b/test/yarp/snapshots/seattlerb/masgn_colon3.txt index abb7125505e734..9dab8dc0484108 100644 --- a/test/yarp/snapshots/seattlerb/masgn_colon3.txt +++ b/test/yarp/snapshots/seattlerb/masgn_colon3.txt @@ -2,10 +2,14 @@ ProgramNode(0...15)( [], StatementsNode(0...15)( [MultiWriteNode(0...15)( - [ConstantPathTargetNode(0...3)(nil, ConstantReadNode(2...3)(), (0...2)), + [ConstantPathTargetNode(0...3)( + nil, + ConstantReadNode(2...3)(:A), + (0...2) + ), ConstantPathTargetNode(5...8)( nil, - ConstantReadNode(7...8)(), + ConstantReadNode(7...8)(:B), (5...7) )], (9...10), diff --git a/test/yarp/snapshots/seattlerb/messy_op_asgn_lineno.txt b/test/yarp/snapshots/seattlerb/messy_op_asgn_lineno.txt index 71a28870bd2240..74da38dee6310c 100644 --- a/test/yarp/snapshots/seattlerb/messy_op_asgn_lineno.txt +++ b/test/yarp/snapshots/seattlerb/messy_op_asgn_lineno.txt @@ -11,8 +11,8 @@ ProgramNode(0...15)( StatementsNode(3...14)( [ConstantPathOperatorWriteNode(3...14)( ConstantPathNode(3...7)( - ConstantReadNode(3...4)(), - ConstantReadNode(6...7)(), + ConstantReadNode(3...4)(:B), + ConstantReadNode(6...7)(:C), (4...6) ), (8...10), diff --git a/test/yarp/snapshots/seattlerb/module_comments.txt b/test/yarp/snapshots/seattlerb/module_comments.txt index 4f399904111e29..b384dad8e58eba 100644 --- a/test/yarp/snapshots/seattlerb/module_comments.txt +++ b/test/yarp/snapshots/seattlerb/module_comments.txt @@ -4,7 +4,7 @@ ProgramNode(24...77)( [ModuleNode(24...77)( [], (24...30), - ConstantReadNode(31...32)(), + ConstantReadNode(31...32)(:X), StatementsNode(46...73)( [DefNode(46...73)( (50...54), diff --git a/test/yarp/snapshots/seattlerb/op_asgn_dot_ident_command_call.txt b/test/yarp/snapshots/seattlerb/op_asgn_dot_ident_command_call.txt index a33ceae8ee257e..00aa4338642209 100644 --- a/test/yarp/snapshots/seattlerb/op_asgn_dot_ident_command_call.txt +++ b/test/yarp/snapshots/seattlerb/op_asgn_dot_ident_command_call.txt @@ -2,7 +2,7 @@ ProgramNode(0...11)( [], StatementsNode(0...11)( [CallOrWriteNode(0...11)( - ConstantReadNode(0...1)(), + ConstantReadNode(0...1)(:A), (1...2), (2...3), nil, diff --git a/test/yarp/snapshots/seattlerb/op_asgn_primary_colon_const_command_call.txt b/test/yarp/snapshots/seattlerb/op_asgn_primary_colon_const_command_call.txt index 0cd3775202dff6..9459bf5ce52bc2 100644 --- a/test/yarp/snapshots/seattlerb/op_asgn_primary_colon_const_command_call.txt +++ b/test/yarp/snapshots/seattlerb/op_asgn_primary_colon_const_command_call.txt @@ -3,8 +3,8 @@ ProgramNode(0...11)( StatementsNode(0...11)( [ConstantPathOperatorWriteNode(0...11)( ConstantPathNode(0...4)( - ConstantReadNode(0...1)(), - ConstantReadNode(3...4)(), + ConstantReadNode(0...1)(:A), + ConstantReadNode(3...4)(:B), (1...3) ), (5...7), diff --git a/test/yarp/snapshots/seattlerb/op_asgn_primary_colon_identifier1.txt b/test/yarp/snapshots/seattlerb/op_asgn_primary_colon_identifier1.txt index 85673bab52aca8..d2703a3e48d8d0 100644 --- a/test/yarp/snapshots/seattlerb/op_asgn_primary_colon_identifier1.txt +++ b/test/yarp/snapshots/seattlerb/op_asgn_primary_colon_identifier1.txt @@ -2,7 +2,7 @@ ProgramNode(0...9)( [], StatementsNode(0...9)( [CallOperatorWriteNode(0...9)( - ConstantReadNode(0...1)(), + ConstantReadNode(0...1)(:A), (1...3), (3...4), nil, diff --git a/test/yarp/snapshots/seattlerb/op_asgn_primary_colon_identifier_command_call.txt b/test/yarp/snapshots/seattlerb/op_asgn_primary_colon_identifier_command_call.txt index 741620d847afed..845e0c30a0c2ad 100644 --- a/test/yarp/snapshots/seattlerb/op_asgn_primary_colon_identifier_command_call.txt +++ b/test/yarp/snapshots/seattlerb/op_asgn_primary_colon_identifier_command_call.txt @@ -2,7 +2,7 @@ ProgramNode(0...11)( [], StatementsNode(0...11)( [CallOperatorWriteNode(0...11)( - ConstantReadNode(0...1)(), + ConstantReadNode(0...1)(:A), (1...3), (3...4), nil, diff --git a/test/yarp/snapshots/seattlerb/parse_line_heredoc_hardnewline.txt b/test/yarp/snapshots/seattlerb/parse_line_heredoc_hardnewline.txt index 4445e447d015e9..5f4c3ec93d0690 100644 --- a/test/yarp/snapshots/seattlerb/parse_line_heredoc_hardnewline.txt +++ b/test/yarp/snapshots/seattlerb/parse_line_heredoc_hardnewline.txt @@ -14,7 +14,7 @@ ProgramNode(0...48)( ClassNode(35...48)( [], (35...40), - ConstantReadNode(41...44)(), + ConstantReadNode(41...44)(:Foo), nil, nil, nil, diff --git a/test/yarp/snapshots/seattlerb/parse_pattern_044.txt b/test/yarp/snapshots/seattlerb/parse_pattern_044.txt index 2788137784b48c..09d0143eff5561 100644 --- a/test/yarp/snapshots/seattlerb/parse_pattern_044.txt +++ b/test/yarp/snapshots/seattlerb/parse_pattern_044.txt @@ -5,7 +5,7 @@ ProgramNode(0...31)( CallNode(5...8)(nil, nil, (5...8), nil, nil, nil, nil, 2, "obj"), [InNode(9...27)( ArrayPatternNode(12...20)( - ConstantReadNode(12...18)(), + ConstantReadNode(12...18)(:Object), [], nil, [], diff --git a/test/yarp/snapshots/seattlerb/parse_pattern_069.txt b/test/yarp/snapshots/seattlerb/parse_pattern_069.txt index 1d3772e93fd271..b704851937c9fd 100644 --- a/test/yarp/snapshots/seattlerb/parse_pattern_069.txt +++ b/test/yarp/snapshots/seattlerb/parse_pattern_069.txt @@ -5,7 +5,7 @@ ProgramNode(0...31)( SymbolNode(5...7)((5...6), (6...7), nil, "a"), [InNode(8...27)( HashPatternNode(11...23)( - ConstantReadNode(11...17)(), + ConstantReadNode(11...17)(:Object), [AssocNode(18...22)( SymbolNode(18...20)(nil, (18...19), (19...20), "b"), IntegerNode(21...22)(), diff --git a/test/yarp/snapshots/unparser/corpus/literal/assignment.txt b/test/yarp/snapshots/unparser/corpus/literal/assignment.txt index ab443e43889f7c..38c06a29bc928c 100644 --- a/test/yarp/snapshots/unparser/corpus/literal/assignment.txt +++ b/test/yarp/snapshots/unparser/corpus/literal/assignment.txt @@ -285,13 +285,13 @@ ProgramNode(0...704)( ConstantPathWriteNode(288...301)( ConstantPathNode(288...293)( nil, - ConstantReadNode(290...293)(), + ConstantReadNode(290...293)(:Foo), (288...290) ), (294...295), ConstantPathNode(296...301)( nil, - ConstantReadNode(298...301)(), + ConstantReadNode(298...301)(:Bar), (296...298) ) ), @@ -308,6 +308,7 @@ ProgramNode(0...704)( (313...314) ), ConstantWriteNode(317...326)( + :CONST, (317...322), IntegerNode(325...326)(), (323...324) @@ -315,11 +316,11 @@ ProgramNode(0...704)( ConstantPathWriteNode(327...350)( ConstantPathNode(327...346)( ConstantPathNode(327...339)( - ConstantReadNode(327...331)(), - ConstantReadNode(333...339)(), + ConstantReadNode(327...331)(:Name), + ConstantReadNode(333...339)(:Spaced), (331...333) ), - ConstantReadNode(341...346)(), + ConstantReadNode(341...346)(:CONST), (339...341) ), (347...348), diff --git a/test/yarp/snapshots/unparser/corpus/literal/block.txt b/test/yarp/snapshots/unparser/corpus/literal/block.txt index 6ee2fbb1fa8803..514ce627600655 100644 --- a/test/yarp/snapshots/unparser/corpus/literal/block.txt +++ b/test/yarp/snapshots/unparser/corpus/literal/block.txt @@ -742,7 +742,7 @@ ProgramNode(0...737)( nil, RescueNode(365...386)( (365...371), - [ConstantReadNode(372...381)()], + [ConstantReadNode(372...381)(:Exception)], (382...384), LocalVariableTargetNode(385...386)(:e, 0), nil, @@ -785,7 +785,7 @@ ProgramNode(0...737)( ), RescueNode(402...431)( (402...408), - [ConstantReadNode(409...418)()], + [ConstantReadNode(409...418)(:Exception)], (419...421), LocalVariableTargetNode(422...425)(:bar, 0), StatementsNode(428...431)( @@ -830,7 +830,7 @@ ProgramNode(0...737)( ), RescueNode(447...475)( (447...453), - [ConstantReadNode(454...463)(), + [ConstantReadNode(454...463)(:SomeError), SplatNode(465...469)( (465...466), CallNode(466...469)( @@ -899,7 +899,7 @@ ProgramNode(0...737)( ), RescueNode(491...532)( (491...497), - [ConstantReadNode(498...507)(), + [ConstantReadNode(498...507)(:SomeError), SplatNode(509...513)( (509...510), CallNode(510...513)( @@ -1036,7 +1036,7 @@ ProgramNode(0...737)( ), RescueNode(581...597)( (581...587), - [ConstantReadNode(588...597)()], + [ConstantReadNode(588...597)(:LoadError)], nil, nil, nil, diff --git a/test/yarp/snapshots/unparser/corpus/literal/class.txt b/test/yarp/snapshots/unparser/corpus/literal/class.txt index aa457618026144..b4cca16f39b2c7 100644 --- a/test/yarp/snapshots/unparser/corpus/literal/class.txt +++ b/test/yarp/snapshots/unparser/corpus/literal/class.txt @@ -4,7 +4,7 @@ ProgramNode(0...213)( [ClassNode(0...11)( [], (0...5), - ConstantReadNode(6...7)(), + ConstantReadNode(6...7)(:A), nil, nil, nil, @@ -33,8 +33,8 @@ ProgramNode(0...213)( [], (49...54), ConstantPathNode(55...59)( - ConstantReadNode(55...56)(), - ConstantReadNode(58...59)(), + ConstantReadNode(55...56)(:A), + ConstantReadNode(58...59)(:B), (56...58) ), nil, @@ -48,11 +48,11 @@ ProgramNode(0...213)( (65...70), ConstantPathNode(71...78)( ConstantPathNode(71...75)( - ConstantReadNode(71...72)(), - ConstantReadNode(74...75)(), + ConstantReadNode(71...72)(:A), + ConstantReadNode(74...75)(:B), (72...74) ), - ConstantReadNode(77...78)(), + ConstantReadNode(77...78)(:C), (75...77) ), nil, @@ -64,9 +64,9 @@ ProgramNode(0...213)( ClassNode(84...99)( [], (84...89), - ConstantReadNode(90...91)(), + ConstantReadNode(90...91)(:A), (92...93), - ConstantReadNode(94...95)(), + ConstantReadNode(94...95)(:B), nil, (96...99), "A" @@ -74,11 +74,11 @@ ProgramNode(0...213)( ClassNode(101...119)( [], (101...106), - ConstantReadNode(107...108)(), + ConstantReadNode(107...108)(:A), (109...110), ConstantPathNode(111...115)( - ConstantReadNode(111...112)(), - ConstantReadNode(114...115)(), + ConstantReadNode(111...112)(:B), + ConstantReadNode(114...115)(:C), (112...114) ), nil, @@ -89,14 +89,14 @@ ProgramNode(0...213)( [], (121...126), ConstantPathNode(127...131)( - ConstantReadNode(127...128)(), - ConstantReadNode(130...131)(), + ConstantReadNode(127...128)(:A), + ConstantReadNode(130...131)(:B), (128...130) ), (132...133), ConstantPathNode(134...138)( - ConstantReadNode(134...135)(), - ConstantReadNode(137...138)(), + ConstantReadNode(134...135)(:C), + ConstantReadNode(137...138)(:D), (135...137) ), nil, @@ -106,7 +106,7 @@ ProgramNode(0...213)( ClassNode(144...198)( [], (144...149), - ConstantReadNode(150...151)(), + ConstantReadNode(150...151)(:A), nil, nil, StatementsNode(154...194)( @@ -117,7 +117,7 @@ ProgramNode(0...213)( (161...162), ArgumentsNode(162...167)( [CallNode(162...167)( - ConstantReadNode(162...163)(), + ConstantReadNode(162...163)(:B), (163...164), (164...167), nil, @@ -157,7 +157,7 @@ ProgramNode(0...213)( (200...205), ConstantPathNode(206...209)( nil, - ConstantReadNode(208...209)(), + ConstantReadNode(208...209)(:A), (206...208) ), nil, diff --git a/test/yarp/snapshots/unparser/corpus/literal/defined.txt b/test/yarp/snapshots/unparser/corpus/literal/defined.txt index 9229badf44efbe..8e77e8e5df9a68 100644 --- a/test/yarp/snapshots/unparser/corpus/literal/defined.txt +++ b/test/yarp/snapshots/unparser/corpus/literal/defined.txt @@ -9,7 +9,7 @@ ProgramNode(0...56)( ), DefinedNode(15...28)( (23...24), - ConstantReadNode(24...27)(), + ConstantReadNode(24...27)(:Foo), (27...28), (15...23) ), diff --git a/test/yarp/snapshots/unparser/corpus/literal/defs.txt b/test/yarp/snapshots/unparser/corpus/literal/defs.txt index b980c15c9e71d2..0d18f430af83f9 100644 --- a/test/yarp/snapshots/unparser/corpus/literal/defs.txt +++ b/test/yarp/snapshots/unparser/corpus/literal/defs.txt @@ -47,7 +47,7 @@ ProgramNode(0...266)( ), DefNode(72...93)( (80...83), - ConstantReadNode(76...79)(), + ConstantReadNode(76...79)(:Foo), nil, StatementsNode(86...89)( [CallNode(86...89)(nil, nil, (86...89), nil, nil, nil, nil, 2, "bar")] @@ -162,8 +162,8 @@ ProgramNode(0...266)( ParenthesesNode(162...176)( CallNode(163...175)( ConstantPathNode(163...171)( - ConstantReadNode(163...166)(), - ConstantReadNode(168...171)(), + ConstantReadNode(163...166)(:Foo), + ConstantReadNode(168...171)(:Bar), (166...168) ), (171...172), @@ -204,8 +204,8 @@ ProgramNode(0...266)( (207...210), ParenthesesNode(196...206)( ConstantPathNode(197...205)( - ConstantReadNode(197...200)(), - ConstantReadNode(202...205)(), + ConstantReadNode(197...200)(:Foo), + ConstantReadNode(202...205)(:Bar), (200...202) ), (196...197), @@ -235,7 +235,7 @@ ProgramNode(0...266)( ), DefNode(222...243)( (230...233), - ConstantReadNode(226...229)(), + ConstantReadNode(226...229)(:Foo), nil, StatementsNode(236...239)( [CallNode(236...239)( diff --git a/test/yarp/snapshots/unparser/corpus/literal/if.txt b/test/yarp/snapshots/unparser/corpus/literal/if.txt index 77fb5c8c636042..b25ada8a362906 100644 --- a/test/yarp/snapshots/unparser/corpus/literal/if.txt +++ b/test/yarp/snapshots/unparser/corpus/literal/if.txt @@ -52,7 +52,7 @@ ProgramNode(0...246)( ModuleNode(102...133)( [:foo], (102...108), - ConstantReadNode(109...110)(), + ConstantReadNode(109...110)(:A), StatementsNode(113...129)( [IfNode(113...129)( (123...125), @@ -86,7 +86,7 @@ ProgramNode(0...246)( ModuleNode(135...170)( [:foo], (135...141), - ConstantReadNode(142...143)(), + ConstantReadNode(142...143)(:B), StatementsNode(146...166)( [UnlessNode(146...166)( (156...162), diff --git a/test/yarp/snapshots/unparser/corpus/literal/kwbegin.txt b/test/yarp/snapshots/unparser/corpus/literal/kwbegin.txt index 1f28ad87b416b0..79f4c36be646ee 100644 --- a/test/yarp/snapshots/unparser/corpus/literal/kwbegin.txt +++ b/test/yarp/snapshots/unparser/corpus/literal/kwbegin.txt @@ -81,7 +81,7 @@ ProgramNode(0...530)( nil, RescueNode(113...121)( (113...119), - [ConstantReadNode(120...121)()], + [ConstantReadNode(120...121)(:A)], nil, nil, nil, @@ -96,7 +96,7 @@ ProgramNode(0...530)( nil, RescueNode(133...148)( (133...139), - [ConstantReadNode(140...141)()], + [ConstantReadNode(140...141)(:A)], (142...144), LocalVariableTargetNode(145...148)(:foo, 0), nil, @@ -123,7 +123,7 @@ ProgramNode(0...530)( ), RescueNode(164...189)( (164...170), - [ConstantReadNode(171...172)()], + [ConstantReadNode(171...172)(:A)], nil, nil, StatementsNode(175...176)( @@ -141,7 +141,7 @@ ProgramNode(0...530)( ), RescueNode(177...189)( (177...183), - [ConstantReadNode(184...185)()], + [ConstantReadNode(184...185)(:B)], nil, nil, StatementsNode(188...189)( @@ -249,7 +249,9 @@ ProgramNode(0...530)( nil, (283...288), (288...289), - ArgumentsNode(289...298)([ConstantReadNode(289...298)()]), + ArgumentsNode(289...298)( + [ConstantReadNode(289...298)(:Exception)] + ), (298...299), nil, 0, @@ -277,7 +279,7 @@ ProgramNode(0...530)( ), RescueNode(317...333)( (317...323), - [ConstantReadNode(324...333)()], + [ConstantReadNode(324...333)(:Exception)], nil, nil, nil, @@ -309,7 +311,8 @@ ProgramNode(0...530)( StatementsNode(384...387)([LocalVariableReadNode(384...387)(:foo, 0)]), RescueNode(388...424)( (388...394), - [ConstantReadNode(395...404)(), ConstantReadNode(406...411)()], + [ConstantReadNode(395...404)(:Exception), + ConstantReadNode(406...411)(:Other)], (412...414), LocalVariableTargetNode(415...418)(:bar, 0), StatementsNode(421...424)( @@ -326,7 +329,7 @@ ProgramNode(0...530)( StatementsNode(438...441)([LocalVariableReadNode(438...441)(:bar, 0)]), RescueNode(442...483)( (442...448), - [ConstantReadNode(449...458)(), + [ConstantReadNode(449...458)(:SomeError), SplatNode(460...464)( (460...461), LocalVariableReadNode(461...464)(:bar, 0) diff --git a/test/yarp/snapshots/unparser/corpus/literal/module.txt b/test/yarp/snapshots/unparser/corpus/literal/module.txt index 4c805d3d67f0be..8ec85333e206bd 100644 --- a/test/yarp/snapshots/unparser/corpus/literal/module.txt +++ b/test/yarp/snapshots/unparser/corpus/literal/module.txt @@ -4,7 +4,7 @@ ProgramNode(0...106)( [ModuleNode(0...12)( [], (0...6), - ConstantReadNode(7...8)(), + ConstantReadNode(7...8)(:A), nil, (9...12), "A" @@ -13,8 +13,8 @@ ProgramNode(0...106)( [], (14...20), ConstantPathNode(21...25)( - ConstantReadNode(21...22)(), - ConstantReadNode(24...25)(), + ConstantReadNode(21...22)(:A), + ConstantReadNode(24...25)(:B), (22...24) ), nil, @@ -26,11 +26,11 @@ ProgramNode(0...106)( (31...37), ConstantPathNode(38...45)( ConstantPathNode(38...42)( - ConstantReadNode(38...39)(), - ConstantReadNode(41...42)(), + ConstantReadNode(38...39)(:A), + ConstantReadNode(41...42)(:B), (39...41) ), - ConstantReadNode(44...45)(), + ConstantReadNode(44...45)(:C), (42...44) ), nil, @@ -40,7 +40,7 @@ ProgramNode(0...106)( ModuleNode(51...106)( [], (51...57), - ConstantReadNode(58...59)(), + ConstantReadNode(58...59)(:A), StatementsNode(62...102)( [CallNode(62...76)( nil, @@ -49,7 +49,7 @@ ProgramNode(0...106)( (69...70), ArgumentsNode(70...75)( [CallNode(70...75)( - ConstantReadNode(70...71)(), + ConstantReadNode(70...71)(:B), (71...72), (72...75), nil, diff --git a/test/yarp/snapshots/unparser/corpus/literal/pattern.txt b/test/yarp/snapshots/unparser/corpus/literal/pattern.txt index 227938293bdc78..2d6ec772f44e8f 100644 --- a/test/yarp/snapshots/unparser/corpus/literal/pattern.txt +++ b/test/yarp/snapshots/unparser/corpus/literal/pattern.txt @@ -5,7 +5,7 @@ ProgramNode(0...408)( CallNode(5...8)(nil, nil, (5...8), nil, nil, nil, nil, 2, "foo"), [InNode(9...38)( ArrayPatternNode(12...26)( - ConstantReadNode(12...13)(), + ConstantReadNode(12...13)(:A), [IntegerNode(14...15)(), IntegerNode(17...18)()], SplatNode(20...22)( (20...21), @@ -46,7 +46,7 @@ ProgramNode(0...408)( ), InNode(60...80)( HashPatternNode(63...68)( - ConstantReadNode(63...64)(), + ConstantReadNode(63...64)(:A), [AssocNode(65...67)( SymbolNode(65...67)(nil, (65...66), (66...67), "x"), nil, @@ -235,7 +235,7 @@ ProgramNode(0...408)( ), [InNode(355...372)( ArrayPatternNode(358...372)( - ConstantReadNode(358...359)(), + ConstantReadNode(358...359)(:A), [IntegerNode(360...361)(), IntegerNode(363...364)()], SplatNode(366...368)( (366...367), @@ -266,7 +266,7 @@ ProgramNode(0...408)( "foo" ), [InNode(386...390)( - ConstantReadNode(389...390)(), + ConstantReadNode(389...390)(:A), nil, (386...388), nil diff --git a/test/yarp/snapshots/unparser/corpus/literal/send.txt b/test/yarp/snapshots/unparser/corpus/literal/send.txt index 7ec3a338ce9ffc..68eb44288918c3 100644 --- a/test/yarp/snapshots/unparser/corpus/literal/send.txt +++ b/test/yarp/snapshots/unparser/corpus/literal/send.txt @@ -4,7 +4,7 @@ ProgramNode(0...999)( [ModuleNode(0...35)( [:foo, :a, :_], (0...6), - ConstantReadNode(7...8)(), + ConstantReadNode(7...8)(:A), StatementsNode(11...31)( [LocalVariableOrWriteNode(11...31)( (11...14), @@ -43,7 +43,7 @@ ProgramNode(0...999)( ModuleNode(37...73)( [:local], (37...43), - ConstantReadNode(44...45)(), + ConstantReadNode(44...45)(:A), StatementsNode(48...69)( [LocalVariableWriteNode(48...57)( :local, @@ -71,7 +71,7 @@ ProgramNode(0...999)( ClassNode(74...85)( [], (74...79), - ConstantReadNode(80...81)(), + ConstantReadNode(80...81)(:A), nil, nil, nil, @@ -91,7 +91,7 @@ ProgramNode(0...999)( ModuleNode(90...102)( [], (90...96), - ConstantReadNode(97...98)(), + ConstantReadNode(97...98)(:A), nil, (99...102), "A" @@ -547,7 +547,7 @@ ProgramNode(0...999)( 0 ), CallNode(405...410)( - ConstantReadNode(405...406)(), + ConstantReadNode(405...406)(:A), (406...407), (407...410), nil, diff --git a/test/yarp/snapshots/unparser/corpus/literal/variables.txt b/test/yarp/snapshots/unparser/corpus/literal/variables.txt index 21738f74f0a5e5..f012dc900c2890 100644 --- a/test/yarp/snapshots/unparser/corpus/literal/variables.txt +++ b/test/yarp/snapshots/unparser/corpus/literal/variables.txt @@ -7,16 +7,24 @@ ProgramNode(0...66)( GlobalVariableReadNode(9...11)(:$a), NumberedReferenceReadNode(12...14)(1), BackReferenceReadNode(15...17)(), - ConstantReadNode(18...23)(), + ConstantReadNode(18...23)(:CONST), ConstantPathNode(24...37)( - ConstantReadNode(24...30)(), - ConstantReadNode(32...37)(), + ConstantReadNode(24...30)(:SCOPED), + ConstantReadNode(32...37)(:CONST), (30...32) ), - ConstantPathNode(38...48)(nil, ConstantReadNode(40...48)(), (38...40)), + ConstantPathNode(38...48)( + nil, + ConstantReadNode(40...48)(:TOPLEVEL), + (38...40) + ), ConstantPathNode(49...66)( - ConstantPathNode(49...59)(nil, ConstantReadNode(51...59)(), (49...51)), - ConstantReadNode(61...66)(), + ConstantPathNode(49...59)( + nil, + ConstantReadNode(51...59)(:TOPLEVEL), + (49...51) + ), + ConstantReadNode(61...66)(:CONST), (59...61) )] ) diff --git a/test/yarp/snapshots/unparser/corpus/literal/while.txt b/test/yarp/snapshots/unparser/corpus/literal/while.txt index 7fcd66a01e61d1..6bddfff409f741 100644 --- a/test/yarp/snapshots/unparser/corpus/literal/while.txt +++ b/test/yarp/snapshots/unparser/corpus/literal/while.txt @@ -4,7 +4,7 @@ ProgramNode(0...620)( [ModuleNode(0...68)( [], (0...6), - ConstantReadNode(7...8)(), + ConstantReadNode(7...8)(:A), StatementsNode(11...64)( [CallNode(11...64)( nil, @@ -130,7 +130,7 @@ ProgramNode(0...620)( ModuleNode(112...146)( [:foo], (112...118), - ConstantReadNode(119...120)(), + ConstantReadNode(119...120)(:A), StatementsNode(123...142)( [WhileNode(123...142)( (133...138), @@ -164,7 +164,7 @@ ProgramNode(0...620)( ModuleNode(148...182)( [:foo], (148...154), - ConstantReadNode(155...156)(), + ConstantReadNode(155...156)(:A), StatementsNode(159...178)( [UntilNode(159...178)( (169...174), @@ -198,7 +198,7 @@ ProgramNode(0...620)( ModuleNode(184...228)( [:foo], (184...190), - ConstantReadNode(191...192)(), + ConstantReadNode(191...192)(:A), StatementsNode(195...224)( [WhileNode(195...224)( (195...200), @@ -242,7 +242,7 @@ ProgramNode(0...620)( ModuleNode(230...299)( [], (230...236), - ConstantReadNode(237...238)(), + ConstantReadNode(237...238)(:A), StatementsNode(241...295)( [CallNode(241...295)( nil, @@ -317,7 +317,7 @@ ProgramNode(0...620)( ModuleNode(301...370)( [], (301...307), - ConstantReadNode(308...309)(), + ConstantReadNode(308...309)(:A), StatementsNode(312...366)( [CallNode(312...366)( nil, diff --git a/test/yarp/snapshots/unparser/corpus/semantic/def.txt b/test/yarp/snapshots/unparser/corpus/semantic/def.txt index 439ffafe1be5d2..46c69936a44504 100644 --- a/test/yarp/snapshots/unparser/corpus/semantic/def.txt +++ b/test/yarp/snapshots/unparser/corpus/semantic/def.txt @@ -62,7 +62,7 @@ ProgramNode(0...55)( [RescueModifierNode(33...51)( CallNode(33...34)(nil, nil, (33...34), nil, nil, nil, nil, 2, "a"), (35...41), - ConstantReadNode(42...51)() + ConstantReadNode(42...51)(:Exception) )] ), [], diff --git a/test/yarp/snapshots/unparser/corpus/semantic/kwbegin.txt b/test/yarp/snapshots/unparser/corpus/semantic/kwbegin.txt index 5ae3acede61319..231ed767cf4ed8 100644 --- a/test/yarp/snapshots/unparser/corpus/semantic/kwbegin.txt +++ b/test/yarp/snapshots/unparser/corpus/semantic/kwbegin.txt @@ -81,7 +81,7 @@ ProgramNode(0...215)( nil, RescueNode(118...126)( (118...124), - [ConstantReadNode(125...126)()], + [ConstantReadNode(125...126)(:A)], nil, nil, nil, @@ -96,7 +96,7 @@ ProgramNode(0...215)( nil, RescueNode(144...152)( (144...150), - [ConstantReadNode(151...152)()], + [ConstantReadNode(151...152)(:A)], nil, nil, nil, @@ -123,7 +123,7 @@ ProgramNode(0...215)( ), RescueNode(175...200)( (175...181), - [ConstantReadNode(182...183)()], + [ConstantReadNode(182...183)(:A)], nil, nil, StatementsNode(186...187)( @@ -141,7 +141,7 @@ ProgramNode(0...215)( ), RescueNode(188...200)( (188...194), - [ConstantReadNode(195...196)()], + [ConstantReadNode(195...196)(:B)], nil, nil, StatementsNode(199...200)( diff --git a/test/yarp/snapshots/unparser/corpus/semantic/while.txt b/test/yarp/snapshots/unparser/corpus/semantic/while.txt index d6d4198447aabe..de7f2b750dbb14 100644 --- a/test/yarp/snapshots/unparser/corpus/semantic/while.txt +++ b/test/yarp/snapshots/unparser/corpus/semantic/while.txt @@ -140,7 +140,7 @@ ProgramNode(0...188)( ModuleNode(132...188)( [:foo], (132...138), - ConstantReadNode(139...140)(), + ConstantReadNode(139...140)(:A), StatementsNode(143...184)( [LocalVariableWriteNode(143...152)( :foo, diff --git a/test/yarp/snapshots/variables.txt b/test/yarp/snapshots/variables.txt index 11e232c1cb2398..4d50fa0db398d2 100644 --- a/test/yarp/snapshots/variables.txt +++ b/test/yarp/snapshots/variables.txt @@ -191,6 +191,7 @@ ProgramNode(0...293)( (264...265) ), ConstantWriteNode(272...282)( + :Foo, (272...275), ArrayNode(278...282)( [IntegerNode(278...279)(), IntegerNode(281...282)()], diff --git a/test/yarp/snapshots/while.txt b/test/yarp/snapshots/while.txt index 4aa5fe85f1428d..e85b5e667263d5 100644 --- a/test/yarp/snapshots/while.txt +++ b/test/yarp/snapshots/while.txt @@ -116,7 +116,7 @@ ProgramNode(0...314)( ClassNode(169...198)( [:a], (169...174), - ConstantReadNode(175...178)(), + ConstantReadNode(175...178)(:Foo), nil, nil, StatementsNode(179...193)( diff --git a/test/yarp/snapshots/whitequark/bug_rescue_empty_else.txt b/test/yarp/snapshots/whitequark/bug_rescue_empty_else.txt index 83ea8818ee852f..02c4736f8c6814 100644 --- a/test/yarp/snapshots/whitequark/bug_rescue_empty_else.txt +++ b/test/yarp/snapshots/whitequark/bug_rescue_empty_else.txt @@ -6,7 +6,7 @@ ProgramNode(0...34)( nil, RescueNode(7...23)( (7...13), - [ConstantReadNode(14...23)()], + [ConstantReadNode(14...23)(:LoadError)], nil, nil, nil, diff --git a/test/yarp/snapshots/whitequark/casgn_scoped.txt b/test/yarp/snapshots/whitequark/casgn_scoped.txt index 4f3dbf682ea759..b5e719abfc667c 100644 --- a/test/yarp/snapshots/whitequark/casgn_scoped.txt +++ b/test/yarp/snapshots/whitequark/casgn_scoped.txt @@ -3,8 +3,8 @@ ProgramNode(0...13)( StatementsNode(0...13)( [ConstantPathWriteNode(0...13)( ConstantPathNode(0...8)( - ConstantReadNode(0...3)(), - ConstantReadNode(5...8)(), + ConstantReadNode(0...3)(:Bar), + ConstantReadNode(5...8)(:Foo), (3...5) ), (9...10), diff --git a/test/yarp/snapshots/whitequark/casgn_toplevel.txt b/test/yarp/snapshots/whitequark/casgn_toplevel.txt index 50d683b3667879..7fff870f8a2bd5 100644 --- a/test/yarp/snapshots/whitequark/casgn_toplevel.txt +++ b/test/yarp/snapshots/whitequark/casgn_toplevel.txt @@ -2,7 +2,7 @@ ProgramNode(0...10)( [], StatementsNode(0...10)( [ConstantPathWriteNode(0...10)( - ConstantPathNode(0...5)(nil, ConstantReadNode(2...5)(), (0...2)), + ConstantPathNode(0...5)(nil, ConstantReadNode(2...5)(:Foo), (0...2)), (6...7), IntegerNode(8...10)() )] diff --git a/test/yarp/snapshots/whitequark/casgn_unscoped.txt b/test/yarp/snapshots/whitequark/casgn_unscoped.txt index 16c6636bb4d07f..7e778015b15334 100644 --- a/test/yarp/snapshots/whitequark/casgn_unscoped.txt +++ b/test/yarp/snapshots/whitequark/casgn_unscoped.txt @@ -1,6 +1,6 @@ ProgramNode(0...8)( [], StatementsNode(0...8)( - [ConstantWriteNode(0...8)((0...3), IntegerNode(6...8)(), (4...5))] + [ConstantWriteNode(0...8)(:Foo, (0...3), IntegerNode(6...8)(), (4...5))] ) ) diff --git a/test/yarp/snapshots/whitequark/class.txt b/test/yarp/snapshots/whitequark/class.txt index c176350d059daa..217b8011f00ec6 100644 --- a/test/yarp/snapshots/whitequark/class.txt +++ b/test/yarp/snapshots/whitequark/class.txt @@ -4,7 +4,7 @@ ProgramNode(0...29)( [ClassNode(0...13)( [], (0...5), - ConstantReadNode(6...9)(), + ConstantReadNode(6...9)(:Foo), nil, nil, nil, @@ -14,7 +14,7 @@ ProgramNode(0...29)( ClassNode(15...29)( [], (15...20), - ConstantReadNode(21...24)(), + ConstantReadNode(21...24)(:Foo), nil, nil, nil, diff --git a/test/yarp/snapshots/whitequark/class_definition_in_while_cond.txt b/test/yarp/snapshots/whitequark/class_definition_in_while_cond.txt index 1e954972a8df0b..d14e3907f0288d 100644 --- a/test/yarp/snapshots/whitequark/class_definition_in_while_cond.txt +++ b/test/yarp/snapshots/whitequark/class_definition_in_while_cond.txt @@ -65,7 +65,7 @@ ProgramNode(0...197)( ClassNode(110...139)( [:a], (110...115), - ConstantReadNode(116...119)(), + ConstantReadNode(116...119)(:Foo), nil, nil, StatementsNode(120...134)( @@ -99,7 +99,7 @@ ProgramNode(0...197)( ClassNode(159...185)( [], (159...164), - ConstantReadNode(165...168)(), + ConstantReadNode(165...168)(:Foo), nil, nil, StatementsNode(170...180)( diff --git a/test/yarp/snapshots/whitequark/class_super.txt b/test/yarp/snapshots/whitequark/class_super.txt index 3dda8280a1628e..4a77a4213c650c 100644 --- a/test/yarp/snapshots/whitequark/class_super.txt +++ b/test/yarp/snapshots/whitequark/class_super.txt @@ -4,9 +4,9 @@ ProgramNode(0...20)( [ClassNode(0...20)( [], (0...5), - ConstantReadNode(6...9)(), + ConstantReadNode(6...9)(:Foo), (10...11), - ConstantReadNode(12...15)(), + ConstantReadNode(12...15)(:Bar), nil, (17...20), "Foo" diff --git a/test/yarp/snapshots/whitequark/class_super_label.txt b/test/yarp/snapshots/whitequark/class_super_label.txt index 17e92e1693d97c..10d4b28cea343b 100644 --- a/test/yarp/snapshots/whitequark/class_super_label.txt +++ b/test/yarp/snapshots/whitequark/class_super_label.txt @@ -4,7 +4,7 @@ ProgramNode(0...20)( [ClassNode(0...20)( [], (0...5), - ConstantReadNode(6...9)(), + ConstantReadNode(6...9)(:Foo), (10...11), CallNode(12...15)( nil, diff --git a/test/yarp/snapshots/whitequark/const_op_asgn.txt b/test/yarp/snapshots/whitequark/const_op_asgn.txt index 8a7bb4eae86a92..d417c5d1c915a0 100644 --- a/test/yarp/snapshots/whitequark/const_op_asgn.txt +++ b/test/yarp/snapshots/whitequark/const_op_asgn.txt @@ -2,12 +2,13 @@ ProgramNode(0...77)( [], StatementsNode(0...77)( [ConstantPathOperatorWriteNode(0...8)( - ConstantPathNode(0...3)(nil, ConstantReadNode(2...3)(), (0...2)), + ConstantPathNode(0...3)(nil, ConstantReadNode(2...3)(:A), (0...2)), (4...6), IntegerNode(7...8)(), :+ ), ConstantOperatorWriteNode(10...16)( + :A, (10...11), (12...14), IntegerNode(15...16)(), @@ -15,8 +16,8 @@ ProgramNode(0...77)( ), ConstantPathOperatorWriteNode(18...27)( ConstantPathNode(18...22)( - ConstantReadNode(18...19)(), - ConstantReadNode(21...22)(), + ConstantReadNode(18...19)(:B), + ConstantReadNode(21...22)(:A), (19...21) ), (23...25), @@ -31,7 +32,7 @@ ProgramNode(0...77)( [ConstantPathOrWriteNode(36...45)( ConstantPathNode(36...39)( nil, - ConstantReadNode(38...39)(), + ConstantReadNode(38...39)(:A), (36...38) ), (40...43), @@ -54,7 +55,7 @@ ProgramNode(0...77)( [ConstantPathOrWriteNode(59...72)( ConstantPathNode(59...66)( SelfNode(59...63)(), - ConstantReadNode(65...66)(), + ConstantReadNode(65...66)(:A), (63...65) ), (67...70), diff --git a/test/yarp/snapshots/whitequark/const_scoped.txt b/test/yarp/snapshots/whitequark/const_scoped.txt index 8aa53922cd7220..2404bd05290faf 100644 --- a/test/yarp/snapshots/whitequark/const_scoped.txt +++ b/test/yarp/snapshots/whitequark/const_scoped.txt @@ -2,8 +2,8 @@ ProgramNode(0...8)( [], StatementsNode(0...8)( [ConstantPathNode(0...8)( - ConstantReadNode(0...3)(), - ConstantReadNode(5...8)(), + ConstantReadNode(0...3)(:Bar), + ConstantReadNode(5...8)(:Foo), (3...5) )] ) diff --git a/test/yarp/snapshots/whitequark/const_toplevel.txt b/test/yarp/snapshots/whitequark/const_toplevel.txt index 248b407e67edbc..14647d31be8545 100644 --- a/test/yarp/snapshots/whitequark/const_toplevel.txt +++ b/test/yarp/snapshots/whitequark/const_toplevel.txt @@ -1,6 +1,6 @@ ProgramNode(0...5)( [], StatementsNode(0...5)( - [ConstantPathNode(0...5)(nil, ConstantReadNode(2...5)(), (0...2))] + [ConstantPathNode(0...5)(nil, ConstantReadNode(2...5)(:Foo), (0...2))] ) ) diff --git a/test/yarp/snapshots/whitequark/const_unscoped.txt b/test/yarp/snapshots/whitequark/const_unscoped.txt index 8b8198ef49be03..716cbf524973b9 100644 --- a/test/yarp/snapshots/whitequark/const_unscoped.txt +++ b/test/yarp/snapshots/whitequark/const_unscoped.txt @@ -1 +1 @@ -ProgramNode(0...3)([], StatementsNode(0...3)([ConstantReadNode(0...3)()])) +ProgramNode(0...3)([], StatementsNode(0...3)([ConstantReadNode(0...3)(:Foo)])) diff --git a/test/yarp/snapshots/whitequark/cpath.txt b/test/yarp/snapshots/whitequark/cpath.txt index 2f8387115c62fd..1c3d4e6c3065e4 100644 --- a/test/yarp/snapshots/whitequark/cpath.txt +++ b/test/yarp/snapshots/whitequark/cpath.txt @@ -4,7 +4,7 @@ ProgramNode(0...39)( [ModuleNode(0...17)( [], (0...6), - ConstantPathNode(7...12)(nil, ConstantReadNode(9...12)(), (7...9)), + ConstantPathNode(7...12)(nil, ConstantReadNode(9...12)(:Foo), (7...9)), nil, (14...17), "Foo" @@ -13,8 +13,8 @@ ProgramNode(0...39)( [], (19...25), ConstantPathNode(26...34)( - ConstantReadNode(26...29)(), - ConstantReadNode(31...34)(), + ConstantReadNode(26...29)(:Bar), + ConstantReadNode(31...34)(:Foo), (29...31) ), nil, diff --git a/test/yarp/snapshots/whitequark/defs.txt b/test/yarp/snapshots/whitequark/defs.txt index ef7d56edbb7893..372edbfdcd0eee 100644 --- a/test/yarp/snapshots/whitequark/defs.txt +++ b/test/yarp/snapshots/whitequark/defs.txt @@ -20,7 +20,7 @@ ProgramNode(0...100)( ), DefNode(20...39)( (31...34), - ConstantReadNode(24...30)(), + ConstantReadNode(24...30)(:String), nil, nil, [], @@ -33,7 +33,7 @@ ProgramNode(0...100)( ), DefNode(41...61)( (53...56), - ConstantReadNode(45...51)(), + ConstantReadNode(45...51)(:String), nil, nil, [], diff --git a/test/yarp/snapshots/whitequark/if_while_after_class__since_32.txt b/test/yarp/snapshots/whitequark/if_while_after_class__since_32.txt index 1ebb67a457477a..e1e4419b1c88ea 100644 --- a/test/yarp/snapshots/whitequark/if_while_after_class__since_32.txt +++ b/test/yarp/snapshots/whitequark/if_while_after_class__since_32.txt @@ -8,11 +8,11 @@ ProgramNode(0...178)( IfNode(6...25)( (6...8), TrueNode(9...13)(), - StatementsNode(15...21)([ConstantReadNode(15...21)()]), + StatementsNode(15...21)([ConstantReadNode(15...21)(:Object)]), nil, (22...25) ), - ConstantReadNode(27...33)(), + ConstantReadNode(27...33)(:Kernel), (25...27) ), nil, @@ -31,13 +31,13 @@ ProgramNode(0...178)( TrueNode(52...56)(), StatementsNode(58...70)( [BreakNode(58...70)( - ArgumentsNode(64...70)([ConstantReadNode(64...70)()]), + ArgumentsNode(64...70)([ConstantReadNode(64...70)(:Object)]), (58...63) )] ), 0 ), - ConstantReadNode(76...82)(), + ConstantReadNode(76...82)(:Kernel), (74...76) ), nil, @@ -53,11 +53,11 @@ ProgramNode(0...178)( IfNode(96...115)( (96...98), TrueNode(99...103)(), - StatementsNode(105...111)([ConstantReadNode(105...111)()]), + StatementsNode(105...111)([ConstantReadNode(105...111)(:Object)]), nil, (112...115) ), - ConstantReadNode(117...123)(), + ConstantReadNode(117...123)(:Kernel), (115...117) ), nil, @@ -74,13 +74,15 @@ ProgramNode(0...178)( TrueNode(143...147)(), StatementsNode(149...161)( [BreakNode(149...161)( - ArgumentsNode(155...161)([ConstantReadNode(155...161)()]), + ArgumentsNode(155...161)( + [ConstantReadNode(155...161)(:Object)] + ), (149...154) )] ), 0 ), - ConstantReadNode(167...173)(), + ConstantReadNode(167...173)(:Kernel), (165...167) ), nil, diff --git a/test/yarp/snapshots/whitequark/masgn_const.txt b/test/yarp/snapshots/whitequark/masgn_const.txt index 7aeb91557c4914..51f44f4d2bf7a5 100644 --- a/test/yarp/snapshots/whitequark/masgn_const.txt +++ b/test/yarp/snapshots/whitequark/masgn_const.txt @@ -2,7 +2,11 @@ ProgramNode(0...34)( [:foo], StatementsNode(0...34)( [MultiWriteNode(0...14)( - [ConstantPathTargetNode(0...3)(nil, ConstantReadNode(2...3)(), (0...2)), + [ConstantPathTargetNode(0...3)( + nil, + ConstantReadNode(2...3)(:A), + (0...2) + ), LocalVariableTargetNode(5...8)(:foo, 0)], (9...10), LocalVariableReadNode(11...14)(:foo, 0), @@ -12,7 +16,7 @@ ProgramNode(0...34)( MultiWriteNode(16...34)( [ConstantPathTargetNode(16...23)( SelfNode(16...20)(), - ConstantReadNode(22...23)(), + ConstantReadNode(22...23)(:A), (20...22) ), LocalVariableTargetNode(25...28)(:foo, 0)], diff --git a/test/yarp/snapshots/whitequark/module.txt b/test/yarp/snapshots/whitequark/module.txt index 1695fb8fa92608..395bc6136652e7 100644 --- a/test/yarp/snapshots/whitequark/module.txt +++ b/test/yarp/snapshots/whitequark/module.txt @@ -4,7 +4,7 @@ ProgramNode(0...15)( [ModuleNode(0...15)( [], (0...6), - ConstantReadNode(7...10)(), + ConstantReadNode(7...10)(:Foo), nil, (12...15), "Foo" diff --git a/test/yarp/snapshots/whitequark/numparam_outside_block.txt b/test/yarp/snapshots/whitequark/numparam_outside_block.txt index ac120e8188d330..c3972dbf9b0412 100644 --- a/test/yarp/snapshots/whitequark/numparam_outside_block.txt +++ b/test/yarp/snapshots/whitequark/numparam_outside_block.txt @@ -15,7 +15,7 @@ ProgramNode(0...83)( ClassNode(27...43)( [], (27...32), - ConstantReadNode(33...34)(), + ConstantReadNode(33...34)(:A), nil, nil, StatementsNode(36...38)( @@ -42,7 +42,7 @@ ProgramNode(0...83)( ModuleNode(66...83)( [], (66...72), - ConstantReadNode(73...74)(), + ConstantReadNode(73...74)(:A), StatementsNode(76...78)( [CallNode(76...78)(nil, nil, (76...78), nil, nil, nil, nil, 2, "_1")] ), diff --git a/test/yarp/snapshots/whitequark/op_asgn_cmd.txt b/test/yarp/snapshots/whitequark/op_asgn_cmd.txt index 9bf83ad959a3ce..9c15e15cde7ab7 100644 --- a/test/yarp/snapshots/whitequark/op_asgn_cmd.txt +++ b/test/yarp/snapshots/whitequark/op_asgn_cmd.txt @@ -76,7 +76,7 @@ ProgramNode(0...64)( ConstantPathOperatorWriteNode(32...47)( ConstantPathNode(32...38)( CallNode(32...35)(nil, nil, (32...35), nil, nil, nil, nil, 2, "foo"), - ConstantReadNode(37...38)(), + ConstantReadNode(37...38)(:A), (35...37) ), (39...41), diff --git a/test/yarp/snapshots/whitequark/parser_bug_490.txt b/test/yarp/snapshots/whitequark/parser_bug_490.txt index 8ea556d927713e..ca6ab1a69d41e8 100644 --- a/test/yarp/snapshots/whitequark/parser_bug_490.txt +++ b/test/yarp/snapshots/whitequark/parser_bug_490.txt @@ -13,6 +13,7 @@ ProgramNode(0...132)( SelfNode(16...20)(), StatementsNode(22...29)( [ConstantWriteNode(22...29)( + :A, (22...23), NilNode(26...29)(), (24...25) @@ -43,7 +44,7 @@ ProgramNode(0...132)( [ClassNode(63...75)( [], (63...68), - ConstantReadNode(69...70)(), + ConstantReadNode(69...70)(:C), nil, nil, nil, @@ -76,7 +77,7 @@ ProgramNode(0...132)( [ModuleNode(109...122)( [], (109...115), - ConstantReadNode(116...117)(), + ConstantReadNode(116...117)(:M), nil, (119...122), "M" diff --git a/test/yarp/snapshots/whitequark/parser_bug_518.txt b/test/yarp/snapshots/whitequark/parser_bug_518.txt index bee652b20a9402..dd831ac54d3110 100644 --- a/test/yarp/snapshots/whitequark/parser_bug_518.txt +++ b/test/yarp/snapshots/whitequark/parser_bug_518.txt @@ -4,9 +4,9 @@ ProgramNode(0...15)( [ClassNode(0...15)( [], (0...5), - ConstantReadNode(6...7)(), + ConstantReadNode(6...7)(:A), (8...9), - ConstantReadNode(10...11)(), + ConstantReadNode(10...11)(:B), nil, (12...15), "A" diff --git a/test/yarp/snapshots/whitequark/resbody_list.txt b/test/yarp/snapshots/whitequark/resbody_list.txt index a3f80a0f22989d..8456996663daa9 100644 --- a/test/yarp/snapshots/whitequark/resbody_list.txt +++ b/test/yarp/snapshots/whitequark/resbody_list.txt @@ -8,7 +8,7 @@ ProgramNode(0...39)( ), RescueNode(13...34)( (13...19), - [ConstantReadNode(20...29)()], + [ConstantReadNode(20...29)(:Exception)], nil, nil, StatementsNode(31...34)( diff --git a/test/yarp/snapshots/whitequark/resbody_list_mrhs.txt b/test/yarp/snapshots/whitequark/resbody_list_mrhs.txt index 4969f5929ba1d2..f4160d82daf037 100644 --- a/test/yarp/snapshots/whitequark/resbody_list_mrhs.txt +++ b/test/yarp/snapshots/whitequark/resbody_list_mrhs.txt @@ -8,7 +8,7 @@ ProgramNode(0...44)( ), RescueNode(13...39)( (13...19), - [ConstantReadNode(20...29)(), + [ConstantReadNode(20...29)(:Exception), CallNode(31...34)( nil, nil, diff --git a/test/yarp/snapshots/whitequark/ruby_bug_12073.txt b/test/yarp/snapshots/whitequark/ruby_bug_12073.txt index 8a3aee68a6998d..0688332fd34292 100644 --- a/test/yarp/snapshots/whitequark/ruby_bug_12073.txt +++ b/test/yarp/snapshots/whitequark/ruby_bug_12073.txt @@ -47,8 +47,8 @@ ProgramNode(0...49)( nil, ArgumentsNode(36...44)( [ConstantPathNode(36...40)( - ConstantReadNode(36...37)(), - ConstantReadNode(39...40)(), + ConstantReadNode(36...37)(:A), + ConstantReadNode(39...40)(:B), (37...39) ), StringNode(42...44)((42...43), (43...43), (43...44), "")] diff --git a/test/yarp/snapshots/whitequark/ruby_bug_12402.txt b/test/yarp/snapshots/whitequark/ruby_bug_12402.txt index 396349c5b579a0..2f7562fd20b22d 100644 --- a/test/yarp/snapshots/whitequark/ruby_bug_12402.txt +++ b/test/yarp/snapshots/whitequark/ruby_bug_12402.txt @@ -298,7 +298,7 @@ ProgramNode(0...437)( ConstantPathOrWriteNode(242...273)( ConstantPathNode(242...248)( LocalVariableReadNode(242...245)(:foo, 0), - ConstantReadNode(247...248)(), + ConstantReadNode(247...248)(:C), (245...247) ), (249...252), @@ -333,7 +333,7 @@ ProgramNode(0...437)( ConstantPathOrWriteNode(275...307)( ConstantPathNode(275...281)( LocalVariableReadNode(275...278)(:foo, 0), - ConstantReadNode(280...281)(), + ConstantReadNode(280...281)(:C), (278...280) ), (282...285), diff --git a/test/yarp/snapshots/whitequark/send_attr_asgn.txt b/test/yarp/snapshots/whitequark/send_attr_asgn.txt index 9d70f90f9a51f4..b4b3d5706433c5 100644 --- a/test/yarp/snapshots/whitequark/send_attr_asgn.txt +++ b/test/yarp/snapshots/whitequark/send_attr_asgn.txt @@ -26,7 +26,7 @@ ProgramNode(0...44)( ConstantPathWriteNode(22...32)( ConstantPathNode(22...28)( CallNode(22...25)(nil, nil, (22...25), nil, nil, nil, nil, 2, "foo"), - ConstantReadNode(27...28)(), + ConstantReadNode(27...28)(:A), (25...27) ), (29...30), diff --git a/test/yarp/snapshots/whitequark/ternary_ambiguous_symbol.txt b/test/yarp/snapshots/whitequark/ternary_ambiguous_symbol.txt index 3f77bfd3e5c30d..e7e814c053ac41 100644 --- a/test/yarp/snapshots/whitequark/ternary_ambiguous_symbol.txt +++ b/test/yarp/snapshots/whitequark/ternary_ambiguous_symbol.txt @@ -20,7 +20,7 @@ ProgramNode(0...13)( StatementsNode(10...11)([LocalVariableReadNode(10...11)(:t, 0)]), ElseNode(11...13)( (11...12), - StatementsNode(12...13)([ConstantReadNode(12...13)()]), + StatementsNode(12...13)([ConstantReadNode(12...13)(:T)]), nil ), nil diff --git a/yarp/config.yml b/yarp/config.yml index a53b7aaa861768..a8841bed4c64a1 100644 --- a/yarp/config.yml +++ b/yarp/config.yml @@ -867,6 +867,8 @@ nodes: ^^^^^^^^^ - name: ConstantAndWriteNode fields: + - name: name + type: constant - name: name_loc type: location - name: operator_loc @@ -880,6 +882,8 @@ nodes: ^^^^^^^^^^^^^^^^ - name: ConstantOperatorWriteNode fields: + - name: name + type: constant - name: name_loc type: location - name: operator_loc @@ -895,6 +899,8 @@ nodes: ^^^^^^^^^^^^^^^ - name: ConstantOrWriteNode fields: + - name: name + type: constant - name: name_loc type: location - name: operator_loc @@ -997,12 +1003,18 @@ nodes: ::Foo::Bar = 1 ^^^^^^^^^^^^^^ - name: ConstantReadNode + fields: + - name: name + type: constant comment: | Represents referencing a constant. Foo ^^^ - name: ConstantTargetNode + fields: + - name: name + type: constant comment: | Represents writing to a constant in a context that doesn't have an explicit value. @@ -1010,6 +1022,8 @@ nodes: ^^^ ^^^ - name: ConstantWriteNode fields: + - name: name + type: constant - name: name_loc type: location - name: value diff --git a/yarp/yarp.c b/yarp/yarp.c index 8079bb55f67543..df1cec913ce5bb 100644 --- a/yarp/yarp.c +++ b/yarp/yarp.c @@ -1747,7 +1747,7 @@ yp_class_variable_read_node_create(yp_parser_t *parser, const yp_token_t *token) .type = YP_CLASS_VARIABLE_READ_NODE, .location = YP_LOCATION_TOKEN_VALUE(token) }, - .name = yp_parser_constant_id_location(parser, token->start, token->end) + .name = yp_parser_constant_id_token(parser, token) }; return node; @@ -1885,8 +1885,7 @@ yp_constant_path_write_node_create(yp_parser_t *parser, yp_constant_path_node_t // Allocate and initialize a new ConstantAndWriteNode node. static yp_constant_and_write_node_t * -yp_constant_and_write_node_create(yp_parser_t *parser, yp_node_t *target, const yp_token_t *operator, yp_node_t *value) { - assert(YP_NODE_TYPE_P(target, YP_CONSTANT_READ_NODE)); +yp_constant_and_write_node_create(yp_parser_t *parser, yp_constant_read_node_t *target, const yp_token_t *operator, yp_node_t *value) { assert(operator->type == YP_TOKEN_AMPERSAND_AMPERSAND_EQUAL); yp_constant_and_write_node_t *node = YP_ALLOC_NODE(parser, yp_constant_and_write_node_t); @@ -1894,11 +1893,12 @@ yp_constant_and_write_node_create(yp_parser_t *parser, yp_node_t *target, const { .type = YP_CONSTANT_AND_WRITE_NODE, .location = { - .start = target->location.start, + .start = target->base.location.start, .end = value->location.end } }, - .name_loc = target->location, + .name = target->name, + .name_loc = target->base.location, .operator_loc = YP_LOCATION_TOKEN_VALUE(operator), .value = value }; @@ -1908,18 +1908,19 @@ yp_constant_and_write_node_create(yp_parser_t *parser, yp_node_t *target, const // Allocate and initialize a new ConstantOperatorWriteNode node. static yp_constant_operator_write_node_t * -yp_constant_operator_write_node_create(yp_parser_t *parser, yp_node_t *target, const yp_token_t *operator, yp_node_t *value) { +yp_constant_operator_write_node_create(yp_parser_t *parser, yp_constant_read_node_t *target, const yp_token_t *operator, yp_node_t *value) { yp_constant_operator_write_node_t *node = YP_ALLOC_NODE(parser, yp_constant_operator_write_node_t); *node = (yp_constant_operator_write_node_t) { { .type = YP_CONSTANT_OPERATOR_WRITE_NODE, .location = { - .start = target->location.start, + .start = target->base.location.start, .end = value->location.end } }, - .name_loc = target->location, + .name = target->name, + .name_loc = target->base.location, .operator_loc = YP_LOCATION_TOKEN_VALUE(operator), .value = value, .operator = yp_parser_constant_id_location(parser, operator->start, operator->end - 1) @@ -1930,8 +1931,7 @@ yp_constant_operator_write_node_create(yp_parser_t *parser, yp_node_t *target, c // Allocate and initialize a new ConstantOrWriteNode node. static yp_constant_or_write_node_t * -yp_constant_or_write_node_create(yp_parser_t *parser, yp_node_t *target, const yp_token_t *operator, yp_node_t *value) { - assert(YP_NODE_TYPE_P(target, YP_CONSTANT_READ_NODE)); +yp_constant_or_write_node_create(yp_parser_t *parser, yp_constant_read_node_t *target, const yp_token_t *operator, yp_node_t *value) { assert(operator->type == YP_TOKEN_PIPE_PIPE_EQUAL); yp_constant_or_write_node_t *node = YP_ALLOC_NODE(parser, yp_constant_or_write_node_t); @@ -1939,11 +1939,12 @@ yp_constant_or_write_node_create(yp_parser_t *parser, yp_node_t *target, const y { .type = YP_CONSTANT_OR_WRITE_NODE, .location = { - .start = target->location.start, + .start = target->base.location.start, .end = value->location.end } }, - .name_loc = target->location, + .name = target->name, + .name_loc = target->base.location, .operator_loc = YP_LOCATION_TOKEN_VALUE(operator), .value = value }; @@ -1955,26 +1956,34 @@ yp_constant_or_write_node_create(yp_parser_t *parser, yp_node_t *target, const y static yp_constant_read_node_t * yp_constant_read_node_create(yp_parser_t *parser, const yp_token_t *name) { assert(name->type == YP_TOKEN_CONSTANT || name->type == YP_TOKEN_MISSING); - yp_constant_read_node_t *node = YP_ALLOC_NODE(parser, yp_constant_read_node_t); - *node = (yp_constant_read_node_t) {{ .type = YP_CONSTANT_READ_NODE, .location = YP_LOCATION_TOKEN_VALUE(name) }}; + + *node = (yp_constant_read_node_t) { + { + .type = YP_CONSTANT_READ_NODE, + .location = YP_LOCATION_TOKEN_VALUE(name) + }, + .name = yp_parser_constant_id_token(parser, name) + }; + return node; } // Allocate a new ConstantWriteNode node. static yp_constant_write_node_t * -yp_constant_write_node_create(yp_parser_t *parser, yp_location_t *name_loc, const yp_token_t *operator, yp_node_t *value) { +yp_constant_write_node_create(yp_parser_t *parser, yp_constant_read_node_t *target, const yp_token_t *operator, yp_node_t *value) { yp_constant_write_node_t *node = YP_ALLOC_NODE(parser, yp_constant_write_node_t); *node = (yp_constant_write_node_t) { { .type = YP_CONSTANT_WRITE_NODE, .location = { - .start = name_loc->start, + .start = target->base.location.start, .end = value->location.end - }, + } }, - .name_loc = *name_loc, + .name = target->name, + .name_loc = target->base.location, .operator_loc = YP_OPTIONAL_LOCATION_TOKEN_VALUE(operator), .value = value }; @@ -2478,7 +2487,7 @@ yp_global_variable_read_node_create(yp_parser_t *parser, const yp_token_t *name) .type = YP_GLOBAL_VARIABLE_READ_NODE, .location = YP_LOCATION_TOKEN_VALUE(name), }, - .name = yp_parser_constant_id_location(parser, name->start, name->end) + .name = yp_parser_constant_id_token(parser, name) }; return node; @@ -2840,7 +2849,7 @@ yp_instance_variable_read_node_create(yp_parser_t *parser, const yp_token_t *tok .type = YP_INSTANCE_VARIABLE_READ_NODE, .location = YP_LOCATION_TOKEN_VALUE(token) }, - .name = yp_parser_constant_id_location(parser, token->start, token->end) + .name = yp_parser_constant_id_token(parser, token) }; return node; @@ -8167,7 +8176,7 @@ parse_write(yp_parser_t *parser, yp_node_t *target, yp_token_t *operator, yp_nod case YP_CONSTANT_PATH_NODE: return (yp_node_t *) yp_constant_path_write_node_create(parser, (yp_constant_path_node_t *) target, operator, value); case YP_CONSTANT_READ_NODE: { - yp_constant_write_node_t *node = yp_constant_write_node_create(parser, &target->location, operator, value); + yp_constant_write_node_t *node = yp_constant_write_node_create(parser, (yp_constant_read_node_t *) target, operator, value); yp_node_destroy(parser, target); return (yp_node_t *) node; } @@ -13005,7 +13014,7 @@ parse_expression_infix(yp_parser_t *parser, yp_node_t *node, yp_binding_power_t parser_lex(parser); yp_node_t *value = parse_expression(parser, binding_power, "Expected a value after &&="); - yp_node_t *result = (yp_node_t *) yp_constant_and_write_node_create(parser, node, &token, value); + yp_node_t *result = (yp_node_t *) yp_constant_and_write_node_create(parser, (yp_constant_read_node_t *) node, &token, value); yp_node_destroy(parser, node); return result; @@ -13106,7 +13115,7 @@ parse_expression_infix(yp_parser_t *parser, yp_node_t *node, yp_binding_power_t parser_lex(parser); yp_node_t *value = parse_expression(parser, binding_power, "Expected a value after ||="); - yp_node_t *result = (yp_node_t *) yp_constant_or_write_node_create(parser, node, &token, value); + yp_node_t *result = (yp_node_t *) yp_constant_or_write_node_create(parser, (yp_constant_read_node_t *) node, &token, value); yp_node_destroy(parser, node); return result; @@ -13217,7 +13226,7 @@ parse_expression_infix(yp_parser_t *parser, yp_node_t *node, yp_binding_power_t parser_lex(parser); yp_node_t *value = parse_expression(parser, binding_power, "Expected a value after the operator."); - yp_node_t *result = (yp_node_t *) yp_constant_operator_write_node_create(parser, node, &token, value); + yp_node_t *result = (yp_node_t *) yp_constant_operator_write_node_create(parser, (yp_constant_read_node_t *) node, &token, value); yp_node_destroy(parser, node); return result; From dae6a0a29579291f7775e397c1523ce23fba1f48 Mon Sep 17 00:00:00 2001 From: Kevin Newton Date: Tue, 5 Sep 2023 10:22:57 -0400 Subject: [PATCH 82/95] [ruby/yarp] Introduce YARP::Pattern https://github.com/ruby/yarp/commit/2a12e9637b --- lib/yarp.rb | 1 + lib/yarp/pattern.rb | 239 ++++++++++++++++++++++++++++++++++++++ lib/yarp/yarp.gemspec | 1 + test/yarp/pattern_test.rb | 132 +++++++++++++++++++++ 4 files changed, 373 insertions(+) create mode 100644 lib/yarp/pattern.rb create mode 100644 test/yarp/pattern_test.rb diff --git a/lib/yarp.rb b/lib/yarp.rb index a77292d26de644..0dab1515fc3512 100644 --- a/lib/yarp.rb +++ b/lib/yarp.rb @@ -609,6 +609,7 @@ def self.parse_serialize_file(filepath) require_relative "yarp/ripper_compat" require_relative "yarp/serialize" require_relative "yarp/pack" +require_relative "yarp/pattern" if RUBY_ENGINE == "ruby" and !ENV["YARP_FFI_BACKEND"] require "yarp/yarp" diff --git a/lib/yarp/pattern.rb b/lib/yarp/pattern.rb new file mode 100644 index 00000000000000..339f1506c35cb1 --- /dev/null +++ b/lib/yarp/pattern.rb @@ -0,0 +1,239 @@ +# frozen_string_literal: true + +module YARP + # A pattern is an object that wraps a Ruby pattern matching expression. The + # expression would normally be passed to an `in` clause within a `case` + # expression or a rightward assignment expression. For example, in the + # following snippet: + # + # case node + # in ConstantPathNode[ConstantReadNode[name: :YARP], ConstantReadNode[name: :Pattern]] + # end + # + # the pattern is the `ConstantPathNode[...]` expression. + # + # The pattern gets compiled into an object that responds to #call by running + # the #compile method. This method itself will run back through YARP to + # parse the expression into a tree, then walk the tree to generate the + # necessary callable objects. For example, if you wanted to compile the + # expression above into a callable, you would: + # + # callable = YARP::Pattern.new("ConstantPathNode[ConstantReadNode[name: :YARP], ConstantReadNode[name: :Pattern]]").compile + # callable.call(node) + # + # The callable object returned by #compile is guaranteed to respond to #call + # with a single argument, which is the node to match against. It also is + # guaranteed to respond to #===, which means it itself can be used in a `case` + # expression, as in: + # + # case node + # when callable + # end + # + # If the query given to the initializer cannot be compiled into a valid + # matcher (either because of a syntax error or because it is using syntax we + # do not yet support) then a YARP::Pattern::CompilationError will be + # raised. + class Pattern + # Raised when the query given to a pattern is either invalid Ruby syntax or + # is using syntax that we don't yet support. + class CompilationError < StandardError + def initialize(repr) + super(<<~ERROR) + YARP was unable to compile the pattern you provided into a usable + expression. It failed on to understand the node represented by: + + #{repr} + + Note that not all syntax supported by Ruby's pattern matching syntax + is also supported by YARP's patterns. If you're using some syntax + that you believe should be supported, please open an issue on + GitHub at https://github.com/ruby/yarp/issues/new. + ERROR + end + end + + attr_reader :query + + def initialize(query) + @query = query + @compiled = nil + end + + def compile + result = YARP.parse("case nil\nin #{query}\nend") + compile_node(result.value.statements.body.last.conditions.last.pattern) + end + + def scan(root) + return to_enum(__method__, root) unless block_given? + + @compiled ||= compile + queue = [root] + + while (node = queue.shift) + yield node if @compiled.call(node) + queue.concat(node.child_nodes.compact) + end + end + + private + + # Shortcut for combining two procs into one that returns true if both return + # true. + def combine_and(left, right) + ->(other) { left.call(other) && right.call(other) } + end + + # Shortcut for combining two procs into one that returns true if either + # returns true. + def combine_or(left, right) + ->(other) { left.call(other) || right.call(other) } + end + + # Raise an error because the given node is not supported. + def compile_error(node) + raise CompilationError, node.inspect + end + + # in [foo, bar, baz] + def compile_array_pattern_node(node) + compile_error(node) if !node.rest.nil? || node.posts.any? + + constant = node.constant + compiled_constant = compile_node(constant) if constant + + preprocessed = node.requireds.map { |required| compile_node(required) } + + compiled_requireds = ->(other) do + deconstructed = other.deconstruct + + deconstructed.length == preprocessed.length && + preprocessed + .zip(deconstructed) + .all? { |(matcher, value)| matcher.call(value) } + end + + if compiled_constant + combine_and(compiled_constant, compiled_requireds) + else + compiled_requireds + end + end + + # in foo | bar + def compile_alternation_pattern_node(node) + combine_or(compile_node(node.left), compile_node(node.right)) + end + + # in YARP::ConstantReadNode + def compile_constant_path_node(node) + parent = node.parent + + if parent.is_a?(ConstantReadNode) && parent.slice == "YARP" + compile_node(node.child) + else + compile_error(node) + end + end + + # in ConstantReadNode + # in String + def compile_constant_read_node(node) + value = node.slice + + if YARP.const_defined?(value, false) + clazz = YARP.const_get(value) + + ->(other) { clazz === other } + elsif Object.const_defined?(value, false) + clazz = Object.const_get(value) + + ->(other) { clazz === other } + else + compile_error(node) + end + end + + # in InstanceVariableReadNode[name: Symbol] + # in { name: Symbol } + def compile_hash_pattern_node(node) + compile_error(node) unless node.kwrest.nil? + compiled_constant = compile_node(node.constant) if node.constant + + preprocessed = + node.assocs.to_h do |assoc| + [assoc.key.unescaped.to_sym, compile_node(assoc.value)] + end + + compiled_keywords = ->(other) do + deconstructed = other.deconstruct_keys(preprocessed.keys) + + preprocessed.all? do |keyword, matcher| + deconstructed.key?(keyword) && matcher.call(deconstructed[keyword]) + end + end + + if compiled_constant + combine_and(compiled_constant, compiled_keywords) + else + compiled_keywords + end + end + + # in nil + def compile_nil_node(node) + ->(attribute) { attribute.nil? } + end + + # in /foo/ + def compile_regular_expression_node(node) + regexp = Regexp.new(node.unescaped, node.closing[1..]) + + ->(attribute) { regexp === attribute } + end + + # in "" + # in "foo" + def compile_string_node(node) + string = node.unescaped + + ->(attribute) { string === attribute } + end + + # in :+ + # in :foo + def compile_symbol_node(node) + symbol = node.unescaped.to_sym + + ->(attribute) { symbol === attribute } + end + + # Compile any kind of node. Dispatch out to the individual compilation + # methods based on the type of node. + def compile_node(node) + case node + when AlternationPatternNode + compile_alternation_pattern_node(node) + when ArrayPatternNode + compile_array_pattern_node(node) + when ConstantPathNode + compile_constant_path_node(node) + when ConstantReadNode + compile_constant_read_node(node) + when HashPatternNode + compile_hash_pattern_node(node) + when NilNode + compile_nil_node(node) + when RegularExpressionNode + compile_regular_expression_node(node) + when StringNode + compile_string_node(node) + when SymbolNode + compile_symbol_node(node) + else + compile_error(node) + end + end + end +end diff --git a/lib/yarp/yarp.gemspec b/lib/yarp/yarp.gemspec index 9603f5b1cd02fa..33b47d676aa25e 100644 --- a/lib/yarp/yarp.gemspec +++ b/lib/yarp/yarp.gemspec @@ -65,6 +65,7 @@ Gem::Specification.new do |spec| "lib/yarp/mutation_visitor.rb", "lib/yarp/node.rb", "lib/yarp/pack.rb", + "lib/yarp/pattern.rb", "lib/yarp/ripper_compat.rb", "lib/yarp/serialize.rb", "src/diagnostic.c", diff --git a/test/yarp/pattern_test.rb b/test/yarp/pattern_test.rb new file mode 100644 index 00000000000000..76e6e3e7885a18 --- /dev/null +++ b/test/yarp/pattern_test.rb @@ -0,0 +1,132 @@ +# frozen_string_literal: true + +require_relative "test_helper" + +module YARP + class PatternTest < Test::Unit::TestCase + def test_invalid_syntax + assert_raises(Pattern::CompilationError) { scan("", "<>") } + end + + def test_invalid_constant + assert_raises(Pattern::CompilationError) { scan("", "Foo") } + end + + def test_invalid_nested_constant + assert_raises(Pattern::CompilationError) { scan("", "Foo::Bar") } + end + + def test_regexp_with_interpolation + assert_raises(Pattern::CompilationError) { scan("", "/\#{foo}/") } + end + + def test_string_with_interpolation + assert_raises(Pattern::CompilationError) { scan("", '"#{foo}"') } + end + + def test_symbol_with_interpolation + assert_raises(Pattern::CompilationError) { scan("", ":\"\#{foo}\"") } + end + + def test_invalid_node + assert_raises(Pattern::CompilationError) { scan("", "IntegerNode[^foo]") } + end + + def test_self + assert_raises(Pattern::CompilationError) { scan("", "self") } + end + + def test_array_pattern_no_constant + results = scan("1 + 2", "[IntegerNode]") + + assert_equal 1, results.length + end + + def test_array_pattern + results = scan("1 + 2", "CallNode[name: \"+\", receiver: IntegerNode, arguments: [IntegerNode]]") + + assert_equal 1, results.length + end + + def test_alternation_pattern + results = scan("Foo + Bar + 1", "ConstantReadNode | IntegerNode") + + assert_equal 3, results.length + assert_equal 1, results.grep(IntegerNode).first.value + end + + def test_constant_read_node + results = scan("Foo + Bar + Baz", "ConstantReadNode") + + assert_equal 3, results.length + assert_equal %w[Bar Baz Foo], results.map(&:slice).sort + end + + def test_object_const + results = scan("1 + 2 + 3", "IntegerNode[]") + + assert_equal 3, results.length + end + + def test_constant_path + results = scan("Foo + Bar + Baz", "YARP::ConstantReadNode") + + assert_equal 3, results.length + end + + def test_hash_pattern_no_constant + results = scan("Foo + Bar + Baz", "{ name: \"+\" }") + + assert_equal 2, results.length + end + + def test_hash_pattern_regexp + results = scan("Foo + Bar + Baz", "{ name: /^[[:punct:]]$/ }") + + assert_equal 2, results.length + assert_equal ["YARP::CallNode"], results.map { |node| node.class.name }.uniq + end + + def test_nil + results = scan("foo", "{ receiver: nil }") + + assert_equal 1, results.length + end + + def test_regexp_options + results = scan("@foo + @bar + @baz", "InstanceVariableReadNode[name: /^@B/i]") + + assert_equal 2, results.length + end + + def test_string_empty + results = scan("", "''") + + assert_empty results + end + + def test_symbol_empty + results = scan("", ":''") + + assert_empty results + end + + def test_symbol_plain + results = scan("@foo", "{ name: :\"@foo\" }") + + assert_equal 1, results.length + end + + def test_symbol + results = scan("@foo", "{ name: :@foo }") + + assert_equal 1, results.length + end + + private + + def scan(source, query) + YARP::Pattern.new(query).scan(YARP.parse(source).value).to_a + end + end +end From 5537169ef0a8a42f8923a545a1fa6a1768e0f0d6 Mon Sep 17 00:00:00 2001 From: Kevin Newton Date: Wed, 6 Sep 2023 09:06:21 -0400 Subject: [PATCH 83/95] [ruby/yarp] Temporarily add name_constant to replace name on ClassNode/ModuleNode https://github.com/ruby/yarp/commit/8f87686e9c --- test/yarp/errors_test.rb | 18 ++++++++------ test/yarp/snapshots/classes.txt | 21 ++++++++++------ test/yarp/snapshots/method_calls.txt | 6 +++-- test/yarp/snapshots/modules.txt | 18 +++++++++----- .../seattlerb/TestRubyParserShared.txt | 21 ++++++++++------ .../snapshots/seattlerb/class_comments.txt | 3 ++- .../snapshots/seattlerb/defn_oneliner_eq2.txt | 3 ++- .../snapshots/seattlerb/defs_oneliner_eq2.txt | 3 ++- .../seattlerb/magic_encoding_comment.txt | 3 ++- .../snapshots/seattlerb/module_comments.txt | 3 ++- .../parse_line_heredoc_hardnewline.txt | 3 ++- .../unparser/corpus/literal/class.txt | 24 ++++++++++++------- .../snapshots/unparser/corpus/literal/if.txt | 6 +++-- .../unparser/corpus/literal/module.txt | 12 ++++++---- .../unparser/corpus/literal/send.txt | 12 ++++++---- .../unparser/corpus/literal/while.txt | 18 +++++++++----- .../unparser/corpus/semantic/while.txt | 3 ++- test/yarp/snapshots/while.txt | 3 ++- test/yarp/snapshots/whitequark/class.txt | 6 +++-- .../class_definition_in_while_cond.txt | 6 +++-- .../yarp/snapshots/whitequark/class_super.txt | 3 ++- .../whitequark/class_super_label.txt | 3 ++- test/yarp/snapshots/whitequark/cpath.txt | 6 +++-- .../if_while_after_class__since_32.txt | 12 ++++++---- test/yarp/snapshots/whitequark/module.txt | 3 ++- .../whitequark/numparam_outside_block.txt | 6 +++-- .../snapshots/whitequark/parser_bug_490.txt | 6 +++-- .../snapshots/whitequark/parser_bug_518.txt | 3 ++- yarp/config.yml | 4 ++++ yarp/yarp.c | 6 +++-- 30 files changed, 163 insertions(+), 81 deletions(-) diff --git a/test/yarp/errors_test.rb b/test/yarp/errors_test.rb index 90be76ab5b72fa..f5064ba70f2b63 100644 --- a/test/yarp/errors_test.rb +++ b/test/yarp/errors_test.rb @@ -19,10 +19,11 @@ def test_module_name_recoverable Location(), ConstantReadNode(:Parent), StatementsNode( - [ModuleNode([], Location(), MissingNode(), nil, Location(), "")] + [ModuleNode([], Location(), MissingNode(), nil, Location(), "", :"")] ), Location(), - "Parent" + "Parent", + :Parent ) assert_errors expected, "module Parent module end", [ @@ -393,7 +394,7 @@ def test_module_definition_in_method_body Location(), nil, nil, - StatementsNode([ModuleNode([], Location(), ConstantReadNode(:A), nil, Location(), "A")]), + StatementsNode([ModuleNode([], Location(), ConstantReadNode(:A), nil, Location(), "A", :A)]), [], Location(), nil, @@ -424,7 +425,7 @@ def test_module_definition_in_method_body_within_block BlockNode( [], nil, - StatementsNode([ModuleNode([], Location(), ConstantReadNode(:Foo), nil, Location(), "Foo")]), + StatementsNode([ModuleNode([], Location(), ConstantReadNode(:Foo), nil, Location(), "Foo", :Foo)]), Location(), Location() ), @@ -464,7 +465,8 @@ def test_class_definition_in_method_body nil, nil, Location(), - "A" + "A", + :A )] ), [], @@ -979,7 +981,8 @@ def test_dont_allow_return_inside_class_body nil, StatementsNode([ReturnNode(Location(), nil)]), Location(), - "A" + "A", + :A ) assert_errors expected, "class A; return; end", [ @@ -994,7 +997,8 @@ def test_dont_allow_return_inside_module_body ConstantReadNode(:A), StatementsNode([ReturnNode(Location(), nil)]), Location(), - "A" + "A", + :A ) assert_errors expected, "module A; return; end", [ diff --git a/test/yarp/snapshots/classes.txt b/test/yarp/snapshots/classes.txt index 4f4bc5513df818..9a5fd84ad216a7 100644 --- a/test/yarp/snapshots/classes.txt +++ b/test/yarp/snapshots/classes.txt @@ -17,7 +17,8 @@ ProgramNode(0...370)( )] ), (14...17), - "A" + "A", + :A ), ClassNode(19...39)( [], @@ -34,7 +35,8 @@ ProgramNode(0...370)( (36...39) ), (36...39), - "A" + "A", + :A ), ClassNode(41...75)( [], @@ -51,7 +53,8 @@ ProgramNode(0...370)( (72...75) ), (72...75), - "A" + "A", + :A ), ClassNode(77...98)( [:a], @@ -69,7 +72,8 @@ ProgramNode(0...370)( )] ), (95...98), - "A" + "A", + :A ), SingletonClassNode(100...120)( [], @@ -123,7 +127,8 @@ ProgramNode(0...370)( )] ), (159...162), - "A" + "A", + :A ), ClassNode(164...218)( [], @@ -149,7 +154,8 @@ ProgramNode(0...370)( )] ), (215...218), - "A" + "A", + :A ), SingletonClassNode(220...240)( [], @@ -281,7 +287,8 @@ ProgramNode(0...370)( ), nil, (367...370), - "A" + "A", + :A )] ) ) diff --git a/test/yarp/snapshots/method_calls.txt b/test/yarp/snapshots/method_calls.txt index 6f11633de29b28..a479948ce187c1 100644 --- a/test/yarp/snapshots/method_calls.txt +++ b/test/yarp/snapshots/method_calls.txt @@ -1192,7 +1192,8 @@ ProgramNode(0...1237)( )] ), (926...929), - "Bar" + "Bar", + :Bar )] ), nil, @@ -1224,7 +1225,8 @@ ProgramNode(0...1237)( )] ), (957...960), - "Bar" + "Bar", + :Bar )] ), nil, diff --git a/test/yarp/snapshots/modules.txt b/test/yarp/snapshots/modules.txt index 9ed5c89fe10450..4b00c1ebafc677 100644 --- a/test/yarp/snapshots/modules.txt +++ b/test/yarp/snapshots/modules.txt @@ -15,7 +15,8 @@ ProgramNode(0...140)( )] ), (15...18), - "A" + "A", + :A ), InterpolatedStringNode(20...38)( (20...23), @@ -50,7 +51,8 @@ ProgramNode(0...140)( ), nil, (52...55), - "M" + "M", + :M ), ModuleNode(57...85)( [:x], @@ -73,7 +75,8 @@ ProgramNode(0...140)( (82...85) ), (82...85), - "A" + "A", + :A ), ModuleNode(87...101)( [], @@ -85,7 +88,8 @@ ProgramNode(0...140)( ), nil, (98...101), - "A" + "A", + :A ), ModuleNode(103...120)( [], @@ -107,7 +111,8 @@ ProgramNode(0...140)( ), nil, (117...120), - "B" + "B", + :B ), ModuleNode(122...140)( [], @@ -129,7 +134,8 @@ ProgramNode(0...140)( ), nil, (137...140), - "B" + "B", + :B )] ) ) diff --git a/test/yarp/snapshots/seattlerb/TestRubyParserShared.txt b/test/yarp/snapshots/seattlerb/TestRubyParserShared.txt index 32b444a2fc83fe..27e8a6b753b98a 100644 --- a/test/yarp/snapshots/seattlerb/TestRubyParserShared.txt +++ b/test/yarp/snapshots/seattlerb/TestRubyParserShared.txt @@ -87,7 +87,8 @@ ProgramNode(0...689)( )] ), (266...269), - "X" + "X", + :X ), ClassNode(293...376)( [], @@ -111,11 +112,13 @@ ProgramNode(0...689)( )] ), (355...358), - "Y" + "Y", + :Y )] ), (373...376), - "X" + "X", + :X ), ClassNode(395...498)( [], @@ -162,7 +165,8 @@ ProgramNode(0...689)( )] ), (495...498), - "X" + "X", + :X ), ModuleNode(517...565)( [], @@ -182,7 +186,8 @@ ProgramNode(0...689)( )] ), (562...565), - "X" + "X", + :X ), ModuleNode(568...651)( [], @@ -202,11 +207,13 @@ ProgramNode(0...689)( )] ), (630...633), - "Y" + "Y", + :Y )] ), (648...651), - "X" + "X", + :X ), CallNode(670...689)( nil, diff --git a/test/yarp/snapshots/seattlerb/class_comments.txt b/test/yarp/snapshots/seattlerb/class_comments.txt index c7a36379fbc0fc..1751e299291970 100644 --- a/test/yarp/snapshots/seattlerb/class_comments.txt +++ b/test/yarp/snapshots/seattlerb/class_comments.txt @@ -23,7 +23,8 @@ ProgramNode(19...71)( )] ), (68...71), - "X" + "X", + :X )] ) ) diff --git a/test/yarp/snapshots/seattlerb/defn_oneliner_eq2.txt b/test/yarp/snapshots/seattlerb/defn_oneliner_eq2.txt index db684a0b1049c1..43d13f27cb4bbf 100644 --- a/test/yarp/snapshots/seattlerb/defn_oneliner_eq2.txt +++ b/test/yarp/snapshots/seattlerb/defn_oneliner_eq2.txt @@ -31,7 +31,8 @@ ProgramNode(0...28)( )] ), (25...28), - "X" + "X", + :X )] ) ) diff --git a/test/yarp/snapshots/seattlerb/defs_oneliner_eq2.txt b/test/yarp/snapshots/seattlerb/defs_oneliner_eq2.txt index 793139ed5ef3e5..636a1fd66caad6 100644 --- a/test/yarp/snapshots/seattlerb/defs_oneliner_eq2.txt +++ b/test/yarp/snapshots/seattlerb/defs_oneliner_eq2.txt @@ -31,7 +31,8 @@ ProgramNode(0...33)( )] ), (30...33), - "X" + "X", + :X )] ) ) diff --git a/test/yarp/snapshots/seattlerb/magic_encoding_comment.txt b/test/yarp/snapshots/seattlerb/magic_encoding_comment.txt index b183b39ead718a..c231c841242423 100644 --- a/test/yarp/snapshots/seattlerb/magic_encoding_comment.txt +++ b/test/yarp/snapshots/seattlerb/magic_encoding_comment.txt @@ -31,7 +31,8 @@ ProgramNode(18...90)( )] ), (87...90), - "ExampleUTF8ClassNameVarietà" + "ExampleUTF8ClassNameVarietà", + :ExampleUTF8ClassNameVarietà )] ) ) diff --git a/test/yarp/snapshots/seattlerb/module_comments.txt b/test/yarp/snapshots/seattlerb/module_comments.txt index b384dad8e58eba..63019796ccd63d 100644 --- a/test/yarp/snapshots/seattlerb/module_comments.txt +++ b/test/yarp/snapshots/seattlerb/module_comments.txt @@ -21,7 +21,8 @@ ProgramNode(24...77)( )] ), (74...77), - "X" + "X", + :X )] ) ) diff --git a/test/yarp/snapshots/seattlerb/parse_line_heredoc_hardnewline.txt b/test/yarp/snapshots/seattlerb/parse_line_heredoc_hardnewline.txt index 5f4c3ec93d0690..c29b09012edb0a 100644 --- a/test/yarp/snapshots/seattlerb/parse_line_heredoc_hardnewline.txt +++ b/test/yarp/snapshots/seattlerb/parse_line_heredoc_hardnewline.txt @@ -19,7 +19,8 @@ ProgramNode(0...48)( nil, nil, (45...48), - "Foo" + "Foo", + :Foo )] ) ) diff --git a/test/yarp/snapshots/unparser/corpus/literal/class.txt b/test/yarp/snapshots/unparser/corpus/literal/class.txt index b4cca16f39b2c7..60de85cb90e6ef 100644 --- a/test/yarp/snapshots/unparser/corpus/literal/class.txt +++ b/test/yarp/snapshots/unparser/corpus/literal/class.txt @@ -9,7 +9,8 @@ ProgramNode(0...213)( nil, nil, (8...11), - "A" + "A", + :A ), SingletonClassNode(13...27)( [], @@ -41,7 +42,8 @@ ProgramNode(0...213)( nil, nil, (60...63), - "B" + "B", + :B ), ClassNode(65...82)( [], @@ -59,7 +61,8 @@ ProgramNode(0...213)( nil, nil, (79...82), - "C" + "C", + :C ), ClassNode(84...99)( [], @@ -69,7 +72,8 @@ ProgramNode(0...213)( ConstantReadNode(94...95)(:B), nil, (96...99), - "A" + "A", + :A ), ClassNode(101...119)( [], @@ -83,7 +87,8 @@ ProgramNode(0...213)( ), nil, (116...119), - "A" + "A", + :A ), ClassNode(121...142)( [], @@ -101,7 +106,8 @@ ProgramNode(0...213)( ), nil, (139...142), - "B" + "B", + :B ), ClassNode(144...198)( [], @@ -150,7 +156,8 @@ ProgramNode(0...213)( )] ), (195...198), - "A" + "A", + :A ), ClassNode(200...213)( [], @@ -164,7 +171,8 @@ ProgramNode(0...213)( nil, nil, (210...213), - "A" + "A", + :A )] ) ) diff --git a/test/yarp/snapshots/unparser/corpus/literal/if.txt b/test/yarp/snapshots/unparser/corpus/literal/if.txt index b25ada8a362906..0ab7b311635bab 100644 --- a/test/yarp/snapshots/unparser/corpus/literal/if.txt +++ b/test/yarp/snapshots/unparser/corpus/literal/if.txt @@ -81,7 +81,8 @@ ProgramNode(0...246)( )] ), (130...133), - "A" + "A", + :A ), ModuleNode(135...170)( [:foo], @@ -115,7 +116,8 @@ ProgramNode(0...246)( )] ), (167...170), - "B" + "B", + :B ), UnlessNode(171...197)( (171...177), diff --git a/test/yarp/snapshots/unparser/corpus/literal/module.txt b/test/yarp/snapshots/unparser/corpus/literal/module.txt index 8ec85333e206bd..d2dd0fa351b46f 100644 --- a/test/yarp/snapshots/unparser/corpus/literal/module.txt +++ b/test/yarp/snapshots/unparser/corpus/literal/module.txt @@ -7,7 +7,8 @@ ProgramNode(0...106)( ConstantReadNode(7...8)(:A), nil, (9...12), - "A" + "A", + :A ), ModuleNode(14...29)( [], @@ -19,7 +20,8 @@ ProgramNode(0...106)( ), nil, (26...29), - "B" + "B", + :B ), ModuleNode(31...49)( [], @@ -35,7 +37,8 @@ ProgramNode(0...106)( ), nil, (46...49), - "C" + "C", + :C ), ModuleNode(51...106)( [], @@ -82,7 +85,8 @@ ProgramNode(0...106)( )] ), (103...106), - "A" + "A", + :A )] ) ) diff --git a/test/yarp/snapshots/unparser/corpus/literal/send.txt b/test/yarp/snapshots/unparser/corpus/literal/send.txt index 68eb44288918c3..ff90dc52cdeb1d 100644 --- a/test/yarp/snapshots/unparser/corpus/literal/send.txt +++ b/test/yarp/snapshots/unparser/corpus/literal/send.txt @@ -38,7 +38,8 @@ ProgramNode(0...999)( )] ), (32...35), - "A" + "A", + :A ), ModuleNode(37...73)( [:local], @@ -65,7 +66,8 @@ ProgramNode(0...999)( )] ), (70...73), - "A" + "A", + :A ), CallNode(74...89)( ClassNode(74...85)( @@ -76,7 +78,8 @@ ProgramNode(0...999)( nil, nil, (82...85), - "A" + "A", + :A ), (85...86), (86...89), @@ -94,7 +97,8 @@ ProgramNode(0...999)( ConstantReadNode(97...98)(:A), nil, (99...102), - "A" + "A", + :A ), (102...103), (103...106), diff --git a/test/yarp/snapshots/unparser/corpus/literal/while.txt b/test/yarp/snapshots/unparser/corpus/literal/while.txt index 6bddfff409f741..aed21abefc22fa 100644 --- a/test/yarp/snapshots/unparser/corpus/literal/while.txt +++ b/test/yarp/snapshots/unparser/corpus/literal/while.txt @@ -64,7 +64,8 @@ ProgramNode(0...620)( )] ), (65...68), - "A" + "A", + :A ), DefNode(70...110)( (74...77), @@ -159,7 +160,8 @@ ProgramNode(0...620)( )] ), (143...146), - "A" + "A", + :A ), ModuleNode(148...182)( [:foo], @@ -193,7 +195,8 @@ ProgramNode(0...620)( )] ), (179...182), - "A" + "A", + :A ), ModuleNode(184...228)( [:foo], @@ -237,7 +240,8 @@ ProgramNode(0...620)( )] ), (225...228), - "A" + "A", + :A ), ModuleNode(230...299)( [], @@ -312,7 +316,8 @@ ProgramNode(0...620)( )] ), (296...299), - "A" + "A", + :A ), ModuleNode(301...370)( [], @@ -377,7 +382,8 @@ ProgramNode(0...620)( )] ), (367...370), - "A" + "A", + :A ), LocalVariableWriteNode(371...402)( :x, diff --git a/test/yarp/snapshots/unparser/corpus/semantic/while.txt b/test/yarp/snapshots/unparser/corpus/semantic/while.txt index de7f2b750dbb14..7426fac71d37a6 100644 --- a/test/yarp/snapshots/unparser/corpus/semantic/while.txt +++ b/test/yarp/snapshots/unparser/corpus/semantic/while.txt @@ -186,7 +186,8 @@ ProgramNode(0...188)( )] ), (185...188), - "A" + "A", + :A )] ) ) diff --git a/test/yarp/snapshots/while.txt b/test/yarp/snapshots/while.txt index e85b5e667263d5..c04963bf9b6db7 100644 --- a/test/yarp/snapshots/while.txt +++ b/test/yarp/snapshots/while.txt @@ -139,7 +139,8 @@ ProgramNode(0...314)( )] ), (195...198), - "Foo" + "Foo", + :Foo ), StatementsNode(200...205)([BreakNode(200...205)(nil, (200...205))]), 0 diff --git a/test/yarp/snapshots/whitequark/class.txt b/test/yarp/snapshots/whitequark/class.txt index 217b8011f00ec6..ad181664b58434 100644 --- a/test/yarp/snapshots/whitequark/class.txt +++ b/test/yarp/snapshots/whitequark/class.txt @@ -9,7 +9,8 @@ ProgramNode(0...29)( nil, nil, (10...13), - "Foo" + "Foo", + :Foo ), ClassNode(15...29)( [], @@ -19,7 +20,8 @@ ProgramNode(0...29)( nil, nil, (26...29), - "Foo" + "Foo", + :Foo )] ) ) diff --git a/test/yarp/snapshots/whitequark/class_definition_in_while_cond.txt b/test/yarp/snapshots/whitequark/class_definition_in_while_cond.txt index d14e3907f0288d..292b0b79880f86 100644 --- a/test/yarp/snapshots/whitequark/class_definition_in_while_cond.txt +++ b/test/yarp/snapshots/whitequark/class_definition_in_while_cond.txt @@ -88,7 +88,8 @@ ProgramNode(0...197)( )] ), (136...139), - "Foo" + "Foo", + :Foo ), StatementsNode(141...146)([BreakNode(141...146)(nil, (141...146))]), 0 @@ -116,7 +117,8 @@ ProgramNode(0...197)( )] ), (182...185), - "Foo" + "Foo", + :Foo ), StatementsNode(187...192)([BreakNode(187...192)(nil, (187...192))]), 0 diff --git a/test/yarp/snapshots/whitequark/class_super.txt b/test/yarp/snapshots/whitequark/class_super.txt index 4a77a4213c650c..6ebbb1364c12a6 100644 --- a/test/yarp/snapshots/whitequark/class_super.txt +++ b/test/yarp/snapshots/whitequark/class_super.txt @@ -9,7 +9,8 @@ ProgramNode(0...20)( ConstantReadNode(12...15)(:Bar), nil, (17...20), - "Foo" + "Foo", + :Foo )] ) ) diff --git a/test/yarp/snapshots/whitequark/class_super_label.txt b/test/yarp/snapshots/whitequark/class_super_label.txt index 10d4b28cea343b..a53dac8f2c32ee 100644 --- a/test/yarp/snapshots/whitequark/class_super_label.txt +++ b/test/yarp/snapshots/whitequark/class_super_label.txt @@ -21,7 +21,8 @@ ProgramNode(0...20)( ), nil, (17...20), - "Foo" + "Foo", + :Foo )] ) ) diff --git a/test/yarp/snapshots/whitequark/cpath.txt b/test/yarp/snapshots/whitequark/cpath.txt index 1c3d4e6c3065e4..3df789b5caa1ee 100644 --- a/test/yarp/snapshots/whitequark/cpath.txt +++ b/test/yarp/snapshots/whitequark/cpath.txt @@ -7,7 +7,8 @@ ProgramNode(0...39)( ConstantPathNode(7...12)(nil, ConstantReadNode(9...12)(:Foo), (7...9)), nil, (14...17), - "Foo" + "Foo", + :Foo ), ModuleNode(19...39)( [], @@ -19,7 +20,8 @@ ProgramNode(0...39)( ), nil, (36...39), - "Foo" + "Foo", + :Foo )] ) ) diff --git a/test/yarp/snapshots/whitequark/if_while_after_class__since_32.txt b/test/yarp/snapshots/whitequark/if_while_after_class__since_32.txt index e1e4419b1c88ea..a088237a852b35 100644 --- a/test/yarp/snapshots/whitequark/if_while_after_class__since_32.txt +++ b/test/yarp/snapshots/whitequark/if_while_after_class__since_32.txt @@ -19,7 +19,8 @@ ProgramNode(0...178)( nil, nil, (35...38), - "Kernel" + "Kernel", + :Kernel ), ClassNode(40...87)( [], @@ -44,7 +45,8 @@ ProgramNode(0...178)( nil, nil, (84...87), - "Kernel" + "Kernel", + :Kernel ), ModuleNode(89...128)( [], @@ -62,7 +64,8 @@ ProgramNode(0...178)( ), nil, (125...128), - "Kernel" + "Kernel", + :Kernel ), ModuleNode(130...178)( [], @@ -87,7 +90,8 @@ ProgramNode(0...178)( ), nil, (175...178), - "Kernel" + "Kernel", + :Kernel )] ) ) diff --git a/test/yarp/snapshots/whitequark/module.txt b/test/yarp/snapshots/whitequark/module.txt index 395bc6136652e7..9d3a1148f37708 100644 --- a/test/yarp/snapshots/whitequark/module.txt +++ b/test/yarp/snapshots/whitequark/module.txt @@ -7,7 +7,8 @@ ProgramNode(0...15)( ConstantReadNode(7...10)(:Foo), nil, (12...15), - "Foo" + "Foo", + :Foo )] ) ) diff --git a/test/yarp/snapshots/whitequark/numparam_outside_block.txt b/test/yarp/snapshots/whitequark/numparam_outside_block.txt index c3972dbf9b0412..9ef6b0cfbbe575 100644 --- a/test/yarp/snapshots/whitequark/numparam_outside_block.txt +++ b/test/yarp/snapshots/whitequark/numparam_outside_block.txt @@ -22,7 +22,8 @@ ProgramNode(0...83)( [CallNode(36...38)(nil, nil, (36...38), nil, nil, nil, nil, 2, "_1")] ), (40...43), - "A" + "A", + :A ), DefNode(45...64)( (54...55), @@ -47,7 +48,8 @@ ProgramNode(0...83)( [CallNode(76...78)(nil, nil, (76...78), nil, nil, nil, nil, 2, "_1")] ), (80...83), - "A" + "A", + :A )] ) ) diff --git a/test/yarp/snapshots/whitequark/parser_bug_490.txt b/test/yarp/snapshots/whitequark/parser_bug_490.txt index ca6ab1a69d41e8..680b5fe146dda9 100644 --- a/test/yarp/snapshots/whitequark/parser_bug_490.txt +++ b/test/yarp/snapshots/whitequark/parser_bug_490.txt @@ -49,7 +49,8 @@ ProgramNode(0...132)( nil, nil, (72...75), - "C" + "C", + :C )] ), (77...80) @@ -80,7 +81,8 @@ ProgramNode(0...132)( ConstantReadNode(116...117)(:M), nil, (119...122), - "M" + "M", + :M )] ), (124...127) diff --git a/test/yarp/snapshots/whitequark/parser_bug_518.txt b/test/yarp/snapshots/whitequark/parser_bug_518.txt index dd831ac54d3110..0f92f9e95bddaf 100644 --- a/test/yarp/snapshots/whitequark/parser_bug_518.txt +++ b/test/yarp/snapshots/whitequark/parser_bug_518.txt @@ -9,7 +9,8 @@ ProgramNode(0...15)( ConstantReadNode(10...11)(:B), nil, (12...15), - "A" + "A", + :A )] ) ) diff --git a/yarp/config.yml b/yarp/config.yml index a8841bed4c64a1..354c90abcdfc7f 100644 --- a/yarp/config.yml +++ b/yarp/config.yml @@ -780,6 +780,8 @@ nodes: type: location - name: name type: string + - name: name_constant + type: constant comment: | Represents a class declaration involving the `class` keyword. @@ -1738,6 +1740,8 @@ nodes: type: location - name: name type: string + - name: name_constant + type: constant comment: | Represents a module declaration involving the `module` keyword. diff --git a/yarp/yarp.c b/yarp/yarp.c index df1cec913ce5bb..78b3907308ed1a 100644 --- a/yarp/yarp.c +++ b/yarp/yarp.c @@ -1660,7 +1660,8 @@ yp_class_node_create(yp_parser_t *parser, yp_constant_id_list_t *locals, const y .superclass = superclass, .body = body, .end_keyword_loc = YP_LOCATION_TOKEN_VALUE(end_keyword), - .name = YP_EMPTY_STRING + .name = YP_EMPTY_STRING, + .name_constant = yp_parser_constant_id_token(parser, name) }; yp_string_shared_init(&node->name, name->start, name->end); @@ -3310,7 +3311,8 @@ yp_module_node_create(yp_parser_t *parser, yp_constant_id_list_t *locals, const .constant_path = constant_path, .body = body, .end_keyword_loc = YP_LOCATION_TOKEN_VALUE(end_keyword), - .name = YP_EMPTY_STRING + .name = YP_EMPTY_STRING, + .name_constant = yp_parser_constant_id_token(parser, name) }; yp_string_shared_init(&node->name, name->start, name->end); From ae41bdac1ea96de1d75ddf9a4a0ca3dc827a501b Mon Sep 17 00:00:00 2001 From: Jemma Issroff Date: Wed, 6 Sep 2023 10:28:29 -0400 Subject: [PATCH 84/95] [YARP] Use constant_id lookups where possible (#8374) This commit extracts a `yp_constant_id_lookup` method and uses yp_constant_id_lookup where possible --- yarp/yarp_compiler.c | 63 ++++++++++++++++++++++++++++---------------- 1 file changed, 40 insertions(+), 23 deletions(-) diff --git a/yarp/yarp_compiler.c b/yarp/yarp_compiler.c index 59a1444f654305..a074a1e525eea0 100644 --- a/yarp/yarp_compiler.c +++ b/yarp/yarp_compiler.c @@ -359,6 +359,18 @@ yp_lookup_local_index_with_depth(rb_iseq_t *iseq, yp_compile_context_t *compile_ return yp_lookup_local_index(iseq, compile_context, constant_id); } +// This returns the CRuby ID which maps to the yp_constant_id_t +// +// Constant_ids in YARP are indexes of the constants in YARP's constant pool. +// We add a constants mapping on the compile_context which is a mapping from +// these constant_id indexes to the CRuby IDs that they represent. +// This helper method allows easy access to those IDs +static ID +yp_constant_id_lookup(yp_compile_context_t *compile_context, yp_constant_id_t constant_id) +{ + return compile_context->constants[constant_id - 1]; +} + static rb_iseq_t * yp_new_child_iseq(rb_iseq_t *iseq, yp_scope_node_t * node, yp_parser_t *parser, VALUE name, const rb_iseq_t *parent, enum rb_iseq_type type, int line_no) @@ -616,7 +628,7 @@ yp_compile_node(rb_iseq_t *iseq, const yp_node_t *node, LINK_ANCHOR *const ret, LABEL *end_label = NEW_LABEL(lineno); - ID class_variable_name_id = compile_context->constants[class_variable_and_write_node->name - 1]; + ID class_variable_name_id = yp_constant_id_lookup(compile_context, class_variable_and_write_node->name); VALUE class_variable_name_val = ID2SYM(class_variable_name_id); ADD_INSN2(ret, &dummy_line_node, getclassvariable, @@ -649,7 +661,7 @@ yp_compile_node(rb_iseq_t *iseq, const yp_node_t *node, LINK_ANCHOR *const ret, case YP_NODE_CLASS_VARIABLE_OPERATOR_WRITE_NODE: { yp_class_variable_operator_write_node_t *class_variable_operator_write_node = (yp_class_variable_operator_write_node_t*) node; - ID class_variable_name_id = compile_context->constants[class_variable_operator_write_node->name - 1]; + ID class_variable_name_id = yp_constant_id_lookup(compile_context, class_variable_operator_write_node->name); VALUE class_variable_name_val = ID2SYM(class_variable_name_id); ADD_INSN2(ret, &dummy_line_node, getclassvariable, @@ -657,7 +669,7 @@ yp_compile_node(rb_iseq_t *iseq, const yp_node_t *node, LINK_ANCHOR *const ret, get_cvar_ic_value(iseq, class_variable_name_id)); yp_compile_node(iseq, class_variable_operator_write_node->value, ret, src, false, compile_context); - ID method_id = compile_context->constants[class_variable_operator_write_node->operator - 1]; + ID method_id = yp_constant_id_lookup(compile_context, class_variable_operator_write_node->operator); int flags = VM_CALL_ARGS_SIMPLE; ADD_SEND_WITH_FLAG(ret, &dummy_line_node, method_id, INT2NUM(1), INT2FIX(flags)); @@ -677,7 +689,7 @@ yp_compile_node(rb_iseq_t *iseq, const yp_node_t *node, LINK_ANCHOR *const ret, LABEL *end_label = NEW_LABEL(lineno); - ID class_variable_name_id = compile_context->constants[class_variable_or_write_node->name - 1]; + ID class_variable_name_id = yp_constant_id_lookup(compile_context, class_variable_or_write_node->name); VALUE class_variable_name_val = ID2SYM(class_variable_name_id); ADD_INSN2(ret, &dummy_line_node, getclassvariable, @@ -709,7 +721,8 @@ yp_compile_node(rb_iseq_t *iseq, const yp_node_t *node, LINK_ANCHOR *const ret, } case YP_NODE_CLASS_VARIABLE_READ_NODE: { if (!popped) { - ID cvar_name = parse_node_symbol((yp_node_t *)node); + yp_class_variable_read_node_t *class_variable_read_node = (yp_class_variable_read_node_t *) node; + ID cvar_name = yp_constant_id_lookup(compile_context, class_variable_read_node->name); ADD_INSN2( ret, &dummy_line_node, @@ -727,7 +740,7 @@ yp_compile_node(rb_iseq_t *iseq, const yp_node_t *node, LINK_ANCHOR *const ret, ADD_INSN(ret, &dummy_line_node, dup); } - ID cvar_name = parse_location_symbol(&write_node->name_loc); + ID cvar_name = yp_constant_id_lookup(compile_context, write_node->name); ADD_INSN2(ret, &dummy_line_node, setclassvariable, ID2SYM(cvar_name), get_cvar_ic_value(iseq, cvar_name)); return; } @@ -805,7 +818,7 @@ yp_compile_node(rb_iseq_t *iseq, const yp_node_t *node, LINK_ANCHOR *const ret, ADD_INSN1(ret, &dummy_line_node, getconstant, ID2SYM(constant_name)); yp_compile_node(iseq, constant_operator_write_node->value, ret, src, false, compile_context); - ID method_id = compile_context->constants[constant_operator_write_node->operator - 1]; + ID method_id = yp_constant_id_lookup(compile_context, constant_operator_write_node->operator); int flags = VM_CALL_ARGS_SIMPLE; ADD_SEND_WITH_FLAG(ret, &dummy_line_node, method_id, INT2NUM(1), INT2FIX(flags)); @@ -968,7 +981,8 @@ yp_compile_node(rb_iseq_t *iseq, const yp_node_t *node, LINK_ANCHOR *const ret, LABEL *end_label = NEW_LABEL(lineno); - VALUE global_variable_name = ID2SYM(parse_location_symbol(&global_variable_and_write_node->name_loc)); + VALUE global_variable_name = ID2SYM(yp_constant_id_lookup(compile_context, global_variable_and_write_node->name)); + ADD_INSN1(ret, &dummy_line_node, getglobal, global_variable_name); if (!popped) { @@ -995,11 +1009,11 @@ yp_compile_node(rb_iseq_t *iseq, const yp_node_t *node, LINK_ANCHOR *const ret, case YP_NODE_GLOBAL_VARIABLE_OPERATOR_WRITE_NODE: { yp_global_variable_operator_write_node_t *global_variable_operator_write_node = (yp_global_variable_operator_write_node_t*) node; - ID global_variable_name = parse_location_symbol(&global_variable_operator_write_node->name_loc); - ADD_INSN1(ret, &dummy_line_node, getglobal, ID2SYM(global_variable_name)); + VALUE global_variable_name = ID2SYM(yp_constant_id_lookup(compile_context, global_variable_operator_write_node->name)); + ADD_INSN1(ret, &dummy_line_node, getglobal, global_variable_name); yp_compile_node(iseq, global_variable_operator_write_node->value, ret, src, false, compile_context); - ID method_id = compile_context->constants[global_variable_operator_write_node->operator - 1]; + ID method_id = yp_constant_id_lookup(compile_context, global_variable_operator_write_node->operator); int flags = VM_CALL_ARGS_SIMPLE; ADD_SEND_WITH_FLAG(ret, &dummy_line_node, method_id, INT2NUM(1), INT2FIX(flags)); @@ -1009,7 +1023,7 @@ yp_compile_node(rb_iseq_t *iseq, const yp_node_t *node, LINK_ANCHOR *const ret, ADD_INSN(ret, &dummy_line_node, dup); } - ADD_INSN1(ret, &dummy_line_node, setglobal, ID2SYM(global_variable_name)); + ADD_INSN1(ret, &dummy_line_node, setglobal, global_variable_name); return; } @@ -1020,7 +1034,7 @@ yp_compile_node(rb_iseq_t *iseq, const yp_node_t *node, LINK_ANCHOR *const ret, LABEL *end_label = NEW_LABEL(lineno); ADD_INSN(ret, &dummy_line_node, putnil); - VALUE global_variable_name = ID2SYM(parse_location_symbol(&global_variable_or_write_node->name_loc)); + VALUE global_variable_name = ID2SYM(yp_constant_id_lookup(compile_context, global_variable_or_write_node->name)); ADD_INSN3(ret, &dummy_line_node, defined, INT2FIX(DEFINED_GVAR), global_variable_name, Qtrue); @@ -1051,7 +1065,8 @@ yp_compile_node(rb_iseq_t *iseq, const yp_node_t *node, LINK_ANCHOR *const ret, return; } case YP_NODE_GLOBAL_VARIABLE_READ_NODE: { - VALUE global_variable_name = ID2SYM(parse_location_symbol((yp_location_t *)(&node->location))); + yp_global_variable_read_node_t *global_variable_read_node = (yp_global_variable_read_node_t *)node; + VALUE global_variable_name = ID2SYM(yp_constant_id_lookup(compile_context, global_variable_read_node->name)); ADD_INSN1(ret, &dummy_line_node, getglobal, global_variable_name); if (popped) { ADD_INSN(ret, &dummy_line_node, pop); @@ -1064,7 +1079,7 @@ yp_compile_node(rb_iseq_t *iseq, const yp_node_t *node, LINK_ANCHOR *const ret, if (!popped) { ADD_INSN(ret, &dummy_line_node, dup); } - ID ivar_name = parse_location_symbol(&write_node->name_loc); + ID ivar_name = yp_constant_id_lookup(compile_context, write_node->name); ADD_INSN1(ret, &dummy_line_node, setglobal, ID2SYM(ivar_name)); return; } @@ -1116,7 +1131,8 @@ yp_compile_node(rb_iseq_t *iseq, const yp_node_t *node, LINK_ANCHOR *const ret, LABEL *end_label = NEW_LABEL(lineno); - ID instance_variable_name_id = compile_context->constants[instance_variable_and_write_node->name - 1]; + ID instance_variable_name_id = yp_constant_id_lookup(compile_context, instance_variable_and_write_node->name); + VALUE instance_variable_name_val = ID2SYM(instance_variable_name_id); ADD_INSN2(ret, &dummy_line_node, getinstancevariable, @@ -1149,7 +1165,7 @@ yp_compile_node(rb_iseq_t *iseq, const yp_node_t *node, LINK_ANCHOR *const ret, case YP_NODE_INSTANCE_VARIABLE_OPERATOR_WRITE_NODE: { yp_instance_variable_operator_write_node_t *instance_variable_operator_write_node = (yp_instance_variable_operator_write_node_t*) node; - ID instance_variable_name_id = compile_context->constants[instance_variable_operator_write_node->name - 1]; + ID instance_variable_name_id = yp_constant_id_lookup(compile_context, instance_variable_operator_write_node->name); VALUE instance_variable_name_val = ID2SYM(instance_variable_name_id); ADD_INSN2(ret, &dummy_line_node, getinstancevariable, @@ -1157,7 +1173,7 @@ yp_compile_node(rb_iseq_t *iseq, const yp_node_t *node, LINK_ANCHOR *const ret, get_ivar_ic_value(iseq, instance_variable_name_id)); yp_compile_node(iseq, instance_variable_operator_write_node->value, ret, src, false, compile_context); - ID method_id = compile_context->constants[instance_variable_operator_write_node->operator - 1]; + ID method_id = yp_constant_id_lookup(compile_context, instance_variable_operator_write_node->operator); int flags = VM_CALL_ARGS_SIMPLE; ADD_SEND_WITH_FLAG(ret, &dummy_line_node, method_id, INT2NUM(1), INT2FIX(flags)); @@ -1177,7 +1193,7 @@ yp_compile_node(rb_iseq_t *iseq, const yp_node_t *node, LINK_ANCHOR *const ret, LABEL *end_label = NEW_LABEL(lineno); - ID instance_variable_name_id = compile_context->constants[instance_variable_or_write_node->name - 1]; + ID instance_variable_name_id = yp_constant_id_lookup(compile_context, instance_variable_or_write_node->name); VALUE instance_variable_name_val = ID2SYM(instance_variable_name_id); ADD_INSN2(ret, &dummy_line_node, getinstancevariable, @@ -1210,7 +1226,8 @@ yp_compile_node(rb_iseq_t *iseq, const yp_node_t *node, LINK_ANCHOR *const ret, } case YP_NODE_INSTANCE_VARIABLE_READ_NODE: { if (!popped) { - ID ivar_name = parse_node_symbol((yp_node_t *)node); + yp_instance_variable_read_node_t *instance_variable_read_node = (yp_instance_variable_read_node_t *) node; + ID ivar_name = yp_constant_id_lookup(compile_context, instance_variable_read_node->name); ADD_INSN2(ret, &dummy_line_node, getinstancevariable, ID2SYM(ivar_name), get_ivar_ic_value(iseq, ivar_name)); @@ -1225,7 +1242,7 @@ yp_compile_node(rb_iseq_t *iseq, const yp_node_t *node, LINK_ANCHOR *const ret, ADD_INSN(ret, &dummy_line_node, dup); } - ID ivar_name = parse_location_symbol(&write_node->name_loc); + ID ivar_name = yp_constant_id_lookup(compile_context, write_node->name); ADD_INSN2(ret, &dummy_line_node, setinstancevariable, ID2SYM(ivar_name), get_ivar_ic_value(iseq, ivar_name)); @@ -1365,7 +1382,7 @@ yp_compile_node(rb_iseq_t *iseq, const yp_node_t *node, LINK_ANCHOR *const ret, ADD_GETLOCAL(ret, &dummy_line_node, local_index, depth); yp_compile_node(iseq, local_variable_operator_write_node->value, ret, src, false, compile_context); - ID method_id = compile_context->constants[local_variable_operator_write_node->operator - 1]; + ID method_id = yp_constant_id_lookup(compile_context, local_variable_operator_write_node->operator); int flags = VM_CALL_ARGS_SIMPLE | VM_CALL_FCALL | VM_CALL_VCALL; ADD_SEND_WITH_FLAG(ret, &dummy_line_node, method_id, INT2NUM(1), INT2FIX(flags)); @@ -1645,7 +1662,7 @@ yp_compile_node(rb_iseq_t *iseq, const yp_node_t *node, LINK_ANCHOR *const ret, // Calculate the local index for all locals for (size_t i = 0; i < size; i++) { yp_constant_id_t constant_id = locals.ids[i]; - ID local = compile_context->constants[constant_id - 1]; + ID local = yp_constant_id_lookup(compile_context, constant_id); tbl->ids[i] = local; st_insert(index_lookup_table, constant_id, i); } From a52ac350ccb8eb2ab394548844ffe681f9f02d0f Mon Sep 17 00:00:00 2001 From: Kevin Newton Date: Wed, 6 Sep 2023 10:30:47 -0400 Subject: [PATCH 85/95] [ruby/yarp] Fix assert_raises in YARP https://github.com/ruby/yarp/commit/8f8f3530aa --- test/yarp/pattern_test.rb | 18 +++++++++--------- test/yarp/test_helper.rb | 4 ++++ 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/test/yarp/pattern_test.rb b/test/yarp/pattern_test.rb index 76e6e3e7885a18..d34fe84458f206 100644 --- a/test/yarp/pattern_test.rb +++ b/test/yarp/pattern_test.rb @@ -3,37 +3,37 @@ require_relative "test_helper" module YARP - class PatternTest < Test::Unit::TestCase + class PatternTest < TestCase def test_invalid_syntax - assert_raises(Pattern::CompilationError) { scan("", "<>") } + assert_raise(Pattern::CompilationError) { scan("", "<>") } end def test_invalid_constant - assert_raises(Pattern::CompilationError) { scan("", "Foo") } + assert_raise(Pattern::CompilationError) { scan("", "Foo") } end def test_invalid_nested_constant - assert_raises(Pattern::CompilationError) { scan("", "Foo::Bar") } + assert_raise(Pattern::CompilationError) { scan("", "Foo::Bar") } end def test_regexp_with_interpolation - assert_raises(Pattern::CompilationError) { scan("", "/\#{foo}/") } + assert_raise(Pattern::CompilationError) { scan("", "/\#{foo}/") } end def test_string_with_interpolation - assert_raises(Pattern::CompilationError) { scan("", '"#{foo}"') } + assert_raise(Pattern::CompilationError) { scan("", '"#{foo}"') } end def test_symbol_with_interpolation - assert_raises(Pattern::CompilationError) { scan("", ":\"\#{foo}\"") } + assert_raise(Pattern::CompilationError) { scan("", ":\"\#{foo}\"") } end def test_invalid_node - assert_raises(Pattern::CompilationError) { scan("", "IntegerNode[^foo]") } + assert_raise(Pattern::CompilationError) { scan("", "IntegerNode[^foo]") } end def test_self - assert_raises(Pattern::CompilationError) { scan("", "self") } + assert_raise(Pattern::CompilationError) { scan("", "self") } end def test_array_pattern_no_constant diff --git a/test/yarp/test_helper.rb b/test/yarp/test_helper.rb index b79adf4b166e91..086b73dd563a6c 100644 --- a/test/yarp/test_helper.rb +++ b/test/yarp/test_helper.rb @@ -19,6 +19,10 @@ module YARP class TestCase < ::Test::Unit::TestCase private + def assert_raises(*args, &block) + raise "Use assert_raise instead" + end + def assert_equal_nodes(expected, actual, compare_location: true, parent: nil) assert_equal expected.class, actual.class From b3b57f70cc1ee6f40ff10b2abaa51889abce2331 Mon Sep 17 00:00:00 2001 From: Peter Zhu Date: Wed, 6 Sep 2023 10:27:57 -0400 Subject: [PATCH 86/95] Fix missing write barrier in iseq instruction list There's a missing write barrier for operands in the iseq instruction list, which can cause crashes. It can be reproduced when Ruby is compiled with `-DRUBY_DEBUG_ENV=1`. Using the following command: ``` RUBY_GC_HEAP_OLDOBJECT_LIMIT_FACTOR=0 RUBY_DEBUG=gc_stress ruby -w --disable=gems -Itool/lib -W0 test.rb ``` The following script crashes: ``` require "test/unit" ``` --- compile.c | 53 ++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 36 insertions(+), 17 deletions(-) diff --git a/compile.c b/compile.c index 4d344fff9c6aca..a165690597938a 100644 --- a/compile.c +++ b/compile.c @@ -1282,6 +1282,32 @@ new_adjust_body(rb_iseq_t *iseq, LABEL *label, int line) return adjust; } +static void +iseq_insn_each_markable_object(INSN *insn, void (*func)(VALUE *, VALUE), VALUE data) +{ + const char *types = insn_op_types(insn->insn_id); + for (int j = 0; types[j]; j++) { + char type = types[j]; + switch (type) { + case TS_CDHASH: + case TS_ISEQ: + case TS_VALUE: + case TS_IC: // constant path array + case TS_CALLDATA: // ci is stored. + func(&OPERAND_AT(insn, j), data); + break; + default: + break; + } + } +} + +static void +iseq_insn_each_object_write_barrier(VALUE *obj_ptr, VALUE iseq) +{ + RB_OBJ_WRITTEN(iseq, Qundef, *obj_ptr); +} + static INSN * new_insn_core(rb_iseq_t *iseq, const NODE *line_node, int insn_id, int argc, VALUE *argv) @@ -1299,6 +1325,9 @@ new_insn_core(rb_iseq_t *iseq, const NODE *line_node, iobj->operands = argv; iobj->operand_size = argc; iobj->sc_state = 0; + + iseq_insn_each_markable_object(iobj, iseq_insn_each_object_write_barrier, (VALUE)iseq); + return iobj; } @@ -10735,6 +10764,12 @@ iseq_build_kw(rb_iseq_t *iseq, VALUE params, VALUE keywords) return keyword; } +static void +iseq_insn_each_object_mark_and_move(VALUE *obj_ptr, VALUE _) +{ + rb_gc_mark_and_move(obj_ptr); +} + void rb_iseq_mark_and_move_insn_storage(struct iseq_compile_data_storage *storage) { @@ -10761,23 +10796,7 @@ rb_iseq_mark_and_move_insn_storage(struct iseq_compile_data_storage *storage) iobj = (INSN *)&storage->buff[pos]; if (iobj->operands) { - int j; - const char *types = insn_op_types(iobj->insn_id); - - for (j = 0; types[j]; j++) { - char type = types[j]; - switch (type) { - case TS_CDHASH: - case TS_ISEQ: - case TS_VALUE: - case TS_IC: // constant path array - case TS_CALLDATA: // ci is stored. - rb_gc_mark_and_move(&OPERAND_AT(iobj, j)); - break; - default: - break; - } - } + iseq_insn_each_markable_object(iobj, iseq_insn_each_object_mark_and_move, (VALUE)0); } pos += (int)size; } From 1d4d9a016a5e38d07cff7581c0bf82df784e5617 Mon Sep 17 00:00:00 2001 From: Jemma Issroff Date: Wed, 6 Sep 2023 12:19:23 -0400 Subject: [PATCH 87/95] [YARP] ClassNode and ModuleNode use name_constant (#8384) --- yarp/yarp_compiler.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/yarp/yarp_compiler.c b/yarp/yarp_compiler.c index a074a1e525eea0..10ef6a1e8c4d9f 100644 --- a/yarp/yarp_compiler.c +++ b/yarp/yarp_compiler.c @@ -597,7 +597,7 @@ yp_compile_node(rb_iseq_t *iseq, const yp_node_t *node, LINK_ANCHOR *const ret, yp_scope_node_t scope_node; yp_scope_node_init((yp_node_t *)class_node, &scope_node); - ID class_id = parse_string_symbol(&class_node->name); + ID class_id = yp_constant_id_lookup(compile_context, class_node->name_constant); VALUE class_name = rb_str_freeze(rb_sprintf("", rb_id2str(class_id))); @@ -1463,7 +1463,7 @@ yp_compile_node(rb_iseq_t *iseq, const yp_node_t *node, LINK_ANCHOR *const ret, yp_scope_node_t scope_node; yp_scope_node_init((yp_node_t *)module_node, &scope_node); - ID module_id = parse_string_symbol(&module_node->name); + ID module_id = yp_constant_id_lookup(compile_context, module_node->name_constant); VALUE module_name = rb_str_freeze(rb_sprintf("", rb_id2str(module_id))); const rb_iseq_t *module_iseq = NEW_CHILD_ISEQ(&scope_node, module_name, ISEQ_TYPE_CLASS, lineno); From dee383b2625187ee2e9d27799aa83c2afe91caa2 Mon Sep 17 00:00:00 2001 From: Kevin Newton Date: Wed, 6 Sep 2023 12:19:38 -0400 Subject: [PATCH 88/95] [ruby/yarp] Constants on classes and modules (https://github.com/ruby/yarp/pull/1409) https://github.com/ruby/yarp/commit/0a11ec579f --- test/yarp/errors_test.rb | 14 +++++++------- test/yarp/snapshots/classes.txt | 14 +++++++------- test/yarp/snapshots/method_calls.txt | 4 ++-- test/yarp/snapshots/modules.txt | 12 ++++++------ .../snapshots/seattlerb/TestRubyParserShared.txt | 14 +++++++------- test/yarp/snapshots/seattlerb/class_comments.txt | 2 +- .../snapshots/seattlerb/defn_oneliner_eq2.txt | 2 +- .../snapshots/seattlerb/defs_oneliner_eq2.txt | 2 +- .../seattlerb/magic_encoding_comment.txt | 2 +- .../yarp/snapshots/seattlerb/module_comments.txt | 2 +- .../seattlerb/parse_line_heredoc_hardnewline.txt | 2 +- .../snapshots/unparser/corpus/literal/class.txt | 16 ++++++++-------- .../snapshots/unparser/corpus/literal/if.txt | 4 ++-- .../snapshots/unparser/corpus/literal/module.txt | 8 ++++---- .../snapshots/unparser/corpus/literal/send.txt | 8 ++++---- .../snapshots/unparser/corpus/literal/while.txt | 12 ++++++------ .../snapshots/unparser/corpus/semantic/while.txt | 2 +- test/yarp/snapshots/while.txt | 2 +- test/yarp/snapshots/whitequark/class.txt | 4 ++-- .../class_definition_in_while_cond.txt | 4 ++-- test/yarp/snapshots/whitequark/class_super.txt | 2 +- .../snapshots/whitequark/class_super_label.txt | 2 +- test/yarp/snapshots/whitequark/cpath.txt | 4 ++-- .../if_while_after_class__since_32.txt | 8 ++++---- test/yarp/snapshots/whitequark/module.txt | 2 +- .../whitequark/numparam_outside_block.txt | 4 ++-- .../yarp/snapshots/whitequark/parser_bug_490.txt | 4 ++-- .../yarp/snapshots/whitequark/parser_bug_518.txt | 2 +- yarp/config.yml | 4 ++-- yarp/yarp.c | 12 ++++++------ 30 files changed, 87 insertions(+), 87 deletions(-) diff --git a/test/yarp/errors_test.rb b/test/yarp/errors_test.rb index f5064ba70f2b63..aa39982d22119e 100644 --- a/test/yarp/errors_test.rb +++ b/test/yarp/errors_test.rb @@ -19,10 +19,10 @@ def test_module_name_recoverable Location(), ConstantReadNode(:Parent), StatementsNode( - [ModuleNode([], Location(), MissingNode(), nil, Location(), "", :"")] + [ModuleNode([], Location(), MissingNode(), nil, Location(), :"", :"")] ), Location(), - "Parent", + :Parent, :Parent ) @@ -394,7 +394,7 @@ def test_module_definition_in_method_body Location(), nil, nil, - StatementsNode([ModuleNode([], Location(), ConstantReadNode(:A), nil, Location(), "A", :A)]), + StatementsNode([ModuleNode([], Location(), ConstantReadNode(:A), nil, Location(), :A, :A)]), [], Location(), nil, @@ -425,7 +425,7 @@ def test_module_definition_in_method_body_within_block BlockNode( [], nil, - StatementsNode([ModuleNode([], Location(), ConstantReadNode(:Foo), nil, Location(), "Foo", :Foo)]), + StatementsNode([ModuleNode([], Location(), ConstantReadNode(:Foo), nil, Location(), :Foo, :Foo)]), Location(), Location() ), @@ -465,7 +465,7 @@ def test_class_definition_in_method_body nil, nil, Location(), - "A", + :A, :A )] ), @@ -981,7 +981,7 @@ def test_dont_allow_return_inside_class_body nil, StatementsNode([ReturnNode(Location(), nil)]), Location(), - "A", + :A, :A ) @@ -997,7 +997,7 @@ def test_dont_allow_return_inside_module_body ConstantReadNode(:A), StatementsNode([ReturnNode(Location(), nil)]), Location(), - "A", + :A, :A ) diff --git a/test/yarp/snapshots/classes.txt b/test/yarp/snapshots/classes.txt index 9a5fd84ad216a7..43c0d24ab9817b 100644 --- a/test/yarp/snapshots/classes.txt +++ b/test/yarp/snapshots/classes.txt @@ -17,7 +17,7 @@ ProgramNode(0...370)( )] ), (14...17), - "A", + :A, :A ), ClassNode(19...39)( @@ -35,7 +35,7 @@ ProgramNode(0...370)( (36...39) ), (36...39), - "A", + :A, :A ), ClassNode(41...75)( @@ -53,7 +53,7 @@ ProgramNode(0...370)( (72...75) ), (72...75), - "A", + :A, :A ), ClassNode(77...98)( @@ -72,7 +72,7 @@ ProgramNode(0...370)( )] ), (95...98), - "A", + :A, :A ), SingletonClassNode(100...120)( @@ -127,7 +127,7 @@ ProgramNode(0...370)( )] ), (159...162), - "A", + :A, :A ), ClassNode(164...218)( @@ -154,7 +154,7 @@ ProgramNode(0...370)( )] ), (215...218), - "A", + :A, :A ), SingletonClassNode(220...240)( @@ -287,7 +287,7 @@ ProgramNode(0...370)( ), nil, (367...370), - "A", + :A, :A )] ) diff --git a/test/yarp/snapshots/method_calls.txt b/test/yarp/snapshots/method_calls.txt index a479948ce187c1..f320ab86feed20 100644 --- a/test/yarp/snapshots/method_calls.txt +++ b/test/yarp/snapshots/method_calls.txt @@ -1192,7 +1192,7 @@ ProgramNode(0...1237)( )] ), (926...929), - "Bar", + :Bar, :Bar )] ), @@ -1225,7 +1225,7 @@ ProgramNode(0...1237)( )] ), (957...960), - "Bar", + :Bar, :Bar )] ), diff --git a/test/yarp/snapshots/modules.txt b/test/yarp/snapshots/modules.txt index 4b00c1ebafc677..306e7db3e34c30 100644 --- a/test/yarp/snapshots/modules.txt +++ b/test/yarp/snapshots/modules.txt @@ -15,7 +15,7 @@ ProgramNode(0...140)( )] ), (15...18), - "A", + :A, :A ), InterpolatedStringNode(20...38)( @@ -51,7 +51,7 @@ ProgramNode(0...140)( ), nil, (52...55), - "M", + :M, :M ), ModuleNode(57...85)( @@ -75,7 +75,7 @@ ProgramNode(0...140)( (82...85) ), (82...85), - "A", + :A, :A ), ModuleNode(87...101)( @@ -88,7 +88,7 @@ ProgramNode(0...140)( ), nil, (98...101), - "A", + :A, :A ), ModuleNode(103...120)( @@ -111,7 +111,7 @@ ProgramNode(0...140)( ), nil, (117...120), - "B", + :B, :B ), ModuleNode(122...140)( @@ -134,7 +134,7 @@ ProgramNode(0...140)( ), nil, (137...140), - "B", + :B, :B )] ) diff --git a/test/yarp/snapshots/seattlerb/TestRubyParserShared.txt b/test/yarp/snapshots/seattlerb/TestRubyParserShared.txt index 27e8a6b753b98a..6ae8ed6d031f7d 100644 --- a/test/yarp/snapshots/seattlerb/TestRubyParserShared.txt +++ b/test/yarp/snapshots/seattlerb/TestRubyParserShared.txt @@ -87,7 +87,7 @@ ProgramNode(0...689)( )] ), (266...269), - "X", + :X, :X ), ClassNode(293...376)( @@ -112,12 +112,12 @@ ProgramNode(0...689)( )] ), (355...358), - "Y", + :Y, :Y )] ), (373...376), - "X", + :X, :X ), ClassNode(395...498)( @@ -165,7 +165,7 @@ ProgramNode(0...689)( )] ), (495...498), - "X", + :X, :X ), ModuleNode(517...565)( @@ -186,7 +186,7 @@ ProgramNode(0...689)( )] ), (562...565), - "X", + :X, :X ), ModuleNode(568...651)( @@ -207,12 +207,12 @@ ProgramNode(0...689)( )] ), (630...633), - "Y", + :Y, :Y )] ), (648...651), - "X", + :X, :X ), CallNode(670...689)( diff --git a/test/yarp/snapshots/seattlerb/class_comments.txt b/test/yarp/snapshots/seattlerb/class_comments.txt index 1751e299291970..905c5914a2f19b 100644 --- a/test/yarp/snapshots/seattlerb/class_comments.txt +++ b/test/yarp/snapshots/seattlerb/class_comments.txt @@ -23,7 +23,7 @@ ProgramNode(19...71)( )] ), (68...71), - "X", + :X, :X )] ) diff --git a/test/yarp/snapshots/seattlerb/defn_oneliner_eq2.txt b/test/yarp/snapshots/seattlerb/defn_oneliner_eq2.txt index 43d13f27cb4bbf..bbbdc17368d7b9 100644 --- a/test/yarp/snapshots/seattlerb/defn_oneliner_eq2.txt +++ b/test/yarp/snapshots/seattlerb/defn_oneliner_eq2.txt @@ -31,7 +31,7 @@ ProgramNode(0...28)( )] ), (25...28), - "X", + :X, :X )] ) diff --git a/test/yarp/snapshots/seattlerb/defs_oneliner_eq2.txt b/test/yarp/snapshots/seattlerb/defs_oneliner_eq2.txt index 636a1fd66caad6..1a88fffa507e10 100644 --- a/test/yarp/snapshots/seattlerb/defs_oneliner_eq2.txt +++ b/test/yarp/snapshots/seattlerb/defs_oneliner_eq2.txt @@ -31,7 +31,7 @@ ProgramNode(0...33)( )] ), (30...33), - "X", + :X, :X )] ) diff --git a/test/yarp/snapshots/seattlerb/magic_encoding_comment.txt b/test/yarp/snapshots/seattlerb/magic_encoding_comment.txt index c231c841242423..77efd6f4160317 100644 --- a/test/yarp/snapshots/seattlerb/magic_encoding_comment.txt +++ b/test/yarp/snapshots/seattlerb/magic_encoding_comment.txt @@ -31,7 +31,7 @@ ProgramNode(18...90)( )] ), (87...90), - "ExampleUTF8ClassNameVarietà", + :ExampleUTF8ClassNameVarietà, :ExampleUTF8ClassNameVarietà )] ) diff --git a/test/yarp/snapshots/seattlerb/module_comments.txt b/test/yarp/snapshots/seattlerb/module_comments.txt index 63019796ccd63d..152697f4022a1d 100644 --- a/test/yarp/snapshots/seattlerb/module_comments.txt +++ b/test/yarp/snapshots/seattlerb/module_comments.txt @@ -21,7 +21,7 @@ ProgramNode(24...77)( )] ), (74...77), - "X", + :X, :X )] ) diff --git a/test/yarp/snapshots/seattlerb/parse_line_heredoc_hardnewline.txt b/test/yarp/snapshots/seattlerb/parse_line_heredoc_hardnewline.txt index c29b09012edb0a..623eb3aabf840b 100644 --- a/test/yarp/snapshots/seattlerb/parse_line_heredoc_hardnewline.txt +++ b/test/yarp/snapshots/seattlerb/parse_line_heredoc_hardnewline.txt @@ -19,7 +19,7 @@ ProgramNode(0...48)( nil, nil, (45...48), - "Foo", + :Foo, :Foo )] ) diff --git a/test/yarp/snapshots/unparser/corpus/literal/class.txt b/test/yarp/snapshots/unparser/corpus/literal/class.txt index 60de85cb90e6ef..cb49848ae35d70 100644 --- a/test/yarp/snapshots/unparser/corpus/literal/class.txt +++ b/test/yarp/snapshots/unparser/corpus/literal/class.txt @@ -9,7 +9,7 @@ ProgramNode(0...213)( nil, nil, (8...11), - "A", + :A, :A ), SingletonClassNode(13...27)( @@ -42,7 +42,7 @@ ProgramNode(0...213)( nil, nil, (60...63), - "B", + :B, :B ), ClassNode(65...82)( @@ -61,7 +61,7 @@ ProgramNode(0...213)( nil, nil, (79...82), - "C", + :C, :C ), ClassNode(84...99)( @@ -72,7 +72,7 @@ ProgramNode(0...213)( ConstantReadNode(94...95)(:B), nil, (96...99), - "A", + :A, :A ), ClassNode(101...119)( @@ -87,7 +87,7 @@ ProgramNode(0...213)( ), nil, (116...119), - "A", + :A, :A ), ClassNode(121...142)( @@ -106,7 +106,7 @@ ProgramNode(0...213)( ), nil, (139...142), - "B", + :B, :B ), ClassNode(144...198)( @@ -156,7 +156,7 @@ ProgramNode(0...213)( )] ), (195...198), - "A", + :A, :A ), ClassNode(200...213)( @@ -171,7 +171,7 @@ ProgramNode(0...213)( nil, nil, (210...213), - "A", + :A, :A )] ) diff --git a/test/yarp/snapshots/unparser/corpus/literal/if.txt b/test/yarp/snapshots/unparser/corpus/literal/if.txt index 0ab7b311635bab..455db66af842f4 100644 --- a/test/yarp/snapshots/unparser/corpus/literal/if.txt +++ b/test/yarp/snapshots/unparser/corpus/literal/if.txt @@ -81,7 +81,7 @@ ProgramNode(0...246)( )] ), (130...133), - "A", + :A, :A ), ModuleNode(135...170)( @@ -116,7 +116,7 @@ ProgramNode(0...246)( )] ), (167...170), - "B", + :B, :B ), UnlessNode(171...197)( diff --git a/test/yarp/snapshots/unparser/corpus/literal/module.txt b/test/yarp/snapshots/unparser/corpus/literal/module.txt index d2dd0fa351b46f..28de3bfa3bc00d 100644 --- a/test/yarp/snapshots/unparser/corpus/literal/module.txt +++ b/test/yarp/snapshots/unparser/corpus/literal/module.txt @@ -7,7 +7,7 @@ ProgramNode(0...106)( ConstantReadNode(7...8)(:A), nil, (9...12), - "A", + :A, :A ), ModuleNode(14...29)( @@ -20,7 +20,7 @@ ProgramNode(0...106)( ), nil, (26...29), - "B", + :B, :B ), ModuleNode(31...49)( @@ -37,7 +37,7 @@ ProgramNode(0...106)( ), nil, (46...49), - "C", + :C, :C ), ModuleNode(51...106)( @@ -85,7 +85,7 @@ ProgramNode(0...106)( )] ), (103...106), - "A", + :A, :A )] ) diff --git a/test/yarp/snapshots/unparser/corpus/literal/send.txt b/test/yarp/snapshots/unparser/corpus/literal/send.txt index ff90dc52cdeb1d..fccb137c0932b0 100644 --- a/test/yarp/snapshots/unparser/corpus/literal/send.txt +++ b/test/yarp/snapshots/unparser/corpus/literal/send.txt @@ -38,7 +38,7 @@ ProgramNode(0...999)( )] ), (32...35), - "A", + :A, :A ), ModuleNode(37...73)( @@ -66,7 +66,7 @@ ProgramNode(0...999)( )] ), (70...73), - "A", + :A, :A ), CallNode(74...89)( @@ -78,7 +78,7 @@ ProgramNode(0...999)( nil, nil, (82...85), - "A", + :A, :A ), (85...86), @@ -97,7 +97,7 @@ ProgramNode(0...999)( ConstantReadNode(97...98)(:A), nil, (99...102), - "A", + :A, :A ), (102...103), diff --git a/test/yarp/snapshots/unparser/corpus/literal/while.txt b/test/yarp/snapshots/unparser/corpus/literal/while.txt index aed21abefc22fa..4d924f0d3df9fa 100644 --- a/test/yarp/snapshots/unparser/corpus/literal/while.txt +++ b/test/yarp/snapshots/unparser/corpus/literal/while.txt @@ -64,7 +64,7 @@ ProgramNode(0...620)( )] ), (65...68), - "A", + :A, :A ), DefNode(70...110)( @@ -160,7 +160,7 @@ ProgramNode(0...620)( )] ), (143...146), - "A", + :A, :A ), ModuleNode(148...182)( @@ -195,7 +195,7 @@ ProgramNode(0...620)( )] ), (179...182), - "A", + :A, :A ), ModuleNode(184...228)( @@ -240,7 +240,7 @@ ProgramNode(0...620)( )] ), (225...228), - "A", + :A, :A ), ModuleNode(230...299)( @@ -316,7 +316,7 @@ ProgramNode(0...620)( )] ), (296...299), - "A", + :A, :A ), ModuleNode(301...370)( @@ -382,7 +382,7 @@ ProgramNode(0...620)( )] ), (367...370), - "A", + :A, :A ), LocalVariableWriteNode(371...402)( diff --git a/test/yarp/snapshots/unparser/corpus/semantic/while.txt b/test/yarp/snapshots/unparser/corpus/semantic/while.txt index 7426fac71d37a6..3e6ef668a1cfc0 100644 --- a/test/yarp/snapshots/unparser/corpus/semantic/while.txt +++ b/test/yarp/snapshots/unparser/corpus/semantic/while.txt @@ -186,7 +186,7 @@ ProgramNode(0...188)( )] ), (185...188), - "A", + :A, :A )] ) diff --git a/test/yarp/snapshots/while.txt b/test/yarp/snapshots/while.txt index c04963bf9b6db7..843db1e147fb2b 100644 --- a/test/yarp/snapshots/while.txt +++ b/test/yarp/snapshots/while.txt @@ -139,7 +139,7 @@ ProgramNode(0...314)( )] ), (195...198), - "Foo", + :Foo, :Foo ), StatementsNode(200...205)([BreakNode(200...205)(nil, (200...205))]), diff --git a/test/yarp/snapshots/whitequark/class.txt b/test/yarp/snapshots/whitequark/class.txt index ad181664b58434..84ab3a72ef0ace 100644 --- a/test/yarp/snapshots/whitequark/class.txt +++ b/test/yarp/snapshots/whitequark/class.txt @@ -9,7 +9,7 @@ ProgramNode(0...29)( nil, nil, (10...13), - "Foo", + :Foo, :Foo ), ClassNode(15...29)( @@ -20,7 +20,7 @@ ProgramNode(0...29)( nil, nil, (26...29), - "Foo", + :Foo, :Foo )] ) diff --git a/test/yarp/snapshots/whitequark/class_definition_in_while_cond.txt b/test/yarp/snapshots/whitequark/class_definition_in_while_cond.txt index 292b0b79880f86..cec17515f12d46 100644 --- a/test/yarp/snapshots/whitequark/class_definition_in_while_cond.txt +++ b/test/yarp/snapshots/whitequark/class_definition_in_while_cond.txt @@ -88,7 +88,7 @@ ProgramNode(0...197)( )] ), (136...139), - "Foo", + :Foo, :Foo ), StatementsNode(141...146)([BreakNode(141...146)(nil, (141...146))]), @@ -117,7 +117,7 @@ ProgramNode(0...197)( )] ), (182...185), - "Foo", + :Foo, :Foo ), StatementsNode(187...192)([BreakNode(187...192)(nil, (187...192))]), diff --git a/test/yarp/snapshots/whitequark/class_super.txt b/test/yarp/snapshots/whitequark/class_super.txt index 6ebbb1364c12a6..ec400beb09de74 100644 --- a/test/yarp/snapshots/whitequark/class_super.txt +++ b/test/yarp/snapshots/whitequark/class_super.txt @@ -9,7 +9,7 @@ ProgramNode(0...20)( ConstantReadNode(12...15)(:Bar), nil, (17...20), - "Foo", + :Foo, :Foo )] ) diff --git a/test/yarp/snapshots/whitequark/class_super_label.txt b/test/yarp/snapshots/whitequark/class_super_label.txt index a53dac8f2c32ee..8ebba419a27333 100644 --- a/test/yarp/snapshots/whitequark/class_super_label.txt +++ b/test/yarp/snapshots/whitequark/class_super_label.txt @@ -21,7 +21,7 @@ ProgramNode(0...20)( ), nil, (17...20), - "Foo", + :Foo, :Foo )] ) diff --git a/test/yarp/snapshots/whitequark/cpath.txt b/test/yarp/snapshots/whitequark/cpath.txt index 3df789b5caa1ee..b557da7e7fc522 100644 --- a/test/yarp/snapshots/whitequark/cpath.txt +++ b/test/yarp/snapshots/whitequark/cpath.txt @@ -7,7 +7,7 @@ ProgramNode(0...39)( ConstantPathNode(7...12)(nil, ConstantReadNode(9...12)(:Foo), (7...9)), nil, (14...17), - "Foo", + :Foo, :Foo ), ModuleNode(19...39)( @@ -20,7 +20,7 @@ ProgramNode(0...39)( ), nil, (36...39), - "Foo", + :Foo, :Foo )] ) diff --git a/test/yarp/snapshots/whitequark/if_while_after_class__since_32.txt b/test/yarp/snapshots/whitequark/if_while_after_class__since_32.txt index a088237a852b35..c18c1b4e9a4a9e 100644 --- a/test/yarp/snapshots/whitequark/if_while_after_class__since_32.txt +++ b/test/yarp/snapshots/whitequark/if_while_after_class__since_32.txt @@ -19,7 +19,7 @@ ProgramNode(0...178)( nil, nil, (35...38), - "Kernel", + :Kernel, :Kernel ), ClassNode(40...87)( @@ -45,7 +45,7 @@ ProgramNode(0...178)( nil, nil, (84...87), - "Kernel", + :Kernel, :Kernel ), ModuleNode(89...128)( @@ -64,7 +64,7 @@ ProgramNode(0...178)( ), nil, (125...128), - "Kernel", + :Kernel, :Kernel ), ModuleNode(130...178)( @@ -90,7 +90,7 @@ ProgramNode(0...178)( ), nil, (175...178), - "Kernel", + :Kernel, :Kernel )] ) diff --git a/test/yarp/snapshots/whitequark/module.txt b/test/yarp/snapshots/whitequark/module.txt index 9d3a1148f37708..7880ab9980ac22 100644 --- a/test/yarp/snapshots/whitequark/module.txt +++ b/test/yarp/snapshots/whitequark/module.txt @@ -7,7 +7,7 @@ ProgramNode(0...15)( ConstantReadNode(7...10)(:Foo), nil, (12...15), - "Foo", + :Foo, :Foo )] ) diff --git a/test/yarp/snapshots/whitequark/numparam_outside_block.txt b/test/yarp/snapshots/whitequark/numparam_outside_block.txt index 9ef6b0cfbbe575..61d138fa6d5a89 100644 --- a/test/yarp/snapshots/whitequark/numparam_outside_block.txt +++ b/test/yarp/snapshots/whitequark/numparam_outside_block.txt @@ -22,7 +22,7 @@ ProgramNode(0...83)( [CallNode(36...38)(nil, nil, (36...38), nil, nil, nil, nil, 2, "_1")] ), (40...43), - "A", + :A, :A ), DefNode(45...64)( @@ -48,7 +48,7 @@ ProgramNode(0...83)( [CallNode(76...78)(nil, nil, (76...78), nil, nil, nil, nil, 2, "_1")] ), (80...83), - "A", + :A, :A )] ) diff --git a/test/yarp/snapshots/whitequark/parser_bug_490.txt b/test/yarp/snapshots/whitequark/parser_bug_490.txt index 680b5fe146dda9..b3b5b04a4a4baf 100644 --- a/test/yarp/snapshots/whitequark/parser_bug_490.txt +++ b/test/yarp/snapshots/whitequark/parser_bug_490.txt @@ -49,7 +49,7 @@ ProgramNode(0...132)( nil, nil, (72...75), - "C", + :C, :C )] ), @@ -81,7 +81,7 @@ ProgramNode(0...132)( ConstantReadNode(116...117)(:M), nil, (119...122), - "M", + :M, :M )] ), diff --git a/test/yarp/snapshots/whitequark/parser_bug_518.txt b/test/yarp/snapshots/whitequark/parser_bug_518.txt index 0f92f9e95bddaf..fc53bcb5274727 100644 --- a/test/yarp/snapshots/whitequark/parser_bug_518.txt +++ b/test/yarp/snapshots/whitequark/parser_bug_518.txt @@ -9,7 +9,7 @@ ProgramNode(0...15)( ConstantReadNode(10...11)(:B), nil, (12...15), - "A", + :A, :A )] ) diff --git a/yarp/config.yml b/yarp/config.yml index 354c90abcdfc7f..164e96101f5cb7 100644 --- a/yarp/config.yml +++ b/yarp/config.yml @@ -779,7 +779,7 @@ nodes: - name: end_keyword_loc type: location - name: name - type: string + type: constant - name: name_constant type: constant comment: | @@ -1739,7 +1739,7 @@ nodes: - name: end_keyword_loc type: location - name: name - type: string + type: constant - name: name_constant type: constant comment: | diff --git a/yarp/yarp.c b/yarp/yarp.c index 78b3907308ed1a..4e291637f1c056 100644 --- a/yarp/yarp.c +++ b/yarp/yarp.c @@ -1647,6 +1647,7 @@ yp_case_node_end_keyword_loc_set(yp_case_node_t *node, const yp_token_t *end_key static yp_class_node_t * yp_class_node_create(yp_parser_t *parser, yp_constant_id_list_t *locals, const yp_token_t *class_keyword, yp_node_t *constant_path, const yp_token_t *name, const yp_token_t *inheritance_operator, yp_node_t *superclass, yp_node_t *body, const yp_token_t *end_keyword) { yp_class_node_t *node = YP_ALLOC_NODE(parser, yp_class_node_t); + yp_constant_id_t name_constant = yp_parser_constant_id_token(parser, name); *node = (yp_class_node_t) { { @@ -1660,11 +1661,10 @@ yp_class_node_create(yp_parser_t *parser, yp_constant_id_list_t *locals, const y .superclass = superclass, .body = body, .end_keyword_loc = YP_LOCATION_TOKEN_VALUE(end_keyword), - .name = YP_EMPTY_STRING, - .name_constant = yp_parser_constant_id_token(parser, name) + .name = name_constant, + .name_constant = name_constant }; - yp_string_shared_init(&node->name, name->start, name->end); return node; } @@ -3297,6 +3297,7 @@ yp_match_required_node_create(yp_parser_t *parser, yp_node_t *value, yp_node_t * static yp_module_node_t * yp_module_node_create(yp_parser_t *parser, yp_constant_id_list_t *locals, const yp_token_t *module_keyword, yp_node_t *constant_path, const yp_token_t *name, yp_node_t *body, const yp_token_t *end_keyword) { yp_module_node_t *node = YP_ALLOC_NODE(parser, yp_module_node_t); + yp_constant_id_t name_constant = yp_parser_constant_id_token(parser, name); *node = (yp_module_node_t) { { @@ -3311,11 +3312,10 @@ yp_module_node_create(yp_parser_t *parser, yp_constant_id_list_t *locals, const .constant_path = constant_path, .body = body, .end_keyword_loc = YP_LOCATION_TOKEN_VALUE(end_keyword), - .name = YP_EMPTY_STRING, - .name_constant = yp_parser_constant_id_token(parser, name) + .name = name_constant, + .name_constant = name_constant }; - yp_string_shared_init(&node->name, name->start, name->end); return node; } From a334077b7b4dfc2439afd9b429c2fcd9e4c3012e Mon Sep 17 00:00:00 2001 From: Takashi Kokubun Date: Wed, 6 Sep 2023 09:29:33 -0700 Subject: [PATCH 89/95] YJIT: Make compiled_* stats available by default (#8379) * YJIT: Make compiled_* stats available by default * Update comment about default counters [ci skip] Co-authored-by: Maxime Chevalier-Boisvert --------- Co-authored-by: Maxime Chevalier-Boisvert --- yjit/src/asm/mod.rs | 3 ++- yjit/src/codegen.rs | 15 +++------------ yjit/src/stats.rs | 30 +++++++++++++++++++++++++----- 3 files changed, 30 insertions(+), 18 deletions(-) diff --git a/yjit/src/asm/mod.rs b/yjit/src/asm/mod.rs index 3c6c6e8e80bdbd..989fcd2a0fc94a 100644 --- a/yjit/src/asm/mod.rs +++ b/yjit/src/asm/mod.rs @@ -6,6 +6,7 @@ use crate::core::IseqPayload; use crate::core::for_each_off_stack_iseq_payload; use crate::core::for_each_on_stack_iseq_payload; use crate::invariants::rb_yjit_tracing_invalidate_all; +use crate::stats::incr_counter; use crate::virtualmem::WriteError; #[cfg(feature = "disasm")] @@ -652,7 +653,7 @@ impl CodeBlock { ocb.unwrap().freed_pages = new_freed_pages; assert_eq!(1, Rc::strong_count(&old_freed_pages)); // will deallocate - CodegenGlobals::incr_code_gc_count(); + incr_counter!(code_gc_count); } pub fn inline(&self) -> bool { diff --git a/yjit/src/codegen.rs b/yjit/src/codegen.rs index b51704b2c606f0..f36d52a6e33824 100644 --- a/yjit/src/codegen.rs +++ b/yjit/src/codegen.rs @@ -249,6 +249,9 @@ pub enum JCCKinds { #[inline(always)] fn gen_counter_incr(asm: &mut Assembler, counter: Counter) { + // Assert that default counters are not incremented by generated code as this would impact performance + assert!(!DEFAULT_COUNTERS.contains(&counter), "gen_counter_incr incremented {:?}", counter); + if get_option!(gen_stats) { asm.comment(&format!("increment counter {}", counter.get_name())); let ptr = get_counter_ptr(&counter.get_name()); @@ -8581,9 +8584,6 @@ pub struct CodegenGlobals { /// Page indexes for outlined code that are not associated to any ISEQ. ocb_pages: Vec, - - /// How many times code GC has been executed. - code_gc_count: usize, } /// For implementing global code invalidation. A position in the inline @@ -8679,7 +8679,6 @@ impl CodegenGlobals { global_inval_patches: Vec::new(), method_codegen_table: HashMap::new(), ocb_pages, - code_gc_count: 0, }; // Register the method codegen functions @@ -8841,14 +8840,6 @@ impl CodegenGlobals { pub fn get_ocb_pages() -> &'static Vec { &CodegenGlobals::get_instance().ocb_pages } - - pub fn incr_code_gc_count() { - CodegenGlobals::get_instance().code_gc_count += 1; - } - - pub fn get_code_gc_count() -> usize { - CodegenGlobals::get_instance().code_gc_count - } } #[cfg(test)] diff --git a/yjit/src/stats.rs b/yjit/src/stats.rs index 27e3c6d08bb9fe..a4f95db6ae15cb 100644 --- a/yjit/src/stats.rs +++ b/yjit/src/stats.rs @@ -163,6 +163,17 @@ macro_rules! make_counters { } } +/// The list of counters that are available without --yjit-stats. +/// They are incremented only by `incr_counter!` and don't use `gen_counter_incr`. +pub const DEFAULT_COUNTERS: [Counter; 6] = [ + Counter::code_gc_count, + Counter::compiled_iseq_entry, + Counter::compiled_iseq_count, + Counter::compiled_blockid_count, + Counter::compiled_block_count, + Counter::compiled_branch_count, +]; + /// Macro to increase a counter by name and count macro_rules! incr_counter_by { // Unsafe is ok here because options are initialized @@ -424,6 +435,8 @@ make_counters! { // executable memory, so this should be 0. exec_mem_non_bump_alloc, + code_gc_count, + num_gc_obj_refs, num_send, @@ -571,9 +584,6 @@ fn rb_yjit_gen_stats_dict(context: bool) -> VALUE { // Live pages hash_aset_usize!(hash, "live_page_count", cb.num_mapped_pages() - freed_page_count); - // Code GC count - hash_aset_usize!(hash, "code_gc_count", CodegenGlobals::get_code_gc_count()); - // Size of memory region allocated for JIT code hash_aset_usize!(hash, "code_region_size", cb.mapped_region_size()); @@ -594,13 +604,23 @@ fn rb_yjit_gen_stats_dict(context: bool) -> VALUE { hash_aset_usize!(hash, "vm_insns_count", rb_vm_insns_count as usize); } - // If we're not generating stats, the hash is done + // If we're not generating stats, put only default counters if !get_option!(gen_stats) { + for counter in DEFAULT_COUNTERS { + // Get the counter value + let counter_ptr = get_counter_ptr(&counter.get_name()); + let counter_val = unsafe { *counter_ptr }; + + // Put counter into hash + let key = rust_str_to_sym(&counter.get_name()); + let value = VALUE::fixnum_from_usize(counter_val as usize); + unsafe { rb_hash_aset(hash, key, value); } + } + return hash; } // If the stats feature is enabled - unsafe { // Indicate that the complete set of stats is available rb_hash_aset(hash, rust_str_to_sym("all_stats"), Qtrue); From 08929b344d89fb12fb3a12eccf686458dc820e6d Mon Sep 17 00:00:00 2001 From: Peter Zhu Date: Wed, 6 Sep 2023 13:31:50 -0400 Subject: [PATCH 90/95] Try to fix flaky test_warmup_frees_pages This test sometimes fails with: ``` 1) Failure: TestProcess#test_warmup_frees_pages [test/ruby/test_process.rb:2750]: <202> expected but was <203>. ``` --- test/ruby/test_process.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/test/ruby/test_process.rb b/test/ruby/test_process.rb index d7910e5acf5178..dc0ccd1f770cd6 100644 --- a/test/ruby/test_process.rb +++ b/test/ruby/test_process.rb @@ -2742,6 +2742,9 @@ def test_warmup_frees_pages ary.clear ary = nil + # Disable GC so we can make sure GC only runs in Process.warmup + GC.disable + total_pages_before = GC.stat(:heap_eden_pages) + GC.stat(:heap_allocatable_pages) Process.warmup From 746eede412f083dc93923e39e3299c69fce46c15 Mon Sep 17 00:00:00 2001 From: Kevin Newton Date: Wed, 6 Sep 2023 10:46:20 -0400 Subject: [PATCH 91/95] [ruby/yarp] Constant on block parameter node https://github.com/ruby/yarp/commit/2cd9a67150 --- test/yarp/errors_test.rb | 6 +-- test/yarp/snapshots/methods.txt | 4 +- test/yarp/snapshots/procs.txt | 6 +-- .../snapshots/seattlerb/args_kw_block.txt | 2 +- .../snapshots/seattlerb/block_arg__bare.txt | 2 +- .../seattlerb/block_arg_opt_arg_block.txt | 2 +- .../block_arg_opt_splat_arg_block_omfg.txt | 2 +- .../snapshots/seattlerb/block_args_opt3.txt | 2 +- .../block_opt_splat_arg_block_omfg.txt | 2 +- .../yarp/snapshots/seattlerb/difficult3_3.txt | 2 +- .../snapshots/seattlerb/iter_args_10_2.txt | 2 +- .../snapshots/seattlerb/iter_args_11_2.txt | 2 +- test/yarp/snapshots/seattlerb/iter_args_5.txt | 2 +- .../snapshots/seattlerb/iter_args_7_2.txt | 2 +- .../snapshots/seattlerb/iter_args_8_2.txt | 2 +- .../snapshots/seattlerb/iter_args_9_2.txt | 2 +- .../stabby_arg_opt_splat_arg_block_omfg.txt | 2 +- .../snapshots/unparser/corpus/literal/def.txt | 6 +-- .../unparser/corpus/literal/since/31.txt | 4 +- .../whitequark/anonymous_blockarg.txt | 2 +- test/yarp/snapshots/whitequark/args.txt | 34 ++++++++--------- test/yarp/snapshots/whitequark/blockarg.txt | 2 +- test/yarp/snapshots/whitequark/blockargs.txt | 38 +++++++++---------- yarp/config.yml | 2 + yarp/templates/ext/yarp/api_node.c.erb | 2 + yarp/templates/include/yarp/ast.h.erb | 2 +- yarp/templates/lib/yarp/node.rb.erb | 2 +- yarp/templates/lib/yarp/serialize.rb.erb | 17 +++++++-- yarp/templates/src/node.c.erb | 6 +-- yarp/templates/src/prettyprint.c.erb | 8 ++++ yarp/templates/src/serialize.c.erb | 2 +- yarp/templates/template.rb | 16 +++++++- yarp/yarp.c | 8 ++++ 33 files changed, 119 insertions(+), 76 deletions(-) diff --git a/test/yarp/errors_test.rb b/test/yarp/errors_test.rb index aa39982d22119e..6c03960ec3ed3e 100644 --- a/test/yarp/errors_test.rb +++ b/test/yarp/errors_test.rb @@ -644,7 +644,7 @@ def test_method_parameters_after_block nil, [], nil, - BlockParameterNode(Location(), Location()) + BlockParameterNode(:block, Location(), Location()) ), nil, [:block, :a], @@ -664,7 +664,7 @@ def test_method_with_arguments_after_anonymous_block expected = DefNode( Location(), nil, - ParametersNode([], [], [RequiredParameterNode(:a)], nil, [], nil, BlockParameterNode(nil, Location())), + ParametersNode([], [], [RequiredParameterNode(:a)], nil, [], nil, BlockParameterNode(nil, nil, Location())), nil, [:&, :a], Location(), @@ -1087,7 +1087,7 @@ def test_duplicated_parameter_names expected = DefNode( Location(), nil, - ParametersNode([RequiredParameterNode(:a), RequiredParameterNode(:b)], [], [], nil, [], nil, BlockParameterNode(Location(), Location())), + ParametersNode([RequiredParameterNode(:a), RequiredParameterNode(:b)], [], [], nil, [], nil, BlockParameterNode(:a, Location(), Location())), nil, [:a, :b], Location(), diff --git a/test/yarp/snapshots/methods.txt b/test/yarp/snapshots/methods.txt index a822d44199d462..13a81d15cda623 100644 --- a/test/yarp/snapshots/methods.txt +++ b/test/yarp/snapshots/methods.txt @@ -876,7 +876,7 @@ ProgramNode(0...1194)( nil, [], nil, - BlockParameterNode(789...791)((790...791), (789...790)) + BlockParameterNode(789...791)(:b, (790...791), (789...790)) ), nil, [:b], @@ -897,7 +897,7 @@ ProgramNode(0...1194)( nil, [], nil, - BlockParameterNode(803...804)(nil, (803...804)) + BlockParameterNode(803...804)(nil, nil, (803...804)) ), nil, [:&], diff --git a/test/yarp/snapshots/procs.txt b/test/yarp/snapshots/procs.txt index 4510160c44178a..64ad900220fa5f 100644 --- a/test/yarp/snapshots/procs.txt +++ b/test/yarp/snapshots/procs.txt @@ -93,7 +93,7 @@ ProgramNode(0...266)( [KeywordParameterNode(113...115)((113...115), nil), KeywordParameterNode(117...119)((117...119), nil)], nil, - BlockParameterNode(121...123)((122...123), (121...122)) + BlockParameterNode(121...123)(:e, (122...123), (121...122)) ), [], nil, @@ -120,7 +120,7 @@ ProgramNode(0...266)( [KeywordParameterNode(149...151)((149...151), nil), KeywordParameterNode(153...155)((153...155), nil)], KeywordRestParameterNode(157...160)((157...159), (159...160)), - BlockParameterNode(162...164)((163...164), (162...163)) + BlockParameterNode(162...164)(:g, (163...164), (162...163)) ), [], (134...135), @@ -147,7 +147,7 @@ ProgramNode(0...266)( [KeywordParameterNode(191...193)((191...193), nil), KeywordParameterNode(195...197)((195...197), nil)], KeywordRestParameterNode(199...202)((199...201), (201...202)), - BlockParameterNode(204...206)((205...206), (204...205)) + BlockParameterNode(204...206)(:g, (205...206), (204...205)) ), [], (176...177), diff --git a/test/yarp/snapshots/seattlerb/args_kw_block.txt b/test/yarp/snapshots/seattlerb/args_kw_block.txt index ee6e224c8048e7..c11a1590702c09 100644 --- a/test/yarp/snapshots/seattlerb/args_kw_block.txt +++ b/test/yarp/snapshots/seattlerb/args_kw_block.txt @@ -11,7 +11,7 @@ ProgramNode(0...20)( nil, [KeywordParameterNode(6...10)((6...8), IntegerNode(9...10)())], nil, - BlockParameterNode(12...14)((13...14), (12...13)) + BlockParameterNode(12...14)(:b, (13...14), (12...13)) ), nil, [:a, :b], diff --git a/test/yarp/snapshots/seattlerb/block_arg__bare.txt b/test/yarp/snapshots/seattlerb/block_arg__bare.txt index 94451c870d35b6..c660aeb54e725e 100644 --- a/test/yarp/snapshots/seattlerb/block_arg__bare.txt +++ b/test/yarp/snapshots/seattlerb/block_arg__bare.txt @@ -11,7 +11,7 @@ ProgramNode(0...13)( nil, [], nil, - BlockParameterNode(6...7)(nil, (6...7)) + BlockParameterNode(6...7)(nil, nil, (6...7)) ), nil, [:&], diff --git a/test/yarp/snapshots/seattlerb/block_arg_opt_arg_block.txt b/test/yarp/snapshots/seattlerb/block_arg_opt_arg_block.txt index 9a663faff84b59..dd24630442aa5a 100644 --- a/test/yarp/snapshots/seattlerb/block_arg_opt_arg_block.txt +++ b/test/yarp/snapshots/seattlerb/block_arg_opt_arg_block.txt @@ -23,7 +23,7 @@ ProgramNode(0...21)( nil, [], nil, - BlockParameterNode(16...18)((17...18), (16...17)) + BlockParameterNode(16...18)(:e, (17...18), (16...17)) ), [], (4...5), diff --git a/test/yarp/snapshots/seattlerb/block_arg_opt_splat_arg_block_omfg.txt b/test/yarp/snapshots/seattlerb/block_arg_opt_splat_arg_block_omfg.txt index 6ace3ff446c813..dc7500ce920e53 100644 --- a/test/yarp/snapshots/seattlerb/block_arg_opt_splat_arg_block_omfg.txt +++ b/test/yarp/snapshots/seattlerb/block_arg_opt_splat_arg_block_omfg.txt @@ -23,7 +23,7 @@ ProgramNode(0...25)( RestParameterNode(13...15)((13...14), (14...15)), [], nil, - BlockParameterNode(20...22)((21...22), (20...21)) + BlockParameterNode(20...22)(:f, (21...22), (20...21)) ), [], (4...5), diff --git a/test/yarp/snapshots/seattlerb/block_args_opt3.txt b/test/yarp/snapshots/seattlerb/block_args_opt3.txt index 0513157505addc..6d4e26c8eda195 100644 --- a/test/yarp/snapshots/seattlerb/block_args_opt3.txt +++ b/test/yarp/snapshots/seattlerb/block_args_opt3.txt @@ -29,7 +29,7 @@ ProgramNode(0...42)( nil, [], nil, - BlockParameterNode(24...26)((25...26), (24...25)) + BlockParameterNode(24...26)(:d, (25...26), (24...25)) ), [], (4...5), diff --git a/test/yarp/snapshots/seattlerb/block_opt_splat_arg_block_omfg.txt b/test/yarp/snapshots/seattlerb/block_opt_splat_arg_block_omfg.txt index cc48f213f8e348..0efcade2290767 100644 --- a/test/yarp/snapshots/seattlerb/block_opt_splat_arg_block_omfg.txt +++ b/test/yarp/snapshots/seattlerb/block_opt_splat_arg_block_omfg.txt @@ -23,7 +23,7 @@ ProgramNode(0...22)( RestParameterNode(10...12)((10...11), (11...12)), [], nil, - BlockParameterNode(17...19)((18...19), (17...18)) + BlockParameterNode(17...19)(:e, (18...19), (17...18)) ), [], (4...5), diff --git a/test/yarp/snapshots/seattlerb/difficult3_3.txt b/test/yarp/snapshots/seattlerb/difficult3_3.txt index 7a25bc9c8be563..5b1e1ca29d00b1 100644 --- a/test/yarp/snapshots/seattlerb/difficult3_3.txt +++ b/test/yarp/snapshots/seattlerb/difficult3_3.txt @@ -18,7 +18,7 @@ ProgramNode(0...17)( RestParameterNode(5...7)((5...6), (6...7)), [], nil, - BlockParameterNode(12...14)((13...14), (12...13)) + BlockParameterNode(12...14)(:c, (13...14), (12...13)) ), [], (4...5), diff --git a/test/yarp/snapshots/seattlerb/iter_args_10_2.txt b/test/yarp/snapshots/seattlerb/iter_args_10_2.txt index 5059820edcccb5..f847bcc0317ea2 100644 --- a/test/yarp/snapshots/seattlerb/iter_args_10_2.txt +++ b/test/yarp/snapshots/seattlerb/iter_args_10_2.txt @@ -23,7 +23,7 @@ ProgramNode(0...25)( RestParameterNode(16...18)((16...17), (17...18)), [], nil, - BlockParameterNode(20...22)((21...22), (20...21)) + BlockParameterNode(20...22)(:d, (21...22), (20...21)) ), [], (4...5), diff --git a/test/yarp/snapshots/seattlerb/iter_args_11_2.txt b/test/yarp/snapshots/seattlerb/iter_args_11_2.txt index b14ca29440d393..bfd864e20e2649 100644 --- a/test/yarp/snapshots/seattlerb/iter_args_11_2.txt +++ b/test/yarp/snapshots/seattlerb/iter_args_11_2.txt @@ -23,7 +23,7 @@ ProgramNode(0...28)( RestParameterNode(16...18)((16...17), (17...18)), [], nil, - BlockParameterNode(23...25)((24...25), (23...24)) + BlockParameterNode(23...25)(:e, (24...25), (23...24)) ), [], (4...5), diff --git a/test/yarp/snapshots/seattlerb/iter_args_5.txt b/test/yarp/snapshots/seattlerb/iter_args_5.txt index 826ec62097ea1f..224bdc0bf9b14d 100644 --- a/test/yarp/snapshots/seattlerb/iter_args_5.txt +++ b/test/yarp/snapshots/seattlerb/iter_args_5.txt @@ -18,7 +18,7 @@ ProgramNode(0...13)( nil, [], nil, - BlockParameterNode(8...10)((9...10), (8...9)) + BlockParameterNode(8...10)(:b, (9...10), (8...9)) ), [], (4...5), diff --git a/test/yarp/snapshots/seattlerb/iter_args_7_2.txt b/test/yarp/snapshots/seattlerb/iter_args_7_2.txt index c151325c93da88..3ce974e279027f 100644 --- a/test/yarp/snapshots/seattlerb/iter_args_7_2.txt +++ b/test/yarp/snapshots/seattlerb/iter_args_7_2.txt @@ -23,7 +23,7 @@ ProgramNode(0...22)( RestParameterNode(13...15)((13...14), (14...15)), [], nil, - BlockParameterNode(17...19)((18...19), (17...18)) + BlockParameterNode(17...19)(:c, (18...19), (17...18)) ), [], (4...5), diff --git a/test/yarp/snapshots/seattlerb/iter_args_8_2.txt b/test/yarp/snapshots/seattlerb/iter_args_8_2.txt index 84b0ae8e6589ab..8b2b3f2b85c46e 100644 --- a/test/yarp/snapshots/seattlerb/iter_args_8_2.txt +++ b/test/yarp/snapshots/seattlerb/iter_args_8_2.txt @@ -23,7 +23,7 @@ ProgramNode(0...25)( RestParameterNode(13...15)((13...14), (14...15)), [], nil, - BlockParameterNode(20...22)((21...22), (20...21)) + BlockParameterNode(20...22)(:d, (21...22), (20...21)) ), [], (4...5), diff --git a/test/yarp/snapshots/seattlerb/iter_args_9_2.txt b/test/yarp/snapshots/seattlerb/iter_args_9_2.txt index b85e5a84bb2ea0..904d13e7e160a7 100644 --- a/test/yarp/snapshots/seattlerb/iter_args_9_2.txt +++ b/test/yarp/snapshots/seattlerb/iter_args_9_2.txt @@ -23,7 +23,7 @@ ProgramNode(0...21)( nil, [], nil, - BlockParameterNode(16...18)((17...18), (16...17)) + BlockParameterNode(16...18)(:c, (17...18), (16...17)) ), [], (4...5), diff --git a/test/yarp/snapshots/seattlerb/stabby_arg_opt_splat_arg_block_omfg.txt b/test/yarp/snapshots/seattlerb/stabby_arg_opt_splat_arg_block_omfg.txt index 0f64173a920c99..4b16ebf090eb02 100644 --- a/test/yarp/snapshots/seattlerb/stabby_arg_opt_splat_arg_block_omfg.txt +++ b/test/yarp/snapshots/seattlerb/stabby_arg_opt_splat_arg_block_omfg.txt @@ -19,7 +19,7 @@ ProgramNode(0...23)( RestParameterNode(11...13)((11...12), (12...13)), [], nil, - BlockParameterNode(18...20)((19...20), (18...19)) + BlockParameterNode(18...20)(:f, (19...20), (18...19)) ), [], (2...3), diff --git a/test/yarp/snapshots/unparser/corpus/literal/def.txt b/test/yarp/snapshots/unparser/corpus/literal/def.txt index 360c39b5e09798..f458483791f2a4 100644 --- a/test/yarp/snapshots/unparser/corpus/literal/def.txt +++ b/test/yarp/snapshots/unparser/corpus/literal/def.txt @@ -781,7 +781,7 @@ ProgramNode(0...913)( RestParameterNode(654...658)((654...655), (655...658)), [], nil, - BlockParameterNode(660...666)((661...666), (660...661)) + BlockParameterNode(660...666)(:block, (661...666), (660...661)) ), StatementsNode(670...673)( [CallNode(670...673)( @@ -840,7 +840,7 @@ ProgramNode(0...913)( nil, [], nil, - BlockParameterNode(729...735)((730...735), (729...730)) + BlockParameterNode(729...735)(:block, (730...735), (729...730)) ), StatementsNode(739...742)( [CallNode(739...742)( @@ -873,7 +873,7 @@ ProgramNode(0...913)( nil, [], nil, - BlockParameterNode(761...767)((762...767), (761...762)) + BlockParameterNode(761...767)(:block, (762...767), (761...762)) ), StatementsNode(771...774)([LocalVariableReadNode(771...774)(:bar, 0)]), [:bar, :block], diff --git a/test/yarp/snapshots/unparser/corpus/literal/since/31.txt b/test/yarp/snapshots/unparser/corpus/literal/since/31.txt index b646850e2bb64c..f21bf30e0473d2 100644 --- a/test/yarp/snapshots/unparser/corpus/literal/since/31.txt +++ b/test/yarp/snapshots/unparser/corpus/literal/since/31.txt @@ -11,7 +11,7 @@ ProgramNode(0...51)( nil, [], nil, - BlockParameterNode(8...9)(nil, (8...9)) + BlockParameterNode(8...9)(nil, nil, (8...9)) ), StatementsNode(13...19)( [CallNode(13...19)( @@ -46,7 +46,7 @@ ProgramNode(0...51)( nil, [], nil, - BlockParameterNode(36...37)(nil, (36...37)) + BlockParameterNode(36...37)(nil, nil, (36...37)) ), StatementsNode(41...47)( [CallNode(41...47)( diff --git a/test/yarp/snapshots/whitequark/anonymous_blockarg.txt b/test/yarp/snapshots/whitequark/anonymous_blockarg.txt index d3679ca4244ee7..d5c7ef56dd86ea 100644 --- a/test/yarp/snapshots/whitequark/anonymous_blockarg.txt +++ b/test/yarp/snapshots/whitequark/anonymous_blockarg.txt @@ -11,7 +11,7 @@ ProgramNode(0...23)( nil, [], nil, - BlockParameterNode(8...9)(nil, (8...9)) + BlockParameterNode(8...9)(nil, nil, (8...9)) ), StatementsNode(12...18)( [CallNode(12...18)( diff --git a/test/yarp/snapshots/whitequark/args.txt b/test/yarp/snapshots/whitequark/args.txt index 37e281c5346269..faa2ee445925f6 100644 --- a/test/yarp/snapshots/whitequark/args.txt +++ b/test/yarp/snapshots/whitequark/args.txt @@ -11,7 +11,7 @@ ProgramNode(0...690)( nil, [], nil, - BlockParameterNode(6...8)((7...8), (6...7)) + BlockParameterNode(6...8)(:b, (7...8), (6...7)) ), nil, [:b], @@ -310,7 +310,7 @@ ProgramNode(0...690)( IntegerNode(241...242)() )], nil, - BlockParameterNode(244...246)((245...246), (244...245)) + BlockParameterNode(244...246)(:b, (245...246), (244...245)) ), nil, [:foo, :b], @@ -338,7 +338,7 @@ ProgramNode(0...690)( IntegerNode(274...275)() )], KeywordRestParameterNode(277...282)((277...279), (279...282)), - BlockParameterNode(284...286)((285...286), (284...285)) + BlockParameterNode(284...286)(:b, (285...286), (284...285)) ), nil, [:foo, :bar, :baz, :b], @@ -359,7 +359,7 @@ ProgramNode(0...690)( nil, [], KeywordRestParameterNode(300...305)((300...302), (302...305)), - BlockParameterNode(307...309)((308...309), (307...308)) + BlockParameterNode(307...309)(:b, (308...309), (307...308)) ), nil, [:baz, :b], @@ -401,7 +401,7 @@ ProgramNode(0...690)( RestParameterNode(340...342)((340...341), (341...342)), [], nil, - BlockParameterNode(344...346)((345...346), (344...345)) + BlockParameterNode(344...346)(:b, (345...346), (344...345)) ), nil, [:r, :b], @@ -422,7 +422,7 @@ ProgramNode(0...690)( RestParameterNode(359...361)((359...360), (360...361)), [], nil, - BlockParameterNode(366...368)((367...368), (366...367)) + BlockParameterNode(366...368)(:b, (367...368), (366...367)) ), nil, [:r, :p, :b], @@ -456,7 +456,7 @@ ProgramNode(0...690)( nil, [], nil, - BlockParameterNode(397...399)((398...399), (397...398)) + BlockParameterNode(397...399)(:b, (398...399), (397...398)) ), nil, [:a, :b], @@ -477,7 +477,7 @@ ProgramNode(0...690)( RestParameterNode(415...417)((415...416), (416...417)), [], nil, - BlockParameterNode(419...421)((420...421), (419...420)) + BlockParameterNode(419...421)(:b, (420...421), (419...420)) ), nil, [:a, :r, :b], @@ -498,7 +498,7 @@ ProgramNode(0...690)( RestParameterNode(437...439)((437...438), (438...439)), [], nil, - BlockParameterNode(444...446)((445...446), (444...445)) + BlockParameterNode(444...446)(:b, (445...446), (444...445)) ), nil, [:a, :r, :p, :b], @@ -524,7 +524,7 @@ ProgramNode(0...690)( nil, [], nil, - BlockParameterNode(467...469)((468...469), (467...468)) + BlockParameterNode(467...469)(:b, (468...469), (467...468)) ), nil, [:a, :o, :b], @@ -550,7 +550,7 @@ ProgramNode(0...690)( RestParameterNode(490...492)((490...491), (491...492)), [], nil, - BlockParameterNode(494...496)((495...496), (494...495)) + BlockParameterNode(494...496)(:b, (495...496), (494...495)) ), nil, [:a, :o, :r, :b], @@ -576,7 +576,7 @@ ProgramNode(0...690)( RestParameterNode(517...519)((517...518), (518...519)), [], nil, - BlockParameterNode(524...526)((525...526), (524...525)) + BlockParameterNode(524...526)(:b, (525...526), (524...525)) ), nil, [:a, :o, :r, :p, :b], @@ -602,7 +602,7 @@ ProgramNode(0...690)( nil, [], nil, - BlockParameterNode(550...552)((551...552), (550...551)) + BlockParameterNode(550...552)(:b, (551...552), (550...551)) ), nil, [:a, :o, :p, :b], @@ -673,7 +673,7 @@ ProgramNode(0...690)( nil, [], nil, - BlockParameterNode(609...611)((610...611), (609...610)) + BlockParameterNode(609...611)(:b, (610...611), (609...610)) ), nil, [:o, :b], @@ -699,7 +699,7 @@ ProgramNode(0...690)( RestParameterNode(629...631)((629...630), (630...631)), [], nil, - BlockParameterNode(633...635)((634...635), (633...634)) + BlockParameterNode(633...635)(:b, (634...635), (633...634)) ), nil, [:o, :r, :b], @@ -725,7 +725,7 @@ ProgramNode(0...690)( RestParameterNode(653...655)((653...654), (654...655)), [], nil, - BlockParameterNode(660...662)((661...662), (660...661)) + BlockParameterNode(660...662)(:b, (661...662), (660...661)) ), nil, [:o, :r, :p, :b], @@ -751,7 +751,7 @@ ProgramNode(0...690)( nil, [], nil, - BlockParameterNode(683...685)((684...685), (683...684)) + BlockParameterNode(683...685)(:b, (684...685), (683...684)) ), nil, [:o, :p, :b], diff --git a/test/yarp/snapshots/whitequark/blockarg.txt b/test/yarp/snapshots/whitequark/blockarg.txt index 544b14f8bbe1c0..4e31eac3d8bf36 100644 --- a/test/yarp/snapshots/whitequark/blockarg.txt +++ b/test/yarp/snapshots/whitequark/blockarg.txt @@ -11,7 +11,7 @@ ProgramNode(0...18)( nil, [], nil, - BlockParameterNode(6...12)((7...12), (6...7)) + BlockParameterNode(6...12)(:block, (7...12), (6...7)) ), nil, [:block], diff --git a/test/yarp/snapshots/whitequark/blockargs.txt b/test/yarp/snapshots/whitequark/blockargs.txt index 76f9dd4c5183cf..d716003643385c 100644 --- a/test/yarp/snapshots/whitequark/blockargs.txt +++ b/test/yarp/snapshots/whitequark/blockargs.txt @@ -46,7 +46,7 @@ ProgramNode(0...550)( nil, [], nil, - BlockParameterNode(21...23)((22...23), (21...22)) + BlockParameterNode(21...23)(:b, (22...23), (21...22)) ), [], (20...21), @@ -76,7 +76,7 @@ ProgramNode(0...550)( nil, [], KeywordRestParameterNode(32...37)((32...34), (34...37)), - BlockParameterNode(39...41)((40...41), (39...40)) + BlockParameterNode(39...41)(:b, (40...41), (39...40)) ), [], (31...32), @@ -106,7 +106,7 @@ ProgramNode(0...550)( RestParameterNode(50...51)((50...51), nil), [], nil, - BlockParameterNode(53...55)((54...55), (53...54)) + BlockParameterNode(53...55)(:b, (54...55), (53...54)) ), [], (49...50), @@ -136,7 +136,7 @@ ProgramNode(0...550)( RestParameterNode(64...66)((64...65), (65...66)), [], nil, - BlockParameterNode(71...73)((72...73), (71...72)) + BlockParameterNode(71...73)(:b, (72...73), (71...72)) ), [], (63...64), @@ -166,7 +166,7 @@ ProgramNode(0...550)( RestParameterNode(82...84)((82...83), (83...84)), [], nil, - BlockParameterNode(86...88)((87...88), (86...87)) + BlockParameterNode(86...88)(:b, (87...88), (86...87)) ), [], (81...82), @@ -300,7 +300,7 @@ ProgramNode(0...550)( nil, [], nil, - BlockParameterNode(145...147)((146...147), (145...146)) + BlockParameterNode(145...147)(:b, (146...147), (145...146)) ), [], (141...142), @@ -330,7 +330,7 @@ ProgramNode(0...550)( RestParameterNode(159...160)((159...160), nil), [], nil, - BlockParameterNode(162...164)((163...164), (162...163)) + BlockParameterNode(162...164)(:b, (163...164), (162...163)) ), [], (155...156), @@ -360,7 +360,7 @@ ProgramNode(0...550)( RestParameterNode(176...178)((176...177), (177...178)), [], nil, - BlockParameterNode(183...185)((184...185), (183...184)) + BlockParameterNode(183...185)(:b, (184...185), (183...184)) ), [], (172...173), @@ -390,7 +390,7 @@ ProgramNode(0...550)( RestParameterNode(197...199)((197...198), (198...199)), [], nil, - BlockParameterNode(201...203)((202...203), (201...202)) + BlockParameterNode(201...203)(:b, (202...203), (201...202)) ), [], (193...194), @@ -547,7 +547,7 @@ ProgramNode(0...550)( nil, [], nil, - BlockParameterNode(274...276)((275...276), (274...275)) + BlockParameterNode(274...276)(:b, (275...276), (274...275)) ), [], (265...266), @@ -582,7 +582,7 @@ ProgramNode(0...550)( RestParameterNode(293...295)((293...294), (294...295)), [], nil, - BlockParameterNode(300...302)((301...302), (300...301)) + BlockParameterNode(300...302)(:b, (301...302), (300...301)) ), [], (284...285), @@ -623,7 +623,7 @@ ProgramNode(0...550)( RestParameterNode(325...327)((325...326), (326...327)), [], nil, - BlockParameterNode(329...331)((330...331), (329...330)) + BlockParameterNode(329...331)(:b, (330...331), (329...330)) ), [], (310...311), @@ -658,7 +658,7 @@ ProgramNode(0...550)( nil, [], nil, - BlockParameterNode(351...353)((352...353), (351...352)) + BlockParameterNode(351...353)(:b, (352...353), (351...352)) ), [], (339...340), @@ -811,7 +811,7 @@ ProgramNode(0...550)( IntegerNode(408...409)() )], nil, - BlockParameterNode(411...413)((412...413), (411...412)) + BlockParameterNode(411...413)(:b, (412...413), (411...412)) ), [], (402...403), @@ -848,7 +848,7 @@ ProgramNode(0...550)( IntegerNode(435...436)() )], KeywordRestParameterNode(438...443)((438...440), (440...443)), - BlockParameterNode(445...447)((446...447), (445...446)) + BlockParameterNode(445...447)(:b, (446...447), (445...446)) ), [], (421...422), @@ -913,7 +913,7 @@ ProgramNode(0...550)( nil, [], nil, - BlockParameterNode(474...476)((475...476), (474...475)) + BlockParameterNode(474...476)(:b, (475...476), (474...475)) ), [], (468...469), @@ -948,7 +948,7 @@ ProgramNode(0...550)( RestParameterNode(490...492)((490...491), (491...492)), [], nil, - BlockParameterNode(494...496)((495...496), (494...495)) + BlockParameterNode(494...496)(:b, (495...496), (494...495)) ), [], (484...485), @@ -983,7 +983,7 @@ ProgramNode(0...550)( RestParameterNode(510...512)((510...511), (511...512)), [], nil, - BlockParameterNode(517...519)((518...519), (517...518)) + BlockParameterNode(517...519)(:b, (518...519), (517...518)) ), [], (504...505), @@ -1018,7 +1018,7 @@ ProgramNode(0...550)( nil, [], nil, - BlockParameterNode(536...538)((537...538), (536...537)) + BlockParameterNode(536...538)(:b, (537...538), (536...537)) ), [], (527...528), diff --git a/yarp/config.yml b/yarp/config.yml index 164e96101f5cb7..5ccdabab16cda9 100644 --- a/yarp/config.yml +++ b/yarp/config.yml @@ -549,6 +549,8 @@ nodes: ^^^^^^^^^^^^^^ - name: BlockParameterNode fields: + - name: name + type: constant? - name: name_loc type: location? - name: operator_loc diff --git a/yarp/templates/ext/yarp/api_node.c.erb b/yarp/templates/ext/yarp/api_node.c.erb index c3a232ec5fa468..8fb2d2e507c12c 100644 --- a/yarp/templates/ext/yarp/api_node.c.erb +++ b/yarp/templates/ext/yarp/api_node.c.erb @@ -154,6 +154,8 @@ yp_ast_new(yp_parser_t *parser, yp_node_t *node, rb_encoding *encoding) { argv[<%= index %>] = yp_string_new(&cast-><%= field.name %>, encoding); <%- when YARP::ConstantField -%> argv[<%= index %>] = rb_id2sym(constants[cast-><%= field.name %> - 1]); + <%- when YARP::OptionalConstantField -%> + argv[<%= index %>] = cast-><%= field.name %> == 0 ? Qnil : rb_id2sym(constants[cast-><%= field.name %> - 1]); <%- when YARP::ConstantListField -%> argv[<%= index %>] = rb_ary_new_capa(cast-><%= field.name %>.size); for (size_t index = 0; index < cast-><%= field.name %>.size; index++) { diff --git a/yarp/templates/include/yarp/ast.h.erb b/yarp/templates/include/yarp/ast.h.erb index 82fb7584406370..09841408eb5c33 100644 --- a/yarp/templates/include/yarp/ast.h.erb +++ b/yarp/templates/include/yarp/ast.h.erb @@ -95,7 +95,7 @@ typedef struct yp_<%= node.human %> { <%= case field when YARP::NodeField, YARP::OptionalNodeField then "struct #{field.c_type} *#{field.name}" when YARP::NodeListField then "struct yp_node_list #{field.name}" - when YARP::ConstantField then "yp_constant_id_t #{field.name}" + when YARP::ConstantField, YARP::OptionalConstantField then "yp_constant_id_t #{field.name}" when YARP::ConstantListField then "yp_constant_id_list_t #{field.name}" when YARP::StringField then "yp_string_t #{field.name}" when YARP::LocationField, YARP::OptionalLocationField then "yp_location_t #{field.name}" diff --git a/yarp/templates/lib/yarp/node.rb.erb b/yarp/templates/lib/yarp/node.rb.erb index 105830836f8a1d..0d404063601d0f 100644 --- a/yarp/templates/lib/yarp/node.rb.erb +++ b/yarp/templates/lib/yarp/node.rb.erb @@ -112,7 +112,7 @@ module YARP inspector << "<%= pointer %><%= field.name %>:\n" inspector << <%= field.name %>.inspect(inspector.child_inspector("<%= preadd %>")).delete_prefix(inspector.prefix) end - <%- when YARP::ConstantField, YARP::StringField, YARP::UInt32Field -%> + <%- when YARP::ConstantField, YARP::OptionalConstantField, YARP::StringField, YARP::UInt32Field -%> inspector << "<%= pointer %><%= field.name %>: #{<%= field.name %>.inspect}\n" <%- when YARP::FlagsField -%> <%- flag = flags.find { |flag| flag.name == field.kind }.tap { |flag| raise unless flag } -%> diff --git a/yarp/templates/lib/yarp/serialize.rb.erb b/yarp/templates/lib/yarp/serialize.rb.erb index ee0b8666bfd3e7..2f6d6421a9f50f 100644 --- a/yarp/templates/lib/yarp/serialize.rb.erb +++ b/yarp/templates/lib/yarp/serialize.rb.erb @@ -152,8 +152,7 @@ module YARP load_location if io.getbyte != 0 end - def load_constant - index = load_varint - 1 + def load_constant(index) constant = constant_pool[index] unless constant @@ -169,6 +168,15 @@ module YARP constant end + def load_required_constant + load_constant(load_varint - 1) + end + + def load_optional_constant + index = load_varint + load_constant(index - 1) if index != 0 + end + def load_node type = io.getbyte location = load_location @@ -185,8 +193,9 @@ module YARP when YARP::OptionalNodeField then "load_optional_node" when YARP::StringField then "load_string" when YARP::NodeListField then "Array.new(load_varint) { load_node }" - when YARP::ConstantField then "load_constant" - when YARP::ConstantListField then "Array.new(load_varint) { load_constant }" + when YARP::ConstantField then "load_required_constant" + when YARP::OptionalConstantField then "load_optional_constant" + when YARP::ConstantListField then "Array.new(load_varint) { load_required_constant }" when YARP::LocationField then "load_location" when YARP::OptionalLocationField then "load_optional_location" when YARP::UInt32Field, YARP::FlagsField then "load_varint" diff --git a/yarp/templates/src/node.c.erb b/yarp/templates/src/node.c.erb index 732749394a72ec..9f231239142dcf 100644 --- a/yarp/templates/src/node.c.erb +++ b/yarp/templates/src/node.c.erb @@ -55,12 +55,12 @@ yp_node_destroy(yp_parser_t *parser, yp_node_t *node) { <%- nodes.each do |node| -%> #line <%= __LINE__ + 1 %> "<%= File.basename(__FILE__) %>" case <%= node.type %>: { - <%- if node.fields.any? { |field| ![YARP::LocationField, YARP::OptionalLocationField, YARP::UInt32Field, YARP::FlagsField, YARP::ConstantField].include?(field.class) } -%> + <%- if node.fields.any? { |field| ![YARP::LocationField, YARP::OptionalLocationField, YARP::UInt32Field, YARP::FlagsField, YARP::ConstantField, YARP::OptionalConstantField].include?(field.class) } -%> yp_<%= node.human %>_t *cast = (yp_<%= node.human %>_t *) node; <%- end -%> <%- node.fields.each do |field| -%> <%- case field -%> - <%- when YARP::LocationField, YARP::OptionalLocationField, YARP::UInt32Field, YARP::FlagsField, YARP::ConstantField -%> + <%- when YARP::LocationField, YARP::OptionalLocationField, YARP::UInt32Field, YARP::FlagsField, YARP::ConstantField, YARP::OptionalConstantField -%> <%- when YARP::NodeField -%> yp_node_destroy(parser, (yp_node_t *)cast-><%= field.name %>); <%- when YARP::OptionalNodeField -%> @@ -104,7 +104,7 @@ yp_node_memsize_node(yp_node_t *node, yp_memsize_t *memsize) { memsize->memsize += sizeof(*cast); <%- node.fields.each do |field| -%> <%- case field -%> - <%- when YARP::ConstantField, YARP::UInt32Field, YARP::FlagsField, YARP::LocationField, YARP::OptionalLocationField -%> + <%- when YARP::ConstantField, YARP::OptionalConstantField, YARP::UInt32Field, YARP::FlagsField, YARP::LocationField, YARP::OptionalLocationField -%> <%- when YARP::NodeField -%> yp_node_memsize_node((yp_node_t *)cast-><%= field.name %>, memsize); <%- when YARP::OptionalNodeField -%> diff --git a/yarp/templates/src/prettyprint.c.erb b/yarp/templates/src/prettyprint.c.erb index 774720a24502b9..796d8ccafb9dd0 100644 --- a/yarp/templates/src/prettyprint.c.erb +++ b/yarp/templates/src/prettyprint.c.erb @@ -49,6 +49,14 @@ prettyprint_node(yp_buffer_t *buffer, yp_parser_t *parser, yp_node_t *node) { char <%= field.name %>_buffer[12]; snprintf(<%= field.name %>_buffer, sizeof(<%= field.name %>_buffer), "%u", ((yp_<%= node.human %>_t *)node)-><%= field.name %>); yp_buffer_append_str(buffer, <%= field.name %>_buffer, strlen(<%= field.name %>_buffer)); + <%- when YARP::OptionalConstantField -%> + if (((yp_<%= node.human %>_t *)node)-><%= field.name %> == 0) { + yp_buffer_append_str(buffer, "nil", 3); + } else { + char <%= field.name %>_buffer[12]; + snprintf(<%= field.name %>_buffer, sizeof(<%= field.name %>_buffer), "%u", ((yp_<%= node.human %>_t *)node)-><%= field.name %>); + yp_buffer_append_str(buffer, <%= field.name %>_buffer, strlen(<%= field.name %>_buffer)); + } <%- when YARP::ConstantListField -%> yp_buffer_append_str(buffer, "[", 1); for (uint32_t index = 0; index < ((yp_<%= node.human %>_t *)node)-><%= field.name %>.size; index++) { diff --git a/yarp/templates/src/serialize.c.erb b/yarp/templates/src/serialize.c.erb index 4816f154ba1ef7..8e0b0905dcc5d1 100644 --- a/yarp/templates/src/serialize.c.erb +++ b/yarp/templates/src/serialize.c.erb @@ -86,7 +86,7 @@ yp_serialize_node(yp_parser_t *parser, yp_node_t *node, yp_buffer_t *buffer) { for (uint32_t index = 0; index < <%= field.name %>_size; index++) { yp_serialize_node(parser, (yp_node_t *) ((yp_<%= node.human %>_t *)node)-><%= field.name %>.nodes[index], buffer); } - <%- when YARP::ConstantField -%> + <%- when YARP::ConstantField, YARP::OptionalConstantField -%> yp_buffer_append_u32(buffer, yp_sizet_to_u32(((yp_<%= node.human %>_t *)node)-><%= field.name %>)); <%- when YARP::ConstantListField -%> uint32_t <%= field.name %>_size = yp_sizet_to_u32(((yp_<%= node.human %>_t *)node)-><%= field.name %>.size); diff --git a/yarp/templates/template.rb b/yarp/templates/template.rb index d73951cb538c5d..928ade61a6e601 100755 --- a/yarp/templates/template.rb +++ b/yarp/templates/template.rb @@ -85,6 +85,18 @@ def java_type end end + # This represents a field on a node that is the ID of a string interned + # through the parser's constant pool and can be optionally null. + class OptionalConstantField < Field + def rbs_class + "Symbol?" + end + + def java_type + "byte[]" + end + end + # This represents a field on a node that is a list of IDs that are associated # with strings interned through the parser's constant pool. class ConstantListField < Field @@ -195,6 +207,7 @@ def field_type_for(name) when "node[]" then NodeListField when "string" then StringField when "constant" then ConstantField + when "constant?" then OptionalConstantField when "constant[]" then ConstantListField when "location" then LocationField when "location?" then OptionalLocationField @@ -275,7 +288,8 @@ def template(name, write_to: nil) HEADING - heading = if File.extname(filepath.gsub(".erb", "")) == ".rb" + heading = + if File.extname(filepath.gsub(".erb", "")) == ".rb" ruby_heading else non_ruby_heading diff --git a/yarp/yarp.c b/yarp/yarp.c index 4e291637f1c056..2bce80abade61f 100644 --- a/yarp/yarp.c +++ b/yarp/yarp.c @@ -437,6 +437,13 @@ yp_parser_constant_id_token(yp_parser_t *parser, const yp_token_t *token) { return yp_parser_constant_id_location(parser, token->start, token->end); } +// Retrieve the constant pool id for the given token. If the token is not +// provided, then return 0. +static inline yp_constant_id_t +yp_parser_optional_constant_id_token(yp_parser_t *parser, const yp_token_t *token) { + return token->type == YP_TOKEN_NOT_PROVIDED ? 0 : yp_parser_constant_id_token(parser, token); +} + // Mark any range nodes in this subtree as flipflops. static void yp_flip_flop(yp_node_t *node) { @@ -1134,6 +1141,7 @@ yp_block_parameter_node_create(yp_parser_t *parser, const yp_token_t *name, cons .end = (name->type == YP_TOKEN_NOT_PROVIDED ? operator->end : name->end) }, }, + .name = yp_parser_optional_constant_id_token(parser, name), .name_loc = YP_OPTIONAL_LOCATION_TOKEN_VALUE(name), .operator_loc = YP_LOCATION_TOKEN_VALUE(operator) }; From 12102d101af258d7a3e9695b736a189cd3658df1 Mon Sep 17 00:00:00 2001 From: Peter Zhu Date: Wed, 6 Sep 2023 14:20:23 -0400 Subject: [PATCH 92/95] Fix crash in WeakMap during compaction WeakMap can crash during compaction because the st_insert could allocate memory. --- gc.c | 17 ++++------------- internal/gc.h | 11 +++++++++++ test/ruby/test_weakmap.rb | 12 ++++++++++++ weakmap.c | 6 +++++- 4 files changed, 32 insertions(+), 14 deletions(-) diff --git a/gc.c b/gc.c index c8f570940cf040..c71fdd10ed91ca 100644 --- a/gc.c +++ b/gc.c @@ -9799,15 +9799,6 @@ gc_is_moveable_obj(rb_objspace_t *objspace, VALUE obj) return FALSE; } -/* Used in places that could malloc, which can cause the GC to run. We need to - * temporarily disable the GC to allow the malloc to happen. */ -#define COULD_MALLOC_REGION_START() \ - GC_ASSERT(during_gc); \ - VALUE _already_disabled = rb_gc_disable_no_rest(); \ - -#define COULD_MALLOC_REGION_END() \ - if (_already_disabled == Qfalse) rb_objspace_gc_enable(objspace); - static VALUE gc_move(rb_objspace_t *objspace, VALUE scan, VALUE free, size_t src_slot_size, size_t slot_size) { @@ -9840,11 +9831,11 @@ gc_move(rb_objspace_t *objspace, VALUE scan, VALUE free, size_t src_slot_size, s if (FL_TEST((VALUE)src, FL_EXIVAR)) { /* Resizing the st table could cause a malloc */ - COULD_MALLOC_REGION_START(); + DURING_GC_COULD_MALLOC_REGION_START(); { rb_mv_generic_ivar((VALUE)src, (VALUE)dest); } - COULD_MALLOC_REGION_END(); + DURING_GC_COULD_MALLOC_REGION_END(); } st_data_t srcid = (st_data_t)src, id; @@ -9854,12 +9845,12 @@ gc_move(rb_objspace_t *objspace, VALUE scan, VALUE free, size_t src_slot_size, s if (st_lookup(objspace->obj_to_id_tbl, srcid, &id)) { gc_report(4, objspace, "Moving object with seen id: %p -> %p\n", (void *)src, (void *)dest); /* Resizing the st table could cause a malloc */ - COULD_MALLOC_REGION_START(); + DURING_GC_COULD_MALLOC_REGION_START(); { st_delete(objspace->obj_to_id_tbl, &srcid, 0); st_insert(objspace->obj_to_id_tbl, (st_data_t)dest, id); } - COULD_MALLOC_REGION_END(); + DURING_GC_COULD_MALLOC_REGION_END(); } /* Move the object */ diff --git a/internal/gc.h b/internal/gc.h index 28b82f4196edf6..f8f88a41cba39c 100644 --- a/internal/gc.h +++ b/internal/gc.h @@ -189,6 +189,17 @@ struct rb_objspace; /* in vm_core.h */ # define SIZE_POOL_COUNT 5 #endif +/* Used in places that could malloc during, which can cause the GC to run. We + * need to temporarily disable the GC to allow the malloc to happen. + * Allocating memory during GC is a bad idea, so use this only when absolutely + * necessary. */ +#define DURING_GC_COULD_MALLOC_REGION_START() \ + assert(rb_during_gc()); \ + VALUE _already_disabled = rb_gc_disable_no_rest() + +#define DURING_GC_COULD_MALLOC_REGION_END() \ + if (_already_disabled == Qfalse) rb_gc_enable() + typedef struct ractor_newobj_size_pool_cache { struct RVALUE *freelist; struct heap_page *using_page; diff --git a/test/ruby/test_weakmap.rb b/test/ruby/test_weakmap.rb index b42787ad5e2a3d..a30004bce3be1c 100644 --- a/test/ruby/test_weakmap.rb +++ b/test/ruby/test_weakmap.rb @@ -223,6 +223,18 @@ def test_compaction assert_equal(val, wm[key]) end; + + assert_separately(["-W0"], <<-'end;') + wm = ObjectSpace::WeakMap.new + + ary = 10_000.times.map do + o = Object.new + wm[o] = 1 + o + end + + GC.verify_compaction_references(expand_heap: true, toward: :empty) + end; end def test_replaced_values_bug_19531 diff --git a/weakmap.c b/weakmap.c index d79f5b3f941615..3c7fd43f9bc45d 100644 --- a/weakmap.c +++ b/weakmap.c @@ -122,7 +122,11 @@ wmap_compact_table_i(st_data_t key, st_data_t val, st_data_t data) if (key_obj != new_key_obj) { *(VALUE *)key = new_key_obj; - st_insert(table, key, val); + DURING_GC_COULD_MALLOC_REGION_START(); + { + st_insert(table, key, val); + } + DURING_GC_COULD_MALLOC_REGION_END(); return ST_DELETE; } From fdf7aad902ccc9e2f32e4b6b3e21fb68a8788d16 Mon Sep 17 00:00:00 2001 From: Andy Waite Date: Tue, 29 Aug 2023 16:42:43 -0400 Subject: [PATCH 93/95] [ruby/yarp] Fix `Location#end_column` https://github.com/ruby/yarp/commit/00e4711026 --- lib/yarp.rb | 2 +- test/yarp/location_test.rb | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/yarp.rb b/lib/yarp.rb index 0dab1515fc3512..769b149bcabf55 100644 --- a/lib/yarp.rb +++ b/lib/yarp.rb @@ -95,7 +95,7 @@ def start_column # The column number in bytes where this location ends from the start of the # line. def end_column - source.column(end_offset - 1) + source.column(end_offset) end def deconstruct_keys(keys) diff --git a/test/yarp/location_test.rb b/test/yarp/location_test.rb index 4509fc0cf5d9d2..d86afb0b3bb1a4 100644 --- a/test/yarp/location_test.rb +++ b/test/yarp/location_test.rb @@ -817,6 +817,14 @@ def assert_location(kind, source, expected = 0...source.length) node = result.value.statements.body.last node = yield node if block_given? + if expected.begin == 0 + assert_equal 0, node.location.start_column + end + + if expected.end == source.length + assert_equal source.split("\n").last.length, node.location.end_column + end + assert_kind_of kind, node assert_equal expected.begin, node.location.start_offset assert_equal expected.end, node.location.end_offset From f1422e4cecdbff12148b4b94e1f00646251f2dae Mon Sep 17 00:00:00 2001 From: Alan Wu Date: Wed, 6 Sep 2023 15:32:36 -0400 Subject: [PATCH 94/95] YJIT: Different comment when only setting ec->cfp [ci skip] --- yjit/src/codegen.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/yjit/src/codegen.rs b/yjit/src/codegen.rs index f36d52a6e33824..92dd239c8b9f66 100644 --- a/yjit/src/codegen.rs +++ b/yjit/src/codegen.rs @@ -5226,12 +5226,13 @@ fn gen_push_frame( let ep = asm.sub(sp, SIZEOF_VALUE.into()); asm.mov(cfp_opnd(RUBY_OFFSET_CFP_EP), ep); - asm.comment("switch to new CFP"); let new_cfp = asm.lea(cfp_opnd(0)); if set_sp_cfp { + asm.comment("switch to new CFP"); asm.mov(CFP, new_cfp); asm.store(Opnd::mem(64, EC, RUBY_OFFSET_EC_CFP), CFP); } else { + asm.comment("set ec->cfp"); asm.store(Opnd::mem(64, EC, RUBY_OFFSET_EC_CFP), new_cfp); } } From acd626a58345247a2d98c3cff1233008a6e81c61 Mon Sep 17 00:00:00 2001 From: Vinicius Stock Date: Wed, 6 Sep 2023 15:21:07 -0400 Subject: [PATCH 95/95] [ruby/yarp] Consider source encoding for `slice` https://github.com/ruby/yarp/commit/8f59fc27cd Co-authored-by: Kevin Newton --- test/yarp/encoding_test.rb | 6 ++++++ yarp/extension.c | 2 +- yarp/extension.h | 2 +- yarp/templates/ext/yarp/api_node.c.erb | 6 +++--- yarp/templates/lib/yarp/serialize.rb.erb | 8 +++++++- 5 files changed, 18 insertions(+), 6 deletions(-) diff --git a/test/yarp/encoding_test.rb b/test/yarp/encoding_test.rb index 828b45be7302c3..8427bddcbefa58 100644 --- a/test/yarp/encoding_test.rb +++ b/test/yarp/encoding_test.rb @@ -96,5 +96,11 @@ def test_first_lexed_token encoding = YARP.lex("# encoding: ascii-8bit").value[0][0].value.encoding assert_equal Encoding.find("ascii-8bit"), encoding end + + def test_slice_encoding + slice = YARP.parse("# encoding: Shift_JIS\nア").value.slice + assert_equal (+"ア").force_encoding(Encoding::SHIFT_JIS), slice + assert_equal Encoding::SHIFT_JIS, slice.encoding + end end end diff --git a/yarp/extension.c b/yarp/extension.c index de925f1509d7fd..8d36cd44272f02 100644 --- a/yarp/extension.c +++ b/yarp/extension.c @@ -347,7 +347,7 @@ parse_input(yp_string_t *input, const char *filepath) { yp_node_t *node = yp_parse(&parser); rb_encoding *encoding = rb_enc_find(parser.encoding.name); - VALUE source = yp_source_new(&parser); + VALUE source = yp_source_new(&parser, encoding); VALUE result_argv[] = { yp_ast_new(&parser, node, encoding), parser_comments(&parser, source), diff --git a/yarp/extension.h b/yarp/extension.h index ae7db77ca02da3..ccfb6f9454f173 100644 --- a/yarp/extension.h +++ b/yarp/extension.h @@ -7,7 +7,7 @@ #include #include "yarp.h" -VALUE yp_source_new(yp_parser_t *parser); +VALUE yp_source_new(yp_parser_t *parser, rb_encoding *encoding); VALUE yp_token_new(yp_parser_t *parser, yp_token_t *token, rb_encoding *encoding, VALUE source); VALUE yp_ast_new(yp_parser_t *parser, yp_node_t *node, rb_encoding *encoding); diff --git a/yarp/templates/ext/yarp/api_node.c.erb b/yarp/templates/ext/yarp/api_node.c.erb index 8fb2d2e507c12c..0d075112c8f96f 100644 --- a/yarp/templates/ext/yarp/api_node.c.erb +++ b/yarp/templates/ext/yarp/api_node.c.erb @@ -38,8 +38,8 @@ yp_string_new(yp_string_t *string, rb_encoding *encoding) { // Create a YARP::Source object from the given parser. VALUE -yp_source_new(yp_parser_t *parser) { - VALUE source = rb_str_new((const char *) parser->start, parser->end - parser->start); +yp_source_new(yp_parser_t *parser, rb_encoding *encoding) { + VALUE source = rb_enc_str_new((const char *) parser->start, parser->end - parser->start, encoding); VALUE offsets = rb_ary_new_capa(parser->newline_list.size); for (size_t index = 0; index < parser->newline_list.size; index++) { @@ -78,7 +78,7 @@ yp_node_stack_pop(yp_node_stack_node_t **stack) { VALUE yp_ast_new(yp_parser_t *parser, yp_node_t *node, rb_encoding *encoding) { - VALUE source = yp_source_new(parser); + VALUE source = yp_source_new(parser, encoding); ID *constants = calloc(parser->constant_pool.size, sizeof(ID)); for (size_t index = 0; index < parser->constant_pool.capacity; index++) { diff --git a/yarp/templates/lib/yarp/serialize.rb.erb b/yarp/templates/lib/yarp/serialize.rb.erb index 2f6d6421a9f50f..c8d7f422cdb5ba 100644 --- a/yarp/templates/lib/yarp/serialize.rb.erb +++ b/yarp/templates/lib/yarp/serialize.rb.erb @@ -18,7 +18,13 @@ module YARP PATCH_VERSION = 0 def self.load(input, serialized) - Loader.new(Source.new(input), serialized).load_result + input = input.dup + source = Source.new(input) + loader = Loader.new(source, serialized) + result = loader.load_result + + input.force_encoding(loader.encoding) + result end def self.load_tokens(source, serialized)