summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAaron Patterson <[email protected]>2022-10-14 11:59:31 -0700
committerAaron Patterson <[email protected]>2022-10-14 12:01:42 -0700
commitcbd3d655745564e3c33a29a5625ac30b4d69fb29 (patch)
tree4f618782e951469771c6dc602874f5859c8feb2e
parent9a5684bf7f92ae71a55ede82ec18c31c161694ec (diff)
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
-rw-r--r--test/ruby/test_shapes.rb25
1 files changed, 25 insertions, 0 deletions
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)