Commit graph

93207 commits

Author SHA1 Message Date
Max Bernstein
ef95e5ba3d
ZJIT: Profile type+shape distributions (#13901)
ZJIT uses the interpreter to take type profiles of what objects pass through
the code. It stores a compressed record of the history per opcode for the
opcodes we select.

Before this change, we re-used the HIR Type data-structure, a shallow type
lattice, to store historical type information. This was quick for bringup but
is quite lossy as profiles go: we get one bit per built-in type seen, and if we
see a non-built-in type in addition, we end up with BasicObject. Not very
helpful. Additionally, it does not give us any notion of cardinality: how many
of each type did we see?

This change brings with it a much more interesting slice of type history: a
histogram. A Distribution holds a record of the top-N (where N is fixed at Ruby
compile-time) `(Class, ShapeId)` pairs and their counts. It also holds an
*other* count in case we see more than N pairs.

Using this distribution, we can make more informed decisions about when we
should use type information. We can determine if we are strictly monomorphic,
very nearly monomorphic, or something else. Maybe the call-site is polymorphic,
so we should have a polymorphic inline cache. Exciting stuff.

I also plumb this new distribution into the HIR part of the compilation
pipeline.
2025-08-05 16:56:04 -04:00
Burdette Lamar
52312d53ca
[DOC] Tweaks for GC.start (#14093) 2025-08-05 15:58:00 -04:00
S-H-GAMELINKS
6bc07f1422 [ruby/prism] Convert implicit parameter it to local variable in parse_expression_infix function
fb136c6eb5
2025-08-05 13:58:09 -04:00
S-H-GAMELINKS
a12e0c1db1 [ruby/prism] Remove uneeded test
a6b448b10f
2025-08-05 13:58:09 -04:00
S-H-GAMELINKS
02200ac81c [ruby/prism] Add it read and assignment test
659d769621
2025-08-05 13:58:09 -04:00
S-H-GAMELINKS
b482e3d7cd [ruby/prism] Make it = it assign nil to match parse.y behavior [Bug #21139]
Currently Prism returns `42` for code like this:
```ruby
42.tap { it = it; p it } # => 42
```

But parse.y returns `nil`:
```ruby
42.tap { it = it; p it } # => nil
```

In parse.y, it on the right-hand side is parsed as a local variable.
In Prism, it was parsed as the implicit block parameter it, which caused this inconsistent behavior.

This change makes the right-hand side it to be parsed as a local variable, aligning with parse.y's behavior.

Bug ticket: https://bugs.ruby-lang.org/issues/21139

cf3bbf9d2c
2025-08-05 13:58:09 -04:00
Kevin Newton
6e2b139d6a [ruby/prism] Ensure context terminators terminate expressions
915f6b3ae9
2025-08-05 13:58:09 -04:00
Kevin Newton
2e672fdee0 [ruby/prism] Bump JRuby version
27d284bbb8
2025-08-05 13:58:09 -04:00
Kevin Newton
2936da902c [ruby/prism] Handle new ractor stuff
f5ded5104d
2025-08-05 13:58:09 -04:00
ydah
087190fcd2 [ruby/prism] Improve error handling for missing parentheses after 'not' in command calls
d9151b8a82
2025-08-05 13:58:09 -04:00
Yusuke Endoh
f814a77755 [ruby/prism] Reject true && not true
A command-call-like `not true` must be rejected after `&&` and `||`.

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

0513cf22ad
2025-08-05 13:58:09 -04:00
Kevin Newton
18e37ac430 [ruby/prism] Optimize context_terminator with a lookup table
483aa89234
2025-08-05 13:58:09 -04:00
Jean Boussier
3ef8d833ab rb_gc_impl_mark_and_move: avoid needless writes
Assuming not all objects are moved during compaction, it
is preferable to avoid rewriting references that haven't moved
as to avoid invalidating potentially shared memory pages.
2025-08-05 18:41:40 +02:00
Peter Zhu
95320f1ddf Fix RUBY_FREE_AT_EXIT for static symbols
Since static symbols allocate memory, we should deallocate them at shutdown
to prevent memory leaks from being reported with RUBY_FREE_AT_EXIT.
2025-08-05 12:04:27 -04:00
Nobuyoshi Nakada
0e33256c8e
CI: Use \e instead of \033 [ci skip] 2025-08-06 00:22:43 +09:00
Étienne Barrié
4cfe5baf3d Use snprintf instead of deprecated sprintf
When compiling with -fsanitize=address on macOS, the deprecation of
sprintf is effective and prevents compiling yjit.c.

More details: https://openradar.appspot.com/FB11761475.
2025-08-05 17:18:32 +02:00
Nobuyoshi Nakada
79d8a3159f Check if the found pkg-config is usable actually 2025-08-05 23:37:51 +09:00
Nobuyoshi Nakada
8e9ea4c202 Convert PKG_CONFIG_PATH to msys/cygwin path 2025-08-05 23:37:51 +09:00
BurdetteLamar
72b8bb4caf [DOC] Tweaks for String#gsub! 2025-08-05 10:11:11 -04:00
Burdette Lamar
409da39afb
[DOC] Tweaks for String#gsub 2025-08-05 10:06:47 -04:00
BurdetteLamar
b7f65f01ee [DOC] Tweaks for String#grapheme_clusters 2025-08-05 09:26:42 -04:00
ArtSin
a6aaeb9acf load.c: fix prev_ext_config clobbering in require_internal
The variable `prev_ext_config` is modified by `ext_config_push` between
`setjmp` and `longjmp` calls. Since `ext_config_push` and `ext_config_pop`
are small and likely to be inlined, `prev_ext_config` can be allocated on
a register and get clobbered. Fix by making it `volatile`.

This bug can be observed by adding a check for values greater than 1 in
`th2->ext_config.ractor_safe` after `ext_config_pop` and building with Clang.
2025-08-05 22:19:55 +09:00
ydah
3d8af5df11 Fix typo in documentation comment for exc_inspect method in error.c 2025-08-05 21:58:12 +09:00
Nobuyoshi Nakada
d5e7e88f32
Show mkmf.log contents even when pkg-config command failed 2025-08-05 15:56:26 +09:00
Hiroshi SHIBATA
06b14f29a3 Added missing block argument 2025-08-05 13:11:18 +09:00
Hiroshi SHIBATA
015d874133 Sync https://github.com/ruby/test-unit-ruby-core/pull/8 2025-08-05 13:11:18 +09:00
Hiroshi SHIBATA
946165bd48 Added clang-22 build 2025-08-05 11:41:43 +09:00
Hiroshi SHIBATA
3c6bd9c9c7
Pathname is now core class.
We will restore this sync target when `lib/pathname.rb` is migrated to `pathname_builtin.rb`
and backport that file to `ruby/pathname` repo.
2025-08-05 10:33:53 +09:00
Takashi Kokubun
196155812b Resurrect another ZJIT skip on test_handle_interrupted?
Failed at:
4737899286

Partially reverting https://github.com/ruby/ruby/pull/14097
2025-08-04 17:49:43 -07:00
Takashi Kokubun
591849a1a5 Resurrect a ZJIT skip on test_switch_while_busy_loop
This can still hang:
4737338125

partially reverting https://github.com/ruby/ruby/pull/14097
2025-08-04 17:31:09 -07:00
Stan Lo
8091f3bce5
ZJIT: Remove passing tests from exclusions (#14097) 2025-08-04 15:20:07 -07:00
Takashi Kokubun
53b0462841
ZJIT: Add helpers to prepare for C calls (#14100) 2025-08-04 14:44:51 -07:00
Aaron Patterson
89d89fa49d When reading from stdin, put a wrapper around the IO object
The purpose of this commit is to fix Bug #21188.  We need to detect when
stdin has run in to an EOF case.  Unfortunately we can't _call_ the eof
function on IO because it will block.

Here is a short script to demonstrate the issue:

```ruby
x = STDIN.gets
puts x
puts x.eof?
```

If you run the script, then type some characters (but _NOT_ a newline),
then hit Ctrl-D twice, it will print the input string.  Unfortunately,
calling `eof?` will try to read from STDIN again causing us to need a
3rd Ctrl-D to exit the program.

Before introducing the EOF callback to Prism, the input loop looked
kind of like this:

```ruby
loop do
  str = STDIN.gets
  process(str)

  if str.nil?
    p :DONE
  end
end
```

Which required 3 Ctrl-D to exit.  If we naively changed it to something
like this:

```ruby
loop do
  str = STDIN.gets
  process(str)

  if STDIN.eof?
    p :DONE
  end
end
```

It would still require 3 Ctrl-D because `eof?` would block.  In this
patch, we're wrapping the IO object, checking the buffer for a newline
and length, and then using that to simulate a non-blocking eof? method.

This commit wraps STDIN and emulates a non-blocking `eof` function.

[Bug #21188]
2025-08-04 12:34:33 -07:00
Jean Boussier
1c6b36af18
Only define String.json_create & al when json/add is required
All the `json/add` related methods for string were
always defined unconditionally from the generators.

It's preferable to only define them if `json/add` is actually used.
2025-08-04 09:29:53 +09:00
David Rodríguez
65612dbb38 [rubygems/rubygems] Fix daily CI
Platform specific versions of ffi-1.17.2 are not compatible with Ruby
3.5, so Bundler fails to resolve in Ruby 3.5 using recorded VCR
responses.

Use the generic version of ffi-1.17.2, which should work for all rubies,
consistently to fix that.

a192f7e35d
2025-08-04 09:27:51 +09:00
Nobuyoshi Nakada
6179cc0118
[DOC] Fill undocumented documents 2025-08-04 02:23:43 +09:00
Nobuyoshi Nakada
b4dfdb915d
[DOC] Show the rdoc coverage of ruby core 2025-08-04 02:22:44 +09:00
Nobuyoshi Nakada
01fafcca90
[DOC] Fix rdoc coverages for rdoc-srcdir 2025-08-04 02:21:22 +09:00
Nobuyoshi Nakada
0aae9e2afa
[DOC] irb is a bundled gem now 2025-08-04 02:02:33 +09:00
Jean Boussier
a12914b516 pathname_buitin.rb: Remove useless o modifier 2025-08-03 17:28:16 +02:00
Lars Kanis
dc10c92749 Revert to shell execution when invoking nm tool
This reverts a change of commit b3598cf2a3 .
On Windows on ARM64 with LLVM the "NM" tool is called with a parameter like so:
```
  RbConfig::CONFIG["NM"] # => "llvm-nm --no-llvm-bc"
```

Therefore the command must be called with a shell string.
2025-08-03 23:43:58 +09:00
Nobuyoshi Nakada
deb0240ea0 [ruby/optparse] Expand literal home paths only
Paths in environment variables should already be expanded.
The base name of the program is also not subject to expansion.

181752391c
2025-08-03 13:53:27 +00:00
Nobuyoshi Nakada
1619afb350 [ruby/optparse] Fallback HOME
e0fdabf946
2025-08-03 13:53:27 +00:00
Stan Lo
30a20bc166 ZJIT: Reject builtin annotation if its iseq has multiple invokebuiltin insns 2025-08-01 17:44:39 -07:00
Stan Lo
44dee185aa ZJIT: Annotate Kernel#class 2025-08-01 17:44:39 -07:00
Stan Lo
3c1ca509b8 ZJIT: Improve builtin function annotation collection 2025-08-01 17:44:39 -07:00
Stan Lo
85510fc2ff ZJIT: Support annotating builtin functions
This allows us to annotate builtin functions with their return type.
2025-08-01 17:44:39 -07:00
Takashi Kokubun
19cbf8406a
ZJIT: Enable IncrCounter for arm64 (#14086) 2025-08-01 17:37:00 -07:00
Alan Wu
3ad6bba136 ZJIT: Refer to scratch registers in operands
Co-authored-by: Takashi Kokubun <takashi.kokubun@shopify.com>
2025-08-01 17:56:15 -04:00
Alan Wu
afac226478 ZJIT: Fix side-exit panicking when there's too many locals
Previously, ARM64 panicked due to compiled_side_exits() when the memory
displacement got large enough to exceed the 9 bits limit. Usually, we split
these kind of memory operands, but compiled_side_exits() runs after
split.

Using scratch registers, implement `Insn::Store` on ARM such that it can
handle large displacements without split(). Do this for x86 as well, and
remove arch specific code from compiled_side_exits(). We can now run
`TestKeywordArguments`.

Since `Insn::Store` doesn't need splitting now, users enjoy lower
register pressure.

Downside is, using `Assembler::SCRATCH_REG` as a base register is now
sometimes an error, depending on whether `Insn::Store` also needs to
use the register. It seems a fair trade off since `SCRATCH_REG` is
not often used, and we don't put it as a base register anywhere at the
moment.
2025-08-01 17:56:15 -04:00