| Age | Commit message (Collapse) | Author |
|
When these instructions were introduced it was common to read from a
hash with mutable string literals. However, these days, I think these
instructions are fairly rare.
I tested this with the lobsters benchmark, and saw no difference in
speed. In order to be sure, I tracked down every use of this
instruction in the lobsters benchmark, and there were only 4 places
where it was used.
Additionally, this patch fixes a case where "chilled strings" should
emit a warning but they don't.
```ruby
class Foo
def self.[](x)= x.gsub!(/hello/, "hi")
end
Foo["hello world"]
```
Removing these instructions shows this warning:
```
> ./miniruby -vw test.rb
ruby 3.5.0dev (2025-08-25T21:36:50Z rm-opt_aref_with dca08e286c) +PRISM [arm64-darwin24]
test.rb:2: warning: literal string will be frozen in the future (run with --debug-frozen-string-literal for more information)
```
[Feature #21553]
|
|
|
|
When using MN threads (such as running the test in a ractor), this test
failed because it was raising a SystemStackError: stack level too deep.
This is because the machine stack is smaller under MN threads than on
the native main thread.
Notes:
Merged: https://github.com/ruby/ruby/pull/13427
|
|
Prior to https://github.com/ruby/ruby/commit/49b306ecb9e2e9e06e0b1590bacc5f4b38169c3c
the `optional_arg` passed from `rb_hash_update_block_i` to `tbl_update`
was a hash value (i.e. a VALUE). After that commit it changed to an
`update_call_args`.
If the block sets or changes the value, `tbl_update_modify` will set the
`arg.value` back to an actual value and we won't crash. But in the case
where the block returns the original value we end up calling
`RB_OBJ_WRITTEN` with the `update_call_args` which is not expected and
may crash.
`arg.value` appears to only be used to pass to `RB_OBJ_WRITTEN` (others
who need the `update_call_args` get it from `arg.arg`), so I don't think
it needs to be set to anything upfront. And `tbl_update_modify` will set
the `arg.value` in the cases we need the write barrier.
Notes:
Merged: https://github.com/ruby/ruby/pull/13404
|
|
Notes:
Merged: https://github.com/ruby/ruby/pull/13344
|
|
Notes:
Merged: https://github.com/ruby/ruby/pull/13329
|
|
This reverts commit bb180b87b43c45e17ff49735a26d7a188d5c8396, which
caused "malloc during GC" error on wasm.
Notes:
Merged: https://github.com/ruby/ruby/pull/13329
|
|
Notes:
Merged: https://github.com/ruby/ruby/pull/13317
|
|
The code between the two ObjectSpace.count_objects could trigger a GC,
which could free string objects causing this test to fail.
We can see this failure on CI http://ci.rvm.jp/results/trunk-random2@ruby-sp2-noble-docker/5651016
TestHashOnly#test_AREF_fstring_key [test/ruby/test_hash.rb:1991]:
<197483> expected but was
<129689>.
Notes:
Merged: https://github.com/ruby/ruby/pull/12916
|
|
[Bug #21170]
st_table reserves -1 as a special hash value to indicate that an entry
has been deleted. So that that's a valid value to be returned from the
hash function, do_hash replaces -1 with 0 so that it is not mistaken for
the sentinel.
Previously, when upgrading an AR table to an ST table,
rb_st_add_direct_with_hash was used which did not perform the same
conversion, this could lead to a hash in a broken state where one if its
entries which was supposed to exist being marked as a tombstone.
The hash could then become further corrupted when the ST table required
resizing as the falsely tombstoned entry would be skipped but it would
be counted in num entries, leading to an uninitialized entry at index
15.
In most cases this will be really rare, unless using a very poorly
implemented custom hash function.
This also adds two debug assertions, one that st_add_direct_with_hash
does not receive the reserved hash value, and a second in
rebuild_table_with, which ensures that after we rebuild/compact a table
it contains the expected number of elements.
Co-authored-by: Alan Wu <alanwu@ruby-lang.org>
Notes:
Merged: https://github.com/ruby/ruby/pull/12852
|
|
|
|
|
|
Notes:
Merged: https://github.com/ruby/ruby/pull/10924
|
|
Notes:
Merged: https://github.com/ruby/ruby/pull/10924
|
|
As preparation for https://bugs.ruby-lang.org/issues/20205
making sure the test suite is compatible with frozen string
literals is making things easier.
|
|
|
|
callcc's implementation is fundamentally incompatible with ASAN. Since
callcc is deprecated and almost never used, it's probably OK to disable
callcc when ruby is compiled with ASAN.
[Bug #20273]
|
|
[Bug #20145]
Before this commit, both copy_compare_by_id and hash_copy will create a
copy of the ST table, so the ST table created in copy_compare_by_id will
be leaked.
h = { 1 => 2 }.compare_by_identity
10.times do
1_000_000.times do
h.select { false }
end
puts `ps -o rss= -p #{$$}`
end
Before:
110736
204352
300272
395520
460704
476736
542000
604704
682624
770528
After:
15504
16048
16144
16256
16320
16320
16752
16752
16752
16752
|
|
proposed at https://bugs.ruby-lang.org/issues/20050#note-5
|
|
We didn't free the old ST before overwriting it which caused a leak.
Found with RUBY_FREE_ON_EXIT.
Co-authored-by: Peter Zhu <peter@peterzhu.ca>
|
|
|
|
|
|
|
|
|
|
|
|
We need to free the old ST table in Hash#rehash.
Co-authored-by: Adam Hess <adamhess1991@gmail.com>
|
|
Hash#replace can leak memory if the receiver has an ST table.
Notes:
Merged: https://github.com/ruby/ruby/pull/8001
|
|
Test for commit f0d08d11dcd404f3146c0d71d6ff743bbc6e7193.
|
|
With VWA, AR hashes are much larger than ST hashes. Hash#replace
attempts to directly copy the contents of AR hashes into ST hashes so
there will be memory corruption caused by writing past the end of memory.
This commit changes it so that if a ST hash is being replaced with an AR
hash it will insert each element into the ST hash.
Notes:
Merged: https://github.com/ruby/ruby/pull/7846
|
|
[Bug #19589]
When decrementing `iter_lev` from `65` to `64` the flags would be
corrupted, causing the shape_id to be invalid.
Notes:
Merged: https://github.com/ruby/ruby/pull/7686
|
|
opt_aref_with is an optimized instruction for accessing a Hash using a
non-frozen string key (ie. from a file without frozen_string_literal).
It attempts to avoid allocating the string, and instead silently using a
frozen string (hash string keys are always fstrings).
Because this is just an optimization, it should be invisible to the
user. However, previously this optimization was could be seen via hashes
with default procs.
For example, previously:
h = Hash.new { |h, k| k.frozen? }
str = "foo"
h[str] # false
h["foo"] # true when optimizations enabled
This commit checks that the Hash doesn't have a default proc when using
opt_aref_with.
Notes:
Merged: https://github.com/ruby/ruby/pull/6196
|
|
Previously, because opt_aref and opt_aset don't push a frame, when they
would call rb_hash to determine the hash value of the key, the initial
level of recursion would incorrectly use the method id at the top of the
stack instead of "hash".
This commit replaces rb_exec_recursive_outer with
rb_exec_recursive_outer_mid, which takes an explicit method id, so that
we can make the hash calculation behave consistently.
rb_exec_recursive_outer was documented as being internal, so I believe
this should be okay to change.
Notes:
Merged: https://github.com/ruby/ruby/pull/6004
|
|
tab->entries_bound is used to check if the bins are full in
rebuild_table_if_necessary.
Hash#shift against an empty hash assigned 0 to tab->entries_bound, but
didn't clear the bins. Thus, the table is not rebuilt even when the bins
are full. Attempting to add a new element into full-bin hash gets stuck.
This change stops clearing tab->entries_bound in Hash#shift.
[Bug #18578]
Notes:
Merged: https://github.com/ruby/ruby/pull/5539
|
|
Fixes [Bug #16908]
Notes:
Merged: https://github.com/ruby/ruby/pull/5360
|
|
[Feature #14579]
|
|
The value of the dynamic key cannot be omitted for now.
|
|
`{x:, y:}` is a syntax sugar of `{x: x, y: y}`.
|
|
Notes:
Merged: https://github.com/ruby/ruby/pull/4788
|
|
|
|
This makes the compare_by_identity setting always copied
for the following methods:
* except
* merge
* reject
* select
* slice
* transform_values
Some of these methods did not copy the setting, or only
copied the setting if the receiver was not empty.
Fixes [Bug #17757]
Co-authored-by: Kenichi Kamiya <kachick1@gmail.com>
Notes:
Merged: https://github.com/ruby/ruby/pull/4616
Merged-By: jeremyevans <code@jeremyevans.net>
|
|
For a73f13c9070a5189947641638398cbffb8d012d8.
|
|
Notes:
Merged: https://github.com/ruby/ruby/pull/4294
Merged-By: nobu <nobu@ruby-lang.org>
|
|
Notes:
Merged: https://github.com/ruby/ruby/pull/4302
Merged-By: nobu <nobu@ruby-lang.org>
|
|
Close https://github.com/ruby/ruby/pull/4298
Notes:
Merged: https://github.com/ruby/ruby/pull/4299
|
|
Notes:
Merged: https://github.com/ruby/ruby/pull/4299
|
|
refs:
* https://bugs.ruby-lang.org/issues/17736
* https://github.com/ruby/ruby/pull/4296
This commit aims to cover following methods
* Hash#select!
* Hash#filter!
* Hash#keep_if
* Hash#reject!
* Hash#delete_if
I think these are not all.
---
* Ensure the receiver is modifiable or not
* Assert the receiver is not modified
Notes:
Merged: https://github.com/ruby/ruby/pull/4297
|
|
|
|
|
|
As hnum is an unsigned st_index_t, the result of RSHIFT may not be
in the fixable range.
Co-authored-by: NeoCat <neocat@neocat.jp>
|
|
follow up to 9908177857a28633d6279c43a1ad4dfedcb98596
|