Commit graph

20692 commits

Author SHA1 Message Date
Aiden Fox Ivey
164bd8e1a6 Add codegen support for ArrayDup 2025-04-18 21:53:01 +09:00
Alan Wu
3e57c4dceb Strength reduce to CCall for sends landing in simple C methods
A new optimization pass. Also:
- Printing for `Insn::CCall`
- Wrap `ID` and add convenience method for printing, replacing calls to rb_id2name()
2025-04-18 21:53:01 +09:00
Takashi Kokubun
ddef6a7ce4 Split LHS of CMP if it's an immediate (https://github.com/Shopify/zjit/pull/94) 2025-04-18 21:53:01 +09:00
Max Bernstein
d8a6d43fa4 Fix opt_neq HIR codegen 2025-04-18 21:53:01 +09:00
Takashi Kokubun
cfc9234ccd Compile Param into VReg and ParallelMov (https://github.com/Shopify/zjit/pull/87) 2025-04-18 21:53:01 +09:00
Maxime Chevalier-Boisvert
97a478f95f Add recursive factorial and fibonacci functions to test_zjit.rb 2025-04-18 21:53:01 +09:00
Takashi Kokubun
6ec411add7 Compile IfFalse, IfTrue, and Jump instructions (https://github.com/Shopify/zjit/pull/72)
* Compile IfFalse instruction

* Add a TODO comment

* Rename *s_len to num_*s

* Run only gen_param() against block.params

* Add a few more tests

* Wrap label indexes with Label

* Compile blocks in reverse post-order

* Simplify a nested test

* s/get_block/block/

* Return a number instead of an iterator

* Clarify the allocator uses disjoint sets of registers

* Use Display for Block and Insn

* Compile IfTrue and Jump

* Avoid resolving Param instructions

* Always compile Insn::Param as basic block arguments

* Remove an obsoleted variable

* Change it back to use find

* Use find for params too

* Use Display more

* Add more tests

* nested if
* if after if
* if elsif else
* loop after loop
* nested loops
* if in loop
* loop in if
2025-04-18 21:53:00 +09:00
Takashi Kokubun
fa7c3e6c9c Implement dynamic dispatch for opt_send_without_block (https://github.com/Shopify/zjit/pull/63)
* Implement dynamic dispatch for opt_send_without_block

* Rename stack methods

* Fix typos

* More clarification on gen_save_sp()

* Update a comment

* Update a comment about spills

* Rename name to method_name

* Test no-arg and 2-arg method calls
2025-04-18 21:53:00 +09:00
Maxime Chevalier-Boisvert
c39a150787 Implement codegen for Test insn (https://github.com/Shopify/zjit/pull/57)
* Implement codegen for Test insn

* Update zjit/src/codegen.rs

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

---------

Co-authored-by: Alan Wu <XrXr@users.noreply.github.com>
2025-04-18 21:53:00 +09:00
Maxime Chevalier-Boisvert
b345fa9006 Reorder two tests, update comment 2025-04-18 21:53:00 +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
Maxime Chevalier-Boisvert
708940e8c2 Add commented out if-else test to test_zjit.rb 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
8adbe292ed Implement Insn::FixnumSub (https://github.com/Shopify/zjit/pull/42) 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
Mari Imaizumi
63b07cdcbb [Feature #20724] Bump Unicode version to 16.0.0 2025-04-18 19:50:23 +09:00
Samuel Williams
06a7b3c144
Only test on known good platforms. (#13123) 2025-04-17 16:19:05 +00:00
Samuel Williams
c4ae6cb500
Prefer th->ec for stack base/size. (#13101) 2025-04-17 13:21:51 +00:00
Kazuki Yamaguchi
0a8a641d0a [ruby/openssl] ssl: fix SSLSocket#syswrite with String-convertible objects
Correctly pass the new object assigned by StringValue() to
ossl_ssl_write_internal_safe().

This is a follow-up to commit 0d8c17aa85 (Reduce
OpenSSL::Buffering#do_write overhead, 2024-12-21).

3ff096196a
2025-04-16 15:16:50 +00:00
Hiroshi SHIBATA
51952929e1
[rubygems/rubygems] Fixed rubocop issue: Layout/SpaceInsideBlockBraces
77a52b011a
2025-04-16 14:10:36 +09:00
Nobuyoshi Nakada
2cf95e2e04
Run the proper version of rake 2025-04-16 08:29:23 +09:00
Tanaka Akira
698ef864a5 IO.select accepts +Float::INFINITY+ as a timeout argument.
matz accepted at the developper meeting 2024-07-11.
2025-04-15 15:55:40 +09:00
Jean Boussier
0606046c1a Lazily create objspace->id_to_obj_tbl
This inverse table is only useful if `ObjectSpace._id2ref` is used,
which is extremely rare. The only notable exception is the `drb` gem
and even then it has an option not to rely on `_id2ref`.

So if we assume this table will never be looked up, we can just
not maintain it, and if it turns out `_id2ref` is called, we
can lock the VM and re-build it.

```
compare-ruby: ruby 3.5.0dev (2025-04-10T09:44:40Z master 684cfa42d7) +YJIT +PRISM [arm64-darwin24]
built-ruby: ruby 3.5.0dev (2025-04-10T10:13:43Z lazy-id-to-obj d3aa9626cc) +YJIT +PRISM [arm64-darwin24]
warming up..

|           |compare-ruby|built-ruby|
|:----------|-----------:|---------:|
|baseline   |     26.364M|   25.974M|
|           |       1.01x|         -|
|object_id  |     10.293M|   14.202M|
|           |           -|     1.38x|
```
2025-04-15 07:57:39 +09:00
viralpraxis
543dd77cc3 [ruby/prism] Fix parsing rescued exception via indexed assignment
Given this code

```ruby
begin
  raise '42'
rescue => A[]
end
```

Prism fails with this backtrace

```
Error: test_unparser/corpus/literal/rescue.txt(Prism::ParserTest): NoMethodError: undefined method `arguments' for nil
prism/lib/prism/translation/parser/compiler.rb:1055:in `visit_index_target_node'
prism/lib/prism/node.rb:9636:in `accept'
prism/lib/prism/compiler.rb:30:in `visit'
prism/lib/prism/translation/parser/compiler.rb:218:in `visit_begin_node'
```

Seems like

```diff
-            visit_all(node.arguments.arguments),
+            visit_all(node.arguments&.arguments || []),
```

fixes the problem.

76d01aeb6c
2025-04-12 17:43:57 +00:00
Xavier Noria
c5c0bb5afc Restore the original order of const_added and inherited callbacks
Originally, if a class was defined with the class keyword, the cref had a
const_added callback, and the superclass an inherited callback, const_added was
called first, and inherited second.

This was discussed in

    https://bugs.ruby-lang.org/issues/21143

and an attempt at changing this order was made.

While both constant assignment and inheritance have happened before these
callbacks are invoked, it was deemed nice to have the same order as in

    C = Class.new

This was mostly for alignment: In that last use case things happen at different
times and therefore the order of execution is kind of obvious, whereas when the
class keyword is involved, the order is opaque to the user and it is up to the
interpreter.

However, soon in

    https://bugs.ruby-lang.org/issues/21193

Matz decided to play safe and keep the existing order.

This reverts commits:

    de097fbe5f
    de48e47ddf
2025-04-10 10:20:31 +02:00
Yusuke Endoh
0d6263bd41 Fix coverage measurement for negative line numbers
Fixes [Bug #21220]

Co-Authored-By: Mike Bourgeous <mike@mikebourgeous.com>
Co-Authored-By: Jean Boussier <jean.boussier@gmail.com>
2025-04-09 23:45:54 +09:00
Nobuyoshi Nakada
ce0d5cc069
Refine dirname test on Windows
- Compare with the root of the target file
- Fix root path of UNC path
2025-04-09 19:14:36 +09:00
Hiroshi SHIBATA
9e93759b99
Restore assertion that is not related mswin platform 2025-04-09 10:20:22 +09:00
Jun Aruga
d5f94941d8 [ruby/openssl] Fix the tests using SHA-1 Probabilistic Signature Scheme (PSS) parameters.
Fedora OpenSSL 3.5 on rawhide stopped accepting SHA-1 PSS[1] parameters.
This is different from the SHA-1 signatures which Fedora OpenSSL stopped
accepting since Fedora 41.[2]

This commit fixes the following test failures related to the SHA-1 PSS
parameters with Fedora OpenSSL 3.5.
Note these failures are the downstream Fedora OpenSSL RPM specific. The tests
pass without this commit with the upstream OpenSSL 3.5.

```
$ rpm -q openssl-libs openssl-devel
openssl-libs-3.5.0-2.fc43.x86_64
openssl-devel-3.5.0-2.fc43.x86_64

$ bundle exec rake test
...
E
===============================================================================================
Error: test_sign_verify_options(OpenSSL::TestPKeyRSA): OpenSSL::PKey::PKeyError: EVP_PKEY_CTX_ctrl_str(ctx, "rsa_mgf1_md", "SHA1"): digest not allowed (digest=SHA1)
/mnt/git/ruby/openssl/test/openssl/test_pkey_rsa.rb:113:in 'Hash#each'
/mnt/git/ruby/openssl/test/openssl/test_pkey_rsa.rb:113:in 'OpenSSL::PKey::PKey#sign'
/mnt/git/ruby/openssl/test/openssl/test_pkey_rsa.rb:113:in 'OpenSSL::TestPKeyRSA#test_sign_verify_options'
     110:       "rsa_pss_saltlen" => 20,
     111:       "rsa_mgf1_md" => "SHA1"
     112:     }
  => 113:     sig_pss = key.sign("SHA256", data, pssopts)
     114:     assert_equal 256, sig_pss.bytesize
     115:     assert_equal true, key.verify("SHA256", sig_pss, data, pssopts)
     116:     assert_equal true, key.verify_pss("SHA256", sig_pss, data,
===============================================================================================
E
===============================================================================================
Error: test_sign_verify_pss(OpenSSL::TestPKeyRSA): OpenSSL::PKey::RSAError: digest not allowed (digest=SHA1)
/mnt/git/ruby/openssl/test/openssl/test_pkey_rsa.rb:191:in 'OpenSSL::PKey::RSA#sign_pss'
/mnt/git/ruby/openssl/test/openssl/test_pkey_rsa.rb:191:in 'OpenSSL::TestPKeyRSA#test_sign_verify_pss'
     188:     data = "Sign me!"
     189:     invalid_data = "Sign me?"
     190:
  => 191:     signature = key.sign_pss("SHA256", data, salt_length: 20, mgf1_hash: "SHA1")
     192:     assert_equal 256, signature.bytesize
     193:     assert_equal true,
     194:       key.verify_pss("SHA256", signature, data, salt_length: 20, mgf1_hash: "SHA1")
===============================================================================================
...
577 tests, 4186 assertions, 0 failures, 2 errors, 0 pendings, 3 omissions, 0 notifications
```

[1] https://en.wikipedia.org/wiki/Probabilistic_signature_scheme
[2] https://fedoraproject.org/wiki/Changes/OpenSSLDistrustSHA1SigVer

e0e771b76f
2025-04-08 17:46:42 +00:00
Hiroshi SHIBATA
b68fe530f1
Windows 11 24H2 with VS 2019 16.11.45 couldn't handle long name test
```
  2) Error:
TestDir#test_children_long_name:
Test::Unit::ProxyError: No such file or directory @ apply2files - C:/Users/hsbt/AppData/Local/Temp/rubytest.zxydnz/d20250408-35424-2b0o6e/bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb/c
    V:/github.com/ruby/ruby/test/ruby/test_dir.rb:653:in 'File.unlink'
    V:/github.com/ruby/ruby/test/ruby/test_dir.rb:653:in 'block in TestDir#test_children_long_name'
    V:/github.com/ruby/ruby/lib/tmpdir.rb:105:in 'Dir.mktmpdir'
    V:/github.com/ruby/ruby/test/ruby/test_dir.rb:646:in 'TestDir#test_children_long_name'
```
2025-04-08 15:46:45 +09:00
Hiroshi SHIBATA
10d6ee6554
Skip some assertions of TestFileExhaustive#test_dirname with Windows platform.
These assertions didn't handle drive letter of Windows

```
  1) Failure:
TestFileExhaustive#test_dirname [V:/github.com/ruby/ruby/test/ruby/test_file_exhaustive.rb:1282]:
<"V:/"> expected but was
<"C:/">.
```
2025-04-08 15:46:45 +09:00
Peter Zhu
e3abdfbc84 Skip test_heaps_grow_independently for MMTk 2025-04-07 09:41:11 -04:00
Peter Zhu
d4406f0627 Grow GC heaps independently
[Bug #21214]

If we allocate objects where one heap holds transient objects and another
holds long lived objects, then the heap with transient objects will grow
along the heap with long lived objects, causing higher memory usage.

For example, we can see this issue in this script:

    def allocate_small_object = []
    def allocate_large_object = Array.new(10)

    arys = Array.new(1_000_000) do
      # Allocate 10 small transient objects
      10.times { allocate_small_object }
      # Allocate 1 large object that is persistent
      allocate_large_object
    end

    pp GC.stat
    pp GC.stat_heap

Before this change:

    heap_live_slots: 2837243
    {0 =>
      {slot_size: 40,
       heap_eden_pages: 1123,
       heap_eden_slots: 1838807},
     2 =>
      {slot_size: 160,
       heap_eden_pages: 2449,
       heap_eden_slots: 1001149},
    }

After this change:

    heap_live_slots: 1094474
    {0 =>
      {slot_size: 40,
       heap_eden_pages: 58,
       heap_eden_slots: 94973},
     2 =>
      {slot_size: 160,
       heap_eden_pages: 2449,
       heap_eden_slots: 1001149},
    }
2025-04-07 09:41:11 -04:00
Yusuke Endoh
3a7b9ca93b Fix Integer.sqrt to never exceed actual value
`Integer.sqrt` uses `sqrt(3)` from libm for small values.
This method must return a value less than or equal to the actual integer
square root, but libm's sqrt does not always guarantee that.

This change corrects that by decrementing the result if necessary.

Fixes [Bug #21217]
2025-04-07 11:08:10 +09:00
Hiroshi SHIBATA
0251abca7f
Fixed mismatched indentation 2025-04-04 14:23:25 +09:00
Hiroshi SHIBATA
705a95323e
Removed unused variable 2025-04-04 14:21:05 +09:00
Kazuki Yamaguchi
6b5e187d0e [ruby/openssl] pkcs7: fix test failure on RHEL 9
The test case test_split_content fails on RHEL 9 and Fedora 41 because
their OpenSSL packages do not accept SHA-1 signatures. This was only
caught after commit 69fd7f8863 added the missing assertion.

While the example PKCS#7 structures could be simply regenerated with
SHA-256, this test case could be simplified because it is checking two
different things.

Replace test_split_content with separate test cases: one verifying
signed-data authenticatedAttributes and another for decoding BER input.

Fixes https://github.com/ruby/openssl/issues/875

b32406b0c1
2025-04-03 17:58:30 +00:00
Kazuki Yamaguchi
3911113bc4 [ruby/openssl] pkcs7: update test case test_graceful_parsing_failure
Using test_pkcs7.rb as an example invalid input is not reliable because
we may happen to include a valid PKCS#7 PEM block in a heredoc.

76fead26d2
2025-04-03 17:58:29 +00:00
Hiroshi SHIBATA
fab133e629 Use EnvUtil.apply_timeout_scale 2025-04-03 20:03:18 +09:00
Hiroshi SHIBATA
3f152ce767 Extend open_timeout for test failure on s390x
20250403T060004Z.fail.html.gz
2025-04-03 20:03:18 +09:00
Jeremy Evans
29dafa5fc2 Fix assertion failure with anonymous splats
When calling a method that accepts an anonymous splat and literal
keywords without any arguments, an assertion failure was previously
raised. Set rest_index to 0 when setting rest to the frozen hash,
so the args_argc calculation is accurate.

While here, add more tests for methods with anonymous splats with
and without keywords and keyword splats to confirm behavior is
correct.

Also add a basic bootstrap test that would hit the previous assertion
failure.

Co-authored-by: Jean Boussier <jean.boussier@gmail.com>
2025-04-02 19:31:05 -07:00
Earlopain
d543fda433 [ruby/prism] Be explicit in tests which files parser can't parse
It also updates to latest `parser`, which allows numbered
parameters in pattern matching pin,
passing `patterns.txt` and `case.txt`

bdcc8b3dc5
2025-04-02 20:53:34 +00:00
Earlopain
334c261cc9 [ruby/prism] Fix parser translator when splatting in pattern matching pin
Because it ends up treating it as a local variable, and `a.x`
is not a valid local variable name.

I'm not big on pattern matching, but conceptually it makes sense to me
to treat anything inside ^() to not be
pattern matching syntax?

80dbd85c45
2025-04-02 20:51:54 +00:00
Hiroshi SHIBATA
43ee4a50d9 Fixup comment for Windows platform, not Solaris 2025-04-02 16:24:47 +09:00