Skip to content

Commit 06d90ff

Browse files
committed
[GR-26317] Prefer implementing the 'withState' variants of PythonObjectLibrary messages.
PullRequest: graalpython/1296
2 parents b8ed041 + 80f3a07 commit 06d90ff

File tree

5 files changed

+19
-8
lines changed

5 files changed

+19
-8
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -514,10 +514,10 @@ static boolean isMappingType(PythonBuiltinClassType type,
514514
}
515515

516516
@ExportMessage
517-
static long hash(PythonBuiltinClassType type,
517+
static long hashWithState(PythonBuiltinClassType type, ThreadState state,
518518
@CachedContext(PythonLanguage.class) PythonContext context,
519519
@CachedLibrary(limit = "1") PythonObjectLibrary lib) {
520-
return lib.hash(context.getCore().lookupType(type));
520+
return lib.hashWithState(context.getCore().lookupType(type), state);
521521
}
522522

523523
@ExportMessage

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/PythonNativeVoidPtr.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ public String toString() {
117117
}
118118

119119
@ExportMessage(limit = "2")
120-
long hash(
120+
long hashWithState(@SuppressWarnings("unused") ThreadState state,
121121
@CachedLibrary("this.getPointerObject()") InteropLibrary lib) {
122122
if (lib.hasIdentity(object)) {
123123
try {

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ public Object asIndexWithState(@SuppressWarnings("unused") ThreadState threadSta
228228
}
229229

230230
@ExportMessage
231-
public int asFileDescriptor(
231+
public int asFileDescriptorWithState(@SuppressWarnings("unused") ThreadState state,
232232
@Exclusive @Cached PRaiseNode raiseNode,
233233
@Exclusive @Cached CastToJavaIntExactNode castToJavaIntNode) {
234234
try {
@@ -287,6 +287,11 @@ public PInt asPInt() {
287287
return this;
288288
}
289289

290+
@ExportMessage
291+
public PInt asPIntWithState(@SuppressWarnings("unused") ThreadState state) {
292+
return this;
293+
}
294+
290295
@Override
291296
public int hashCode() {
292297
return value.hashCode();
@@ -563,6 +568,11 @@ public long hash() {
563568
return hashBigInteger(value);
564569
}
565570

571+
@ExportMessage
572+
public long hashWithState(@SuppressWarnings("unused") ThreadState state) {
573+
return hash();
574+
}
575+
566576
@TruffleBoundary
567577
public static long hashBigInteger(BigInteger i) {
568578
long h = i.remainder(BigInteger.valueOf(SysModuleBuiltins.HASH_MODULUS)).longValue();

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/range/PBigRange.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,17 +131,17 @@ public BigInteger getBigIntItemNormalized(BigInteger index) {
131131
}
132132

133133
@ExportMessage
134-
public int length(@CachedLibrary("this.length") PythonObjectLibrary pol,
134+
public int lengthWithState(@SuppressWarnings("unused") ThreadState state, @CachedLibrary("this.length") PythonObjectLibrary pol,
135135
@Cached PRaiseNode raiseNode) {
136136
if (pol.canBeIndex(length)) {
137-
return pol.asSize(length);
137+
return pol.asSizeWithState(length, state);
138138
}
139139
throw raiseNode.raiseNumberTooLarge(OverflowError, length);
140140
}
141141

142142
@ExportMessage
143143
@TruffleBoundary
144-
public boolean isTrue() {
144+
public boolean isTrueWithState(@SuppressWarnings("unused") ThreadState state) {
145145
return length.getValue().compareTo(BigInteger.ZERO) != 0;
146146
}
147147

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/range/PRange.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
package com.oracle.graal.python.builtins.objects.range;
2727

2828
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
29+
import com.oracle.graal.python.builtins.objects.function.PArguments.ThreadState;
2930
import com.oracle.graal.python.builtins.objects.object.PythonBuiltinObject;
3031
import com.oracle.graal.python.builtins.objects.object.PythonObjectLibrary;
3132
import com.oracle.truffle.api.CompilerDirectives;
@@ -70,7 +71,7 @@ public boolean isIterable() {
7071
}
7172

7273
@ExportMessage
73-
public String asPString() {
74+
public String asPStringWithState(@SuppressWarnings("unused") ThreadState state) {
7475
return toString();
7576
}
7677

0 commit comments

Comments
 (0)