Skip to content

Commit e89c49e

Browse files
committed
Make non-state variants of remaining POL methods final
1 parent 075966a commit e89c49e

File tree

9 files changed

+38
-50
lines changed

9 files changed

+38
-50
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ static long hash(boolean value) {
104104
}
105105

106106
@ExportMessage
107-
static boolean isTrue(Boolean value) {
107+
static boolean isTrueWithState(Boolean value, @SuppressWarnings("unused") ThreadState threadState) {
108108
return value;
109109
}
110110

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ static long hash(double number) {
121121
}
122122

123123
@ExportMessage
124-
static boolean isTrue(Double value) {
124+
static boolean isTrueWithState(Double value, @SuppressWarnings("unused") ThreadState threadState) {
125125
return value != 0.0;
126126
}
127127

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ static long hash(int value) {
103103
}
104104

105105
@ExportMessage
106-
static boolean isTrue(Integer value) {
106+
static boolean isTrueWithState(Integer value, @SuppressWarnings("unused") ThreadState threadState) {
107107
return value != 0;
108108
}
109109

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ static long hash(long value) {
126126
}
127127

128128
@ExportMessage
129-
static boolean isTrue(Long value) {
129+
static boolean isTrueWithState(Long value, @SuppressWarnings("unused") ThreadState threadState) {
130130
return value != 0;
131131
}
132132

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

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ static long hashWithState(Object receiver, @SuppressWarnings("unused") ThreadSta
139139
}
140140

141141
@ExportMessage
142-
static int length(Object receiver,
142+
static int lengthWithState(Object receiver, @SuppressWarnings("unused") ThreadState threadState,
143143
@Shared("raiseNode") @Cached PRaiseNode raise,
144144
@CachedLibrary("receiver") InteropLibrary interopLib) {
145145
if (interopLib.hasArrayElements(receiver)) {
@@ -161,9 +161,9 @@ static int length(Object receiver,
161161
}
162162

163163
@ExportMessage
164-
static class IsTrue {
164+
static class IsTrueWithState {
165165
@Specialization(guards = "lib.isBoolean(receiver)")
166-
static boolean bool(Object receiver,
166+
static boolean bool(Object receiver, @SuppressWarnings("unused") ThreadState threadState,
167167
@CachedLibrary("receiver") InteropLibrary lib) {
168168
try {
169169
return lib.asBoolean(receiver);
@@ -174,7 +174,7 @@ static boolean bool(Object receiver,
174174
}
175175

176176
@Specialization(guards = "lib.fitsInLong(receiver)")
177-
static boolean integer(Object receiver,
177+
static boolean integer(Object receiver, @SuppressWarnings("unused") ThreadState threadState,
178178
@CachedLibrary("receiver") InteropLibrary lib) {
179179
try {
180180
return lib.asLong(receiver) != 0;
@@ -185,7 +185,7 @@ static boolean integer(Object receiver,
185185
}
186186

187187
@Specialization(guards = "lib.fitsInDouble(receiver)")
188-
static boolean floatingPoint(Object receiver,
188+
static boolean floatingPoint(Object receiver, @SuppressWarnings("unused") ThreadState threadState,
189189
@CachedLibrary("receiver") InteropLibrary lib) {
190190
try {
191191
return lib.asDouble(receiver) != 0.0;
@@ -196,7 +196,7 @@ static boolean floatingPoint(Object receiver,
196196
}
197197

198198
@Specialization(guards = "lib.hasArrayElements(receiver)")
199-
static boolean array(Object receiver,
199+
static boolean array(Object receiver, @SuppressWarnings("unused") ThreadState threadState,
200200
@CachedLibrary("receiver") InteropLibrary lib) {
201201
try {
202202
return lib.getArraySize(receiver) > 0;
@@ -210,7 +210,7 @@ static boolean array(Object receiver,
210210
"!lib.isBoolean(receiver)", "!lib.fitsInLong(receiver)",
211211
"!lib.fitsInDouble(receiver)", "!lib.hasArrayElements(receiver)"
212212
})
213-
static boolean generic(Object receiver,
213+
static boolean generic(Object receiver, @SuppressWarnings("unused") ThreadState threadState,
214214
@CachedLibrary("receiver") InteropLibrary lib) {
215215
return !lib.isNull(receiver);
216216
}
@@ -361,10 +361,10 @@ static Object lookupAndCallRegularMethodWithState(Object receiver, ThreadState s
361361
}
362362

363363
@ExportMessage
364-
abstract static class GetIterator {
364+
abstract static class GetIteratorWithState {
365365

366366
@Specialization(guards = "lib.hasArrayElements(receiver)")
367-
static PForeignArrayIterator doForeignArray(Object receiver,
367+
static PForeignArrayIterator doForeignArray(Object receiver, @SuppressWarnings("unused") ThreadState threadState,
368368
@Shared("factory") @Cached PythonObjectFactory factory,
369369
@Shared("raiseNode") @Cached PRaiseNode raiseNode,
370370
@CachedLibrary("receiver") InteropLibrary lib) {
@@ -380,7 +380,7 @@ static PForeignArrayIterator doForeignArray(Object receiver,
380380
}
381381

382382
@Specialization(guards = "lib.isString(receiver)")
383-
static PStringIterator doBoxedString(Object receiver,
383+
static PStringIterator doBoxedString(Object receiver, @SuppressWarnings("unused") ThreadState threadState,
384384
@Shared("factory") @Cached PythonObjectFactory factory,
385385
@CachedLibrary("receiver") InteropLibrary lib) {
386386
try {
@@ -391,15 +391,15 @@ static PStringIterator doBoxedString(Object receiver,
391391
}
392392

393393
@Specialization(replaces = {"doForeignArray", "doBoxedString"})
394-
static PythonBuiltinObject doGeneric(Object receiver,
394+
static PythonBuiltinObject doGeneric(Object receiver, ThreadState threadState,
395395
@Shared("factory") @Cached PythonObjectFactory factory,
396396
@Shared("raiseNode") @Cached PRaiseNode raiseNode,
397397
@CachedLibrary("receiver") InteropLibrary lib) {
398398

399399
if (lib.hasArrayElements(receiver)) {
400-
return doForeignArray(receiver, factory, raiseNode, lib);
400+
return doForeignArray(receiver, threadState, factory, raiseNode, lib);
401401
} else if (lib.isString(receiver)) {
402-
return doBoxedString(receiver, factory, lib);
402+
return doBoxedString(receiver, threadState, factory, lib);
403403
}
404404
throw raiseNode.raise(TypeError, ErrorMessages.FOREIGN_OBJ_ISNT_ITERABLE);
405405
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,12 +107,12 @@ static long hashWithState(String self, @SuppressWarnings("unused") ThreadState s
107107
}
108108

109109
@ExportMessage
110-
static int length(String self) {
110+
static int lengthWithState(String self, @SuppressWarnings("unused") ThreadState threadState) {
111111
return self.length();
112112
}
113113

114114
@ExportMessage
115-
static boolean isTrue(String self) {
115+
static boolean isTrueWithState(String self, @SuppressWarnings("unused") ThreadState threadState) {
116116
return self.length() > 0;
117117
}
118118

@@ -243,7 +243,7 @@ static boolean typeCheck(@SuppressWarnings("unused") String receiver, Object typ
243243
}
244244

245245
@ExportMessage
246-
static PStringIterator getIterator(String receiver,
246+
static PStringIterator getIteratorWithState(String receiver, @SuppressWarnings("unused") ThreadState threadState,
247247
@Cached PythonObjectFactory factory) {
248248
return factory.createStringIterator(receiver);
249249
}

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

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -932,16 +932,13 @@ public boolean isSequence(Object receiver) {
932932
* {@code slot_nb_bool} coercion and {@link #length}/{@link #lengthWithState}.
933933
*/
934934
public boolean isTrueWithState(Object receiver, ThreadState state) {
935-
if (state == null) {
936-
return true;
937-
}
938-
return isTrue(receiver);
935+
return true;
939936
}
940937

941938
/**
942939
* @see #isTrueWithState
943940
*/
944-
public boolean isTrue(Object receiver) {
941+
public final boolean isTrue(Object receiver) {
945942
return isTrueWithState(receiver, null);
946943
}
947944

@@ -967,16 +964,13 @@ public final boolean isTrue(Object receiver, VirtualFrame frame) {
967964
* that slot.
968965
*/
969966
public int lengthWithState(Object receiver, ThreadState state) {
970-
if (state == null) {
971-
throw PRaiseNode.getUncached().raiseHasNoLength(receiver);
972-
}
973-
return length(receiver);
967+
throw PRaiseNode.getUncached().raiseHasNoLength(receiver);
974968
}
975969

976970
/**
977971
* @see #lengthWithState
978972
*/
979-
public int length(Object receiver) {
973+
public final int length(Object receiver) {
980974
return lengthWithState(receiver, null);
981975
}
982976

@@ -1102,16 +1096,13 @@ public boolean typeCheck(Object receiver, Object type) {
11021096
* Implements the logic from {@code PyObject_GetIter}.
11031097
*/
11041098
public Object getIteratorWithState(Object receiver, ThreadState state) {
1105-
if (state == null) {
1106-
throw PRaiseNode.getUncached().raise(PythonBuiltinClassType.TypeError, ErrorMessages.OBJ_NOT_ITERABLE, receiver);
1107-
}
1108-
return getIterator(receiver);
1099+
throw PRaiseNode.getUncached().raise(PythonBuiltinClassType.TypeError, ErrorMessages.OBJ_NOT_ITERABLE, receiver);
11091100
}
11101101

11111102
/**
11121103
* @see #getIteratorWithState
11131104
*/
1114-
public Object getIterator(Object receiver) {
1105+
public final Object getIterator(Object receiver) {
11151106
return getIteratorWithState(receiver, null);
11161107
}
11171108

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

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -118,12 +118,7 @@ public int lengthWithState(@SuppressWarnings("unused") ThreadState state) {
118118
}
119119

120120
@ExportMessage
121-
public boolean isTrue() {
122-
return length != 0;
123-
}
124-
125-
@ExportMessage
126-
public boolean isTrueWithState(@SuppressWarnings("unused") ThreadState state) {
121+
public boolean isTrueWithState(@SuppressWarnings("unused") ThreadState threadState) {
127122
return length != 0;
128123
}
129124

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/set/PBaseSet.java

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,15 @@
2929
import com.oracle.graal.python.builtins.objects.common.HashingStorage;
3030
import com.oracle.graal.python.builtins.objects.common.HashingStorageLibrary;
3131
import com.oracle.graal.python.builtins.objects.common.PHashingCollection;
32-
import com.oracle.graal.python.builtins.objects.function.PArguments;
32+
import com.oracle.graal.python.builtins.objects.function.PArguments.ThreadState;
3333
import com.oracle.graal.python.builtins.objects.object.PythonObjectLibrary;
34+
import com.oracle.truffle.api.dsl.Cached;
35+
import com.oracle.truffle.api.dsl.Cached.Exclusive;
3436
import com.oracle.truffle.api.library.CachedLibrary;
3537
import com.oracle.truffle.api.library.ExportLibrary;
3638
import com.oracle.truffle.api.library.ExportMessage;
3739
import com.oracle.truffle.api.object.Shape;
40+
import com.oracle.truffle.api.profiles.ConditionProfile;
3841

3942
@ExportLibrary(PythonObjectLibrary.class)
4043
public abstract class PBaseSet extends PHashingCollection {
@@ -62,14 +65,13 @@ public void setDictStorage(HashingStorage storage) {
6265
}
6366

6467
@ExportMessage(limit = "1")
65-
int lengthWithState(PArguments.ThreadState state,
68+
int lengthWithState(ThreadState state,
69+
@Exclusive @Cached ConditionProfile gotState,
6670
@CachedLibrary("this.set") HashingStorageLibrary lib) {
67-
return lib.lengthWithState(set, state);
68-
}
69-
70-
@ExportMessage(limit = "1")
71-
int length(
72-
@CachedLibrary("this.set") HashingStorageLibrary lib) {
73-
return lib.length(set);
71+
if (gotState.profile(state != null)) {
72+
return lib.lengthWithState(set, state);
73+
} else {
74+
return lib.length(set);
75+
}
7476
}
7577
}

0 commit comments

Comments
 (0)