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

1425 Коммитов

Автор SHA1 Сообщение Дата
Jeremy Evans 5c823aa686
Support keyword splatting nil
nil is treated similarly to the empty hash in this case, passing
no keywords and not calling any conversion methods.

Fixes [Bug #20064]

Co-authored-by: Nobuyoshi Nakada <nobu@ruby-lang.org>
2024-01-14 11:41:02 -08:00
Jeremy Evans ef75125271 Make defined? for op asgn expressions to constants use "assignment"
Previously, it used "expression", as that was the default.  However,
op asgn expressions to constants use the NODE_OP_CDECL, so recognize
that node type as assignement.

Fixes [Bug #20111]
2024-01-10 16:02:38 -08:00
S-H-GAMELINKS a1949df547 Remove unnecessary semicolon and add break 2024-01-10 12:58:19 +09:00
yui-knk db476cc71c Introduce NODE_SYM to manage symbol literal
`:sym` was managed by `NODE_LIT` with `Symbol` object.
This commit introduces `NODE_SYM` so that

1. Symbol literal is detectable from AST Node
2. Reduce dependency on ruby object
2024-01-09 16:07:19 +09:00
yui-knk 41e2d180a3 Do not convert NODE_STR to NODE_LIT when the string is hash key
parse.y converted NODE_STR when the string is hash key like

```
h1 = {"str1" => 1}
m1("str2" => 2)
m2({"str3" => 3})
```

This commit stop the conversion.
`static_literal_node_p` needs to know the node is for hash key or not
for the optimization.
2024-01-08 18:48:24 +09:00
yui-knk 7ffff3e043 Change numeric node value functions argument to `NODE *`
Change the argument to align with other node value functions
like `rb_node_line_lineno_val`.
2024-01-08 14:02:48 +09:00
Nobuyoshi Nakada c30b8ae947
Adjust styles and indents [ci skip] 2024-01-08 00:50:41 +09:00
yui-knk 83c98ead4e Do not remove hash duplicated keys in parse.y
When hash keys are duplicated, e.g. `h = {k: 1, l: 2, k: 3}`,
parser changes node structure for correct compilation.
This generates tricky AST. This commit removes AST manipulation
from parser to keep AST structure simple.
2024-01-07 16:18:16 +09:00
S-H-GAMELINKS 1b8d01136c Introduce Numeric Node's 2024-01-07 09:24:34 +09:00
yui-knk 7a050638b1 Introduce NODE_FILE
`__FILE__` was managed by `NODE_STR` with `String` object.
This commit introduces `NODE_FILE` and `struct rb_parser_string` so that

1. `__FILE__` is detectable from AST Node
2. Reduce dependency ruby object
2024-01-02 14:19:42 +09:00
yui-knk 1ade170a6c Introduce NODE_LINE
`__LINE__` was managed by `NODE_LIT` with `Integer` object.
This commit introduces `NODE_LINE` so that

1. `__LINE__` is detectable from AST Node
2. Reduce dependency ruby object
2023-12-29 18:32:27 +09:00
yui-knk 87e8e961b7 Check node type before cast 2023-12-28 18:47:05 +09:00
Nobuyoshi Nakada bc002971b6
[Bug #20094] Distinguish `begin` and parentheses 2023-12-27 17:50:15 +09:00
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