aboutsummaryrefslogtreecommitdiffstats
path: root/bootstraptest
diff options
context:
space:
mode:
authorOle Friis Østergaard <olefriis@gmail.com>2023-03-23 16:04:30 +0100
committerGitHub <noreply@github.com>2023-03-23 11:04:30 -0400
commite950781880784de843aaad8cb4e38c78f96683b2 (patch)
tree057d0d6bd9c8e058c9312ac88c1c1a15ed09bc81 /bootstraptest
parentb738cb01b66c7b80364f9044b64097d690e49fc7 (diff)
downloadruby-e950781880784de843aaad8cb4e38c78f96683b2.tar.gz
Use shape information in YJIT's definedivar implementation (#7579)
* Use shape information in YJIT's definedivar implementation * Handle complex shape for definedivar
Diffstat (limited to 'bootstraptest')
-rw-r--r--bootstraptest/test_yjit.rb47
1 files changed, 47 insertions, 0 deletions
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