ruby-changes:50232
From: nobu <ko1@a...>
Date: Sun, 11 Feb 2018 01:54:53 +0900 (JST)
Subject: [ruby-changes:50232] nobu:r62350 (trunk): insns.def: cache nil const
nobu 2018-02-11 01:54:47 +0900 (Sun, 11 Feb 2018) New Revision: 62350 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=62350 Log: insns.def: cache nil const * insns.def (getinlinecache): Qnil is a valid value as a constant. this can be observable when accessing a deprecated constant which is nil. non-nil constant is warned just once for each location, but every time if it is nil. Modified files: trunk/insns.def trunk/test/ruby/test_module.rb trunk/vm_insnhelper.c Index: insns.def =================================================================== --- insns.def (revision 62349) +++ insns.def (revision 62350) @@ -951,10 +951,13 @@ getinlinecache https://github.com/ruby/ruby/blob/trunk/insns.def#L951 () (VALUE val) { - val = vm_ic_hit_p(ic, GET_EP()); - if (val != Qnil) { + if (vm_ic_hit_p(ic, GET_EP())) { + val = ic->ic_value.value; JUMP(dst); } + else { + val = Qnil; + } } /* set inline cache */ Index: vm_insnhelper.c =================================================================== --- vm_insnhelper.c (revision 62349) +++ vm_insnhelper.c (revision 62350) @@ -3265,16 +3265,13 @@ vm_opt_newarray_min(rb_num_t num, const https://github.com/ruby/ruby/blob/trunk/vm_insnhelper.c#L3265 #undef id_cmp -static VALUE +static int vm_ic_hit_p(IC ic, const VALUE *reg_ep) { - if (ic->ic_serial == GET_GLOBAL_CONSTANT_STATE() && - (ic->ic_cref == NULL || ic->ic_cref == rb_vm_get_cref(reg_ep))) { - return ic->ic_value.value; - } - else { - return Qnil; + if (ic->ic_serial == GET_GLOBAL_CONSTANT_STATE()) { + return (ic->ic_cref == NULL || ic->ic_cref == rb_vm_get_cref(reg_ep)); } + return FALSE; } static void Index: test/ruby/test_module.rb =================================================================== --- test/ruby/test_module.rb (revision 62349) +++ test/ruby/test_module.rb (revision 62350) @@ -1429,6 +1429,17 @@ class TestModule < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_module.rb#L1429 assert_warn(/deprecated/, bug12382) {c.class_eval "FOO"} end + NIL = nil + FALSE = false + deprecate_constant(:NIL, :FALSE) + + def test_deprecate_nil_constant + w = EnvUtil.verbose_warning {2.times {FALSE}} + assert_equal(1, w.scan("::FALSE").size, w) + w = EnvUtil.verbose_warning {2.times {NIL}} + assert_equal(1, w.scan("::NIL").size, w) + end + def test_constants_with_private_constant assert_not_include(::TestModule.constants, :PrivateClass) assert_not_include(::TestModule.constants(true), :PrivateClass) -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/