1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00
Commit graph

2132 commits

Author SHA1 Message Date
Yusuke Endoh
fb01411ae8 node.h: Reduce struct size to fit with Ruby object size (five VALUEs)
by merging `rb_ast_body_t#line_count` and `#script_lines`.

Fortunately `line_count == RARRAY_LEN(script_lines)` was always
satisfied. When script_lines is saved, it has an array of lines, and
when not saved, it has a Fixnum that represents the old line_count.
2021-06-18 02:34:27 +09:00
Yusuke Endoh
acae5f363d ast.rb: RubyVM::AST.parse and .of accepts save_script_lines: true
This option makes the parser keep the original source as an array of
the original code lines. This feature exploits the mechanism of
`SCRIPT_LINES__` but records only the specified code that is passed to
RubyVM::AST.of or .parse, instead of recording all parsed program texts.
2021-06-18 02:34:27 +09:00
Nobuyoshi Nakada
e4f891ce8d
Adjust styles [ci skip]
* --braces-after-func-def-line
* --dont-cuddle-else
* --procnames-start-lines
* --space-after-for
* --space-after-if
* --space-after-while
2021-06-17 10:13:40 +09:00
Yusuke Endoh
70313ec01a parse.y: Fix the location of a target constant of OP_CDECL
```
p RubyVM::AbstractSyntaxTree.parse("::Foo += 1").children
 #=> before: [[], nil, (OP_CDECL@1:0-1:10 (COLON3@1:0-1:10 :Foo) :+ (LIT@1:9-1:10 1))]
 #=> after:  [[], nil, (OP_CDECL@1:0-1:10 (COLON3@1:0-1:5 :Foo) :+ (LIT@1:9-1:10 1))]
```
2021-06-14 10:02:02 +09:00
Nobuyoshi Nakada
9f3888d6a3 Warn more duplicate literal hash keys
Following non-special_const literals:
* T_REGEXP
2021-06-03 15:11:18 +09:00
Nobuyoshi Nakada
37eb5e7439 Warn more duplicate literal hash keys
Following non-special_const literals:
* T_BIGNUM
* T_FLOAT (non-flonum)
* T_RATIONAL
* T_COMPLEX
2021-06-03 15:11:18 +09:00
Nobuyoshi Nakada
50a534a152 ripper: wrap endless method in bodystmt [Bug ] 2021-05-21 18:28:24 +09:00
Nobuyoshi Nakada
110f242ef9
Also \U after control/meta is invalid [Bug ]
As well as `\u`, `\U` should be invalid there too.
And highlight including `u`/`U` not only the backslash before it.
2021-05-13 12:54:56 +09:00
Jeremy Evans
11ae581a4a Fix handling of control/meta escapes in literal regexps
Ruby uses a recursive algorithm for handling control/meta escapes
in strings (read_escape).  However, the equivalent code for regexps
(tokadd_escape) in did not use a recursive algorithm.  Due to this,
Handling of control/meta escapes in regexp did not have the same
behavior as in strings, leading to behavior such as the following
returning nil:

```ruby
/\c\xFF/ =~ "\c\xFF"
```

Switch the code for handling \c, \C and \M in literal regexps to
use the same code as for strings (read_escape), to keep behavior
consistent between the two.

Fixes [Bug ]
2021-05-12 18:55:43 -07:00
Yusuke Endoh
31794d2e73 parse.y: Allow "command" syntax in endless method definition
This change allows `def hello = puts "Hello"` without parentheses.

Note that `private def hello = puts "Hello"` does not parse for
technical reason.

