Skip to content

Commit dd762a3

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

File tree

7 files changed

+102
-76
lines changed

7 files changed

+102
-76
lines changed

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

Lines changed: 22 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,8 @@
5656
import com.oracle.graal.python.builtins.objects.exception.OsErrorBuiltins;
5757
import com.oracle.graal.python.builtins.objects.exception.PBaseException;
5858
import com.oracle.graal.python.lib.PyNumberAsSizeNode;
59-
import com.oracle.graal.python.nodes.PNodeWithRaise;
59+
import com.oracle.graal.python.nodes.PNodeWithContext;
6060
import com.oracle.graal.python.nodes.PRaiseNode;
61-
import com.oracle.graal.python.nodes.function.PythonBuiltinNode;
6261
import com.oracle.graal.python.nodes.function.builtins.PythonBinaryBuiltinNode;
6362
import com.oracle.graal.python.nodes.function.builtins.PythonBinaryClinicBuiltinNode;
6463
import com.oracle.graal.python.nodes.function.builtins.PythonUnaryBuiltinNode;
@@ -71,8 +70,8 @@
7170
import com.oracle.graal.python.runtime.exception.PException;
7271
import com.oracle.graal.python.runtime.object.PythonObjectFactory;
7372
import com.oracle.truffle.api.CompilerDirectives;
74-
import com.oracle.truffle.api.dsl.Bind;
7573
import com.oracle.truffle.api.dsl.Cached;
74+
import com.oracle.truffle.api.dsl.Fallback;
7675
import com.oracle.truffle.api.dsl.GenerateCached;
7776
import com.oracle.truffle.api.dsl.GenerateInline;
7877
import com.oracle.truffle.api.dsl.Specialization;
@@ -84,22 +83,24 @@ abstract class AbstractBufferedIOBuiltins extends PythonBuiltins {
8483

8584
public static final int DEFAULT_BUFFER_SIZE = IOModuleBuiltins.DEFAULT_BUFFER_SIZE;
8685

87-
public abstract static class BufferedInitNode extends PNodeWithRaise {
86+
@GenerateInline
87+
@GenerateCached(false)
88+
public abstract static class BufferedInitNode extends PNodeWithContext {
8889

89-
public abstract void execute(VirtualFrame frame, PBuffered self, int bufferSize, PythonObjectFactory factory);
90+
public abstract void execute(VirtualFrame frame, Node inliningTarget, PBuffered self, int bufferSize, PythonObjectFactory factory);
9091

9192
@Specialization(guards = "bufferSize > 0")
92-
void bufferedInit(VirtualFrame frame, PBuffered self, int bufferSize, PythonObjectFactory factory,
93-
@Bind("this") Node inliningTarget,
93+
static void bufferedInit(VirtualFrame frame, Node inliningTarget, PBuffered self, int bufferSize, PythonObjectFactory factory,
9494
@Cached RawTellNode rawTellNode) {
9595
init(self, bufferSize, factory);
9696
rawTellNode.executeIgnoreError(frame, inliningTarget, self);
9797
}
9898

9999
@SuppressWarnings("unused")
100100
@Specialization(guards = "bufferSize <= 0")
101-
void bufferSizeError(PBuffered self, int bufferSize, PythonObjectFactory factory) {
102-
throw raise(ValueError, BUF_SIZE_POS);
101+
static void bufferSizeError(PBuffered self, int bufferSize, PythonObjectFactory factory,
102+
@Cached(inline = false) PRaiseNode raiseNode) {
103+
throw raiseNode.raise(ValueError, BUF_SIZE_POS);
103104
}
104105

105106
private static void init(PBuffered self, int bufferSize, PythonObjectFactory factory) {
@@ -132,35 +133,25 @@ protected static boolean isFileIO(PBuffered self, Object raw, PythonBuiltinClass
132133
getRawClass.execute(inliningTarget, raw) == PythonBuiltinClassType.PFileIO;
133134
}
134135

135-
public abstract static class BaseInitNode extends PythonBuiltinNode {
136+
@GenerateInline
137+
@GenerateCached(false)
138+
public abstract static class InitBufferSizeNode extends Node {
139+
public abstract int execute(VirtualFrame frame, Node inliningTarget, Object bufferSize);
136140

137141
@Specialization
138-
public PNone doInit(VirtualFrame frame, PBuffered self, Object raw, @SuppressWarnings("unused") PNone bufferSize) {
139-
init(frame, self, raw, DEFAULT_BUFFER_SIZE);
140-
return PNone.NONE;
142+
static int doInit(@SuppressWarnings("unused") PNone bufferSize) {
143+
return DEFAULT_BUFFER_SIZE;
141144
}
142145

143146
@Specialization
144-
public PNone doInit(VirtualFrame frame, PBuffered self, Object raw, int bufferSize) {
145-
init(frame, self, raw, bufferSize);
146-
return PNone.NONE;
147+
static int doInt(int bufferSize) {
148+
return bufferSize;
147149
}
148150

149-
@Specialization(guards = "!isInt(bufferSizeObj)")
150-
public PNone doInit(VirtualFrame frame, PBuffered self, Object raw, Object bufferSizeObj,
151-
@Cached PyNumberAsSizeNode asSizeNode) {
152-
int bufferSize = asSizeNode.executeExact(frame, bufferSizeObj, ValueError);
153-
init(frame, self, raw, bufferSize);
154-
return PNone.NONE;
155-
}
156-
157-
protected static boolean isInt(Object obj) {
158-
return obj instanceof Integer;
159-
}
160-
161-
@SuppressWarnings("unused")
162-
protected void init(VirtualFrame frame, PBuffered self, Object raw, int bufferSize) {
163-
throw CompilerDirectives.shouldNotReachHere("Abstract buffered init");
151+
@Fallback
152+
static int doOther(VirtualFrame frame, Object bufferSizeObj,
153+
@Cached(inline = false) PyNumberAsSizeNode asSizeNode) {
154+
return asSizeNode.executeExact(frame, bufferSizeObj, ValueError);
164155
}
165156
}
166157

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,9 +128,9 @@ public PNone doInit(VirtualFrame frame, PRWPair self, Object reader, Object writ
128128
checkReadableNode.checkReadable(frame, inliningTarget, reader);
129129
checkWritableNode.checkWriteable(frame, inliningTarget, writer);
130130
self.setReader(factory().createBufferedReader(PBufferedReader));
131-
initReaderNode.execute(frame, self.getReader(), reader, bufferSize, factory());
131+
initReaderNode.execute(frame, inliningTarget, self.getReader(), reader, bufferSize, factory());
132132
self.setWriter(factory().createBufferedWriter(PBufferedWriter));
133-
initWriterNode.execute(frame, self.getWriter(), writer, bufferSize, factory());
133+
initWriterNode.execute(frame, inliningTarget, self.getWriter(), writer, bufferSize, factory());
134134
return PNone.NONE;
135135
}
136136
}

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

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,16 @@
4747

4848
import com.oracle.graal.python.builtins.Builtin;
4949
import com.oracle.graal.python.builtins.CoreFunctions;
50+
import com.oracle.graal.python.builtins.objects.PNone;
5051
import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
52+
import com.oracle.graal.python.nodes.function.PythonBuiltinNode;
5153
import com.oracle.graal.python.nodes.object.InlinedGetClassNode;
5254
import com.oracle.graal.python.nodes.object.InlinedGetClassNode.GetPythonObjectClassNode;
5355
import com.oracle.graal.python.runtime.object.PythonObjectFactory;
5456
import com.oracle.truffle.api.dsl.Bind;
5557
import com.oracle.truffle.api.dsl.Cached;
58+
import com.oracle.truffle.api.dsl.GenerateCached;
59+
import com.oracle.truffle.api.dsl.GenerateInline;
5660
import com.oracle.truffle.api.dsl.GenerateNodeFactory;
5761
import com.oracle.truffle.api.dsl.NodeFactory;
5862
import com.oracle.truffle.api.dsl.Specialization;
@@ -66,12 +70,14 @@ protected List<? extends NodeFactory<? extends PythonBuiltinBaseNode>> getNodeFa
6670
return BufferedRandomBuiltinsFactory.getFactories();
6771
}
6872

73+
@GenerateCached(false)
74+
@GenerateInline
6975
public abstract static class BufferedRandomInit extends Node {
7076

71-
public abstract void execute(VirtualFrame frame, PBuffered self, Object raw, int bufferSize, PythonObjectFactory factory);
77+
public abstract void execute(VirtualFrame frame, Node inliningTarget, PBuffered self, Object raw, int bufferSize, PythonObjectFactory factory);
7278

7379
@Specialization
74-
static void doInit(VirtualFrame frame, PBuffered self, Object raw, int bufferSize, PythonObjectFactory factory,
80+
static void doInit(VirtualFrame frame, @SuppressWarnings("unused") Node ignored, PBuffered self, Object raw, int bufferSize, PythonObjectFactory factory,
7581
@Bind("this") Node inliningTarget,
7682
@Cached IOBaseBuiltins.CheckBoolMethodHelperNode checkSeekableNode,
7783
@Cached IOBaseBuiltins.CheckBoolMethodHelperNode checkReadableNode,
@@ -85,7 +91,7 @@ static void doInit(VirtualFrame frame, PBuffered self, Object raw, int bufferSiz
8591
checkReadableNode.checkReadable(frame, inliningTarget, raw);
8692
checkWritableNode.checkWriteable(frame, inliningTarget, raw);
8793
self.setRaw(raw, isFileIO(self, raw, PBufferedRandom, inliningTarget, getSelfClass, getRawClass));
88-
bufferedInitNode.execute(frame, self, bufferSize, factory);
94+
bufferedInitNode.execute(frame, inliningTarget, self, bufferSize, factory);
8995
self.resetRead();
9096
self.resetWrite();
9197
self.setPos(0);
@@ -97,13 +103,16 @@ static void doInit(VirtualFrame frame, PBuffered self, Object raw, int bufferSiz
97103
// BufferedRandom(raw[, buffer_size=DEFAULT_BUFFER_SIZE])
98104
@Builtin(name = J___INIT__, minNumOfPositionalArgs = 2, parameterNames = {"self", "raw", "buffer_size"}, raiseErrorName = "BufferedRandom")
99105
@GenerateNodeFactory
100-
public abstract static class InitNode extends BaseInitNode {
101-
102-
@Child private BufferedRandomInit init = BufferedRandomBuiltinsFactory.BufferedRandomInitNodeGen.create();
103-
104-
@Override
105-
protected final void init(VirtualFrame frame, PBuffered self, Object raw, int bufferSize) {
106-
init.execute(frame, self, raw, bufferSize, factory());
106+
public abstract static class InitNode extends PythonBuiltinNode {
107+
@Specialization
108+
@SuppressWarnings("truffle-static-method") // factory
109+
final Object doIt(VirtualFrame frame, PBuffered self, Object raw, Object bufferSize,
110+
@Bind("this") Node inliningTarget,
111+
@Cached InitBufferSizeNode initBufferSizeNode,
112+
@Cached BufferedRandomInit init) {
113+
int size = initBufferSizeNode.execute(frame, inliningTarget, bufferSize);
114+
init.execute(frame, inliningTarget, self, raw, size, factory());
115+
return PNone.NONE;
107116
}
108117
}
109118
}

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

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,18 @@
4949

5050
import com.oracle.graal.python.builtins.Builtin;
5151
import com.oracle.graal.python.builtins.CoreFunctions;
52-
import com.oracle.graal.python.builtins.modules.io.BufferedReaderBuiltinsFactory.BufferedReaderInitNodeGen;
52+
import com.oracle.graal.python.builtins.objects.PNone;
5353
import com.oracle.graal.python.lib.PyObjectCallMethodObjArgs;
5454
import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
55+
import com.oracle.graal.python.nodes.function.PythonBuiltinNode;
5556
import com.oracle.graal.python.nodes.object.InlinedGetClassNode;
5657
import com.oracle.graal.python.nodes.object.InlinedGetClassNode.GetPythonObjectClassNode;
5758
import com.oracle.graal.python.runtime.PosixSupportLibrary;
5859
import com.oracle.graal.python.runtime.object.PythonObjectFactory;
5960
import com.oracle.truffle.api.dsl.Bind;
6061
import com.oracle.truffle.api.dsl.Cached;
62+
import com.oracle.truffle.api.dsl.GenerateCached;
63+
import com.oracle.truffle.api.dsl.GenerateInline;
6164
import com.oracle.truffle.api.dsl.GenerateNodeFactory;
6265
import com.oracle.truffle.api.dsl.NodeFactory;
6366
import com.oracle.truffle.api.dsl.Specialization;
@@ -71,22 +74,25 @@ protected List<? extends NodeFactory<? extends PythonBuiltinBaseNode>> getNodeFa
7174
return BufferedReaderBuiltinsFactory.getFactories();
7275
}
7376

77+
@GenerateInline
78+
@GenerateCached(false)
7479
public abstract static class BufferedReaderInit extends Node {
7580

76-
public abstract void execute(VirtualFrame frame, PBuffered self, Object raw, int bufferSize, PythonObjectFactory factory);
81+
public abstract void execute(VirtualFrame frame, Node inliningTarget, PBuffered self, Object raw, int bufferSize, PythonObjectFactory factory);
7782

7883
@Specialization
79-
static void doInit(VirtualFrame frame, PBuffered self, Object raw, int bufferSize, PythonObjectFactory factory,
80-
@Bind("this") Node inliningTarget,
84+
static void doInit(VirtualFrame frame, @SuppressWarnings("unused") Node ignored, PBuffered self, Object raw, int bufferSize, PythonObjectFactory factory,
85+
/* @Bind("this") Node inliningTarget, */
8186
@Cached IOBaseBuiltins.CheckBoolMethodHelperNode checkReadableNode,
8287
@Cached BufferedInitNode bufferedInitNode,
8388
@Cached(inline = true) GetPythonObjectClassNode getSelfClass,
8489
@Cached InlinedGetClassNode getRawClass) {
90+
Node inliningTarget = ignored;
8591
self.setOK(false);
8692
self.setDetached(false);
8793
checkReadableNode.checkReadable(frame, inliningTarget, raw);
8894
self.setRaw(raw, isFileIO(self, raw, PBufferedReader, inliningTarget, getSelfClass, getRawClass));
89-
bufferedInitNode.execute(frame, self, bufferSize, factory);
95+
bufferedInitNode.execute(frame, inliningTarget, self, bufferSize, factory);
9096
self.resetRead();
9197
self.setOK(true);
9298
}
@@ -105,13 +111,16 @@ public static void internalInit(PBuffered self, PFileIO raw, int bufferSize, Pyt
105111
// BufferedReader(raw[, buffer_size=DEFAULT_BUFFER_SIZE])
106112
@Builtin(name = J___INIT__, minNumOfPositionalArgs = 2, parameterNames = {"self", "raw", "buffer_size"}, raiseErrorName = "BufferedReader")
107113
@GenerateNodeFactory
108-
public abstract static class InitNode extends BaseInitNode {
109-
110-
@Child private BufferedReaderInit init = BufferedReaderInitNodeGen.create();
111-
112-
@Override
113-
protected final void init(VirtualFrame frame, PBuffered self, Object raw, int bufferSize) {
114-
init.execute(frame, self, raw, bufferSize, factory());
114+
public abstract static class InitNode extends PythonBuiltinNode {
115+
@Specialization
116+
@SuppressWarnings("truffle-static-method") // factory
117+
final Object doIt(VirtualFrame frame, PBuffered self, Object raw, Object bufferSize,
118+
@Bind("this") Node inliningTarget,
119+
@Cached InitBufferSizeNode initBufferSizeNode,
120+
@Cached BufferedReaderInit init) {
121+
int size = initBufferSizeNode.execute(frame, inliningTarget, bufferSize);
122+
init.execute(frame, inliningTarget, self, raw, size, factory());
123+
return PNone.NONE;
115124
}
116125
}
117126

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

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,18 @@
4747

4848
import com.oracle.graal.python.builtins.Builtin;
4949
import com.oracle.graal.python.builtins.CoreFunctions;
50-
import com.oracle.graal.python.builtins.modules.io.BufferedWriterBuiltinsFactory.BufferedWriterInitNodeGen;
5150
import com.oracle.graal.python.builtins.modules.io.IOBaseBuiltins.CheckBoolMethodHelperNode;
51+
import com.oracle.graal.python.builtins.objects.PNone;
5252
import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
53+
import com.oracle.graal.python.nodes.function.PythonBuiltinNode;
5354
import com.oracle.graal.python.nodes.object.InlinedGetClassNode;
5455
import com.oracle.graal.python.nodes.object.InlinedGetClassNode.GetPythonObjectClassNode;
5556
import com.oracle.graal.python.runtime.PosixSupportLibrary;
5657
import com.oracle.graal.python.runtime.object.PythonObjectFactory;
5758
import com.oracle.truffle.api.dsl.Bind;
5859
import com.oracle.truffle.api.dsl.Cached;
60+
import com.oracle.truffle.api.dsl.GenerateCached;
61+
import com.oracle.truffle.api.dsl.GenerateInline;
5962
import com.oracle.truffle.api.dsl.GenerateNodeFactory;
6063
import com.oracle.truffle.api.dsl.NodeFactory;
6164
import com.oracle.truffle.api.dsl.Specialization;
@@ -69,12 +72,14 @@ protected List<? extends NodeFactory<? extends PythonBuiltinBaseNode>> getNodeFa
6972
return BufferedWriterBuiltinsFactory.getFactories();
7073
}
7174

75+
@GenerateInline
76+
@GenerateCached(false)
7277
public abstract static class BufferedWriterInit extends Node {
7378

74-
public abstract void execute(VirtualFrame frame, PBuffered self, Object raw, int bufferSize, PythonObjectFactory factory);
79+
public abstract void execute(VirtualFrame frame, Node inliningTarget, PBuffered self, Object raw, int bufferSize, PythonObjectFactory factory);
7580

7681
@Specialization
77-
static void doInit(VirtualFrame frame, PBuffered self, Object raw, int bufferSize, PythonObjectFactory factory,
82+
static void doInit(VirtualFrame frame, @SuppressWarnings("unused") Node ignored, PBuffered self, Object raw, int bufferSize, PythonObjectFactory factory,
7883
@Bind("this") Node inliningTarget,
7984
@Cached CheckBoolMethodHelperNode checkWritableNode,
8085
@Cached BufferedInitNode bufferedInitNode,
@@ -84,7 +89,7 @@ static void doInit(VirtualFrame frame, PBuffered self, Object raw, int bufferSiz
8489
self.setDetached(false);
8590
checkWritableNode.checkWriteable(frame, inliningTarget, raw);
8691
self.setRaw(raw, isFileIO(self, raw, PBufferedWriter, inliningTarget, getSelfClass, getRawClass));
87-
bufferedInitNode.execute(frame, self, bufferSize, factory);
92+
bufferedInitNode.execute(frame, inliningTarget, self, bufferSize, factory);
8893
self.resetWrite();
8994
self.setPos(0);
9095
self.setOK(true);
@@ -106,13 +111,16 @@ public static void internalInit(PBuffered self, PFileIO raw, int bufferSize, Pyt
106111
// BufferedWriter(raw[, buffer_size=DEFAULT_BUFFER_SIZE])
107112
@Builtin(name = J___INIT__, minNumOfPositionalArgs = 2, parameterNames = {"self", "raw", "buffer_size"}, raiseErrorName = "BufferedWriter")
108113
@GenerateNodeFactory
109-
public abstract static class InitNode extends BaseInitNode {
110-
111-
@Child private BufferedWriterInit init = BufferedWriterInitNodeGen.create();
112-
113-
@Override
114-
protected final void init(VirtualFrame frame, PBuffered self, Object raw, int bufferSize) {
115-
init.execute(frame, self, raw, bufferSize, factory());
114+
public abstract static class InitNode extends PythonBuiltinNode {
115+
@Specialization
116+
@SuppressWarnings("truffle-static-method") // factory
117+
final Object doIt(VirtualFrame frame, PBuffered self, Object raw, Object bufferSize,
118+
@Bind("this") Node inliningTarget,
119+
@Cached InitBufferSizeNode initBufferSizeNode,
120+
@Cached BufferedWriterInit init) {
121+
int size = initBufferSizeNode.execute(frame, inliningTarget, bufferSize);
122+
init.execute(frame, inliningTarget, self, raw, size, factory());
123+
return PNone.NONE;
116124
}
117125
}
118126
}

0 commit comments

Comments
 (0)