From aea14e68fb32af5323a52676f760938794080ba0 Mon Sep 17 00:00:00 2001 From: nobu Date: Sat, 10 Feb 2018 16:54:47 +0000 Subject: 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. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62350 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- insns.def | 7 +++++-- test/ruby/test_module.rb | 11 +++++++++++ vm_insnhelper.c | 11 ++++------- 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/insns.def b/insns.def index fb5e83cc75..2c1f7d3198 100644 --- a/insns.def +++ b/insns.def @@ -951,10 +951,13 @@ getinlinecache () (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 */ diff --git a/test/ruby/test_module.rb b/test/ruby/test_module.rb index 9980844eb4..1b04b954af 100644 --- a/test/ruby/test_module.rb +++ b/test/ruby/test_module.rb @@ -1429,6 +1429,17 @@ class TestModule < Test::Unit::TestCase 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) diff --git a/vm_insnhelper.c b/vm_insnhelper.c index c14f05e3aa..a0f63dfbc4 100644 --- a/vm_insnhelper.c +++ b/vm_insnhelper.c @@ -3265,16 +3265,13 @@ vm_opt_newarray_min(rb_num_t num, const VALUE *ptr) #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 -- cgit v1.2.3