Skip to content

Commit

Permalink
[Truffle] Don't override standard execute<type> methods in ToIntNode.
Browse files Browse the repository at this point in the history
When I added these variants, I didn't want UnexpectedResultException to propagate, so I removed it from the signature.  This changes the way Truffle generates code, however, and it was creating problems for us because the overridden standard methods were still being hooked into the normal specialized node chain, but not propagating the UnexpectedResultException there.  The fix is to use a unique method name in the cases where we don't want UnexpectedResultException to propagate, thereby fixing the standard chain.
  • Loading branch information
nirvdrum committed Apr 17, 2015
1 parent b24e190 commit 9ad70d5
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 51 deletions.
Expand Up @@ -98,14 +98,5 @@ public Object coerceObject(VirtualFrame frame, Object object) {
}
}

@Override
public abstract int executeIntegerFixnum(VirtualFrame frame);

public abstract int executeIntegerFixnum(VirtualFrame frame, Object object);

@Override
public abstract long executeLongFixnum(VirtualFrame frame);

@Override
public abstract RubyBignum executeBignum(VirtualFrame frame);
public abstract int executeInt(VirtualFrame frame, Object object);
}
62 changes: 30 additions & 32 deletions truffle/src/main/java/org/jruby/truffle/nodes/core/ArrayNodes.java
Expand Up @@ -21,7 +21,6 @@
import com.oracle.truffle.api.source.SourceSection;
import com.oracle.truffle.api.utilities.BranchProfile;

import org.jruby.RubyObject;
import org.jruby.runtime.Visibility;
import org.jruby.runtime.builtin.IRubyObject;
import org.jruby.truffle.nodes.CoreSourceSection;
Expand Down Expand Up @@ -52,7 +51,6 @@
import org.jruby.util.Memo;

import java.util.Arrays;
import java.util.Comparator;

@CoreClass(name = "Array")
public abstract class ArrayNodes {
Expand Down Expand Up @@ -291,7 +289,7 @@ public Object mulObjectCount(VirtualFrame frame, RubyArray array, Object object)
CompilerDirectives.transferToInterpreter();
toIntNode = insert(ToIntNodeFactory.create(getContext(), getSourceSection(), null));
}
final int count = toIntNode.executeIntegerFixnum(frame, object);
final int count = toIntNode.executeInt(frame, object);
if (count < 0) {
CompilerDirectives.transferToInterpreter();
throw new RaiseException(getContext().getCoreLibrary().argumentError("negative argument", this));
Expand Down Expand Up @@ -433,7 +431,7 @@ public Object set(VirtualFrame frame, RubyArray array, Object indexObject, Objec
CompilerDirectives.transferToInterpreter();
toIntNode = insert(ToIntNodeFactory.create(getContext(), getSourceSection(), null));
}
final int index = toIntNode.executeIntegerFixnum(frame, indexObject);
final int index = toIntNode.executeInt(frame, indexObject);
return set(frame, array, index, value, unused);
}

Expand All @@ -458,7 +456,7 @@ public Object setObject(VirtualFrame frame, RubyArray array, int start, Object l
CompilerDirectives.transferToInterpreter();
toIntNode = insert(ToIntNodeFactory.create(getContext(), getSourceSection(), null));
}
int length = toIntNode.executeIntegerFixnum(frame, lengthObject);
int length = toIntNode.executeInt(frame, lengthObject);
return setObject(frame, array, start, length, value);
}

Expand All @@ -468,7 +466,7 @@ public Object setObject(VirtualFrame frame, RubyArray array, Object startObject,
CompilerDirectives.transferToInterpreter();
toIntNode = insert(ToIntNodeFactory.create(getContext(), getSourceSection(), null));
}
int start = toIntNode.executeIntegerFixnum(frame, startObject);
int start = toIntNode.executeInt(frame, startObject);
return setObject(frame, array, start, length, value);
}

Expand All @@ -478,8 +476,8 @@ public Object setObject(VirtualFrame frame, RubyArray array, Object startObject,
CompilerDirectives.transferToInterpreter();
toIntNode = insert(ToIntNodeFactory.create(getContext(), getSourceSection(), null));
}
int length = toIntNode.executeIntegerFixnum(frame, lengthObject);
int start = toIntNode.executeIntegerFixnum(frame, startObject);
int length = toIntNode.executeInt(frame, lengthObject);
int start = toIntNode.executeInt(frame, startObject);
return setObject(frame, array, start, length, value);
}

