Details
-
Type:
Bug
-
Status:
Closed
-
Priority:
Blocker
-
Resolution: Fixed
-
Affects Version/s: None
-
Fix Version/s: JRuby 1.1.5
-
Component/s: Core Classes/Modules
-
Labels:None
-
Number of attachments :
Description
In response to a report from Raphael Valyi I have discovered some crucial flaws in the constant caching logic; some of them may not be reconcilable with the current design.
The first is when a value previously cached gets shadowed by new value in an intermediate module or class in the inheritance hierarchy:
BAR = 1 class Bar; end class Foo < Bar def bar; BAR; end end puts Foo.new.bar Bar.const_set(:BAR, 2) puts Foo.new.bar
This should print 1, then 2, but it prints 1 and 1.
The second case is when a previously cached value is shadowed by a new value in an intermediate module or class in the containment hierarchy.
BAR = 1
class Bar
class Foo
def bar; BAR; end
end
end
puts Bar::Foo.new.bar
Bar.const_set(:BAR, 2)
puts Bar::Foo.new.bar
The first case seems like it would be caused by bad generation-twiddling. It could probably be fixed by sorting out when generation-twiddling is not happening and making sure it is cascading properly.
The second case, however, is a more serious problem. Because we do not currently track cref containment from parent to child, there's no way for an update to a cref constant scope to inform containing scopes of the change. We would need to add a new weak list of contained crefs similar to the subclasses list currently in RubyModule.
If we can't resolve these problems 1.1.5 will have to ship without constant caching. I'm committing a change to temporarily disable constant caching, and I am adding the tests I describe above.
Patch to disable constant caching. I'm applying this to trunk while we investigate the problems with the caching logic.