summaryrefslogtreecommitdiff
path: root/symbol.c
AgeCommit message (Collapse)Author
2025-10-23use `SET_SHAREABLE`Koichi Sasada
to adopt strict shareable rule. * (basically) shareable objects only refer shareable objects * (exception) shareable objects can refere unshareable objects but should not leak reference to unshareable objects to Ruby world
2025-10-08[Bug #21629] Initialize `struct RString`Nobuyoshi Nakada
2025-08-26[DOC] Tweaks for String#intern (#14314)Burdette Lamar
2025-08-07symbol.c: use `rb_gc_mark_and_move` over `rb_gc_location`Jean Boussier
The `p->field = rb_gc_location(p->field)` isn't ideal because it means all references are rewritten on compaction, regardless of whether the referenced object has moved. This isn't good for caches nor for Copy-on-Write. `rb_gc_mark_and_move` avoid needless writes, and most of the time allow to have a single function for both marking and updating references.
2025-08-06Fix off-by-one in symbol next_idPeter Zhu
Symbol last_id was changed to next_id, but it remained to be set to tNEXT_ID - 1 initially, causing the initial static symbol to overlap with the last built-in symbol in id.def.
2025-08-05Fix RUBY_FREE_AT_EXIT for static symbolsPeter Zhu
Since static symbols allocate memory, we should deallocate them at shutdown to prevent memory leaks from being reported with RUBY_FREE_AT_EXIT.
2025-07-31Make static symbol ID atomicPeter Zhu
We don't need the VM lock if we make static symbol IDs atomic.
2025-07-28Get rid of ID_JUNKJean Boussier
It has been aliased as ID_INTERNAL for a long time and that alias is much more descriptive.
2025-07-25Remove VM lock in register_static_symidPeter Zhu
2025-07-25Remove VM lock for sym_findPeter Zhu
2025-07-25Remove VM lock for rb_id_attrsetPeter Zhu
2025-07-23Remove global symbol locks for rb_internPeter Zhu
2025-07-23Remove global symbol lock for rb_gc_free_dsymbolPeter Zhu
2025-07-21Introduce free function to rb_concurrent_set_funcsPeter Zhu
If we create a key but don't insert it (due to other Ractor winning the race), then it would leak memory if we don't free it. This introduces a new function to free that memory for this case.
2025-07-21Remove lock for dynamic symbolPeter Zhu
Benchmark: ARGV[0].to_i.times.map do Ractor.new do 1_000_000.times do |i| "hello#{i}".to_sym end end end.map(&:value) Results: | Ractor count | Branch (s) | Master (s) | |--------------|------------|------------| | 1 | 0.364 | 0.401 | | 2 | 0.555 | 1.149 | | 3 | 0.583 | 3.890 | | 4 | 0.680 | 3.288 | | 5 | 0.789 | 5.107 |
2025-07-21Remove dsymbol_fstr_hashPeter Zhu
We don't need to delay the freeing of the fstr for the symbol if we store the hash of the fstr in the dynamic symbol and we use compare-by-identity for removing the dynamic symbol from the sym_set.
2025-07-21Convert global symbol table to concurrent setPeter Zhu
2025-07-04Assume that symbol in rb_check_symbol is not garbagePeter Zhu
rb_check_symbol is a public API, so it is always a bug if the user holds on to a dead object and passes it in.
2025-07-03Assume that the symbol is not garbage in rb_sym2idPeter Zhu
rb_sym2id is a public API, so it is always a bug if the user holds on to a dead object and passes it in.
2025-07-03symbol.c: enforce `intern_str` is always called with a lockJean Boussier
Add missing locks in `rb_intern_str`, `rb_id_attrset` and `rb_intern3`.
2025-06-05Suppress warnings by gcc-13 with `-Og`Nobuyoshi Nakada
2025-05-25Delimit the scopes using encoding/symbol tablesNobuyoshi Nakada
Notes: Merged: https://github.com/ruby/ruby/pull/13439
2025-05-05Add `RBIMPL_ATTR_NONSTRING_ARRAY()` macro for GCC 15Nobuyoshi Nakada
Notes: Merged: https://github.com/ruby/ruby/pull/13256
2025-05-01Drop an ignored attributeTakashi Kokubun
GCC 13.3.0 (Ubuntu 24.04) emits the following warning: ../symbol.c: In function ‘rb_id_attrset’: ../symbol.c:175:9: warning: ‘nonstring’ attribute ignored on objects of type ‘const char[][8]’ [-Wattributes] 175 | RBIMPL_ATTR_NONSTRING() static const char id_types[][8] = { | ^~~~~~~~~~~~~~~~~~~~~
2025-04-30Suppress gcc 15 unterminated-string-initialization warningsNobuyoshi Nakada
2025-02-10Move global symbol reference updating to rb_sym_global_symbols_update_referencesPeter Zhu
Notes: Merged: https://github.com/ruby/ruby/pull/12711
2025-02-10Make ruby_global_symbols movablePeter Zhu
The `ids` array and `dsymbol_fstr_hash` were pinned because they were kept alive by rb_vm_register_global_object. This prevented the GC from moving them even though there were reference updating code. This commit changes it to be marked movable by marking it as a root object. Notes: Merged: https://github.com/ruby/ruby/pull/12711
2024-04-08Add builtin type assertionNobuyoshi Nakada
2024-04-05Assert correct types in get_id_serial_entryPeter Zhu
2024-04-05Assert correct types in set_id_entryPeter Zhu
2024-04-05Assert that rb_sym2str returns 0 or a T_STRINGPeter Zhu
2024-03-06Refactor VM root modulesJean Boussier
This `st_table` is used to both mark and pin classes defined from the C API. But `vm->mark_object_ary` already does both much more efficiently. Currently a Ruby process starts with 252 rooted classes, which uses `7224B` in an `st_table` or `2016B` in an `RArray`. So a baseline of 5kB saved, but since `mark_object_ary` is preallocated with `1024` slots but only use `405` of them, it's a net `7kB` save. `vm->mark_object_ary` is also being refactored. Prior to this changes, `mark_object_ary` was a regular `RArray`, but since this allows for references to be moved, it was marked a second time from `rb_vm_mark()` to pin these objects. This has the detrimental effect of marking these references on every minors even though it's a mostly append only list. But using a custom TypedData we can save from having to mark all the references on minor GC runs. Addtionally, immediate values are now ignored and not appended to `vm->mark_object_ary` as it's just wasted space.
2024-02-14YJIT: Simplify Kernel#send guards and admit more cases (#9956)Alan Wu
Previously, our compile time check rejected dynamic symbols (e.g. what String#to_sym could return) even though we could handle them just fine. The runtime guards for the type of method name was also overly restrictive and didn't accept dynamic symbols. Fold the type check into the rb_get_symbol_id() and take advantage of the guard already checking for 0. This also avoids generating the same call twice in case the same method name is presented as different types.
2024-02-14[DOC] Doc compliance (#9955)Burdette Lamar
2024-02-13Change dsymbol_alloc to use NEWOBJ_OFPeter Zhu
2024-02-08Fix crash when checking symbol encodingPeter Zhu
[Bug #20245] We sometimes pass in a fake string to sym_check_asciionly. This can crash if sym_check_asciionly raises because it creates a CFP with the fake string as the receiver which will crash if GC tries to mark the CFP. For example, the following script crashes: GC.stress = true Object.const_defined?("\xC3")
2023-12-07Free everything at shutdownAdam Hess
when the RUBY_FREE_ON_SHUTDOWN environment variable is set, manually free memory at shutdown. Co-authored-by: Nobuyoshi Nakada <nobu@ruby-lang.org> Co-authored-by: Peter Zhu <peter@peterzhu.ca>
2023-11-29[Bug #20025] Check if upper/lower before fallback to case-foldingNobuyoshi Nakada
2023-06-30Compile debugging code for symbol and ID alwaysNobuyoshi Nakada
2023-06-30Compile code without Symbol GC alwaysNobuyoshi Nakada
2023-02-09Merge gc.h and internal/gc.hMatt Valentine-House
[Feature #19425] Notes: Merged: https://github.com/ruby/ruby/pull/7273
2022-11-15Rewrite Symbol#to_sym and #intern in Ruby (#6683)Takashi Kokubun
Notes: Merged-By: k0kubun <takashikkbn@gmail.com>
2022-10-11Implement optimize send in yjit (#6488)Jimmy Miller
* Implement optimize send in yjit This successfully makes all our benchmarks exit way less for optimize send reasons. It makes some benchmarks faster, but not by as much as I'd like. I think this implementation works, but there are definitely more optimial arrangements. For example, what if we compiled send to a jump table? That seems like perhaps the most optimal we could do, but not obvious (to me) how to implement give our current setup. Co-authored-by: Alan Wu <XrXr@users.noreply.github.com> * Attempt at fixing the issues raised by @XrXr * fix allowlist * returns 0 instead of nil when not found * remove comment about encoding exception * Fix up c changes * Update assert Co-authored-by: Alan Wu <XrXr@users.noreply.github.com> * get rid of unneeded code and fix the flags * Apply suggestions from code review Co-authored-by: Alan Wu <XrXr@users.noreply.github.com> * rename and fix typo Co-authored-by: Alan Wu <XrXr@users.noreply.github.com> Notes: Merged-By: maximecb <maximecb@ruby-lang.org>
2022-07-26Rename rb_ary_tmp_new to rb_ary_hidden_newPeter Zhu
rb_ary_tmp_new suggests that the array is temporary in some way, but that's not true, it just creates an array that's hidden and not on the transient heap. This commit renames it to rb_ary_hidden_new. Notes: Merged: https://github.com/ruby/ruby/pull/6180
2022-07-21Expand tabs [ci skip]Takashi Kokubun
[Misc #18891] Notes: Merged: https://github.com/ruby/ruby/pull/6094
2022-07-20Ensure _id2ref finds symbols with the correct typeDaniel Colson
Prior to this commit it was possible to call `ObjectSpace._id2ref` with an offset static symbol object_id and get back a new, incorrectly tagged symbol: ``` > sensible_sym = ObjectSpace._id2ref(:a.object_id) => :a > nonsense_sym = ObjectSpace._id2ref(:a.object_id + 40) => :a > sensible_sym == nonsense_sym => false ``` `nonsense_sym` ends up tagged with `RUBY_ID_INSTANCE` instead of `RB_ID_LOCAL`. That means we can do silly things like: ``` > foo = Object.new > foo.instance_variable_set(:a, 123) (irb):2:in `instance_variable_set': `a' is not allowed as an instance variable name (NameError) > foo.instance_variable_set(ObjectSpace._id2ref(:a.object_id + 40), 123) => 123 > foo.instance_variables => [:a] ``` This was happening because `get_id_entry` ignores the tag bits when looking up the symbol. So `rb_id2str(symid)` would return a value and then we'd continue on with the nonsense `symid`. This commit prevents the situation by checking that the `symid` actually matches what we get back from `get_id_entry`. Now we get a `RangeError` for the nonsense id: ``` > ObjectSpace._id2ref(:a.object_id) => :a > ObjectSpace._id2ref(:a.object_id + 40) (irb):1:in `_id2ref': 0x000000000013f408 is not symbol id value (RangeError) ``` Co-authored-by: John Hawthorn <jhawthorn@github.com> Notes: Merged: https://github.com/ruby/ruby/pull/6147
2022-07-20[Bug #18905] Check symbol name types more strictlyNobuyoshi Nakada
Notes: Merged: https://github.com/ruby/ruby/pull/6149
2022-04-14[DOC] Move the documentations of moved Symbol methodsNobuyoshi Nakada
2021-11-23Assign temporary ID to anonymous ID [Bug #18250]Nobuyoshi Nakada
Dumped iseq binary can not have unnamed symbols/IDs, and ID 0 is stored instead. As `struct rb_id_table` disallows ID 0, also for the distinction, re-assign a new temporary ID based on the local variable table index when loading from the binary, as well as the parser. Notes: Merged: https://github.com/ruby/ruby/pull/5157
2021-11-07rb_id_serial_to_id: return unregistered ID as an internal IDNobuyoshi Nakada
```ruby def foo(*); ->{ super }; end ``` This code makes anonymous parameters which is not registered as an ID. The problem is that when Ractors try to scan `getlocal` instructions, it puts the Symbol corresponding to the parameter in to a hash. Since it is not registered, we end up with a strange exception. This commit wraps the unregistered ID in an internal ID so that we get the same exception for `...` as `*`. Co-Authored-By: Aaron Patterson <tenderlove@ruby-lang.org> Co-Authored-By: John Hawthorn <john@hawthorn.email> Notes: Merged: https://github.com/ruby/ruby/pull/5035