Skip to content

Commit 1132b35

Browse files
committed
Move logic of _PyTruffleErr_Occurred into helper node
1 parent 37a082a commit 1132b35

File tree

2 files changed

+31
-13
lines changed

2 files changed

+31
-13
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextErrBuiltins.java

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@
8383
import com.oracle.graal.python.builtins.modules.cext.PythonCextFileBuiltins.PyFile_WriteObject;
8484
import com.oracle.graal.python.builtins.objects.PNone;
8585
import com.oracle.graal.python.builtins.objects.cext.capi.CExtNodes.ClearCurrentExceptionNode;
86+
import com.oracle.graal.python.builtins.objects.cext.capi.CExtNodes.PyErrOccurredNode;
8687
import com.oracle.graal.python.builtins.objects.cext.capi.CExtNodes.TransformExceptionToNativeNode;
8788
import com.oracle.graal.python.builtins.objects.cext.capi.PThreadState;
8889
import com.oracle.graal.python.builtins.objects.cext.common.NativePointer;
@@ -93,7 +94,6 @@
9394
import com.oracle.graal.python.builtins.objects.exception.PBaseException;
9495
import com.oracle.graal.python.builtins.objects.exception.PrepareExceptionNode;
9596
import com.oracle.graal.python.builtins.objects.function.PKeyword;
96-
import com.oracle.graal.python.builtins.objects.ints.PInt;
9797
import com.oracle.graal.python.builtins.objects.module.PythonModule;
9898
import com.oracle.graal.python.builtins.objects.traceback.LazyTraceback;
9999
import com.oracle.graal.python.builtins.objects.traceback.MaterializeLazyTracebackNode;
@@ -102,7 +102,6 @@
102102
import com.oracle.graal.python.builtins.objects.tuple.TupleBuiltins;
103103
import com.oracle.graal.python.builtins.objects.tuple.TupleBuiltins.GetItemNode;
104104
import com.oracle.graal.python.builtins.objects.type.TypeNodes.IsTypeNode;
105-
import com.oracle.graal.python.lib.PyErrExceptionMatchesNode;
106105
import com.oracle.graal.python.lib.PyObjectCallMethodObjArgs;
107106
import com.oracle.graal.python.lib.PyObjectGetAttr;
108107
import com.oracle.graal.python.lib.PyObjectLookupAttr;
@@ -224,14 +223,10 @@ Object run(
224223
abstract static class _PyTruffleErr_Occurred extends CApiUnaryBuiltinNode {
225224
@Specialization
226225
Object run(PThreadState state,
227-
@Bind("this") Node inliningTarget,
228-
@Cached GetClassNode getClassNode) {
229-
PException currentException = state.getThreadState().getCurrentException();
230-
if (currentException != null) {
231-
// getClassNode acts as a branch profile
232-
return getClassNode.execute(inliningTarget, currentException.getUnreifiedException());
233-
}
234-
return getNativeNull();
226+
@Bind("this") Node inliningTarget,
227+
@Cached PyErrOccurredNode pyErrOccurredNode) {
228+
Object excType = pyErrOccurredNode.execute(inliningTarget, state.getThreadState());
229+
return excType != null ? excType : getNativeNull();
235230
}
236231
}
237232

@@ -425,7 +420,6 @@ abstract static class PyErr_PrintEx extends CApiUnaryBuiltinNode {
425420
@TruffleBoundary
426421
@Specialization
427422
static Object raise(int set_sys_last_vars,
428-
@Cached _PyTruffleErr_Occurred errOccuredNode,
429423
@Cached TupleBuiltins.GetItemNode getItemNode,
430424
@Cached IsInstanceNode isInstanceNode,
431425
@Cached ExcInfoNode excInfoNode,
@@ -437,7 +431,7 @@ static Object raise(int set_sys_last_vars,
437431
PythonContext context = PythonContext.get(null);
438432
NativePointer nativeNull = context.getNativeNull();
439433

440-
Object err = errOccuredNode.execute(context.getThreadState(PythonLanguage.get(null)));
434+
Object err = PyErrOccurredNode.executeUncached(context.getThreadState(PythonLanguage.get(null)));
441435
PythonModule sys = context.getSysModule();
442436
if (err != nativeNull && IsBuiltinObjectProfile.profileObjectUncached(err, PythonBuiltinClassType.SystemExit)) {
443437
handleSystemExit(excInfoNode, getItemNode, isInstanceNode, restoreNode, (SysModuleBuiltins) sys.getBuiltins(), writeFileNode, exitNode);

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/CExtNodes.java

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@
8787
import com.oracle.graal.python.builtins.objects.cext.capi.CExtNodesFactory.AsCharPointerNodeGen;
8888
import com.oracle.graal.python.builtins.objects.cext.capi.CExtNodesFactory.CreateFunctionNodeGen;
8989
import com.oracle.graal.python.builtins.objects.cext.capi.CExtNodesFactory.FromCharPointerNodeGen;
90+
import com.oracle.graal.python.builtins.objects.cext.capi.CExtNodesFactory.PyErrOccurredNodeGen;
9091
import com.oracle.graal.python.builtins.objects.cext.capi.CExtNodesFactory.ResolvePointerNodeGen;
9192
import com.oracle.graal.python.builtins.objects.cext.capi.ExternalFunctionNodes.DefaultCheckFunctionResultNode;
9293
import com.oracle.graal.python.builtins.objects.cext.capi.ExternalFunctionNodes.PExternalFunctionWrapper;
@@ -1068,7 +1069,7 @@ public final PException getCurrentExceptionForReraise(Node inliningTarget, Pytho
10681069
}
10691070

10701071
@Specialization
1071-
static void doGeneric(Node inliningTarget, PythonThreadState threadState,
1072+
static void doGeneric(PythonThreadState threadState,
10721073
@Cached(inline = false) CStructAccess.WritePointerNode writePointerNode) {
10731074
threadState.clearCurrentException();
10741075
PThreadState nativeWrapper = threadState.getNativeWrapper();
@@ -1079,6 +1080,29 @@ static void doGeneric(Node inliningTarget, PythonThreadState threadState,
10791080
}
10801081
}
10811082

1083+
@GenerateInline
1084+
@GenerateCached(false)
1085+
@GenerateUncached
1086+
public abstract static class PyErrOccurredNode extends Node {
1087+
1088+
public static Object executeUncached(PythonThreadState threadState) {
1089+
return PyErrOccurredNodeGen.getUncached().execute(null, threadState);
1090+
}
1091+
1092+
public abstract Object execute(Node inliningTarget, PythonThreadState threadState);
1093+
1094+
@Specialization
1095+
static Object doGeneric(Node inliningTarget, PythonThreadState threadState,
1096+
@Cached GetClassNode getClassNode) {
1097+
PException currentException = threadState.getCurrentException();
1098+
if (currentException != null) {
1099+
// getClassNode acts as a branch profile
1100+
return getClassNode.execute(inliningTarget, currentException.getUnreifiedException());
1101+
}
1102+
return null;
1103+
}
1104+
}
1105+
10821106
@GenerateUncached
10831107
@GenerateCached
10841108
@GenerateInline(false)

0 commit comments

Comments
 (0)