Expand Down Expand Up @@ -549,7 +547,7 @@ public Object setOtherArray(VirtualFrame frame, RubyArray array, Object startObj
CompilerDirectives.transferToInterpreter();
toIntNode = insert(ToIntNodeFactory.create(getContext(), getSourceSection(), null));
}
int start = toIntNode.executeIntegerFixnum(frame, startObject);
int start = toIntNode.executeInt(frame, startObject);
return setOtherArray(frame, array, start, length, value);
}

Expand All @@ -559,7 +557,7 @@ public Object setOtherArray(VirtualFrame frame, RubyArray array, int start, Obje
CompilerDirectives.transferToInterpreter();
toIntNode = insert(ToIntNodeFactory.create(getContext(), getSourceSection(), null));
}
int length = toIntNode.executeIntegerFixnum(frame, lengthObject);
int length = toIntNode.executeInt(frame, lengthObject);
return setOtherArray(frame, array, start, length, value);
}

Expand All @@ -569,8 +567,8 @@ public Object setOtherArray(VirtualFrame frame, RubyArray array, Object startObj
CompilerDirectives.transferToInterpreter();
toIntNode = insert(ToIntNodeFactory.create(getContext(), getSourceSection(), null));
}
int start = toIntNode.executeIntegerFixnum(frame, startObject);
int length = toIntNode.executeIntegerFixnum(frame, lengthObject);
int start = toIntNode.executeInt(frame, startObject);
int length = toIntNode.executeInt(frame, lengthObject);
return setOtherArray(frame, array, start, length, value);
}

Expand Down Expand Up @@ -741,7 +739,7 @@ public AtNode(AtNode prev) {
}

@CreateCast("index") public RubyNode coerceOtherToInt(RubyNode index) {
return ToIntNodeFactory.create(getContext(), getSourceSection(), index);
return new FixnumLowerNode(ToIntNodeFactory.create(getContext(), getSourceSection(), index));
}

@Specialization
Expand Down Expand Up @@ -1786,7 +1784,7 @@ public RubyArray initialize(VirtualFrame frame, RubyArray array, Object object,
CompilerDirectives.transferToInterpreter();
toIntNode = insert(ToIntNodeFactory.create(getContext(), getSourceSection(), null));
}
int size = toIntNode.executeIntegerFixnum(frame, object);
int size = toIntNode.executeInt(frame, object);
if (size < 0) {
return initializeNegative(array, size, UndefinedPlaceholder.INSTANCE, UndefinedPlaceholder.INSTANCE);
} else {
Expand Down Expand Up @@ -1895,7 +1893,7 @@ public RubyArray initialize(VirtualFrame frame, RubyArray array, Object sizeObje
CompilerDirectives.transferToInterpreter();
toIntNode = insert(ToIntNodeFactory.create(getContext(), getSourceSection(), null));
}
int size = toIntNode.executeIntegerFixnum(frame, sizeObject);
int size = toIntNode.executeInt(frame, sizeObject);
if (size < 0) {
return initializeNegative(array, size, defaultValue, UndefinedPlaceholder.INSTANCE);
} else {
Expand Down Expand Up @@ -2236,7 +2234,7 @@ public Object insertBoxed(VirtualFrame frame, RubyArray array, Object[] values)
CompilerDirectives.transferToInterpreter();
toIntNode = insert(ToIntNodeFactory.create(getContext(), getSourceSection(), null));
}
index = toIntNode.executeIntegerFixnum(frame, values[0]);
index = toIntNode.executeInt(frame, values[0]);
}

