[前][次][番号順一覧][スレッド一覧]

ruby-changes:73990

From: Aaron <ko1@a...>
Date: Sat, 15 Oct 2022 04:02:14 +0900 (JST)
Subject: [ruby-changes:73990] cbd3d65574 (master): Add a test for transition order

https://git.ruby-lang.org/ruby.git/commit/?id=cbd3d65574

From cbd3d655745564e3c33a29a5625ac30b4d69fb29 Mon Sep 17 00:00:00 2001
From: Aaron Patterson <tenderlove@r...>
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(+)

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' https://github.com/ruby/ruby/blob/trunk/test/ruby/test_shapes.rb#L3
 
 # 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 https://github.com/ruby/ruby/blob/trunk/test/ruby/test_shapes.rb#L51
     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.1


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]