[前][次][番号順一覧][スレッド一覧]

ruby-changes:69136

From: John <ko1@a...>
Date: Thu, 21 Oct 2021 08:20:58 +0900 (JST)
Subject: [ruby-changes:69136] 5092d6129a (master): Fix opt_eq for overridden equality

https://git.ruby-lang.org/ruby.git/commit/?id=5092d6129a

From 5092d6129a9f1d57752a29f4808fe74e1c6a666b Mon Sep 17 00:00:00 2001
From: John Hawthorn <john@h...>
Date: Sat, 11 Sep 2021 23:29:24 -0700
Subject: Fix opt_eq for overridden equality

---
 bootstraptest/test_yjit.rb | 26 +++++++++++++++++++++++---
 yjit_codegen.c             |  8 +++++---
 2 files changed, 28 insertions(+), 6 deletions(-)

diff --git a/bootstraptest/test_yjit.rb b/bootstraptest/test_yjit.rb
index 8ddff90050..1ff6b13f5c 100644
--- a/bootstraptest/test_yjit.rb
+++ b/bootstraptest/test_yjit.rb
@@ -1965,7 +1965,7 @@ assert_equal '[true, false, false, false]', %q{ https://github.com/ruby/ruby/blob/trunk/bootstraptest/test_yjit.rb#L1965
   ]
 }
 
-# Redefined eq
+# Redefined String eq
 assert_equal 'true', %q{
   class String
     def ==(other)
@@ -1973,6 +1973,26 @@ assert_equal 'true', %q{ https://github.com/ruby/ruby/blob/trunk/bootstraptest/test_yjit.rb#L1973
     end
   end
 
-  "foo" == "bar"
-  "foo" == "bar"
+  def eq(a, b)
+    a == b
+  end
+
+  eq("foo", "bar")
+  eq("foo", "bar")
+}
+
+# Redefined Integer eq
+assert_equal 'true', %q{
+  class Integer
+    def ==(other)
+      true
+    end
+  end
+
+  def eq(a, b)
+    a == b
+  end
+
+  eq(1, 2)
+  eq(1, 2)
 }
diff --git a/yjit_codegen.c b/yjit_codegen.c
index 2e6613510f..83e6785a97 100644
--- a/yjit_codegen.c
+++ b/yjit_codegen.c
@@ -2048,7 +2048,8 @@ gen_equality_specialized(jitstate_t* jit, ctx_t* ctx, uint8_t *side_exit) https://github.com/ruby/ruby/blob/trunk/yjit_codegen.c#L2048
 
     if (FIXNUM_P(comptime_a) && FIXNUM_P(comptime_b)) {
         if (!assume_bop_not_redefined(jit->block, INTEGER_REDEFINED_OP_FLAG, BOP_EQ)) {
-            return YJIT_CANT_COMPILE;
+            // if overridden, emit the generic version
+            return false;
         }
 
         guard_two_fixnums(ctx, side_exit);
@@ -2067,9 +2068,10 @@ gen_equality_specialized(jitstate_t* jit, ctx_t* ctx, uint8_t *side_exit) https://github.com/ruby/ruby/blob/trunk/yjit_codegen.c#L2068
 
         return true;
     } else if (CLASS_OF(comptime_a) == rb_cString &&
-		    CLASS_OF(comptime_b) == rb_cString) {
+            CLASS_OF(comptime_b) == rb_cString) {
         if (!assume_bop_not_redefined(jit->block, STRING_REDEFINED_OP_FLAG, BOP_EQ)) {
-            return YJIT_CANT_COMPILE;
+            // if overridden, emit the generic version
+            return false;
         }
 
         // Load a and b in preparation for call later
-- 
cgit v1.2.1


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]