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

ruby-changes:59125

From: Yusuke <ko1@a...>
Date: Mon, 9 Dec 2019 15:23:57 +0900 (JST)
Subject: [ruby-changes:59125] 156fb72d70 (master): vm_args.c (rb_warn_check): Use iseq_unique_id instead of its pointer

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

From 156fb72d7015b420c57b0bd230693f52d8d75b32 Mon Sep 17 00:00:00 2001
From: Yusuke Endoh <mame@r...>
Date: Mon, 9 Dec 2019 15:22:48 +0900
Subject: vm_args.c (rb_warn_check): Use iseq_unique_id instead of its pointer

(This is the second try of 036bc1da6c6c9b0fa9b7f5968d897a9554dd770e.)

If iseq is GC'ed, the pointer of iseq may be reused, which may hide a
deprecation warning of keyword argument change.

http://ci.rvm.jp/results/trunk-test1@phosphorus-docker/2474221

```
1) Failure:
TestKeywordArguments#test_explicit_super_kwsplat [/tmp/ruby/v2/src/trunk-test1/test/ruby/test_keyword.rb:549]:
--- expected
+++ actual
@@ -1 +1 @@
-/The keyword argument is passed as the last hash parameter.* for `m'/m
+""
```

This change ad-hocly adds iseq_unique_id for each iseq, and use it
instead of iseq pointer.  This covers the case where caller is GC'ed.
Still, the case where callee is GC'ed, is not covered.

But anyway, it is very rare that iseq is GC'ed.  Even when it occurs, it
just hides some warnings.  It's no big deal.

diff --git a/compile.c b/compile.c
index aee9672..e46035a 100644
--- a/compile.c
+++ b/compile.c
@@ -10490,7 +10490,7 @@ ibf_load_location_str(const struct ibf_load *load, VALUE str_index) https://github.com/ruby/ruby/blob/trunk/compile.c#L10490
 static void
 ibf_load_iseq_each(struct ibf_load *load, rb_iseq_t *iseq, ibf_offset_t offset)
 {
-    struct rb_iseq_constant_body *load_body = iseq->body = ZALLOC(struct rb_iseq_constant_body);
+    struct rb_iseq_constant_body *load_body = iseq->body = rb_iseq_constant_body_alloc();
 
     ibf_offset_t reading_pos = offset;
 
diff --git a/iseq.c b/iseq.c
index 7fbb906..4298130 100644
--- a/iseq.c
+++ b/iseq.c
@@ -427,11 +427,22 @@ rb_iseq_memsize(const rb_iseq_t *iseq) https://github.com/ruby/ruby/blob/trunk/iseq.c#L427
     return size;
 }
 
+static unsigned long fresh_iseq_unique_id = 0; /* -- Remove In 3.0 -- */
+
+struct rb_iseq_constant_body *
+rb_iseq_constant_body_alloc(void)
+{
+    struct rb_iseq_constant_body *iseq_body;
+    iseq_body = ZALLOC(struct rb_iseq_constant_body);
+    iseq_body->iseq_unique_id = fresh_iseq_unique_id++; /* -- Remove In 3.0 -- */
+    return iseq_body;
+}
+
 static rb_iseq_t *
 iseq_alloc(void)
 {
     rb_iseq_t *iseq = iseq_imemo_alloc();
-    iseq->body = ZALLOC(struct rb_iseq_constant_body);
+    iseq->body = rb_iseq_constant_body_alloc();
     return iseq;
 }
 
diff --git a/iseq.h b/iseq.h
index 3701c32..25c62a3 100644
--- a/iseq.h
+++ b/iseq.h
@@ -186,6 +186,7 @@ void rb_iseq_trace_set(const rb_iseq_t *iseq, rb_event_flag_t turnon_events); https://github.com/ruby/ruby/blob/trunk/iseq.h#L186
 void rb_iseq_trace_set_all(rb_event_flag_t turnon_events);
 void rb_iseq_insns_info_encode_positions(const rb_iseq_t *iseq);
 
+struct rb_iseq_constant_body *rb_iseq_constant_body_alloc(void);
 VALUE rb_iseqw_new(const rb_iseq_t *iseq);
 const rb_iseq_t *rb_iseqw_to_iseq(VALUE iseqw);
 
diff --git a/vm_args.c b/vm_args.c
index 97b1d4a..c6c1118 100644
--- a/vm_args.c
+++ b/vm_args.c
@@ -593,8 +593,12 @@ VALUE rb_iseq_location(const rb_iseq_t *iseq); https://github.com/ruby/ruby/blob/trunk/vm_args.c#L593
  */
 static st_table *caller_to_callees = 0;
 
-static VALUE rb_warn_check(const rb_execution_context_t * const ec, const void *const callee)
+static VALUE rb_warn_check(const rb_execution_context_t * const ec, const rb_iseq_t *const iseq)
 {
+    if (!iseq) return 0;
+
+    const void *const callee = (void *)(iseq->body->iseq_unique_id * 2);
+
     const rb_control_frame_t * const cfp = rb_vm_get_ruby_level_next_cfp(ec, ec->cfp);
 
     if (!cfp) return 0;
diff --git a/vm_core.h b/vm_core.h
index f7ec156..4b1b9e4 100644
--- a/vm_core.h
+++ b/vm_core.h
@@ -447,6 +447,8 @@ struct rb_iseq_constant_body { https://github.com/ruby/ruby/blob/trunk/vm_core.h#L447
     long unsigned total_calls; /* number of total calls with `mjit_exec()` */
     struct rb_mjit_unit *jit_unit;
 #endif
+
+    unsigned long iseq_unique_id; /* -- Remove In 3.0 -- */
 };
 
 /* T_IMEMO/iseq */
-- 
cgit v0.10.2


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

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