Skip to content

Commit 2d308c1

Browse files
committed
Introduce and use PythonUtils#assertUncached
1 parent 72791e0 commit 2d308c1

File tree

4 files changed

+30
-24
lines changed

4 files changed

+30
-24
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyObjectFormat.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
import com.oracle.graal.python.nodes.call.special.CallBinaryMethodNode;
5757
import com.oracle.graal.python.nodes.call.special.LookupAndCallBinaryNode;
5858
import com.oracle.graal.python.nodes.object.GetClassNode;
59-
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
59+
import com.oracle.graal.python.util.PythonUtils;
6060
import com.oracle.truffle.api.dsl.Cached;
6161
import com.oracle.truffle.api.dsl.Cached.Exclusive;
6262
import com.oracle.truffle.api.dsl.Cached.Shared;
@@ -134,11 +134,11 @@ static Object doGeneric(VirtualFrame frame, Object obj, Object formatSpec,
134134
}
135135

136136
@Specialization(guards = "isString(formatSpec)", replaces = "doGeneric")
137-
@TruffleBoundary
138-
static Object doGenericUncached(Object obj, Object formatSpec) {
137+
static Object doGenericUncached(VirtualFrame frame, Object obj, Object formatSpec) {
138+
PythonUtils.assertUncached();
139139
Object klass = GetClassNode.getUncached().execute(obj);
140140
Object slot = LookupCallableSlotInMRONode.getUncached(SpecialMethodSlot.Format).execute(klass);
141-
return CallBinaryMethodNode.getUncached().executeObject(null, slot, obj, formatSpec);
141+
return CallBinaryMethodNode.getUncached().executeObject(frame, slot, obj, formatSpec);
142142
}
143143

144144
// Note: PRaiseNode is @Exclusive to workaround a bug in DSL

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/attributes/DeleteAttributeNode.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
import com.oracle.graal.python.nodes.call.special.CallBinaryMethodNode;
4646
import com.oracle.graal.python.nodes.call.special.LookupAndCallBinaryNode;
4747
import com.oracle.graal.python.nodes.object.GetClassNode;
48-
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
48+
import com.oracle.graal.python.util.PythonUtils;
4949
import com.oracle.truffle.api.dsl.Cached;
5050
import com.oracle.truffle.api.dsl.GenerateUncached;
5151
import com.oracle.truffle.api.dsl.NeverDefault;
@@ -68,10 +68,10 @@ protected void doIt(VirtualFrame frame, Object object, Object key,
6868
}
6969

7070
@Specialization(replaces = "doIt")
71-
@TruffleBoundary
72-
protected void doItUncached(Object object, Object key) {
71+
protected void doItUncached(VirtualFrame frame, Object object, Object key) {
72+
PythonUtils.assertUncached();
7373
Object klass = GetClassNode.getUncached().execute(object);
7474
Object method = LookupCallableSlotInMRONode.getUncached(SpecialMethodSlot.DelAttr).execute(klass);
75-
CallBinaryMethodNode.getUncached().executeObject(null, method, object, key);
75+
CallBinaryMethodNode.getUncached().executeObject(frame, method, object, key);
7676
}
7777
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/frame/ReadNameNode.java

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,11 @@
4545
import com.oracle.graal.python.builtins.objects.common.HashingStorage;
4646
import com.oracle.graal.python.builtins.objects.dict.PDict;
4747
import com.oracle.graal.python.builtins.objects.function.PArguments;
48-
import com.oracle.graal.python.lib.PyObjectGetItem;
4948
import com.oracle.graal.python.nodes.PNodeWithContext;
5049
import com.oracle.graal.python.nodes.object.IsBuiltinClassProfile;
5150
import com.oracle.graal.python.runtime.exception.PException;
5251
import com.oracle.truffle.api.CompilerAsserts;
5352
import com.oracle.truffle.api.dsl.Cached;
54-
import com.oracle.truffle.api.dsl.Cached.Shared;
5553
import com.oracle.truffle.api.dsl.GenerateUncached;
5654
import com.oracle.truffle.api.dsl.Specialization;
5755
import com.oracle.truffle.api.frame.VirtualFrame;
@@ -81,7 +79,7 @@ protected static HashingStorage getStorage(VirtualFrame frame) {
8179

8280
@Specialization(guards = "!hasLocals(frame)")
8381
protected Object readFromLocals(VirtualFrame frame, TruffleString attributeId,
84-
@Shared("readGlobal") @Cached ReadGlobalOrBuiltinNode readGlobalNode) {
82+
@Cached ReadGlobalOrBuiltinNode readGlobalNode) {
8583
return readGlobalNode.execute(frame, attributeId);
8684
}
8785

@@ -96,17 +94,4 @@ protected Object readFromLocalsDict(VirtualFrame frame, TruffleString attributeI
9694
return result;
9795
}
9896
}
99-
100-
@Specialization(guards = "hasLocals(frame)", replaces = "readFromLocalsDict")
101-
protected Object readFromLocals(VirtualFrame frame, TruffleString attributeId,
102-
@Shared("readGlobal") @Cached ReadGlobalOrBuiltinNode readGlobalNode,
103-
@Cached PyObjectGetItem getItem,
104-
@Cached IsBuiltinClassProfile keyError) {
105-
Object frameLocals = PArguments.getSpecialArgument(frame);
106-
try {
107-
return getItem.execute(frame, frameLocals, attributeId);
108-
} catch (PException e) {
109-
return readGlobalsIfKeyError(frame, attributeId, readGlobalNode, e, keyError);
110-
}
111-
}
11297
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/util/PythonUtils.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@
8989
import com.oracle.truffle.api.CompilerDirectives;
9090
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
9191
import com.oracle.truffle.api.RootCallTarget;
92+
import com.oracle.truffle.api.TruffleOptions;
9293
import com.oracle.truffle.api.dsl.NodeFactory;
9394
import com.oracle.truffle.api.frame.Frame;
9495
import com.oracle.truffle.api.frame.MaterializedFrame;
@@ -864,4 +865,24 @@ public static long crc32(int initialValue, byte[] bytes, int offset, int length)
864865
0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605, 0xcdd70693, 0x54de5729, 0x23d967bf,
865866
0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d
866867
};
868+
869+
/**
870+
* Use as a documentation and safety guard in specializations that are meant to be activated
871+
* only in the uncached case. Those Specializations exist only to allow to generate an uncached
872+
* variant of the node, but should never be activated in a regular cached case.
873+
*
874+
* Note that such specializations can take VirtualFrame and should forward it to other uncached
875+
* (and cached) nodes. The uncached nodes may be executed during the uncached execution of the
876+
* bytecode root node where it is allowed to pass the VirtualFrame around without materializing
877+
* it.
878+
*/
879+
public static void assertUncached() {
880+
if (!TruffleOptions.AOT) {
881+
// We cannot assert that it's never part of compilation, because then it would fail
882+
// during native-image build since it cannot prove that this Specialization is never
883+
// activated at runtime and includes this in runtime compiled methods.
884+
CompilerAsserts.neverPartOfCompilation();
885+
}
886+
CompilerDirectives.transferToInterpreter();
887+
}
867888
}

0 commit comments

Comments
 (0)