Skip to content

Commit 6392da1

Browse files
committed
Resolve all remaining DSL warnings in the io module
1 parent dd762a3 commit 6392da1

File tree

11 files changed

+115
-134
lines changed

11 files changed

+115
-134
lines changed

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

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,6 @@
158158
import com.oracle.graal.python.builtins.modules.io.PBuffered;
159159
import com.oracle.graal.python.builtins.modules.io.PFileIO;
160160
import com.oracle.graal.python.builtins.modules.io.PTextIO;
161-
import com.oracle.graal.python.builtins.modules.io.TextIOWrapperNodes.TextIOWrapperInitNode;
162161
import com.oracle.graal.python.builtins.modules.io.TextIOWrapperNodesFactory.TextIOWrapperInitNodeGen;
163162
import com.oracle.graal.python.builtins.objects.PNone;
164163
import com.oracle.graal.python.builtins.objects.PythonAbstractObject;
@@ -708,7 +707,6 @@ public void postInitialize(Python3Core core) {
708707

709708
@TruffleBoundary
710709
public void initStd(Python3Core core) {
711-
TextIOWrapperInitNode textIOWrapperInitNode = TextIOWrapperInitNodeGen.getUncached();
712710
PythonObjectFactory factory = core.factory();
713711

714712
// wrap std in/out/err
@@ -722,17 +720,17 @@ public void initStd(Python3Core core) {
722720
PBuffered reader = factory.createBufferedReader(PythonBuiltinClassType.PBufferedReader);
723721
BufferedReaderBuiltins.BufferedReaderInit.internalInit(reader, (PFileIO) getBuiltinConstant(T_STDIN), BufferedReaderBuiltins.DEFAULT_BUFFER_SIZE, factory, posixSupport,
724722
posixLib);
725-
setWrapper(T_STDIN, T___STDIN__, T_R, stdioEncoding, stdioError, reader, sysModule, textIOWrapperInitNode, factory);
723+
setWrapper(T_STDIN, T___STDIN__, T_R, stdioEncoding, stdioError, reader, sysModule, factory);
726724

727725
PBuffered writer = factory.createBufferedWriter(PythonBuiltinClassType.PBufferedWriter);
728726
BufferedWriterBuiltins.BufferedWriterInit.internalInit(writer, (PFileIO) getBuiltinConstant(T_STDOUT), BufferedReaderBuiltins.DEFAULT_BUFFER_SIZE, factory, posixSupport,
729727
posixLib);
730-
PTextIO stdout = setWrapper(T_STDOUT, T___STDOUT__, T_W, stdioEncoding, stdioError, writer, sysModule, textIOWrapperInitNode, factory);
728+
PTextIO stdout = setWrapper(T_STDOUT, T___STDOUT__, T_W, stdioEncoding, stdioError, writer, sysModule, factory);
731729

732730
writer = factory.createBufferedWriter(PythonBuiltinClassType.PBufferedWriter);
733731
BufferedWriterBuiltins.BufferedWriterInit.internalInit(writer, (PFileIO) getBuiltinConstant(T_STDERR), BufferedReaderBuiltins.DEFAULT_BUFFER_SIZE, factory, posixSupport,
734732
posixLib);
735-
PTextIO stderr = setWrapper(T_STDERR, T___STDERR__, T_W, stdioEncoding, T_BACKSLASHREPLACE, writer, sysModule, textIOWrapperInitNode, factory);
733+
PTextIO stderr = setWrapper(T_STDERR, T___STDERR__, T_W, stdioEncoding, T_BACKSLASHREPLACE, writer, sysModule, factory);
736734

737735
// register atexit close std out/err
738736
core.getContext().registerAtexitHook((ctx) -> {
@@ -742,9 +740,9 @@ public void initStd(Python3Core core) {
742740
}
743741

744742
private static PTextIO setWrapper(TruffleString name, TruffleString specialName, TruffleString mode, TruffleString encoding, TruffleString error, PBuffered buffered, PythonModule sysModule,
745-
TextIOWrapperInitNode textIOWrapperInitNode, PythonObjectFactory factory) {
743+
PythonObjectFactory factory) {
746744
PTextIO textIOWrapper = factory.createTextIO(PythonBuiltinClassType.PTextIOWrapper);
747-
textIOWrapperInitNode.execute(null, textIOWrapper, buffered, encoding, error, PNone.NONE, true, true);
745+
TextIOWrapperInitNodeGen.getUncached().execute(null, null, textIOWrapper, buffered, encoding, error, PNone.NONE, true, true);
748746

749747
setAttribute(textIOWrapper, T_MODE, mode);
750748
setAttribute(sysModule, name, textIOWrapper);

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,13 +77,12 @@ public abstract static class BufferedRandomInit extends Node {
7777
public abstract void execute(VirtualFrame frame, Node inliningTarget, PBuffered self, Object raw, int bufferSize, PythonObjectFactory factory);
7878

7979
@Specialization
80-
static void doInit(VirtualFrame frame, @SuppressWarnings("unused") Node ignored, PBuffered self, Object raw, int bufferSize, PythonObjectFactory factory,
81-
@Bind("this") Node inliningTarget,
80+
static void doInit(VirtualFrame frame, Node inliningTarget, PBuffered self, Object raw, int bufferSize, PythonObjectFactory factory,
8281
@Cached IOBaseBuiltins.CheckBoolMethodHelperNode checkSeekableNode,
8382
@Cached IOBaseBuiltins.CheckBoolMethodHelperNode checkReadableNode,
8483
@Cached IOBaseBuiltins.CheckBoolMethodHelperNode checkWritableNode,
8584
@Cached BufferedInitNode bufferedInitNode,
86-
@Cached(inline = true) GetPythonObjectClassNode getSelfClass,
85+
@Cached GetPythonObjectClassNode getSelfClass,
8786
@Cached InlinedGetClassNode getRawClass) {
8887
self.setOK(false);
8988
self.setDetached(false);

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,13 +81,11 @@ public abstract static class BufferedReaderInit extends Node {
8181
public abstract void execute(VirtualFrame frame, Node inliningTarget, PBuffered self, Object raw, int bufferSize, PythonObjectFactory factory);
8282

8383
@Specialization
84-
static void doInit(VirtualFrame frame, @SuppressWarnings("unused") Node ignored, PBuffered self, Object raw, int bufferSize, PythonObjectFactory factory,
85-
/* @Bind("this") Node inliningTarget, */
84+
static void doInit(VirtualFrame frame, Node inliningTarget, PBuffered self, Object raw, int bufferSize, PythonObjectFactory factory,
8685
@Cached IOBaseBuiltins.CheckBoolMethodHelperNode checkReadableNode,
8786
@Cached BufferedInitNode bufferedInitNode,
88-
@Cached(inline = true) GetPythonObjectClassNode getSelfClass,
87+
@Cached GetPythonObjectClassNode getSelfClass,
8988
@Cached InlinedGetClassNode getRawClass) {
90-
Node inliningTarget = ignored;
9189
self.setOK(false);
9290
self.setDetached(false);
9391
checkReadableNode.checkReadable(frame, inliningTarget, raw);

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

Lines changed: 44 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@
8888
import com.oracle.graal.python.lib.PyObjectCallMethodObjArgs;
8989
import com.oracle.graal.python.nodes.ErrorMessages;
9090
import com.oracle.graal.python.nodes.PNodeWithContext;
91-
import com.oracle.graal.python.nodes.PNodeWithRaise;
91+
import com.oracle.graal.python.nodes.PRaiseNode;
9292
import com.oracle.graal.python.nodes.attributes.LookupAttributeInMRONode;
9393
import com.oracle.graal.python.nodes.call.special.CallUnaryMethodNode;
9494
import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
@@ -100,6 +100,8 @@
100100
import com.oracle.truffle.api.dsl.Bind;
101101
import com.oracle.truffle.api.dsl.Cached;
102102
import com.oracle.truffle.api.dsl.Cached.Shared;
103+
import com.oracle.truffle.api.dsl.GenerateCached;
104+
import com.oracle.truffle.api.dsl.GenerateInline;
103105
import com.oracle.truffle.api.dsl.GenerateNodeFactory;
104106
import com.oracle.truffle.api.dsl.ImportStatic;
105107
import com.oracle.truffle.api.dsl.NodeFactory;
@@ -123,19 +125,21 @@ protected List<? extends NodeFactory<? extends PythonBuiltinBaseNode>> getNodeFa
123125

124126
private static final byte[] BLOCKED = new byte[0];
125127

126-
abstract static class RawReadNode extends PNodeWithRaise {
128+
@GenerateInline
129+
@GenerateCached(false)
130+
abstract static class RawReadNode extends PNodeWithContext {
127131

128-
public abstract byte[] execute(VirtualFrame frame, PBuffered self, int len);
132+
public abstract byte[] execute(VirtualFrame frame, Node inliningTarget, PBuffered self, int len);
129133

130134
// This is the spec way
131135
@Specialization
132-
byte[] bufferedreaderRawRead(VirtualFrame frame, PBuffered self, int len,
133-
@Bind("this") Node inliningTarget,
134-
@Cached BytesNodes.ToBytesNode toBytes,
135-
@Cached PythonObjectFactory factory,
136-
@Cached PyObjectCallMethodObjArgs callMethodReadInto,
137-
@Cached PyNumberAsSizeNode asSizeNode,
138-
@Cached InlinedConditionProfile osError) {
136+
static byte[] bufferedreaderRawRead(VirtualFrame frame, Node inliningTarget, PBuffered self, int len,
137+
@Cached(inline = false) BytesNodes.ToBytesNode toBytes,
138+
@Cached(inline = false) PythonObjectFactory factory,
139+
@Cached(inline = false) PyObjectCallMethodObjArgs callMethodReadInto,
140+
@Cached(inline = false) PyNumberAsSizeNode asSizeNode,
141+
@Cached InlinedConditionProfile osError,
142+
@Cached PRaiseNode.Lazy lazyRaiseNode) {
139143
PByteArray memobj = factory.createByteArray(new byte[len]);
140144
// TODO _PyIO_trap_eintr [GR-23297]
141145
Object res = callMethodReadInto.execute(frame, self.getRaw(), T_READINTO, memobj);
@@ -147,10 +151,10 @@ byte[] bufferedreaderRawRead(VirtualFrame frame, PBuffered self, int len,
147151
try {
148152
n = asSizeNode.executeExact(frame, res, ValueError);
149153
} catch (PException e) {
150-
throw raise(OSError, e, ErrorMessages.RAW_READINTO_FAILED);
154+
throw lazyRaiseNode.get(inliningTarget).raise(OSError, e, ErrorMessages.RAW_READINTO_FAILED);
151155
}
152156
if (osError.profile(inliningTarget, n < 0 || n > len)) {
153-
throw raise(OSError, IO_S_INVALID_LENGTH, "readinto()", n, len);
157+
throw lazyRaiseNode.get(inliningTarget).raise(OSError, IO_S_INVALID_LENGTH, "readinto()", n, len);
154158
}
155159
if (n > 0 && self.getAbsPos() != -1) {
156160
self.incAbsPos(n);
@@ -170,12 +174,14 @@ byte[] bufferedreaderRawRead(VirtualFrame frame, PBuffered self, int len,
170174
/**
171175
* implementation of cpython/Modules/_io/bufferedio.c:_bufferedreader_fill_buffer
172176
*/
177+
@GenerateInline
178+
@GenerateCached(false)
173179
abstract static class FillBufferNode extends PNodeWithContext {
174180

175-
public abstract int execute(VirtualFrame frame, PBuffered self);
181+
public abstract int execute(VirtualFrame frame, Node inliningTarget, PBuffered self);
176182

177183
@Specialization
178-
static int bufferedreaderFillBuffer(VirtualFrame frame, PBuffered self,
184+
static int bufferedreaderFillBuffer(VirtualFrame frame, Node inliningTarget, PBuffered self,
179185
@Cached RawReadNode rawReadNode) {
180186
int start;
181187
if (isValidReadBuffer(self)) {
@@ -184,7 +190,7 @@ static int bufferedreaderFillBuffer(VirtualFrame frame, PBuffered self,
184190
start = 0;
185191
}
186192
int len = self.getBufferSize() - start;
187-
byte[] fill = rawReadNode.execute(frame, self, len);
193+
byte[] fill = rawReadNode.execute(frame, inliningTarget, self, len);
188194
if (fill == BLOCKED) {
189195
return -2;
190196
}
@@ -276,7 +282,7 @@ Object bufferedreaderReadGeneric(VirtualFrame frame, PBuffered self, int size,
276282
@Shared @Cached EnterBufferedNode lock,
277283
@Cached RawReadNode rawReadNode,
278284
@Cached FillBufferNode fillBufferNode,
279-
@Cached FlushAndRewindUnlockedNode flushAndRewindUnlockedNode) {
285+
@Shared @Cached FlushAndRewindUnlockedNode flushAndRewindUnlockedNode) {
280286
checkIsClosedNode.execute(frame, self);
281287
try {
282288
lock.enter(inliningTarget, self);
@@ -306,7 +312,7 @@ If we had readv() we could do this in one pass. */
306312
if (r == 0) {
307313
break;
308314
}
309-
byte[] fill = rawReadNode.execute(frame, self, r);
315+
byte[] fill = rawReadNode.execute(frame, inliningTarget, self, r);
310316
if (fill == BLOCKED) {
311317
r = -2;
312318
} else {
@@ -331,7 +337,7 @@ If we had readv() we could do this in one pass. */
331337
reads, which could block indefinitely (e.g. on a socket).
332338
See issue #9550. */
333339
while (remaining > 0 && self.getReadEnd() < self.getBufferSize()) {
334-
int r = fillBufferNode.execute(frame, self);
340+
int r = fillBufferNode.execute(frame, inliningTarget, self);
335341
if (r == 0 || r == -2) {
336342
/* EOF occurred */
337343
if (r == 0 || written > 0) {
@@ -373,7 +379,7 @@ reads, which could block indefinitely (e.g. on a socket).
373379
Object bufferedreaderReadAll(VirtualFrame frame, PBuffered self, @SuppressWarnings("unused") int size,
374380
@Bind("this") Node inliningTarget,
375381
@Shared @Cached EnterBufferedNode lock,
376-
@Cached FlushAndRewindUnlockedNode flushAndRewindUnlockedNode,
382+
@Shared @Cached FlushAndRewindUnlockedNode flushAndRewindUnlockedNode,
377383
@Cached("create(T_READALL)") LookupAttributeInMRONode readallAttr,
378384
@Cached InlinedConditionProfile hasReadallProfile,
379385
@Cached InlinedConditionProfile currentSize0Profile,
@@ -500,7 +506,7 @@ PBytes doit(VirtualFrame frame, PBuffered self, int size,
500506
try {
501507
lock.enter(inliningTarget, self);
502508
self.resetRead(); // _bufferedreader_reset_buf
503-
byte[] fill = rawReadNode.execute(frame, self, n);
509+
byte[] fill = rawReadNode.execute(frame, inliningTarget, self, n);
504510
return factory().createBytes(fill == BLOCKED ? PythonUtils.EMPTY_BYTE_ARRAY : fill);
505511
} finally {
506512
EnterBufferedNode.leave(self);
@@ -519,6 +525,7 @@ abstract static class ReadIntoNode extends PythonBinaryWithInitErrorClinicBuilti
519525
* implementation of cpython/Modules/_io/bufferedio.c:_buffered_readinto_generic
520526
*/
521527
@Specialization(guards = "self.isOK()", limit = "3")
528+
@SuppressWarnings("truffle-static-method")
522529
Object bufferedReadintoGeneric(VirtualFrame frame, PBuffered self, Object buffer,
523530
@Bind("this") Node inliningTarget,
524531
@CachedLibrary("buffer") PythonBufferAccessLibrary bufferLib,
@@ -558,7 +565,7 @@ Object bufferedReadintoGeneric(VirtualFrame frame, PBuffered self, Object buffer
558565
caller's buffer.
559566
*/
560567
if (remaining > self.getBufferSize()) {
561-
byte[] fill = rawReadNode.execute(frame, self, remaining);
568+
byte[] fill = rawReadNode.execute(frame, inliningTarget, self, remaining);
562569
if (fill == BLOCKED) {
563570
n = -2;
564571
} else {
@@ -570,7 +577,7 @@ Object bufferedReadintoGeneric(VirtualFrame frame, PBuffered self, Object buffer
570577
In readinto1 mode, we do not want to fill the internal buffer if we already have
571578
some data to return
572579
*/
573-
n = fillBufferNode.execute(frame, self);
580+
n = fillBufferNode.execute(frame, inliningTarget, self);
574581
if (n > 0) {
575582
if (n > remaining) {
576583
n = remaining;
@@ -632,13 +639,14 @@ protected ArgumentClinicProvider getArgumentClinic() {
632639
/**
633640
* implementation of cpython/Modules/_io/bufferedio.c:_buffered_readline
634641
*/
642+
@GenerateInline
643+
@GenerateCached(false)
635644
abstract static class BufferedReadlineNode extends PNodeWithContext {
636645

637-
public abstract byte[] execute(VirtualFrame frame, PBuffered self, int size);
646+
public abstract byte[] execute(VirtualFrame frame, Node inliningTarget, PBuffered self, int size);
638647

639648
@Specialization
640-
static byte[] readline(VirtualFrame frame, PBuffered self, int size,
641-
@Bind("this") Node inliningTarget,
649+
static byte[] readline(VirtualFrame frame, Node inliningTarget, PBuffered self, int size,
642650
@Cached EnterBufferedNode lock,
643651
@Cached FlushAndRewindUnlockedNode flushAndRewindUnlockedNode,
644652
@Cached FillBufferNode fillBufferNode,
@@ -684,7 +692,7 @@ static byte[] readline(VirtualFrame frame, PBuffered self, int size,
684692

685693
while (true) {
686694
self.resetRead(); // _bufferedreader_reset_buf
687-
n = fillBufferNode.execute(frame, self);
695+
n = fillBufferNode.execute(frame, inliningTarget, self);
688696
if (n <= 0) {
689697
break;
690698
}
@@ -728,11 +736,13 @@ protected ArgumentClinicProvider getArgumentClinic() {
728736
}
729737

730738
@Specialization(guards = "self.isOK()")
739+
@SuppressWarnings("truffle-static-method")
731740
PBytes doit(VirtualFrame frame, PBuffered self, int size,
741+
@Bind("this") Node inliningTarget,
732742
@Cached("create(T_READLINE)") CheckIsClosedNode checkIsClosedNode,
733743
@Cached BufferedReadlineNode readlineNode) {
734744
checkIsClosedNode.execute(frame, self);
735-
byte[] res = readlineNode.execute(frame, self, size);
745+
byte[] res = readlineNode.execute(frame, inliningTarget, self, size);
736746
return factory().createBytes(res);
737747
}
738748
}
@@ -750,7 +760,7 @@ protected ArgumentClinicProvider getArgumentClinic() {
750760
/**
751761
* implementation of cpython/Modules/_io/bufferedio.c:_bufferedreader_peek_unlocked
752762
*/
753-
static byte[] bufferedreaderPeekUnlocked(VirtualFrame frame, PBuffered self,
763+
static byte[] bufferedreaderPeekUnlocked(VirtualFrame frame, Node inliningTarget, PBuffered self,
754764
FillBufferNode fillBufferNode) {
755765
int have = safeDowncast(self);
756766
/*-
@@ -765,7 +775,7 @@ static byte[] bufferedreaderPeekUnlocked(VirtualFrame frame, PBuffered self,
765775

766776
/* Fill the buffer from the raw stream, and copy it to the result. */
767777
self.resetRead(); // _bufferedreader_reset_buf
768-
int r = fillBufferNode.execute(frame, self);
778+
int r = fillBufferNode.execute(frame, inliningTarget, self);
769779
if (r == -2) {
770780
r = 0;
771781
}
@@ -774,6 +784,7 @@ static byte[] bufferedreaderPeekUnlocked(VirtualFrame frame, PBuffered self,
774784
}
775785

776786
@Specialization(guards = "self.isOK()")
787+
@SuppressWarnings("truffle-static-method")
777788
Object doit(VirtualFrame frame, PBuffered self, @SuppressWarnings("unused") int size,
778789
@Bind("this") Node inliningTarget,
779790
@Cached EnterBufferedNode lock,
@@ -786,7 +797,7 @@ Object doit(VirtualFrame frame, PBuffered self, @SuppressWarnings("unused") int
786797
if (self.isWritable()) {
787798
flushAndRewindUnlockedNode.execute(frame, inliningTarget, self);
788799
}
789-
return factory().createBytes(bufferedreaderPeekUnlocked(frame, self, fillBufferNode));
800+
return factory().createBytes(bufferedreaderPeekUnlocked(frame, inliningTarget, self, fillBufferNode));
790801
} finally {
791802
EnterBufferedNode.leave(self);
792803
}
@@ -799,11 +810,13 @@ Object doit(VirtualFrame frame, PBuffered self, @SuppressWarnings("unused") int
799810
abstract static class NextNode extends PythonUnaryWithInitErrorBuiltinNode {
800811

801812
@Specialization(guards = "self.isOK()")
813+
@SuppressWarnings("truffle-static-method")
802814
PBytes doit(VirtualFrame frame, PBuffered self,
815+
@Bind("this") Node inliningTarget,
803816
@Cached("create(T_READLINE)") CheckIsClosedNode checkIsClosedNode,
804817
@Cached BufferedReadlineNode readlineNode) {
805818
checkIsClosedNode.execute(frame, self);
806-
byte[] line = readlineNode.execute(frame, self, -1);
819+
byte[] line = readlineNode.execute(frame, inliningTarget, self, -1);
807820
if (line.length == 0) {
808821
throw raiseStopIteration();
809822
}

0 commit comments

Comments
 (0)