Skip to content

Commit 6428162

Browse files
committed
Merge branch 'truffle-break'
2 parents 4e4a5f5 + 3eab260 commit 6428162

17 files changed

+226
-76
lines changed

core/src/main/java/org/jruby/truffle/nodes/cast/LambdaNode.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public Object execute(VirtualFrame frame) {
3737
// TODO(CS): not sure we're closing over the correct state here
3838

3939
return new RubyProc(getContext().getCoreLibrary().getProcClass(), RubyProc.Type.LAMBDA,
40-
method.getSharedMethodInfo(), method.getCallTarget(), method.getCallTarget(),
40+
method.getSharedMethodInfo(), method.getCallTarget(), method.getCallTarget(), method.getCallTarget(),
4141
method.getDeclarationFrame(), method.getDeclaringModule(), method, RubyArguments.getSelf(frame.getArguments()), null);
4242
}
4343

core/src/main/java/org/jruby/truffle/nodes/control/TraceNode.java

+1-4
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,12 @@
1313
import com.oracle.truffle.api.CompilerDirectives;
1414
import com.oracle.truffle.api.Truffle;
1515
import com.oracle.truffle.api.frame.VirtualFrame;
16-
import com.oracle.truffle.api.instrument.KillException;
1716
import com.oracle.truffle.api.nodes.DirectCallNode;
1817
import com.oracle.truffle.api.nodes.InvalidAssumptionException;
19-
import com.oracle.truffle.api.nodes.UnexpectedResultException;
2018
import com.oracle.truffle.api.source.SourceSection;
2119
import org.jruby.truffle.nodes.RubyNode;
2220
import org.jruby.truffle.runtime.RubyArguments;
2321
import org.jruby.truffle.runtime.RubyContext;
24-
import org.jruby.truffle.runtime.UndefinedPlaceholder;
2522
import org.jruby.truffle.runtime.core.*;
2623

2724
public class TraceNode extends RubyNode {
@@ -70,7 +67,7 @@ public void trace(VirtualFrame frame) {
7067
traceFunc = context.getTraceManager().getTraceFunc();
7168

7269
if (traceFunc != null) {
73-
callNode = insert(Truffle.getRuntime().createDirectCallNode(traceFunc.getCallTarget()));
70+
callNode = insert(Truffle.getRuntime().createDirectCallNode(traceFunc.getCallTargetForBlocks()));
7471
} else {
7572
callNode = null;
7673
}

core/src/main/java/org/jruby/truffle/nodes/core/ArrayNodes.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -2510,7 +2510,7 @@ public Object max(VirtualFrame frame, RubyArray array) {
25102510

25112511
final RubyProc block = new RubyProc(getContext().getCoreLibrary().getProcClass(), RubyProc.Type.PROC,
25122512
maxBlock.getSharedMethodInfo(), maxBlock.getCallTarget(), maxBlock.getCallTarget(),
2513-
maximumClosureFrame.materialize(), null, null, array, null);
2513+
maxBlock.getCallTarget(), maximumClosureFrame.materialize(), null, null, array, null);
25142514

25152515
eachNode.call(frame, array, "each", block);
25162516

@@ -2629,7 +2629,7 @@ public Object min(VirtualFrame frame, RubyArray array) {
26292629

26302630
final RubyProc block = new RubyProc(getContext().getCoreLibrary().getProcClass(), RubyProc.Type.PROC,
26312631
minBlock.getSharedMethodInfo(), minBlock.getCallTarget(), minBlock.getCallTarget(),
2632-
minimumClosureFrame.materialize(), null, null, array, null);
2632+
minBlock.getCallTarget(), minimumClosureFrame.materialize(), null, null, array, null);
26332633

26342634
eachNode.call(frame, array, "each", block);
26352635

core/src/main/java/org/jruby/truffle/nodes/core/KernelNodes.java

+5-3
Original file line numberDiff line numberDiff line change
@@ -1240,7 +1240,8 @@ public RubyProc proc(RubyProc block) {
12401240

12411241
return new RubyProc(getContext().getCoreLibrary().getProcClass(), RubyProc.Type.LAMBDA,
12421242
block.getSharedMethodInfo(), block.getCallTargetForMethods(), block.getCallTargetForMethods(),
1243-
block.getDeclarationFrame(), block.getDeclaringModule(), block.getMethod(), block.getSelfCapturedInScope(), block.getBlockCapturedInScope());
1243+
block.getCallTargetForMethods(), block.getDeclarationFrame(), block.getDeclaringModule(),
1244+
block.getMethod(), block.getSelfCapturedInScope(), block.getBlockCapturedInScope());
12441245
}
12451246
}
12461247

