summaryrefslogtreecommitdiff
path: root/object.c
AgeCommit message (Collapse)Author
7 daysInitialize 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]
7 daysobject.c: make rb_obj_class_must static inlineJean Boussier
7 daysobject.c: refactor rb_obj_class and rb_class_realJean Boussier
7 daysKernel#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| ```
7 daysobject.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.
7 daysMicro-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| ```
10 daysReplace 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.
11 daysEnsure T_OBJECT and T_IMEMO/fields have identical layoutJean Boussier
12 daysGet 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
2025-05-11namespace on readSatoshi Tagomori
2025-05-09Refactor `FIRST_T_OBJECT_SHAPE_ID` to not be used outside `shape.c`Jean Boussier
Notes: Merged: https://github.com/ruby/ruby/pull/13291
2025-05-09Rename `RB_OBJ_SHAPE` -> `rb_obj_shape`Jean Boussier
As well as `RB_OBJ_SHAPE_ID` -> `rb_obj_shape_id` and `RSHAPE` is now a simple alias for `rb_shape_lookup`. I tried to turn all these into `static inline` but I'm having trouble with `RUBY_EXTERN rb_shape_tree_t *rb_shape_tree_ptr;` not being exposed as I'd expect. Notes: Merged: https://github.com/ruby/ruby/pull/13283
2025-05-09Rename `rb_shape_get_shape_id` -> `RB_OBJ_SHAPE_ID`Jean Boussier
And `rb_shape_get_shape` -> `RB_OBJ_SHAPE`. Notes: Merged: https://github.com/ruby/ruby/pull/13283
2025-05-09Rename `rb_shape_obj_too_complex` -> `rb_shape_obj_too_complex_p`Jean Boussier
Notes: Merged: https://github.com/ruby/ruby/pull/13283
2025-05-09Refactor `rb_shape_transition_frozen` to return a `shape_id`.Jean Boussier
Notes: Merged: https://github.com/ruby/ruby/pull/13283
2025-05-09Rename `rb_shape_get_shape_by_id` -> `RSHAPE`Jean Boussier
Notes: Merged: https://github.com/ruby/ruby/pull/13283
2025-05-08Move `object_id` in object fields.Jean Boussier
And get rid of the `obj_to_id_tbl` It's no longer needed, the `object_id` is now stored inline in the object alongside instance variables. We still need the inverse table in case `_id2ref` is invoked, but we lazily build it by walking the heap if that happens. The `object_id` concern is also no longer a GC implementation concern, but a generic implementation. Co-Authored-By: Matt Valentine-House <matt@eightbitraptor.com> Notes: Merged: https://github.com/ruby/ruby/pull/13159
2025-05-08shape.c: refactor frozen shape to no longer be finalJean Boussier
This opens the door to store more informations in shapes, such as the `object_id` or object address in case it has been observed and the object has to be moved. Notes: Merged: https://github.com/ruby/ruby/pull/13159
2025-05-08Refactor OBJ_TOO_COMPLEX_SHAPE_ID to not be referenced outside shape.hJean Boussier
Also refactor checks for `->type == SHAPE_OBJ_TOO_COMPLEX`. Notes: Merged: https://github.com/ruby/ruby/pull/13159
2025-05-08Rename `ivptr` -> `fields`, `next_iv_index` -> `next_field_index`Jean Boussier
Ivars will longer be the only thing stored inline via shapes, so keeping the `iv_index` and `ivptr` names would be confusing. Instance variables won't be the only thing stored inline via shapes, so keeping the `ivptr` name would be confusing. `field` encompass anything that can be stored in a VALUE array. Similarly, `gen_ivtbl` becomes `gen_fields_tbl`. Notes: Merged: https://github.com/ruby/ruby/pull/13159
2025-04-30Improve syntax style consistency in shape.c and shape.hJean Boussier
Most of this code use the `type * name` style, while the overwhemling majority of the rest of ruby use the `type *name` style. This is a cosmetic change, but helps with readability.
2025-04-10Document order of execution const_added vs inheritedXavier Noria
Notes: Merged: https://github.com/ruby/ruby/pull/12759
2025-03-07[Bug #21163] Fix hexadecimal float conversionNobuyoshi Nakada
Notes: Merged: https://github.com/ruby/ruby/pull/12878
2025-01-23Repair documentation markup in object.cOlle Jonsson
Issue was visible in https://docs.ruby-lang.org/en/3.4/Kernel.html#module-Kernel-label-IO Notes: Merged: https://github.com/ruby/ruby/pull/12613
2025-01-02[DOC] Exclude 'Class' and 'Module' from RDoc's autolinkingNobuyoshi Nakada
Notes: Merged: https://github.com/ruby/ruby/pull/12496
2025-01-02[DOC] Exclude 'Method' from RDoc's autolinkingNobuyoshi Nakada
Notes: Merged: https://github.com/ruby/ruby/pull/12496