Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[Truffle] Clear $! when leaving a try-rescue-ensure block.
  • Loading branch information
chrisseaton committed Dec 29, 2014
1 parent fdfe94d commit 3792e0f
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
Expand Up @@ -15,7 +15,9 @@
import com.oracle.truffle.api.nodes.*;
import com.oracle.truffle.api.utilities.*;
import org.jruby.truffle.nodes.*;
import org.jruby.truffle.nodes.literal.ObjectLiteralNode;
import org.jruby.truffle.nodes.methods.ExceptionTranslatingNode;
import org.jruby.truffle.nodes.objects.WriteInstanceVariableNode;
import org.jruby.truffle.runtime.*;
import org.jruby.truffle.runtime.control.*;

Expand All @@ -28,6 +30,7 @@ public class TryNode extends RubyNode {
@Child protected ExceptionTranslatingNode tryPart;
@Children final RescueNode[] rescueParts;
@Child protected RubyNode elsePart;
@Child protected WriteInstanceVariableNode clearExceptionVariableNode;

private final BranchProfile elseProfile = BranchProfile.create();
private final BranchProfile controlFlowProfile = BranchProfile.create();
Expand All @@ -38,6 +41,10 @@ public TryNode(RubyContext context, SourceSection sourceSection, ExceptionTransl
this.tryPart = tryPart;
this.rescueParts = rescueParts;
this.elsePart = elsePart;
clearExceptionVariableNode = new WriteInstanceVariableNode(context, sourceSection, "$!",
new ObjectLiteralNode(context, sourceSection, context.getCoreLibrary().getGlobalVariablesObject()),
new ObjectLiteralNode(context, sourceSection, context.getCoreLibrary().getNilObject()),
true);
}

@Override
Expand All @@ -60,6 +67,8 @@ public Object execute(VirtualFrame frame) {
} catch (RetryException e) {
continue;
}
} finally {
clearExceptionVariableNode.execute(frame);
}

elseProfile.enter();
Expand Down
Expand Up @@ -105,7 +105,7 @@ public Object isDefined(VirtualFrame frame) {
if (isGlobal) {
final RubyBasicObject recieverValue = (RubyBasicObject) receiver.execute(frame);

if (readNode.getName().equals("$~")) {
if (readNode.getName().equals("$~") || readNode.getName().equals("$!")) {
return getContext().makeString("global-variable");
} else if (readNode.isSet(recieverValue)) {
if (readNode.execute(recieverValue) == getContext().getCoreLibrary().getNilObject()) {
Expand Down
1 change: 0 additions & 1 deletion spec/truffle/tags/language/predefined_tags.txt
@@ -1,2 +1 @@
fails:Predefined global $! remains nil after a failed core class "checked" coercion against a class that defines method_missing
fails:Predefined global $_ is Thread-local

0 comments on commit 3792e0f

Please sign in to comment.