Project

General

Profile

Bug #967

Results of const_missing are being cached incorrectly

Added by headius (Charles Nutter) over 11 years ago. Updated about 9 years ago.

Status:
Closed
Priority:
Normal
Target version:
ruby -v:
Backport:
[ruby-core:21059]

Description

=begin
Ruby 1.9 sped up constant lookup by adding an inline cache, cleared by a global serial number incremented when any constant is set. This works well for normal constants, but unfortunately 1.9 is also caching the result of const_missing. For example, the following output:

◆ ruby1.9 -e "def Object.const_missing(sym); Time.now; end; 5.times { p XXX; sleep 1 }"
2009-01-01 23:59:33 -0600
2009-01-01 23:59:33 -0600
2009-01-01 23:59:33 -0600
2009-01-01 23:59:33 -0600
2009-01-01 23:59:33 -0600

The result of const_missing is being cached at the lookup site for XXX. Here's what the output should look like, with incrementing seconds:

◆ ruby -e "def Object.const_missing(sym); Time.now; end; 5.times { p XXX; sleep 1 }"
Fri Jan 02 00:02:09 -0600 2009
Fri Jan 02 00:02:10 -0600 2009
Fri Jan 02 00:02:11 -0600 2009
Fri Jan 02 00:02:12 -0600 2009
Fri Jan 02 00:02:13 -0600 2009

Note that this also affects colon2 and colon3 constant lookup:

◆ ruby1.9 -e "def Object.const_missing(sym); cls = Class.new; cls.class_eval 'Foo = Time.now'; cls; end; 5.times { p XXX::Foo; sleep 1 }"
2009-01-02 00:02:44 -0600
2009-01-02 00:02:44 -0600
2009-01-02 00:02:44 -0600
2009-01-02 00:02:44 -0600
2009-01-02 00:02:44 -0600

◆ ruby1.9 -e "def Object.const_missing(sym); Time.now; end; 5.times { p ::XXX; sleep 1 }"
2009-01-02 00:03:06 -0600
2009-01-02 00:03:06 -0600
2009-01-02 00:03:06 -0600
2009-01-02 00:03:06 -0600
2009-01-02 00:03:06 -0600

The result of const_missing should never be cached, since doing so would break code that expects const_missing to keep firing (some DSLs for example).

This was run against the just-released Ruby 1.9 RC.
=end

#1

Updated by yugui (Yuki Sonoda) over 11 years ago

  • Target version set to 1.9.1 RC2

=begin

=end

#2

Updated by ko1 (Koichi Sasada) over 11 years ago

  • Status changed from Open to Closed
  • % Done changed from 0 to 100

=begin
Applied in changeset r21536.
=end

Also available in: Atom PDF