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

563 Коммитов

Автор SHA1 Сообщение Дата
Alan Wu 1b06422767
YJIT: Leave cfp->pc uninitialized for VM_FRAME_MAGIC_CFUNC
C function frames don't need to use the VM-specific pc field to run
properly. When pushing a control frame from output code, save one
instruction by leaving the field uninitialized.

Fix-up rb_vm_svar_lep(), which is used while setting local variables via
Regexp#=~. Use cfp->iseq as a secondary signal so it can stop assuming
that all CFUNC frames always have zero pc's.
2023-03-29 17:57:52 -04:00
Alan Wu a1a4d77472 YJIT: code_gc(): Assert self is inline to avoid other_cb()
The derived `&mut` from `other_cb()` overlapped with the parameter
`ocb`.

Use `cfg!()` instead of `#[cfg...]` to avoid unused warnings.
2023-03-29 14:53:49 -04:00
Alan Wu cdededf24d YJIT: Take VM lock in RubyVM::YJIT.code_gc
Code GC needs synchronization.
2023-03-29 14:53:49 -04:00
Alan Wu 93b6997103 YJIT: Fix overlapping &mut in Assembler::code_gc()
Making overlapping `&mut`s triggers Undefined Bahavior. This function
previously had them through `cb` and `ocb` aliasing with `self` or live
references in the caller.

