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

ruby-changes:68659

From: Maxime <ko1@a...>
Date: Thu, 21 Oct 2021 08:12:00 +0900 (JST)
Subject: [ruby-changes:68659] 64072dd3a6 (master): Rename variables for clarity

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

From 64072dd3a6a321b674255f44632f2c34ac196507 Mon Sep 17 00:00:00 2001
From: Maxime Chevalier-Boisvert <maxime.chevalierboisvert@s...>
Date: Mon, 9 Nov 2020 16:38:50 -0500
Subject: Rename variables for clarity

---
 ujit_compile.c | 33 +++++++++++++++++----------------
 1 file changed, 17 insertions(+), 16 deletions(-)

diff --git a/ujit_compile.c b/ujit_compile.c
index e6b3864cd9..20592ba54a 100644
--- a/ujit_compile.c
+++ b/ujit_compile.c
@@ -47,10 +47,12 @@ typedef struct ctx_struct https://github.com/ruby/ruby/blob/trunk/ujit_compile.c#L47
 
     // The iseq that owns the region that is compiling
     const rb_iseq_t *iseq;
-    // Index in the iseq to the opcode we are replacing
-    size_t replacement_idx;
-    // The start of output code
-    uint8_t *region_start;
+
+    // Index in the iseq of the opcode we are replacing
+    size_t start_idx;
+
+    // The start of the generated code
+    uint8_t *code_ptr;
 
 } ctx_t;
 
@@ -109,14 +111,14 @@ struct compiled_region_array { https://github.com/ruby/ruby/blob/trunk/ujit_compile.c#L111
     int32_t capa;
     struct compiled_region {
         const rb_iseq_t *iseq;
-        size_t replacement_idx;
+        size_t start_idx;
         uint8_t *code;
     }data[];
 };
 
 // Add an element to a region array, or allocate a new region array.
 static struct compiled_region_array *
-add_compiled_region(struct compiled_region_array *array, const rb_iseq_t *iseq, size_t replacement_idx, uint8_t *code)
+add_compiled_region(struct compiled_region_array *array, const rb_iseq_t *iseq, size_t start_idx, uint8_t *code)
 {
     if (!array) {
         // Allocate a brand new array with space for one
@@ -132,7 +134,7 @@ add_compiled_region(struct compiled_region_array *array, const rb_iseq_t *iseq, https://github.com/ruby/ruby/blob/trunk/ujit_compile.c#L134
     }
     // Check if the region is already present
     for (int32_t i = 0; i < array->size; i++) {
-        if (array->data[i].iseq == iseq && array->data[i].replacement_idx == replacement_idx) {
+        if (array->data[i].iseq == iseq && array->data[i].start_idx == start_idx) {
             return array;
         }
     }
@@ -152,7 +154,7 @@ add_compiled_region(struct compiled_region_array *array, const rb_iseq_t *iseq, https://github.com/ruby/ruby/blob/trunk/ujit_compile.c#L154
 
     int32_t size = array->size;
     array->data[size].iseq = iseq;
-    array->data[size].replacement_idx = replacement_idx;
+    array->data[size].start_idx = start_idx;
     array->data[size].code = code;
     array->size++;
     return array;
@@ -166,7 +168,7 @@ add_lookup_dependency_i(st_data_t *key, st_data_t *value, st_data_t data, int ex https://github.com/ruby/ruby/blob/trunk/ujit_compile.c#L168
     if (existing) {
         regions = (struct compiled_region_array *)*value;
     }
-    regions = add_compiled_region(regions, ctx->iseq, ctx->replacement_idx, ctx->region_start);
+    regions = add_compiled_region(regions, ctx->iseq, ctx->start_idx, ctx->code_ptr);
     if (!regions) {
         rb_bug("ujit: failed to add method lookup dependency"); // TODO: we could bail out of compiling instead
     }
@@ -247,7 +249,6 @@ ctx_get_opcode(ctx_t *ctx) https://github.com/ruby/ruby/blob/trunk/ujit_compile.c#L249
     return opcode_at_pc(ctx->iseq, ctx->pc);
 }
 
-
 // Get an instruction argument from the context object
 static VALUE
 ctx_get_arg(ctx_t* ctx, size_t arg_idx)
@@ -398,8 +399,8 @@ ujit_compile_insn(const rb_iseq_t *iseq, unsigned int insn_idx, unsigned int *ne https://github.com/ruby/ruby/blob/trunk/ujit_compile.c#L399
     ctx.pc = NULL;
     ctx.stack_diff = 0;
     ctx.iseq = iseq;
-    ctx.region_start = code_ptr;
-    ctx.replacement_idx = insn_idx;
+    ctx.code_ptr = code_ptr;
+    ctx.start_idx = insn_idx;
 
     // For each instruction to compile
     unsigned num_instrs = 0;
@@ -975,14 +976,14 @@ rb_ujit_method_lookup_change(VALUE cme_or_cc) https://github.com/ruby/ruby/blob/trunk/ujit_compile.c#L976
         for (int32_t i = 0; i < array->size; i++) {
             struct compiled_region *region = &array->data[i];
             const struct rb_iseq_constant_body *body = region->iseq->body;
-            RUBY_ASSERT((unsigned int)region->replacement_idx < body->iseq_size);
+            RUBY_ASSERT((unsigned int)region->start_idx < body->iseq_size);
             // Restore region address to interpreter address in bytecode sequence
-            if (body->iseq_encoded[region->replacement_idx] == (VALUE)region->code) {
+            if (body->iseq_encoded[region->start_idx] == (VALUE)region->code) {
                 const void *const *code_threading_table = rb_vm_get_insns_address_table();
                 int opcode = rb_vm_insn_addr2insn(region->code);
-                body->iseq_encoded[region->replacement_idx] = (VALUE)code_threading_table[opcode];
+                body->iseq_encoded[region->start_idx] = (VALUE)code_threading_table[opcode];
                 if (UJIT_DUMP_MODE > 0) {
-                    fprintf(stderr, "cc_or_cme=%p now out of date. Restored idx=%u in iseq=%p\n", (void *)cme_or_cc, (unsigned)region->replacement_idx, (void *)region->iseq);
+                    fprintf(stderr, "cc_or_cme=%p now out of date. Restored idx=%u in iseq=%p\n", (void *)cme_or_cc, (unsigned)region->start_idx, (void *)region->iseq);
                 }
             }
         }
-- 
cgit v1.2.1


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

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