You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
However this is a problem for AST sharing (sharing the same AST for multiple execution contexts, which have different Ruby classes, etc), because RubyRange objects are currently not context-independent, they point to a given RubyClass (private RubyClass metaClass; in RubyDynamicObject).
So to solve this we would need RubyIntRange/RubyLongRange to no longer inherit from RubyRange (we'd also just remove RubyRange), and instead inherit from ImmutableRubyObject.
Then in the translator when building a literal Range with int or long literals for both begin & end (non-beginless & non-endless) we could create a RubyIntRange/RubyLongRange directly in the translator (in org.truffleruby.parser.BodyTranslator#visitDotNode) and use an ObjectLiteralNode to embed the range instance in the AST.
For the cases we need to create a non-frozen range with int/long begin/end we'd go to RubyObjectRange then (e.g., for Range#dup).
I just remembered, there is a follow-up optimization related to this, range literals can be embedded in the AST:
However this is a problem for AST sharing (sharing the same AST for multiple execution contexts, which have different Ruby classes, etc), because RubyRange objects are currently not context-independent, they point to a given RubyClass (
private RubyClass metaClass;
inRubyDynamicObject
).So to solve this we would need RubyIntRange/RubyLongRange to no longer inherit from RubyRange (we'd also just remove RubyRange), and instead inherit from
ImmutableRubyObject
.Then in the translator when building a literal Range with int or long literals for both begin & end (non-beginless & non-endless) we could create a RubyIntRange/RubyLongRange directly in the translator (in
org.truffleruby.parser.BodyTranslator#visitDotNode
) and use an ObjectLiteralNode to embed the range instance in the AST.For the cases we need to create a non-frozen range with int/long begin/end we'd go to RubyObjectRange then (e.g., for
Range#dup
).Originally posted by @eregon in #2570 (comment)
cc @MattAlp
The text was updated successfully, but these errors were encountered: