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

ruby-changes:69012

From: Alan <ko1@a...>
Date: Thu, 21 Oct 2021 08:20:11 +0900 (JST)
Subject: [ruby-changes:69012] da20ff1644 (master): Fix bug in generic case for gen_checktype

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

From da20ff1644a274aff4d5ad22c649c85d83e7e311 Mon Sep 17 00:00:00 2001
From: Alan Wu <XrXr@u...>
Date: Fri, 18 Jun 2021 19:05:02 -0400
Subject: Fix bug in generic case for gen_checktype

When checking for T_HASH, which is Qnil and when the type check succeeds
we were outputting to the stack a Qnil instead of a Qtrue.
---
 bootstraptest/test_yjit.rb | 20 ++++++++++++++++++++
 yjit_codegen.c             |  1 +
 2 files changed, 21 insertions(+)

diff --git a/bootstraptest/test_yjit.rb b/bootstraptest/test_yjit.rb
index e15728fd98..da66c06795 100644
--- a/bootstraptest/test_yjit.rb
+++ b/bootstraptest/test_yjit.rb
@@ -1154,6 +1154,26 @@ assert_equal '7', %q{ https://github.com/ruby/ruby/blob/trunk/bootstraptest/test_yjit.rb#L1154
   foo(5,2)
 }
 
+# test pattern matching
+assert_equal '[:ok, :ok]', %q{
+  class C
+    def destructure_keys
+      {}
+    end
+  end
+
+  pattern_match = ->(i) do
+    case i
+    in a: 0
+      :ng
+    else
+      :ok
+    end
+  end
+
+  [{}, C.new].map(&pattern_match)
+}
+
 # Call to object with singleton
 assert_equal '123', %q{
   obj = Object.new
diff --git a/yjit_codegen.c b/yjit_codegen.c
index 60d2338115..282231ae44 100644
--- a/yjit_codegen.c
+++ b/yjit_codegen.c
@@ -1421,6 +1421,7 @@ gen_checktype(jitstate_t* jit, ctx_t* ctx) https://github.com/ruby/ruby/blob/trunk/yjit_codegen.c#L1421
         mov(cb, REG0, mem_opnd(64, REG0, offsetof(struct RBasic, flags)));
         and(cb, REG0, imm_opnd(RUBY_T_MASK));
         cmp(cb, REG0, imm_opnd(type_val));
+        mov(cb, REG0, imm_opnd(Qtrue));
         mov(cb, REG1, imm_opnd(Qfalse));
         cmovne(cb, REG0, REG1);
 
-- 
cgit v1.2.1


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

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