@@ -577,7 +577,7 @@ public RubyRootNode getRootNode() {
577
577
"equalNode.execute(rope(source), cachedSource)" ,
578
578
"equalNode.execute(rope(file), cachedFile)" ,
579
579
"line == cachedLine" ,
580
- "assignsNoNewVariables( cachedRootNode)" ,
580
+ "!assignsNewUserVariables(getDescriptor( cachedRootNode) )" ,
581
581
"bindingDescriptor == getBindingDescriptor(binding)"
582
582
}, limit = "getCacheLimit()" )
583
583
public Object evalBindingNoAddsVarsCached (
@@ -602,8 +602,8 @@ public Object evalBindingNoAddsVarsCached(
602
602
"equalNode.execute(rope(source), cachedSource)" ,
603
603
"equalNode.execute(rope(file), cachedFile)" ,
604
604
"line == cachedLine" ,
605
- "!assignsNoNewVariables( cachedRootNode)" ,
606
- "assignsNoNewVariables( rootNodeToEval)" ,
605
+ "assignsNewUserVariables(getDescriptor( cachedRootNode) )" ,
606
+ "!assignsNewUserVariables(getDescriptor( rootNodeToEval) )" ,
607
607
"bindingDescriptor == getBindingDescriptor(binding)"
608
608
}, limit = "getCacheLimit()" )
609
609
public Object evalBindingAddsVarsCached (
@@ -617,13 +617,12 @@ public Object evalBindingAddsVarsCached(
617
617
@ Cached ("line" ) int cachedLine ,
618
618
@ Cached ("getBindingDescriptor(binding)" ) FrameDescriptor bindingDescriptor ,
619
619
@ Cached ("compileSource(cachedSource, getBindingFrame(binding), cachedFile, cachedLine)" ) RootNodeWrapper cachedRootNode ,
620
- @ Cached ("newBindingDescriptor(getContext(), cachedRootNode)" ) FrameDescriptor newBindingDescriptor ,
620
+ @ Cached ("getDescriptor( cachedRootNode).copy( )" ) FrameDescriptor newBindingDescriptor ,
621
621
@ Cached ("compileSource(cachedSource, getBindingFrame(binding), newBindingDescriptor, cachedFile, cachedLine)" ) RootNodeWrapper rootNodeToEval ,
622
622
@ Cached ("createCallTarget(rootNodeToEval)" ) RootCallTarget cachedCallTarget ,
623
623
@ Cached ("create(cachedCallTarget)" ) DirectCallNode callNode ,
624
624
@ Cached ("create()" ) RopeNodes .EqualNode equalNode ) {
625
- final MaterializedFrame parentFrame = BindingNodes .newFrame (binding ,
626
- newBindingDescriptor );
625
+ final MaterializedFrame parentFrame = BindingNodes .newFrame (binding , newBindingDescriptor );
627
626
return eval (self , rootNodeToEval , cachedCallTarget , callNode , parentFrame );
628
627
}
629
628
@@ -658,7 +657,7 @@ private CodeLoader.DeferredCall doEvalX(Object self, Rope source,
658
657
final DeclarationContext declarationContext = RubyArguments .getDeclarationContext (frame );
659
658
final FrameDescriptor descriptor = frame .getFrameDescriptor ();
660
659
RubyRootNode rootNode = buildRootNode (source , frame , file , line , false );
661
- if (! frameHasOnlySelf (descriptor )) {
660
+ if (assignsNewUserVariables (descriptor )) {
662
661
Layouts .BINDING .setFrame (binding , frame );
663
662
}
664
663
return getContext ().getCodeLoader ().prepareExecute (
@@ -687,32 +686,26 @@ protected FrameDescriptor getBindingDescriptor(DynamicObject binding) {
687
686
return BindingNodes .getFrameDescriptor (binding );
688
687
}
689
688
690
- protected FrameDescriptor newBindingDescriptor (RubyContext context , RootNodeWrapper rootNode ) {
691
- FrameDescriptor descriptor = rootNode .getRootNode ().getFrameDescriptor ();
692
- FrameDescriptor newDescriptor = new FrameDescriptor (context .getCoreLibrary ().getNil ());
693
- for (FrameSlot frameSlot : descriptor .getSlots ()) {
694
- newDescriptor .findOrAddFrameSlot (frameSlot .getIdentifier ());
695
- }
696
- return newDescriptor ;
689
+ protected FrameDescriptor getDescriptor (RootNodeWrapper rootNode ) {
690
+ return rootNode .getRootNode ().getFrameDescriptor ();
697
691
}
698
692
699
693
protected MaterializedFrame getBindingFrame (DynamicObject binding ) {
700
694
return BindingNodes .getFrame (binding );
701
695
}
702
696
703
- protected int getCacheLimit ( ) {
704
- return getContext (). getOptions (). EVAL_CACHE ;
705
- }
706
-
707
- protected boolean assignsNoNewVariables ( RootNodeWrapper rootNode ) {
708
- FrameDescriptor descriptor = rootNode . getRootNode (). getFrameDescriptor ();
709
- return frameHasOnlySelf ( descriptor ) ;
697
+ protected static boolean assignsNewUserVariables ( FrameDescriptor descriptor ) {
698
+ for ( FrameSlot slot : descriptor . getSlots ()) {
699
+ if (! BindingNodes . hiddenVariable ( slot . getIdentifier ())) {
700
+ return true ;
701
+ }
702
+ }
703
+ return false ;
710
704
}
711
705
712
- private boolean frameHasOnlySelf ( FrameDescriptor descriptor ) {
713
- return descriptor . getSize () == 1 && SelfNode . SELF_IDENTIFIER . equals ( descriptor . getSlots (). get ( 0 ). getIdentifier ()) ;
706
+ protected int getCacheLimit ( ) {
707
+ return getContext (). getOptions (). EVAL_CACHE ;
714
708
}
715
-
716
709
}
717
710
718
711
@ CoreMethod (names = "freeze" )
0 commit comments