Skip to content

Commit d1590df

Browse files
committed
[GR-25942] Fix PE recursion in Proc.new
PullRequest: truffleruby/1981
2 parents 9cda3b3 + 8909707 commit d1590df

File tree

2 files changed

+18
-35
lines changed

2 files changed

+18
-35
lines changed

src/main/java/org/truffleruby/core/kernel/KernelNodes.java

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@
99
*/
1010
package org.truffleruby.core.kernel;
1111

12+
import static org.truffleruby.language.dispatch.DispatchConfiguration.PRIVATE;
13+
import static org.truffleruby.language.dispatch.DispatchConfiguration.PRIVATE_DOES_RESPOND;
14+
import static org.truffleruby.language.dispatch.DispatchConfiguration.PUBLIC;
15+
import static org.truffleruby.language.dispatch.DispatchConfiguration.PUBLIC_DOES_RESPOND;
16+
1217
import java.io.File;
1318
import java.io.PrintStream;
1419
import java.nio.file.Paths;
@@ -17,7 +22,6 @@
1722
import java.util.List;
1823
import java.util.concurrent.TimeUnit;
1924

20-
import com.oracle.truffle.api.nodes.NodeUtil;
2125
import org.jcodings.specific.UTF8Encoding;
2226
import org.truffleruby.RubyContext;
2327
import org.truffleruby.builtins.CoreMethod;
@@ -59,7 +63,6 @@
5963
import org.truffleruby.core.numeric.BigIntegerOps;
6064
import org.truffleruby.core.numeric.RubyBignum;
6165
import org.truffleruby.core.proc.ProcNodes.ProcNewNode;
62-
import org.truffleruby.core.proc.ProcNodesFactory.ProcNewNodeFactory;
6366
import org.truffleruby.core.proc.ProcOperations;
6467
import org.truffleruby.core.proc.RubyProc;
6568
import org.truffleruby.core.rope.CodeRange;
@@ -148,18 +151,14 @@
148151
import com.oracle.truffle.api.nodes.ExplodeLoop;
149152
import com.oracle.truffle.api.nodes.IndirectCallNode;
150153
import com.oracle.truffle.api.nodes.Node;
154+
import com.oracle.truffle.api.nodes.NodeUtil;
151155
import com.oracle.truffle.api.object.DynamicObjectLibrary;
152156
import com.oracle.truffle.api.object.Property;
153157
import com.oracle.truffle.api.object.Shape;
154158
import com.oracle.truffle.api.profiles.BranchProfile;
155159
import com.oracle.truffle.api.profiles.ConditionProfile;
156160
import com.oracle.truffle.api.source.SourceSection;
157161

158-
import static org.truffleruby.language.dispatch.DispatchConfiguration.PRIVATE;
159-
import static org.truffleruby.language.dispatch.DispatchConfiguration.PRIVATE_DOES_RESPOND;
160-
import static org.truffleruby.language.dispatch.DispatchConfiguration.PUBLIC;
161-
import static org.truffleruby.language.dispatch.DispatchConfiguration.PUBLIC_DOES_RESPOND;
162-
163162
@CoreModule("Kernel")
164163
public abstract class KernelNodes {
165164

@@ -1424,10 +1423,9 @@ protected RubyArray privateMethods(Object self, boolean includeAncestors) {
14241423
@CoreMethod(names = "proc", isModuleFunction = true, needsBlock = true)
14251424
public abstract static class ProcNode extends CoreMethodArrayArgumentsNode {
14261425

1427-
@Child private ProcNewNode procNewNode = ProcNewNodeFactory.create(null);
1428-
14291426
@Specialization
1430-
protected RubyProc proc(VirtualFrame frame, Object maybeBlock) {
1427+
protected RubyProc proc(VirtualFrame frame, Object maybeBlock,
1428+
@Cached ProcNewNode procNewNode) {
14311429
return procNewNode.executeProcNew(frame, coreLibrary().procClass, ArrayUtils.EMPTY_ARRAY, maybeBlock);
14321430
}
14331431

src/main/java/org/truffleruby/core/proc/ProcNodes.java

Lines changed: 10 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -63,42 +63,27 @@ protected RubyProc allocate(RubyClass rubyClass) {
6363
@CoreMethod(names = "new", constructor = true, needsBlock = true, rest = true)
6464
public abstract static class ProcNewNode extends CoreMethodArrayArgumentsNode {
6565

66-
@Child private DispatchNode initializeNode;
67-
@Child private AllocateHelperNode allocateHelper;
66+
public static ProcNewNode create() {
67+
return ProcNodesFactory.ProcNewNodeFactory.create(null);
68+
}
6869

69-
public abstract RubyProc executeProcNew(
70-
VirtualFrame frame,
71-
RubyClass procClass,
72-
Object[] args,
73-
Object block);
70+
public abstract RubyProc executeProcNew(VirtualFrame frame, RubyClass procClass, Object[] args, Object block);
7471

7572
@Specialization
7673
protected RubyProc proc(VirtualFrame frame, RubyClass procClass, Object[] args, NotProvided block,
7774
@Cached("create(nil)") FindAndReadDeclarationVariableNode readNode,
78-
@Cached ReadCallerFrameNode readCaller) {
75+
@Cached ReadCallerFrameNode readCaller,
76+
@Cached ProcNewNode recurseNode) {
7977
final MaterializedFrame parentFrame = readCaller.execute(frame);
8078

81-
Object parentBlock = readNode
82-
.execute(parentFrame, TranslatorEnvironment.METHOD_BLOCK_NAME);
83-
84-
if (parentBlock == nil) {
85-
parentBlock = tryParentBlockForCExts();
86-
}
79+
Object parentBlock = readNode.execute(parentFrame, TranslatorEnvironment.METHOD_BLOCK_NAME);
8780

8881
if (parentBlock == nil) {
8982
throw new RaiseException(getContext(), coreExceptions().argumentErrorProcWithoutBlock(this));
83+
} else {
84+
final RubyProc proc = (RubyProc) parentBlock;
85+
return recurseNode.executeProcNew(frame, procClass, args, proc);
9086
}
91-
92-
return executeProcNew(frame, procClass, args, parentBlock);
93-
}
94-
95-
@TruffleBoundary
96-
protected Object tryParentBlockForCExts() {
97-
/* TODO CS 11-Mar-17 to pass the remaining cext proc specs we need to determine here if Proc.new has been
98-
* called from a cext from rb_funcall, and then reach down the stack to the Ruby method that originally went
99-
* into C and get the block from there. */
100-
101-
return nil;
10287
}
10388

10489
@Specialization(guards = { "procClass == getProcClass()", "block.getShape() == getProcShape()" })

0 commit comments

Comments
 (0)