Commit 27684959
276849591fafMerged
Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 10 files · +2 added · ~8 modified
Description
Make Class#ancestors / #superclass span the full chain, fix Class inspect
Three related class-object (CLASS-OBJECT.md Phase 3) gaps surfaced against CRuby:
- Class#ancestors on a user class stopped at its first builtin parent, so Dog.ancestors was [Dog, Animal] instead of [Dog, Animal, Object, Kernel, BasicObject]. sp_class_ancestors now continues into the builtin chain (with its module includes) when the walk reaches a builtin, for user and builtin starts alike.
- Class#superclass on a builtin returned Object (sp_class_superclass only knows the user chain), so Integer.superclass was Object, not Numeric. The call site now dispatches cls_id<0 to sp_builtin_superclass, mirroring sp_class_is_ancestor.
- A Class value inspected blank: sp_poly_inspect had no SP_TAG_CLASS arm (so
a class inside an array rendered ""), and
p <class>was unsupported. Both now render the class name via sp_class_to_s.
Two existing tests (class_hierarchy, class_hierarchy_module) asserted the old user-only ancestors via checked-in .expected; regenerated from CRuby (and the inline comments updated) so they pin the now-correct full chain. New test/class_ancestors_superclass.rb covers ancestors/superclass/inspect across user and builtin classes; the < / <= comparisons (now seeing Object in a user class's ancestors) still hold.
965 test (gcc + clang) / 57 bench / optcarrot 59662; clean under clang -fsanitize=address,undefined.
Co-Authored-By: Claude Opus 4.8 [email protected]
Details
- Commit
- 276849591faf
- Parent
- e7af2c6317b4
lib/sp_runtime.hmodifiedView file
case SP_TAG_NIL: return SPL("nil"); case SP_TAG_SYM: return sp_str_concat(SPL(":"), sp_sym_to_s((sp_sym)v.v.i)); case SP_TAG_ENCODING: return sp_sprintf("#<Encoding:%s>", v.v.s ? v.v.s : ""); case SP_TAG_CLASS: { sp_Class c = {v.v.i}; return sp_class_to_s(c); } case SP_TAG_OBJ: /* Built-in container / value-type tags get their typed inspect helper. Matches the dispatch shape in sp_poly_to_s above and thesrc/codegen.cmodifiedView file
Loading diff…
src/codegen_call.cmodifiedView file
Loading diff…
src/codegen_stmt.cmodifiedView file
Loading diff…
test/class_ancestors_superclass.rbaddedView file
Loading diff…
test/class_ancestors_superclass.rb.expectedaddedView file
Loading diff…
test/class_hierarchy.rbmodifiedView file
Loading diff…
test/class_hierarchy.rb.expectedmodifiedView file
Loading diff…
test/class_hierarchy_module.rbmodifiedView file
Loading diff…
test/class_hierarchy_module.rb.expectedmodifiedView file
Loading diff…