Commit graph

2691 commits

Author SHA1 Message Date
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 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