@@ -1513,8 +1514,9 @@ public RubyProc proc(RubyProc block) {
15131514
notDesignedForCompilation();
15141515

15151516
return new RubyProc(getContext().getCoreLibrary().getProcClass(), RubyProc.Type.PROC,
1516-
block.getSharedMethodInfo(), block.getCallTarget(), block.getCallTargetForMethods(), block.getDeclarationFrame(),
1517-
block.getDeclaringModule(), block.getMethod(), block.getSelfCapturedInScope(), block.getBlockCapturedInScope());
1517+
block.getSharedMethodInfo(), block.getCallTargetForProcs(), block.getCallTargetForProcs(),
1518+
block.getCallTargetForMethods(), block.getDeclarationFrame(), block.getDeclaringModule(),
1519+
block.getMethod(), block.getSelfCapturedInScope(), block.getBlockCapturedInScope());
15181520
}
15191521
}
15201522

core/src/main/java/org/jruby/truffle/nodes/core/ProcNodes.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,10 @@ public InitializeNode(InitializeNode prev) {
113113

114114
@Specialization
115115
public RubyNilClass initialize(RubyProc proc, RubyProc block) {
116-
proc.initialize(block.getSharedMethodInfo(), block.getCallTargetForMethods(), block.getCallTargetForMethods(),
117-
block.getDeclarationFrame(), block.getDeclaringModule(), block.getMethod(), block.getSelfCapturedInScope(), block.getBlockCapturedInScope());
116+
proc.initialize(block.getSharedMethodInfo(), block.getCallTargetForProcs(),
117+
block.getCallTargetForProcs(), block.getCallTargetForMethods(), block.getDeclarationFrame(),
118+
block.getDeclaringModule(), block.getMethod(), block.getSelfCapturedInScope(),
119+
block.getBlockCapturedInScope());
118120

119121
return getContext().getCoreLibrary().getNilObject();
120122
}

core/src/main/java/org/jruby/truffle/nodes/methods/BlockDefinitionNode.java

+11-5
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
import com.oracle.truffle.api.frame.VirtualFrame;
1515
import com.oracle.truffle.api.source.SourceSection;
1616
import org.jruby.truffle.nodes.RubyNode;
17-
import org.jruby.truffle.nodes.RubyRootNode;
1817
import org.jruby.truffle.runtime.RubyArguments;
1918
import org.jruby.truffle.runtime.RubyContext;
2019
import org.jruby.truffle.runtime.core.RubyModule;
@@ -30,17 +29,23 @@ public class BlockDefinitionNode extends RubyNode {
3029

3130
private final SharedMethodInfo sharedMethodInfo;
3231

33-
private final CallTarget callTarget;
32+
// TODO(CS, 10-Jan-15) having three call targets isn't ideal, but they all have different semantics, and we don't
33+
// want to move logic into the call site
34+
35+
private final CallTarget callTargetForBlocks;
36+
private final CallTarget callTargetForProcs;
3437
private final CallTarget callTargetForMethods;
3538

3639
private final boolean requiresDeclarationFrame;
3740

3841
public BlockDefinitionNode(RubyContext context, SourceSection sourceSection, SharedMethodInfo sharedMethodInfo,
39-
boolean requiresDeclarationFrame, CallTarget callTarget, CallTarget callTargetForMethods) {
42+
boolean requiresDeclarationFrame, CallTarget callTargetForBlocks,
43+
CallTarget callTargetForProcs, CallTarget callTargetForMethods) {
4044
super(context, sourceSection);
4145
this.sharedMethodInfo = sharedMethodInfo;
4246

43-
this.callTarget = callTarget;
47+
this.callTargetForBlocks = callTargetForBlocks;
48+
this.callTargetForProcs = callTargetForProcs;
4449
this.callTargetForMethods = callTargetForMethods;
4550

4651
this.requiresDeclarationFrame = requiresDeclarationFrame;
@@ -68,7 +73,8 @@ public Object execute(VirtualFrame frame) {
6873
}
6974

7075
return new RubyProc(getContext().getCoreLibrary().getProcClass(), RubyProc.Type.PROC, sharedMethodInfo,
71-
callTarget, callTargetForMethods, declarationFrame, declaringModule, RubyArguments.getMethod(frame.getArguments()), RubyArguments.getSelf(frame.getArguments()),
76+
callTargetForBlocks, callTargetForProcs, callTargetForMethods, declarationFrame, declaringModule,
77+
RubyArguments.getMethod(frame.getArguments()), RubyArguments.getSelf(frame.getArguments()),
7278
RubyArguments.getBlock(frame.getArguments()));
7379
}
7480

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
* Copyright (c) 2015 Oracle and/or its affiliates. All rights reserved. This
3+
* code is released under a tri EPL/GPL/LGPL license. You can use it,
4+
* redistribute it and/or modify it under the terms of the:
5+
*
6+
* Eclipse Public License version 1.0
7+
* GNU General Public License version 2
8+
* GNU Lesser General Public License version 2.1
9+
*/
10+
package org.jruby.truffle.nodes.methods;
11+
12+
import com.oracle.truffle.api.CompilerDirectives;
13+
import com.oracle.truffle.api.frame.VirtualFrame;
14+
import com.oracle.truffle.api.source.SourceSection;
15+
import com.oracle.truffle.api.utilities.BranchProfile;
16+
import org.jruby.truffle.nodes.RubyNode;
17+
import org.jruby.truffle.runtime.RubyContext;
18+
import org.jruby.truffle.runtime.control.BreakException;
19+
import org.jruby.truffle.runtime.control.RaiseException;
20+
21+
public class CatchBreakAsProcErrorNode extends RubyNode {
22+
23+
@Child private RubyNode body;
24+
25+
public CatchBreakAsProcErrorNode(RubyContext context, SourceSection sourceSection, RubyNode body) {
26+
super(context, sourceSection);
27+
this.body = body;
28+
}
29+
30+
@Override
31+
public Object execute(VirtualFrame frame) {
32+
try {
33+
return body.execute(frame);
34+
} catch (BreakException e) {
35+
CompilerDirectives.transferToInterpreter();
36+
throw new RaiseException(getContext().getCoreLibrary().loadError("break from proc-closure", this));
37+
}
38+
}
39+
40+
}

core/src/main/java/org/jruby/truffle/nodes/yield/CachedYieldDispatchNode.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public class CachedYieldDispatchNode extends YieldDispatchNode {
2828
public CachedYieldDispatchNode(RubyContext context, RubyProc block, YieldDispatchNode next) {
2929
super(context);
3030

31-
callNode = Truffle.getRuntime().createDirectCallNode(block.getCallTarget());
31+
callNode = Truffle.getRuntime().createDirectCallNode(block.getCallTargetForBlocks());
3232
insert(callNode);
3333

3434
if (Options.TRUFFLE_INLINER_ALWAYS_CLONE_YIELD.load() && callNode.isCallTargetCloningAllowed()) {
@@ -44,7 +44,7 @@ public CachedYieldDispatchNode(RubyContext context, RubyProc block, YieldDispatc
4444

4545
@Override
4646
public Object dispatch(VirtualFrame frame, RubyProc block, Object[] argumentsObjects) {
47-
if (block.getCallTarget() != callNode.getCallTarget()) {
47+
if (block.getCallTargetForBlocks() != callNode.getCallTarget()) {
4848
return next.dispatch(frame, block, argumentsObjects);
4949
}
5050

@@ -53,7 +53,7 @@ public Object dispatch(VirtualFrame frame, RubyProc block, Object[] argumentsObj
5353

5454
@Override
5555
public Object dispatchWithModifiedBlock(VirtualFrame frame, RubyProc block, RubyProc modifiedBlock, Object[] argumentsObjects) {
56-
if (block.getCallTarget() != callNode.getCallTarget()) {
56+
if (block.getCallTargetForBlocks() != callNode.getCallTarget()) {
5757
return next.dispatch(frame, block, argumentsObjects);
5858
}
5959

@@ -62,7 +62,7 @@ public Object dispatchWithModifiedBlock(VirtualFrame frame, RubyProc block, Ruby
6262

6363
@Override
6464
public Object dispatchWithModifiedSelf(VirtualFrame frame, RubyProc block, Object self, Object... argumentsObjects) {
65-
if (block.getCallTarget() != callNode.getCallTarget()) {
65+
if (block.getCallTargetForBlocks() != callNode.getCallTarget()) {
6666
return next.dispatchWithModifiedSelf(frame, block, self, argumentsObjects);
6767
}
6868

core/src/main/java/org/jruby/truffle/nodes/yield/GeneralYieldDispatchNode.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,17 @@ public GeneralYieldDispatchNode(RubyContext context) {
3030

3131
@Override
3232
public Object dispatch(VirtualFrame frame, RubyProc block, Object[] argumentsObjects) {
33-
return callNode.call(frame, block.getCallTarget(), RubyArguments.pack(block, block.getDeclarationFrame(), block.getSelfCapturedInScope(), block.getBlockCapturedInScope(), argumentsObjects));
33+
return callNode.call(frame, block.getCallTargetForBlocks(), RubyArguments.pack(block, block.getDeclarationFrame(), block.getSelfCapturedInScope(), block.getBlockCapturedInScope(), argumentsObjects));
3434
}
3535

3636
@Override
3737
public Object dispatchWithModifiedBlock(VirtualFrame frame, RubyProc block, RubyProc modifiedBlock, Object[] argumentsObjects) {
38-
return callNode.call(frame, block.getCallTarget(), RubyArguments.pack(block, block.getDeclarationFrame(), block.getSelfCapturedInScope(), modifiedBlock, argumentsObjects));
38+
return callNode.call(frame, block.getCallTargetForBlocks(), RubyArguments.pack(block, block.getDeclarationFrame(), block.getSelfCapturedInScope(), modifiedBlock, argumentsObjects));
3939
}
4040

4141
@Override
4242
public Object dispatchWithModifiedSelf(VirtualFrame frame, RubyProc block, Object self, Object... argumentsObjects) {
43-
return callNode.call(frame, block.getCallTarget(), RubyArguments.pack(block, block.getDeclarationFrame(), self, block.getBlockCapturedInScope(), argumentsObjects));
43+
return callNode.call(frame, block.getCallTargetForBlocks(), RubyArguments.pack(block, block.getDeclarationFrame(), self, block.getBlockCapturedInScope(), argumentsObjects));
4444
}
4545

4646
}

core/src/main/java/org/jruby/truffle/runtime/core/RubyProc.java

+24-12
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,15 @@ public class RubyProc extends RubyBasicObject implements MethodLike {
2929
public static final boolean PROC_BINDING = Options.TRUFFLE_PROC_BINDING.load();
3030

3131
public static enum Type {
32-
PROC, LAMBDA
32+
BLOCK, PROC, LAMBDA
3333
}
3434

3535
private final Type type;
3636
@CompilationFinal private SharedMethodInfo sharedMethodInfo;
37-
/** Call target for procs, which have special arguments destructuring */
38-
@CompilationFinal private CallTarget callTarget;
37+
/** Call target for blocks, which have special arguments destructuring */
38+
@CompilationFinal private CallTarget callTargetForBlocks;
39+
/** Call target for actual Proc arguments, which handle break differently */
40+
@CompilationFinal private CallTarget callTargetForProcs;
3941
/** Call target for lambdas and methods, which have strict arguments destructuring */
4042
@CompilationFinal private CallTarget callTargetForMethods;
4143
@CompilationFinal private MaterializedFrame declarationFrame;
@@ -49,16 +51,20 @@ public RubyProc(RubyClass procClass, Type type) {
4951
this.type = type;
5052
}
5153

52-
public RubyProc(RubyClass procClass, Type type, SharedMethodInfo sharedMethodInfo, CallTarget callTarget,
53-
CallTarget callTargetForMethods, MaterializedFrame declarationFrame, RubyModule declaringModule, MethodLike method, Object self, RubyProc block) {
54+
public RubyProc(RubyClass procClass, Type type, SharedMethodInfo sharedMethodInfo, CallTarget callTargetForBlocks,
55+
CallTarget callTargetForProcs, CallTarget callTargetForMethods, MaterializedFrame declarationFrame,
56+
RubyModule declaringModule, MethodLike method, Object self, RubyProc block) {
5457
this(procClass, type);
55-
initialize(sharedMethodInfo, callTarget, callTargetForMethods, declarationFrame, declaringModule, method, self, block);
58+
initialize(sharedMethodInfo, callTargetForBlocks, callTargetForProcs, callTargetForMethods, declarationFrame,
59+
declaringModule, method, self, block);
5660
}
5761

58-
public void initialize(SharedMethodInfo sharedMethodInfo, CallTarget callTarget, CallTarget callTargetForMethods,
59-
MaterializedFrame declarationFrame, RubyModule declaringModule, MethodLike method, Object self, RubyProc block) {
62+
public void initialize(SharedMethodInfo sharedMethodInfo, CallTarget callTargetForBlocks, CallTarget callTargetForProcs,
63+
CallTarget callTargetForMethods, MaterializedFrame declarationFrame, RubyModule declaringModule,
64+
MethodLike method, Object self, RubyProc block) {
6065
this.sharedMethodInfo = sharedMethodInfo;
61-
this.callTarget = callTarget;
66+
this.callTargetForBlocks = callTargetForBlocks;
67+
this.callTargetForProcs = callTargetForProcs;
6268
this.callTargetForMethods = callTargetForMethods;
6369
this.declarationFrame = declarationFrame;
6470
this.declaringModule = declaringModule;
@@ -69,8 +75,10 @@ public void initialize(SharedMethodInfo sharedMethodInfo, CallTarget callTarget,
6975

7076
public CallTarget getCallTargetForType() {
7177
switch (type) {
78+
case BLOCK:
79+
return callTargetForBlocks;
7280
case PROC:
73-
return callTarget;
81+
return callTargetForProcs;
7482
case LAMBDA:
7583
return callTargetForMethods;
7684
}
@@ -94,8 +102,12 @@ public SharedMethodInfo getSharedMethodInfo() {
94102
return sharedMethodInfo;
95103
}
96104

97-
public CallTarget getCallTarget() {
98-
return callTarget;
105+
public CallTarget getCallTargetForBlocks() {
106+
return callTargetForBlocks;
107+
}
108+
109+
public CallTarget getCallTargetForProcs() {
110+
return callTargetForProcs;
99111
}
100112

101113
public CallTarget getCallTargetForMethods() {

core/src/main/java/org/jruby/truffle/runtime/core/RubySymbol.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public RubyProc toProc(SourceSection sourceSection, final RubyNode currentNode)
5555
final CallTarget callTarget = Truffle.getRuntime().createCallTarget(rootNode);
5656

5757
return new RubyProc(context.getCoreLibrary().getProcClass(), RubyProc.Type.PROC, sharedMethodInfo, callTarget,
58-
callTarget, null, null, null, getContext().getCoreLibrary().getNilObject(), null);
58+
callTarget, callTarget, null, null, null, getContext().getCoreLibrary().getNilObject(), null);
5959
}
6060

6161
public org.jruby.RubySymbol getJRubySymbol() {

core/src/main/java/org/jruby/truffle/translator/BehaveAsBlockNode.java

+9-9
Original file line numberDiff line numberDiff line change
@@ -19,26 +19,26 @@
1919
@NodeInfo(cost = NodeCost.NONE)
2020
public class BehaveAsBlockNode extends RubyNode {
2121

22-
@Child private RubyNode asBlockNode;
23-
@Child private RubyNode asMethodNode;
22+
@Child private RubyNode asBlock;
23+
@Child private RubyNode notAsBlock;
2424

25-
public BehaveAsBlockNode(RubyContext context, SourceSection sourceSection, RubyNode asBlockNode, RubyNode asMethodNode) {
25+
public BehaveAsBlockNode(RubyContext context, SourceSection sourceSection, RubyNode asBlock, RubyNode notAsBlock) {
2626
super(context, sourceSection);
27-
this.asBlockNode = asBlockNode;
28-
this.asMethodNode = asMethodNode;
27+
this.asBlock = asBlock;
28+
this.notAsBlock = notAsBlock;
2929
}
3030

3131
@Override
3232
public Object execute(VirtualFrame frame) {
3333
throw new UnsupportedOperationException();
3434
}
3535

36-
public RubyNode getAsBlockNode() {
37-
return asBlockNode;
36+
public RubyNode getAsBlock() {
37+
return asBlock;
3838
}
3939

40-
public RubyNode getAsMethodNode() {
41-
return asMethodNode;
40+
public RubyNode getNotAsBlock() {
41+
return notAsBlock;
4242
}
4343

4444
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* Copyright (c) 2014, 2015 Oracle and/or its affiliates. All rights reserved. This
3+
* code is released under a tri EPL/GPL/LGPL license. You can use it,
4+
* redistribute it and/or modify it under the terms of the:
5+
*
6+
* Eclipse Public License version 1.0
7+
* GNU General Public License version 2
8+
* GNU Lesser General Public License version 2.1
9+
*/
10+
package org.jruby.truffle.translator;
11+
12+
import com.oracle.truffle.api.frame.VirtualFrame;
13+
import com.oracle.truffle.api.nodes.NodeCost;
14+
import com.oracle.truffle.api.nodes.NodeInfo;
15+
import com.oracle.truffle.api.source.SourceSection;
16+
import org.jruby.truffle.nodes.RubyNode;
17+
import org.jruby.truffle.runtime.RubyContext;
18+
19+
@NodeInfo(cost = NodeCost.NONE)
20+
public class BehaveAsProcNode extends RubyNode {
21+
22+
@Child private RubyNode asProc;
23+
@Child private RubyNode notAsProc;
24+
25+
public BehaveAsProcNode(RubyContext context, SourceSection sourceSection, RubyNode asProc, RubyNode notAsProc) {
26+
super(context, sourceSection);
27+
this.asProc = asProc;
28+
this.notAsProc = notAsProc;
29+
}
30+
31+
@Override
32+
public Object execute(VirtualFrame frame) {
33+
throw new UnsupportedOperationException();
34+
}
35+
36+
public RubyNode getAsProc() {
37+
return asProc;
38+
}
39+
40+
public RubyNode getNotAsProc() {
41+
return notAsProc;
42+
}
43+
44+
}

0 commit comments

Comments
 (0)