Skip to content

Commit 70a15d1

Browse files
committed
static-ing some methods
1 parent 1b5226e commit 70a15d1

File tree

6 files changed

+42
-57
lines changed

6 files changed

+42
-57
lines changed

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

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
import static com.oracle.graal.python.builtins.PythonBuiltinClassType.PIOBase;
5050
import static com.oracle.graal.python.builtins.PythonBuiltinClassType.PStringIO;
5151
import static com.oracle.graal.python.builtins.PythonBuiltinClassType.PTextIOWrapper;
52+
import static com.oracle.graal.python.builtins.modules.io.IONodes.getDict;
5253
import static com.oracle.graal.python.nodes.SpecialAttributeNames.__DICT__;
5354

5455
import java.util.List;
@@ -57,16 +58,13 @@
5758
import com.oracle.graal.python.builtins.CoreFunctions;
5859
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
5960
import com.oracle.graal.python.builtins.objects.PNone;
60-
import com.oracle.graal.python.builtins.objects.dict.PDict;
6161
import com.oracle.graal.python.builtins.objects.object.PythonObject;
6262
import com.oracle.graal.python.builtins.objects.object.PythonObjectLibrary;
6363
import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
6464
import com.oracle.graal.python.nodes.function.builtins.PythonBinaryBuiltinNode;
65-
import com.oracle.truffle.api.CompilerDirectives;
6665
import com.oracle.truffle.api.dsl.GenerateNodeFactory;
6766
import com.oracle.truffle.api.dsl.NodeFactory;
6867
import com.oracle.truffle.api.dsl.Specialization;
69-
import com.oracle.truffle.api.interop.UnsupportedMessageException;
7068
import com.oracle.truffle.api.library.CachedLibrary;
7169

