Fwd: shugo:r37616 (trunk): * vm_core.h (rb_call_info_t::refinements), compile.c (new_callinfo):

refinement $B$rF3F~$9$k$H$-$N@-G=$KBP$9$k(B excuse $B$,!V(Bmethod cache
$B$KKX$I$"(B
$B$?$k$+$i!$!J(Brefinement
$B$K4X78L5$$ItJ,$N!K@-G=Dc2<$O$J$$!W$H$$$&OC$@$C$?(B
$B$H;W$&$N$G$9$,!$:#2s$N%3!<%I$r8+$k$H!$$=$l$J$j$K%a%=%C%IC5:w%3%9%H$,A}$((B
$B$=$&$J5$$,$9$k$s$G$9$,!$$$$+$,$G$7$g$&$+!%(B

$B:rF|AjCL$5$;$FD:$$$?$H$*$j!$<BAu$H$7$F$O(B refinement $B$O(B

  • $B%a%=%C%IC5:w$+$i(B refinement $B4X78$N=hM}$r:o=|(B
  • $BC5:w$7$?%a%=%C%I$,(B refine $B$5$l$?%a%=%C%I$@$C$?$i!$(B
    $B$=$N;~E@$GE,@Z$J%a%=%C%I$r8F$S=P$9(B
    $B$N$,NI$$$H;W$$$^$9!%(B

$B$A$g$C$H!$8=>u$N%3!<%I$O<u$1F~$l$i$l$^$;$s!%(B

-------- Original Message --------
Subject: [ruby-changes:25559] shugo:r37616 (trunk): * vm_core.h
(rb_call_info_t::refinements), compile.c (new_callinfo):
Date: Sun, 11 Nov 2012 11:42:16 +0900 (JST)
From: shugo [email protected]
Reply-To: [email protected]
To: [email protected]

shugo 2012-11-11 11:42:04 +0900 (Sun, 11 Nov 2012)

New Revision: 37616

http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=37616

Log:
* vm_core.h (rb_call_info_t::refinements), compile.c (new_callinfo):
add a new field for inline method cache.

* vm_insnhelper.c (vm_search_method): check 

rb_call_info_t::refinements
not to confuse inline method cache when module_eval is used with
refinements.

* test/ruby/test_refinement.rb: related test.

Modified files:
trunk/ChangeLog
trunk/compile.c
trunk/test/ruby/test_refinement.rb
trunk/vm_core.h
trunk/vm_insnhelper.c

Index: ChangeLog

— ChangeLog (revision 37615)
+++ ChangeLog (revision 37616)
@@ -1,3 +1,14 @@
+Sun Nov 11 11:36:19 2012 Shugo M. [email protected]
+

    • vm_core.h (rb_call_info_t::refinements), compile.c (new_callinfo):
  • add a new field for inline method cache.
    • vm_insnhelper.c (vm_search_method): check
      rb_call_info_t::refinements
  • not to confuse inline method cache when module_eval is used with
  • refinements.
    • test/ruby/test_refinement.rb: related test.

Sun Nov 11 08:45:45 2012 Martin D. [email protected]

  • ruby.c: removed a comma before “before”
    Index: vm_core.h
    ===================================================================
    — vm_core.h (revision 37615)
    +++ vm_core.h (revision 37616)
    @@ -153,6 +153,7 @@
    /* inline cache: keys */
    VALUE vmstat;
    VALUE klass;
  • VALUE refinements;

    /* inline cache: values */
    const rb_method_entry_t *me;
    Index: compile.c
    ===================================================================
    — compile.c (revision 37615)
    +++ compile.c (revision 37616)
    @@ -954,6 +954,7 @@
    }
    }
    ci->vmstat = 0;

  • ci->refinements = Qundef;
    ci->blockptr = 0;
    ci->recv = Qundef;
    ci->call = 0; /* TODO: should set default function? */
    Index: vm_insnhelper.c
    ===================================================================
    — vm_insnhelper.c (revision 37615)
    +++ vm_insnhelper.c (revision 37616)
    @@ -843,19 +843,30 @@
    vm_search_method(rb_call_info_t *ci, VALUE recv)
    {
    VALUE klass = CLASS_OF(recv);

  • NODE *cref = rb_vm_cref();

  • VALUE refinements = Qnil;

  • if (cref && !NIL_P(cref->nd_refinements)) {

  • refinements = cref->nd_refinements;

  • }

#if OPT_INLINE_METHOD_CACHE

  • if (LIKELY(GET_VM_STATE_VERSION() == ci->vmstat && klass ==
    ci->klass)) {
  • if (LIKELY(GET_VM_STATE_VERSION() == ci->vmstat && klass ==
    ci->klass &&
  •     refinements == ci->refinements)) {
    
    /* cache hit! */
    }
    else {
  • ci->me = rb_method_entry(klass, ci->mid, &ci->defined_class);
  • ci->me = rb_method_entry_get_with_refinements(refinements, klass,
  •              ci->mid,
    
  •              &ci->defined_class);
    
    ci->klass = klass;
  • ci->refinements = refinements;
    ci->vmstat = GET_VM_STATE_VERSION();
    ci->call = vm_call_general;
    }
    #else
  • ci->me = rb_method_entry(klass, ci->mid, &ci->defined_class);
  • ci->me = rb_method_entry_get_with_refinements(refinements, klass,
    ci->mid,
  •          &ci->defined_class);
    
    ci->call = vm_call_general;
    ci->klass = klass;
    #endif
    Index: test/ruby/test_refinement.rb
    ===================================================================
    — test/ruby/test_refinement.rb (revision 37615)
    +++ test/ruby/test_refinement.rb (revision 37616)
    @@ -685,4 +685,28 @@
    assert_equal(“#refinement:#{c.inspect}@#{m.inspect}”,
    m.refinements[c].inspect)
    end
  • module InlineMethodCache
  • class C
  •  def foo
    
  •    "original"
    
  •  end
    
  • end
  • module M
  •  refine C do
    
  •    def foo
    
  •      "refined"
    
  •    end
    
  •  end
    
  • end
  • end
  • def test_inline_method_cache
  • c = InlineMethodCache::C.new
  • f = Proc.new { c.foo }
  • assert_equal(“original”, f.call)
  • assert_equal(“refined”, InlineMethodCache::M.module_eval(&f))
  • assert_equal(“original”, f.call)
  • end
    end

$BA0ED$G$9!#(B

2012/11/11 SASADA Koichi [email protected]:

refinement $B$rF3F~$9$k$H$-$N@-G=$KBP$9$k(B excuse $B$,!V(Bmethod cache
$B$KKX$I$"(B
$B$?$k$+$i!$!J(Brefinement $B$K4X78L5$$ItJ,$N!K@-G=Dc2<$O$J$$!W$H$$$&OC$@$C$?(B
$B$H;W$&$N$G$9$,!$:#2s$N%3!<%I$r8+$k$H!$$=$l$J$j$K%a%=%C%IC5:w%3%9%H$,A}$((B
$B$=$&$J5$$,$9$k$s$G$9$,!$$$$+$,$G$7$g$&$+!%(B

$B:rF|AjCL$5$;$FD:$$$?$H$*$j!$<BAu$H$7$F$O(B refinement $B$O(B

  • $B%a%=%C%IC5:w$+$i(B refinement $B4X78$N=hM}$r:o=|(B
  • $BC5:w$7$?%a%=%C%I$,(B refine $B$5$l$?%a%=%C%I$@$C$?$i!$(B
    $B$=$N;~E@$GE,@Z$J%a%=%C%I$r8F$S=P$9(B
    $B$N$,NI$$$H;W$$$^$9!%(B

$B>e5-$NJQ99$NA0$K!“$H$j$”$($:%F%9%H$NDI2C$H!“$=$l$,DL$k$h$&$J=$@5$r$7$F$$$^$9!#(B
$B$?$@!”>e5-$NJQ99$C$F;d$,<BAu$9$k$H$$$&OC$J$s$G$7$?$C$1(B?

$B$@$H$9$k$H!"$b$&$A$g$C$H:Y$+$$$H$3$m$r3NG’$7$?$$$G$9!#(B

$B4pK\E*$J%“%$%G%”$O!"(Brefine$BBP>]$N%/%i%9(B(refine$B$N0z?t(B)$B$N%a%=%C%I$K(Brefine$B$5$l$?$3$H(B
$B$rI=$90u$rIU$1$F$*$$$F!"DL>o$N%a%=%C%IC5:w$G$=$N%a%=%C%I$,8+$D$+$C$?;~$K$O$8$a$F(B
refinements$B@lMQ$N%Q%9$GC5:w$9$k$H$$$&$3$H$G$9$h$M!#(B

$B0J2<$N$h$&$J5?Ld$,$"$j$^$9!#(B

  • refine$B$5$l$?$3$H$rI=$9(Bmethod entry$B$N9=B$$r$I$&$9$k$+(B
    rb_method_type_t$B$K(BVM_METHOD_TYPE_REFINED$B$_$?$$$J$N$rDI2C$9$k$s$G$7$?$C$1!#(B
    $B$b$H$N(Bmethod
    entry$B$O(Brb_method_entry_t::def->body$B$H$+$+$i;2>H$9$k$s$G$9$+$M!#(B
  • refine$B$7$?;~$K(Brefine$BBP>]%/%i%9$K%a%=%C%I$,$J$$;~$O$I$&$9$k$+(B
    $B%a%=%C%I$,$J$$;~$b>o$K(Brefine$B$5$l$?$3$H$r<($9(Bmethod
    entry$B$rDI2C$9$k(B?

refine$B$5$l$?%a%=%C%I$N8F=P;~$K(Brb_call_info_t$B$K$I$&$$$&>pJs$r3JG<$9$k$+(B
Twitter$B$G$O!“(Brefine$B$5$l$?$3$H$r<($9(Bmethod
entry$B$rF~$l$F$*$/$H$$$&$3$H$G$7$?$,!”(B
$B:#$N(Bvm_call_method$B$N9=B$$@$H(Brb_call_info_t$B$NCf?H$r=q$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 2.0.0dev (2012-11-10 trunk 37604) [x86_64-linux] 11/10 $B$NHG(B
(b) ruby 2.0.0dev (2012-11-11 trunk 37624) [x86_64-linux] $B:#D+$N(B
trunk

                     (a)     (b)   # $BC10L$OIC(B

loop_whileloop 1.029 1.024
vm1_yield* 1.414 1.780
vm2_defined_method 6.252 6.788
vm2_method 2.585 3.251
vm2_method_missing 4.558 5.066
vm2_method_with_block 2.576 3.326
vm2_poly_method 4.989 4.645
vm2_poly_method_ov 0.715 0.768
vm3_clearmethodcache 1.062 1.097
app_mandelbrot 2.625 2.738
app_tak 1.958 2.016
app_tarai 1.336 1.441
so_mandelbrot 5.924 5.712

$B!!!(B $B!!(B(b)/(a) # $BBg$-$$$H(B (2) $B$,B.$$(B
loop_whileloop 1.005
vm1_yield* 0.795
vm2_defined_method 0.921
vm2_method 0.795
vm2_method_missing 0.900
vm2_method_with_block 0.774
vm2_poly_method 1.074
vm2_poly_method_ov 0.931
vm3_clearmethodcache 0.968
app_mandelbrot 0.959
app_tak 0.971
app_tarai 0.927
so_mandelbrot 1.037

$B!!C1=c$JNc!J(Bvm2_method$B!K$@$H(B 2
$B3d$[$ICY$/$J$C$F$$$k$h$&$G$9!%(Btarai $B$@$H(B
8% $B$G$9$M!%(B

$B%$%s%i%$%s%a%=%C%I%-%c%C%7%e$,8z$+$J$$Nc!J(Bvm2_poly_method$B!K$@$HB.$/(B
$B$J$C$F$$$k$N$O$J$<$J$s$@$m$&(B…$B!%(B

$B!!F0$/$N$G!VBgLdBj!W$G$O$J$$$H;W$$$^$9$,!$$3$N$^$^%j%j!<%9$9$k$K$ODq93$,(B
$B$"$j$^$9!%(B

$B$b$H$N(Bmethod
entry$B$O(Brb_method_entry_t::def->body$B$H$+$+$i;2>H$9$k$s$G$9$+$M!#(B
$B!!Nc$($P!$$=$s$J46$8$N$b$N$rA[Dj$7$F$$$^$7$?!%(B

  • refine$B$7$?;~$K(Brefine$BBP>]%/%i%9$K%a%=%C%I$,$J$$;~$O$I$&$9$k$+(B
    $B%a%=%C%I$,$J$$;~$b>o$K(Brefine$B$5$l$?$3$H$r<($9(Bmethod
    entry$B$rDI2C$9$k(B?

$B!!$=$NE@!$;d$b$"$N$"$H5$$E$$$?$N$G$9$,!$(Brefine
$B$5$l$k%a%=%C%I$ODI2C$9$k(B
$B$HNI$$$H;W$$$^$9!%(B

$B!J$=$b$=$b!$(Brefine $B$5$l$k$Y$-%a%=%C%I$,$J$$$N$K(B refine
$B$G$-$k!$$C$F;EMM(B
$B$O$I$&$J$N!$$H$$$&5$$b$7$^$7$?$,!%$^$!!$$=$&$$$&%7%A%e%(!<%7%g%s$b$"$k$N(B
$B$+$J$!!K(B

  • refine$B$5$l$?%a%=%C%I$N8F=P;~$K(Brb_call_info_t$B$K$I$&$$$&>pJs$r3JG<$9$k$+(B
    Twitter$B$G$O!"(Brefine$B$5$l$?$3$H$r<($9(Bmethod
    entry$B$rF~$l$F$*$/$H$$$&$3$H$G$7$?$,!"(B

$B:#$N(Bvm_call_method$B$N9=B$$@$H(Brb_call_info_t$B$NCf?H$r=q$-49$($F(Bgoto$B$9$k$h$&$J(B

$B7A$K$J$C$F$$$k$N$G!"$I$&$$$&JQ99$r0U?^$5$l$F$$$k$N$+$h$/$o$+$j$^$;$s$G$7$?!#(B

$B!!(Bgoto $B$OL5$$$G$9$,!$$3$NJU$OFC$KJQ99$OITMW$J5$$,$7$^$9!%(B

$B!!7kO@$,=P$?$i!$;d$,<BAu$7$^$9$+$M!%(B

(2012/11/12 14:58), SASADA Koichi wrote:

$B!!!(B $B!!(B(b)/(a) # $BBg$-$$$H(B (2) $B$,B.$$(B

(a)/(b) $B$G$9$M!%$9$_$^$;$s!%(B

$BA0ED$G$9!#(B

2012$BG/(B11$B7n(B12$BF|(B 14:58 SASADA Koichi [email protected]:

$B!!$3$N7o!$;d$,<BAu$7$F$b(B shugo $B$5$s$,$5$l$F$bNI$$$+$H;W$$$^$9!%$?$@!$OC(B
$B$N=gHV$,$*$+$7$$!$$H$$$&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%i%9$K%a%=%C%I$,DI2C$5$l$?$j$9$k$H(B
$B$^$:$=$&$J$N$G!”$d$C$Q$j(Brefine$B$7$?;~E@$G%a%=%C%I$rDI2C$7$F$*$+$J$$$H(B
$B$^$:$=$&$G$9!#(B

$B!J$=$b$=$b!$(Brefine $B$5$l$k$Y$-%a%=%C%I$,$J$$$N$K(B refine
$B$G$-$k!$$C$F;EMM(B
$B$O$I$&$J$N!$$H$$$&5$$b$7$^$7$?$,!%$^$!!$$=$&$$$&%7%A%e%(!<%7%g%s$b$"$k$N(B
$B$+$J$!!K(B

refine$B$NBP>]$O%a%=%C%I$G$O$J$/%/%i%9$J$N$G!"?75,%a%=%C%I$NDI2C$b;EMM$H(B
$B$7$?$$$H9M$($F$$$^$9!#(B
$B6qBNE*$J%f!<%9%1!<%9$H$7$F$O!“Nc$($P(BRSpec$B$N(Bshould$B$N$h$&$J$b$N$,$”$j$^$9!#(B

refine$B$5$l$?%a%=%C%I$N8F=P;~$K(Brb_call_info_t$B$K$I$&$$$&>pJs$r3JG<$9$k$+(B

Twitter$B$G$O!“(Brefine$B$5$l$?$3$H$r<($9(Bmethod
entry$B$rF~$l$F$*$/$H$$$&$3$H$G$7$?$,!”(B

$B:#$N(Bvm_call_method$B$N9=B$$@$H(Brb_call_info_t$B$NCf?H$r=q$-49$($F(Bgoto$B$9$k$h$&$J(B

$B7A$K$J$C$F$$$k$N$G!"$I$&$$$&JQ99$r0U?^$5$l$F$$$k$N$+$h$/$o$+$j$^$;$s$G$7$?!#(B

$B!!(Bgoto $B$OL5$$$G$9$,!$$3$NJU$OFC$KJQ99$OITMW$J5$$,$7$^$9!%(B

vm_call_method$B$KJ,4t$rA}$d$7$F!"(B

          case VM_METHOD_TYPE_REFINED:{
            rb_call_info_t cie = *ci;
            ci = &cie;

            ci->me = (refinements$B$+$iC5:w$7$?(Bmethod 

entry$B!"$^$?$O85$N%/%i%9$N(Bmethod entry);
if (ci->me != 0) {
goto normal_method_dispatch;
}
else {
/*
refinements$B$+$i%a%=%C%I$,8+$D$+$i$:!"85$N%/%i%9$K$b%a%=%C%IDj5A$,$J$$>l9g(B
*/
goto start_method_dispatch;
}

$B$H$9$k$h$&$J%$%a!<%8$G9g$C$F$$$^$9$+(B?

refinements$B$+$iC5:w$7$?(Bmethod
entry$B$ODL>o$N%$%s%i%$%s%-%c%C%7%e$K$O(B
$B:$i$J$$$N$G$9$h$M(B?

$B$G$-$l$PJL$N$H$3$m$K%-%c%C%7%e$rCV$$$?J}$,$$$$$+$b$7$l$J$$$G$9$1$I!#(B

$B!!7kO@$,=P$?$i!$;d$,<BAu$7$^$9$+$M!%(B

$B0U?^$r@5$7$/M}2r$G$-$F$$$k$+IT0B$G$O$“$j$^$9$,!”$5$5$@$5$s$OB>$K$b:n6H$,(B
$B$?$/$5$s$“$j$=$&$J$N$G!”$$$C$?$s;d$,$d$C$F$_$^$7$g$&$+(B?

$B$“$H!“K\Bj$H4X78$”$j$^$;$s$,!”%3!<%I$rFI$s$G$$$F0J2<$N5?Ld$,$"$j$^$7$?!#(B

  • rb_iseq_t::ic_entries$B$O$^$@;H$o$l$F$$$^$9$+(B?
  • callinfo$B$H(Bcall_info$B$GL>A0$NIU$1J}$KMI$l$,$"$k$N$O0U?^E*$G$9$+(B?

$BA0ED$G$9!#(B

2012$BG/(B11$B7n(B12$BF|(B 17:10 SASADA Koichi [email protected]:

$B!!8D?ME*$K$O!$!V%^%$%/%m%Y%s%A%^!<%/0J30$K$O8z$+$J$$$s$@$+$i$$$$$h!W$H$$(B
$B$&0U8+$b$"$j$@$m$&$H;W$&$N$G!$5!G=$+@-G=$+!$$N7hDj$O$I$J$?$+$K$*G$$;$7$?(B
$B$$$H$3$m$G$9!%(B

$B!!$I$A$i$+$H$$$&$H!$8D?ME*$J0u>]$NOC$K$J$C$F$7$^$&$N$G$9$,!$@-G=$h$j$b!$(B
$B!V%a%=%C%IC5:w$N:,44$K4X$o$kItJ,$K$h$&$o$+$i$s=hM}$GKd$^$k!W$H$$$&$N(B
$B$O!$(BRuby $B$H$$$&8@8l$r$I$s$I$sM}2r$7$,$?$$$b$N$K$9$k$N$GH?BP$7$?$$!$$H$$(B
$B$&$N$,$"$j$^$9!%M}2r$7$,$?$$8@8l$d5!G=$O8m2r$5$l$?$jIT9,$K$7$+$J$i$J$$46$8!%(B

$BN;2r$7$^$7$?!#(B
$B$^$@4V$K9g$&$N$G$b$C$HH?BP0U8+$b=P$7$F$$$?$@$1$l$P$H;W$$$^$9!#(B

$B!!$=$N>l9g$N%3%9%H$O8=>u$HJQ$o$i$J$$$G$9$h$M!%8=>u$G$b!$I,$:(B refinement
$B$r5$$K$9$k$N$G!%(B

$B$O$$!"<B9T%3%9%H$OLdBj$J$$$H;W$$$^$9!#(B
$B<BAu%3%9%H$b>o$K%a%=%C%I$rDI2C$7$?J}$,3Z$+$J!#(B

            else {
                /* 

refinements$B$+$i%a%=%C%I$,8+$D$+$i$:!"85$N%/%i%9$K$b%a%=%C%IDj5A$,$J$$>l9g(B */

                goto start_method_dispatch;
            }

$B$H$9$k$h$&$J%$%a!<%8$G9g$C$F$$$^$9$+(B?

$B!!$O$$!%$A$J$_$K!$(Brb_call_info_t $B$r0z$-2s$9@_7W$K$OLdBj$,$“$k$3$H$,$o(B
$B$+$C$F$$$k!J%a%=%C%I8F$S=P$7ESCf$G(B to_proc $B$d(B to_a
$B$rFI$s$@$H$-!$GK2u$5(B
$B$l$k2DG=@-$,$”$k!K$?$a!$:#BeBX0F$r8!F$Cf$G$9!%(B

$BN;2r$7$^$7$?!#(B

$B!!(Belse $B@a$N$[$&$O!$(Bsuper class
$B$rC5:w$7$J$$$H$$$1$J$$$N$G!$$A$g$C$H0c$&(B
$B$h$&$J5$$,$7$^$9$,!$!V$^$?$O85$N%/%i%9$N(Bmethod entry$B!W$,(B super class
$BC5(B
$B:w$r4^0U$7$F$$$k5$$b$7$^$9$M!%(B

$B$“$”!"$=$&$G$9$M!#9MN8O3$l$G$7$?!#(B

refinements$B$+$iC5:w$7$?(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Bcall_info$B$GL>A0$NIU$1J}$KMI$l$,$"$k$N$O0U?^E*$G$9$+(B?

$B!!$3$lLB$C$?$s$G$9$h$M$'!%(Brb_callinfo_t $B$KDq93$,$"$C$?$s$G$9(B
$B$,!$(Bprefix/suffix $BE*$K;H$&>l9g$K(B call_info $B$C$F$N$K$OJQ$@$H;W$$!%(B

$B$J$k$[$I!#(B

$B!!A4It(B callinfo $B$KIU$1BX$($h$&$+$J$!!%(B

$BE}0l$7$?J}$,$h$$5$$,$7$^$9$M!#(B

(2012/11/12 18:20), Shugo M. wrote:

$BLdBj$O!"(Brefine$B$5$l$?8e$G(Bprepend$B$5$l$?>l9g$G$9$,!"$3$A$i$O$A$g$C$HBP1~$,(B

$BLLE]$=$&$G$9$M$(!#(B
prepend$B$7$?;~$K!">o$K(Bprepend$BBP>]$N%/%i%9$N%a%=%C%I%F!<%V%k$rD4$Y$F!"(B
$B%b%8%e!<%k$K(Brefined$B%a%=%C%I$rDI2C$9$k$/$i$$$G$9$+$M$(!#(B

$B!!(Bprepend $B$N:Y$+$$5sF0$rCN$i$J$$$N$G$9$,!$(B

class C
prepend M1
prepend M2
end

module M
refine C

end
end

class C
prepend M3
end

$B$N$H$-!$$?$7$+(B C $B$N%a%=%C%I%F!<%V%k$r(B null
$B$K$7$F$*$$$F1>!9!$$HJ9$$$?$H(B
$B;W$&$s$G$9$,!$$3$3$G$b$&!$(Brefinement check only
$B$J%a%=%C%I%(%s%H%j$rCV$/(B
$B$h$&$K$9$k$H$I$&$G$9$+$M!%(B

$B$$$d!$$J$s$+$=$b$=$b(B refinement $B$H(B prepend

$B$r:.$<$k$C$F$N$O!$(B

$B?’!9$H4pK@_7W4V0c$C$F$k$H$$$&$+!$8eIU$146$,$R$I$$46$8$,$9$k!%(B

$B=PMh$k$1$I$d$C$A$c$$$1$J$$46$8!%(B

$B$^$D$b$H(B $B$f$-$R$m$G$9(B

In message “Re: [ruby-dev:46497] Re: Fwd: [ruby-changes:25559]
shugo:r37616 (trunk): * vm_core.h (rb_call_info_t::refinements),
compile.c (new_callinfo):”
on Mon, 12 Nov 2012 19:20:09 +0900, SASADA Koichi [email protected]
writes:

|# $B$$$d!$$J$s$+$=$b$=$b(B refinement $B$H(B prepend $B$r:.$<$k$C$F$N$O!$(B
|# $B?'!9$H4pK@_7W4V0c$C$F$k$H$$$&$+!$8eIU$146$,$R$I$$46$8$,$9$k!%(B
|# $B=PMh$k$1$I$d$C$A$c$$$1$J$$46$8!%(B

$B!V=PMh$k$1$I$d$C$A$c$$$1$J$$!W$C$F$N$O8@8l@_7WE*$K$O$“$j$($J(B
$B$$8@$$Lu$J$N$G!”!V$G$-$k!W$+!V$G$-$J$$$+!W$I$A$i$+$G$"$k$Y$-(B
$B$G$7$g$&$M!#(B

$B$?$@!“3N$+$K(Brefinement$B$GDI2C$5$l$?%a%=%C%I$H(Bprepend$B$5$l$?$j!”(B
$B%5%V%/%i%9$G%*!<%P!<%i%$%I$5$l$?$j$7$?%a%=%C%I$HN>J}$,$“$k$H!”(B
$B$o$+$j$K$/$$$N$O3N$+$J$N$G!"$=$3$K$D$$$F$h$j9M;!$7$?$[$&$,NI(B
$B$$$@$m$&$H$$$&<(:6$OM}2r$G$-$^$9!#(B

$BFC$K7Q>5$5$l$?$j(Binclude$B$5$l$?$j$7$F$b(Brefinement$B$,M-8z$G$“$k(B
$B$HL@8@$7$F$7$^$C$?$N$G!”(Brefinement$B$,$h$j%*!<%P!<%i%$%I$K$h$k(B
$B1F6A$r<u$1$d$9$/$J$C$?$H8@$($^$9!#(B

$B$&!<$`!“$$$C$=(Brefinement$B$GDI2C$5$l$?%a%=%C%I$O>o$K:GM%@h$K$9(B
$B$Y$-$J$N$+$J$”!#%5%V%/%i%9$G%*!<%P!<%i%$%I$5$l$F$$$?$H$7$F$b(B
refinement$B$5$l$?%a%=%C%IM%@h!#$I$&$d$C$F<BAu$9$k$N$+$K$o$+$K(B
$B$O$o$+$i$J$$$1$I!#(B

                            $B$^$D$b$H(B $B$f$-$R$m(B /:|)

$BA0ED$G$9!#(B

2012$BG/(B11$B7n(B12$BF|(B 19:20 SASADA Koichi [email protected]:

$B$N$H$-!$$?$7$+(B C $B$N%a%=%C%I%F!<%V%k$r(B null
$B$K$7$F$*$$$F1>!9!$$HJ9$$$?$H(B
$B;W$&$s$G$9$,!$$3$3$G$b$&!$(Brefinement check only $B$J%a%=%C%I%(%s%H%j$rCV$/(B
$B$h$&$K$9$k$H$I$&$G$9$+$M!%(B

$B$“$”!“$=$3$K%a%=%C%I%(%s%H%j$rCV$$$F$$$$$J$i!”$=$NJ}$,$$$$$+$b$7$l$J$$$G$9$M!#(B
$B$I$&$G$7$g$&$+(B? > $B$J$+$@$5$s(B
$B$?$@!"(B

class C
end

module R
refine C do
def foo; end
end
end

class C
prepend M
end

$B$_$?$$$J%1!<%9$@$H!“(BC$B$K(Brefined$B%a%=%C%I$,$9$G$KDI2C$5$l$?8e$G(Bprepend
$B$5$l$F!”(BC$B$N$9$Y$F$N%a%=%C%I$,(Biclass(C’)$B$K0\F0$5$l$k$N$G!"$=$N;~$K$O(B
$B$d$O$j(BC$B$K(Brefined$B%a%=%C%I%(%s%H%j$@$1(B($B%a%=%C%IK\BN$O(BC’$B$@$1$,;}$D(B)$B$r(B
$BDI2C$7$F$*$+$J$$$H$$$1$J$5$=$&$G$9$M!#(B

$B$$$d!$$J$s$+$=$b$=$b(B refinement $B$H(B prepend $B$r:.$<$k$C$F$N$O!$(B

$B?'!9$H4pK@_7W4V0c$C$F$k$H$$$&$+!$8eIU$146$,$R$I$$46$8$,$9$k!%(B

$B=PMh$k$1$I$d$C$A$c$$$1$J$$46$8!%(B

Rails$B$N%U%l!<%`%o!<%/B&$N%3!<%I$G:#8e(Bmonkey
patching$B$,(Bprepend$B$K(B
$BCV$-49$($i$l$kM=Dj$J$N$G!“%f!<%6$,$5$i$K(Brefine$B$G3HD%$9$k$h$&$J%1!<%9(B
$B$O$R$g$C$H$7$?$i=P$F$/$k$+$b$7$l$^$;$s!#(B
$B$5$9$,$K(Brefine$B$7$?8e$G(Bprepend$B$9$k$h$&$J%1!<%9$O$”$^$j$J$$$H;W$&$N(B
$B$G$9$,!#(B

(2012/11/12 22:21), Shugo M. wrote:

Rails$B$N%U%l!<%`%o!<%/B&$N%3!<%I$G:#8e(Bmonkey patching$B$,(Bprepend$B$K(B
$BCV$-49$($i$l$kM=Dj$J$N$G!"%f!<%6$,$5$i$K(Brefine$B$G3HD%$9$k$h$&$J%1!<%9(B
$B$O$R$g$C$H$7$?$i=P$F$/$k$+$b$7$l$^$;$s!#(B
$B$5$9$,$K(Brefine$B$7$?8e$G(Bprepend$B$9$k$h$&$J%1!<%9$O$"$^$j$J$$$H;W$&$N(B
$B$G$9$,!#(B

$B$"$j!$(Bmonkey patching $B$O(B refinement
$B$GCV$-49$($i$l$k$b$N$J$s$G$O$J$$$N$G(B
$B$9$+!)(B

$BA0ED$G$9!#(B

2012$BG/(B11$B7n(B12$BF|(B 22:45 SASADA Koichi [email protected]:

(2012/11/12 22:21), Shugo M. wrote:

Rails$B$N%U%l!<%`%o!<%/B&$N%3!<%I$G:#8e(Bmonkey patching$B$,(Bprepend$B$K(B
$BCV$-49$($i$l$kM=Dj$J$N$G!“%f!<%6$,$5$i$K(Brefine$B$G3HD%$9$k$h$&$J%1!<%9(B
$B$O$R$g$C$H$7$?$i=P$F$/$k$+$b$7$l$^$;$s!#(B
$B$5$9$,$K(Brefine$B$7$?8e$G(Bprepend$B$9$k$h$&$J%1!<%9$O$”$^$j$J$$$H;W$&$N(B
$B$G$9$,!#(B

$B$"$j!$(Bmonkey patching $B$O(B refinement
$B$GCV$-49$($i$l$k$b$N$J$s$G$O$J$$$N$G(B
$B$9$+!)(B

monkey
patching$B$H$$$&$+!“(Balias_method_chain$B$r;H$C$F$$$k$h$&$J%3!<%I$G!”(B
$B%0%m!<%P%k$K3HD%$7$FLdBj$J$$$h$&$J%1!<%9(B(Rails$B$GDj5A$7$F$$$k%/%i%9$N3HD%$H$+(B)
$B$G$O(Bprepend$B$GCV$-49$($i$l$k$s$8$c$J$$$+$H;W$$$^$9!#(B
$BAH$9~$%/%i%9$N3HD%$O(Brefinements$B$GCV$-49$($i$l$k$+$b$7$l$^$;$s$,!#(B

$B$J$+$@$G$9!#(B

At Mon, 12 Nov 2012 22:21:46 +0900,
Shugo M. wrote in [ruby-dev:46501]:

2012$BG/(B11$B7n(B12$BF|(B 19:20 SASADA Koichi [email protected]:

$B$N$H$-!$$?$7$+(B C $B$N%a%=%C%I%F!<%V%k$r(B null
$B$K$7$F$*$$$F1>!9!$$HJ9$$$?$H(B
$B;W$&$s$G$9$,!$$3$3$G$b$&!$(Brefinement check only
$B$J%a%=%C%I%(%s%H%j$rCV$/(B
$B$h$&$K$9$k$H$I$&$G$9$+$M!%(B

$B$“$”!“$=$3$K%a%=%C%I%(%s%H%j$rCV$$$F$$$$$J$i!”$=$NJ}$,$$$$$+$b$7$l$J$$$G$9$M!#(B

$B$I$&$G$7$g$&$+(B? > $B$J$+$@$5$s(B

$BDL>o$N%a%=%C%I%F!<%V%k$H(Brefine$BMQ%a%=%C%I%F!<%V%k$,0l$D$N(BRClass$BCf(B
$B$KF15o$9$k$s$G$9$+(B?
$BJ#?t(Busing$B$7$?$H$-$N(Bsuper$B$J$I$,$&$^$/$$$/$+5?(B
$BLd$J$N$G$9$,!#(B

$B;d$O!“(Brefined
method$B$@$1$N(Biclass$B$r(Bprepend$B$9$k!”$H$$$&J}N,$+$H;W$C(B
$B$F$$$^$7$?!#(B

$BA0ED$G$9!#(B

2012$BG/(B11$B7n(B14$BF|(B 17:28 Nobuyoshi N. [email protected]:

$B$N$H$-!$$?$7$+(B C $B$N%a%=%C%I%F!<%V%k$r(B null
$B$K$7$F$*$$$F1>!9!$$HJ9$$$?$H(B
$B;W$&$s$G$9$,!$$3$3$G$b$&!$(Brefinement check only
$B$J%a%=%C%I%(%s%H%j$rCV$/(B
$B$h$&$K$9$k$H$I$&$G$9$+$M!%(B

$B$“$”!“$=$3$K%a%=%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

$B$N$h$&$JI=5-$O$I$&$+!$$H$$$&OC$r$7$^$7$?$,!$$3$l$O(B method
$B$r=$>~$9$k!$$H(B
$B$$$&H/A[$+$i$G$7$?!%(B

            rb_call_info_t cie = *ci;

$B$H$9$k$h$&$J%$%a!<%8$G9g$C$F$$$^$9$+(B?

$B!!$O$$!%$A$J$_$K!$(Brb_call_info_t
$B$r0z$-2s$9@_7W$K$OLdBj$,$"$k$3$H$,$o(B
$B$+$C$F$$$k!J%a%=%C%I8F$S=P$7ESCf$G(B to_proc $B$d(B to_a
$B$rFI$s$@$H$-!$GK2u$5(B
$B$l$k2DG=@-$,$"$k!K$?$a!$:#BeBX0F$r8!F$Cf$G$9!%(B

$B!!(Belse $B@a$N$[$&$O!$(Bsuper class
$B$rC5:w$7$J$$$H$$$1$J$$$N$G!$$A$g$C$H0c$&(B
$B$h$&$J5$$,$7$^$9$,!$!V$^$?$O85$N%/%i%9$N(Bmethod entry$B!W$,(B super
class $BC5(B
$B:w$r4^0U$7$F$$$k5$$b$7$^$9$M!%(B

refinements$B$+$iC5:w$7$?(Bmethod entry$B$ODL>o$N%$%s%i%$%s%-%c%C%7%e$K$O(B
$B:$i$J$$$N$G$9$h$M(B?

$B$G$-$l$PJL$N$H$3$m$K%-%c%C%7%e$rCV$$$?J}$,$$$$$+$b$7$l$J$$$G$9$1$I!#(B

$B!!(Byes$B!%%$%s%i%$%s%-%c%C%7%e$K$O>h$j$^$;$s!%$J$N$G!$?’!9%7%s%W%k$K$J$k$H(B
$B;W$$$^$9!%(B

$B!!@-G=$GLdBj$K$J$k$h$&$J$i!$(Brefinement $BMQ$N(B global cache
$B$rMQ0U$9$l$PNI(B
$B$$$+$H;W$$$^$9!%(B

$B!!7kO@$,=P$?$i!$;d$,<BAu$7$^$9$+$M!%(B

$B0U?^$r@5$7$/M}2r$G$-$F$$$k$+IT0B$G$O$"$j$^$9$,!"$5$5$@$5$s$OB>$K$b:n6H$,(B
$B$?$/$5$s$"$j$=$&$J$N$G!"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$^$9!#(B

class X
end
module M
refine(X) {}
end
using M
module M
refine(X) {def foo;:foo;end}
end
p X.new.foo

refine$BCf$G$OBP>]$N%/%i%9$O$o$+$C$F$$$k$o$1$@$+$i!"%a%=%C%IDj5A$N(B
$B$H$-$K$9$G$K=q$-49$($i$l$?%a%=%C%I%(%s%H%j$r=q$-D>$7$F$^$o$l$P$$(B
$B$$$N$+$J!#(B

(2012/11/16 17:22), Shugo M. wrote:

$B=q$-49$($i$l$J$$$N$G$O$J$$$+$H$$$&5$$,$7$^$9!#(B
p X.new.foo

refine$BCf$G$OBP>]$N%/%i%9$O$o$+$C$F$$$k$o$1$@$+$i!"%a%=%C%IDj5A$N(B
$B$H$-$K$9$G$K=q$-49$($i$l$?%a%=%C%I%(%s%H%j$r=q$-D>$7$F$^$o$l$P$$(B
$B$$$N$+$J!#(B

refine$B$N%V%m%C%/Fb$G%a%=%C%IDj5A$9$k$?$S$K%a%=%C%I%(%s%H%j$rDI2CKt$OJQ99$9$k$b$N$H;W$C$F(B

$B$$$^$7$?$,!"(Bprepend$B%Y!<%9$N0F$@$H$=$&$7$J$/$F$h$$$s$G$9(B?

prepend$B%Y!<%9$@$HDI2C$@$1$G$h$/$J$k$H;W$$$^$9$,!#(B

$B!!>/$J$/$H$b:#2s$NNc$O!$(B2$B2sL$N(B refine $B$^$G(B X::foo
$B$ODI2C$5$l$J$$$H;W$&(B
$B$N$G2?$bLdBjL5$$$H;W$&$s$G$9$,!$4*0c$$$G$7$g$&$+!%(B

$B$I$A$i$+$H$$$&$H!"(Brb_method_definition_t::body$B$K85$N%a%=%C%I%(%s%H%j$rJ]B8$9$kJ}K!$@$H(B

$B%a%b%j4IM}$NLL$GLLE](B($B%a%=%C%I%(%s%H%j$O%a%b%j4IM}$,FC<l$J$N$G(B)$B$J5$$,$7$F$-$?$N$G!"(B

$B$=$&$$$&0UL#$G(Bprepend$B%Y!<%9$NJ}$,$9$C$-$j$9$k$+$b$7$l$J$$$G$9$M!#(B

$B!!$(!<$H!$FC<l$+$J$!!%$?$s$K!$(Brefine type $B$J(B definition
$B$,>C$($?$H$-$K!$(B
$B0l=o$K(B original_definition $B$r>C$;$P$$$$$@$1$N$h$&$J!%(B

$B!!$$$d!$$d$C$F$_$J$$$H$o$+$i$J$$$+$b$7$l$J$$$G$9$,!$2?$+J#;(2x4q$J%j%U%!(B
$B%l%s%9$r;}$A2s$k$h$&$J>l9g$O$o$+$i$s$G$9$,!$$=$&$J$kNc$,;W$$$D$-$^$;$s$G(B
$B$7$?!%(B

$B!!$=$&$$$($P(B alias $B$C$F$I$&$J$s$@$m$&!%(B

$BA0ED$G$9!#(B

2012$BG/(B11$B7n(B16$BF|(B 17:52 SASADA Koichi [email protected]:

refine$B$N%V%m%C%/Fb$G%a%=%C%IDj5A$9$k$?$S$K%a%=%C%I%(%s%H%j$rDI2CKt$OJQ99$9$k$b$N$H;W$C$F(B

$B$$$^$7$?$,!"(Bprepend$B%Y!<%9$N0F$@$H$=$&$7$J$/$F$h$$$s$G$9(B?

prepend$B%Y!<%9$@$HDI2C$@$1$G$h$/$J$k$H;W$$$^$9$,!#(B

$B!!>/$J$/$H$b:#2s$NNc$O!$(B2$B2sL$N(B refine $B$^$G(B X::foo
$B$ODI2C$5$l$J$$$H;W$&(B
$B$N$G2?$bLdBjL5$$$H;W$&$s$G$9$,!$4*0c$$$G$7$g$&$+!%(B

prepend$B%Y!<%9$K$7$J$/$F$bLdBj$J$$$H$$$&$3$H$G$9$h$M!#(B
$B;d$b$=$&;W$&$N$G$9$,!“$J$+$@$5$s$O0c$&<BAu$N%$%a!<%8$J$N$+$J$”$H;W$C$F",$N$h$&$K=q$-$^$7$?!#(B

$B$I$A$i$+$H$$$&$H!"(Brb_method_definition_t::body$B$K85$N%a%=%C%I%(%s%H%j$rJ]B8$9$kJ}K!$@$H(B

$B%a%b%j4IM}$NLL$GLLE](B($B%a%=%C%I%(%s%H%j$O%a%b%j4IM}$,FC<l$J$N$G(B)$B$J5$$,$7$F$-$?$N$G!"(B

$B$=$&$$$&0UL#$G(Bprepend$B%Y!<%9$NJ}$,$9$C$-$j$9$k$+$b$7$l$J$$$G$9$M!#(B

$B!!$(!<$H!$FC<l$+$J$!!%$?$s$K!$(Brefine type $B$J(B definition
$B$,>C$($?$H$-$K!$(B
$B0l=o$K(B original_definition $B$r>C$;$P$$$$$@$1$N$h$&$J!%(B

rb_method_entry_t$B$8$c$J$/$F(Brb_method_definition_t$B$N>pJs$@$1J]B8$7$F!"(Bflag$B$H$+$O(B
refined$B$J%a%=%C%I%(%s%H%j(B(rb_method_entry_t)$B$NJ}$K;}$?$;$k$H$$$&$3$H$G$9$+(B?
$B%%j%8%J%k$N(Brb_method_entry_t$B$rJ]B8$7$F$$/$H$$$&OC$@$H;W$C$F$$$?$N$GLLE]$=$&$@$J(B
$B$H;W$C$F$$$^$7$?!#(B

original_definition$B$r>C$9$H$$$&$N$O(Balias_count$B$,(B0$B$K$J$C$?$i!"$H$$$&$3$H$G9g$C$F$^$9(B?
$B8F$S=P$7;~$K$O?7$7$$(Brb_method_entry_t$B$rMQ0U$7$F(Brefined$B$J%a%=%C%I%(%s%H%j$N>pJs$r(B
$B%3%T!<$9$k46$8$G$9$+$M!#(B

$B!!$$$d!$$d$C$F$_$J$$$H$o$+$i$J$$$+$b$7$l$J$$$G$9$,!$2?$+J#;(2x4q$J%j%U%!(B
$B%l%s%9$r;}$A2s$k$h$&$J>l9g$O$o$+$i$s$G$9$,!$$=$&$J$kNc$,;W$$$D$-$^$;$s$G(B
$B$7$?!%(B

$B!!$=$&$$$($P(B alias $B$C$F$I$&$J$s$@$m$&!%(B

refined$B$J%a%=%C%I$N(Balias$B$r:n$k;~$O!“(Brefined$B$8$c$J$$J}$N(Brb_method_definiton_t$B$r0z$C$Q$C$F(B
$BMh$F(Balias$B$N%(%s%H%j$r:n$k$N$+$J$H;W$C$F$$$^$7$?$,!”$=$&$$$&OC$G$O$J$/(B?

$BA0ED$G$9!#(B

2012$BG/(B11$B7n(B16$BF|(B 18:07 Shugo M. [email protected]:

$B$H;W$C$F$$$^$7$?!#(B

original_definition$B$r>C$9$H$$$&$N$O(Balias_count$B$,(B0$B$K$J$C$?$i!"$H$$$&$3$H$G9g$C$F$^$9(B?

$B8F$S=P$7;~$K$O?7$7$$(Brb_method_entry_t$B$rMQ0U$7$F(Brefined$B$J%a%=%C%I%(%s%H%j$N>pJs$r(B

$B%3%T!<$9$k46$8$G$9$+$M!#(B

$B$H$j$“$($:!”>e5-$NJ}?K$G<BAu$7$F$_$^$7$?!#(B

http://shugo.net/tmp/refinement_fix_1119.diff

$B?'!9$Hf+$,$"$C$F;W$C$?$h$jBgJQ$G$7$?!D!#(B

$BA0ED$G$9!#(B

2012$BG/(B11$B7n(B19$BF|(B 0:53 Shugo M. [email protected]:

$B$H$j$“$($:!”>e5-$NJ}?K$G<BAu$7$F$_$^$7$?!#(B

http://shugo.net/tmp/refinement_fix_1119.diff

$B%Y%s%A%^!<%/$r<h$C$F$_$^$7$?!#(B
$B:8$,=$@5A0!“1&$,=$@58e$G$9!#(B
VirtualBox$B>e$G<h$C$?$N$G$I$J$?$+DI;n$7$F$$$?$@$1$k$H$”$j$,$?$$$G$9!#(B

benchmark results:
Execution time (sec)
name ruby 2.0.0dev (2012-11-17 trunk 37698) [i686-linux] ruby 2.0.0dev
(2012-11-17 trunk 37698) [i686-linux]
app_mandelbrot 4.913 5.017
app_tak 2.839 2.908
app_tarai 2.317 2.346
loop_whileloop 1.540 1.572
loop_whileloop2 0.337 0.332
so_mandelbrot 14.508 14.347
vm1_yield* 1.682 1.389
vm2_defined_method* 5.978 6.099
vm2_method* 3.191 3.090
vm2_method_missing* 5.432 4.683
vm2_method_with_block* 3.105 3.095
vm2_poly_method* 5.922 5.224
vm2_poly_method_ov* 0.520 0.508
vm3_clearmethodcache 0.864 0.762

Speedup ratio comare with the result of `[“ruby-r37698-optimized”,
“ruby 2.0.0dev (2012-11-17 trunk 37698) [i686-linux]”]’ (greater is
better)
name ruby 2.0.0dev (2012-11-17 trunk 37698) [i686-linux]
app_mandelbrot 0.979
app_tak 0.976
app_tarai 0.988
loop_whileloop 0.980
loop_whileloop2 1.014
so_mandelbrot 1.011
vm1_yield* 1.211
vm2_defined_method* 0.980
vm2_method* 1.033
vm2_method_missing* 1.160
vm2_method_with_block* 1.003
vm2_poly_method* 1.134
vm2_poly_method_ov* 1.025
vm3_clearmethodcache 1.133