From e950781880784de843aaad8cb4e38c78f96683b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ole=20Friis=20=C3=98stergaard?= Date: Thu, 23 Mar 2023 16:04:30 +0100 Subject: Use shape information in YJIT's definedivar implementation (#7579) * Use shape information in YJIT's definedivar implementation * Handle complex shape for definedivar --- bootstraptest/test_yjit.rb | 47 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) (limited to 'bootstraptest') diff --git a/bootstraptest/test_yjit.rb b/bootstraptest/test_yjit.rb index 64203322c6..14ed13035d 100644 --- a/bootstraptest/test_yjit.rb +++ b/bootstraptest/test_yjit.rb @@ -79,6 +79,53 @@ assert_equal '[nil, nil, nil, nil, nil, nil]', %q{ end } +assert_equal '[nil, nil, nil, nil, nil, nil]', %q{ + # Tests defined? on non-heap objects + [NilClass, TrueClass, FalseClass, Integer, Float, Symbol].each do |klass| + klass.class_eval("def foo = defined?(@foo)") + end + + [nil, true, false, 0xFABCAFE, 0.42, :cake].map do |instance| + instance.foo + instance.foo + end +} + +assert_equal '[nil, "instance-variable", nil, "instance-variable"]', %q{ + # defined? on object that changes shape between calls + class Foo + def foo + defined?(@foo) + end + + def add + @foo = 1 + end + + def remove + self.remove_instance_variable(:@foo) + end + end + + obj = Foo.new + [obj.foo, (obj.add; obj.foo), (obj.remove; obj.foo), (obj.add; obj.foo)] +} + +assert_equal '["instance-variable", 5]', %q{ + # defined? on object too complex for shape information + class Foo + def initialize + 100.times { |i| instance_variable_set("@foo#{i}", i) } + end + + def foo + [defined?(@foo5), @foo5] + end + end + + Foo.new.foo +} + assert_equal '0', %q{ # This is a regression test for incomplete invalidation from # opt_setinlinecache. This test might be brittle, so -- cgit v1.2.1