Skip to content

Commit ab15c46

Browse files
eregonandrykonchin
authored andcommitted
Extract ClassExecBlockNode so it can be uncached
1 parent 848674c commit ab15c46

File tree

1 file changed

+17
-24
lines changed

1 file changed

+17
-24
lines changed

src/main/java/org/truffleruby/core/module/ModuleNodes.java

Lines changed: 17 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@
5959
import org.truffleruby.core.method.MethodFilter;
6060
import org.truffleruby.core.method.RubyMethod;
6161
import org.truffleruby.core.method.RubyUnboundMethod;
62-
import org.truffleruby.core.module.ModuleNodesFactory.ClassExecNodeFactory;
6362
import org.truffleruby.core.module.ModuleNodesFactory.ConstSetNodeFactory;
6463
import org.truffleruby.core.module.ModuleNodesFactory.ConstSetUncheckedNodeGen;
6564
import org.truffleruby.core.module.ModuleNodesFactory.GeneratedReaderNodeFactory;
@@ -668,7 +667,7 @@ public abstract static class ClassEvalNode extends AlwaysInlinedMethodNode {
668667
@Specialization(guards = "isBlockProvided(rubyArgs)")
669668
protected Object evalWithBlock(Frame callerFrame, RubyModule self, Object[] rubyArgs, RootCallTarget target,
670669
@Cached BranchProfile errorProfile,
671-
@Cached(allowUncached = true) ClassExecNode classExecNode) {
670+
@Cached ClassExecBlockNode classExecNode) {
672671
final int count = RubyArguments.getPositionalArgumentsCount(rubyArgs, false);
673672

674673
if (count > 0) {
@@ -677,7 +676,7 @@ protected Object evalWithBlock(Frame callerFrame, RubyModule self, Object[] ruby
677676
}
678677

679678
final Object block = RubyArguments.getBlock(rubyArgs);
680-
return classExecNode.classExec(EmptyArgumentsDescriptor.INSTANCE, self, new Object[]{ self },
679+
return classExecNode.execute(EmptyArgumentsDescriptor.INSTANCE, self, new Object[]{ self },
681680
(RubyProc) block);
682681
}
683682

@@ -763,23 +762,26 @@ private Object classEvalSource(MaterializedFrame callerFrame, RubyModule module,
763762
@CoreMethod(names = { "class_exec", "module_exec" }, rest = true, needsBlock = true)
764763
public abstract static class ClassExecNode extends CoreMethodArrayArgumentsNode {
765764

766-
public static ClassExecNode create() {
767-
return ClassExecNodeFactory.create(null);
768-
}
769-
770-
@Child private CallBlockNode callBlockNode = CallBlockNode.create();
771-
772765
@Specialization
773-
protected Object withBlock(VirtualFrame frame, RubyModule self, Object[] args, RubyProc block) {
774-
return classExec(RubyArguments.getDescriptor(frame), self, args, block);
766+
protected Object withBlock(VirtualFrame frame, RubyModule self, Object[] args, RubyProc block,
767+
@Cached ClassExecBlockNode classExecBlockNode) {
768+
return classExecBlockNode.execute(RubyArguments.getDescriptor(frame), self, args, block);
775769
}
776770

777771
@Specialization
778772
protected Object noBlock(RubyModule self, Object[] args, Nil block) {
779773
throw new RaiseException(getContext(), coreExceptions().noBlockGiven(this));
780774
}
775+
}
776+
777+
@GenerateUncached
778+
public abstract static class ClassExecBlockNode extends RubyBaseNode {
779+
780+
public abstract Object execute(ArgumentsDescriptor descriptor, RubyModule self, Object[] args, RubyProc block);
781781

782-
public Object classExec(ArgumentsDescriptor descriptor, RubyModule self, Object[] args, RubyProc block) {
782+
@Specialization
783+
protected Object classExec(ArgumentsDescriptor descriptor, RubyModule self, Object[] args, RubyProc block,
784+
@Cached CallBlockNode callBlockNode) {
783785
final DeclarationContext declarationContext = new DeclarationContext(
784786
Visibility.PUBLIC,
785787
new FixedDefaultDefinee(self),
@@ -1457,26 +1459,17 @@ protected Object extended(RubyModule module, Object object) {
14571459
@CoreMethod(names = "initialize", needsBlock = true) // Ideally should not split if no block given
14581460
public abstract static class InitializeNode extends CoreMethodArrayArgumentsNode {
14591461

1460-
@Child private ClassExecNode classExecNode;
1461-
14621462
public abstract RubyModule executeInitialize(RubyModule module, Object block);
14631463

1464-
void classEval(RubyModule module, RubyProc block) {
1465-
if (classExecNode == null) {
1466-
CompilerDirectives.transferToInterpreterAndInvalidate();
1467-
classExecNode = insert(ClassExecNode.create());
1468-
}
1469-
classExecNode.classExec(EmptyArgumentsDescriptor.INSTANCE, module, new Object[]{ module }, block);
1470-
}
1471-
14721464
@Specialization
14731465
protected RubyModule initialize(RubyModule module, Nil block) {
14741466
return module;
14751467
}
14761468

14771469
@Specialization
1478-
protected RubyModule initialize(RubyModule module, RubyProc block) {
1479-
classEval(module, block);
1470+
protected RubyModule initialize(RubyModule module, RubyProc block,
1471+
@Cached ClassExecBlockNode classExecBlockNode) {
1472+
classExecBlockNode.execute(EmptyArgumentsDescriptor.INSTANCE, module, new Object[]{ module }, block);
14801473
return module;
14811474
}
14821475

0 commit comments

Comments
 (0)