Skip to content

Commit f6f0579

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

File tree

7 files changed

+72
-49
lines changed

7 files changed

+72
-49
lines changed

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@
7373
import com.oracle.graal.python.runtime.object.PythonObjectFactory;
7474
import com.oracle.truffle.api.CompilerDirectives;
7575
import com.oracle.truffle.api.dsl.Cached;
76+
import com.oracle.truffle.api.dsl.GenerateInline;
7677
import com.oracle.truffle.api.dsl.Specialization;
7778
import com.oracle.truffle.api.frame.VirtualFrame;
7879
import com.oracle.truffle.api.nodes.Node;
@@ -204,6 +205,7 @@ Object initError(PBuffered self) {
204205
}
205206
}
206207

208+
@GenerateInline(false)
207209
public abstract static class RaiseBlockingIOError extends Node {
208210
protected abstract PException execute(Node node, Object errno, TruffleString message, int written);
209211

@@ -235,6 +237,18 @@ static PException raise(Node node, Object errno, TruffleString message, int writ
235237
exception.setExceptionAttributes(attrs);
236238
return PRaiseNode.raise(node, exception, PythonOptions.isPExceptionWithJavaStacktrace(PythonLanguage.get(node)));
237239
}
240+
}
241+
242+
public abstract static class LazyRaiseBlockingIOError extends Node {
243+
public final RaiseBlockingIOError get(Node inliningTarget) {
244+
return execute(inliningTarget);
245+
}
238246

247+
protected abstract RaiseBlockingIOError execute(Node inliningTarget);
248+
249+
@Specialization
250+
static RaiseBlockingIOError doIt(@Cached(inline = false) RaiseBlockingIOError node) {
251+
return node;
252+
}
239253
}
240254
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ static long doit(VirtualFrame frame, PBuffered self, Object off, int whence,
268268
checkIsClosedNode.execute(frame, self);
269269
checkIsSeekabledNode.execute(frame, self);
270270
long pos = asOffNumberNode.execute(frame, inliningTarget, off, TypeError);
271-
return seekNode.execute(frame, self, pos, whence);
271+
return seekNode.execute(frame, inliningTarget, self, pos, whence);
272272
}
273273

