diff options
author | HASUMI Hitoshi <[email protected]> | 2024-04-26 21:43:35 +0900 |
---|---|---|
committer | Yuichiro Kaneko <[email protected]> | 2024-04-27 12:08:26 +0900 |
commit | 55a402bb759597487905a94d5b1bbff4a672499c (patch) | |
tree | 9a6309c61f0f6871de0d47c135d4270bb270dfc7 /ruby_parser.c | |
parent | bf1f16ef47966e33401e5b9656a4ae4152dd1e60 (diff) |
Add line_count field to rb_ast_body_t
This patch adds `int line_count` field to `rb_ast_body_t` structure.
Instead, we no longer cast `script_lines` to Fixnum.
## Background
Ref https://github.com/ruby/ruby/pull/10618
In the PR above, we have decoupled IMEMO from `rb_ast_t`.
This means we could lift the five-words-restriction of the structure
that forced us to unionize `rb_ast_t *` and `FIXNUM` in one field.
## Relating refactor
- Remove the second parameter of `rb_ruby_ast_new()` function
## Attention
I will remove a code that assigns -1 to line_count, in `rb_binding_add_dynavars()`
of vm.c, because I don't think it is necessary.
But I will make another PR for this so that we can atomically revert
in case I was wrong (See the comment on the code)
Diffstat (limited to 'ruby_parser.c')
-rw-r--r-- | ruby_parser.c | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/ruby_parser.c b/ruby_parser.c index b72f875155..63cd8df814 100644 --- a/ruby_parser.c +++ b/ruby_parser.c @@ -893,6 +893,7 @@ VALUE rb_parser_build_script_lines_from(rb_parser_ary_t *lines) { int i; + if (!lines) return Qnil; if (lines->data_type != PARSER_ARY_DATA_SCRIPT_LINE) { rb_bug("unexpected rb_parser_ary_data_type (%d) for script lines", lines->data_type); } @@ -1115,7 +1116,7 @@ parser_aset_script_lines_for(VALUE path, rb_parser_ary_t *lines) { VALUE hash, script_lines; ID script_lines_id; - if (NIL_P(path) || !lines || FIXNUM_P((VALUE)lines)) return; + if (NIL_P(path) || !lines) return; CONST_ID(script_lines_id, "SCRIPT_LINES__"); if (!rb_const_defined_at(rb_cObject, script_lines_id)) return; hash = rb_const_get_at(rb_cObject, script_lines_id); @@ -1126,7 +1127,7 @@ parser_aset_script_lines_for(VALUE path, rb_parser_ary_t *lines) } VALUE -rb_ruby_ast_new(const NODE *const root, rb_parser_ary_t *script_lines) +rb_ruby_ast_new(const NODE *const root) { VALUE vast = ast_alloc(); rb_ast_t *ast = DATA_PTR(vast); @@ -1134,7 +1135,8 @@ rb_ruby_ast_new(const NODE *const root, rb_parser_ary_t *script_lines) .root = root, .frozen_string_literal = -1, .coverage_enabled = -1, - .script_lines = script_lines + .script_lines = NULL, + .line_count = 0, }; return vast; } |