ruby-changes:25559
From: shugo <ko1@a...>
Date: Sun, 11 Nov 2012 11:42:16 +0900 (JST)
Subject: [ruby-changes:25559] shugo:r37616 (trunk): * vm_core.h (rb_call_info_t::refinements), compile.c (new_callinfo):
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 Maeda <shugo@r...> + + * 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 Duerst <duerst@i...> * 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 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/