Skip to content

Commit 075966a

Browse files
committed
Make non-state variants of POL asSomething methods final
1 parent 4ed05bc commit 075966a

File tree

10 files changed

+122
-135
lines changed

10 files changed

+122
-135
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/PythonBuiltinClassType.java

Lines changed: 50 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,55 @@ static long hashWithState(PythonBuiltinClassType type, ThreadState state,
524524
return lib.hashWithState(context.getCore().lookupType(type), state);
525525
}
526526

527+
@ExportMessage
528+
static Object asIndexWithState(PythonBuiltinClassType type, ThreadState state,
529+
@CachedContext(PythonLanguage.class) PythonContext context,
530+
@CachedLibrary(limit = "1") PythonObjectLibrary lib) {
531+
return lib.asIndexWithState(context.getCore().lookupType(type), state);
532+
}
533+
534+
@ExportMessage
535+
static String asPathWithState(PythonBuiltinClassType type, ThreadState state,
536+
@CachedContext(PythonLanguage.class) PythonContext context,
537+
@CachedLibrary(limit = "1") PythonObjectLibrary lib) {
538+
return lib.asPathWithState(context.getCore().lookupType(type), state);
539+
}
540+
541+
@ExportMessage
542+
static int asFileDescriptorWithState(PythonBuiltinClassType type, ThreadState state,
543+
@CachedContext(PythonLanguage.class) PythonContext context,
544+
@CachedLibrary(limit = "1") PythonObjectLibrary lib) {
545+
return lib.asFileDescriptorWithState(context.getCore().lookupType(type), state);
546+
}
547+
548+
@ExportMessage
549+
static double asJavaDoubleWithState(PythonBuiltinClassType type, ThreadState state,
550+
@CachedContext(PythonLanguage.class) PythonContext context,
551+
@CachedLibrary(limit = "1") PythonObjectLibrary lib) {
552+
return lib.asJavaDoubleWithState(context.getCore().lookupType(type), state);
553+
}
554+
555+
@ExportMessage
556+
static Object asPIntWithState(PythonBuiltinClassType type, ThreadState state,
557+
@CachedContext(PythonLanguage.class) PythonContext context,
558+
@CachedLibrary(limit = "1") PythonObjectLibrary lib) {
559+
return lib.asPIntWithState(context.getCore().lookupType(type), state);
560+
}
561+
562+
@ExportMessage
563+
static long asJavaLongWithState(PythonBuiltinClassType type, ThreadState state,
564+
@CachedContext(PythonLanguage.class) PythonContext context,
565+
@CachedLibrary(limit = "1") PythonObjectLibrary lib) {
566+
return lib.asJavaLongWithState(context.getCore().lookupType(type), state);
567+
}
568+
569+
@ExportMessage
570+
static int asSizeWithState(PythonBuiltinClassType type, Object errorType, ThreadState state,
571+
@CachedContext(PythonLanguage.class) PythonContext context,
572+
@CachedLibrary(limit = "1") PythonObjectLibrary lib) {
573+
return lib.asSizeWithState(context.getCore().lookupType(type), errorType, state);
574+
}
575+
527576
@ExportMessage
528577
static Object getLazyPythonClass(@SuppressWarnings("unused") PythonBuiltinClassType type) {
529578
return PythonClass;
@@ -610,13 +659,8 @@ public static boolean isExceptionType(PythonBuiltinClassType type) {
610659
* {@link com.oracle.graal.python.builtins.objects.type.TypeBuiltins.ReprNode
611660
* TypeBuiltins.ReprNode}
612661
*/
613-
@ExportMessage
614-
String asPString() {
615-
return getQualifiedName();
616-
}
617-
618662
@ExportMessage
619663
String asPStringWithState(@SuppressWarnings("unused") ThreadState state) {
620-
return asPString();
664+
return getQualifiedName();
621665
}
622666
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/floats/PFloat.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import com.oracle.graal.python.PythonLanguage;
2929
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
3030
import com.oracle.graal.python.builtins.objects.cext.capi.PythonNativeWrapperLibrary;
31+
import com.oracle.graal.python.builtins.objects.function.PArguments.ThreadState;
3132
import com.oracle.graal.python.builtins.objects.object.PythonBuiltinObject;
3233
import com.oracle.graal.python.builtins.objects.object.PythonObjectLibrary;
3334
import com.oracle.truffle.api.CompilerAsserts;
@@ -188,7 +189,7 @@ public boolean canBeJavaDouble() {
188189
}
189190

190191
@ExportMessage
191-
public double asJavaDouble() {
192+
public double asJavaDoubleWithState(@SuppressWarnings("unused") ThreadState threadState) {
192193
return value;
193194
}
194195
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/ints/PInt.java

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -245,17 +245,10 @@ public boolean canBeJavaDouble() {
245245
return true;
246246
}
247247

248-
@ExportMessage
249-
public double asJavaDouble(
250-
@CachedLibrary("this") PythonObjectLibrary lib,
251-
@Shared("castToDouble") @Cached CastToJavaDoubleNode castToDouble) {
252-
return castToDouble.execute(lib.asIndex(this));
253-
}
254-
255248
@ExportMessage
256249
public double asJavaDoubleWithState(ThreadState threadState,
257250
@CachedLibrary("this") PythonObjectLibrary lib,
258-
@Shared("castToDouble") @Cached CastToJavaDoubleNode castToDouble) {
251+
@Cached CastToJavaDoubleNode castToDouble) {
259252
return castToDouble.execute(lib.asIndexWithState(this, threadState));
260253
}
261254

@@ -265,15 +258,9 @@ public boolean canBeJavaLong() {
265258
return true;
266259
}
267260

268-
@ExportMessage
269-
public long asJavaLong(
270-
@Cached @Shared("asJavaLong") CastToJavaLongLossyNode castToLong) {
271-
return castToLong.execute(this);
272-
}
273-
274261
@ExportMessage
275262
public long asJavaLongWithState(@SuppressWarnings("unused") ThreadState threadState,
276-
@Cached @Shared("asJavaLong") CastToJavaLongLossyNode castToLong) {
263+
@Cached CastToJavaLongLossyNode castToLong) {
277264
return castToLong.execute(this);
278265
}
279266

@@ -283,11 +270,6 @@ public boolean canBePInt() {
283270
return true;
284271
}
285272

286-
@ExportMessage
287-
public PInt asPInt() {
288-
return this;
289-
}
290-
291273
@ExportMessage
292274
public PInt asPIntWithState(@SuppressWarnings("unused") ThreadState state) {
293275
return this;

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/object/DefaultPythonBooleanExports.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,13 @@ static boolean canBeIndex(@SuppressWarnings("unused") Boolean value) {
7474
}
7575

7676
@ExportMessage
77-
static int asIndex(Boolean value) {
77+
static int asIndexWithState(Boolean value, @SuppressWarnings("unused") ThreadState state) {
7878
return value ? 1 : 0;
7979
}
8080

8181
@ExportMessage
82-
static int asSize(Boolean value, @SuppressWarnings("unused") Object errorType) {
83-
return asIndex(value);
82+
static int asSizeWithState(Boolean value, @SuppressWarnings("unused") Object errorType, ThreadState state) {
83+
return asIndexWithState(value, state);
8484
}
8585

8686
@ExportMessage
@@ -247,12 +247,12 @@ static boolean bO(Boolean receiver, Object other, PythonObjectLibrary oLib, Thre
247247
}
248248

249249
@ExportMessage
250-
static String asPString(Boolean receiver) {
250+
static String asPStringWithState(Boolean receiver, @SuppressWarnings("unused") ThreadState state) {
251251
return receiver ? "True" : "False";
252252
}
253253

254254
@ExportMessage
255-
static int asFileDescriptor(Boolean x) {
255+
static int asFileDescriptorWithState(Boolean x, @SuppressWarnings("unused") ThreadState threadState) {
256256
return x ? 1 : 0;
257257
}
258258

@@ -263,7 +263,7 @@ static boolean canBeJavaDouble(@SuppressWarnings("unused") Boolean receiver) {
263263
}
264264

265265
@ExportMessage
266-
static double asJavaDouble(Boolean receiver) {
266+
static double asJavaDoubleWithState(Boolean receiver, @SuppressWarnings("unused") ThreadState state) {
267267
return receiver ? 1.0 : 0.0;
268268
}
269269

@@ -273,7 +273,7 @@ static boolean canBeJavaLong(@SuppressWarnings("unused") Boolean receiver) {
273273
}
274274

275275
@ExportMessage
276-
static long asJavaLong(Boolean receiver) {
276+
static long asJavaLongWithState(Boolean receiver, @SuppressWarnings("unused") ThreadState state) {
277277
return receiver ? 1 : 0;
278278
}
279279

@@ -283,7 +283,7 @@ static boolean canBePInt(@SuppressWarnings("unused") Boolean receiver) {
283283
}
284284

285285
@ExportMessage
286-
static int asPInt(Boolean receiver) {
286+
static int asPIntWithState(Boolean receiver, @SuppressWarnings("unused") ThreadState state) {
287287
return receiver ? 1 : 0;
288288
}
289289

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/object/DefaultPythonDoubleExports.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -193,12 +193,12 @@ static int dO(Double receiver, Object other, @SuppressWarnings("unused") ThreadS
193193
}
194194

195195
@ExportMessage
196-
static Object asPString(Double receiver,
196+
static Object asPStringWithState(Double receiver, ThreadState state,
197197
@CachedLibrary("receiver") PythonObjectLibrary lib,
198198
@CachedLibrary(limit = "1") PythonObjectLibrary resultLib,
199199
@Shared("isSubtypeNode") @Cached IsSubtypeNode isSubtypeNode,
200200
@Exclusive @Cached PRaiseNode raise) {
201-
return PythonAbstractObject.asPString(lib, receiver, null, isSubtypeNode, resultLib, raise);
201+
return PythonAbstractObject.asPString(lib, receiver, state, isSubtypeNode, resultLib, raise);
202202
}
203203

204204
@SuppressWarnings("static-method")
@@ -208,7 +208,7 @@ static boolean canBeJavaDouble(@SuppressWarnings("unused") Double receiver) {
208208
}
209209

210210
@ExportMessage
211-
static double asJavaDouble(Double receiver) {
211+
static double asJavaDoubleWithState(Double receiver, @SuppressWarnings("unused") ThreadState state) {
212212
return receiver;
213213
}
214214

@@ -218,7 +218,7 @@ static boolean canBeJavaLong(@SuppressWarnings("unused") Double receiver) {
218218
}
219219

220220
@ExportMessage
221-
static long asJavaLong(Double receiver,
221+
static long asJavaLongWithState(Double receiver, @SuppressWarnings("unused") ThreadState state,
222222
@Exclusive @Cached PRaiseNode raise) {
223223
throw raise.raise(TypeError, ErrorMessages.MUST_BE_NUMERIC, receiver);
224224
}
@@ -229,7 +229,7 @@ static boolean canBePInt(@SuppressWarnings("unused") Double receiver) {
229229
}
230230

231231
@ExportMessage
232-
static int asPInt(Double receiver,
232+
static int asPIntWithState(Double receiver, @SuppressWarnings("unused") ThreadState state,
233233
@Exclusive @Cached PRaiseNode raise) {
234234
throw raise.raise(TypeError, ErrorMessages.OBJ_CANNOT_BE_INTERPRETED_AS_INTEGER, receiver);
235235
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/object/DefaultPythonIntegerExports.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,12 @@ static boolean canBeIndex(@SuppressWarnings("unused") Integer value) {
7878
}
7979

8080
@ExportMessage
81-
static int asIndex(Integer value) {
81+
static int asIndexWithState(Integer value, @SuppressWarnings("unused") ThreadState state) {
8282
return value;
8383
}
8484

8585
@ExportMessage
86-
static int asSize(Integer value, @SuppressWarnings("unused") Object errorType) {
86+
static int asSizeWithState(Integer value, @SuppressWarnings("unused") Object errorType, @SuppressWarnings("unused") ThreadState state) {
8787
return value;
8888
}
8989

@@ -252,12 +252,12 @@ static boolean iO(Integer receiver, Object other, PythonObjectLibrary oLib, Thre
252252

253253
@ExportMessage
254254
@CompilerDirectives.TruffleBoundary
255-
static String asPString(Integer receiver) {
255+
static String asPStringWithState(Integer receiver, @SuppressWarnings("unused") ThreadState state) {
256256
return Integer.toString(receiver);
257257
}
258258

259259
@ExportMessage
260-
static int asFileDescriptor(Integer x) {
260+
static int asFileDescriptorWithState(Integer x, @SuppressWarnings("unused") ThreadState state) {
261261
return x;
262262
}
263263

@@ -268,7 +268,7 @@ static boolean canBeJavaDouble(@SuppressWarnings("unused") Integer receiver) {
268268
}
269269

270270
@ExportMessage
271-
static double asJavaDouble(Integer receiver) {
271+
static double asJavaDoubleWithState(Integer receiver, @SuppressWarnings("unused") ThreadState state) {
272272
return receiver.doubleValue();
273273
}
274274

@@ -278,7 +278,7 @@ static boolean canBeJavaLong(@SuppressWarnings("unused") Integer receiver) {
278278
}
279279

280280
@ExportMessage
281-
static long asJavaLong(Integer receiver) {
281+
static long asJavaLongWithState(Integer receiver, @SuppressWarnings("unused") ThreadState state) {
282282
return receiver;
283283
}
284284

@@ -288,7 +288,7 @@ static boolean canBePInt(@SuppressWarnings("unused") Integer receiver) {
288288
}
289289

290290
@ExportMessage
291-
static int asPInt(Integer receiver) {
291+
static int asPIntWithState(Integer receiver, @SuppressWarnings("unused") ThreadState state) {
292292
return receiver;
293293
}
294294

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/object/DefaultPythonLongExports.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -83,19 +83,19 @@ static boolean canBeIndex(@SuppressWarnings("unused") Long value) {
8383
}
8484

8585
@ExportMessage
86-
static Object asIndex(Long value) {
86+
static Object asIndexWithState(Long value, @SuppressWarnings("unused") ThreadState state) {
8787
return value;
8888
}
8989

9090
@ExportMessage
91-
static class AsSize {
91+
static class AsSizeWithState {
9292
@Specialization(rewriteOn = OverflowException.class)
93-
static int noOverflow(Long self, @SuppressWarnings("unused") Object type) throws OverflowException {
93+
static int noOverflow(Long self, @SuppressWarnings("unused") Object type, @SuppressWarnings("unused") ThreadState state) throws OverflowException {
9494
return PInt.intValueExact(self);
9595
}
9696

9797
@Specialization(replaces = "noOverflow")
98-
static int withOverflow(Long self, Object type,
98+
static int withOverflow(Long self, Object type, @SuppressWarnings("unused") ThreadState state,
9999
@Exclusive @Cached PRaiseNode raise) {
100100
try {
101101
return PInt.intValueExact(self);
@@ -275,12 +275,12 @@ static boolean lO(Long receiver, Object other, PythonObjectLibrary oLib, ThreadS
275275

276276
@ExportMessage
277277
@TruffleBoundary
278-
static String asPString(Long x) {
278+
static String asPStringWithState(Long x, @SuppressWarnings("unused") ThreadState state) {
279279
return Long.toString(x);
280280
}
281281

282282
@ExportMessage
283-
static int asFileDescriptor(Long x,
283+
static int asFileDescriptorWithState(Long x, @SuppressWarnings("unused") ThreadState state,
284284
@Exclusive @Cached PRaiseNode raiseNode,
285285
@Exclusive @Cached CastToJavaIntExactNode castToJavaIntNode,
286286
@Exclusive @Cached IsBuiltinClassProfile errorProfile) {
@@ -300,7 +300,7 @@ static boolean canBeJavaDouble(@SuppressWarnings("unused") Long receiver) {
300300
}
301301

302302
@ExportMessage
303-
static double asJavaDouble(Long receiver) {
303+
static double asJavaDoubleWithState(Long receiver, @SuppressWarnings("unused") ThreadState state) {
304304
return receiver.doubleValue();
305305
}
306306

@@ -310,7 +310,7 @@ static boolean canBeJavaLong(@SuppressWarnings("unused") Long receiver) {
310310
}
311311

312312
@ExportMessage
313-
static long asJavaLong(Long receiver) {
313+
static long asJavaLongWithState(Long receiver, @SuppressWarnings("unused") ThreadState state) {
314314
return receiver;
315315
}
316316

@@ -320,7 +320,7 @@ static boolean canBePInt(@SuppressWarnings("unused") Long receiver) {
320320
}
321321

322322
@ExportMessage
323-
static long asPInt(Long receiver) {
323+
static long asPIntWithState(Long receiver, @SuppressWarnings("unused") ThreadState state) {
324324
return receiver;
325325
}
326326

0 commit comments

Comments
 (0)