274274
@Specialization(guards = {"self.isOK()", "!isSupportedWhence(whence)"})
@@ -320,7 +320,7 @@ static Object doit(VirtualFrame frame, PBuffered self, Object pos,
320320
checkIsClosedNode.execute(frame, self);
321321
try {
322322
lock.enter(inliningTarget, self);
323-
flushAndRewindUnlockedNode.execute(frame, self);
323+
flushAndRewindUnlockedNode.execute(frame, inliningTarget, self);
324324
Object res = callMethodTruncate.execute(frame, self.getRaw(), T_TRUNCATE, pos);
325325
/* Reset cached position */
326326
rawTellNode.execute(frame, self);

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

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -280,14 +280,15 @@ static long bufferedRawSeek(VirtualFrame frame, Node inliningTarget, PBuffered s
280280
/**
281281
* implementation of cpython/Modules/_io/bufferedio.c:buffered_flush_and_rewind_unlocked
282282
*/
283+
@GenerateInline
284+
@GenerateCached(false)
283285
abstract static class FlushAndRewindUnlockedNode extends PNodeWithContext {
284286

285-
public abstract void execute(VirtualFrame frame, PBuffered self);
287+
public abstract void execute(VirtualFrame frame, Node inliningTarget, PBuffered self);
286288

287289
@Specialization(guards = {"self.isReadable()", "!self.isWritable()"})
288-
protected static void readOnly(VirtualFrame frame, PBuffered self,
289-
@Bind("this") Node inliningTarget,
290-
@Cached RawSeekNode rawSeekNode) {
290+
protected static void readOnly(VirtualFrame frame, Node inliningTarget, PBuffered self,
291+
@Shared @Cached RawSeekNode rawSeekNode) {
291292
/*
292293
* Rewind the raw stream so that its position corresponds to the current logical
293294
* position.
@@ -298,17 +299,16 @@ protected static void readOnly(VirtualFrame frame, PBuffered self,
298299
}
299300

300301
@Specialization(guards = {"!self.isReadable()", "self.isWritable()"})
301-
protected static void writeOnly(VirtualFrame frame, PBuffered self,
302-
@Cached BufferedWriterNodes.FlushUnlockedNode flushUnlockedNode) {
303-
flushUnlockedNode.execute(frame, self);
302+
protected static void writeOnly(VirtualFrame frame, Node inliningTarget, PBuffered self,
303+
@Shared @Cached BufferedWriterNodes.FlushUnlockedNode flushUnlockedNode) {
304+
flushUnlockedNode.execute(frame, inliningTarget, self);
304305
}
305306

306307
@Specialization(guards = {"self.isReadable()", "self.isWritable()"})
307-
protected static void readWrite(VirtualFrame frame, PBuffered self,
308-
@Bind("this") Node inliningTarget,
309-
@Cached BufferedWriterNodes.FlushUnlockedNode flushUnlockedNode,
310-
@Cached RawSeekNode rawSeekNode) {
311-
flushUnlockedNode.execute(frame, self);
308+
protected static void readWrite(VirtualFrame frame, Node inliningTarget, PBuffered self,
309+
@Shared @Cached BufferedWriterNodes.FlushUnlockedNode flushUnlockedNode,
310+
@Shared @Cached RawSeekNode rawSeekNode) {
311+
flushUnlockedNode.execute(frame, inliningTarget, self);
312312
/*
313313
* Rewind the raw stream so that its position corresponds to the current logical
314314
* position.
@@ -322,13 +322,14 @@ protected static void readWrite(VirtualFrame frame, PBuffered self,
322322
/**
323323
* implementation of cpython/Modules/_io/bufferedio.c:_io__Buffered_seek_impl
324324
*/
325+
@GenerateInline
326+
@GenerateCached(false)
325327
abstract static class SeekNode extends PNodeWithContext {
326328

327-
public abstract long execute(VirtualFrame frame, PBuffered self, long off, int whence);
329+
public abstract long execute(VirtualFrame frame, Node inliningTarget, PBuffered self, long off, int whence);
328330

329331
@Specialization
330-
static long seek(VirtualFrame frame, PBuffered self, long off, int whence,
331-
@Bind("this") Node inliningTarget,
332+
static long seek(VirtualFrame frame, Node inliningTarget, PBuffered self, long off, int whence,
332333
@Cached EnterBufferedNode lock,
333334
@Cached BufferedWriterNodes.FlushUnlockedNode flushUnlockedNode,
334335
@Cached RawSeekNode rawSeekNode,
@@ -372,7 +373,7 @@ static long seek(VirtualFrame frame, PBuffered self, long off, int whence,
372373
try {
373374
/* Fallback: invoke raw seek() method and clear buffer */
374375
if (isWriteableProfile.profile(inliningTarget, self.isWritable())) {
375-
flushUnlockedNode.execute(frame, self);
376+
flushUnlockedNode.execute(frame, inliningTarget, self);
376377
}
377378

378379
if (whenceSeekCur) {

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ Object bufferedreaderReadGeneric(VirtualFrame frame, PBuffered self, int size,
294294
}
295295
/* Flush the write buffer if necessary */
296296
if (self.isWritable()) {
297-
flushAndRewindUnlockedNode.execute(frame, self);
297+
flushAndRewindUnlockedNode.execute(frame, inliningTarget, self);
298298
}
299299
self.resetRead(); // _bufferedreader_reset_buf
300300
while (remaining > 0) {
@@ -391,7 +391,7 @@ Object bufferedreaderReadAll(VirtualFrame frame, PBuffered self, @SuppressWarnin
391391

392392
/* We're going past the buffer's bounds, flush it */
393393
if (self.isWritable()) {
394-
flushAndRewindUnlockedNode.execute(frame, self);
394+
flushAndRewindUnlockedNode.execute(frame, inliningTarget, self);
395395
}
396396

397397
self.resetRead(); // _bufferedreader_reset_buf
@@ -542,7 +542,7 @@ Object bufferedReadintoGeneric(VirtualFrame frame, PBuffered self, Object buffer
542542
}
543543

544544
if (self.isWritable()) {
545-
flushAndRewindUnlockedNode.execute(frame, self);
545+
flushAndRewindUnlockedNode.execute(frame, inliningTarget, self);
546546
}
547547

548548
self.resetRead(); // _bufferedreader_reset_buf
@@ -675,7 +675,7 @@ static byte[] readline(VirtualFrame frame, PBuffered self, int size,
675675
}
676676
}
677677
if (self.isWritable()) {
678-
flushAndRewindUnlockedNode.execute(frame, self);
678+
flushAndRewindUnlockedNode.execute(frame, inliningTarget, self);
679679
}
680680

681681
while (true) {
@@ -780,7 +780,7 @@ Object doit(VirtualFrame frame, PBuffered self, @SuppressWarnings("unused") int
780780
try {
781781
lock.enter(inliningTarget, self);
782782
if (self.isWritable()) {
783-
flushAndRewindUnlockedNode.execute(frame, self);
783+
flushAndRewindUnlockedNode.execute(frame, inliningTarget, self);
784784
}
785785
return factory().createBytes(bufferedreaderPeekUnlocked(frame, self, fillBufferNode));
786786
} finally {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ Object write(@SuppressWarnings("unused") VirtualFrame frame, PBuffered self, Obj
103103
try {
104104
lock.enter(inliningTarget, self);
105105
checkIsClosedNode.execute(frame, self);
106-
return writeNode.execute(frame, self, buffer);
106+
return writeNode.execute(frame, inliningTarget, self, buffer);
107107
} finally {
108108
bufferLib.release(buffer, frame, this);
109109
EnterBufferedNode.leave(self);
@@ -130,7 +130,7 @@ static Object doit(VirtualFrame frame, PBuffered self,
130130
checkIsClosedNode.execute(frame, self);
131131
try {
132132
lock.enter(inliningTarget, self);
133-
flushAndRewindUnlockedNode.execute(frame, self);
133+
flushAndRewindUnlockedNode.execute(frame, inliningTarget, self);
134134
} finally {
135135
EnterBufferedNode.leave(self);
136136
}

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

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,17 @@
5656
import com.oracle.graal.python.builtins.objects.bytes.PBytes;
5757
import com.oracle.graal.python.lib.PyNumberAsSizeNode;
5858
import com.oracle.graal.python.lib.PyObjectCallMethodObjArgs;
59+
import com.oracle.graal.python.nodes.PNodeWithContext;
5960
import com.oracle.graal.python.nodes.PNodeWithRaise;
61+
import com.oracle.graal.python.nodes.PRaiseNode;
6062
import com.oracle.graal.python.nodes.object.BuiltinClassProfiles.IsBuiltinObjectProfile;
6163
import com.oracle.graal.python.runtime.exception.PException;
6264
import com.oracle.graal.python.runtime.object.PythonObjectFactory;
6365
import com.oracle.graal.python.util.PythonUtils;
6466
import com.oracle.truffle.api.dsl.Bind;
6567
import com.oracle.truffle.api.dsl.Cached;
68+
import com.oracle.truffle.api.dsl.GenerateCached;
69+
import com.oracle.truffle.api.dsl.GenerateInline;
6670
import com.oracle.truffle.api.dsl.Specialization;
6771
import com.oracle.truffle.api.frame.VirtualFrame;
6872
import com.oracle.truffle.api.library.CachedLibrary;
@@ -79,16 +83,16 @@ private static void adjustPosition(PBuffered self, int newPos) {
7983

8084
abstract static class WriteNode extends PNodeWithRaise {
8185

82-
public abstract int execute(VirtualFrame frame, PBuffered self, Object buffer);
86+
public abstract int execute(VirtualFrame frame, Node inliningTarget, PBuffered self, Object buffer);
8387

8488
/**
8589
* implementation of cpython/Modules/_io/bufferedio.c:_io_BufferedWriter_write_impl
8690
*/
8791
@Specialization
88-
static int bufferedWriterWrite(VirtualFrame frame, PBuffered self, Object buffer,
92+
static int bufferedWriterWrite(VirtualFrame frame, @SuppressWarnings("unused") Node ignored, PBuffered self, Object buffer,
8993
@Bind("this") Node inliningTarget,
9094
@CachedLibrary(limit = "3") PythonBufferAccessLibrary bufferLib,
91-
@Cached AbstractBufferedIOBuiltins.RaiseBlockingIOError raiseBlockingIOError,
95+
@Cached AbstractBufferedIOBuiltins.LazyRaiseBlockingIOError raiseBlockingIOError,
9296
@Cached IsBuiltinObjectProfile isBuiltinClassProfile,
9397
@Cached BufferedIONodes.RawSeekNode rawSeekNode,
9498
@Cached RawWriteNode rawWriteNode,
@@ -118,7 +122,7 @@ static int bufferedWriterWrite(VirtualFrame frame, PBuffered self, Object buffer
118122

119123
/* First write the current buffer */
120124
try {
121-
flushUnlockedNode.execute(frame, self);
125+
flushUnlockedNode.execute(frame, inliningTarget, self);
122126
} catch (PException e) {
123127
e.expect(inliningTarget, BlockingIOError, isBuiltinClassProfile);
124128
if (self.isReadable()) {
@@ -150,7 +154,7 @@ static int bufferedWriterWrite(VirtualFrame frame, PBuffered self, Object buffer
150154
* error.
151155
*/
152156
Object errno = e.getUnreifiedException().getArgs().getSequenceStorage().getItemNormalized(0);
153-
throw raiseBlockingIOError.raise(errno, WRITE_COULD_NOT_COMPLETE_WITHOUT_BLOCKING, avail);
157+
throw raiseBlockingIOError.get(inliningTarget).raise(errno, WRITE_COULD_NOT_COMPLETE_WITHOUT_BLOCKING, avail);
154158
}
155159
/*
156160
* Adjust the raw stream position if it is away from the logical stream position. This
@@ -171,15 +175,15 @@ static int bufferedWriterWrite(VirtualFrame frame, PBuffered self, Object buffer
171175
// TODO use memoryview
172176
byte[] buf = new byte[bufLen];
173177
bufferLib.readIntoByteArray(buffer, written, buf, 0, bufLen - written);
174-
int n = rawWriteNode.execute(frame, self, buf, bufLen - written);
178+
int n = rawWriteNode.execute(frame, inliningTarget, self, buf, bufLen - written);
175179
if (n == -2) {
176180
if (remaining > self.getBufferSize()) {
177181
bufferLib.readIntoByteArray(buffer, written, self.getBuffer(), 0, self.getBufferSize());
178182
self.setRawPos(0);
179183
adjustPosition(self, self.getBufferSize());
180184
self.setWriteEnd(self.getBufferSize());
181185
written += self.getBufferSize();
182-
throw raiseBlockingIOError.raiseEWOULDBLOCK(WRITE_COULD_NOT_COMPLETE_WITHOUT_BLOCKING, written);
186+
throw raiseBlockingIOError.get(inliningTarget).raiseEWOULDBLOCK(WRITE_COULD_NOT_COMPLETE_WITHOUT_BLOCKING, written);
183187
}
184188
break;
185189
}
@@ -205,18 +209,21 @@ static int bufferedWriterWrite(VirtualFrame frame, PBuffered self, Object buffer
205209
}
206210
}
207211

208-
abstract static class RawWriteNode extends PNodeWithRaise {
212+
@GenerateInline
213+
@GenerateCached(false)
214+
abstract static class RawWriteNode extends PNodeWithContext {
209215

210-
public abstract int execute(VirtualFrame frame, PBuffered self, byte[] buf, int len);
216+
public abstract int execute(VirtualFrame frame, Node inliningTarget, PBuffered self, byte[] buf, int len);
211217

212218
/**
213219
* implementation of cpython/Modules/_io/bufferedio.c:_bufferedwriter_raw_write
214220
*/
215221
@Specialization
216-
int bufferedwriterRawWrite(VirtualFrame frame, PBuffered self, byte[] buf, int len,
217-
@Cached PythonObjectFactory factory,
218-
@Cached PyObjectCallMethodObjArgs callMethod,
219-
@Cached PyNumberAsSizeNode asSizeNode) {
222+
static int bufferedwriterRawWrite(VirtualFrame frame, Node inliningTarget, PBuffered self, byte[] buf, int len,
223+
@Cached(inline = false) PythonObjectFactory factory,
224+
@Cached(inline = false) PyObjectCallMethodObjArgs callMethod,
225+
@Cached(inline = false) PyNumberAsSizeNode asSizeNode,
226+
@Cached PRaiseNode.Lazy lazyRaiseNode) {
220227
PBytes memobj = factory.createBytes(buf, len);
221228
Object res = callMethod.execute(frame, self.getRaw(), T_WRITE, memobj);
222229
if (res == PNone.NONE) {
@@ -227,7 +234,7 @@ int bufferedwriterRawWrite(VirtualFrame frame, PBuffered self, byte[] buf, int l
227234
}
228235
int n = asSizeNode.executeExact(frame, res, ValueError);
229236
if (n < 0 || n > len) {
230-
throw raise(OSError, IO_S_INVALID_LENGTH, "write()", n, len);
237+
throw lazyRaiseNode.get(inliningTarget).raise(OSError, IO_S_INVALID_LENGTH, "write()", n, len);
231238
}
232239
if (n > 0 && self.getAbsPos() != -1) {
233240
self.incAbsPos(n);
@@ -236,17 +243,18 @@ int bufferedwriterRawWrite(VirtualFrame frame, PBuffered self, byte[] buf, int l
236243
}
237244
}
238245

239-
abstract static class FlushUnlockedNode extends PNodeWithRaise {
246+
@GenerateInline
247+
@GenerateCached(false)
248+
abstract static class FlushUnlockedNode extends PNodeWithContext {
240249

241-
public abstract void execute(VirtualFrame frame, PBuffered self);
250+
public abstract void execute(VirtualFrame frame, Node inliningTarget, PBuffered self);
242251

243252
/**
244253
* implementation of cpython/Modules/_io/bufferedio.c:_bufferedwriter_flush_unlocked
245254
*/
246255
@Specialization
247-
protected static void bufferedwriterFlushUnlocked(VirtualFrame frame, PBuffered self,
248-
@Bind("this") Node inliningTarget,
249-
@Cached AbstractBufferedIOBuiltins.RaiseBlockingIOError raiseBlockingIOError,
256+
protected static void bufferedwriterFlushUnlocked(VirtualFrame frame, Node inliningTarget, PBuffered self,
257+
@Cached AbstractBufferedIOBuiltins.LazyRaiseBlockingIOError raiseBlockingIOError,
250258
@Cached RawWriteNode rawWriteNode,
251259
@Cached BufferedIONodes.RawSeekNode rawSeekNode) {
252260
if (!isValidWriteBuffer(self) || self.getWritePos() == self.getWriteEnd()) {
@@ -261,9 +269,9 @@ protected static void bufferedwriterFlushUnlocked(VirtualFrame frame, PBuffered
261269
}
262270
while (self.getWritePos() < self.getWriteEnd()) {
263271
byte[] buf = PythonUtils.arrayCopyOfRange(self.getBuffer(), self.getWritePos(), self.getWriteEnd());
264-
int n = rawWriteNode.execute(frame, self, buf, buf.length);
272+
int n = rawWriteNode.execute(frame, inliningTarget, self, buf, buf.length);
265273
if (n == -2) {
266-
throw raiseBlockingIOError.raiseEAGAIN(WRITE_COULD_NOT_COMPLETE_WITHOUT_BLOCKING, 0);
274+
throw raiseBlockingIOError.get(inliningTarget).raiseEAGAIN(WRITE_COULD_NOT_COMPLETE_WITHOUT_BLOCKING, 0);
267275
}
268276
self.incWritePos(n);
269277
self.setRawPos(self.getWritePos());

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ void doInit(VirtualFrame frame, PFileIO self, Object nameobj, IONodes.IOMode mod
383383
try {
384384
posixLib.setInheritable(ctxt.getPosixSupport(), self.getFD(), false);
385385
} catch (PosixException e) {
386-
exceptionProfile.enter(inliningTarget);
386+
exceptionProfile1.enter(inliningTarget);
387387
throw raiseOSErrorFromPosixException(frame, e, fromJavaStringNode);
388388
}
389389
fdIsOwn = true;
@@ -411,7 +411,7 @@ void doInit(VirtualFrame frame, PFileIO self, Object nameobj, IONodes.IOMode mod
411411
* self.setBlksize(fstatResult[8]); }
412412
*/
413413
} catch (PosixException e) {
414-
exceptionProfile.enter(inliningTarget);
414+
exceptionProfile2.enter(inliningTarget);
415415
/*
416416
* Tolerate fstat() errors other than EBADF. See Issue #25717, where an
417417
* anonymous file on a Virtual Box shared folder filesystem would raise ENOENT.
@@ -437,7 +437,7 @@ void doInit(VirtualFrame frame, PFileIO self, Object nameobj, IONodes.IOMode mod
437437
gil.acquire();
438438
}
439439
} catch (PosixException e) {
440-
exceptionProfile.enter(inliningTarget);
440+
exceptionProfile3.enter(inliningTarget);
441441
if (self.getSeekable() < 0) {
442442
self.setSeekable(0);
443443
}

0 commit comments

Comments
 (0)