Skip to content

Commit

Permalink
[Truffle] Workaround for bad interaction between probability injectio…
Browse files Browse the repository at this point in the history
…n and consuming a value from an if-statement.
  • Loading branch information
chrisseaton committed Feb 20, 2015
1 parent 75ab133 commit 2a21e14
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions truffle/src/main/java/org/jruby/truffle/nodes/control/IfNode.java
Expand Up @@ -11,6 +11,7 @@

import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.source.SourceSection;
import com.oracle.truffle.api.utilities.BranchProfile;
import com.oracle.truffle.api.utilities.ConditionProfile;

import org.jruby.truffle.nodes.RubyNode;
Expand All @@ -27,7 +28,11 @@ public class IfNode extends RubyNode {
@Child private BooleanCastNode condition;
@Child private RubyNode thenBody;
@Child private RubyNode elseBody;
private final ConditionProfile conditionProfile = ConditionProfile.createCountingProfile();

private final BranchProfile thenBranch = BranchProfile.create();
private final BranchProfile elseBranch = BranchProfile.create();

// private final ConditionProfile conditionProfile = ConditionProfile.createCountingProfile();

public IfNode(RubyContext context, SourceSection sourceSection, RubyNode condition, RubyNode thenBody, RubyNode elseBody) {
super(context, sourceSection);
Expand All @@ -43,9 +48,13 @@ public IfNode(RubyContext context, SourceSection sourceSection, RubyNode conditi

@Override
public Object execute(VirtualFrame frame) {
if (conditionProfile.profile(condition.executeBoolean(frame))) {
// TODO CS 20-Feb-15 - we'd like to use this but it causes problems where we do things like x = if ...
// if (conditionProfile.profile(condition.executeBoolean(frame))) {
if (condition.executeBoolean(frame)) {
thenBranch.enter();
return thenBody.execute(frame);
} else {
elseBranch.enter();
return elseBody.execute(frame);
}
}
Expand Down

0 comments on commit 2a21e14

Please sign in to comment.