summaryrefslogtreecommitdiff
path: root/test/ruby/test_shapes.rb
diff options
context:
space:
mode:
authorAaron Patterson <[email protected]>2023-10-19 16:01:35 -0700
committerAaron Patterson <[email protected]>2023-10-24 10:52:06 -0700
commita3f66e09f6596259677f00255a9b6231a2739774 (patch)
treeaddc47766e34c520307baab7952343855af872e0 /test/ruby/test_shapes.rb
parentcaf6a72348431e0e6b61be84919cd06c7a745189 (diff)
geniv objects can become too complex
Diffstat (limited to 'test/ruby/test_shapes.rb')
-rw-r--r--test/ruby/test_shapes.rb94
1 files changed, 89 insertions, 5 deletions
diff --git a/test/ruby/test_shapes.rb b/test/ruby/test_shapes.rb
index ebc94a12d2..591fdbe4a3 100644
--- a/test/ruby/test_shapes.rb
+++ b/test/ruby/test_shapes.rb
@@ -126,13 +126,24 @@ class TestShapes < Test::Unit::TestCase
end
def test_too_many_ivs_on_obj
- obj = Object.new
+ assert_separately([], "#{<<~"begin;"}\n#{<<~'end;'}")
+ begin;
+ class Hi; end
- (RubyVM::Shape::SHAPE_MAX_NUM_IVS + 1).times do
- obj.instance_variable_set(:"@a#{_1}", 1)
- end
+ obj = Hi.new
+ i = 0
+ while RubyVM::Shape.shapes_available > 2
+ obj.instance_variable_set(:"@a#{i}", 1)
+ i += 1
+ end
+
+ obj = Hi.new
+ obj.instance_variable_set(:"@b", 1)
+ obj.instance_variable_set(:"@c", 1)
+ obj.instance_variable_set(:"@d", 1)
- assert_predicate RubyVM::Shape.of(obj), :too_complex?
+ assert_predicate RubyVM::Shape.of(obj), :too_complex?
+ end;
end
def test_too_many_ivs_on_class
@@ -171,6 +182,79 @@ class TestShapes < Test::Unit::TestCase
assert_empty obj.instance_variables
end
+ def test_use_all_shapes_then_freeze
+ assert_separately([], "#{<<~"begin;"}\n#{<<~'end;'}")
+ begin;
+ class Hi; end
+
+ obj = Hi.new
+ i = 0
+ while RubyVM::Shape.shapes_available > 2
+ obj.instance_variable_set(:"@a#{i}", 1)
+ i += 1
+ end
+
+ obj = Hi.new
+ i = 0
+ while RubyVM::Shape.shapes_available > 0
+ obj.instance_variable_set(:"@b#{i}", 1)
+ i += 1
+ end
+ obj.freeze
+ obj.frozen?
+ end;
+ end
+
+ def test_use_all_shapes_module
+ assert_separately([], "#{<<~"begin;"}\n#{<<~'end;'}")
+ begin;
+ class Hi; end
+
+ obj = Hi.new
+ i = 0
+ while RubyVM::Shape.shapes_available > 2
+ obj.instance_variable_set(:"@a#{i}", 1)
+ i += 1
+ end
+
+ obj = Module.new
+ 3.times do
+ obj.instance_variable_set(:"@a#{_1}", _1)
+ end
+
+ ivs = 3.times.map do
+ obj.instance_variable_get(:"@a#{_1}")
+ end
+
+ assert_equal [0, 1, 2], ivs
+ end;
+ end
+
+ def test_complex_freeze_after_clone
+ assert_separately([], "#{<<~"begin;"}\n#{<<~'end;'}")
+ begin;
+ class Hi; end
+
+ obj = Hi.new
+ i = 0
+ while RubyVM::Shape.shapes_available > 2
+ obj.instance_variable_set(:"@a#{i}", 1)
+ i += 1
+ end
+
+ obj = Object.new
+ i = 0
+ while RubyVM::Shape.shapes_available > 0
+ obj.instance_variable_set(:"@b#{i}", i)
+ i += 1
+ end
+
+ v = obj.clone(freeze: true)
+ assert_predicate v, :frozen?
+ assert_equal 0, v.instance_variable_get(:@b0)
+ end;
+ end
+
def test_too_complex_ractor
assert_separately([], "#{<<~"begin;"}\n#{<<~'end;'}")
begin;