Skip to content

Commit 1279450

Browse files
committed
Remove ArgumentCastNodeWithRaise
1 parent b6e5c7a commit 1279450

File tree

14 files changed

+206
-214
lines changed

14 files changed

+206
-214
lines changed

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

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@
7171
import com.oracle.graal.python.nodes.function.builtins.PythonClinicBuiltinNode;
7272
import com.oracle.graal.python.nodes.function.builtins.PythonTernaryClinicBuiltinNode;
7373
import com.oracle.graal.python.nodes.function.builtins.PythonUnaryClinicBuiltinNode;
74-
import com.oracle.graal.python.nodes.function.builtins.clinic.ArgumentCastNode.ArgumentCastNodeWithRaise;
74+
import com.oracle.graal.python.nodes.function.builtins.clinic.ArgumentCastNode;
7575
import com.oracle.graal.python.nodes.function.builtins.clinic.ArgumentClinicProvider;
7676
import com.oracle.graal.python.nodes.util.CastToTruffleStringNode;
7777
import com.oracle.graal.python.runtime.IndirectCallData;
@@ -104,7 +104,7 @@ protected List<? extends NodeFactory<? extends PythonBuiltinBaseNode>> getNodeFa
104104
return BinasciiModuleBuiltinsFactory.getFactories();
105105
}
106106