7270
@CoreFunctions(extendClasses = {PIOBase, PFileIO, PStringIO, PTextIOWrapper, PBytesIO,
@@ -85,18 +83,9 @@ protected List<? extends NodeFactory<? extends PythonBuiltinBaseNode>> getNodeFa
8583
public abstract static class DictNode extends PythonBinaryBuiltinNode {
8684

8785
@Specialization(guards = "isNoValue(none)", limit = "2")
88-
protected Object getDict(PythonObject self, @SuppressWarnings("unused") PNone none,
86+
protected Object doit(PythonObject self, @SuppressWarnings("unused") PNone none,
8987
@CachedLibrary("self") PythonObjectLibrary lib) {
90-
PDict dict = lib.getDict(self);
91-
if (dict == null) {
92-
dict = factory().createDictFixedStorage(self);
93-
try {
94-
lib.setDict(self, dict);
95-
} catch (UnsupportedMessageException e) {
96-
throw CompilerDirectives.shouldNotReachHere(e);
97-
}
98-
}
99-
return dict;
88+
return getDict(self, lib, factory());
10089
}
10190

10291
@Specialization

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/common/DynamicObjectStorage.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,7 @@ static int cachedLen(DynamicObjectStorage self,
138138
@Cached(value = "keyArray(self)", dimensions = 1) Object[] keys,
139139
@Exclusive @Cached ReadAttributeFromDynamicObjectNode readNode) {
140140
int len = 0;
141-
for (int i = 0; i < keys.length; i++) {
142-
Object key = keys[i];
141+
for (Object key : keys) {
143142
len = incrementLen(self, readNode, len, key);
144143
}
145144
return len;
@@ -151,8 +150,7 @@ static int cachedKeys(DynamicObjectStorage self,
151150
@Cached(value = "keyArray(self)", dimensions = 1) Object[] keys,
152151
@Exclusive @Cached ReadAttributeFromDynamicObjectNode readNode) {
153152
int len = 0;
154-
for (int i = 0; i < keys.length; i++) {
155-
Object key = keys[i];
153+
for (Object key : keys) {
156154
len = incrementLen(self, readNode, len, key);
157155
}
158156
return len;
@@ -210,8 +208,7 @@ static Object notString(DynamicObjectStorage self, Object key, ThreadState state
210208
@Exclusive @Cached ConditionProfile gotState,
211209
@Exclusive @Cached ConditionProfile noValueProfile) {
212210
long hash = getHashWithState(key, lib, state, gotState);
213-
for (int i = 0; i < keyList.length; i++) {
214-
Object currentKey = keyList[i];
211+
for (Object currentKey : keyList) {
215212
if (currentKey instanceof String) {
216213
if (gotState.profile(state != null)) {
217214
long keyHash = lib.hashWithState(currentKey, state);
@@ -446,8 +443,8 @@ public static HashingStorage copyGeneric(DynamicObjectStorage receiver,
446443
@CachedLibrary(limit = "3") DynamicObjectLibrary dylib) {
447444
DynamicObject copy = new Store(lang.getEmptyShape());
448445
Object[] keys = dylib.getKeyArray(receiver.store);
449-
for (int i = 0; i < keys.length; i++) {
450-
dylib.put(copy, keys[i], dylib.getOrDefault(receiver.store, keys[i], PNone.NO_VALUE));
446+
for (Object key : keys) {
447+
dylib.put(copy, key, dylib.getOrDefault(receiver.store, key, PNone.NO_VALUE));
451448
}
452449
return new DynamicObjectStorage(copy);
453450
}

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

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ private static boolean isBuiltinClassNotModule(Object lazyClass) {
195195
if (lazyClass instanceof PythonBuiltinClass) {
196196
return ((PythonBuiltinClass) lazyClass).getType() != PythonBuiltinClassType.PythonModule;
197197
} else if (lazyClass instanceof PythonBuiltinClassType) {
198-
return ((PythonBuiltinClassType) lazyClass) != PythonBuiltinClassType.PythonModule;
198+
return lazyClass != PythonBuiltinClassType.PythonModule;
199199
}
200200
return false;
201201
}
@@ -235,13 +235,13 @@ public final Object varArgExecute(VirtualFrame frame, @SuppressWarnings("unused"
235235

236236
@Specialization(guards = {"arguments.length == 0", "keywords.length == 0"})
237237
@SuppressWarnings("unused")
238-
public PNone initNoArgs(Object self, Object[] arguments, PKeyword[] keywords) {
238+
static PNone initNoArgs(Object self, Object[] arguments, PKeyword[] keywords) {
239239
return PNone.NONE;
240240
}
241241

242242
@Specialization(replaces = "initNoArgs")
243243
@SuppressWarnings("unused")
244-
public PNone init(Object self, Object[] arguments, PKeyword[] keywords,
244+
PNone init(Object self, Object[] arguments, PKeyword[] keywords,
245245
@Cached GetClassNode getClassNode,
246246
@Cached ConditionProfile overridesNew,
247247
@Cached ConditionProfile overridesInit,
@@ -292,7 +292,7 @@ public static <T extends NodeFactory<? extends PythonBuiltinBaseNode>> boolean o
292292
public abstract static class HashNode extends PythonUnaryBuiltinNode {
293293
@TruffleBoundary
294294
@Specialization
295-
public int hash(Object self) {
295+
public static int hash(Object self) {
296296
return self.hashCode();
297297
}
298298
}
@@ -301,7 +301,7 @@ public int hash(Object self) {
301301
@GenerateNodeFactory
302302
public abstract static class EqNode extends PythonBinaryBuiltinNode {
303303
@Specialization
304-
Object eq(Object self, Object other,
304+
static Object eq(Object self, Object other,
305305
@Cached ConditionProfile isEq,
306306
@Cached IsNode isNode) {
307307
if (isEq.profile(isNode.execute(self, other))) {
@@ -322,7 +322,7 @@ public abstract static class NeNode extends PythonBinaryBuiltinNode {
322322
@Child private CoerceToBooleanNode ifFalseNode;
323323

324324
@Specialization
325-
boolean ne(PythonAbstractNativeObject self, PythonAbstractNativeObject other,
325+
static boolean ne(PythonAbstractNativeObject self, PythonAbstractNativeObject other,
326326
@Cached CExtNodes.PointerCompareNode nativeNeNode) {
327327
return nativeNeNode.execute(__NE__, self, other);
328328
}
@@ -353,7 +353,7 @@ Object ne(VirtualFrame frame, Object self, Object other) {
353353
public abstract static class LtLeGtGeNode extends PythonBinaryBuiltinNode {
354354
@Specialization
355355
@SuppressWarnings("unused")
356-
Object notImplemented(Object self, Object other) {
356+
static Object notImplemented(Object self, Object other) {
357357
return PNotImplemented.NOT_IMPLEMENTED;
358358
}
359359
}
@@ -728,7 +728,7 @@ Object dict(PythonAbstractNativeObject self, @SuppressWarnings("unused") PNone n
728728
}
729729

730730
@Specialization(limit = "1")
731-
Object dict(VirtualFrame frame, @SuppressWarnings("unused") PythonObject self, @SuppressWarnings("unused") DescriptorDeleteMarker marker,
731+
static Object dict(VirtualFrame frame, @SuppressWarnings("unused") PythonObject self, @SuppressWarnings("unused") DescriptorDeleteMarker marker,
732732
@Cached GetClassNode getClassNode,
733733
@Cached GetBaseClassNode getBaseNode,
734734
@Cached("createForLookupOfUnmanagedClasses(__DICT__)") LookupAttributeInMRONode getDescrNode,
@@ -744,8 +744,7 @@ Object dict(VirtualFrame frame, @SuppressWarnings("unused") PythonObject self, @
744744
try {
745745
lib.deleteDict(self);
746746
} catch (UnsupportedMessageException e) {
747-
CompilerDirectives.transferToInterpreterAndInvalidate();
748-
throw new IllegalStateException(e);
747+
throw CompilerDirectives.shouldNotReachHere(e);
749748
}
750749
return PNone.NONE;
751750
}
@@ -808,7 +807,7 @@ abstract static class RichCompareNode extends PythonTernaryBuiltinNode {
808807
protected static final int NO_SLOW_PATH = Integer.MAX_VALUE;
809808
@CompilationFinal private boolean seenNonBoolean = false;
810809

811-
protected BinaryComparisonNode createOp(String op) {
810+
static BinaryComparisonNode createOp(String op) {
812811
return (BinaryComparisonNode) PythonLanguage.getCurrent().getNodeFactory().createComparisonOperation(op, null, null);
813812
}
814813

@@ -835,7 +834,7 @@ boolean richcmp(VirtualFrame frame, Object left, Object right, @SuppressWarnings
835834
@GenerateNodeFactory
836835
abstract static class InitSubclass extends PythonUnaryBuiltinNode {
837836
@Specialization
838-
PNone initSubclass(@SuppressWarnings("unused") Object self) {
837+
static PNone initSubclass(@SuppressWarnings("unused") Object self) {
839838
return PNone.NONE;
840839
}
841840
}
@@ -889,7 +888,7 @@ Object doit(VirtualFrame frame, Object obj,
889888
public abstract static class ReduceNode extends PythonBuiltinNode {
890889
@Specialization
891890
@SuppressWarnings("unused")
892-
Object doit(VirtualFrame frame, Object obj, @SuppressWarnings("unused") Object ignored,
891+
static Object doit(VirtualFrame frame, Object obj, @SuppressWarnings("unused") Object ignored,
893892
@Cached ObjectNodes.CommonReduceNode commonReduceNode) {
894893
return commonReduceNode.execute(frame, obj, 0);
895894
}
@@ -910,7 +909,7 @@ protected ArgumentClinicProvider getArgumentClinic() {
910909

911910
@Specialization
912911
@SuppressWarnings("unused")
913-
Object doit(VirtualFrame frame, Object obj, int proto,
912+
static Object doit(VirtualFrame frame, Object obj, int proto,
914913
@Cached ConditionProfile reduceProfile,
915914
@Cached ObjectNodes.CommonReduceNode commonReduceNode,
916915
@CachedLibrary(limit = "getCallSiteInlineCacheMaxDepth()") PythonObjectLibrary pol) {

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/attributes/WriteAttributeToDynamicObjectNode.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,21 +70,21 @@ public static WriteAttributeToDynamicObjectNode getUncached() {
7070
}
7171

7272
@Specialization(limit = "getAttributeAccessInlineCacheMaxDepth()")
73-
protected boolean writeDirect(DynamicObject dynamicObject, String key, Object value,
73+
static boolean writeDirect(DynamicObject dynamicObject, String key, Object value,
7474
@CachedLibrary("dynamicObject") DynamicObjectLibrary dylib) {
7575
dylib.put(dynamicObject, key, value);
7676
return true;
7777
}
7878

7979
@Specialization(guards = "isHiddenKey(key)", limit = "getAttributeAccessInlineCacheMaxDepth()")
80-
protected boolean writeDirectHidden(DynamicObject dynamicObject, Object key, Object value,
80+
static boolean writeDirectHidden(DynamicObject dynamicObject, Object key, Object value,
8181
@CachedLibrary("dynamicObject") DynamicObjectLibrary dylib) {
8282
dylib.put(dynamicObject, key, value);
8383
return true;
8484
}
8585

8686
@Specialization(guards = "!isHiddenKey(key)", replaces = "writeDirect", limit = "getAttributeAccessInlineCacheMaxDepth()")
87-
protected boolean write(DynamicObject dynamicObject, Object key, Object value,
87+
static boolean write(DynamicObject dynamicObject, Object key, Object value,
8888
@Cached CastToJavaStringNode castNode,
8989
@CachedLibrary("dynamicObject") DynamicObjectLibrary dylib) {
9090
dylib.put(dynamicObject, attrKey(key, castNode), value);

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/attributes/WriteAttributeToObjectNode.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ private static void handlePythonClass(HandlePythonClassProfiles profiles, Python
133133
"isAttrWritable(object, key)",
134134
"isHiddenKey(key) || !lib.hasDict(object)"
135135
}, limit = "1")
136-
protected boolean writeToDynamicStorage(PythonObject object, Object key, Object value,
136+
static boolean writeToDynamicStorage(PythonObject object, Object key, Object value,
137137
@CachedLibrary("object") @SuppressWarnings("unused") PythonObjectLibrary lib,
138138
@Cached WriteAttributeToDynamicObjectNode writeAttributeToDynamicObjectNode,
139139
@Exclusive @Cached HandlePythonClassProfiles handlePythonClassProfiles) {
@@ -149,7 +149,7 @@ protected boolean writeToDynamicStorage(PythonObject object, Object key, Object
149149
"!isHiddenKey(key)",
150150
"lib.hasDict(object)"
151151
}, limit = "1")
152-
protected boolean writeToDict(PythonObject object, Object key, Object value,
152+
static boolean writeToDict(PythonObject object, Object key, Object value,
153153
@CachedLibrary("object") PythonObjectLibrary lib,
154154
@Cached BranchProfile updateStorage,
155155
@CachedLibrary(limit = "1") HashingStorageLibrary hlib,

0 commit comments

Comments
 (0)