Skip to content

Commit 3ff7c6a

Browse files
committed
Resolve DSL warnings the io and json modules
1 parent b64f051 commit 3ff7c6a

12 files changed

+165
-193
lines changed

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2021, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2021, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* The Universal Permissive License (UPL), Version 1.0
@@ -64,7 +64,8 @@
6464
import com.oracle.graal.python.nodes.function.builtins.PythonBinaryClinicBuiltinNode;
6565
import com.oracle.graal.python.nodes.function.builtins.PythonUnaryBuiltinNode;
6666
import com.oracle.graal.python.nodes.function.builtins.clinic.ArgumentClinicProvider;
67-
import com.oracle.graal.python.nodes.object.GetClassNode;
67+
import com.oracle.graal.python.nodes.object.InlinedGetClassNode;
68+
import com.oracle.graal.python.nodes.object.InlinedGetClassNode.GetPythonObjectClassNode;
6869
import com.oracle.graal.python.runtime.PosixSupportLibrary;
6970
import com.oracle.graal.python.runtime.PosixSupportLibrary.PosixException;
7071
import com.oracle.graal.python.runtime.PythonOptions;
@@ -123,10 +124,10 @@ public static void internalInit(PBuffered self, int bufferSize, PythonObjectFact
123124
}
124125

125126
protected static boolean isFileIO(PBuffered self, Object raw, PythonBuiltinClassType type,
126-
GetClassNode getSelfClass, GetClassNode getRawClass) {
127+
Node inliningTarget, GetPythonObjectClassNode getSelfClass, InlinedGetClassNode getRawClass) {
127128
return raw instanceof PFileIO &&
128-
getSelfClass.execute(self) == type &&
129-
getRawClass.execute(raw) == PythonBuiltinClassType.PFileIO;
129+
getSelfClass.execute(inliningTarget, self) == type &&
130+
getRawClass.execute(inliningTarget, raw) == PythonBuiltinClassType.PFileIO;
130131
}
131132

