From 28da9909849dc02abe74de8170fe4036534361ba Mon Sep 17 00:00:00 2001 From: Jemma Issroff Date: Thu, 26 Jan 2023 11:42:17 -0500 Subject: Limit maximum number of IVs on a shape on T_OBJECTS Create SHAPE_MAX_NUM_IVS (currently 50) and limit all shapes of T_OBJECTS to that number of IVs. When a shape with a T_OBJECT has more than 50 IVs, fall back to the obj_too_complex shape which uses hash lookup for ivs. Note that a previous version of this commit 78fcc9847a9db6d42c8c263154ec05903a370b6b was reverted in 88f2b94065be3fcd6769a3f132cfee8ecfb663b8 because it did not account for non-T_OBJECTS --- test/ruby/test_shapes.rb | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'test/ruby') diff --git a/test/ruby/test_shapes.rb b/test/ruby/test_shapes.rb index b2cd79ab12..85adcd4a80 100644 --- a/test/ruby/test_shapes.rb +++ b/test/ruby/test_shapes.rb @@ -88,6 +88,26 @@ class TestShapes < Test::Unit::TestCase assert_predicate RubyVM::Shape.of(tc), :too_complex? end + def test_too_many_ivs_on_obj + obj = Object.new + + (RubyVM::Shape::SHAPE_MAX_NUM_IVS + 1).times do + obj.instance_variable_set(:"@a#{_1}", 1) + end + + assert_predicate RubyVM::Shape.of(obj), :too_complex? + end + + def test_too_many_ivs_on_class + obj = Class.new + + (RubyVM::Shape::SHAPE_MAX_NUM_IVS + 1).times do + obj.instance_variable_set(:"@a#{_1}", 1) + end + + assert_false RubyVM::Shape.of(obj).too_complex? + end + def test_too_complex_ractor assert_separately([], "#{<<~"begin;"}\n#{<<~'end;'}") begin; -- cgit v1.2.3