Skip to content

Commit 0c1ce03

Browse files
committed
ZJIT: Make hir::types::Class not final and have it include metaclasses
Every class boots with a metaclass, and all metaclasses are subclasses of Class, so `types::Class` has no business in `ExactBitsAndClass`. In fact, we should never see an object whose RBasic::class is exactly rb_cClass because classes get a metaclass on boot. So there is no ClassExact type. This fixes the side exits on getivar-module.rb that were introduced in a8f3c34 ("ZJIT: Add missing guard on ivar access on T_{DATA,CLASS,MODULE}"). The `GuardType v, Class` checked for exactly rb_cClass and never passed.
1 parent 8aa2322 commit 0c1ce03

2 files changed

Lines changed: 8 additions & 9 deletions

File tree

zjit/src/hir_type/gen_hir_type.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ def base_type name, c_name: nil
8989
[type, exact]
9090
end
9191

92-
# Define a new type that cannot be subclassed.
92+
# Define a new type that has no subclasses and cannot be subclassed.
9393
# If c_name is given, mark the rb_cXYZ object as equivalent to this type.
9494
def final_type name, base: $object, c_name: nil
9595
if c_name
@@ -109,7 +109,9 @@ def final_type name, base: $object, c_name: nil
109109
base_type "Set", c_name: "rb_cSet"
110110
base_type "Regexp", c_name: "rb_cRegexp"
111111
module_class, _ = base_type "Module", c_name: "rb_cModule"
112-
class_ = final_type "Class", base: module_class, c_name: "rb_cClass"
112+
# Class cannot be subclassed by doing `class Sub < Class`,
113+
# but every metaclass is a subclass of `Class`. It's not final.
114+
module_class.subtype "Class"
113115

114116
numeric, _ = base_type "Numeric", c_name: "rb_cNumeric"
115117

zjit/src/hir_type/hir_type.inc.rs

Lines changed: 4 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)