summaryrefslogtreecommitdiff
path: root/object.c
AgeCommit message (Collapse)Author
4 days[DOC] Improve docs for Module#>=Peter Zhu
4 days[DOC] Improve docs for Module#<=Peter Zhu
4 days[DOC] Improve docs for Module#<Peter Zhu
4 days[DOC] Improve docs for Module#>Peter Zhu
5 days[DOC] Harmonize #> methodsBurdette Lamar
8 days[DOC] Harmonize #== methods (#15805)Burdette Lamar
9 days[DOC] Harmonize #=== methodsBurdetteLamar
2025-12-21[DOC] Tweaks for Object#<=>Burdette Lamar
2025-12-20[DOC] Tweaks for Module#<=>BurdetteLamar
2025-12-18[DOC] Harmonize lt methodsBurdette Lamar
2025-12-11Assume result from allocator will be validJohn Hawthorn
This adds a fastpath in class_call_alloc_func to simply return if the class matches the one expected. I think we could probably just remove this check, or move it to the debug build.
2025-12-03Handle NEWOBJ tracepoints settings fieldsJean Boussier
[Bug #21710] - struct.c: `struct_alloc` It is possible for a `NEWOBJ` tracepoint call back to write fields into a newly allocated object before `struct_alloc` had the time to set the `RSTRUCT_GEN_FIELDS` flags and such. Hence we can't blindly initialize the `fields_obj` reference to `0` we first need to check no fields were added yet. - object.c: `rb_class_allocate_instance` Similarly, if a `NEWOBJ` tracepoint tries to set fields on the object, the `shape_id` must already be set, as it's required on T_OBJECT to know where to write fields. `NEWOBJ_OF` had to be refactored to accept a `shape_id`.
2025-11-28[DOC] Tweaks for Module#<=>Burdette Lamar
2025-11-28Define Kernel#instance_variables_to_inspectJean Boussier
[Bug #21718] Otherwise objects that don't define it, but define a fairly liberal `method_missing` method will run into errors that are hard to understand: ```ruby class Foo def method_missing(name, ...) name end end p Foo.new.inspect ``` ``` 'Kernel#inspect': wrong argument type Symbol (expected Array) (TypeError) from ../test.rb:7:in '<main>' ```
2025-11-27Reorganize page documentations (#15154)Stan Lo
Re-organize page docs
2025-09-17ZJIT: Call instance allocation function directlyMax Bernstein
2025-09-17ZJIT: Prevent custom allocator in ObjectAllocClassMax Bernstein
2025-08-30Initialize class dup/clone before calling initialize_dup/initialize_cloneJeremy Evans
Previously, you could override the class initialize_dup/initialize_clone method and the class hierarchy would not be set correctly inside the method before calling super. This removes Module#initialize_copy, and instead makes Object#dup/clone call the underlying C function (rb_mod_init_copy) before calling the appropriate initialize_dup/initialize_clone method. This results in the following fixes: * The appropriate initialize_dup method is called (dup on a class will respect superclass initialize_dup). * Inside class initialize_dup/initialize_clone/initialize_copy, class ancestor hierarchy is correct. * Calling singleton_class inside initialize_dup no longer raises a TypeError later in dup. * Calling singleton_class.ancestors inside initialize_dup no longer results in missing ancestors. Fixes [Bug #21538]
2025-08-30object.c: make rb_obj_class_must static inlineJean Boussier
2025-08-30object.c: refactor rb_obj_class and rb_class_realJean Boussier
2025-08-30Kernel#class skip null checkJean Boussier
`Kernel#class` can't possibly be called on an hidden object, hence we don't need to check for `klass == 0`. ``` compare-ruby: ruby 3.5.0dev (2025-08-30T01:45:42Z obj-class 01a57bd6cd) +YJIT +PRISM [arm64-darwin24] built-ruby: ruby 3.5.0dev (2025-08-30T10:21:10Z obj-class b67c16c477) +YJIT +PRISM [arm64-darwin24] | |compare-ruby|built-ruby| |:----------|-----------:|---------:| |obj | 445.217| 642.446| | | -| 1.44x| |extended | 136.826| 117.974| | | 1.16x| -| |singleton | 166.269| 166.695| | | -| 1.00x| |immediate | 380.243| 515.775| | | -| 1.36x| ```
2025-08-30object.c: improve fake_class_p to also handle T_MODULEJean Boussier
This requires ensuring T_MODULE never has FL_SINGLETON set, so RMODULE_IS_REFINEMENT had to be moved.
2025-08-30Micro-optimize Object#classJean Boussier
Since `BUILTIN_TYPE` and `RCLASS_SINGLETON_P` are both stored in `RBasic.flags`, we can combine these two checks in a single bitmask. This rely on `T_ICLASS` and `T_CLASS` not overlapping, and assume `klass` is always either of these types. Just combining the masks brings a small but consistent 1.08x speedup on the simple case benchmark. ``` compare-ruby: ruby 3.5.0dev (2025-08-30T01:45:42Z obj-class 01a57bd6cd) +YJIT +PRISM [arm64-darwin24] built-ruby: ruby 3.5.0dev (2025-08-30T09:56:24Z obj-class 2685f8dbb4) +YJIT +PRISM [arm64-darwin24] | |compare-ruby|built-ruby| |:----------|-----------:|---------:| |obj | 444.410| 478.895| | | -| 1.08x| |extended | 135.139| 140.206| | | -| 1.04x| |singleton | 165.155| 155.832| | | 1.06x| -| |immediate | 380.103| 432.090| | | -| 1.14x| ``` But with the RB_UNLIKELY compiler hint, it's much more significant, however the singleton and enxtended cases are slowed down. However we can assume the simple case is way more common than the other two. ``` compare-ruby: ruby 3.5.0dev (2025-08-30T01:45:42Z obj-class 01a57bd6cd) +YJIT +PRISM [arm64-darwin24] built-ruby: ruby 3.5.0dev (2025-08-30T09:51:01Z obj-class 12d01a1b02) +YJIT +PRISM [arm64-darwin24] | |compare-ruby|built-ruby| |:----------|-----------:|---------:| |obj | 444.951| 556.191| | | -| 1.25x| |extended | 136.836| 113.871| | | 1.20x| -| |singleton | 166.335| 167.747| | | -| 1.01x| |immediate | 379.642| 509.515| | | -| 1.34x| ```
2025-08-27Replace ROBJECT_EMBED by ROBJECT_HEAPJean Boussier
The embed layout is way more common than the heap one, especially since WVA. I think it makes for more readable code to inverse the flag.
2025-08-26Ensure T_OBJECT and T_IMEMO/fields have identical layoutJean Boussier
2025-08-25Get rid of rb_obj_set_shape_idJean Boussier
Now that the shape_id has been unified across all types this helper function doesn't do much over `RBASIC_SET_SHAPE_ID`. It still check if the write is needed, but it doesn't seem useful in places where it's used.
2025-07-31Remove useless set of dest_shape_id in rb_obj_copy_ivarPeter Zhu
2025-07-26Adjust indents [ci skip]Nobuyoshi Nakada
2025-07-04Remove unused src param from rb_shape_copy_fieldsJohn Hawthorn
2025-06-24Reduce exposure of FL_FREEZEJean Boussier
The `FL_FREEZE` flag is redundant with `SHAPE_ID_FL_FROZEN`, so ideally it should be eliminated in favor of the later. Doing so would eliminate the risk of desync between the two, but also solve the problem of the frozen status being global in namespace context (See Bug #21330).
2025-06-15Fix typo in rb_bug message for unreachable codeydah
Notes: Merged: https://github.com/ruby/ruby/pull/13620
2025-06-13Use the `shape_id` rather than `FL_EXIVAR`Jean Boussier
We still keep setting `FL_EXIVAR` so that `rb_shape_verify_consistency` can detect discrepancies. Notes: Merged: https://github.com/ruby/ruby/pull/13612
2025-06-11Refactor the last references to `rb_shape_t`Jean Boussier
The type isn't opaque because Ruby isn't often compiled with LTO, so for optimization purpose it's better to allow as much inlining as possible. However ideally only `shape.c` and `shape.h` should deal with the actual struct, and everything else should just deal with opaque `shape_id_t`. Notes: Merged: https://github.com/ruby/ruby/pull/13586
2025-06-09[Feature #21219] Selective inspect of instance variablesNobuyoshi Nakada
Make Kernel#inspect ask which instance variables should be dumped by the result of `#instance_variables_to_inspect`. Co-Authored-By: Jean Boussier <byroot@ruby-lang.org> Notes: Merged: https://github.com/ruby/ruby/pull/13555
2025-06-07Get rid of SHAPE_T_OBJECTJean Boussier
Now that we have the `heap_index` in shape flags we no longer need `T_OBJECT` shapes. Notes: Merged: https://github.com/ruby/ruby/pull/13556
2025-06-07Replicate `heap_index` in shape_id flags.Jean Boussier
This is preparation to getting rid of `T_OBJECT` transitions. By first only replicating the information it's easier to ensure consistency. Notes: Merged: https://github.com/ruby/ruby/pull/13556
2025-06-05Refactor raw accesses to rb_shape_t.capacityJean Boussier
Notes: Merged: https://github.com/ruby/ruby/pull/13524
2025-06-04Get rid of frozen shapes.Jean Boussier
Instead `shape_id_t` higher bits contain flags, and the first one tells whether the shape is frozen. This has multiple benefits: - Can check if a shape is frozen with a single bit check instead of dereferencing a pointer. - Guarantees it is always possible to transition to frozen. - This allow reclaiming `FL_FREEZE` (not done yet). The downside is you have to be careful to preserve these flags when transitioning. Notes: Merged: https://github.com/ruby/ruby/pull/13289
2025-05-28Use flag for RCLASS_IS_INITIALIZEDJohn Hawthorn
Previously we used a flag to set whether a module was uninitialized. When checked whether a class was initialized, we first had to check that it had a non-zero superclass, as well as that it wasn't BasicObject. With the advent of namespaces, RCLASS_SUPER is now an expensive operation, and though we could just check for the prime superclass, we might as well take this opportunity to use a flag so that we can perform the initialized check with as few instructions as possible. It's possible in the future that we could prevent uninitialized classes from being available to the user, but currently there are a few ways to do that. Notes: Merged: https://github.com/ruby/ruby/pull/13443
2025-05-27Rename `rb_shape_id_canonical_p` -> `rb_shape_canonical_p`Jean Boussier
Notes: Merged: https://github.com/ruby/ruby/pull/13450
2025-05-27Rename `rb_shape_set_shape_id` in `rb_obj_set_shape_id`Jean Boussier
Notes: Merged: https://github.com/ruby/ruby/pull/13450
2025-05-27Refactor `rb_shape_too_complex_p` to take a `shape_id_t`.Jean Boussier
Notes: Merged: https://github.com/ruby/ruby/pull/13450
2025-05-27Refactor `rb_obj_shape` out.Jean Boussier
It still exists but only in `shape.c`. Notes: Merged: https://github.com/ruby/ruby/pull/13450
2025-05-27Refactor `rb_shape_rebuild_shape` to stop exposing `rb_shape_t`Jean Boussier
Notes: Merged: https://github.com/ruby/ruby/pull/13448
2025-05-26Add shape_id to RBasic under 32 bitJohn Hawthorn
This makes `RBobject` `4B` larger on 32 bit systems but simplifies the implementation a lot. [Feature #21353] Co-authored-by: Jean Boussier <byroot@ruby-lang.org> Notes: Merged: https://github.com/ruby/ruby/pull/13341
2025-05-23Avoid calling RCLASS_SUPER in rb_class_superclassJohn Hawthorn
Notes: Merged: https://github.com/ruby/ruby/pull/13420
2025-05-16rb_copy_generic_ivar: reset shape_id when no ivar are presentJean Boussier
Notes: Merged: https://github.com/ruby/ruby/pull/13350
2025-05-16rb_gc_impl_copy_finalizer: generate a new object idJean Boussier
Fix a regression introduced by: https://github.com/ruby/ruby/pull/13155 Notes: Merged: https://github.com/ruby/ruby/pull/13350
2025-05-12Remove respond_to check from Class#bind_callJohn Hawthorn
Notes: Merged: https://github.com/ruby/ruby/pull/13116
2025-05-11Delete code for debugging namespaceSatoshi Tagomori