From 10788166e7e568fdcd0b748e8d5dab442dcdc7ef Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Thu, 17 Nov 2022 15:57:11 -0800 Subject: Differentiate T_OBJECT shapes from other objects We would like to differentiate types of objects via their shape. This commit adds a special T_OBJECT shape when we allocate an instance of T_OBJECT. This allows us to avoid testing whether an object is an instance of a T_OBJECT or not, we can just check the shape. --- test/ruby/test_shapes.rb | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) (limited to 'test/ruby') diff --git a/test/ruby/test_shapes.rb b/test/ruby/test_shapes.rb index 326ff3a453..848bb4971a 100644 --- a/test/ruby/test_shapes.rb +++ b/test/ruby/test_shapes.rb @@ -88,8 +88,8 @@ class TestShapes < Test::Unit::TestCase class TestObject; end - def test_new_obj_has_root_shape - assert_shape_equal(RubyVM::Shape.root_shape, RubyVM::Shape.of(TestObject.new)) + def test_new_obj_has_t_object_shape + assert_shape_equal(RubyVM::Shape.root_shape, RubyVM::Shape.of(TestObject.new).parent) end def test_str_has_root_shape @@ -114,14 +114,23 @@ class TestShapes < Test::Unit::TestCase def test_basic_shape_transition obj = Example.new - refute_equal(RubyVM::Shape.root_shape, RubyVM::Shape.of(obj)) - assert_shape_equal(RubyVM::Shape.root_shape.edges[:@a], RubyVM::Shape.of(obj)) + shape = RubyVM::Shape.of(obj) + refute_equal(RubyVM::Shape.root_shape, shape) + assert_equal :@a, shape.edge_name + assert_equal RubyVM::Shape::SHAPE_IVAR, shape.type + + shape = shape.parent + assert_equal RubyVM::Shape::SHAPE_T_OBJECT, shape.type + + shape = shape.parent + assert_equal(RubyVM::Shape.root_shape.id, shape.id) assert_equal(obj.instance_variable_get(:@a), 1) end def test_different_objects_make_same_transition - obj = Example.new + obj = [] obj2 = "" + obj.instance_variable_set(:@a, 1) obj2.instance_variable_set(:@a, 1) assert_shape_equal(RubyVM::Shape.of(obj), RubyVM::Shape.of(obj2)) end -- cgit v1.2.3