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 @@ -1730,7 +1730,7 @@ abstract static class SetStorageSliceNode extends Node {

public abstract void execute(SequenceStorage s, SliceInfo info, SequenceStorage iterable, boolean canGeneralize);

@Specialization(limit = "MAX_BASIC_STORAGES", guards = {"self.getClass() == cachedClass", "self.getClass() == sequence.getClass()", "replacesWholeSequence(cachedClass, self, info)"})
@Specialization(limit = "MAX_BASIC_STORAGES", guards = {"self.getClass() == cachedClass", "self.getClass() == sequence.getClass()", "replacesWholeSequence(self, info)"})
static void doWholeSequence(ArrayBasedSequenceStorage self, @SuppressWarnings("unused") SliceInfo info, ArrayBasedSequenceStorage sequence, @SuppressWarnings("unused") boolean canGeneralize,
@Cached("self.getClass()") Class<? extends ArrayBasedSequenceStorage> cachedClass) {
ArrayBasedSequenceStorage selfProfiled = cachedClass.cast(self);
Expand Down Expand Up @@ -1878,8 +1878,8 @@ static void singleStep(SequenceStorage self, int lo, int hi, SequenceStorage dat
}
}

protected static boolean replacesWholeSequence(Class<? extends ArrayBasedSequenceStorage> cachedClass, ArrayBasedSequenceStorage s, SliceInfo info) {
return info.start == 0 && info.step == 1 && info.stop == cachedClass.cast(s).length();
protected static boolean replacesWholeSequence(ArrayBasedSequenceStorage s, SliceInfo info) {
return info.start == 0 && info.step == 1 && info.stop == s.length();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,13 +128,21 @@ public static void setGlobals(Object[] arguments, PythonObject globals) {
}

public static PythonObject getGlobals(Object[] arguments) {
return (PythonObject) arguments[INDEX_GLOBALS_ARGUMENT];
return (PythonObject) getGlobalsNoCast(arguments);
}

public static PythonObject getGlobals(Frame frame) {
return getGlobals(frame.getArguments());
}

public static Object getGlobalsNoCast(Object[] arguments) {
return arguments[INDEX_GLOBALS_ARGUMENT];
}

public static Object getGlobalsNoCast(Frame frame) {
return getGlobalsNoCast(frame.getArguments());
}

public static PythonObject getGlobalsSafe(Frame frame) {
if (frame.getArguments()[INDEX_GLOBALS_ARGUMENT] instanceof PythonObject) {
return getGlobals(frame);
Expand Down Expand Up @@ -176,7 +184,11 @@ public static AbstractTruffleException getException(Object[] arguments) {
}

public static AbstractTruffleException getException(Frame frame) {
return (AbstractTruffleException) getExceptionUnchecked(frame.getArguments());
return (AbstractTruffleException) getExceptionUnchecked(frame);
}

public static Object getExceptionUnchecked(Frame frame) {
return getExceptionUnchecked(frame.getArguments());
}

public static Object getExceptionUnchecked(Object[] arguments) {
Expand All @@ -189,7 +201,11 @@ public static boolean hasException(Object[] arguments) {
}

public static void setException(Frame frame, AbstractTruffleException exc) {
setException(frame.getArguments(), exc);
setExceptionUnchecked(frame, exc);
}

public static void setExceptionUnchecked(Frame frame, Object exc) {
setExceptionUnchecked(frame.getArguments(), exc);
}

public static void setException(Object[] arguments, AbstractTruffleException exc) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1649,7 +1649,7 @@ public static void performLocals(VirtualFrame frame, TruffleString name,
@Specialization(guards = "!hasLocals(frame)")
public static void performGlobals(VirtualFrame frame, TruffleString name,
@Cached DeleteGlobalNode deleteNode) {
deleteNode.executeWithGlobals(frame, PArguments.getGlobals(frame), name);
deleteNode.executeWithGlobals(frame, PArguments.getGlobalsNoCast(frame), name);
}

public static boolean hasLocals(VirtualFrame frame) {
Expand Down Expand Up @@ -2379,6 +2379,10 @@ public static boolean isBuiltinTypeType(Shape cachedShape) {
return cachedShape.getDynamicType() == PythonBuiltinClassType.PythonClass;
}

static PythonManagedClass getManagedClassOrNull(Object receiver) {
return receiver instanceof PythonManagedClass klass ? klass : null;
}

public static Assumption getTypeStableAssumptionForReceiver(PythonManagedClass klass) {
return klass instanceof PythonClass pc ? pc.getTypeStableAssumption() : null;
}
Expand All @@ -2390,15 +2394,15 @@ public static boolean canCacheBuiltinTypeMultiContext(Object value, PythonManage
}

@Specialization(guards = {
"isSingleContext()", "!isNoValue(result)", //
"isSingleContext()", "cachedReceiver != null", "!isNoValue(result)", //
"!hasMaterializedDict(cachedShape)", "isBuiltinTypeType(cachedShape)", //
/* dynamic checks: */ "cachedReceiver == receiver"}, //
/* dynamic checks: */ "isSameObject(receiver, cachedReceiver)"}, //
rewriteOn = {UnexpectedResultException.class, InvalidAssumptionException.class}, limit = "3")
static int doTypeInt(@SuppressWarnings("unused") VirtualFrame frame, TruffleString key, PythonManagedClass receiver,
static int doTypeInt(@SuppressWarnings("unused") VirtualFrame frame, TruffleString key, Object receiver,
@Bind Node inliningTarget,
@Cached("receiver.getShape()") Shape cachedShape,
@Cached("loadCacheableTypeAttr(receiver, key)") Object result,
@Cached("receiver") PythonManagedClass cachedReceiver,
@Cached("getManagedClassOrNull(receiver)") PythonManagedClass cachedReceiver,
@Cached("cachedReceiver.getShape()") Shape cachedShape,
@Cached("loadCacheableTypeAttr(cachedReceiver, key)") Object result,
@Cached("getTypeStableAssumptionForReceiver(cachedReceiver)") Assumption typeStableAssumption) throws UnexpectedResultException, InvalidAssumptionException {
assert !shouldInternConstant(key) || isInterned(key);
checkAssumption(typeStableAssumption);
Expand All @@ -2410,15 +2414,15 @@ static int doTypeInt(@SuppressWarnings("unused") VirtualFrame frame, TruffleStri

@ForceQuickening
@Specialization(guards = {
"isSingleContext()", "!isNoValue(result)", //
"isSingleContext()", "cachedReceiver != null", "!isNoValue(result)", //
"!hasMaterializedDict(cachedShape)", "isBuiltinTypeType(cachedShape)", //
/* dynamic checks: */ "cachedReceiver == receiver"}, //
/* dynamic checks: */ "isSameObject(receiver, cachedReceiver)"}, //
rewriteOn = InvalidAssumptionException.class, replaces = "doTypeInt", limit = "3")
static Object doType(@SuppressWarnings("unused") VirtualFrame frame, TruffleString key, PythonManagedClass receiver,
static Object doType(@SuppressWarnings("unused") VirtualFrame frame, TruffleString key, Object receiver,
@Bind Node inliningTarget,
@Cached("receiver.getShape()") Shape cachedShape,
@Cached("loadCacheableTypeAttr(receiver, key)") Object result,
@Cached("receiver") PythonManagedClass cachedReceiver,
@Cached("getManagedClassOrNull(receiver)") PythonManagedClass cachedReceiver,
@Cached("cachedReceiver.getShape()") Shape cachedShape,
@Cached("loadCacheableTypeAttr(cachedReceiver, key)") Object result,
@Cached("getTypeStableAssumptionForReceiver(cachedReceiver)") Assumption typeStableAssumption) throws InvalidAssumptionException {
assert !shouldInternConstant(key) || isInterned(key);
checkAssumption(typeStableAssumption);
Expand All @@ -2427,15 +2431,15 @@ static Object doType(@SuppressWarnings("unused") VirtualFrame frame, TruffleStri

@ForceQuickening
@Specialization(guards = {
"canCacheBuiltinTypeMultiContext(result, cachedReceiver)", "!isNoValue(result)", //
"cachedReceiver != null", "canCacheBuiltinTypeMultiContext(result, cachedReceiver)", "!isNoValue(result)", //
"!hasMaterializedDict(cachedShape)", "isBuiltinTypeType(cachedShape)", //
/* dynamic checks: */ "cachedReceiver == receiver"}, //
/* dynamic checks: */ "isSameObject(receiver, cachedReceiver)"}, //
limit = "3", excludeForUncached = true)
static Object doBuiltinTypeMultiContext(@SuppressWarnings("unused") VirtualFrame frame, TruffleString key, PythonManagedClass receiver,
static Object doBuiltinTypeMultiContext(@SuppressWarnings("unused") VirtualFrame frame, TruffleString key, Object receiver,
@Bind Node inliningTarget,
@Cached("receiver.getShape()") Shape cachedShape,
@Cached("loadCacheableTypeAttr(receiver, key)") Object result,
@Cached(value = "receiver", weak = true) PythonManagedClass cachedReceiver) {
@Cached(value = "getManagedClassOrNull(receiver)", weak = true) PythonManagedClass cachedReceiver,
@Cached("cachedReceiver.getShape()") Shape cachedShape,
@Cached("loadCacheableTypeAttr(cachedReceiver, key)") Object result) {
assert !shouldInternConstant(key) || isInterned(key);
return result;
}
Expand All @@ -2452,15 +2456,15 @@ public static Assumption getTypeStableAssumptionForValue(Object descrValue) {

@ForceQuickening
@Specialization(guards = {
"isSingleContext()", "!isNoValue(result)", //
"isSingleContext()", "cachedReceiver != null", "!isNoValue(result)", //
"!hasMaterializedDict(cachedShape)", "isBuiltinTypeType(cachedShape)", //
/* dynamic checks: */ "cachedReceiver == receiver"}, //
/* dynamic checks: */ "isSameObject(receiver, cachedReceiver)"}, //
limit = "3", excludeForUncached = true, rewriteOn = InvalidAssumptionException.class)
static Object doTypeMutableNonDescriptor(@SuppressWarnings("unused") VirtualFrame frame, TruffleString key, PythonManagedClass receiver,
static Object doTypeMutableNonDescriptor(@SuppressWarnings("unused") VirtualFrame frame, TruffleString key, Object receiver,
@Bind Node inliningTarget,
@Cached("receiver.getShape()") Shape cachedShape,
@Cached("loadCacheableTypeAttr(receiver, key, true)") Object result,
@Cached("receiver") PythonManagedClass cachedReceiver,
@Cached("getManagedClassOrNull(receiver)") PythonManagedClass cachedReceiver,
@Cached("cachedReceiver.getShape()") Shape cachedShape,
@Cached("loadCacheableTypeAttr(cachedReceiver, key, true)") Object result,
@Cached("getTypeStableAssumptionForValue(result)") Assumption valueTypeStableAssumption,
@Cached("getTypeStableAssumptionForReceiver(cachedReceiver)") Assumption typeStableAssumption) throws InvalidAssumptionException {
assert !shouldInternConstant(key) || isInterned(key);
Expand Down Expand Up @@ -2800,7 +2804,7 @@ public static final class DeleteGlobal {
@Specialization
public static void perform(VirtualFrame frame, TruffleString name,
@Cached DeleteGlobalNode deleteNode) {
deleteNode.executeWithGlobals(frame, PArguments.getGlobals(frame), name);
deleteNode.executeWithGlobals(frame, PArguments.getGlobalsNoCast(frame), name);
}
}

Expand Down Expand Up @@ -3687,7 +3691,7 @@ public static final class Import {
@InliningCutoff
public static Object doImport(VirtualFrame frame, TruffleString name, TruffleString[] fromList, int level,
@Cached ImportNode node) {
return node.execute(frame, name, PArguments.getGlobals(frame), fromList, level);
return node.execute(frame, name, PArguments.getGlobalsNoCast(frame), fromList, level);
}
}

Expand Down Expand Up @@ -4296,7 +4300,7 @@ public static void doExceptional(VirtualFrame frame,
@Cached GetClassNode getClass,
@Cached ExceptionNodes.GetTracebackNode getTraceback,
@Cached PyObjectIsTrueNode isTrue) {
AbstractTruffleException savedExcState = PArguments.getException(frame);
Object savedExcState = PArguments.getExceptionUnchecked(frame);
try {
Object pythonException = exception;
if (exception instanceof PException pException) {
Expand All @@ -4318,7 +4322,7 @@ public static void doExceptional(VirtualFrame frame,
}
}
} finally {
PArguments.setException(frame, savedExcState);
PArguments.setExceptionUnchecked(frame, savedExcState);
}
}
}
Expand Down Expand Up @@ -4542,7 +4546,7 @@ public static Object doObject(VirtualFrame frame, LocalAccessor currentGenerator
// saved exception was fetched from the caller, so what we do is that we override it
// to the new caller passed exception state (possibly null meaning we need to fetch
// it via stack-walking if needed).
AbstractTruffleException callerExceptionState = PArguments.getException(frame.getArguments());
Object callerExceptionState = PArguments.getExceptionUnchecked(frame.getArguments());
savedException.setObject(bytecode, frame, callerExceptionState);
}

Expand All @@ -4553,7 +4557,7 @@ public static Object doObject(VirtualFrame frame, LocalAccessor currentGenerator
if (!currentGeneratorException.isCleared(bytecode, frame)) {
Object currentGenEx = currentGeneratorException.getObject(bytecode, frame);
if (currentGenEx != null) {
PArguments.setException(frame, (PException) currentGenEx);
PArguments.setExceptionUnchecked(frame, currentGenEx);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,12 @@ public static boolean isSingleContext() {

@Idempotent
public static PFunction getPFunction(PMethod method) {
return method.getFunction() instanceof PFunction function ? function : null;
return getPFunctionNoCast(method) instanceof PFunction function ? function : null;
}

@Idempotent
public static Object getPFunctionNoCast(PMethod method) {
return method.getFunction();
}

public static Object callUnaryBuiltin(VirtualFrame frame, PythonBuiltinBaseNode builtin, Object arg1) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ public static Object callPFunction(VirtualFrame frame, @SuppressWarnings("unused
return invokeNode.execute(frame, inliningTarget, callNode, cachedFunc, args);
}

@Specialization(guards = {"cachedFunc != null", "isSingleContext()", "getPFunction(func) == cachedFunc", "hasSimpleSignature(cachedFunc, 3)"}, excludeForUncached = true, //
@Specialization(guards = {"cachedFunc != null", "isSingleContext()", "isSameObject(getPFunctionNoCast(func), cachedFunc)", "hasSimpleSignature(cachedFunc, 3)"}, excludeForUncached = true, //
assumptions = "cachedFunc.getCodeStableAssumption()", limit = "getCallSiteInlineCacheMaxDepth()")
public static Object callPMethod(VirtualFrame frame, PMethod func, Object arg1, Object arg2,
@Bind Node inliningTarget,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public static Object callPFunction(VirtualFrame frame, @SuppressWarnings("unused
return invokeNode.execute(frame, inliningTarget, callNode, cachedFunc, args);
}

@Specialization(guards = {"cachedFunc != null", "isSingleContext()", "getPFunction(func) == cachedFunc", "hasSimpleSignature(cachedFunc, 5)"}, excludeForUncached = true, //
@Specialization(guards = {"cachedFunc != null", "isSingleContext()", "isSameObject(getPFunctionNoCast(func), cachedFunc)", "hasSimpleSignature(cachedFunc, 5)"}, excludeForUncached = true, //
assumptions = "cachedFunc.getCodeStableAssumption()", limit = "getCallSiteInlineCacheMaxDepth()")
public static Object callPMethod(VirtualFrame frame, PMethod func, Object arg1, Object arg2, Object arg3, Object arg4,
@Bind Node inliningTarget,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ public static Object callPFunction(VirtualFrame frame, @SuppressWarnings("unused
return invokeNode.execute(frame, inliningTarget, callNode, cachedFunc, args);
}

@Specialization(guards = {"cachedFunc != null", "isSingleContext()", "getPFunction(func) == cachedFunc", "hasSimpleSignature(cachedFunc, 4)"}, excludeForUncached = true, //
@Specialization(guards = {"cachedFunc != null", "isSingleContext()", "isSameObject(getPFunctionNoCast(func), cachedFunc)", "hasSimpleSignature(cachedFunc, 4)"}, excludeForUncached = true, //
assumptions = "cachedFunc.getCodeStableAssumption()", limit = "getCallSiteInlineCacheMaxDepth()")
public static Object callPMethod(VirtualFrame frame, PMethod func, Object arg1, Object arg2, Object arg3,
@Bind Node inliningTarget,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ public static Object callPFunction(VirtualFrame frame, @SuppressWarnings("unused
return invokeNode.execute(frame, inliningTarget, callNode, cachedFunc, args);
}

@Specialization(guards = {"cachedFunc != null", "isSingleContext()", "getPFunction(func) == cachedFunc", "hasSimpleSignature(cachedFunc, 2)"}, excludeForUncached = true, //
@Specialization(guards = {"cachedFunc != null", "isSingleContext()", "isSameObject(getPFunctionNoCast(func), cachedFunc)", "hasSimpleSignature(cachedFunc, 2)"}, excludeForUncached = true, //
assumptions = "cachedFunc.getCodeStableAssumption()", limit = "getCallSiteInlineCacheMaxDepth()")
public static Object callPMethod(VirtualFrame frame, PMethod func, Object arg,
@Bind Node inliningTarget,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@
@GenerateUncached
@GenerateInline(false) // footprint reduction 52 -> 36
public abstract class DeleteGlobalNode extends PNodeWithContext {
static PDict getDictOrNull(Object globals) {
return globals instanceof PDict dict ? dict : null;
}

@NeverDefault
public static DeleteGlobalNode create() {
return DeleteGlobalNodeGen.create();
Expand All @@ -72,10 +76,10 @@ public final void executeWithGlobals(VirtualFrame frame, Object globals, Truffle

public abstract void executeWithGlobalsImpl(VirtualFrame frame, Object globals, TruffleString attributeId);

@Specialization(guards = {"isSingleContext()", "globals == cachedGlobals"}, limit = "1")
static void deleteDictCached(VirtualFrame frame, @SuppressWarnings("unused") PDict globals, TruffleString attributeId,
@Specialization(guards = {"isSingleContext()", "cachedGlobals != null", "isSameObject(globals, cachedGlobals)"}, limit = "1")
static void deleteDictCached(VirtualFrame frame, @SuppressWarnings("unused") Object globals, TruffleString attributeId,
@Bind Node inliningTarget,
@Cached(value = "globals", weak = true) PDict cachedGlobals,
@Cached(value = "getDictOrNull(globals)", weak = true) PDict cachedGlobals,
@Shared("delItem") @Cached PyObjectDelItem deleteNode,
@Shared @Cached PRaiseNode raiseNode) {
try {
Expand Down
Loading
Loading