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

ruby-changes:69274

From: John <ko1@a...>
Date: Thu, 21 Oct 2021 08:20:35 +0900 (JST)
Subject: [ruby-changes:69274] ed8aa3409a (master): Detach mapping to local in ctx_set_local_type

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

From ed8aa3409a606a1c254eb94f7446827a11c66df2 Mon Sep 17 00:00:00 2001
From: John Hawthorn <john@h...>
Date: Tue, 10 Aug 2021 15:41:27 -0700
Subject: Detach mapping to local in ctx_set_local_type

Similar to the previous fix to ctx_clear_local_types, we must detach
mappings to a local if we are changing its value.
---
 bootstraptest/test_yjit.rb | 13 +++++++++++++
 yjit_core.c                |  9 +++++++++
 2 files changed, 22 insertions(+)

diff --git a/bootstraptest/test_yjit.rb b/bootstraptest/test_yjit.rb
index a164b7a413..8b2d5b044e 100644
--- a/bootstraptest/test_yjit.rb
+++ b/bootstraptest/test_yjit.rb
@@ -1599,3 +1599,16 @@ assert_equal '10', %q{ https://github.com/ruby/ruby/blob/trunk/bootstraptest/test_yjit.rb#L1599
 
   val
 }
+
+# regression test of local type change
+assert_equal '1.1', %q{
+def bar(baz, quux)
+  if baz.integer?
+    baz, quux = quux, nil
+  end
+  baz.to_s
+end
+
+bar(123, 1.1)
+bar(123, 1.1)
+}
diff --git a/yjit_core.c b/yjit_core.c
index 3f866b0a2b..5389f3af5f 100644
--- a/yjit_core.c
+++ b/yjit_core.c
@@ -266,6 +266,15 @@ void ctx_set_local_type(ctx_t* ctx, size_t idx, val_type_t type) https://github.com/ruby/ruby/blob/trunk/yjit_core.c#L266
     if (idx >= MAX_LOCAL_TYPES)
         return;
 
+    // If any values on the stack map to this local we must detach them
+    for (int i = 0; i < MAX_TEMP_TYPES; i++) {
+        temp_mapping_t *mapping = &ctx->temp_mapping[i];
+        if (mapping->kind == TEMP_LOCAL && mapping->idx == idx) {
+            ctx->temp_types[i] = ctx->local_types[mapping->idx];
+            *mapping = MAP_STACK;
+        }
+    }
+
     ctx->local_types[idx] = type;
 }
 
-- 
cgit v1.2.1


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

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