Граф коммитов

2162 Коммитов

Автор SHA1 Сообщение Дата
Nobuyoshi Nakada 2496bdb28f
Extracted argument forwarding staffs 2020-06-13 23:33:40 +09:00
Nobuyoshi Nakada 8e5352569b
[ripper] use Ripper DSL 2020-06-13 23:33:40 +09:00
Nobuyoshi Nakada c0ba35f334
Differentiate `...` in lambda arguments 2020-06-07 18:44:07 +09:00
Jeremy Evans f8b4340fa2 Add leading arguments support to arguments forwarding
The idFWD_KWREST sections may be wrong. However, the existing
idFWD_KWREST sections for ... without leading arguments are already
broken.

Implements [Feature #16378]
2020-06-06 17:07:11 -07:00
Nobuyoshi Nakada 27bef64862
Include the entire lambda expression in lambda rule 2020-06-02 09:06:49 +09:00
Nobuyoshi Nakada cadd2245f7
Extracted `excessed_comma` to unify ripper and make the order stable 2020-06-01 18:26:34 +09:00
Nobuyoshi Nakada 71c166e11e
Fixed argument forwarding in reserved word method [Bug #16854] 2020-05-15 14:59:11 +09:00
Nobuyoshi Nakada d7d0d01401 Endless method definition including `rescue` modifier 2020-05-14 19:58:44 +09:00
卜部昌平 9e41a75255 sed -i 's|ruby/impl|ruby/internal|'
To fix build failures.
2020-05-11 09:24:08 +09:00
卜部昌平 d7f4d732c1 sed -i s|ruby/3|ruby/impl|g
This shall fix compile errors.
2020-05-11 09:24:08 +09:00
Nobuyoshi Nakada 5c2508060b
Bison 3.5.91 now defaults parse.error to "simple" 2020-05-04 18:10:02 +09:00
Nobuyoshi Nakada 1997e10f6c
Made parentheses mandatory in endless method defition
Even for empty argument list, not to be confusing with a writer
method name.
2020-04-22 20:44:46 +09:00
Nobuyoshi Nakada 02ad393cd6
Revert "Allow simple R-assign in endless def"
This reverts commit 67bcac879a.
2020-04-22 18:56:06 +09:00
Nobuyoshi Nakada 478135f480
Disallow line-continuation before R-assign 2020-04-15 10:33:11 +09:00
Nobuyoshi Nakada a520ee4763
Removed duplicate value_expr checks
`arg_rhs` has the same check and is always a non-void value
expression.
2020-04-14 19:47:17 +09:00
Nobuyoshi Nakada 67bcac879a Allow simple R-assign in endless def 2020-04-13 21:51:34 +09:00
Nobuyoshi Nakada 022c7bbea9
Relaxed of R-assign value to arg 2020-04-12 00:07:57 +09:00
Nobuyoshi Nakada e8f53692ca
Endless method definition [Feature #16746] 2020-04-10 18:02:15 +09:00
Nobuyoshi Nakada 1b2d351b21
Rightward-assign by ASSOC
[Feature #15921]
2020-04-10 15:03:58 +09:00
卜部昌平 9e6e39c351
Merge pull request #2991 from shyouhei/ruby.h
Split ruby.h
2020-04-08 13:28:13 +09:00
Nobuyoshi Nakada 2544bf9452
New macro `NEW_RIPPER` instead of `NEW_CDECL` 2020-04-03 01:16:57 +09:00
Nobuyoshi Nakada f020d340f4
parse.y: hoisted out new_nil_at
new_nil_at: create NEW_NIL node with zero-width location.
2020-03-11 18:13:40 +09:00
Nobuyoshi Nakada 276859e03e
parse.y: unified kwrest and no-kwrest 2020-03-11 18:13:29 +09:00
Nobuyoshi Nakada 7d05f98a84
Renamed `lex_flags` as `lex_context` 2020-03-05 17:19:17 +09:00
Nobuyoshi Nakada c8d0bf0156
Preserve `kwarg` flag and fix up f5c904c2a9 2020-03-03 16:19:49 +09:00
Nobuyoshi Nakada 85620ffaa6
Reduced parser stack usage by merging non-result actions 2020-03-02 16:45:46 +09:00
Nobuyoshi Nakada 20a2ab0825
Packed stacked bit flags into one struct 2020-03-02 16:34:33 +09:00
Nobuyoshi Nakada f5c904c2a9
Allow newlines inside braced pattern 2020-03-02 15:49:03 +09:00
Kazuki Tsujimoto d25a4f413d
Allow trailing comma in hash pattern 2020-03-01 14:35:48 +09:00
Nobuyoshi Nakada 403675e8dc
Named `tLABEL` token 2020-02-29 21:42:38 +09:00
Nobuyoshi Nakada 07f27383b7
Refined argument name 2020-02-28 20:10:46 +09:00
Nobuyoshi Nakada 6e6844320d Fixed duplicated warning
As `command_rhs` is always a "value expression", `command_asgn`
does not need the same check.
2020-02-10 14:00:40 +09:00
Nobuyoshi Nakada 9cdc964d07
Do not warn CR inside string literal 2020-02-04 14:41:52 +09:00
Kenta Murata 019a0ed0c7
Make RATIONAL_SET_{NUM,DEN} static inline functions 2020-01-17 10:04:19 +09:00
Nobuyoshi Nakada c171ab23e3
Separate numbered parameter scope in eval
[Feature #16432]
2020-01-16 18:38:48 +09:00
Nobuyoshi Nakada f38b3e8c70
Fixed the location of args node with numbered parameter 2020-01-16 18:34:31 +09:00
Yusuke Endoh 5b0c3754d8 parse.y: fix a wrong sizeof argument for ruby_sized_xfree 2020-01-05 11:39:35 +09:00
Jeremy Evans 0eeed5bcc5 Make eval(code, binding) use (eval) as __FILE__ and 1 as __LINE__
This removes the warning that was added in
3802fb92ff, and switches the behavior
so that the eval does not use the binding's __FILE__ and __LINE__
implicitly.

Fixes [Bug #4352]
2020-01-03 20:13:09 -08:00
卜部昌平 5e22f873ed decouple internal.h headers
Saves comitters' daily life by avoid #include-ing everything from
internal.h to make each file do so instead.  This would significantly
speed up incremental builds.

We take the following inclusion order in this changeset:

1.  "ruby/config.h", where _GNU_SOURCE is defined (must be the very
    first thing among everything).
2.  RUBY_EXTCONF_H if any.
3.  Standard C headers, sorted alphabetically.
4.  Other system headers, maybe guarded by #ifdef
5.  Everything else, sorted alphabetically.

Exceptions are those win32-related headers, which tend not be self-
containing (headers have inclusion order dependencies).
2019-12-26 20:45:12 +09:00
Nobuyoshi Nakada 56e002981f
Show the error line only when same as the current 2019-12-25 14:49:48 +09:00
Nobuyoshi Nakada 07e595fdbd
Added `experimental` warning category
[Feature #16420]
2019-12-20 23:48:15 +09:00
Nobuyoshi Nakada dd7f0c87c9
Hoisted out new_case3 2019-12-20 23:43:38 +09:00
Nobuyoshi Nakada 7a94225e7d
Refined the warning message for numbered-parameter like variables
[Bug #16438]
2019-12-20 14:58:51 +09:00
Nobuyoshi Nakada a8bddb3a18
Refined the warning message for numbered-parameter like variables
[Bug #16438]
2019-12-20 14:34:32 +09:00
Nobuyoshi Nakada 2898367b3a
Warn also numbered parameter like methods 2019-12-20 08:18:19 +09:00
Nobuyoshi Nakada 27ddb6e998
Warn also numbered parameter like parameters
[Feature #16433]
2019-12-20 01:25:34 +09:00
Yusuke Endoh 199bd851e4 parse.y: suppress "set but not used" warnings on ripper.y 2019-12-05 14:51:55 +09:00
Jeremy Evans 447d583536 Silence incorrect assigned but unused variable warnings in ripper
To only emit the warnings in correct cases would require tracking
local variable usage in ripper, which ripper currently does not do.

Fixes [Bug #15188]
2019-12-04 03:04:22 +02:00
Nobuyoshi Nakada d1ef4fd08e
Make single line pattern matching void expression
Instead of returning `nil`, raise a syntax error if its value is
used.  [Feature #16355]
2019-11-30 00:15:29 +09:00
Nobuyoshi Nakada 8b4ee5d6ba
Raise `NoMatchingPatternError` when expr `in` pat doesn't match
* `expr in pattern` should raise `NoMatchingError` when unmatched
* `expr in pattern` should return `nil`. (this is unspecified, but
  this feature is experimental, at all)

[Feature #16355]
2019-11-28 13:47:14 +09:00
Nobuyoshi Nakada 9e01fcd0cb
[ripper] Fixed unique key check in pattern matching
Check keys
* by an internal table, instead of unstable dispatched results
* and by parsed key values, instead of escaped forms in the source
2019-11-26 22:54:35 +09:00
Nobuyoshi Nakada 22dfd14c17
Hoisted out `push_pvtbl`/`pop_pvtbl` 2019-11-26 21:57:00 +09:00
Nobuyoshi Nakada 497f13aea6
Wrap `p_kw` in an array at `p_kwarg`
Not in `p_kw` itself, which makes key and variable/expr pair only
now.
2019-11-26 21:57:00 +09:00
Nobuyoshi Nakada 26625bc33c
[ripper] Quoted label without expression must be a local variable
The difference from 0b8c73aa65 is to
add the result of `string_add` event to marking objects.

```C
			    RNODE($1)->nd_rval = add_mark_object(p, $$);
```
2019-11-25 17:42:59 +09:00
Nobuyoshi Nakada 61131edba7
Revert "[ripper] Quoted label without expression must be a local variable"
This reverts commit 0b8c73aa65, which
seems breaking RVALUE consistency check.
2019-11-20 00:56:04 +09:00
Nobuyoshi Nakada 0b8c73aa65
[ripper] Quoted label without expression must be a local variable 2019-11-19 17:18:27 +09:00
Jeremy Evans c5c05460ac Warn on access/modify of $SAFE, and remove effects of modifying $SAFE
This removes the security features added by $SAFE = 1, and warns for access
or modification of $SAFE from Ruby-level, as well as warning when calling
all public C functions related to $SAFE.

This modifies some internal functions that took a safe level argument
to no longer take the argument.

rb_require_safe now warns, rb_require_string has been added as a
version that takes a VALUE and does not warn.

One public C function that still takes a safe level argument and that
this doesn't warn for is rb_eval_cmd.  We may want to consider
adding an alternative method that does not take a safe level argument,
and warn for rb_eval_cmd.
2019-11-18 01:00:25 +02:00
卜部昌平 c9ffe751d1 delete unused functions
Looking at the list of symbols inside of libruby-static.a, I found
hundreds of functions that are defined, but used from nowhere.

There can be reasons for each of them (e.g. some functions are
specific to some platform, some are useful when debugging, etc).
However it seems the functions deleted here exist for no reason.

This changeset reduces the size of ruby binary from 26,671,456
bytes to 26,592,864 bytes on my machine.
2019-11-14 20:35:48 +09:00
Nobuyoshi Nakada 4d615a0c8f
`#@1` is no longer an embedded variable 2019-11-14 16:37:25 +09:00
Nobuyoshi Nakada fb6a489af2
Revert "Method reference operator"
This reverts commit 67c5747369.
[Feature #16275]
2019-11-12 17:24:48 +09:00
Nobuyoshi Nakada a58b4eee25
Warn on `...` at EOL 2019-11-12 17:14:14 +09:00
Nobuyoshi Nakada 7c22898a3a
Disable tOROP at EXPR_BEG
Both cannot appear there anyway.
2019-11-12 15:42:53 +09:00
Nobuyoshi Nakada ed90ec3e0d
Clear current argument name at empty block argument [Bug #16343] 2019-11-12 09:40:18 +09:00
NARUSE, Yui fd69f82675 Revert "Warn EOF char in comment"
This reverts commit 69ec3f70fa.
2019-11-11 17:37:21 +09:00
NARUSE, Yui ba5b51ca59 Revert "Elaborated EOF char message a little"
This reverts commit 6eaac7cfac.
2019-11-11 17:37:14 +09:00
Nobuyoshi Nakada 6eaac7cfac
Elaborated EOF char message a little 2019-11-11 12:57:40 +09:00
Nobuyoshi Nakada 69ec3f70fa
Warn EOF char in comment 2019-11-11 09:59:40 +09:00
Nobuyoshi Nakada ade0388894
Fixed embedded document with EOF char 2019-11-11 09:38:14 +09:00
Kazuki Tsujimoto 6e70fa49b1
Disallow omission of parentheses/brackets in single line pattern matching [Feature #16182] 2019-11-10 22:34:49 +09:00
Kazuki Tsujimoto a396bef8d8
Disallow duplicated pattern variable 2019-11-07 15:40:35 +09:00
Kazuki Tsujimoto 1e620c67af
Add missing semicolon 2019-11-07 13:20:11 +09:00
Nobuyoshi Nakada 2fd465540f
Numbered parameter is an ID_LOCAL now [Bug #16293] 2019-11-06 12:45:11 +09:00
Nobuyoshi Nakada 82e840ad15
Numbered parameter cannot appear outside block now [Bug #16293] 2019-11-06 12:44:50 +09:00
Kazuhiro NISHIYAMA 30a74aaef0
Fix a typo in WARN_EOL 2019-11-05 10:09:44 +09:00
Nobuyoshi Nakada a087e027bf
Fixed conditional expressions with only one void side 2019-11-05 01:32:26 +09:00
Nobuyoshi Nakada e91e3274be
Keep `lex.pcur` after `looking_at_eol_p` 2019-11-04 23:37:53 +09:00
Nobuyoshi Nakada 26316cc350
Warn `if` and `elsif` at EOL [EXPERIMENTAL]
It is unnatural and probably a typo.
2019-11-04 23:17:34 +09:00
Yusuke Endoh c303854e13 Revert "Warn `if` and `elsif` at EOL [EXPERIMENTAL]"
This reverts commit ba35c14325.
This is because ripper fails symbol lookup error.
2019-11-04 22:27:37 +09:00
Nobuyoshi Nakada ba35c14325
Warn `if` and `elsif` at EOL [EXPERIMENTAL]
It is unnatural and probably a typo.
2019-11-04 21:39:54 +09:00
Nobuyoshi Nakada b4229c0a90
Restore `in_kwarg` flag properly 2019-10-29 08:58:39 +09:00
Nobuyoshi Nakada b609bdeb53
Define arguments forwarding as `ruby2_keywords` style
Get rid of these redundant and useless warnings.

```
$ ruby -e 'def bar(a) a; end; def foo(...) bar(...) end; foo({})'
-e:1: warning: The last argument is used as the keyword parameter
-e:1: warning: for `foo' defined here
-e:1: warning: The keyword argument is passed as the last hash parameter
-e:1: warning: for `bar' defined here
```
2019-10-25 01:16:05 +09:00
Nobuyoshi Nakada 6279e45cde
Arguments forwarding is not allowed in lambda [Feature #16253] 2019-10-25 00:15:39 +09:00
Nobuyoshi Nakada 62d4382877 Arguments forwarding [Feature #16253] 2019-10-22 02:35:43 +09:00
Nobuyoshi Nakada bf934e4812
Fixed passing idNil as a Symbol 2019-10-19 00:50:17 +09:00
Jeremy Evans 0162e7e647 Make circular argument reference a SyntaxError instead of a warning
Fixes [Bug #10314]
2019-10-17 09:32:06 -07:00
Nobuyoshi Nakada c2065c64cb
Fixed numbered parameter check
* parse.y (struct local_vars): moved numbered parameter NODEs for
  nesting check to separate per local variable scopes, as numbered
  parameters should belong to local variable scopes.  [Bug #16248]
2019-10-10 14:07:45 +09:00
Nobuyoshi Nakada 25100c4697
lhs of pattern matching expression of should have a value 2019-10-10 08:53:46 +09:00
Ben Woosley bb71a128eb Prefer st_is_member over st_lookup with 0
The st_is_member DEFINE has simpler semantics, for more readable code.
2019-10-09 23:46:50 +09:00
Nobuyoshi Nakada 8feb8c9bb7
Packed delayed token elements 2019-10-08 17:04:46 +09:00
Nobuyoshi Nakada cbbe198c89
Fix potential memory leaks by `rb_imemo_tmpbuf_auto_free_pointer`
This function has been used wrongly always at first, "allocate a
buffer then wrap it with tmpbuf".  This order can cause a memory
leak, as tmpbuf creation also can raise a NoMemoryError exception.
The right order is "create a tmpbuf then allocate&wrap a buffer".
So the argument of this function is rather harmful than just
useless.

TODO:
* Rename this function to more proper name, as it is not used
  "temporary" (function local) purpose.
* Allocate and wrap at once safely, like `ALLOCV`.
2019-10-05 03:02:09 +09:00
Yusuke Endoh b732a9f8a0 parse.y: use "struct rb_iseq_struct" instead of rb_iseq_t
typedef was not declared in parse.y.  Sorry.
2019-10-04 02:34:36 +09:00
Yusuke Endoh b43afa0a8f Make parser_params have parent_iseq instead of base_block
The parser needs to determine whether a local varaiable is defined or
not in outer scope.  For the sake, "base_block" field has kept the outer
block.

However, the whole block was actually unneeded; the parser used only
base_block->iseq.

So, this change lets parser_params have the iseq directly, instead of
the whole block.
2019-10-04 02:30:36 +09:00
Yusuke Endoh 711c40ebdc Refactor parser_params by removing "in_main" flag
The relation between parser_param#base_block and #in_main were very
subtle.
A main script (that is passed via a command line) was parsed under
base_block = TOPLEVEL_BINDING and in_main = 1.
A script loaded by Kernel#require was parsed under
base_block = NULL and in_main = 0.
If base_block is non-NULL and in_main == 0, it is parsed by Kernel#eval
or family.

However, we know that TOPLEVEL_BINDING has no local variables when a
main script is parsed.  So, we don't have to parse a main script under
base_block = TOPLEVEL_BINDING.

Instead, this change parses a main script under base_block = 0.
If base_block is non-NULL, it is parsed by Kernel#eval or family.
By this simplication, "in_main" is no longer needed.
2019-10-04 02:30:36 +09:00
Nobuyoshi Nakada 3cee99808d [EXPERIMENTAL] Expression with modifier `in`
[Feature #15865]
2019-09-26 15:10:48 +09:00
Nobuyoshi Nakada 33c5ad3154
Removed idNUMPARAM_0 2019-09-25 13:52:53 +09:00
Nobuyoshi Nakada 55e1e22b2d
Changed numbered parameters semantics
* `_1` (and no other numbered parameters) to work as `|x|`.
* giving up `_0`.

[ruby-core:95074] [Bug #16178]
2019-09-25 13:01:03 +09:00
Nobuyoshi Nakada e663299a5f
Simplified duplicate code 2019-09-25 10:39:49 +09:00
Nobuyoshi Nakada 0e84eecc17 Make numbered parameters exclusive in a scope 2019-09-24 21:57:54 +09:00
Nobuyoshi Nakada ea68bb914a Changed numbered parameter prefix 2019-09-24 21:57:54 +09:00
Nobuyoshi Nakada e73cc3eead Added implicit block parameter 2019-09-24 21:57:54 +09:00
Nobuyoshi Nakada e81a3e6df5
Allows calling a private method only with bare `self` 2019-09-20 22:05:54 +09:00
Nobuyoshi Nakada 2698f13a1f
Fixed reserved numbered parameter warning 2019-09-19 19:40:44 +09:00
Nobuyoshi Nakada 3a3f48fb8f
Comment lines can be placed between fluent dot now 2019-09-15 23:12:24 +09:00
Aaron Patterson 515b1989b1
Make NODE_ARYPTN layout consistent between Ripper and AST
We are seeing SEGVs in CI:

  http://ci.rvm.jp/results/trunk-gc-asserts@ruby-sky1/2253563

This is happening because Ripper constructs AST nodes differently than
parse.y normally does.  Specifically in this case Ripper is assigning 3
`VALUE` objects:

  1febb6f4a1/parse.y (L757-L761)

Where parse.y will normally assign other things:

  1febb6f4a1/parse.y (L11258-L11260)

The important one is the last one, the `struct rb_ary_pattern_info`. The
mark function assumed that `NODE_ARYPTN` have a pointer to `struct
rb_ary_pattern_info`, and used it:

  1febb6f4a1/node.c (L1269-L1274)

In the case of Ripper, `NODE_ARYPTN` doesn't point to an
`rb_ary_pattern_info`, so the mark function would SEGV.  This commit
changes Ripper so that its `NODE_ARYPTN` nodes also point at an
`rb_ary_pattern_info`, and the mark function can continue with the same
assumption.
2019-09-11 14:58:51 -07:00
Aaron Patterson 14e3731059
Make sure WB executes after object is reachable 2019-09-11 11:57:57 -07:00
Nobuyoshi Nakada 343b0a281d
Made a short-circuit expression w/o result into an `if`-statement 2019-09-11 16:27:30 +09:00
卜部昌平 655c65d65b &$$->nd_lit is uninitialized at this point
See also https://travis-ci.org/ruby/ruby/jobs/583031687#L1874
2019-09-11 16:01:18 +09:00
Aaron Patterson 91ee9584f9
Macros can't be expressions, so make a function
Macros can't be expressions, that is a GNU extension (I didn't know
that).  This commit converts the macro to a function so that everything
will compile correctly on non-GNU compatible compilers.
2019-09-10 14:00:48 -07:00
Aaron Patterson 139510238b
WB needs to be executed after object is reachable 2019-09-10 12:42:35 -07:00
Aaron Patterson d8a4af47a5
Only use `add_mark_object` in Ripper
This patch changes parse.y to only use `add_mark_object` in Ripper.
Previously we were seeing a bug in write barrier verification.  I had
changed `add_mark_object` to execute the write barrier, but the problem
is that we had code like this:

```
NEW_STR(add_mark_object(p, obj), loc)
```

In this case, `add_mark_object` would execute the write barrier between
the ast and `obj`, but the problem is that `obj` isn't actually
reachable from the AST at the time the write barrier executed.
`NEW_STR` can possibly call `malloc` which can kick a GC, and since
`obj` isn't actually reachable from the AST at the time of WB execution,
verification would fail.

Basically the steps were like this:

1. RB_OBJ_WRITTEN via `add_mark_object`
2. Allocate node
3. *Possibly* execute GC via malloc
4. Write obj in to allocated node

This patch changes the steps to:

1. Allocate node
2. *Possibly* execute GC via malloc
3. Write obj in to allocated node
4. RB_OBJ_WRITTEN
2019-09-09 14:26:57 -07:00
Aaron Patterson 4524780d17
Revert "Reverting node marking until I can fix GC problem."
This reverts commit 092f31e7e2.
2019-09-09 14:26:51 -07:00
Yusuke Endoh a3f5265fd1 parse.y: Use the correct alias for brace flag of hash literal
nd_alen and nd_brace is the same field, but nd_brace is more suitable
for this case.
2019-09-08 00:28:03 +09:00
Yusuke Endoh a7a2be7a31 Rename some function/definition names that handles NODE_LIST
from array to list.
Follow up to ac50ac03aeb210763730cdc45f230e236519223d
2019-09-07 13:56:41 +09:00
Yusuke Endoh 99c9431ea1 Rename NODE_ARRAY to NODE_LIST to reflect its actual use cases
and NODE_ZARRAY to NODE_ZLIST.

NODE_ARRAY is used not only by an Array literal, but also the contents
of Hash literals, method call arguments, dynamic string literals, etc.
In addition, the structure of NODE_ARRAY is a linked list, not an array.

This is very confusing, so I believe `NODE_LIST` is a better name.
2019-09-07 13:56:29 +09:00
Nobuyoshi Nakada 3754e15530
Warn local variables which conflict with new numbered parameters 2019-09-06 09:02:12 +09:00
Aaron Patterson 092f31e7e2
Reverting node marking until I can fix GC problem.
Looks like we're getting WB misses during stressful GC on startup.  I am
investigating.
2019-09-05 12:44:23 -07:00
Aaron Patterson 8f096226e1
Stash tmpbuffer inside internal structs
I guess those AST node were actually used for something, so we'd better
not touch them.  Instead this commit just puts the tmpbuffer inside a
different internal struct so that we can mark them.
2019-09-05 11:04:43 -07:00
Aaron Patterson 429ed8d587
Don't change DSTR nodes to ARRAY nodes
DSTR nodes are allocated in to the "markable" bucket where ARRAY nodes
are not.  Switching buckets can cause errors during GC.
2019-09-05 10:13:50 -07:00
Aaron Patterson 545b6db3fb
Create two buckets for allocating NODE structs
This commit adds two buckets for allocating NODE structs, then allocates
"markable" NODE objects from one bucket.  The reason to do this is so
when the AST mark function scans nodes for VALUE objects to mark, we
only scan NODE objects that we know to reference VALUE objects.  If we
*did not* divide the objects, then the mark function spends too much
time scanning objects that don't contain any references.
2019-09-05 10:13:50 -07:00
Aaron Patterson f0fd1c0cd8
Stash the imemo buf at the end of the ID list
Now we can reach the ID table buffer from the id table itself, so when
SCOPE nodes are marked we can keep the buffers alive.  This eliminates
the need for the "mark array" during normal parse / compile (IOW *not*
Ripper).
2019-09-05 10:13:50 -07:00
Aaron Patterson 64817a7cfd
Mark some tmpbufs via node objects
This way we don't need to add the tmpbufs to a Ruby array for marking
2019-09-05 10:13:50 -07:00
Aaron Patterson 581fcde088
Directly mark node objects instead of using a mark array
This patch changes the AST mark function so that it will walk through
nodes in the NODE buffer marking Ruby objects rather than using a mark
array to guarantee liveness.  The reason I want to do this is so that
when compaction happens on major GCs, node objects will have their
references pinned (or possibly we can update them correctly).
2019-09-05 10:13:49 -07:00
Jeremy Evans c6464c44c0 Fix code locations of array node inside hash node when multiple kw splats
This is broken at least since 2.5 (I didn't check earlier versions).
It resulted in failure in test_ast.rb when the tests were added before
the parser change.

Basically, in remove_duplicate_keys, if the node is modified, set
the location information to the previous location information. The
removal of keys should not affect the location in the code.
2019-09-05 09:57:43 -07:00
Jeremy Evans 1d5066efb0 Make m(**{}) mean call without keywords
Previously, **{} was removed by the parser:

```
$ ruby --dump=parse -e '{**{}}'
 @ NODE_SCOPE (line: 1, location: (1,0)-(1,6))
 +- nd_tbl: (empty)
 +- nd_args:
 |   (null node)
 +- nd_body:
     @ NODE_HASH (line: 1, location: (1,0)-(1,6))*
     +- nd_brace: 1 (hash literal)
     +- nd_head:
         (null node)
```

Since it was removed by the parser, the compiler did not know
about it, and `m(**{})` was therefore treated as `m()`.

This modifies the parser to not remove the `**{}`.  A simple
approach for this is fairly simple by just removing a few
lines from the parser, but that would cause two hash
allocations every time it was used.  The approach taken here
modifies both the parser and the compiler, and results in `**{}`
not allocating any hashes in the usual case.

The basic idea is we use a literal node in the parser containing
a frozen empty hash literal.  In the compiler, we recognize when
that is used, and if it is the only keyword present, we just
push it onto the VM stack (no creation of a new hash or merging
of keywords).  If it is the first keyword present, we push a
new empty hash onto the VM stack, so that later keywords can
merge into it.  If it is not the first keyword present, we can
ignore it, since the there is no reason to merge an empty hash
into the existing hash.

Example instructions for `m(**{})`

Before (note ARGS_SIMPLE):

```
== disasm: #<ISeq:<main>@-e:1 (1,0)-(1,7)> (catch: FALSE)
0000 putself                                                          (   1)[Li]
0001 opt_send_without_block       <callinfo!mid:m, argc:0, FCALL|ARGS_SIMPLE>, <callcache>
0004 leave
```

After (note putobject and KW_SPLAT):

```
== disasm: #<ISeq:<main>@-e:1 (1,0)-(1,7)> (catch: FALSE)
0000 putself                                                          (   1)[Li]
0001 putobject                    {}
0003 opt_send_without_block       <callinfo!mid:m, argc:1, FCALL|KW_SPLAT>, <callcache>
0006 leave
```

Example instructions for `m(**h, **{})`

Before and After (no change):

```
== disasm: #<ISeq:<main>@-e:1 (1,0)-(1,12)> (catch: FALSE)
0000 putself                                                          (   1)[Li]
0001 putspecialobject             1
0003 newhash                      0
0005 putself
0006 opt_send_without_block       <callinfo!mid:h, argc:0, FCALL|VCALL|ARGS_SIMPLE>, <callcache>
0009 opt_send_without_block       <callinfo!mid:core#hash_merge_kwd, argc:2, ARGS_SIMPLE>, <callcache>
0012 opt_send_without_block       <callinfo!mid:m, argc:1, FCALL|KW_SPLAT>, <callcache>
0015 leave
```

Example instructions for `m(**{}, **h)`

Before:

```
== disasm: #<ISeq:<main>@-e:1 (1,0)-(1,12)> (catch: FALSE)
0000 putself                                                          (   1)[Li]
0001 putspecialobject             1
0003 newhash                      0
0005 putself
0006 opt_send_without_block       <callinfo!mid:h, argc:0, FCALL|VCALL|ARGS_SIMPLE>, <callcache>
0009 opt_send_without_block       <callinfo!mid:core#hash_merge_kwd, argc:2, ARGS_SIMPLE>, <callcache>
0012 opt_send_without_block       <callinfo!mid:m, argc:1, FCALL|KW_SPLAT>, <callcache>
0015 leave
```

After (basically the same except for the addition of swap):

```
== disasm: #<ISeq:<main>@-e:1 (1,0)-(1,12)> (catch: FALSE)
0000 putself                                                          (   1)[Li]
0001 newhash                      0
0003 putspecialobject             1
0005 swap
0006 putself
0007 opt_send_without_block       <callinfo!mid:h, argc:0, FCALL|VCALL|ARGS_SIMPLE>, <callcache>
0010 opt_send_without_block       <callinfo!mid:core#hash_merge_kwd, argc:2, ARGS_SIMPLE>, <callcache>
0013 opt_send_without_block       <callinfo!mid:m, argc:1, FCALL|KW_SPLAT>, <callcache>
0016 leave
```
2019-09-05 09:57:43 -07:00
Kazuki Tsujimoto 94d6ec1d90
Make pattern matching support **nil syntax 2019-09-01 16:39:34 +09:00
Nobuyoshi Nakada e80a6f65c8
Made :nil static ID 2019-09-01 13:37:28 +09:00
Jeremy Evans 42adc5bc6b Add back missing warning for duplicate keys in splatted hashes
This reverts the changes to parse.y in
a5b37262524ac39d2af13eea174486370a581c23 as they are not actually
needed and cause the warning for duplicate hash keys to not be
emitted.
2019-08-30 12:39:31 -07:00
Jeremy Evans 4d64693c70 Make ripper support **nil syntax
The on_params hook will use :nil as the keyword rest argument.
There is a new on_nokw_param hook as well.

This fixes a type issue in the previous code, where an ID was
passed where a VALUE was the declared type.  The symbol :nil is
passed instead of the id.
2019-08-30 12:39:31 -07:00
Jeremy Evans 6a9ce1fea8 Support **nil syntax for specifying a method does not accept keyword arguments
This syntax means the method should be treated as a method that
uses keyword arguments, but no specific keyword arguments are
supported, and therefore calling the method with keyword arguments
will raise an ArgumentError.  It is still allowed to double splat
an empty hash when calling the method, as that does not pass
any keyword arguments.
2019-08-30 12:39:31 -07:00
Yusuke Endoh 16c6984bb9 Separate keyword arguments from positional arguments
And, allow non-symbol keys as a keyword arugment
2019-08-30 12:39:31 -07:00
Nobuyoshi Nakada 01b723ba6d
Refined warnings against literal in flip-flop 2019-08-29 23:06:27 +09:00
Nobuyoshi Nakada 2ed68d0ff9
Revert "Add pipeline operator [Feature #15799]"
This reverts commits:
* d365fd5a02
* d780c36624
* aa7211836b
* 043f010c28
* bb4dd7c6af05c7821d572e2592ea3d0cc748d81f
* 043f010c28
* f169043d81

http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-core/94645
2019-08-29 15:27:59 +09:00
Aaron Patterson 932a471d38
Directly mark compile options from the AST object
`rb_ast_t` holds a reference to this object, so it should mark the
object.  Currently it is relying on the `mark_ary` on `node_buffer` to
ensure that the object stays alive.  But since the array internals can
move, this could cause a segv if compaction impacts the array.
2019-08-27 11:43:18 -07:00
Kazuhiro NISHIYAMA 5d5502dc85
Fix typos 2019-08-24 21:26:24 +09:00
Nobuyoshi Nakada d5b917d500
Named numbered parameter indexes 2019-08-24 01:10:42 +09:00
Jeremy Evans 53b3be5d58 Fix parsing of mutiple assignment with rescue modifier
Single assignment with rescue modifier applies rescue to the RHS:

  a = raise rescue 1 # a = (raise rescue 1)

Previously, multiple assignment with rescue modifier applied rescue
to the entire expression:

  a, b = raise rescue [1, 2] # (a, b = raise) rescue [1, 2]

This makes multiple assignment with rescue modifier consistent with
single assignment with rescue modifier, applying rescue to the RHS:

  a, b = raise rescue [1, 2] # a, b = (raise rescue [1, 2])

Implements [Feature #8239]
Fixes [Bug #8279]
2019-08-09 09:25:30 -07:00
Takashi Kokubun a3188f43a8
Revert "Revert "Fix dangling path name from fstring""
This reverts commit 326c00b6f8.

We also confirmed that test_gced_eval_location fails without the changes:
https://travis-ci.org/ruby/ruby/builds/567417818
https://rubyci.org/logs/rubyci.s3.amazonaws.com/arch/ruby-master/log/20190804T000003Z.fail.html.gz
https://rubyci.org/logs/rubyci.s3.amazonaws.com/ubuntu1604/ruby-master/log/20190804T003005Z.fail.html.gz
https://rubyci.org/logs/rubyci.s3.amazonaws.com/icc-x64/ruby-master/log/20190804T000007Z.fail.html.gz
https://rubyci.org/logs/rubyci.s3.amazonaws.com/unstable10x/ruby-master/log/20190804T001806Z.fail.html.gz
https://rubyci.org/logs/rubyci.s3.amazonaws.com/debian9/ruby-master/log/20190804T003005Z.fail.html.gz
2019-08-04 10:08:17 +09:00
Takashi Kokubun 326c00b6f8
Revert "Fix dangling path name from fstring"
This reverts commit 5931857281 temporarily,
leaving `TestEval#test_gced_eval_location` to see the impact for missing
the changes.

That's because too many CIs are failing for `require` behaviors:
http://rubyci.s3.amazonaws.com/freebsd11zfs/ruby-master/log/20190803T063004Z.fail.html.gz
http://rubyci.s3.amazonaws.com/unstable10x/ruby-master/log/20190803T051806Z.fail.html.gz
http://rubyci.s3.amazonaws.com/unstable11x/ruby-master/log/20190803T052406Z.fail.html.gz
http://rubyci.s3.amazonaws.com/unstable10s/ruby-master/log/20190803T111909Z.fail.html.gz
http://rubyci.s3.amazonaws.com/unstable11s/ruby-master/log/20190803T062506Z.fail.html.gz
http://rubyci.s3.amazonaws.com/solaris11s-sunc/ruby-master/log/20190803T052505Z.fail.html.gz
https://app.wercker.com/ruby/ruby/runs/mjit-test1/5d4512c921ca08000857936a?step=5d451305c2809c0008a3da76
https://app.wercker.com/ruby/ruby/runs/mjit-test2/5d4512c921ca080008579371?step=5d4513000421020007ca122d
http://ci.rvm.jp/results/trunk_gcc4@silicon-docker/2177591
http://ci.rvm.jp/results/trunk_gcc6@silicon-docker/2177596
http://ci.rvm.jp/results/trunk_clang_60@silicon-docker/2178802
http://ci.rvm.jp/results/trunk-theap-asserts@silicon-docker/2177555
http://ci.rvm.jp/results/trunk-mjit-wait@silicon-docker/2178747

Mostly `TestRequire#test_race_exception` failures, but in ci.rvm.jp
`require` inside rubyspec hangs very often.
2019-08-04 08:52:41 +09:00
Nobuyoshi Nakada 5931857281
Fix dangling path name from fstring
* parse.y (yycompile): make sure in advance that the `__FILE__`
  object shares a fstring, to get rid of dangling path name.
  Fixed up 53e9908d8a.  [Bug #16041]

* vm_eval.c (eval_make_iseq): ditto.
2019-08-03 13:48:29 +09:00
Nobuyoshi Nakada 688a59f8ac
Show the location of `eval` which uses `__FILE__`/`__LINE__` 2019-08-03 11:32:37 +09:00
Yusuke Endoh e9e17cbc05 parse.y: make a warning for __FILE__ in eval by default
[Bug #4352]
2019-08-02 23:17:19 +09:00
Nobuyoshi Nakada d488464106
Use predefined idOr 2019-08-01 16:35:43 +09:00
Nobuyoshi Nakada fd461dea06
Ripper#validate_object: check if the object is hidden 2019-07-19 07:57:17 +09:00
Nobuyoshi Nakada 59d6ce4f4b
Moved RIPPER_DEBUG methods to Ripper from Kernel 2019-07-19 07:50:32 +09:00
Nobuyoshi Nakada 18bce998dd
Fixed build error with RIPPER_DEBUG 2019-07-19 07:50:32 +09:00
Nobuyoshi Nakada a027c4b5b0
Use Qnull instead of 0 and Qundef 2019-07-19 06:23:19 +09:00
Nobuyoshi Nakada 0e23e0c3a0
Adjust indent [ci skip] 2019-07-17 17:04:37 +09:00
Yusuke Endoh 711dfec3fa parse.y (here_document): remove dead code
str is always zero when evaluating the branch.
Found by Coverity Scan.
2019-07-15 14:08:17 +09:00
Yusuke Endoh 9e3971c3ad Add a /* fall through */ comment 2019-07-15 00:29:56 +09:00
Yusuke Endoh 20a3fb3c4b Add a /* fall through */ comment 2019-07-14 21:34:32 +09:00