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

1412 Коммитов

Автор SHA1 Сообщение Дата
HParker 55326a915f Introduce --parser runtime flag
Introduce runtime flag for specifying the parser,

```
ruby --parser=prism
```

also update the description:

```
$ ruby --parser=prism --version
ruby 3.3.0dev (2023-12-08T04:47:14Z add-parser-runtime.. 0616384c9f) +PRISM [x86_64-darwin23]
```

[Bug #20044]
2023-12-15 13:42:19 -05:00
Jeremy Evans a18819e65f Fix op asgn method calls passing mutable keyword splats
When passing the keyword splat to [], it cannot be mutable, because
mutating the keyword splat inside [] would result in changes to the
keyword splat passed to []=.
2023-12-14 08:13:43 -08:00
Jeremy Evans 2f1d6da8c4
Fix op asgn calls with keywords
Examples of such calls:

```ruby
obj[kw: 1] += fo
obj[**kw] &&= bar
```

Before this patch, literal keywords would segfault in the compiler,
and keyword splat usage would result in TypeError.

This handles all cases I can think of:

* literal keywords
* keyword splats
* combined with positional arguments
* combined with regular splats
* both with and without blocks
* both popped and non-popped cases

This also makes sure that to_hash is only called once on the keyword
splat argument, instead of twice, and make sure it is called before
calling to_proc on a passed block.

Fixes [Bug #20051]

Co-authored-by: Nobuyoshi Nakada <nobu@ruby-lang.org>
2023-12-12 07:34:53 -08:00
Jeremy Evans f64357540e Ensure super(**kw, &block) calls kw.to_hash before block.to_proc
Similar as previous commit, but handles the super case with
explicit arguments.
2023-12-09 13:15:47 -08:00
Jeremy Evans a950f23078 Ensure f(**kw, &block) calls kw.to_hash before block.to_proc
Previously, block.to_proc was called first, by vm_caller_setup_arg_block.
kw.to_hash was called later inside CALLER_SETUP_ARG or setup_parameters_complex.

This adds a splatkw instruction that is inserted before sends with
ARGS_BLOCKARG and KW_SPLAT and without KW_SPLAT_MUT. This is not needed in the
KW_SPLAT_MUT case, because then you know the value is a hash, and you don't
need to call to_hash on it.

The splatkw instruction checks whether the second to top block is a hash,
and if not, replaces it with the value of calling to_hash on it (using
rb_to_hash_type).  As it is always before a send with ARGS_BLOCKARG and
KW_SPLAT, second to top is the keyword splat, and top is the passed block.
2023-12-09 13:15:47 -08:00
Jeremy Evans 7738b31d39 Eliminate array allocation for f(1, *a, &arg), f(*a, **kw, &arg), and f(*a, kw: 1, &arg)
These are similar to the f(1, *a, &lvar), f(*a, **kw, &lvar) and
f(*a, kw: 1, &lvar) optimizations, but they use getblockparamproxy
instruction instead of getlocal.

This also fixes the else style to be more similar to the surrounding
code.
2023-12-07 11:27:55 -08:00
Jeremy Evans aa808204bb Eliminate array allocation for f(*a, kw: 1, &lvar) and f(*a, kw: 1, &@iv)
Similar to the previous commit, but this handles the block pass
case.
2023-12-07 11:27:55 -08:00
Jeremy Evans 5e33f2b0e4 Eliminate array allocation for f(*a, kw: 1)
In cases where the compiler can detect the hash is static, it would
use duphash for the hash part. As the hash is static, there is no need
to allocate an array.
2023-12-07 11:27:55 -08:00
Jeremy Evans 95615872e3 Eliminate array allocation for f(*a, **lvar, &lvar) and f(*a, **@iv, &@iv)
The compiler already eliminates the array allocation for
f(*a, &lvar) and f(*a, &@iv).  If that is safe, then eliminating
it for f(*a, **lvar) and f(*a, **@iv) as the last commit did is
as safe, and eliminating it for f(*a, **lvar, &lvar) and
f(*a, **@iv, &@iv) is also as safe.
2023-12-07 11:27:55 -08:00
Jeremy Evans 1731dd05a7 Eliminate array allocation for f(*a, **lvar) and f(*a, **@iv)
The compiler already eliminates the array allocation for
f(*a, &lvar) and f(*a, &@iv), and eliminating the array allocation
for keyword splat is as safe as eliminating it for block passes.
2023-12-07 11:27:55 -08:00
Jeremy Evans c70c1d2a95 Eliminate array allocation for f(1, *a, &lvar) and f(1, *a, &@iv)
Due to how the compiler works, while f(*a, &lvar) and f(*a, &@iv)
do not allocate an array, but f(1, *a, &lvar) and f(1, *a, &@iv)
do.  It's probably possible to fix this in the compiler, but
seems easiest to fix this in the peephole optimizer.

Eliminating this array allocation is as safe as the current
elimination of the array allocation for f(*a, &lvar) and
f(*a, &@iv).
2023-12-07 11:27:55 -08:00
Jeremy Evans 40a2afd08f Eliminate array allocation for f(1, *a)
Due to how the compiler works, while f(*a) does not allocate an
array f(1, *a) does.  This is possible to fix in the compiler, but
the change is much more complex.  This attempts to fix the issue
in a simpler way using the peephole optimizer.

Eliminating this array allocation is safe, since just as in the
f(*a) case, nothing else on the caller side can modify the array.
2023-12-07 11:27:55 -08:00
Peter Zhu d1691617d6 Pin instruction storage
The operands in each instruction needs to be pinned because if
auto-compaction runs in iseq_set_sequence, then the objects could exist
on the generated_iseq buffer, which would not be reference updated which
can lead to T_MOVED (and subsequently T_NONE) objects on the iseq.
2023-12-02 09:06:03 -05:00
Nobuyoshi Nakada a607d62d8c [Bug #20033] Dynamic regexp should not assign captures 2023-12-02 03:57:41 +09:00
Peter Zhu 6ebcf25de2 GC guard catch_table_ary in iseq_set_exception_table
The function iseq_set_exception_table allocates memory which can cause
a GC compaction to run. Since catch_table_ary is not on the stack, it
can be moved, which would make tptr incorrect.
2023-11-29 12:30:12 -05:00
Nobuyoshi Nakada 7fe7b7bc5a
Fix portability of bignum in ISeq Binary Format
- Unless `sizeof(BDIGIT) == 4`, (8-byte integer not available), the
  size to be loaded was wrong.
- Since `BDIGIT`s are dumped as raw binary, the loaded byte order was
  inverted unless little-endian.
2023-11-26 11:42:02 +09:00
Jean Boussier 0aafd040c3 Embed ibf_dump objects 2023-11-21 17:41:27 +01:00
Jean Boussier b4f551686b Get rid of useless dsize functions
If we always return 0, we might as well not define
the function at all.
2023-11-21 15:15:03 +01:00
Jean Boussier 05028f4d55 compile.c: make pinned_list embedable
This saves some malloc churn for small pin lists.
2023-11-20 17:27:32 +01:00
Nobuyoshi Nakada 2a442121d1
Stabilize outer variable list
Sort outer variables by names to make dumped binary data stable.
2023-11-11 16:58:14 +09:00
Nobuyoshi Nakada e2ef85b109 Finer granularity IBF dependendency
It depends on only `VALUE` definition.  Check for endianness and word
size instead of the platform name.
2023-11-09 16:01:01 +09:00
Nobuyoshi Nakada 61bb5c0572 Use `uint32_t` instead of `unsigned int` for the exact size 2023-11-09 16:01:01 +09:00
Matt Valentine-House 8ef7f27321 [PRISM] CompileEnsureNode 2023-11-07 14:03:57 +00:00
Jemma Issroff f6ba87ca88 [PRISM] Implement compilation for MultiWriteNodes, fix MultiTargetNodes
Compilation now works for MultiWriteNodes and MultiTargetNodes, with
nesting on MultiWrites. See the tests added in this commit for example
behavior.
2023-11-06 10:39:07 -03:00
Matt Valentine-House 9249b8622b Move constant indexing into rb_translate_prism 2023-10-30 19:44:42 +00:00
Matt Valentine-House 5dfba84cff [Prism] Compile ForNode
Fixes ruby/prism#1648
2023-10-30 19:44:42 +00:00
Nobuyoshi Nakada 13c9cbe09e
Embed `rb_args_info` in `rb_node_args_t` 2023-10-30 00:19:43 +09:00
Jemma Issroff b5f6e2a7c4 [PRISM] ScopeNode doesn't need void * anymore 2023-10-25 18:18:35 -03:00
Jemma Issroff 8f71a5c530 [PRISM] Move scope_node itself to CRuby, create prism_compile.h 2023-10-25 18:18:35 -03:00
yui-knk 08e25985d1 Expand OP_ASGN1 nd_args to nd_index and nd_rvalue
ARGSCAT has been used for nd_args to hold index and rvalue,
because there was limitation on the number of members for Node.
We can easily change structure of node now, let's expand it.
2023-10-20 07:56:20 +09:00
Nobuyoshi Nakada c2d4c92a98
Extract a local variable 2023-10-19 17:28:41 +09:00
Jemma Issroff 10c5063704 Address PR comments 2023-10-18 17:16:11 -07:00
Jemma Issroff ba3a99acaf Remove pm_compile_context_t, move the context onto ScopeNode
We changed ScopeNodes to point to their parent (previous) ScopeNodes.
Accordingly, we can remove pm_compile_context_t, and store all
necessary context in ScopeNodes, allowing us to access locals from
outer scopes.
2023-10-18 17:16:11 -07:00
Alan Wu d2b0c9da2e
YJIT: Add a live ISeq counter
It's an estimator for application size and could be used as a
compilation heuristic later.

Co-authored-by: Maxime Chevalier-Boisvert <maxime.chevalierboisvert@shopify.com>
Co-authored-by: Takashi Kokubun <takashikkbn@gmail.com>
2023-10-18 23:46:35 +00:00
Nobuyoshi Nakada 8e6a251138
Remove unnecessary and misleading casts 2023-10-18 18:52:05 +09:00
Nobuyoshi Nakada 380c25f89f
Adjust indent [ci skip] 2023-10-11 19:42:07 +09:00
yui-knk f9fe7aeef4 Extract NODE_FL_NEWLINE access to macro 2023-10-11 19:22:34 +09:00
yui-knk 8c2a493233 Fix cast node type 2023-10-09 19:08:23 +09:00
yui-knk fbd534679f Correctly casting node for accessing nd_value and nd_vid in compile.c 2023-10-07 17:54:35 +09:00
yui-knk 5c779dc45d Remove not used fields from MATCH3 2023-10-06 15:32:33 +09:00
Nobuyoshi Nakada a5cc6341c0
Remove `NODE_VALUES`
This node type was added for the multi-value experiment back in 2004.
The feature itself was removed after a few years, but this is its
remnant.
2023-10-06 03:39:58 +09:00
yui-knk 45350a0460 Correctly casting node for accessing COLON node nd_mid in compile.c 2023-10-05 13:19:09 +09:00
Yuichiro Kaneko 1ed6fd8997 Check the result of get_nd_recv before node type check for safety
Co-authored-by: Nobuyoshi Nakada <nobu@ruby-lang.org>
2023-10-02 09:41:45 +09:00
yui-knk b1131851e0 Correctly casting node for accessing nd_recv, nd_mid and nd_args in compile.c 2023-10-02 09:41:45 +09:00
HParker c74dc8b4af Use reference counting to avoid memory leak in kwargs
Tracks other callinfo that references the same kwargs and frees them when all references are cleared.

[bug #19906]

Co-authored-by: Peter Zhu <peter@peterzhu.ca>
2023-10-01 10:55:19 -04:00
yui-knk 08239fd6af Use rb_node_args_t and rb_node_args_aux_t instead of NODE 2023-10-01 19:38:03 +09:00
yui-knk cecd1de2eb Use rb_node_opt_arg_t and rb_node_kw_arg_t instead of NODE 2023-10-01 09:19:42 +09:00
yui-knk d293d9e191 Expand pattern_info struct into ARYPTN Node and FNDPTN Node 2023-09-30 13:11:32 +09:00
yui-knk 129d006852 Remove not used fields from argument nodes 2023-09-30 12:29:29 +09:00
yui-knk 37a783a30c Merge RNode_OP_ASGN2 and RNode_OP_ASGN22 2023-09-29 08:36:39 +09:00