final int valuesLength = values.length - 1;
Expand Down Expand Up @@ -3063,7 +3061,7 @@ public Object popNilWithNum(VirtualFrame frame, RubyArray array, Object object)
CompilerDirectives.transferToInterpreter();
toIntNode = insert(ToIntNodeFactory.create(getContext(), getSourceSection(), null));
}
final int n = toIntNode.executeIntegerFixnum(frame, object);
final int n = toIntNode.executeInt(frame, object);
if (n < 0) {
CompilerDirectives.transferToInterpreter();
throw new RaiseException(getContext().getCoreLibrary().argumentError("negative array size", this));
Expand Down Expand Up @@ -3208,7 +3206,7 @@ public RubyArray popIntegerFixnumInBoundsWithNumObj(VirtualFrame frame, RubyArra
CompilerDirectives.transferToInterpreter();
toIntNode = insert(ToIntNodeFactory.create(getContext(), getSourceSection(), null));
}
final int num = toIntNode.executeIntegerFixnum(frame, object);
final int num = toIntNode.executeInt(frame, object);
if (num < 0) {
CompilerDirectives.transferToInterpreter();
throw new RaiseException(getContext().getCoreLibrary().argumentError("negative array size", this));
Expand All @@ -3232,7 +3230,7 @@ public Object popIntegerFixnumWithNumObj(VirtualFrame frame, RubyArray array, Ob
CompilerDirectives.transferToInterpreter();
toIntNode = insert(ToIntNodeFactory.create(getContext(), getSourceSection(), null));
}
final int num = toIntNode.executeIntegerFixnum(frame, object);
final int num = toIntNode.executeInt(frame, object);
if (num < 0) {
CompilerDirectives.transferToInterpreter();
throw new RaiseException(getContext().getCoreLibrary().argumentError("negative array size", this));
Expand All @@ -3256,7 +3254,7 @@ public RubyArray popLongFixnumInBoundsWithNumObj(VirtualFrame frame, RubyArray a
CompilerDirectives.transferToInterpreter();
toIntNode = insert(ToIntNodeFactory.create(getContext(), getSourceSection(), null));
}
final int num = toIntNode.executeIntegerFixnum(frame, object);
final int num = toIntNode.executeInt(frame, object);
if (num < 0) {
CompilerDirectives.transferToInterpreter();
throw new RaiseException(getContext().getCoreLibrary().argumentError("negative array size", this));
Expand All @@ -3280,7 +3278,7 @@ public Object popLongFixnumWithNumObj(VirtualFrame frame, RubyArray array, Objec
CompilerDirectives.transferToInterpreter();
toIntNode = insert(ToIntNodeFactory.create(getContext(), getSourceSection(), null));
}
final int num = toIntNode.executeIntegerFixnum(frame, object);
final int num = toIntNode.executeInt(frame, object);
if (num < 0) {
CompilerDirectives.transferToInterpreter();
throw new RaiseException(getContext().getCoreLibrary().argumentError("negative array size", this));
Expand All @@ -3303,7 +3301,7 @@ public RubyArray popFloatInBoundsWithNumObj(VirtualFrame frame, RubyArray array,
CompilerDirectives.transferToInterpreter();
toIntNode = insert(ToIntNodeFactory.create(getContext(), getSourceSection(), null));
}
final int num = toIntNode.executeIntegerFixnum(frame, object);
final int num = toIntNode.executeInt(frame, object);
if (num < 0) {
CompilerDirectives.transferToInterpreter();
throw new RaiseException(getContext().getCoreLibrary().argumentError("negative array size", this));
Expand All @@ -3326,7 +3324,7 @@ public Object popFloatWithNumObj(VirtualFrame frame, RubyArray array, Object obj
CompilerDirectives.transferToInterpreter();
toIntNode = insert(ToIntNodeFactory.create(getContext(), getSourceSection(), null));
}
final int num = toIntNode.executeIntegerFixnum(frame, object);
final int num = toIntNode.executeInt(frame, object);
if (num < 0) {
CompilerDirectives.transferToInterpreter();
throw new RaiseException(getContext().getCoreLibrary().argumentError("negative array size", this));
Expand All @@ -3349,7 +3347,7 @@ public Object popObjectWithNumObj(VirtualFrame frame, RubyArray array, Object ob
CompilerDirectives.transferToInterpreter();
toIntNode = insert(ToIntNodeFactory.create(getContext(), getSourceSection(), null));
}
final int num = toIntNode.executeIntegerFixnum(frame, object);
final int num = toIntNode.executeInt(frame, object);
if (num < 0) {
CompilerDirectives.transferToInterpreter();
throw new RaiseException(getContext().getCoreLibrary().argumentError("negative array size", this));
Expand Down Expand Up @@ -4228,7 +4226,7 @@ public Object shiftNilWithNum(VirtualFrame frame, RubyArray array, Object object
CompilerDirectives.transferToInterpreter();
toIntNode = insert(ToIntNodeFactory.create(getContext(), getSourceSection(), null));
}
final int n = toIntNode.executeIntegerFixnum(frame, object);
final int n = toIntNode.executeInt(frame, object);
if (n < 0) {
CompilerDirectives.transferToInterpreter();
throw new RaiseException(getContext().getCoreLibrary().argumentError("negative array size", this));
Expand Down Expand Up @@ -4383,7 +4381,7 @@ public RubyArray shiftIntegerFixnumInBoundsWithNumObj(VirtualFrame frame, RubyAr
CompilerDirectives.transferToInterpreter();
toIntNode = insert(ToIntNodeFactory.create(getContext(), getSourceSection(), null));
}
final int num = toIntNode.executeIntegerFixnum(frame, object);
final int num = toIntNode.executeInt(frame, object);
if (num < 0) {
CompilerDirectives.transferToInterpreter();
throw new RaiseException(getContext().getCoreLibrary().argumentError("negative array size", this));
Expand All @@ -4408,7 +4406,7 @@ public Object shiftIntegerFixnumWithNumObj(VirtualFrame frame, RubyArray array,
CompilerDirectives.transferToInterpreter();
toIntNode = insert(ToIntNodeFactory.create(getContext(), getSourceSection(), null));
}
final int num = toIntNode.executeIntegerFixnum(frame, object);
final int num = toIntNode.executeInt(frame, object);
if (num < 0) {
CompilerDirectives.transferToInterpreter();
throw new RaiseException(getContext().getCoreLibrary().argumentError("negative array size", this));
Expand All @@ -4433,7 +4431,7 @@ public RubyArray shiftLongFixnumInBoundsWithNumObj(VirtualFrame frame, RubyArray
CompilerDirectives.transferToInterpreter();
toIntNode = insert(ToIntNodeFactory.create(getContext(), getSourceSection(), null));
}
final int num = toIntNode.executeIntegerFixnum(frame, object);
final int num = toIntNode.executeInt(frame, object);
if (num < 0) {
CompilerDirectives.transferToInterpreter();
throw new RaiseException(getContext().getCoreLibrary().argumentError("negative array size", this));
Expand All @@ -4458,7 +4456,7 @@ public Object shiftLongFixnumWithNumObj(VirtualFrame frame, RubyArray array, Obj
CompilerDirectives.transferToInterpreter();
toIntNode = insert(ToIntNodeFactory.create(getContext(), getSourceSection(), null));
}
final int num = toIntNode.executeIntegerFixnum(frame, object);
final int num = toIntNode.executeInt(frame, object);
if (num < 0) {
CompilerDirectives.transferToInterpreter();
throw new RaiseException(getContext().getCoreLibrary().argumentError("negative array size", this));
Expand All @@ -4482,7 +4480,7 @@ public RubyArray shiftFloatInBoundsWithNumObj(VirtualFrame frame, RubyArray arra
CompilerDirectives.transferToInterpreter();
toIntNode = insert(ToIntNodeFactory.create(getContext(), getSourceSection(), null));
}
final int num = toIntNode.executeIntegerFixnum(frame, object);
final int num = toIntNode.executeInt(frame, object);
if (num < 0) {
CompilerDirectives.transferToInterpreter();
throw new RaiseException(getContext().getCoreLibrary().argumentError("negative array size", this));
Expand All @@ -4507,7 +4505,7 @@ public Object shiftFloatWithNumObj(VirtualFrame frame, RubyArray array, Object o
CompilerDirectives.transferToInterpreter();
toIntNode = insert(ToIntNodeFactory.create(getContext(), getSourceSection(), null));
}
final int num = toIntNode.executeIntegerFixnum(frame, object);
final int num = toIntNode.executeInt(frame, object);
if (num < 0) {
CompilerDirectives.transferToInterpreter();
throw new RaiseException(getContext().getCoreLibrary().argumentError("negative array size", this));
Expand All @@ -4532,7 +4530,7 @@ public Object shiftObjectWithNumObj(VirtualFrame frame, RubyArray array, Object
CompilerDirectives.transferToInterpreter();
toIntNode = insert(ToIntNodeFactory.create(getContext(), getSourceSection(), null));
}
final int num = toIntNode.executeIntegerFixnum(frame, object);
final int num = toIntNode.executeInt(frame, object);
if (num < 0) {
CompilerDirectives.transferToInterpreter();
throw new RaiseException(getContext().getCoreLibrary().argumentError("negative array size", this));
Expand Down
Expand Up @@ -17,7 +17,6 @@
import com.oracle.truffle.api.utilities.ConditionProfile;

import org.joni.exception.ValueException;
import org.jruby.runtime.Visibility;
import org.jruby.truffle.nodes.RubyNode;
import org.jruby.truffle.nodes.coerce.ToIntNode;
import org.jruby.truffle.nodes.coerce.ToIntNodeFactory;
Expand Down Expand Up @@ -104,7 +103,7 @@ public Object getIndex(VirtualFrame frame, RubyMatchData matchData, Object index
toIntNode = insert(ToIntNodeFactory.create(getContext(), getSourceSection(), null));
}

return getIndex(matchData, toIntNode.executeIntegerFixnum(frame, index));
return getIndex(matchData, toIntNode.executeInt(frame, index));
}

@Specialization(guards = {"!isRubySymbol(arguments[1])", "!isRubyString(arguments[1])"})
Expand Down

0 comments on commit 9ad70d5

Please sign in to comment.