Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,10 @@
import com.oracle.graal.python.builtins.objects.type.TpSlots;
import com.oracle.graal.python.builtins.objects.type.TypeNodes;
import com.oracle.graal.python.builtins.objects.type.slots.TpSlotBinaryOp.BinaryOpBuiltinNode;
import com.oracle.graal.python.lib.PyFloatAsDoubleNode;
import com.oracle.graal.python.lib.PyFloatCheckNode;
import com.oracle.graal.python.lib.PyDateCheckNode;
import com.oracle.graal.python.lib.PyDeltaCheckNode;
import com.oracle.graal.python.lib.PyFloatAsDoubleNode;
import com.oracle.graal.python.lib.PyFloatCheckNode;
import com.oracle.graal.python.lib.PyLongAsLongNode;
import com.oracle.graal.python.lib.PyObjectCallMethodObjArgs;
import com.oracle.graal.python.lib.PyObjectHashNode;
Expand All @@ -120,7 +120,9 @@
import com.oracle.graal.python.nodes.util.CastToJavaStringNode;
import com.oracle.graal.python.nodes.util.CastToTruffleStringNode;
import com.oracle.graal.python.runtime.ExecutionContext;
import com.oracle.graal.python.runtime.ExecutionContext.BoundaryCallContext;
import com.oracle.graal.python.runtime.IndirectCallData;
import com.oracle.graal.python.runtime.IndirectCallData.BoundaryCallData;
import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
import com.oracle.truffle.api.dsl.Bind;
Expand All @@ -129,7 +131,6 @@
import com.oracle.truffle.api.dsl.NodeFactory;
import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.nodes.EncapsulatingNodeReference;
import com.oracle.truffle.api.nodes.Node;
import com.oracle.truffle.api.strings.TruffleString;