[Feature ]
2021-05-13 00:14:50 +09:00
Yusuke Endoh
d405b1a878 Make imemo_ast WB-protected again
by firing the write barrier of imemo_ast after nd_lit is modified.
This will fix the issue of https://github.com/ruby/ruby/pull/4416 more
gracefully.
2021-04-27 17:05:19 +09:00
Nobuyoshi Nakada
607aa11711
Ignore useless separators preceding a file encoding comment 2021-03-23 17:20:19 +09:00
Kazuki Tsujimoto
21863470d9
Pattern matching pin operator against expression [Feature ]
This commit is based on the patch by @nobu.
2021-03-21 15:14:31 +09:00
Takashi Tamura
990b54054d Add a missing semicolon. 2021-02-15 10:46:29 +09:00
Nobuyoshi Nakada
b091889ed6 Removed YYUSE [Bug ]
Although it was used just to suppress an "unsed argument" warning
in the same manner as other bison-provided functions, it has been
dropped since Bision 3.7.5.  And we always suppress that
warnings.
2021-01-26 21:57:09 +09:00
Nobuyoshi Nakada
6bcc4664bd
Return new NODE_LIT
As NODE_ZLIST/NODE_LIST are not markable, cannot be reused as
NODE_LIT.
2021-01-14 16:15:25 +09:00
Nobuyoshi Nakada
bb40c5cbe9
Ensure symbol list node is either NODE_STR or NODE_DSTR 2021-01-14 16:13:26 +09:00
Nobuyoshi Nakada
0036648a42
Capture to reserved name variables if already defined [Bug ] 2021-01-13 21:16:00 +09:00
Nobuhiro IMAI
7ff0e93f96
parse.y: handle "duplicated argument name" appropriately on ripper.y
refs: 733ed1e184
2021-01-09 13:33:33 +09:00
Nobuyoshi Nakada
35c3a24c8c
Fixed error message when % at EOF 2021-01-04 12:11:37 +09:00
Masataka Pocke Kuwabara
de5f8a92d5
Make args info for RubyVM::AST to available on endless method without parens
Problem
===

Arguments information is missing for endless method without parens.
For example:

```ruby
# ok
pp RubyVM::AbstractSyntaxTree.parse(<<~RUBY).children[2]
  def x() = 42
RUBY
# => (DEFN@1:0-1:12
#     mid: :x
#     body:
#       (SCOPE@1:0-1:12
#        tbl: []
#        args:
#          (ARGS@1:5-1:6
#           pre_num: 0
#           pre_init: nil
#           opt: nil
#           first_post: nil
#           post_num: 0
#           post_init: nil
#           rest: nil
#           kw: nil
#           kwrest: nil
#           block: nil)
#        body: (LIT@1:10-1:12 42)))

# ok
pp RubyVM::AbstractSyntaxTree.parse(<<~RUBY).children[2]
  def x() 42 end
RUBY
# => (DEFN@1:0-1:14
#     mid: :x
#     body:
#       (SCOPE@1:0-1:14
#        tbl: []
#        args:
#          (ARGS@1:5-1:6
#           pre_num: 0
#           pre_init: nil
#           opt: nil
#           first_post: nil
#           post_num: 0
#           post_init: nil
#           rest: nil
#           kw: nil
#           kwrest: nil
#           block: nil)
#        body: (LIT@1:8-1:10 42)))

# It has a problem, the `args` is nil
pp RubyVM::AbstractSyntaxTree.parse(<<~RUBY).children[2]
  def x = 42
RUBY
# => (DEFN@1:0-1:10
#     mid: :x
#     body: (SCOPE@1:0-1:10 tbl: [] args: nil body: (LIT@1:8-1:10 42)))
```

It causes an error if a program expects `args` node exists.
For example: https://github.com/ruby/rbs/issues/551

Solution
====

