Skip to content

Commit c3d76b6

Browse files
committed
Remove PythonBuiltinBaseNode#getConstructAndRaiseNode()
1 parent 276c3c5 commit c3d76b6

File tree

9 files changed

+70
-66
lines changed

9 files changed

+70
-66
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/GraalHPyUniversalModuleBuiltins.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@
6161
import com.oracle.graal.python.nodes.ErrorMessages;
6262
import com.oracle.graal.python.nodes.SpecialAttributeNames;
6363
import com.oracle.graal.python.nodes.attributes.WriteAttributeToObjectNode;
64+
import com.oracle.graal.python.nodes.PConstructAndRaiseNode;
65+
import com.oracle.graal.python.nodes.PRaiseNode;
6466
import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
6567
import com.oracle.graal.python.nodes.function.builtins.PythonClinicBuiltinNode;
6668
import com.oracle.graal.python.nodes.function.builtins.clinic.ArgumentClinicProvider;
@@ -72,11 +74,13 @@
7274
import com.oracle.graal.python.runtime.exception.PException;
7375
import com.oracle.graal.python.util.PythonUtils;
7476
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
77+
import com.oracle.truffle.api.dsl.Bind;
7578
import com.oracle.truffle.api.dsl.Cached;
7679
import com.oracle.truffle.api.dsl.GenerateNodeFactory;
7780
import com.oracle.truffle.api.dsl.NodeFactory;
7881
import com.oracle.truffle.api.dsl.Specialization;
7982
import com.oracle.truffle.api.frame.VirtualFrame;
83+
import com.oracle.truffle.api.nodes.Node;
8084
import com.oracle.truffle.api.strings.TruffleString;
8185