To fix the overlap, take `ocb` as a parameter and don't use `get_inline_cb()`
in the body of the function.
2023-03-29 14:53:49 -04:00
Jimmy Miller a8c6ba23a6
YJIT: Rest and keyword (non-supplying) (#7608)
* YJIT: Rest and keyword (non-supplying)

* Update yjit/src/codegen.rs

---------

Co-authored-by: Maxime Chevalier-Boisvert <maximechevalierb@gmail.com>
2023-03-29 12:31:41 -04:00
Maxime Chevalier-Boisvert 39a34694a0
YJIT: Add `--yjit-pause` and `RubyVM::YJIT.resume` (#7609)
* YJIT: Add --yjit-pause and RubyVM::YJIT.resume

This allows booting YJIT in a suspended state. We chose to add a new
command line option as opposed to simply allowing YJIT.resume to work
without any command line option because it allows for combining with
YJIT tuning command line options. It also simpifies implementation.

Paired with Kokubun and Maxime.

* Update yjit.rb

Co-authored-by: Takashi Kokubun <takashikkbn@gmail.com>

---------

Co-authored-by: Alan Wu <XrXr@users.noreply.github.com>
Co-authored-by: Takashi Kokubun <takashikkbn@gmail.com>
2023-03-28 15:21:19 -04:00
Takashi Kokubun 2f8a598dc5
YJIT: Stop using the starting_context pattern (#7610) 2023-03-28 11:40:48 -07:00
Jimmy Miller 59c3fac6c4
YJIT: Rest and block_arg support (#7584) 2023-03-24 17:01:59 -04:00
Alan Wu 35e9b5348d
YJIT: Constify EC to avoid an `as` pointer cast (#7591) 2023-03-24 12:36:06 -04:00
Takashi Kokubun b4e438d8aa
YJIT: Save PC on rb_str_concat (#7586)
[Bug #19483]

Co-authored-by: Alan Wu <alansi.xingwu@shopify.com>
2023-03-23 13:42:49 -07:00
Jimmy Miller 8286544dc5
YJIT: Use starting context for status === CantCompile (#7583) 2023-03-23 13:11:46 -04:00
Ole Friis Østergaard e950781880
Use shape information in YJIT's definedivar implementation (#7579)
* Use shape information in YJIT's definedivar implementation

* Handle complex shape for definedivar
2023-03-23 11:04:30 -04:00
Koichi Sasada c9fd81b860 `vm_call_single_noarg_inline_builtin`
If the iseq only contains `opt_invokebuiltin_delegate_leave` insn and
the builtin-function (bf) is inline-able, the caller doesn't need to
build a method frame.

`vm_call_single_noarg_inline_builtin` is fast path for such cases.
2023-03-23 14:03:12 +09:00
Alan Wu aa54082d70
YJIT: Fix large ISeq rejection (#7576)
We crashed in some edge cases due to the recent change to not compile
encoded iseqs that are larger than `u16::MAX`.

- Match the C signature of rb_yjit_constant_ic_update() and clamp down
  to `IseqIdx` size
- Return failure instead of panicking with `unwrap()` in codegen when
  the iseq is too large

Co-authored-by: Maxime Chevalier-Boisvert <maxime.chevalierboisvert@shopify.com>
Co-authored-by: Noah Gibbs <noah.gibbs@shopify.com>
2023-03-21 14:24:17 -04:00
Jimmy Miller 5de26bc031
YJIT: Fix incorrect exit in splat (#7575)
So by itself, this shouldn't have been a correctness issue, but we
also pop the stack for block_args. Doing stack manipulation like that
and then side-exiting causes issues. So, while this fixes the
immediate failure, we have a bigger issue with block_args popping and
then exiting that we need to deal with.
2023-03-21 12:57:26 -04:00
Peter Zhu 30e7561d1d Revert "YJIT: Rest and block_arg support (#7557)"
This reverts commit 5d0a1ffafa.

This commit is causing sequel in yjit-bench to raise with this stack trace:

```
sequel-5.64.0/lib/sequel/dataset/sql.rb:266:in `literal': wrong argument type Array (expected Proc) (TypeError)
	from sequel-5.64.0/lib/sequel/database/misc.rb:269:in `literal'
	from sequel-5.64.0/lib/sequel/adapters/shared/sqlite.rb:314:in `column_definition_default_sql'
	from sequel-5.64.0/lib/sequel/database/schema_methods.rb:564:in `block in column_definition_sql'
	from sequel-5.64.0/lib/sequel/database/schema_methods.rb:564:in `each'
	from sequel-5.64.0/lib/sequel/database/schema_methods.rb:564:in `column_definition_sql'
	from sequel-5.64.0/lib/sequel/database/schema_methods.rb:634:in `block in column_list_sql'
	from sequel-5.64.0/lib/sequel/database/schema_methods.rb:634:in `map'
	from sequel-5.64.0/lib/sequel/database/schema_methods.rb:634:in `column_list_sql'
	from sequel-5.64.0/lib/sequel/database/schema_methods.rb:753:in `create_table_sql'
	from sequel-5.64.0/lib/sequel/adapters/shared/sqlite.rb:348:in `create_table_sql'
	from sequel-5.64.0/lib/sequel/database/schema_methods.rb:702:in `create_table_from_generator'
	from sequel-5.64.0/lib/sequel/database/schema_methods.rb:203:in `create_table'
	from benchmarks/sequel/benchmark.rb:19:in `<main>'
```
2023-03-21 10:51:35 -04:00
Takashi Kokubun 51834ff2ec
YJIT: Make dev_nodebug closer to dev (#7570) 2023-03-20 13:03:22 -07:00
Maxime Chevalier-Boisvert 44f444478a
YJIT: tag output type as UnknownHeap in `toregexp` (#7562) 2023-03-20 10:16:22 -04:00
Alan Wu b9f411b3a8 YJIT: Simplify using the BITS associated constant
All the integer types have it.
2023-03-17 17:32:06 -04:00
Maxime Chevalier-Boisvert 6ba07df490
YJIT: make type info more specific in gen_fixnum_cmp and gen_opt_mod (#7555) 2023-03-17 16:16:34 -04:00
Alan Wu 7fc796f92a
YJIT: Delete --yjit-global-constant-state (#7559)
It was useful for evaluating 6068da8937
but I think we should remove it now to make the logic around
invalidation more straight forward.
2023-03-17 16:16:17 -04:00
Alan Wu 2a26a5e677 YJIT: Add and use Branch::assert_layout()
This assert would've caught a bug I wrote while developing
ruby/ruby#7443 so I figured it would be good to commit it
as it could be helpful in the future.
2023-03-17 16:15:58 -04:00
Jimmy Miller 5d0a1ffafa
YJIT: Rest and block_arg support (#7557)
* YJIT: Rest and block_arg support

* Update bootstraptest/test_yjit.rb

---------

Co-authored-by: Maxime Chevalier-Boisvert <maximechevalierb@gmail.com>
2023-03-17 16:11:30 -04:00
Takashi Kokubun 9fd94d6a0c
YJIT: Support entry for multiple PCs per ISEQ (GH-7535) 2023-03-17 11:53:17 -07:00
Alan Wu 10e4fa3a0f YJIT: Use raw pointers and shared references over `Rc<RefCell<_>>`
`Rc` and `RefCell` both incur runtime space costs.
In addition, `RefCell` has given us some headaches with the
non obvious borrow panics it likes to throw out. The latest
one started with 7fd53eeb46
and is yet to be resolved.

Since we already rely on the GC to properly reclaim memory for `Block`
and `Branch`, we might as well stop paying the overhead of `Rc` and
`RefCell`. The `RefCell` panics go away with this change, too.

On 25 iterations of `railsbench` with a stats build I got
`yjit_alloc_size: 8,386,129 => 7,348,637`, with the new memory size 87.6%
of the status quo. This makes the metadata and machine code size roughly
line up one-to-one.

The general idea here is to use `&` shared references with
[interior mutability][1] with `Cell`, which doesn't take any extra
space. The `noalias` requirement that `&mut` imposes is way too hard to
meet and verify. Imagine replacing places where we would've gotten
`BorrowError` from `RefCell` with Rust/LLVM miscompiling us due to aliasing
violations. With shared references, we don't have to think about subtle
cases like the GC _sometimes_ calling the mark callback while codegen
has an aliasing reference in a stack frame below. We mostly only need to
worry about liveness, with which the GC already helps.

There is now a clean split between blocks and branches that are not yet
fully constructed and ones that are "in-service", so to speak. Working
with `PendingBranch` and `JITState` don't really involve `unsafe` stuff.
This change allows `Branch` and `Block` to not have as many optional
fields as many of them are only optional during compilation. Fields that
change post-compilation are wrapped in `Cell` to facilitate mutation
through shared references.

I do some `unsafe` dances here. I've included just a couple tests to run
with Miri (`cargo +nightly miri test miri`). We can add more Miri tests
if desired.

[1]: https://doc.rust-lang.org/std/cell/struct.UnsafeCell.html
2023-03-17 09:30:24 -07:00
Jimmy Miller 5825d7d4a1
YJIT: Remove exit for rest and send combo (#7546) 2023-03-16 17:40:36 -04:00
Maxime Chevalier-Boisvert 473009d7cb
YJIT: add stats to keep track of when branch direction is known (#7544)
This measures the impact of changes made by @jhawthorn last year.
2023-03-16 17:24:08 -04:00
Takashi Kokubun 6183180603
YJIT: Eliminate unnecessary mov for trampolines (#7537) 2023-03-15 16:27:36 -07:00
Alan Wu ca10274fe3
YJIT: Use assert_disasm! in an A64 test to avoid unused warning
I kept getting unused warnings for this macro on A64 macOS.
2023-03-15 19:07:49 -04:00
Maxime Chevalier-Boisvert 9a735c776b
YJIT: use u16 for insn_idx instead of u32 (#7534) 2023-03-15 17:55:29 -04:00
Alan Wu de174681f7 YJIT: Assert that we have the VM lock while marking
Somewhat important because having the lock is a key part of the
soundness reasoning for the `unsafe` usage here.
2023-03-15 15:45:20 -04:00
Aaron Patterson 77c8daa2d4
Make EC required on JIT state (#7520)
* Make EC required on JIT state

Lets make EC required on the JITState object so we don't need to
`unwrap` it.

* Minor nitpicks

---------

Co-authored-by: Alan Wu <XrXr@users.noreply.github.com>
2023-03-15 10:55:07 -04:00
Takashi Kokubun 70ba310212
YJIT: Introduce no_gc attribute (#7511) 2023-03-14 15:38:58 -07:00
Takashi Kokubun 9a43c63d43
YJIT: Implement throw instruction (#7491)
* Break up jit_exec from vm_sendish

* YJIT: Implement throw instruction

* YJIT: Explain what rb_vm_throw does [ci skip]
2023-03-14 13:39:06 -07:00
Takashi Kokubun 76f2031884
YJIT: Allow testing assembler with disasm (#7470)
* YJIT: Allow testing assembler with disasm

* YJIT: Drop new dependencies

* YJIT: Avoid address manipulation

* YJIT: Introduce assert_disasm! macro

* YJIT: Update the comment about assert_disasm
2023-03-14 13:26:05 -04:00
Takashi Kokubun c7822b8dbb
YJIT: Merge add/sub/and/or/xor and mov on x86_64 (#7492) 2023-03-13 16:32:45 -04:00
Jimmy Miller 45127c84d9
YJIT: Handle rest+splat where non-splat < required (#7499) 2023-03-13 11:12:23 -04:00
Takashi Kokubun 83f6eee76c
YJIT: Bump SEND_MAX_DEPTH to 20 (#7469)
* YJIT: Bump SEND_MAX_DEPTH to 20

* Fix a test failure
2023-03-10 17:14:38 -05:00
Maxime Chevalier-Boisvert 65a95b8259
YJIT: upgrade type in `guard_object_is_string` (#7489)
* YJIT: upgrade type in guard_object_is_string

Also make logic more in line with other guard_xxx methods

* Update yjit/src/core.rs

* Revert changes to Type::upgrade()
2023-03-09 18:26:21 -05:00
Takashi Kokubun 487142928a
YJIT: Merge x86_merge into x86_split (#7487) 2023-03-09 11:58:40 -08:00
Takashi Kokubun 74f44dae96 Another fix for 262254dc7d
Koichi might want to adjust his editor configuration.
2023-03-09 09:29:08 -08:00
Takashi Kokubun 3938b79ef9 Revert an unneeded diff in 262254dc7d 2023-03-09 09:15:21 -08:00
Koichi Sasada 262254dc7d rename `defined_ivar` to `definedivar`
because non-opt instructions should contain `_` char.
2023-03-10 00:37:11 +09:00
Takashi Kokubun 22d8e95ffe
YJIT: Optimize `cmp REG, 0` into `test REG, REG` (#7471) 2023-03-09 10:19:59 -05:00
Ole Friis Østergaard 4667a3a665 Add defined_ivar as YJIT instruction as well
This works much like the existing `defined` implementation,
but calls out to rb_ivar_defined instead of the more general
rb_vm_defined.

Other difference to the existing `defined` implementation is
that this new instruction has to take the same operands as
the CRuby `defined_ivar` instruction.
2023-03-08 09:34:31 -08:00
Takashi Kokubun e93e780f3d Remove MJIT's builtin function compiler 2023-03-07 23:16:24 -08:00
Takashi Kokubun 3e731cd945 YJIT: Add comments to peek and x86_merge 2023-03-07 14:59:37 -08:00
Takashi Kokubun 7f557d02c3 YJIT: Merge lea and mov on x86_64 when possible 2023-03-07 14:59:37 -08:00
Jimmy Miller 56df6d5f9d
YJIT: Handle splat+rest for args pass greater than required (#7468)
For example:

```ruby
def my_func(x, y, *rest)
    p [x, y, rest]
end

my_func(1, 2, 3, *[4, 5])
```
2023-03-07 17:03:43 -05:00
Takashi Kokubun 33edcc1120
YJIT: Protect strings from GC on String#<< (#7466)
Fix https://github.com/Shopify/yjit/issues/310

[Bug #19483]

Co-authored-by: Maxime Chevalier-Boisvert <maxime.chevalierboisvert@shopify.com>
Co-authored-by: Jimmy Miller <jimmy.miller@shopify.com>
2023-03-07 16:10:07 -05:00