91384 Commits

Author SHA1 Message Date
Max Bernstein
c1d229c505 Remove more outdated TODOs 2025-04-18 21:52:59 +09:00
Max Bernstein
033537fc54 Remove outdated TODO 2025-04-18 21:52:59 +09:00
Takashi Kokubun
9137e24b54 Add a make target to run all ZJIT tests (https://github.com/Shopify/zjit/pull/49)
* Add a make target to run all ZJIT tests

* Remove an unused variable

* Write up a document about testing

* Explain zjit-test-all first

* Clarify what's zjit-test-all
2025-04-18 21:52:59 +09:00
Takashi Kokubun
be8c78f20d Add a skipped test case for opt_mult overflow 2025-04-18 21:52:59 +09:00
Takashi Kokubun
a7f8beee84 Implement all basic Fixnum instructions (https://github.com/Shopify/zjit/pull/50)
* Implement all basic Fixnum instructions

* Use opnd! macro for other instructions as well
2025-04-18 21:52:59 +09:00
Max Bernstein
17ff0bc8d7 Compile FixnumLt (https://github.com/Shopify/zjit/pull/48) 2025-04-18 21:52:59 +09:00
Maxime Chevalier-Boisvert
29c0ef55a7 Add comments to tests 2025-04-18 21:52:59 +09:00
Max Bernstein
1769c05e8d Add diff_text to pretty-print IR differences in unit test failures
This produces errors that look like

    thread 'hir::tests::test_display_types' panicked at src/hir.rs:1777:9:
    assertion `left == right` failed: Differences found (-expected, +actual):
    ---
     bb0():
       v0:NilClassExact = Const Value(nil)
       v2:TrueClassExact = Const Value(true)
       v6:CBool[true] = Test v2
    -  IfFalse v6, bb1(v)
    +  IfFalse v6, bb1(v2)
       v9:Fixnum[3] = Const Value(3)
       Return v9
     bb1(v12):
       v14 = Const Value(4)
       Return v14
    ---

instead of just

    left: "bb0():\n  v0:NilClassExact = Const Value(nil)\n  v2:TrueClassExact = Const Value(true)\n  v6:CBool[true] = Test v2\n  IfFalse v6, bb1(v2)\n  v9:Fixnum[3] = Const Value(3)\n  Return v9\nbb1(v12):\n  v14 = Const Value(4)\n  Return v14\n"
    right: "bb0():\n  v0:NilClassExact = Const Value(nil)\n  v2:TrueClassExact = Const Value(true)\n  v6:CBool[true] = Test v2\n  IfFalse v6, bb1(v)\n  v9:Fixnum[3] = Const Value(3)\n  Return v9\nbb1(v12):\n  v14 = Const Value(4)\n  Return v14\n"
2025-04-18 21:52:59 +09:00
Maxime Chevalier-Boisvert
708940e8c2 Add commented out if-else test to test_zjit.rb 2025-04-18 21:52:59 +09:00
Max Bernstein
a412f9322c Remove reference to nonexistent function 2025-04-18 21:52:59 +09:00
Max Bernstein
42cef565a4 Add intraprocedural flow typing (https://github.com/Shopify/zjit/pull/23)
* Add RPO

* Add basic flow typing

* Add more tests, check for type bit equality

* Run to fixpoint

* Only use/flow types if insn has an output

* WIP

* WIP 2: merge pred args

* It compiles again

* Infer more Const instructions

* Boot VM

* Test displaying types

* .

* Use type_of more

* Extract Param inference into its own function for readability

* .

* .

* Add notion of unions to generated type bit patterns

* .

* .

* Fix hierarchy for user/exact

* .

* .

* .

* Give ArraySet a receiver

* Use Function::find consistently

* s/fd/find/g

* Comment

* .

* Add TODO about recursion

* FrameStateId

* Use worklist based type inference

This requires computing "uses", or at least which blocks to revisit if
their params change.

* Just use a set

* Revert "Just use a set"

This reverts commit 54d88be00cbf78ce7e928c66d955c968187a5ec9.

* Revert "Use worklist based type inference"

This reverts commit e99b24629723c8848fefd5a75caa23e84c2f552e.

* .

* Store block params separately

* Sparse type inference

* Get tests passing after rebase

* .

* Use assert_method_hir

* .
2025-04-18 21:52:59 +09:00
Maxime Chevalier-Boisvert
43d532e36d Add while loop test to test_zjit.rb 2025-04-18 21:52:59 +09:00
Maxime Chevalier-Boisvert
1130809363 Add small test for setlocal 2025-04-18 21:52:59 +09:00
Takashi Kokubun
5fa12b36c2 Set a return value before popping registers (https://github.com/Shopify/zjit/pull/41) 2025-04-18 21:52:59 +09:00
Takashi Kokubun
3e9dd11569 Fix a comment for subtraction 2025-04-18 21:52:59 +09:00
Takashi Kokubun
8adbe292ed Implement Insn::FixnumSub (https://github.com/Shopify/zjit/pull/42) 2025-04-18 21:52:59 +09:00
Takashi Kokubun
c01568e070 Move lib.rs functions to appropriate modules (https://github.com/Shopify/zjit/pull/43) 2025-04-18 21:52:59 +09:00
Takashi Kokubun
ed894fa13b Pass test results using #inspect 2025-04-18 21:52:59 +09:00
Takashi Kokubun
33a052486b Assert everything is compiled in test_zjit (https://github.com/Shopify/zjit/pull/40)
* Assert everything is compiled in test_zjit

* Update a comment on rb_zjit_assert_compiles

Co-authored-by: Maxime Chevalier-Boisvert <maxime.chevalierboisvert@shopify.com>

* Add a comment about assert_compiles

* Actually use pipe_fd

---------

Co-authored-by: Maxime Chevalier-Boisvert <maxime.chevalierboisvert@shopify.com>
2025-04-18 21:52:59 +09:00
Maxime Chevalier-Boisvert
d2115562b9 Add two more small btests 2025-04-18 21:52:59 +09:00
Takashi Kokubun
14253e7d12 Implement Insn::Param using the SP register (https://github.com/Shopify/zjit/pull/39) 2025-04-18 21:52:59 +09:00
Takashi Kokubun
0aef948a1e Load an immediate into a register in the backend (https://github.com/Shopify/zjit/pull/38) 2025-04-18 21:52:59 +09:00
Takashi Kokubun
7dd15abed3 Do not assert inside rb_protect() (https://github.com/Shopify/zjit/pull/37) 2025-04-18 21:52:59 +09:00
Max Bernstein
c5a93df555 Rename Top to Any and Bottom to Empty
Top/Bottom can be unintuitive or ambiguous.
2025-04-18 21:52:59 +09:00
Max Bernstein
bbbf40de3f Store block params separately (https://github.com/Shopify/zjit/pull/35)
Don't put them in the instruction stream. Instead put them in `Block::params`.
2025-04-18 21:52:59 +09:00
Takashi Kokubun
563281e89f Test HIR using FunctionPrinter (https://github.com/Shopify/zjit/pull/34) 2025-04-18 21:52:59 +09:00
Takashi Kokubun
48fa16f644 Load Param off of cfp->ep (https://github.com/Shopify/zjit/pull/31)
* Load Param off of cfp->ep

* Test with --zjit-call-threshold=1 as well

* Fix get_opnd's debug output

* Return Mem operand from gen_param

* Test both first and second calls

* Spell out the namespace for Opnd returns

* Update a comment about gen_param

* Explain why we take a lock

* Fix a typo
2025-04-18 21:52:59 +09:00
Max Bernstein
62adbdf247 Share FrameState by storing it on Function
Give every instruction a cheap ID to hold onto instead of owning a copy.
2025-04-18 21:52:59 +09:00
Takashi Kokubun
22c73f1ccb Implement FixnumAdd and stub PatchPoint/GuardType (https://github.com/Shopify/zjit/pull/30)
* Implement FixnumAdd and stub PatchPoint/GuardType

Co-authored-by: Max Bernstein <max.bernstein@shopify.com>
Co-authored-by: Maxime Chevalier-Boisvert <maxime.chevalierboisvert@shopify.com>

* Clone Target for arm64

* Use $create instead of use create

Co-authored-by: Alan Wu <XrXr@users.noreply.github.com>

* Fix misindentation from suggested changes

* Drop an unneeded variable for mut

* Load operand into a register only if necessary

---------

Co-authored-by: Max Bernstein <max.bernstein@shopify.com>
Co-authored-by: Maxime Chevalier-Boisvert <maxime.chevalierboisvert@shopify.com>
Co-authored-by: Alan Wu <XrXr@users.noreply.github.com>
2025-04-18 21:52:59 +09:00
Max Bernstein
bd41935b02 Add std docs to crate docs
This makes it easier to work offline.
2025-04-18 21:52:59 +09:00
Max Bernstein
d9a51eb865 Sort type bits at compile time for Display 2025-04-18 21:52:59 +09:00
Takashi Kokubun
8b2a4625cb Profile instructions for fixnum arithmetic (https://github.com/Shopify/zjit/pull/24)
* Profile instructions for fixnum arithmetic

* Drop PartialEq from Type

* Do not push PatchPoint onto the stack

* Avoid pushing the output of the guards

* Pop operands after guards

* Test HIR from profiled runs

* Implement Display for new instructions

* Drop unused FIXNUM_BITS

* Use a Rust function to split lines

* Use Display for GuardType operands

Co-authored-by: Max Bernstein <max@bernsteinbear.com>

* Fix tests with Display-ed values

---------

Co-authored-by: Max Bernstein <max@bernsteinbear.com>
2025-04-18 21:52:59 +09:00
Alan Wu
9e31d29e0e Tell GitHub that *.inc.rs files are generated
... and rename hir_type_generated.rs so it gets picked up by the
glob.

This mostly changes how GitHub renders diffs for generated files on
the web interface.

See: https://docs.github.com/en/repositories/working-with-files/managing-files/customizing-how-changed-files-appear-on-github
2025-04-18 21:52:59 +09:00
Max Bernstein
91114b9933 Write all bits in Type as easy-to-read names 2025-04-18 21:52:59 +09:00
Max Bernstein
ec41dffd05 Add compact Type lattice
This will be used for local type inference and potentially SCCP.
2025-04-18 21:52:59 +09:00
Takashi Kokubun
0a543daf15 Add zjit_* instructions to profile the interpreter (https://github.com/Shopify/zjit/pull/16)
* Add zjit_* instructions to profile the interpreter

* Rename FixnumPlus to FixnumAdd

* Update a comment about Invalidate

* Rename Guard to GuardType

* Rename Invalidate to PatchPoint

* Drop unneeded debug!()

* Plan on profiling the types

* Use the output of GuardType as type refined outputs
2025-04-18 21:52:59 +09:00
Takashi Kokubun
30db473389 Compile Insn::Const (https://github.com/Shopify/zjit/pull/18)
* Compile Insn::Const

* Update the comment on JITState

* Print insn index like YJIT

* Wrap and unwrap InsnId
2025-04-18 21:52:59 +09:00
Takashi Kokubun
3c38ad605a Rename --zjit-dump-ssa to --zjit-dump-hir (https://github.com/Shopify/zjit/pull/17)
* Rename --zjit-dump-ssa to --zjit-dump-hir

* Update comments

* Add a comment on iseq_to_hir
2025-04-18 21:52:59 +09:00
Takashi Kokubun
e4d4ee7517 Fix inconsistent triggers of workflows
This is another left-over from https://github.com/Shopify/zjit/pull/12.
No reason to duplicate jobs for PRs.
2025-04-18 21:52:59 +09:00
Takashi Kokubun
c443e538b6 Fix inconsistent workflow settings
This is a left-over from https://github.com/Shopify/zjit/pull/12.
It was supposed to be removed from both workflows in the PR, but this
was somehow uncommitted.
2025-04-18 21:52:59 +09:00
Alan Wu
bd0f63507d Use rustup to get 1.85.0 since GitHub's image doesn't have it 2025-04-18 21:52:59 +09:00
Alan Wu
b8f49888a4 Avoid setting RUST_BACKTRACE environment while panicking
The 2024 edition pointed out that setting env vars in multiple threaded
programs is unsafe, due to it being thread unsafe in glibc. Sure don't
want to crash while already crashing! Always grab a backtrace with
force_backtrace().
2025-04-18 21:52:59 +09:00
Alan Wu
e24be0b8d5 Upgrade bindgen, so it generates unsafe extern as 2024 expects 2025-04-18 21:52:59 +09:00
Alan Wu
26e15ed629 Fix 2024 edition errors 2025-04-18 21:52:59 +09:00
Alan Wu
e5d4769bc5 Bump to Rust 1.85.0, 2024 edition 2025-04-18 21:52:59 +09:00
Max Bernstein
949ef70c5d Make pattern match clearer with global 2025-04-18 21:52:59 +09:00
Max Bernstein
778b67e50d Pretty-print Const 2025-04-18 21:52:59 +09:00
Max Bernstein
cdf16b7393 Add sample union-find implementation 2025-04-18 21:52:59 +09:00
Max Bernstein
fcaa7665c9 Remove Opnd 2025-04-18 21:52:58 +09:00
Max Bernstein
25a36aaf5e Fix ep_offset locals math
Thanks to @xrxr for explaining all of the "kindergarten" math :)
2025-04-18 21:52:58 +09:00