8286
@CoreFunctions(defineModule = GraalHPyUniversalModuleBuiltins.J_HPY_UNIVERSAL)
@@ -113,7 +117,9 @@ protected ArgumentClinicProvider getArgumentClinic() {
113117

114118
@Specialization
115119
Object doGeneric(VirtualFrame frame, TruffleString name, TruffleString path, Object spec, boolean debug, int mode,
116-
@Cached TruffleString.EqualNode eqNode) {
120+
@Bind("this") Node inliningTarget,
121+
@Cached TruffleString.EqualNode eqNode,
122+
@Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode) {
117123
PythonContext context = getContext();
118124
PythonLanguage language = getLanguage();
119125
Object state = IndirectCallContext.enter(frame, language, context, this);
@@ -125,11 +131,11 @@ Object doGeneric(VirtualFrame frame, TruffleString name, TruffleString path, Obj
125131
}
126132
return GraalHPyContext.loadHPyModule(this, context, name, path, spec, hmode);
127133
} catch (ApiInitException ie) {
128-
throw ie.reraise(getConstructAndRaiseNode(), frame);
134+
throw ie.reraise(frame, inliningTarget, constructAndRaiseNode);
129135
} catch (ImportException ie) {
130-
throw ie.reraise(getConstructAndRaiseNode(), frame);
136+
throw ie.reraise(frame, inliningTarget, constructAndRaiseNode);
131137
} catch (IOException e) {
132-
throw getConstructAndRaiseNode().raiseOSError(frame, e, eqNode);
138+
throw constructAndRaiseNode.get(inliningTarget).raiseOSError(frame, e, eqNode);
133139
} finally {
134140
IndirectCallContext.exit(frame, language, context, state);
135141
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ImpModuleBuiltins.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@
100100
import com.oracle.graal.python.lib.PyObjectLookupAttr;
101101
import com.oracle.graal.python.lib.PyObjectStrAsTruffleStringNode;
102102
import com.oracle.graal.python.nodes.ErrorMessages;
103+
import com.oracle.graal.python.nodes.PConstructAndRaiseNode;
103104
import com.oracle.graal.python.nodes.PGuards;
104105
import com.oracle.graal.python.nodes.PRaiseNode;
105106
import com.oracle.graal.python.nodes.attributes.ReadAttributeFromDynamicObjectNode;
@@ -289,7 +290,8 @@ Object run(VirtualFrame frame, PythonObject moduleSpec, @SuppressWarnings("unuse
289290
@Cached ReadAttributeFromDynamicObjectNode readNameNode,
290291
@Cached ReadAttributeFromDynamicObjectNode readOriginNode,
291292
@Cached CastToTruffleStringNode castToTruffleStringNode,
292-
@Cached TruffleString.EqualNode eqNode) {
293+
@Cached TruffleString.EqualNode eqNode,
294+
@Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode) {
293295
TruffleString name = castToTruffleStringNode.execute(inliningTarget, readNameNode.execute(moduleSpec, T_NAME));
294296
TruffleString path = castToTruffleStringNode.execute(inliningTarget, readOriginNode.execute(moduleSpec, T_ORIGIN));
295297

@@ -299,11 +301,11 @@ Object run(VirtualFrame frame, PythonObject moduleSpec, @SuppressWarnings("unuse
299301
try {
300302
return run(context, new ModuleSpec(name, path, moduleSpec));
301303
} catch (ApiInitException ie) {
302-
throw ie.reraise(getConstructAndRaiseNode(), frame);
304+
throw ie.reraise(frame, inliningTarget, constructAndRaiseNode);
303305
} catch (ImportException ie) {
304-
throw ie.reraise(getConstructAndRaiseNode(), frame);
306+
throw ie.reraise(frame, inliningTarget, constructAndRaiseNode);
305307
} catch (IOException e) {
306-
throw getConstructAndRaiseNode().raiseOSError(frame, e, eqNode);
308+
throw constructAndRaiseNode.get(inliningTarget).raiseOSError(frame, e, eqNode);
307309
} finally {
308310
IndirectCallContext.exit(frame, language, context, state);
309311
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/SocketModuleBuiltins.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -611,7 +611,8 @@ Object getAddrInfo(VirtualFrame frame, Object hostObject, Object portObject, int
611611
@Cached GilNode gil,
612612
@Cached SocketNodes.MakeSockAddrNode makeSockAddrNode,
613613
@Cached SequenceStorageNodes.AppendNode appendNode,
614-
@Cached TruffleString.FromLongNode fromLongNode) {
614+
@Cached TruffleString.FromLongNode fromLongNode,
615+
@Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode) {
615616
Object host = null;
616617
if (hostObject != PNone.NONE) {
617618
host = posixLib.createPathFromString(getPosixSupport(), idna.execute(frame, hostObject));
@@ -643,7 +644,7 @@ Object getAddrInfo(VirtualFrame frame, Object hostObject, Object portObject, int
643644
gil.acquire();
644645
}
645646
} catch (GetAddrInfoException e) {
646-
throw getConstructAndRaiseNode().executeWithArgsOnly(frame, SocketGAIError, new Object[]{e.getErrorCode(), e.getMessageAsTruffleString()});
647+
throw constructAndRaiseNode.get(inliningTarget).executeWithArgsOnly(frame, SocketGAIError, new Object[]{e.getErrorCode(), e.getMessageAsTruffleString()});
647648
}
648649
try {
649650
SequenceStorage storage = new ObjectSequenceStorage(5);

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ctypes/CtypesModuleBuiltins.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -288,9 +288,9 @@ public void postInitialize(Python3Core core) {
288288
handle = new DLHandler(cApiContext.getLLVMLibrary(), 0, J_EMPTY_STRING, true);
289289
setCtypeLLVMHelpers(this, handle);
290290
} catch (ApiInitException e) {
291-
throw e.reraise(PConstructAndRaiseNode.getUncached(), null);
291+
throw e.reraise(null, null, PConstructAndRaiseNode.Lazy.getUncached());
292292
} catch (ImportException e) {
293-
throw e.reraise(PConstructAndRaiseNode.getUncached(), null);
293+
throw e.reraise(null, null, PConstructAndRaiseNode.Lazy.getUncached());
294294
} catch (IOException e) {
295295
throw PConstructAndRaiseNode.getUncached().raiseOSError(null, e, EqualNode.getUncached());
296296
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/common/LoadCExtException.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
import com.oracle.graal.python.nodes.PConstructAndRaiseNode;
4646
import com.oracle.graal.python.runtime.exception.PException;
4747
import com.oracle.truffle.api.frame.VirtualFrame;
48+
import com.oracle.truffle.api.nodes.Node;
4849
import com.oracle.truffle.api.strings.TruffleString;
4950

5051
public abstract class LoadCExtException extends Exception {
@@ -84,11 +85,11 @@ public ApiInitException(PException cause, TruffleString name, TruffleString form
8485
super(cause, name, formatString, formatArgs);
8586
}
8687

87-
public PException reraise(PConstructAndRaiseNode raiseNode, VirtualFrame frame) {
88+
public PException reraise(VirtualFrame frame, Node inliningTarget, PConstructAndRaiseNode.Lazy raiseNode) {
8889
if (cause != null) {
8990
throw cause.getExceptionForReraise(false);
9091
}
91-
throw raiseNode.executeWithFmtMessageAndArgs(frame, SystemError, formatString, formatArgs, null);
92+
throw raiseNode.get(inliningTarget).executeWithFmtMessageAndArgs(frame, SystemError, formatString, formatArgs, null);
9293
}
9394
}
9495

@@ -101,11 +102,11 @@ public ImportException(PException cause, TruffleString name, TruffleString path,
101102
this.path = path;
102103
}
103104

104-
public PException reraise(PConstructAndRaiseNode raiseNode, VirtualFrame frame) {
105+
public PException reraise(VirtualFrame frame, Node inliningTarget, PConstructAndRaiseNode.Lazy raiseNode) {
105106
if (cause != null) {
106-
throw raiseNode.raiseImportErrorWithCause(frame, cause.getEscapedException(), name, path, formatString, formatArgs);
107+
throw raiseNode.get(inliningTarget).raiseImportErrorWithCause(frame, cause.getEscapedException(), name, path, formatString, formatArgs);
107108
}
108-
throw raiseNode.raiseImportError(frame, name, path, formatString, formatArgs);
109+
throw raiseNode.get(inliningTarget).raiseImportError(frame, name, path, formatString, formatArgs);
109110
}
110111
}
111112
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/socket/SocketBuiltins.java

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ Object accept(VirtualFrame frame, PSocket self,
287287
checkSelectable(this, self);
288288

289289
try {
290-
PosixSupportLibrary.AcceptResult acceptResult = SocketUtils.callSocketFunctionWithRetry(frame, getConstructAndRaiseNode(), posixLib, getPosixSupport(), gil, self,
290+
PosixSupportLibrary.AcceptResult acceptResult = SocketUtils.callSocketFunctionWithRetry(frame, inliningTarget, constructAndRaiseNode, posixLib, getPosixSupport(), gil, self,
291291
() -> posixLib.accept(getPosixSupport(), self.getFd()),
292292
false, false);
293293
try {
@@ -387,15 +387,15 @@ Object connect(VirtualFrame frame, PSocket self, Object address,
387387
auditNode.audit(inliningTarget, "socket.connect", self, address);
388388

389389
try {
390-
doConnect(frame, getConstructAndRaiseNode(), posixLib, getPosixSupport(), gil, self, connectAddr);
390+
doConnect(frame, inliningTarget, constructAndRaiseNode, posixLib, getPosixSupport(), gil, self, connectAddr);
391391
} catch (PosixException e) {
392392
throw constructAndRaiseNode.get(inliningTarget).raiseOSErrorFromPosixException(frame, e);
393393
}
394394
return PNone.NONE;
395395
}
396396

397-
static void doConnect(Frame frame, PConstructAndRaiseNode constructAndRaiseNode, PosixSupportLibrary posixLib, Object posixSupport, GilNode gil, PSocket self, UniversalSockAddr connectAddr)
398-
throws PosixException {
397+
static void doConnect(Frame frame, Node inliningTarget, PConstructAndRaiseNode.Lazy constructAndRaiseNode, PosixSupportLibrary posixLib, Object posixSupport, GilNode gil, PSocket self,
398+
UniversalSockAddr connectAddr) throws PosixException {
399399
try {
400400
gil.release(true);
401401
try {
@@ -412,7 +412,7 @@ static void doConnect(Frame frame, PConstructAndRaiseNode constructAndRaiseNode,
412412
waitConnect = self.getTimeoutNs() > 0 && e.getErrorCode() == EINPROGRESS.getNumber() && isSelectable(self);
413413
}
414414
if (waitConnect) {
415-
SocketUtils.callSocketFunctionWithRetry(frame, constructAndRaiseNode, posixLib, posixSupport, gil, self,
415+
SocketUtils.callSocketFunctionWithRetry(frame, inliningTarget, constructAndRaiseNode, posixLib, posixSupport, gil, self,
416416
() -> {
417417
byte[] tmp = new byte[4];
418418
posixLib.getsockopt(posixSupport, self.getFd(), SOL_SOCKET.value, SO_ERROR.value, tmp, tmp.length);
@@ -440,13 +440,14 @@ Object connectEx(VirtualFrame frame, PSocket self, Object address,
440440
@Bind("this") Node inliningTarget,
441441
@Cached SocketNodes.GetSockAddrArgNode getSockAddrArgNode,
442442
@Cached GilNode gil,
443-
@Cached SysModuleBuiltins.AuditNode auditNode) {
443+
@Cached SysModuleBuiltins.AuditNode auditNode,
444+
@Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode) {
444445
UniversalSockAddr connectAddr = getSockAddrArgNode.execute(frame, self, address, "connect_ex");
445446

446447
auditNode.audit(inliningTarget, "socket.connect", self, address); // sic! connect
447448

448449
try {
449-
ConnectNode.doConnect(frame, getConstructAndRaiseNode(), posixLib, getPosixSupport(), gil, self, connectAddr);
450+
ConnectNode.doConnect(frame, inliningTarget, constructAndRaiseNode, posixLib, getPosixSupport(), gil, self, connectAddr);
450451
} catch (PosixException e) {
451452
return e.getErrorCode();
452453
}
@@ -592,7 +593,7 @@ Object recv(VirtualFrame frame, PSocket socket, int recvlen, int flags,
592593
}
593594

594595
try {
595-
int outlen = SocketUtils.callSocketFunctionWithRetry(frame, getConstructAndRaiseNode(), posixLib, getPosixSupport(), gil, socket,
596+
int outlen = SocketUtils.callSocketFunctionWithRetry(frame, inliningTarget, constructAndRaiseNode, posixLib, getPosixSupport(), gil, socket,
596597
() -> posixLib.recv(getPosixSupport(), socket.getFd(), bytes, 0, bytes.length, flags),
597598
false, false);
598599
if (outlen == 0) {
@@ -637,7 +638,7 @@ Object recvFrom(VirtualFrame frame, PSocket socket, int recvlen, int flags,
637638
}
638639

639640
try {
640-
RecvfromResult result = SocketUtils.callSocketFunctionWithRetry(frame, getConstructAndRaiseNode(), posixLib, getPosixSupport(), gil, socket,
641+
RecvfromResult result = SocketUtils.callSocketFunctionWithRetry(frame, inliningTarget, constructAndRaiseNode, posixLib, getPosixSupport(), gil, socket,
641642
() -> posixLib.recvfrom(getPosixSupport(), socket.getFd(), bytes, 0, bytes.length, flags),
642643
false, false);
643644
PBytes resultBytes;
@@ -704,7 +705,7 @@ Object recvInto(VirtualFrame frame, PSocket socket, Object bufferObj, int recvle
704705

705706
final int len = recvlen;
706707
try {
707-
int outlen = SocketUtils.callSocketFunctionWithRetry(frame, getConstructAndRaiseNode(), posixLib, getPosixSupport(), gil, socket,
708+
int outlen = SocketUtils.callSocketFunctionWithRetry(frame, inliningTarget, constructAndRaiseNode, posixLib, getPosixSupport(), gil, socket,
708709
() -> posixLib.recv(getPosixSupport(), socket.getFd(), bytes, 0, len, flags),
709710
false, false);
710711
if (!directWrite) {
@@ -770,7 +771,7 @@ Object recvFromInto(VirtualFrame frame, PSocket socket, Object bufferObj, int re
770771
}
771772

772773
try {
773-
RecvfromResult result = SocketUtils.callSocketFunctionWithRetry(frame, getConstructAndRaiseNode(), posixLib, getPosixSupport(), gil, socket,
774+
RecvfromResult result = SocketUtils.callSocketFunctionWithRetry(frame, inliningTarget, constructAndRaiseNode, posixLib, getPosixSupport(), gil, socket,
774775
() -> posixLib.recvfrom(getPosixSupport(), socket.getFd(), bytes, 0, bytes.length, flags),
775776
false, false);
776777
if (!directWrite) {
@@ -813,7 +814,7 @@ int send(VirtualFrame frame, PSocket socket, Object bufferObj, int flags,
813814
byte[] bytes = bufferLib.getInternalOrCopiedByteArray(buffer);
814815

815816
try {
816-
return SocketUtils.callSocketFunctionWithRetry(frame, getConstructAndRaiseNode(), posixLib, getPosixSupport(), gil, socket,
817+
return SocketUtils.callSocketFunctionWithRetry(frame, inliningTarget, constructAndRaiseNode, posixLib, getPosixSupport(), gil, socket,
817818
() -> posixLib.send(getPosixSupport(), socket.getFd(), bytes, 0, len, flags),
818819
true, false);
819820
} catch (PosixException e) {
@@ -862,7 +863,7 @@ Object sendAll(VirtualFrame frame, PSocket socket, Object bufferObj, int flags,
862863
try {
863864
final int offset1 = offset;
864865
final int len1 = len;
865-
int outlen = SocketUtils.callSocketFunctionWithRetry(frame, getConstructAndRaiseNode(), posixLib, getPosixSupport(), gil, socket,
866+
int outlen = SocketUtils.callSocketFunctionWithRetry(frame, inliningTarget, constructAndRaiseNode, posixLib, getPosixSupport(), gil, socket,
866867
() -> posixLib.send(getPosixSupport(), socket.getFd(), bytes, offset1, len1, flags),
867868
true, false, timeoutHelper);
868869
offset += outlen;
@@ -926,7 +927,7 @@ Object sendTo(VirtualFrame frame, PSocket socket, Object bufferObj, Object flags
926927
byte[] bytes = bufferLib.getInternalOrCopiedByteArray(buffer);
927928

928929
try {
929-
return SocketUtils.callSocketFunctionWithRetry(frame, getConstructAndRaiseNode(), posixLib, getPosixSupport(), gil, socket,
930+
return SocketUtils.callSocketFunctionWithRetry(frame, inliningTarget, constructAndRaiseNode, posixLib, getPosixSupport(), gil, socket,
930931
() -> posixLib.sendto(getPosixSupport(), socket.getFd(), bytes, 0, len, flags, addr),
931932
true, false);
932933
} catch (PosixException e) {

0 commit comments

Comments
 (0)