Expand Down Expand Up @@ -176,7 +177,7 @@ public void postInitialize(Python3Core core) {
public abstract static class NewNode extends PythonBuiltinNode {

@Specialization
static Object newDate(Object cls, Object yearObject, Object monthObject, Object dayObject,
static Object newDate(VirtualFrame frame, Object cls, Object yearObject, Object monthObject, Object dayObject,
@Bind Node inliningTarget,
@Cached PRaiseNode raiseNode,
@Cached BytesNodes.ToBytesNode toBytesNode,
Expand Down Expand Up @@ -215,7 +216,7 @@ static Object newDate(Object cls, Object yearObject, Object monthObject, Object
}
}

return newNode.execute(inliningTarget, cls, yearObject, monthObject, dayObject);
return newNode.execute(frame, inliningTarget, cls, yearObject, monthObject, dayObject);
}

/**
Expand Down Expand Up @@ -377,7 +378,7 @@ private static Object addBoundary(Object left, Object right, Node inliningTarget
}

LocalDate localDate = ChronoUnit.DAYS.addTo(from, days - 1);
return DateNodes.SubclassNewNode.getUncached().execute(inliningTarget,
return DateNodes.SubclassNewNode.executeUncached(
getResultDateType(dateObj),
localDate.getYear(),
localDate.getMonthValue(),
Expand Down Expand Up @@ -442,7 +443,7 @@ private static Object subBoundary(Object left, Object right, Node inliningTarget
}

LocalDate localDate = ChronoUnit.DAYS.addTo(from, days - 1);
return DateNodes.SubclassNewNode.getUncached().execute(inliningTarget,
return DateNodes.SubclassNewNode.executeUncached(
getResultDateType(left),
localDate.getYear(),
localDate.getMonthValue(),
Expand Down Expand Up @@ -543,7 +544,7 @@ static Object today(VirtualFrame frame, Object cls,
@TruffleBoundary
private static Object todayBoundary(Object cls, Node inliningTarget) {
var localDate = LocalDate.now();
return DateNodes.SubclassNewNode.getUncached().execute(inliningTarget, cls, localDate.getYear(), localDate.getMonthValue(), localDate.getDayOfMonth());
return DateNodes.SubclassNewNode.executeUncached(cls, localDate.getYear(), localDate.getMonthValue(), localDate.getDayOfMonth());
}
}

Expand All @@ -552,17 +553,14 @@ private static Object todayBoundary(Object cls, Node inliningTarget) {
public abstract static class FromTimestampNode extends PythonBinaryBuiltinNode {

@Specialization
static Object fromTimestamp(Object cls, Object timestampObject,
@Bind Node inliningTarget) {
EncapsulatingNodeReference encapsulating = EncapsulatingNodeReference.getCurrent();
Node encapsulatingNode = encapsulating.set(inliningTarget);
static Object fromTimestamp(VirtualFrame frame, Object cls, Object timestampObject,
@Bind Node inliningTarget,
@Cached("createFor($node)") BoundaryCallData callData) {
Object saved = BoundaryCallContext.enter(frame, callData);
try {
return fromTimestampBoundary(cls, timestampObject, inliningTarget);
} finally {
// Some uncached nodes (e.g. PyFloatAsDoubleNode and PyLongAsLongNode)
// may raise exceptions that are not connected to a current node. Set
// the current node manually.
encapsulating.set(encapsulatingNode);
BoundaryCallContext.exit(frame, callData, saved);
}
}

Expand All @@ -586,7 +584,7 @@ private static Object fromTimestampBoundary(Object cls, Object timestampObject,
TimeZone timeZone = TimeModuleBuiltins.getGlobalTimeZone(getContext(inliningTarget));
ZoneId zoneId = timeZone.toZoneId();
LocalDate localDate = LocalDate.ofInstant(instant, zoneId);
return DateNodes.SubclassNewNode.getUncached().execute(inliningTarget, cls, localDate.getYear(), localDate.getMonthValue(), localDate.getDayOfMonth());
return DateNodes.SubclassNewNode.executeUncached(cls, localDate.getYear(), localDate.getMonthValue(), localDate.getDayOfMonth());
}
}

Expand Down Expand Up @@ -620,7 +618,7 @@ static Object fromIsoCalendar(VirtualFrame frame, Object cls, long year, long we
private static Object fromIsoCalendarBoundary(Object cls, long year, long week, long dayOfWeek, Node inliningTarget) {
DatetimeModuleBuiltins.validateIsoCalendarComponentsAndRaise(inliningTarget, year, week, dayOfWeek);
LocalDate localDate = LocalDate.now().with(IsoFields.WEEK_BASED_YEAR, year).with(IsoFields.WEEK_OF_WEEK_BASED_YEAR, week).with(ChronoField.DAY_OF_WEEK, dayOfWeek);
return DateNodes.SubclassNewNode.getUncached().execute(inliningTarget, cls, localDate.getYear(), localDate.getMonthValue(), localDate.getDayOfMonth());
return DateNodes.SubclassNewNode.executeUncached(cls, localDate.getYear(), localDate.getMonthValue(), localDate.getDayOfMonth());
}
}

Expand Down Expand Up @@ -715,7 +713,7 @@ private static Object parseIsoDateFormat(String source, Node inliningTarget, Obj
}

LocalDate localDate = LocalDate.now().with(IsoFields.WEEK_BASED_YEAR, year).with(IsoFields.WEEK_OF_WEEK_BASED_YEAR, week).with(ChronoField.DAY_OF_WEEK, dayOfWeek);
return DateNodes.SubclassNewNode.getUncached().execute(inliningTarget,
return DateNodes.SubclassNewNode.executeUncached(
cls,
localDate.getYear(),
localDate.getMonthValue(),
Expand All @@ -737,7 +735,7 @@ private static Object parseIsoDateFormat(String source, Node inliningTarget, Obj
return null;
}

return DateNodes.SubclassNewNode.getUncached().execute(inliningTarget, cls, year, month, day);
return DateNodes.SubclassNewNode.executeUncached(cls, year, month, day);
} catch (IndexOutOfBoundsException e) {
return null;
}
Expand Down Expand Up @@ -791,7 +789,7 @@ static Object replace(VirtualFrame frame, Object self, Object yearObject, Object
day = (int) longAsLongNode.execute(frame, inliningTarget, dayObject);
}

return newNode.execute(inliningTarget, getClassNode.execute(inliningTarget, self), year, month, day);
return newNode.execute(frame, inliningTarget, getClassNode.execute(inliningTarget, self), year, month, day);
}
}

Expand Down Expand Up @@ -843,7 +841,7 @@ private static Object fromOrdinalBoundary(Object cls, long days, Node inliningTa
LocalDate baseLocalDate = LocalDate.of(1, 1, 1);
LocalDate localDate = ChronoUnit.DAYS.addTo(baseLocalDate, days - 1);

return DateNodes.SubclassNewNode.getUncached().execute(inliningTarget, cls, localDate.getYear(), localDate.getMonthValue(), localDate.getDayOfMonth());
return DateNodes.SubclassNewNode.executeUncached(cls, localDate.getYear(), localDate.getMonthValue(), localDate.getDayOfMonth());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@

import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
import com.oracle.graal.python.builtins.modules.datetime.DateNodesFactory.NewNodeGen;
import com.oracle.graal.python.builtins.objects.cext.PythonAbstractNativeObject;
import com.oracle.graal.python.builtins.objects.cext.capi.CApiContext;
import com.oracle.graal.python.builtins.objects.cext.capi.ExternalFunctionInvoker;
Expand All @@ -64,17 +65,17 @@
import com.oracle.graal.python.nodes.PGuards;
import com.oracle.graal.python.nodes.PRaiseNode;
import com.oracle.graal.python.nodes.call.CallNode;
import com.oracle.graal.python.runtime.ExecutionContext.BoundaryCallContext;
import com.oracle.graal.python.runtime.IndirectCallData.BoundaryCallData;
import com.oracle.graal.python.runtime.PythonContext;
import com.oracle.graal.python.runtime.nativeaccess.NativeMemory;
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.Fallback;
import com.oracle.truffle.api.dsl.GenerateCached;
import com.oracle.truffle.api.dsl.GenerateInline;
import com.oracle.truffle.api.dsl.GenerateUncached;
import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.api.nodes.EncapsulatingNodeReference;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.nodes.Node;
import com.oracle.truffle.api.object.Shape;

Expand All @@ -85,19 +86,28 @@ public class DateNodes {
@GenerateCached(false)
public abstract static class NewNode extends Node {

public abstract Object execute(Node inliningTarget, Object cls, Object yearObject, Object monthObject, Object dayObject);
public abstract Object execute(VirtualFrame frame, Node inliningTarget, Object cls, Object yearObject, Object monthObject, Object dayObject);

/**
* Executes without access to the current Python frame. This overload may only be used when {@code cls} is
* {@link PythonBuiltinClassType} and all remaining arguments are known to be valid builtin values.
*/
public final Object execute(Node inliningTarget, Object cls, Object yearObject, Object monthObject, Object dayObject) {
return execute(null, inliningTarget, cls, yearObject, monthObject, dayObject);
}

public static Object executeUncached(Object cls, Object yearObject, Object monthObject, Object dayObject) {
return NewNodeGen.getUncached().execute(NewNodeGen.getUncached(), cls, yearObject, monthObject, dayObject);
}

@Specialization
static Object newDate(Node inliningTarget, Object cls, Object yearObject, Object monthObject, Object dayObject) {
EncapsulatingNodeReference encapsulating = EncapsulatingNodeReference.getCurrent();
Node encapsulatingNode = encapsulating.set(inliningTarget);
static Object newDate(VirtualFrame frame, Node inliningTarget, Object cls, Object yearObject, Object monthObject, Object dayObject,
@Cached("createFor($node)") BoundaryCallData callData) {
Object saved = BoundaryCallContext.enter(frame, callData);
try {
return newDateBoundary(inliningTarget, cls, yearObject, monthObject, dayObject);
} finally {
// Some uncached nodes (e.g. PyLongAsLongNode) may raise exceptions
// that are not connected to a current node. Set the current node
// manually.
encapsulating.set(encapsulatingNode);
BoundaryCallContext.exit(frame, callData, saved);
}
}

Expand Down Expand Up @@ -167,31 +177,13 @@ static Object newDate(Node inliningTarget, Object cls, int year, int month, int
}
}

@GenerateUncached
@GenerateInline
@GenerateCached(false)
public abstract static class SubclassNewNode extends Node {

public abstract Object execute(Node inliningTarget, Object cls, Object yearObject, Object monthObject, Object dayObject);

public static SubclassNewNode getUncached() {
return DateNodesFactory.SubclassNewNodeGen.getUncached();
}

@Specialization(guards = {"isBuiltinClass(cls)"})
static Object newDateBuiltin(Node inliningTarget, Object cls, Object yearObject, Object monthObject, Object dayObject,
@Cached NewNode newNode) {
return newNode.execute(inliningTarget, cls, yearObject, monthObject, dayObject);
}

@Fallback
@TruffleBoundary
static Object newDateGeneric(Object cls, Object yearObject, Object monthObject, Object dayObject) {
return CallNode.executeUncached(cls, yearObject, monthObject, dayObject);
}

static boolean isBuiltinClass(Object cls) {
return PGuards.isBuiltinClass(cls, PythonBuiltinClassType.PDate);
public abstract static class SubclassNewNode {
public static Object executeUncached(Object cls, Object yearObject, Object monthObject, Object dayObject) {
if (PGuards.isBuiltinClass(cls, PythonBuiltinClassType.PDate)) {
return NewNode.executeUncached(cls, yearObject, monthObject, dayObject);
} else {
return CallNode.executeUncached(cls, yearObject, monthObject, dayObject);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,6 @@
import com.oracle.truffle.api.dsl.NodeFactory;
import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.nodes.EncapsulatingNodeReference;
import com.oracle.truffle.api.nodes.Node;
import com.oracle.truffle.api.object.Shape;
import com.oracle.truffle.api.strings.TruffleString;
Expand Down Expand Up @@ -403,18 +402,15 @@ static Object str(VirtualFrame frame, Object self,
public abstract static class ReprNode extends PythonUnaryBuiltinNode {

@Specialization
static TruffleString repr(Object selfObj,
static TruffleString repr(VirtualFrame frame, Object selfObj,
@Bind Node inliningTarget,
@Cached DateTimeNodes.TzInfoNode tzInfoNode) {
EncapsulatingNodeReference encapsulating = EncapsulatingNodeReference.getCurrent();
Node encapsulatingNode = encapsulating.set(inliningTarget);
@Cached DateTimeNodes.TzInfoNode tzInfoNode,
@Cached("createFor($node)") IndirectCallData.BoundaryCallData boundaryCallData) {
Object saved = ExecutionContext.BoundaryCallContext.enter(frame, boundaryCallData);
try {
return reprBoundary(inliningTarget, selfObj, tzInfoNode.execute(inliningTarget, selfObj));
} finally {
// Some uncached nodes (e.g. PyFloatAsDoubleNode, PyLongAsLongNode,
// PyObjectReprAsObjectNode) may raise exceptions that are not
// connected to a current node. Set the current node manually.
encapsulating.set(encapsulatingNode);
ExecutionContext.BoundaryCallContext.exit(frame, boundaryCallData, saved);
}
}

Expand Down Expand Up @@ -1818,11 +1814,11 @@ static Object strptime(VirtualFrame frame, Object cls, TruffleString stringTs, T
abstract static class DateNode extends PythonUnaryBuiltinNode {

@Specialization
static Object getDate(Object selfObj,
static Object getDate(VirtualFrame frame, Object selfObj,
@Bind Node inliningTarget,
@Cached DateNodes.NewNode newDateNode) {
DateTimeValue self = TemporalValueNodes.GetDateTimeValue.executeUncached(inliningTarget, selfObj);
return newDateNode.execute(inliningTarget,
return newDateNode.execute(frame, inliningTarget,
PythonBuiltinClassType.PDate,
self.year,
self.month,
Expand All @@ -1835,11 +1831,11 @@ static Object getDate(Object selfObj,
abstract static class TimeNode extends PythonUnaryBuiltinNode {

@Specialization
static Object getTime(Object selfObj,
static Object getTime(VirtualFrame frame, Object selfObj,
@Bind Node inliningTarget,
@Cached TimeNodes.NewNode newTimeNode) {
DateTimeValue self = TemporalValueNodes.GetDateTimeValue.executeUncached(inliningTarget, selfObj);
return newTimeNode.execute(inliningTarget,
return newTimeNode.execute(frame, inliningTarget,
PythonBuiltinClassType.PTime,
self.hour,
self.minute,
Expand All @@ -1855,12 +1851,12 @@ static Object getTime(Object selfObj,
abstract static class TimeTzNode extends PythonUnaryBuiltinNode {

@Specialization
static Object getTime(Object selfObj,
static Object getTime(VirtualFrame frame, Object selfObj,
@Bind Node inliningTarget,
@Cached DateTimeNodes.TzInfoNode tzInfoNode,
@Cached TimeNodes.NewNode newTimeNode) {
DateTimeValue self = TemporalValueNodes.GetDateTimeValue.executeUncached(inliningTarget, selfObj);
return newTimeNode.execute(inliningTarget,
return newTimeNode.execute(frame, inliningTarget,
PythonBuiltinClassType.PTime,
self.hour,
self.minute,
Expand Down Expand Up @@ -2045,8 +2041,7 @@ private static PTimeZone getSystemTimeZoneAt(LocalDateTime localDateTime, int fo
long timestampMillis = timestamp * 1_000;
int offsetMilliseconds = timeZone.getOffset(timestampMillis);

Object timeDeltaType = PythonBuiltinClassType.PTimeDelta;
Object offset = TimeDeltaNodes.NewNode.getUncached().execute(inliningTarget, timeDeltaType, 0, 0, 0, offsetMilliseconds, 0, 0, 0);
Object offset = TimeDeltaNodes.NewNode.getUncached().execute(inliningTarget, PythonBuiltinClassType.PTimeDelta, 0, 0, 0, offsetMilliseconds, 0, 0, 0);

Object timeZoneType = PythonBuiltinClassType.PTimezone;
TruffleString timeZoneNameTS = TruffleString.FromJavaStringNode.getUncached().execute(timeZoneName, TS_ENCODING);
Expand Down
Loading
Loading