From cbd3d655745564e3c33a29a5625ac30b4d69fb29 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Fri, 14 Oct 2022 11:59:31 -0700 Subject: Add a test for transition order We only cache the destination shape id, but that can lead to false cache hits. This patch tests that we correctly handle false cache hits --- test/ruby/test_shapes.rb | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'test') diff --git a/test/ruby/test_shapes.rb b/test/ruby/test_shapes.rb index 0da296189d..0f947bcd47 100644 --- a/test/ruby/test_shapes.rb +++ b/test/ruby/test_shapes.rb @@ -3,6 +3,20 @@ require 'test/unit' # These test the functionality of object shapes class TestShapes < Test::Unit::TestCase + class ShapeOrder + def initialize + @b = :b # 5 => 6 + end + + def set_b + @b = :b # 5 => 6 + end + + def set_c + @c = :c # 5 => 7 + end + end + class Example def initialize @a = 1 @@ -37,6 +51,17 @@ class TestShapes < Test::Unit::TestCase refute_equal(shape1.id, shape2.id) end + def test_shape_order + bar = ShapeOrder.new # 0 => 1 + bar.set_c # 1 => 2 + bar.set_b # 2 => 2 + + foo = ShapeOrder.new # 0 => 1 + shape_id = RubyVM::Shape.of(foo).id + foo.set_b # should not transition + assert_equal shape_id, RubyVM::Shape.of(foo).id + end + def test_iv_index example = RemoveAndAdd.new shape = RubyVM::Shape.of(example) -- cgit v1.2.3