Skip to content

Commit f04d218

Browse files
committed
Resolve more DSL warnings in the io module
1 parent f6f0579 commit f04d218

13 files changed

+103
-75
lines changed

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

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@
5151
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
5252
import com.oracle.graal.python.builtins.PythonBuiltins;
5353
import com.oracle.graal.python.builtins.modules.io.BufferedIONodes.RawTellNode;
54-
import com.oracle.graal.python.builtins.modules.io.BufferedIONodesFactory.RawTellNodeGen;
5554
import com.oracle.graal.python.builtins.objects.PNone;
5655
import com.oracle.graal.python.builtins.objects.exception.OSErrorEnum;
5756
import com.oracle.graal.python.builtins.objects.exception.OsErrorBuiltins;
@@ -72,7 +71,9 @@
7271
import com.oracle.graal.python.runtime.exception.PException;
7372
import com.oracle.graal.python.runtime.object.PythonObjectFactory;
7473
import com.oracle.truffle.api.CompilerDirectives;
74+
import com.oracle.truffle.api.dsl.Bind;
7575
import com.oracle.truffle.api.dsl.Cached;
76+
import com.oracle.truffle.api.dsl.GenerateCached;
7677
import com.oracle.truffle.api.dsl.GenerateInline;
7778
import com.oracle.truffle.api.dsl.Specialization;
7879
import com.oracle.truffle.api.frame.VirtualFrame;
@@ -85,14 +86,14 @@ abstract class AbstractBufferedIOBuiltins extends PythonBuiltins {
8586

8687
public abstract static class BufferedInitNode extends PNodeWithRaise {
8788

88-
@Child private RawTellNode rawTellNode = RawTellNodeGen.create(true);
89-
9089
public abstract void execute(VirtualFrame frame, PBuffered self, int bufferSize, PythonObjectFactory factory);
9190

9291
@Specialization(guards = "bufferSize > 0")
93-
void bufferedInit(VirtualFrame frame, PBuffered self, int bufferSize, PythonObjectFactory factory) {
92+
void bufferedInit(VirtualFrame frame, PBuffered self, int bufferSize, PythonObjectFactory factory,
93+
@Bind("this") Node inliningTarget,
94+
@Cached RawTellNode rawTellNode) {
9495
init(self, bufferSize, factory);
95-
rawTellNode.execute(frame, self);
96+
rawTellNode.executeIgnoreError(frame, inliningTarget, self);
9697
}
9798

9899
@SuppressWarnings("unused")
@@ -239,6 +240,8 @@ static PException raise(Node node, Object errno, TruffleString message, int writ
239240
}
240241
}
241242

243+
@GenerateInline
244+
@GenerateCached(false)
242245
public abstract static class LazyRaiseBlockingIOError extends Node {
243246
public final RaiseBlockingIOError get(Node inliningTarget) {
244247
return execute(inliningTarget);

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ static long doit(VirtualFrame frame, PBuffered self, Object off, int whence,
264264
@Cached("create(T_SEEK)") CheckIsClosedNode checkIsClosedNode,
265265
@Cached BufferedIONodes.CheckIsSeekabledNode checkIsSeekabledNode,
266266
@Cached BufferedIONodes.AsOffNumberNode asOffNumberNode,
267-
@Cached BufferedIONodes.SeekNode seekNode) {
267+
@Cached(inline = true) BufferedIONodes.SeekNode seekNode) {
268268
checkIsClosedNode.execute(frame, self);
269269
checkIsSeekabledNode.execute(frame, self);
270270
long pos = asOffNumberNode.execute(frame, inliningTarget, off, TypeError);
@@ -291,8 +291,9 @@ Object initError(PBuffered self, @SuppressWarnings("unused") int off, @SuppressW
291291
abstract static class TellNode extends PythonUnaryWithInitErrorBuiltinNode {
292292
@Specialization(guards = "self.isOK()")
293293
static long doit(VirtualFrame frame, PBuffered self,
294+
@Bind("this") Node inliningTarget,
294295
@Cached RawTellNode rawTellNode) {
295-
long pos = rawTellNode.execute(frame, self);
296+
long pos = rawTellNode.execute(frame, inliningTarget, self);
296297
pos -= rawOffset(self);
297298
/* TODO: sanity check (pos >= 0) */
298299
return pos;
@@ -323,7 +324,7 @@ static Object doit(VirtualFrame frame, PBuffered self, Object pos,
323324
flushAndRewindUnlockedNode.execute(frame, inliningTarget, self);
324325
Object res = callMethodTruncate.execute(frame, self.getRaw(), T_TRUNCATE, pos);
325326
/* Reset cached position */
326-
rawTellNode.execute(frame, self);
327+
rawTellNode.execute(frame, inliningTarget, self);
327328
return res;
328329
} finally {
329330
EnterBufferedNode.leave(self);

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

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@
8686
import com.oracle.truffle.api.dsl.GenerateCached;
8787
import com.oracle.truffle.api.dsl.GenerateInline;
8888
import com.oracle.truffle.api.dsl.ImportStatic;
89-
import com.oracle.truffle.api.dsl.NeverDefault;
9089
import com.oracle.truffle.api.dsl.Specialization;
9190
import com.oracle.truffle.api.dsl.TypeSystemReference;
9291
import com.oracle.truffle.api.frame.VirtualFrame;
@@ -196,15 +195,18 @@ static long toLong(VirtualFrame frame, Node inliningTarget, Object number, Pytho
196195
}
197196
}
198197

199-
abstract static class RawTellNode extends PNodeWithRaise {
200-
201-
protected final boolean ignore;
198+
@GenerateInline
199+
@GenerateCached(false)
200+
abstract static class RawTellNode extends PNodeWithContext {
201+
final long executeIgnoreError(VirtualFrame frame, Node inliningTarget, PBuffered self) {
202+
return execute(frame, inliningTarget, self, true);
203+
}
202204

203-
public RawTellNode(boolean ignore) {
204-
this.ignore = ignore;
205+
final long execute(VirtualFrame frame, Node inliningTarget, PBuffered self) {
206+
return execute(frame, inliningTarget, self, false);
205207
}
206208

207-
public abstract long execute(VirtualFrame frame, PBuffered self);
209+
abstract long execute(VirtualFrame frame, Node inliningTarget, PBuffered self, boolean ignore);
208210

209211
private static long tell(VirtualFrame frame, Node inliningTarget, Object raw,
210212
PyObjectCallMethodObjArgs callMethod,
@@ -217,22 +219,21 @@ private static long tell(VirtualFrame frame, Node inliningTarget, Object raw,
217219
* implementation of cpython/Modules/_io/bufferedio.c:_buffered_raw_tell
218220
*/
219221
@Specialization(guards = "!ignore")
220-
long bufferedRawTell(VirtualFrame frame, PBuffered self,
221-
@Bind("this") Node inliningTarget,
222-
@Shared("callMethod") @Cached PyObjectCallMethodObjArgs callMethod,
222+
static long bufferedRawTell(VirtualFrame frame, Node inliningTarget, PBuffered self, @SuppressWarnings("unused") boolean ignore,
223+
@Cached PRaiseNode.Lazy lazyRaiseNode,
224+
@Shared("callMethod") @Cached(inline = false) PyObjectCallMethodObjArgs callMethod,
223225
@Shared("asOffT") @Cached AsOffNumberNode asOffNumberNode) {
224226
long n = tell(frame, inliningTarget, self.getRaw(), callMethod, asOffNumberNode);
225227
if (n < 0) {
226-
throw raise(OSError, IO_STREAM_INVALID_POS, n);
228+
throw lazyRaiseNode.get(inliningTarget).raise(OSError, IO_STREAM_INVALID_POS, n);
227229
}
228230
self.setAbsPos(n);
229231
return n;
230232
}
231233

232234
@Specialization(guards = "ignore")
233-
static long bufferedRawTellIgnoreException(VirtualFrame frame, PBuffered self,
234-
@Bind("this") Node inliningTarget,
235-
@Shared("callMethod") @Cached PyObjectCallMethodObjArgs callMethod,
235+
static long bufferedRawTellIgnoreException(VirtualFrame frame, Node inliningTarget, PBuffered self, @SuppressWarnings("unused") boolean ignore,
236+
@Shared("callMethod") @Cached(inline = false) PyObjectCallMethodObjArgs callMethod,
236237
@Shared("asOffT") @Cached AsOffNumberNode asOffNumberNode) {
237238
long n;
238239
try {
@@ -245,12 +246,6 @@ static long bufferedRawTellIgnoreException(VirtualFrame frame, PBuffered self,
245246
self.setAbsPos(n);
246247
return n;
247248
}
248-
249-
@NeverDefault
250-
public static RawTellNode create() {
251-
return BufferedIONodesFactory.RawTellNodeGen.create(false);
252-
}
253-
254249
}
255250

256251
/**
@@ -323,13 +318,14 @@ protected static void readWrite(VirtualFrame frame, Node inliningTarget, PBuffer
323318
* implementation of cpython/Modules/_io/bufferedio.c:_io__Buffered_seek_impl
324319
*/
325320
@GenerateInline
326-
@GenerateCached(false)
321+
@GenerateCached
327322
abstract static class SeekNode extends PNodeWithContext {
328323

329324
public abstract long execute(VirtualFrame frame, Node inliningTarget, PBuffered self, long off, int whence);
330325

331326
@Specialization
332-
static long seek(VirtualFrame frame, Node inliningTarget, PBuffered self, long off, int whence,
327+
static long seek(VirtualFrame frame, @SuppressWarnings("unused") Node ignored, PBuffered self, long off, int whence,
328+
@Bind("this") Node inliningTarget,
333329
@Cached EnterBufferedNode lock,
334330
@Cached BufferedWriterNodes.FlushUnlockedNode flushUnlockedNode,
335331
@Cached RawSeekNode rawSeekNode,
@@ -355,7 +351,8 @@ static long seek(VirtualFrame frame, Node inliningTarget, PBuffered self, long o
355351
* possible. Also, we needn't take the lock in this fast path. Don't know how to do
356352
* that when whence == 2, though.
357353
*/
358-
long current = self.getAbsPos() != -1 ? self.getAbsPos() : rawTellNode.execute(frame, self);
354+
long current = self.getAbsPos() != -1 ? self.getAbsPos()
355+
: rawTellNode.execute(frame, inliningTarget, self);
359356
int avail = readahead(self);
360357
if (isAvail.profile(inliningTarget, avail > 0)) {
361358
long offset = target;

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@
9999
import com.oracle.graal.python.util.PythonUtils;
100100
import com.oracle.truffle.api.dsl.Bind;
101101
import com.oracle.truffle.api.dsl.Cached;
102+
import com.oracle.truffle.api.dsl.Cached.Shared;
102103
import com.oracle.truffle.api.dsl.GenerateNodeFactory;
103104
import com.oracle.truffle.api.dsl.ImportStatic;
104105
import com.oracle.truffle.api.dsl.NodeFactory;
@@ -269,9 +270,10 @@ Object readFast(VirtualFrame frame, PBuffered self, int size) {
269270
* implementation of cpython/Modules/_io/bufferedio.c:_bufferedreader_read_generic
270271
*/
271272
@Specialization(guards = {"self.isOK()", "size > 0", "!isReadFast(self, size)"})
273+
@SuppressWarnings("truffle-static-method") // factory
272274
Object bufferedreaderReadGeneric(VirtualFrame frame, PBuffered self, int size,
273275
@Bind("this") Node inliningTarget,
274-
@Cached EnterBufferedNode lock,
276+
@Shared @Cached EnterBufferedNode lock,
275277
@Cached RawReadNode rawReadNode,
276278
@Cached FillBufferNode fillBufferNode,
277279
@Cached FlushAndRewindUnlockedNode flushAndRewindUnlockedNode) {
@@ -367,9 +369,10 @@ reads, which could block indefinitely (e.g. on a socket).
367369
* implementation of cpython/Modules/_io/bufferedio.c:_bufferedreader_read_all
368370
*/
369371
@Specialization(guards = {"self.isOK()", "isReadAll(size)"})
372+
@SuppressWarnings("truffle-static-method") // factory
370373
Object bufferedreaderReadAll(VirtualFrame frame, PBuffered self, @SuppressWarnings("unused") int size,
371374
@Bind("this") Node inliningTarget,
372-
@Cached EnterBufferedNode lock,
375+
@Shared @Cached EnterBufferedNode lock,
373376
@Cached FlushAndRewindUnlockedNode flushAndRewindUnlockedNode,
374377
@Cached("create(T_READALL)") LookupAttributeInMRONode readallAttr,
375378
@Cached InlinedConditionProfile hasReadallProfile,
@@ -470,6 +473,7 @@ protected ArgumentClinicProvider getArgumentClinic() {
470473
}
471474

472475
@Specialization(guards = "self.isOK()")
476+
@SuppressWarnings("truffle-static-method") // factory
473477
PBytes doit(VirtualFrame frame, PBuffered self, int size,
474478
@Bind("this") Node inliningTarget,
475479
@Cached EnterBufferedNode lock,

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ static Object doit(VirtualFrame frame, PBuffered self,
9494
abstract static class WriteNode extends PythonBinaryWithInitErrorClinicBuiltinNode {
9595

9696
@Specialization(guards = "self.isOK()")
97+
@SuppressWarnings("truffle-static-method") // IndirectCallNode
9798
Object write(@SuppressWarnings("unused") VirtualFrame frame, PBuffered self, Object buffer,
9899
@Bind("this") Node inliningTarget,
99100
@CachedLibrary(limit = "3") PythonBufferAccessLibrary bufferLib,

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,7 @@ Object doWrite(VirtualFrame frame, PBytesIO self, Object b,
441441
@GenerateNodeFactory
442442
abstract static class WriteLinesNode extends ClosedCheckPythonBinaryBuiltinNode {
443443
@Specialization(guards = "self.hasBuf()")
444+
@SuppressWarnings("truffle-static-method") // raise
444445
Object writeLines(VirtualFrame frame, PBytesIO self, Object lines,
445446
@Bind("this") Node inliningTarget,
446447
@Cached GetNextNode getNextNode,

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@
159159
import com.oracle.truffle.api.CompilerDirectives;
160160
import com.oracle.truffle.api.dsl.Bind;
161161
import com.oracle.truffle.api.dsl.Cached;
162+
import com.oracle.truffle.api.dsl.Cached.Exclusive;
162163
import com.oracle.truffle.api.dsl.Cached.Shared;
163164
import com.oracle.truffle.api.dsl.GenerateNodeFactory;
164165
import com.oracle.truffle.api.dsl.NodeFactory;
@@ -313,6 +314,7 @@ protected final Object getPosixSupport() {
313314
}
314315

315316
@Specialization(guards = {"!isBadMode(mode)", "!isInvalidMode(mode)"})
317+
@SuppressWarnings("truffle-static-method")// raise etc.
316318
void doInit(VirtualFrame frame, PFileIO self, Object nameobj, IONodes.IOMode mode, boolean closefd, Object opener,
317319
@Bind("this") Node inliningTarget,
318320
@CachedLibrary("getPosixSupport()") PosixSupportLibrary posixLib,
@@ -537,6 +539,7 @@ Object none(@SuppressWarnings("unused") PFileIO self, @SuppressWarnings("unused"
537539
}
538540

539541
@Specialization(guards = {"!self.isClosed()", "self.isReadable()", "size >= 0"})
542+
@SuppressWarnings("truffle-static-method") // raise
540543
Object read(VirtualFrame frame, PFileIO self, int size,
541544
@Bind("this") Node inliningTarget,
542545
@Cached PosixModuleBuiltins.ReadNode posixRead,
@@ -889,7 +892,7 @@ Object closedError(PFileIO self, Object posobj) {
889892
abstract static class CloseNode extends PythonUnaryBuiltinNode {
890893
@Specialization(guards = "!self.isCloseFD()")
891894
Object simple(VirtualFrame frame, PFileIO self,
892-
@Cached PyObjectCallMethodObjArgs callClose) {
895+
@Exclusive @Cached PyObjectCallMethodObjArgs callClose) {
893896
try {
894897
callClose.execute(frame, getContext().lookupType(PRawIOBase), T_CLOSE, self);
895898
} catch (PException e) {
@@ -903,7 +906,7 @@ Object simple(VirtualFrame frame, PFileIO self,
903906
@Specialization(guards = {"self.isCloseFD()", "!self.isFinalizing()"})
904907
Object common(VirtualFrame frame, PFileIO self,
905908
@Shared("c") @Cached PosixModuleBuiltins.CloseNode posixClose,
906-
@Shared("l") @Cached PyObjectCallMethodObjArgs callSuperClose) {
909+
@Exclusive @Shared("l") @Cached PyObjectCallMethodObjArgs callSuperClose) {
907910
try {
908911
callSuperClose.execute(frame, getContext().lookupType(PRawIOBase), T_CLOSE, self);
909912
} catch (PException e) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ final boolean checkReadable(VirtualFrame frame, Node inliningTarget, Object self
236236

237237
@Specialization
238238
static boolean doIt(VirtualFrame frame, Node inliningTarget, Object self, TruffleString method, TruffleString errorMessage,
239-
@Cached PyObjectCallMethodObjArgs callMethod,
239+
@Cached(inline = false) PyObjectCallMethodObjArgs callMethod,
240240
@Cached(inline = false) IsNode isNode,
241241
@Cached PRaiseNode.Lazy lazyRaiseNode) {
242242
CompilerAsserts.partialEvaluationConstant(method);

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,7 @@ static int fast(long fd) {
436436
}
437437

438438
@Specialization(guards = "!isInteger(nameobj)")
439+
@SuppressWarnings("truffle-static-method") // raise
439440
Object generic(VirtualFrame frame, Object nameobj,
440441
@Bind("this") Node inliningTarget,
441442
@Cached BytesNodes.DecodeUTF8FSPathNode fspath,

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@
7878
import com.oracle.graal.python.util.PythonUtils;
7979
import com.oracle.truffle.api.dsl.Bind;
8080
import com.oracle.truffle.api.dsl.Cached;
81+
import com.oracle.truffle.api.dsl.Cached.Exclusive;
8182
import com.oracle.truffle.api.dsl.GenerateNodeFactory;
8283
import com.oracle.truffle.api.dsl.NodeFactory;
8384
import com.oracle.truffle.api.dsl.Specialization;
@@ -110,14 +111,14 @@ protected ArgumentClinicProvider getArgumentClinic() {
110111

111112
@Specialization(guards = "size < 0")
112113
static Object readall(VirtualFrame frame, Object self, @SuppressWarnings("unused") int size,
113-
@Cached PyObjectCallMethodObjArgs callMethod) {
114+
@Exclusive @Cached PyObjectCallMethodObjArgs callMethod) {
114115
return callMethod.execute(frame, self, T_READALL);
115116
}
116117

117118
@Specialization(guards = "size >= 0")
118119
Object read(VirtualFrame frame, Object self, int size,
119120
@Cached BytesNodes.ToBytesNode toBytes,
120-
@Cached PyObjectCallMethodObjArgs callMethodReadInto,
121+
@Exclusive @Cached PyObjectCallMethodObjArgs callMethodReadInto,
121122
@Cached PyNumberAsSizeNode asSizeNode) {
122123
PByteArray b = factory().createByteArray(new byte[size]);
123124
Object res = callMethodReadInto.execute(frame, self, T_READINTO, b);

0 commit comments

Comments
 (0)