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

ruby-changes:69104

From: John <ko1@a...>
Date: Thu, 21 Oct 2021 08:20:50 +0900 (JST)
Subject: [ruby-changes:69104] cb5571eece (master): Flatten mappings when clearing locals

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

From cb5571eece818b33d2f6a33b892e7cda31231e69 Mon Sep 17 00:00:00 2001
From: John Hawthorn <john@h...>
Date: Mon, 12 Jul 2021 13:35:09 -0700
Subject: Flatten mappings when clearing locals

We clear locals when we know their values might change (ex. when
performing a method call). However previously values on the stack which
were originally pushed from a local would still point back to that
local.

With this commit, when clearing locals, we'll now iterate over the
mappings of the stack and copy the known type from the local to the
stack mapping, removing the association to the local.

This should mean both that we'll retain any information we already know
about the local type, and that if a local is modified we won't
incorrectly infer it's new type from the existing value on the stack.
---
 yjit_core.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/yjit_core.c b/yjit_core.c
index c4f18e872f..ae771fb7c4 100644
--- a/yjit_core.c
+++ b/yjit_core.c
@@ -201,6 +201,16 @@ 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#L201
 // eg: because of a call we can't track
 void ctx_clear_local_types(ctx_t* ctx)
 {
+    // When clearing local types we must detach any stack mappings to those
+    // locals. Even if local values may have changed, stack values will not.
+    for (int i = 0; i < ctx->stack_size && i < MAX_LOCAL_TYPES; i++) {
+        temp_mapping_t *mapping = &ctx->temp_mapping[i];
+        if (mapping->kind == TEMP_LOCAL) {
+            RUBY_ASSERT(mapping->idx < MAX_LOCAL_TYPES);
+            ctx->temp_types[i] = ctx->local_types[mapping->idx];
+            *mapping = MAP_STACK;
+        }
+    }
     memset(&ctx->local_types, 0, sizeof(ctx->local_types));
 }
 
-- 
cgit v1.2.1


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

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