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.
nirvdrum committed Apr 17, 2015
1 parent b24e190 commit 9ad70d5
Showing 4 changed files with 38 additions and 51 deletions.
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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;
@@ -52,7 +51,6 @@
import org.jruby.util.Memo;

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

@CoreClass(name = "Array")
public abstract class ArrayNodes {
@@ -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));
@@ -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);
}

@@ -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);
}

@@ -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);
}

@@ -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);
}

@@ -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);
}

@@ -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);
}

@@ -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);
}

@@ -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
@@ -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 {
@@ -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 {
@@ -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;
@@ -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));
@@ -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));
@@ -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));
@@ -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));
@@ -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));
@@ -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));
@@ -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));
@@ -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));
@@ -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));
@@ -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));
@@ -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));
@@ -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));
@@ -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));
@@ -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));
@@ -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));
@@ -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));
Original file line number Diff line number Diff line change
@@ -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;
@@ -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])"})
Original file line number Diff line number Diff line change
@@ -65,7 +65,6 @@
import org.jruby.truffle.runtime.core.*;
import org.jruby.truffle.runtime.rubinius.RubiniusByteArray;
import org.jruby.util.ByteList;
import org.jruby.util.CodeRangeSupport;
import org.jruby.util.CodeRangeable;
import org.jruby.util.ConvertDouble;
import org.jruby.util.Pack;
@@ -171,7 +170,7 @@ public RubyString multiply(VirtualFrame frame, RubyString string, Object times)
toIntNode = insert(ToIntNodeFactory.create(getContext(), getSourceSection(), null));
}

return multiply(string, toIntNode.executeIntegerFixnum(frame, times));
return multiply(string, toIntNode.executeInt(frame, times));
}
}

@@ -498,7 +497,7 @@ public Object getIndex(VirtualFrame frame, RubyString string, int index, Undefin

@Specialization(guards = { "!isRubyRange(arguments[1])", "!isRubyRegexp(arguments[1])", "!isRubyString(arguments[1])" })
public Object getIndex(VirtualFrame frame, RubyString string, Object index, UndefinedPlaceholder undefined) {
return getIndex(frame, string, getToIntNode().executeIntegerFixnum(frame, index), undefined);
return getIndex(frame, string, getToIntNode().executeInt(frame, index), undefined);
}

@Specialization
@@ -515,8 +514,8 @@ public Object sliceLongRange(VirtualFrame frame, RubyString string, RubyRange.Lo
@Specialization
public Object sliceObjectRange(VirtualFrame frame, RubyString string, RubyRange.ObjectRange range, UndefinedPlaceholder undefined) {
// TODO (nirvdrum 31-Mar-15) The begin and end values may return Fixnums beyond int boundaries and we should handle that -- Bignums are always errors.
final int coercedBegin = getToIntNode().executeIntegerFixnum(frame, range.getBegin());
final int coercedEnd = getToIntNode().executeIntegerFixnum(frame, range.getEnd());
final int coercedBegin = getToIntNode().executeInt(frame, range.getBegin());
final int coercedEnd = getToIntNode().executeInt(frame, range.getEnd());

return sliceRange(frame, string, coercedBegin, coercedEnd, range.doesExcludeEnd());
}
@@ -563,12 +562,12 @@ public Object slice(VirtualFrame frame, RubyString string, int start, int length

@Specialization(guards = "!isUndefinedPlaceholder(arguments[2])")
public Object slice(VirtualFrame frame, RubyString string, int start, Object length) {
return slice(frame, string, start, getToIntNode().executeIntegerFixnum(frame, length));
return slice(frame, string, start, getToIntNode().executeInt(frame, length));
}

@Specialization(guards = { "!isRubyRange(arguments[1])", "!isRubyRegexp(arguments[1])", "!isRubyString(arguments[1])", "!isUndefinedPlaceholder(arguments[2])" })
public Object slice(VirtualFrame frame, RubyString string, Object start, Object length) {
return slice(frame, string, getToIntNode().executeIntegerFixnum(frame, start), getToIntNode().executeIntegerFixnum(frame, length));
return slice(frame, string, getToIntNode().executeInt(frame, start), getToIntNode().executeInt(frame, length));
}

@Specialization

0 comments on commit 9ad70d5

Please sign in to comment.