132133
public abstract static class BaseInitNode extends PythonBuiltinNode {

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ static Object doit(VirtualFrame frame, PBuffered self,
155155
@Cached InlinedConditionProfile profile) {
156156
try {
157157
lock.enter(self);
158-
if (profile.profile(inliningTarget, isClosedNode.execute(frame, self))) {
158+
if (profile.profile(inliningTarget, isClosedNode.execute(frame, inliningTarget, self))) {
159159
return PNone.NONE;
160160
}
161161
if (self.isFinalizing()) {
@@ -357,8 +357,9 @@ static Object doit(PBuffered self) {
357357
abstract static class ClosedNode extends PythonUnaryWithInitErrorBuiltinNode {
358358
@Specialization(guards = "self.isOK()")
359359
static Object doit(VirtualFrame frame, PBuffered self,
360+
@Bind("this") Node inliningTarget,
360361
@Cached BufferedIONodes.IsClosedNode isClosedNode) {
361-
return isClosedNode.execute(frame, self);
362+
return isClosedNode.execute(frame, inliningTarget, self);
362363
}
363364
}
364365

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

Lines changed: 17 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,9 @@
4646
import static com.oracle.graal.python.builtins.modules.io.BufferedIOUtil.rawOffset;
4747
import static com.oracle.graal.python.builtins.modules.io.BufferedIOUtil.readahead;
4848
import static com.oracle.graal.python.builtins.modules.io.IONodes.T_CLOSED;
49-
import static com.oracle.graal.python.builtins.modules.io.IONodes.T_READABLE;
5049
import static com.oracle.graal.python.builtins.modules.io.IONodes.T_SEEK;
5150
import static com.oracle.graal.python.builtins.modules.io.IONodes.T_SEEKABLE;
5251
import static com.oracle.graal.python.builtins.modules.io.IONodes.T_TELL;
53-
import static com.oracle.graal.python.builtins.modules.io.IONodes.T_WRITABLE;
5452
import static com.oracle.graal.python.nodes.ErrorMessages.CANNOT_FIT_P_IN_OFFSET_SIZE;
5553
import static com.oracle.graal.python.nodes.ErrorMessages.FILE_OR_STREAM_IS_NOT_SEEKABLE;
5654
import static com.oracle.graal.python.nodes.ErrorMessages.IO_STREAM_INVALID_POS;
@@ -85,6 +83,8 @@
8583
import com.oracle.truffle.api.dsl.Bind;
8684
import com.oracle.truffle.api.dsl.Cached;
8785
import com.oracle.truffle.api.dsl.Cached.Shared;
86+
import com.oracle.truffle.api.dsl.GenerateCached;
87+
import com.oracle.truffle.api.dsl.GenerateInline;
8888
import com.oracle.truffle.api.dsl.ImportStatic;
8989
import com.oracle.truffle.api.dsl.NeverDefault;
9090
import com.oracle.truffle.api.dsl.Specialization;
@@ -110,35 +110,38 @@ public CheckIsClosedNode(TruffleString method) {
110110

111111
@Specialization
112112
boolean isClosedBuffered(VirtualFrame frame, PBuffered self,
113-
@Cached PRaiseNode raiseNode,
113+
@Bind("this") Node inliningTarget,
114+
@Cached PRaiseNode.Lazy raiseNode,
114115
@Cached IsClosedNode isClosedNode) {
115-
if (isClosedNode.execute(frame, self)) {
116-
throw raiseNode.raise(PythonBuiltinClassType.ValueError, messageFmt, method);
116+
if (isClosedNode.execute(frame, inliningTarget, self)) {
117+
throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.ValueError, messageFmt, method);
117118
}
118119
return false;
119120
}
120121
}
121122

123+
@GenerateInline
124+
@GenerateCached(false)
122125
abstract static class IsClosedNode extends PNodeWithContext {
123126

124-
public abstract boolean execute(VirtualFrame frame, PBuffered self);
127+
public abstract boolean execute(VirtualFrame frame, Node inliningTarget, PBuffered self);
125128

126129
@SuppressWarnings("unused")
127130
@Specialization(guards = {"self.getBuffer() == null"})
128-
static boolean isClosed(VirtualFrame frame, PBuffered self) {
131+
static boolean isClosed(PBuffered self) {
129132
return true;
130133
}
131134

132135
@SuppressWarnings("unused")
133136
@Specialization(guards = {"self.getBuffer() != null", "self.isFastClosedChecks()"})
134-
static boolean isClosedFileIO(VirtualFrame frame, PBuffered self) {
137+
static boolean isClosedFileIO(PBuffered self) {
135138
return self.getFileIORaw().isClosed();
136139
}
137140

138141
@Specialization(guards = {"self.getBuffer() != null", "!self.isFastClosedChecks()"})
139142
static boolean isClosedBuffered(VirtualFrame frame, PBuffered self,
140-
@Cached PyObjectGetAttr getAttr,
141-
@Cached PyObjectIsTrueNode isTrue) {
143+
@Cached(inline = false) PyObjectGetAttr getAttr,
144+
@Cached(inline = false) PyObjectIsTrueNode isTrue) {
142145
Object res = getAttr.execute(frame, self.getRaw(), T_CLOSED);
143146
return isTrue.execute(frame, res);
144147
}
@@ -150,52 +153,14 @@ abstract static class CheckIsSeekabledNode extends PNodeWithRaise {
150153

151154
@Specialization
152155
boolean isSeekable(VirtualFrame frame, PBuffered self,
153-
@Bind("this") Node inliningTarget,
154-
@Cached IsSeekableNode isSeekableNode) {
155-
if (!isSeekableNode.execute(frame, self)) {
156-
throw raise(IOUnsupportedOperation, FILE_OR_STREAM_IS_NOT_SEEKABLE);
157-
}
158-
return true;
159-
}
160-
}
161-
162-
abstract static class IsSeekableNode extends Node {
163-
164-
public abstract boolean execute(VirtualFrame frame, PBuffered self);
165-
166-
@Specialization
167-
static boolean isSeekable(VirtualFrame frame, PBuffered self,
168156
@Cached PyObjectCallMethodObjArgs callMethod,
169157
@Cached PyObjectIsTrueNode isTrue) {
170158
assert self.isOK();
171159
Object res = callMethod.execute(frame, self.getRaw(), T_SEEKABLE);
172-
return isTrue.execute(frame, res);
173-
}
174-
}
175-
176-
abstract static class IsReadableNode extends Node {
177-
178-
public abstract boolean execute(VirtualFrame frame, Object raw);
179-
180-
@Specialization
181-
static boolean isReadable(VirtualFrame frame, Object raw,
182-
@Cached PyObjectCallMethodObjArgs callMethod,
183-
@Cached PyObjectIsTrueNode isTrue) {
184-
Object res = callMethod.execute(frame, raw, T_READABLE);
185-
return isTrue.execute(frame, res);
186-
}
187-
}
188-
189-
abstract static class IsWritableNode extends PNodeWithContext {
190-
191-
public abstract boolean execute(VirtualFrame frame, Object raw);
192-
193-
@Specialization
194-
static boolean isWritable(VirtualFrame frame, Object raw,
195-
@Cached PyObjectCallMethodObjArgs callMethod,
196-
@Cached PyObjectIsTrueNode isTrue) {
197-
Object res = callMethod.execute(frame, raw, T_WRITABLE);
198-
return isTrue.execute(frame, res);
160+
if (!isTrue.execute(frame, res)) {
161+
throw raise(IOUnsupportedOperation, FILE_OR_STREAM_IS_NOT_SEEKABLE);
162+
}
163+
return true;
199164
}
200165
}
201166

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -120,12 +120,13 @@ protected ArgumentClinicProvider getArgumentClinic() {
120120

121121
@Specialization
122122
public PNone doInit(VirtualFrame frame, PRWPair self, Object reader, Object writer, int bufferSize,
123-
@Cached IOBaseBuiltins.CheckReadableNode checkReadableNode,
124-
@Cached IOBaseBuiltins.CheckWritableNode checkWritableNode,
123+
@Bind("this") Node inliningTarget,
124+
@Cached IOBaseBuiltins.CheckBoolMethodHelperNode checkReadableNode,
125+
@Cached IOBaseBuiltins.CheckBoolMethodHelperNode checkWritableNode,
125126
@Cached BufferedReaderBuiltins.BufferedReaderInit initReaderNode,
126127
@Cached BufferedWriterBuiltins.BufferedWriterInit initWriterNode) {
127-
checkReadableNode.execute(frame, reader);
128-
checkWritableNode.execute(frame, writer);
128+
checkReadableNode.checkReadable(frame, inliningTarget, reader);
129+
checkWritableNode.checkWriteable(frame, inliningTarget, writer);
129130
self.setReader(factory().createBufferedReader(PBufferedReader));
130131
initReaderNode.execute(frame, self.getReader(), reader, bufferSize, factory());
131132
self.setWriter(factory().createBufferedWriter(PBufferedWriter));

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

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2021, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2021, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* The Universal Permissive License (UPL), Version 1.0
@@ -48,8 +48,10 @@
4848
import com.oracle.graal.python.builtins.Builtin;
4949
import com.oracle.graal.python.builtins.CoreFunctions;
5050
import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
51-
import com.oracle.graal.python.nodes.object.GetClassNode;
51+
import com.oracle.graal.python.nodes.object.InlinedGetClassNode;
52+
import com.oracle.graal.python.nodes.object.InlinedGetClassNode.GetPythonObjectClassNode;
5253
import com.oracle.graal.python.runtime.object.PythonObjectFactory;
54+
import com.oracle.truffle.api.dsl.Bind;
5355
import com.oracle.truffle.api.dsl.Cached;
5456
import com.oracle.truffle.api.dsl.GenerateNodeFactory;
5557
import com.oracle.truffle.api.dsl.NodeFactory;
@@ -70,18 +72,19 @@ public abstract static class BufferedRandomInit extends Node {
7072

7173
@Specialization
7274
static void doInit(VirtualFrame frame, PBuffered self, Object raw, int bufferSize, PythonObjectFactory factory,
73-
@Cached IOBaseBuiltins.CheckSeekableNode checkSeekableNode,
74-
@Cached IOBaseBuiltins.CheckReadableNode checkReadableNode,
75-
@Cached IOBaseBuiltins.CheckWritableNode checkWritableNode,
75+
@Bind("this") Node inliningTarget,
76+
@Cached IOBaseBuiltins.CheckBoolMethodHelperNode checkSeekableNode,
77+
@Cached IOBaseBuiltins.CheckBoolMethodHelperNode checkReadableNode,
78+
@Cached IOBaseBuiltins.CheckBoolMethodHelperNode checkWritableNode,
7679
@Cached BufferedInitNode bufferedInitNode,
77-
@Cached GetClassNode getSelfClass,
78-
@Cached GetClassNode getRawClass) {
80+
@Cached(inline = true) GetPythonObjectClassNode getSelfClass,
81+
@Cached InlinedGetClassNode getRawClass) {
7982
self.setOK(false);
8083
self.setDetached(false);
81-
checkSeekableNode.execute(frame, raw);
82-
checkReadableNode.execute(frame, raw);
83-
checkWritableNode.execute(frame, raw);
84-
self.setRaw(raw, isFileIO(self, raw, PBufferedRandom, getSelfClass, getRawClass));
84+
checkSeekableNode.checkSeekable(frame, inliningTarget, raw);
85+
checkReadableNode.checkReadable(frame, inliningTarget, raw);
86+
checkWritableNode.checkWriteable(frame, inliningTarget, raw);
87+
self.setRaw(raw, isFileIO(self, raw, PBufferedRandom, inliningTarget, getSelfClass, getRawClass));
8588
bufferedInitNode.execute(frame, self, bufferSize, factory);
8689
self.resetRead();
8790
self.resetWrite();

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

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2020, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2020, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* The Universal Permissive License (UPL), Version 1.0
@@ -52,9 +52,11 @@
5252
import com.oracle.graal.python.builtins.modules.io.BufferedReaderBuiltinsFactory.BufferedReaderInitNodeGen;
5353
import com.oracle.graal.python.lib.PyObjectCallMethodObjArgs;
5454
import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
55-
import com.oracle.graal.python.nodes.object.GetClassNode;
55+
import com.oracle.graal.python.nodes.object.InlinedGetClassNode;
56+
import com.oracle.graal.python.nodes.object.InlinedGetClassNode.GetPythonObjectClassNode;
5657
import com.oracle.graal.python.runtime.PosixSupportLibrary;
5758
import com.oracle.graal.python.runtime.object.PythonObjectFactory;
59+
import com.oracle.truffle.api.dsl.Bind;
5860
import com.oracle.truffle.api.dsl.Cached;
5961
import com.oracle.truffle.api.dsl.GenerateNodeFactory;
6062
import com.oracle.truffle.api.dsl.NodeFactory;
@@ -75,14 +77,15 @@ public abstract static class BufferedReaderInit extends Node {
7577

7678
@Specialization
7779
static void doInit(VirtualFrame frame, PBuffered self, Object raw, int bufferSize, PythonObjectFactory factory,
78-
@Cached IOBaseBuiltins.CheckReadableNode checkReadableNode,
80+
@Bind("this") Node inliningTarget,
81+
@Cached IOBaseBuiltins.CheckBoolMethodHelperNode checkReadableNode,
7982
@Cached BufferedInitNode bufferedInitNode,
80-
@Cached GetClassNode getSelfClass,
81-
@Cached GetClassNode getRawClass) {
83+
@Cached(inline = true) GetPythonObjectClassNode getSelfClass,
84+
@Cached InlinedGetClassNode getRawClass) {
8285
self.setOK(false);
8386
self.setDetached(false);
84-
checkReadableNode.execute(frame, raw);
85-
self.setRaw(raw, isFileIO(self, raw, PBufferedReader, getSelfClass, getRawClass));
87+
checkReadableNode.checkReadable(frame, inliningTarget, raw);
88+
self.setRaw(raw, isFileIO(self, raw, PBufferedReader, inliningTarget, getSelfClass, getRawClass));
8689
bufferedInitNode.execute(frame, self, bufferSize, factory);
8790
self.resetRead();
8891
self.setOK(true);

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@
9393
import com.oracle.graal.python.nodes.call.special.CallUnaryMethodNode;
9494
import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
9595
import com.oracle.graal.python.nodes.function.builtins.clinic.ArgumentClinicProvider;
96-
import com.oracle.graal.python.nodes.object.GetClassNode;
96+
import com.oracle.graal.python.nodes.object.InlinedGetClassNode;
9797
import com.oracle.graal.python.runtime.exception.PException;
9898
import com.oracle.graal.python.runtime.object.PythonObjectFactory;
9999
import com.oracle.graal.python.util.PythonUtils;
@@ -374,7 +374,7 @@ Object bufferedreaderReadAll(VirtualFrame frame, PBuffered self, @SuppressWarnin
374374
@Cached InlinedConditionProfile hasReadallProfile,
375375
@Cached InlinedConditionProfile currentSize0Profile,
376376
@Cached CallUnaryMethodNode dispatchGetattribute,
377-
@Cached GetClassNode getClassNode,
377+
@Cached InlinedGetClassNode getClassNode,
378378
@Cached PyObjectCallMethodObjArgs callMethod,
379379
@CachedLibrary(limit = "1") PythonBufferAccessLibrary bufferLib) {
380380
checkIsClosedNode.execute(frame, self);
@@ -395,7 +395,7 @@ Object bufferedreaderReadAll(VirtualFrame frame, PBuffered self, @SuppressWarnin
395395

396396
self.resetRead(); // _bufferedreader_reset_buf
397397

398-
Object clazz = getClassNode.execute(self.getRaw());
398+
Object clazz = getClassNode.execute(inliningTarget, self.getRaw());
399399
Object readall = readallAttr.execute(clazz);
400400
if (hasReadallProfile.profile(inliningTarget, readall != PNone.NO_VALUE)) {
401401
Object tmp = dispatchGetattribute.executeObject(frame, readall, self.getRaw());

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

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2021, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2021, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* The Universal Permissive License (UPL), Version 1.0
@@ -48,11 +48,13 @@
4848
import com.oracle.graal.python.builtins.Builtin;
4949
import com.oracle.graal.python.builtins.CoreFunctions;
5050
import com.oracle.graal.python.builtins.modules.io.BufferedWriterBuiltinsFactory.BufferedWriterInitNodeGen;
51-
import com.oracle.graal.python.builtins.modules.io.IOBaseBuiltins.CheckWritableNode;
51+
import com.oracle.graal.python.builtins.modules.io.IOBaseBuiltins.CheckBoolMethodHelperNode;
5252
import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
53-
import com.oracle.graal.python.nodes.object.GetClassNode;
53+
import com.oracle.graal.python.nodes.object.InlinedGetClassNode;
54+
import com.oracle.graal.python.nodes.object.InlinedGetClassNode.GetPythonObjectClassNode;
5455
import com.oracle.graal.python.runtime.PosixSupportLibrary;
5556
import com.oracle.graal.python.runtime.object.PythonObjectFactory;
57+
import com.oracle.truffle.api.dsl.Bind;
5658
import com.oracle.truffle.api.dsl.Cached;
5759
import com.oracle.truffle.api.dsl.GenerateNodeFactory;
5860
import com.oracle.truffle.api.dsl.NodeFactory;
@@ -73,14 +75,15 @@ public abstract static class BufferedWriterInit extends Node {
7375

7476
@Specialization
7577
static void doInit(VirtualFrame frame, PBuffered self, Object raw, int bufferSize, PythonObjectFactory factory,
76-
@Cached CheckWritableNode checkWritableNode,
78+
@Bind("this") Node inliningTarget,
79+
@Cached CheckBoolMethodHelperNode checkWritableNode,
7780
@Cached BufferedInitNode bufferedInitNode,
78-
@Cached GetClassNode getSelfClass,
79-
@Cached GetClassNode getRawClass) {
81+
@Cached(inline = true) GetPythonObjectClassNode getSelfClass,
82+
@Cached InlinedGetClassNode getRawClass) {
8083
self.setOK(false);
8184
self.setDetached(false);
82-
checkWritableNode.execute(frame, raw);
83-
self.setRaw(raw, isFileIO(self, raw, PBufferedWriter, getSelfClass, getRawClass));
85+
checkWritableNode.checkWriteable(frame, inliningTarget, raw);
86+
self.setRaw(raw, isFileIO(self, raw, PBufferedWriter, inliningTarget, getSelfClass, getRawClass));
8487
bufferedInitNode.execute(frame, self, bufferSize, factory);
8588
self.resetWrite();
8689
self.setPos(0);

0 commit comments

Comments
 (0)