summaryrefslogtreecommitdiff
path: root/bootstraptest
diff options
context:
space:
mode:
authorAlan Wu <XrXr@users.noreply.github.com>2021-06-16 18:06:06 -0400
committerAlan Wu <XrXr@users.noreply.github.com>2021-10-20 18:19:36 -0400
commit936ee5556280162da3016bf62ebe74ef07caf882 (patch)
tree094b443010a85104f28a1953b4ba2559238215ea /bootstraptest
parent78f64d14d47f49e7fe68aab202a056cec7b86218 (diff)
Improve opt_not by expanding cfunc codegen
This commit improves opt_not by making it correct when TrueClass#! and/or FalseClass#! is defined and genearting better code when the receiver is a heap object. guard_known_class() can now handle true, false, and nil, and we introduce a codegen function reimplementing rb_obj_not(), used when we know we are calling into rb_obj_not(). Co-authored-by: Maxime Chevalier-Boisvert <maximechevalierb@gmail.com> Co-authored-by: Noah Gibbs <the.codefolio.guy@gmail.com>
Diffstat (limited to 'bootstraptest')
-rw-r--r--bootstraptest/test_yjit.rb70
1 files changed, 70 insertions, 0 deletions
diff --git a/bootstraptest/test_yjit.rb b/bootstraptest/test_yjit.rb
index de20b3565e..129903bf9c 100644
--- a/bootstraptest/test_yjit.rb
+++ b/bootstraptest/test_yjit.rb
@@ -1070,6 +1070,76 @@ assert_normal_exit %q{
foo(Object.new)
}
+# defining TrueClass#!
+assert_equal '[false, false, :ok]', %q{
+ def foo(obj)
+ !obj
+ end
+
+ x = foo(true)
+ y = foo(true)
+
+ class TrueClass
+ def !
+ :ok
+ end
+ end
+
+ z = foo(true)
+
+ [x, y, z]
+}
+
+# defining FalseClass#!
+assert_equal '[true, true, :ok]', %q{
+ def foo(obj)
+ !obj
+ end
+
+ x = foo(false)
+ y = foo(false)
+
+ class FalseClass
+ def !
+ :ok
+ end
+ end
+
+ z = foo(false)
+
+ [x, y, z]
+}
+
+# defining NilClass#!
+assert_equal '[true, true, :ok]', %q{
+ def foo(obj)
+ !obj
+ end
+
+ x = foo(nil)
+ y = foo(nil)
+
+ class NilClass
+ def !
+ :ok
+ end
+ end
+
+ z = foo(nil)
+
+ [x, y, z]
+}
+
+# polymorphic opt_not
+assert_equal '[true, true, false, false, false, false, false]', %q{
+ def foo(obj)
+ !obj
+ end
+
+ foo(0)
+ [foo(nil), foo(false), foo(true), foo([]), foo(0), foo(4.2), foo(:sym)]
+}
+
# getlocal with 2 levels
assert_equal '7', %q{
def foo(foo, bar)