Call `new_args` on this case.
2021-01-01 14:25:08 +09:00
Koichi Sasada
6f29716f9f shareable_constant_value: experimental_copy
"experimental_everything" makes the assigned value, it means
the assignment change the state of assigned value.
"experimental_copy" tries to make a deep copy and make copyied object
sharable.
2020-12-24 14:28:47 +09:00
Nobuyoshi Nakada
4a8ff22f0c
Reset paren_nest at tAREF and tASET [Bug ] 2020-12-24 01:39:52 +09:00
Nobuyoshi Nakada
8a1e12499b Ensure non-literal expressions shareable if leteral 2020-12-23 13:50:42 +09:00
Nobuyoshi Nakada
0c450b8647 begin ... end is not a literal 2020-12-23 13:50:42 +09:00
Nobuyoshi Nakada
7a094146e6 Changed shareable literal semantics [Feature ]
When `literal`, check if the literal about to be assigned to a
constant is ractor-shareable, otherwise raise `Ractor::Error` at
runtime instead of `SyntaxError`.
2020-12-23 13:50:42 +09:00
Nobuyoshi Nakada
733ed1e184 ripper: fix bad label parameter handling [Bug ] 2020-12-23 09:56:35 +09:00
Nobuyoshi Nakada
b2acae3274
Reduced ID caches
NEW_GASGN and NEW_GVAR evaluate `id` argument twice.
2020-12-20 03:10:30 +09:00
Jeremy Evans
7e2dbbda35 Use category: :experimental in warnings that are related to experimental features
This adds rb_category_compile_warn in order to emit compiler warnings
with categories.  Note that Ripper currently ignores the category
for these warnings, but by default it ignores the warnings completely,
so this shouldn't matter.
2020-12-18 09:54:11 -08:00
Nobuyoshi Nakada
19a98a8791
Fixed not to make non-literal expression shareable [Feature ]
Non-literal expression which is not a part of a literal expression
is not a subject of `shareable_literal_value: literal`.
2020-12-19 00:34:14 +09:00
Nobuyoshi Nakada
8e03e3b0ba
Drop token info also for endless singleton method definition 2020-12-18 15:16:30 +09:00
Nobuyoshi Nakada
9c859f4b3c
Ripper: Pass callback result to alias_error as well as other errors
[Bug ]
2020-12-16 22:53:43 +09:00
Nobuyoshi Nakada
47328ad217
Ripper: Fixed erred token on wrong alias [Bug ] 2020-12-16 21:08:33 +09:00
Nobuyoshi Nakada
e0bdd54348 Ripper: Refined error callbacks [Bug ] 2020-12-15 21:36:23 +09:00
Nobuyoshi Nakada
3323174727 Support shareable_constant_value: literal 2020-12-14 19:19:16 +09:00
Nobuyoshi Nakada
89e489d51d Make shareable_constant_value tri-state 2020-12-14 19:19:16 +09:00
Nobuyoshi Nakada
7060aeedbd shareable_constant_value: is effective only in comment-only line 2020-12-14 19:19:16 +09:00
Nobuyoshi Nakada
070a990bcb Save and pass lex_context wholely 2020-12-14 19:19:16 +09:00
Nobuyoshi Nakada
dc1cc33d69 Determine shareable-ness after assignment operator 2020-12-14 19:19:16 +09:00
Nobuyoshi Nakada
60f0c376f7 Implemented shareable_constant_value op_asgn 2020-12-14 19:19:16 +09:00
Nobuyoshi Nakada
65450e8f7d Call FrozenCore.make_shareable 2020-12-14 19:19:16 +09:00
Nobuyoshi Nakada
f43c71abe0 Implemented shareable_constant_value
It does shallow freeze only for now.
2020-12-14 19:19:16 +09:00
Nobuyoshi Nakada
b1bd223085 Support shareable_constant_value pragma 2020-12-14 19:19:16 +09:00
Kazuki Tsujimoto
88f3ce12d3
Reintroduce expr in pat [Feature ] 2020-12-13 11:51:49 +09:00
Kazuki Tsujimoto
a8cf526ae9
Don't emit warning when the pattern of one-line pattern matching is just a variable pattern
https://github.com/ruby/dev-meeting-log/blob/master/DevelopersMeeting20201210Japan.md#feature-17371-reintroduce-expr-in-pat-ktsj
2020-12-13 11:51:49 +09:00
Koichi Sasada
5e3259ea74 fix public interface
To make some kind of Ractor related extensions, some functions
should be exposed.

* include/ruby/thread_native.h
  * rb_native_mutex_*
  * rb_native_cond_*
* include/ruby/ractor.h
  * RB_OBJ_SHAREABLE_P(obj)
  * rb_ractor_shareable_p(obj)
  * rb_ractor_std*()
  * rb_cRactor

and rm ractor_pub.h
and rename srcdir/ractor.h to srcdir/ractor_core.h
    (to avoid conflict with include/ruby/ractor.h)
2020-11-18 03:52:41 +09:00
Jeremy Evans
f5bb9115a7 Use more specific warning for ambiguous slash
Fixes [Bug ]
2020-11-15 15:25:32 -08:00
Nobuyoshi Nakada
79b242260b
ripper: Invalid pragma value warning 2020-11-02 22:49:42 +09:00
Nobuyoshi Nakada
539b89075a
Compare boolean values for parser pragma locale-insensitively 2020-11-02 18:24:45 +09:00
Kazuki Tsujimoto
e03e1982bd
Change NODE layout for pattern matching
I prefer pconst to be the first element of NODE.

  Before:

       | ARYPTN | FNDPTN | HSHPTN
    ---+--------+--------+-----------
    u1 | imemo  | imemo  | pkwargs
    u2 | pconst | pconst | pconst
    u3 | apinfo | fpinfo | pkwrestarg

  After:

       | ARYPTN | FNDPTN | HSHPTN
    ---+--------+--------+-----------
    u1 | pconst | pconst | pconst
    u2 | imemo  | imemo  | pkwargs
    u3 | apinfo | fpinfo | pkwrestarg
2020-11-01 16:19:07 +09:00