Commit 216c5eb
ZJIT: Support nil block parameters (ruby#16492)
* ZJIT: Support nil block parameters
zjit-stats for the ActiveRecord benchmark used to look like this:
```
Top-8 popular complex argument-parameter features not optimized (100.0% of total 2,351,376):
param_block: 2,157,030 (91.7%)
param_forwardable: 77,125 ( 3.3%)
param_rest: 35,052 ( 1.5%)
param_kwrest: 28,827 ( 1.2%)
caller_splat: 27,264 ( 1.2%)
caller_blockarg: 25,309 ( 1.1%)
caller_kwarg: 476 ( 0.0%)
caller_kw_splat: 293 ( 0.0%)
```
This is because we weren't handling the case where a callee takes a
block parameter, but the caller doesn't pass one. For example
```ruby
def test(&blk); blk ? blk.call : 42; end
test
test
```
This patch adds support for `nil` block parameters to bmethod methods as
well as iseq methods. Now ActiveRecord benchmark stats look like this:
```
Top-7 popular complex argument-parameter features not optimized (100.0% of total 192,204):
param_forwardable: 74,983 (39.0%)
param_rest: 35,052 (18.2%)
param_kwrest: 28,827 (15.0%)
caller_splat: 27,264 (14.2%)
caller_blockarg: 25,309 (13.2%)
caller_kwarg: 476 ( 0.2%)
caller_kw_splat: 293 ( 0.2%)
```
For posterity: when the callee method is an iseq method, we already
handled the "no block" case by correctly setting BLOCK_HANDLER_NONE in
the environment. When the callee method is a bmethod, we need to
initialize the block to nil as a local
* amend check for complex_arg_pass_param_block instead of deleting
(call to bmethods with a block is rejected elsewhere, but this makes it
so we weaken the check just enough to admit the no block, callee block
param case)
* replace code that directly contradicts comment with an assert
* add snapshot tests
---------
Co-authored-by: Alan Wu <XrXr@users.noreply.github.com>1 parent 6ae062a commit 216c5eb
3 files changed
+83
-11
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1503 | 1503 | | |
1504 | 1504 | | |
1505 | 1505 | | |
1506 | | - | |
| 1506 | + | |
| 1507 | + | |
| 1508 | + | |
1507 | 1509 | | |
1508 | 1510 | | |
1509 | 1511 | | |
| |||
1570 | 1572 | | |
1571 | 1573 | | |
1572 | 1574 | | |
1573 | | - | |
| 1575 | + | |
| 1576 | + | |
| 1577 | + | |
| 1578 | + | |
| 1579 | + | |
| 1580 | + | |
| 1581 | + | |
| 1582 | + | |
1574 | 1583 | | |
1575 | 1584 | | |
1576 | 1585 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2228 | 2228 | | |
2229 | 2229 | | |
2230 | 2230 | | |
2231 | | - | |
| 2231 | + | |
2232 | 2232 | | |
2233 | 2233 | | |
2234 | 2234 | | |
2235 | 2235 | | |
2236 | 2236 | | |
2237 | 2237 | | |
2238 | 2238 | | |
2239 | | - | |
2240 | 2239 | | |
| 2240 | + | |
2241 | 2241 | | |
2242 | 2242 | | |
2243 | 2243 | | |
2244 | 2244 | | |
2245 | | - | |
2246 | | - | |
2247 | 2245 | | |
2248 | | - | |
| 2246 | + | |
| 2247 | + | |
2249 | 2248 | | |
2250 | 2249 | | |
2251 | 2250 | | |
| |||
3570 | 3569 | | |
3571 | 3570 | | |
3572 | 3571 | | |
3573 | | - | |
| 3572 | + | |
3574 | 3573 | | |
3575 | 3574 | | |
3576 | 3575 | | |
| |||
3609 | 3608 | | |
3610 | 3609 | | |
3611 | 3610 | | |
3612 | | - | |
| 3611 | + | |
3613 | 3612 | | |
3614 | 3613 | | |
3615 | 3614 | | |
| |||
3976 | 3975 | | |
3977 | 3976 | | |
3978 | 3977 | | |
3979 | | - | |
| 3978 | + | |
3980 | 3979 | | |
3981 | 3980 | | |
3982 | 3981 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4514 | 4514 | | |
4515 | 4515 | | |
4516 | 4516 | | |
4517 | | - | |
| 4517 | + | |
| 4518 | + | |
| 4519 | + | |
| 4520 | + | |
4518 | 4521 | | |
4519 | 4522 | | |
4520 | 4523 | | |
| |||
7865 | 7868 | | |
7866 | 7869 | | |
7867 | 7870 | | |
| 7871 | + | |
| 7872 | + | |
| 7873 | + | |
| 7874 | + | |
| 7875 | + | |
| 7876 | + | |
| 7877 | + | |
| 7878 | + | |
| 7879 | + | |
| 7880 | + | |
| 7881 | + | |
| 7882 | + | |
| 7883 | + | |
| 7884 | + | |
| 7885 | + | |
| 7886 | + | |
| 7887 | + | |
| 7888 | + | |
| 7889 | + | |
| 7890 | + | |
| 7891 | + | |
| 7892 | + | |
| 7893 | + | |
| 7894 | + | |
| 7895 | + | |
| 7896 | + | |
| 7897 | + | |
| 7898 | + | |
| 7899 | + | |
| 7900 | + | |
| 7901 | + | |
| 7902 | + | |
| 7903 | + | |
| 7904 | + | |
| 7905 | + | |
| 7906 | + | |
| 7907 | + | |
| 7908 | + | |
| 7909 | + | |
| 7910 | + | |
| 7911 | + | |
| 7912 | + | |
| 7913 | + | |
| 7914 | + | |
| 7915 | + | |
| 7916 | + | |
| 7917 | + | |
| 7918 | + | |
| 7919 | + | |
| 7920 | + | |
| 7921 | + | |
| 7922 | + | |
| 7923 | + | |
| 7924 | + | |
| 7925 | + | |
| 7926 | + | |
| 7927 | + | |
| 7928 | + | |
| 7929 | + | |
| 7930 | + | |
| 7931 | + | |
7868 | 7932 | | |
7869 | 7933 | | |
7870 | 7934 | | |
| |||
0 commit comments