107-
abstract static class AsciiBufferConverter extends ArgumentCastNodeWithRaise {
107+
abstract static class AsciiBufferConverter extends ArgumentCastNode {
108108
@Specialization(guards = "acquireLib.hasBuffer(value)", limit = "getCallSiteInlineCacheMaxDepth()")
109109
Object doObject(VirtualFrame frame, Object value,
110110
@Cached("createFor(this)") IndirectCallData indirectCallData,
@@ -143,35 +143,37 @@ byte readByte(int byteOffset,
143143
}
144144

145145
@Specialization(guards = "isAscii(value, getCodeRangeNode)")
146-
Object asciiString(TruffleString value,
146+
static Object asciiString(TruffleString value,
147147
@Shared("getCodeRange") @Cached @SuppressWarnings("unused") TruffleString.GetCodeRangeNode getCodeRangeNode) {
148148
return new AsciiStringBuffer(value);
149149
}
150150

151151
@Specialization(guards = "!isAscii(value, getCodeRangeNode)")
152-
Object nonAsciiString(@SuppressWarnings("unused") TruffleString value,
153-
@Shared("getCodeRange") @Cached @SuppressWarnings("unused") TruffleString.GetCodeRangeNode getCodeRangeNode) {
154-
throw raise(ValueError, ErrorMessages.STRING_ARG_SHOULD_CONTAIN_ONLY_ASCII);
152+
static Object nonAsciiString(@SuppressWarnings("unused") TruffleString value,
153+
@Shared("getCodeRange") @Cached @SuppressWarnings("unused") TruffleString.GetCodeRangeNode getCodeRangeNode,
154+
@Shared @Cached PRaiseNode raiseNode) {
155+
throw raiseNode.raise(ValueError, ErrorMessages.STRING_ARG_SHOULD_CONTAIN_ONLY_ASCII);
155156
}
156157

157158
@Specialization
158-
@SuppressWarnings("truffle-static-method")
159-
Object string(PString value,
159+
static Object string(PString value,
160160
@Bind("this") Node inliningTarget,
161161
@Cached CastToTruffleStringNode cast,
162162
@Shared("getCodeRange") @Cached @SuppressWarnings("unused") TruffleString.GetCodeRangeNode getCodeRangeNode,
163-
@Cached InlinedConditionProfile asciiProfile) {
163+
@Cached InlinedConditionProfile asciiProfile,
164+
@Cached PRaiseNode.Lazy raiseNode) {
164165
TruffleString ts = cast.execute(inliningTarget, value);
165166
if (asciiProfile.profile(inliningTarget, isAscii(ts, getCodeRangeNode))) {
166167
return asciiString(ts, getCodeRangeNode);
167168
} else {
168-
return nonAsciiString(ts, getCodeRangeNode);
169+
return nonAsciiString(ts, getCodeRangeNode, raiseNode.get(inliningTarget));
169170
}
170171
}
171172

172173
@Fallback
173-
Object error(@SuppressWarnings("unused") Object value) {
174-
throw raise(TypeError, ErrorMessages.ARG_SHOULD_BE_BYTES_BUFFER_OR_ASCII_NOT_P, value);
174+
static Object error(@SuppressWarnings("unused") Object value,
175+
@Shared @Cached PRaiseNode raiseNode) {
176+
throw raiseNode.raise(TypeError, ErrorMessages.ARG_SHOULD_BE_BYTES_BUFFER_OR_ASCII_NOT_P, value);
175177
}
176178

177179
@ClinicConverterFactory

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

Lines changed: 81 additions & 68 deletions
Large diffs are not rendered by default.

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

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@
7272
import com.oracle.graal.python.nodes.builtins.ListNodes.FastConstructListNode;
7373
import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
7474
import com.oracle.graal.python.nodes.function.builtins.PythonClinicBuiltinNode;
75-
import com.oracle.graal.python.nodes.function.builtins.clinic.ArgumentCastNode.ArgumentCastNodeWithRaise;
75+
import com.oracle.graal.python.nodes.function.builtins.clinic.ArgumentCastNode;
7676
import com.oracle.graal.python.nodes.function.builtins.clinic.ArgumentClinicProvider;
7777
import com.oracle.graal.python.nodes.object.BuiltinClassProfiles.IsBuiltinObjectProfile;
7878
import com.oracle.graal.python.nodes.util.CannotCastException;
@@ -110,7 +110,7 @@ protected List<? extends NodeFactory<? extends PythonBuiltinBaseNode>> getNodeFa
110110
* Helper converter which iterates the argv argument and converts each element to the opaque
111111
* path representation used by {@link PosixSupportLibrary}.
112112
*/
113-
abstract static class ProcessArgsConversionNode extends ArgumentCastNodeWithRaise {
113+
abstract static class ProcessArgsConversionNode extends ArgumentCastNode {
114114
@Specialization
115115
static Object[] doNone(@SuppressWarnings("unused") PNone processArgs) {
116116
// CPython passes NULL to execve() in this case. man execve explicitly discourages this,
@@ -119,20 +119,20 @@ static Object[] doNone(@SuppressWarnings("unused") PNone processArgs) {
119119
}
120120

121121
@Specialization
122-
@SuppressWarnings("truffle-static-method")
123-
Object[] doSequence(VirtualFrame frame, Object processArgs,
122+
static Object[] doSequence(VirtualFrame frame, Object processArgs,
124123
@Bind("this") Node inliningTarget,
125124
@Cached FastConstructListNode fastConstructListNode,
126125
@Cached GetSequenceStorageNode getSequenceStorageNode,
127126
@Cached IsBuiltinObjectProfile isBuiltinClassProfile,
128127
@Cached ObjectToOpaquePathNode objectToOpaquePathNode,
129-
@Cached("createNotNormalized()") GetItemNode getItemNode) {
128+
@Cached("createNotNormalized()") GetItemNode getItemNode,
129+
@Cached PRaiseNode.Lazy raiseNode) {
130130
PSequence argsSequence;
131131
try {
132132
argsSequence = fastConstructListNode.execute(frame, inliningTarget, processArgs);
133133
} catch (PException e) {
134134
e.expect(inliningTarget, TypeError, isBuiltinClassProfile);
135-
throw raise(TypeError, ErrorMessages.S_MUST_BE_S, "argv", "a tuple");
135+
throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.S_MUST_BE_S, "argv", "a tuple");
136136
}
137137

138138
SequenceStorage argsStorage = getSequenceStorageNode.execute(inliningTarget, argsSequence);
@@ -142,7 +142,7 @@ Object[] doSequence(VirtualFrame frame, Object processArgs,
142142
SequenceStorage newStorage = getSequenceStorageNode.execute(inliningTarget, argsSequence);
143143
if (newStorage != argsStorage || newStorage.length() != len) {
144144
// TODO write a test for this
145-
throw raise(RuntimeError, ErrorMessages.ARGS_CHANGED_DURING_ITERATION);
145+
throw raiseNode.get(inliningTarget).raise(RuntimeError, ErrorMessages.ARGS_CHANGED_DURING_ITERATION);
146146
}
147147
Object o = getItemNode.execute(argsStorage, i);
148148
argsArray[i] = objectToOpaquePathNode.execute(frame, inliningTarget, o, false);
@@ -157,29 +157,29 @@ static ProcessArgsConversionNode create() {
157157
}
158158
}
159159

160-
abstract static class EnvConversionNode extends ArgumentCastNodeWithRaise {
160+
abstract static class EnvConversionNode extends ArgumentCastNode {
161161
@Specialization
162162
static Object doNone(@SuppressWarnings("unused") PNone env) {
163163
return null;
164164
}
165165

166166
@Specialization(guards = "!isPNone(env)")
167-
@SuppressWarnings("truffle-static-method")
168-
Object doSequence(VirtualFrame frame, Object env,
167+
static Object doSequence(VirtualFrame frame, Object env,
169168
@Bind("this") Node inliningTarget,
170169
@Cached PyObjectSizeNode sizeNode,
171170
@Cached ToBytesNode toBytesNode,
172171
@Cached PyObjectGetItem getItem,
173-
@CachedLibrary("getContext().getPosixSupport()") PosixSupportLibrary posixLib) {
172+
@CachedLibrary("getContext().getPosixSupport()") PosixSupportLibrary posixLib,
173+
@Cached PRaiseNode.Lazy raiseNode) {
174174
// TODO unlike CPython, this accepts a dict (if the keys are integers (0, 1, ..., len-1)
175175
int length = sizeNode.execute(frame, inliningTarget, env);
176176
Object[] result = new Object[length];
177177
for (int i = 0; i < length; ++i) {
178178
Object o = getItem.execute(frame, inliningTarget, env, i);
179179
byte[] bytes = toBytesNode.execute(frame, o);
180-
Object o1 = posixLib.createPathFromBytes(getContext().getPosixSupport(), bytes);
180+
Object o1 = posixLib.createPathFromBytes(PythonContext.get(inliningTarget).getPosixSupport(), bytes);
181181
if (o1 == null) {
182-
throw raise(ValueError, ErrorMessages.EMBEDDED_NULL_BYTE);
182+
throw raiseNode.get(inliningTarget).raise(ValueError, ErrorMessages.EMBEDDED_NULL_BYTE);
183183
}
184184
result[i] = o1;
185185
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/io/IONodes.java

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
import com.oracle.truffle.api.CompilerDirectives;
7272
import com.oracle.truffle.api.dsl.Bind;
7373
import com.oracle.truffle.api.dsl.Cached;
74+
import com.oracle.truffle.api.dsl.Cached.Shared;
7475
import com.oracle.truffle.api.dsl.Fallback;
7576
import com.oracle.truffle.api.dsl.GenerateCached;
7677
import com.oracle.truffle.api.dsl.GenerateInline;
@@ -80,7 +81,6 @@
8081
import com.oracle.truffle.api.frame.VirtualFrame;
8182
import com.oracle.truffle.api.nodes.Node;
8283
import com.oracle.truffle.api.profiles.InlinedBranchProfile;
83-
import com.oracle.truffle.api.profiles.InlinedConditionProfile;
8484
import com.oracle.truffle.api.strings.TruffleString;
8585
import com.oracle.truffle.api.strings.TruffleStringIterator;
8686

@@ -345,7 +345,7 @@ public static boolean isBinary(IONodes.IOMode mode) {
345345
}
346346
}
347347

348-
public abstract static class CreateIOModeNode extends ArgumentCastNode.ArgumentCastNodeWithRaise {
348+
public abstract static class CreateIOModeNode extends ArgumentCastNode {
349349

350350
protected final boolean warnUniversal;
351351

@@ -376,21 +376,22 @@ IOMode generic(VirtualFrame frame, Object modeObj,
376376
@Cached InlinedBranchProfile errProfile1,
377377
@Cached InlinedBranchProfile errProfile2,
378378
@Cached InlinedBranchProfile errProfile3,
379-
@Cached WarningsModuleBuiltins.WarnNode warnNode) {
379+
@Cached WarningsModuleBuiltins.WarnNode warnNode,
380+
@Cached PRaiseNode.Lazy raiseNode) {
380381
TruffleString mode;
381382
try {
382383
mode = toString.execute(inliningTarget, modeObj);
383384
} catch (CannotCastException e) {
384-
throw raise(TypeError, ErrorMessages.BAD_ARG_TYPE_FOR_BUILTIN_OP);
385+
throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.BAD_ARG_TYPE_FOR_BUILTIN_OP);
385386
}
386387
IOMode m = new IOMode(mode, createCodePointIteratorNode, nextNode);
387388
if (m.hasNil) {
388389
errProfile1.enter(inliningTarget);
389-
throw raise(ValueError, EMBEDDED_NULL_CHARACTER);
390+
throw raiseNode.get(inliningTarget).raise(ValueError, EMBEDDED_NULL_CHARACTER);
390391
}
391392
if (m.isInvalid) {
392393
errProfile2.enter(inliningTarget);
393-
throw raise(ValueError, INVALID_MODE_S, mode);
394+
throw raiseNode.get(inliningTarget).raise(ValueError, INVALID_MODE_S, mode);
394395
}
395396
if (warnUniversal && m.universal) {
396397
errProfile3.enter(inliningTarget);
@@ -407,7 +408,7 @@ public static CreateIOModeNode create(boolean warnUniversal) {
407408
}
408409

409410
@ImportStatic(PGuards.class)
410-
public abstract static class CastOpenNameNode extends ArgumentCastNode.ArgumentCastNodeWithRaise {
411+
public abstract static class CastOpenNameNode extends ArgumentCastNode {
411412

412413
public static final int MAX = Integer.MAX_VALUE;
413414

@@ -425,17 +426,16 @@ static int fast(long fd) {
425426
}
426427

427428
@Specialization(guards = "!isInteger(nameobj)")
428-
@SuppressWarnings("truffle-static-method") // raise
429-
Object generic(VirtualFrame frame, Object nameobj,
429+
static Object generic(VirtualFrame frame, Object nameobj,
430430
@Bind("this") Node inliningTarget,
431431
@Cached BytesNodes.DecodeUTF8FSPathNode fspath,
432-
@Cached InlinedConditionProfile errorProfile,
433432
@Cached PyIndexCheckNode indexCheckNode,
434-
@Cached PyNumberAsSizeNode asSizeNode) {
433+
@Cached PyNumberAsSizeNode asSizeNode,
434+
@Cached PRaiseNode.Lazy raiseNode) {
435435
if (indexCheckNode.execute(inliningTarget, nameobj)) {
436436
int fd = asSizeNode.executeExact(frame, inliningTarget, nameobj);
437-
if (errorProfile.profile(inliningTarget, fd < 0)) {
438-
err(fd);
437+
if (fd < 0) {
438+
err(fd, raiseNode.get(inliningTarget));
439439
}
440440
return fd;
441441
} else {
@@ -444,13 +444,15 @@ Object generic(VirtualFrame frame, Object nameobj,
444444
}
445445

446446
@Specialization(guards = "fd < 0")
447-
int err(int fd) {
448-
throw raise(ValueError, OPENER_RETURNED_D, fd);
447+
static int err(int fd,
448+
@Shared @Cached PRaiseNode raiseNode) {
449+
throw raiseNode.raise(ValueError, OPENER_RETURNED_D, fd);
449450
}
450451

451452
@Specialization(guards = "fd < 0")
452-
int err(long fd) {
453-
throw raise(ValueError, OPENER_RETURNED_D, fd);
453+
static int err(long fd,
454+
@Shared @Cached PRaiseNode raiseNode) {
455+
throw raiseNode.raise(ValueError, OPENER_RETURNED_D, fd);
454456
}
455457

456458
@ClinicConverterFactory

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/lzma/LZMACompressorBuiltins.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ static PNone error(LZMACompressor self,
240240
}
241241
}
242242

243-
public abstract static class ExpectUINT32Node extends ArgumentCastNode.ArgumentCastNodeWithRaise {
243+
public abstract static class ExpectUINT32Node extends ArgumentCastNode {
244244
private final Object defaultValue;
245245

246246
protected ExpectUINT32Node(Object defaultValue) {

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/zlib/ZLibModuleBuiltins.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ private static TruffleString asString(Object o) {
223223
}
224224

225225
@ImportStatic(MathGuards.class)
226-
public abstract static class ExpectIntNode extends ArgumentCastNode.ArgumentCastNodeWithRaise {
226+
public abstract static class ExpectIntNode extends ArgumentCastNode {
227227
private final Object defaultValue;
228228

229229
protected ExpectIntNode(Object defaultValue) {
@@ -280,7 +280,7 @@ public static ExpectIntNode create(@ClinicConverterFactory.DefaultValue Object d
280280
}
281281
}
282282

283-
public abstract static class ExpectByteLikeNode extends ArgumentCastNode.ArgumentCastNodeWithRaise {
283+
public abstract static class ExpectByteLikeNode extends ArgumentCastNode {
284284
private final byte[] defaultValue;
285285

286286
protected ExpectByteLikeNode(byte[] defaultValue) {
@@ -308,8 +308,9 @@ static byte[] doMemView(VirtualFrame frame, PMemoryView bytesLike,
308308
}
309309

310310
@Fallback
311-
byte[] error(@SuppressWarnings("unused") VirtualFrame frame, Object value) {
312-
throw raise(TypeError, ErrorMessages.BYTESLIKE_OBJ_REQUIRED, value);
311+
static byte[] error(@SuppressWarnings("unused") VirtualFrame frame, Object value,
312+
@Cached PRaiseNode raiseNode) {
313+
throw raiseNode.raise(TypeError, ErrorMessages.BYTESLIKE_OBJ_REQUIRED, value);
313314
}
314315

315316
@ClinicConverterFactory

0 commit comments

Comments
 (0)