Skip to content

Commit 2f96fbd

Browse files
committed
shared some cached nodes PythonCextBuiltins
1 parent e3ed7db commit 2f96fbd

File tree

1 file changed

+24
-53
lines changed

1 file changed

+24
-53
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/PythonCextBuiltins.java

Lines changed: 24 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,6 @@
223223
import com.oracle.graal.python.builtins.objects.getsetdescriptor.GetSetDescriptor;
224224
import com.oracle.graal.python.builtins.objects.ints.PInt;
225225
import com.oracle.graal.python.builtins.objects.iterator.PSequenceIterator;
226-
import com.oracle.graal.python.builtins.objects.list.ListBuiltins;
227226
import com.oracle.graal.python.builtins.objects.list.ListBuiltins.ListExtendNode;
228227
import com.oracle.graal.python.builtins.objects.list.ListBuiltins.ListInsertNode;
229228
import com.oracle.graal.python.builtins.objects.list.ListBuiltins.ListSortNode;
@@ -1164,7 +1163,7 @@ public Object keys(VirtualFrame frame, PDict obj,
11641163
@Cached KeysNode keysNode,
11651164
@Cached ConstructListNode listNode,
11661165
@Cached TransformExceptionToNativeNode transformExceptionToNativeNode,
1167-
@Cached GetNativeNullNode getNativeNullNode) {
1166+
@Shared("nativeNull") @Cached GetNativeNullNode getNativeNullNode) {
11681167
try {
11691168
return listNode.execute(frame, keysNode.execute(frame, obj));
11701169
} catch (PException e) {
@@ -1179,7 +1178,7 @@ public Object keys(VirtualFrame frame, Object obj,
11791178
@Cached CallNode callNode,
11801179
@Cached ConstructListNode listNode,
11811180
@Cached TransformExceptionToNativeNode transformExceptionToNativeNode,
1182-
@Cached GetNativeNullNode getNativeNullNode) {
1181+
@Shared("nativeNull") @Cached GetNativeNullNode getNativeNullNode) {
11831182
try {
11841183
return getKeys(frame, obj, getAttrNode, callNode, listNode);
11851184
} catch (PException e) {
@@ -1203,7 +1202,7 @@ public Object items(VirtualFrame frame, PDict obj,
12031202
@Cached ItemsNode itemsNode,
12041203
@Cached ConstructListNode listNode,
12051204
@Cached TransformExceptionToNativeNode transformExceptionToNativeNode,
1206-
@Cached GetNativeNullNode getNativeNullNode) {
1205+
@Shared("nativeNull") @Cached GetNativeNullNode getNativeNullNode) {
12071206
try {
12081207
return listNode.execute(frame, itemsNode.execute(frame, obj));
12091208
} catch (PException e) {
@@ -1218,7 +1217,7 @@ public Object items(VirtualFrame frame, Object obj,
12181217
@Cached CallNode callNode,
12191218
@Cached ConstructListNode listNode,
12201219
@Cached TransformExceptionToNativeNode transformExceptionToNativeNode,
1221-
@Cached GetNativeNullNode getNativeNullNode) {
1220+
@Shared("nativeNull") @Cached GetNativeNullNode getNativeNullNode) {
12221221
try {
12231222
Object attr = getAttrNode.execute(frame, obj, ITEMS);
12241223
return listNode.execute(frame, callNode.execute(frame, attr));
@@ -1237,7 +1236,7 @@ public Object values(VirtualFrame frame, PDict obj,
12371236
@Cached ConstructListNode listNode,
12381237
@Cached ValuesNode valuesNode,
12391238
@Cached TransformExceptionToNativeNode transformExceptionToNativeNode,
1240-
@Cached GetNativeNullNode getNativeNullNode) {
1239+
@Shared("nativeNull") @Cached GetNativeNullNode getNativeNullNode) {
12411240
try {
12421241
return listNode.execute(frame, valuesNode.execute(frame, obj));
12431242
} catch (PException e) {
@@ -1252,7 +1251,7 @@ public Object values(VirtualFrame frame, Object obj,
12521251
@Cached CallNode callNode,
12531252
@Cached ConstructListNode listNode,
12541253
@Cached TransformExceptionToNativeNode transformExceptionToNativeNode,
1255-
@Cached GetNativeNullNode getNativeNullNode) {
1254+
@Shared("nativeNull") @Cached GetNativeNullNode getNativeNullNode) {
12561255
try {
12571256
Object attr = getAttrNode.execute(frame, obj, VALUES);
12581257
return listNode.execute(frame, callNode.execute(frame, attr));
@@ -1410,20 +1409,20 @@ public Object contains(VirtualFrame frame, PFrozenSet anyset, Object item,
14101409
}
14111410
}
14121411

1413-
@Specialization(guards = "isSetSubtype(frame, anyset, getClassNode, isSubtypeNode)")
1412+
@Specialization(guards = "isSetSubtype(frame, anyset, getClassNode, isSubtypeNode)", limit = "1")
14141413
public Object containsNative(VirtualFrame frame, @SuppressWarnings("unused") Object anyset, @SuppressWarnings("unused") Object item,
14151414
@SuppressWarnings("unused") @Cached GetClassNode getClassNode,
14161415
@SuppressWarnings("unused") @Cached IsSubtypeNode isSubtypeNode,
1417-
@Cached PRaiseNativeNode raiseNativeNode) {
1416+
@Shared("raiseNative") @Cached PRaiseNativeNode raiseNativeNode) {
14181417
return raiseNativeNode.raiseInt(frame, -1, PythonBuiltinClassType.NotImplementedError, NATIVE_S_SUBTYPES_NOT_IMPLEMENTED, "set");
14191418
}
14201419

1421-
@Specialization(guards = {"!isPSet(anyset)", "!isPFrozenSet(anyset)", "!isSetSubtype(frame, anyset, getClassNode, isSubtypeNode)"})
1420+
@Specialization(guards = {"!isPSet(anyset)", "!isPFrozenSet(anyset)", "!isSetSubtype(frame, anyset, getClassNode, isSubtypeNode)"}, limit = "1")
14221421
public Object contains(VirtualFrame frame, Object anyset, @SuppressWarnings("unused") Object item,
14231422
@SuppressWarnings("unused") @Cached GetClassNode getClassNode,
14241423
@SuppressWarnings("unused") @Cached IsSubtypeNode isSubtypeNode,
14251424
@Cached StrNode strNode,
1426-
@Cached PRaiseNativeNode raiseNativeNode) {
1425+
@Shared("raiseNative") @Cached PRaiseNativeNode raiseNativeNode) {
14271426
return raiseNativeNode.raiseInt(frame, -1, SystemError, BAD_ARG_TO_INTERNAL_FUNC_WAS_S_P, strNode.executeWith(frame, anyset), anyset);
14281427
}
14291428

@@ -1679,17 +1678,19 @@ public Object concat(VirtualFrame frame, PBytes original, PBytes newPart,
16791678
public Object concatNative(VirtualFrame frame, @SuppressWarnings("unused") Object obj,
16801679
@SuppressWarnings("unused") @Cached GetClassNode getClassNode,
16811680
@SuppressWarnings("unused") @Cached IsSubtypeNode isSubtypeNode,
1681+
@Cached GetNativeNullNode getNativeNullNode,
16821682
@Cached PRaiseNativeNode raiseNativeNode) {
1683-
return raiseNativeNode.raiseInt(frame, -1, PythonBuiltinClassType.NotImplementedError, NATIVE_S_SUBTYPES_NOT_IMPLEMENTED, "bytes");
1683+
return raiseNativeNode.raise(frame, getNativeNullNode.execute(), PythonBuiltinClassType.NotImplementedError, NATIVE_S_SUBTYPES_NOT_IMPLEMENTED, "bytes");
16841684
}
16851685

16861686
@Specialization(guards = {"!isPBytes(obj)", "!isBytesSubtype(frame, obj, getClassNode, isSubtypeNode)"})
16871687
public Object concat(VirtualFrame frame, Object obj,
16881688
@SuppressWarnings("unused") @Cached GetClassNode getClassNode,
16891689
@SuppressWarnings("unused") @Cached IsSubtypeNode isSubtypeNode,
16901690
@Cached StrNode strNode,
1691+
@Cached GetNativeNullNode getNativeNullNode,
16911692
@Cached PRaiseNativeNode raiseNativeNode) {
1692-
return raiseNativeNode.raiseInt(frame, -1, SystemError, BAD_ARG_TO_INTERNAL_FUNC_WAS_S_P, strNode.executeWith(frame, obj), obj);
1693+
return raiseNativeNode.raise(frame, getNativeNullNode.execute(), SystemError, BAD_ARG_TO_INTERNAL_FUNC_WAS_S_P, strNode.executeWith(frame, obj), obj);
16931694
}
16941695

16951696
protected boolean isBytesSubtype(VirtualFrame frame, Object obj, GetClassNode getClassNode, IsSubtypeNode isSubtypeNode) {
@@ -1717,17 +1718,19 @@ public Object join(VirtualFrame frame, PBytes original, PBytes newPart,
17171718
public Object joinNative(VirtualFrame frame, @SuppressWarnings("unused") Object obj,
17181719
@SuppressWarnings("unused") @Cached GetClassNode getClassNode,
17191720
@SuppressWarnings("unused") @Cached IsSubtypeNode isSubtypeNode,
1720-
@Cached PRaiseNativeNode raiseNativeNode) {
1721-
return raiseNativeNode.raiseInt(frame, -1, PythonBuiltinClassType.NotImplementedError, NATIVE_S_SUBTYPES_NOT_IMPLEMENTED, "bytes");
1721+
@Cached PRaiseNativeNode raiseNativeNode,
1722+
@Cached GetNativeNullNode getNativeNullNode) {
1723+
return raiseNativeNode.raise(frame, getNativeNullNode.execute(), PythonBuiltinClassType.NotImplementedError, NATIVE_S_SUBTYPES_NOT_IMPLEMENTED, "bytes");
17221724
}
17231725

17241726
@Specialization(guards = {"!isPBytes(obj)", "!isBytesSubtype(frame, obj, getClassNode, isSubtypeNode)"})
17251727
public Object join(VirtualFrame frame, Object obj,
17261728
@SuppressWarnings("unused") @Cached GetClassNode getClassNode,
17271729
@SuppressWarnings("unused") @Cached IsSubtypeNode isSubtypeNode,
17281730
@Cached StrNode strNode,
1729-
@Cached PRaiseNativeNode raiseNativeNode) {
1730-
return raiseNativeNode.raiseInt(frame, -1, SystemError, BAD_ARG_TO_INTERNAL_FUNC_WAS_S_P, strNode.executeWith(frame, obj), obj);
1731+
@Cached PRaiseNativeNode raiseNativeNode,
1732+
@Cached GetNativeNullNode getNativeNullNode) {
1733+
return raiseNativeNode.raise(frame, getNativeNullNode.execute(), SystemError, BAD_ARG_TO_INTERNAL_FUNC_WAS_S_P, strNode.executeWith(frame, obj), obj);
17311734
}
17321735

17331736
protected boolean isBytesSubtype(VirtualFrame frame, Object obj, GetClassNode getClassNode, IsSubtypeNode isSubtypeNode) {
@@ -1809,15 +1812,15 @@ protected boolean isAcceptedSubtype(VirtualFrame frame, Object obj, GetClassNode
18091812
public abstract static class PyListNewNode extends PythonUnaryBuiltinNode {
18101813
@Specialization(guards = "size < 0")
18111814
public Object newList(VirtualFrame frame, int size,
1812-
@Cached PRaiseNativeNode raiseNativeNode,
1813-
@Cached GetNativeNullNode getNativeNullNode) {
1815+
@Shared("raiseNative") @Cached PRaiseNativeNode raiseNativeNode,
1816+
@Shared("nativeNull") @Cached GetNativeNullNode getNativeNullNode) {
18141817
return raiseNativeNode.raise(frame, getNativeNullNode.execute(), SystemError, BAD_ARG_TO_INTERNAL_FUNC_S, size);
18151818
}
18161819

18171820
@Specialization(guards = "size < 0")
18181821
public Object newList(VirtualFrame frame, long size,
1819-
@Cached PRaiseNativeNode raiseNativeNode,
1820-
@Cached GetNativeNullNode getNativeNullNode) {
1822+
@Shared("raiseNative") @Cached PRaiseNativeNode raiseNativeNode,
1823+
@Shared("nativeNull") @Cached GetNativeNullNode getNativeNullNode) {
18211824
return raiseNativeNode.raise(frame, getNativeNullNode.execute(), SystemError, BAD_ARG_TO_INTERNAL_FUNC_S, size);
18221825
}
18231826

@@ -1856,32 +1859,11 @@ Object getItem(VirtualFrame frame, @SuppressWarnings("unused") Object list, @Sup
18561859
return raiseNativeNode.raise(frame, getNativeNullNode.execute(), PythonBuiltinClassType.IndexError, LIST_INDEX_OUT_OF_RANGE);
18571860
}
18581861

1859-
@SuppressWarnings("unused")
1860-
@Specialization(guards = "pos < 0")
1861-
Object getItem(VirtualFrame frame, @SuppressWarnings("unused") Object list, @SuppressWarnings("unused") int pos,
1862-
@Cached PRaiseNativeNode raiseNativeNode,
1863-
@Cached GetNativeNullNode getNativeNullNode) {
1864-
return raiseNativeNode.raise(frame, getNativeNullNode.execute(), PythonBuiltinClassType.IndexError, LIST_INDEX_OUT_OF_RANGE);
1865-
}
1866-
1867-
@Specialization(guards = "pos >= 0")
1868-
Object getItem(VirtualFrame frame, PList list, int pos,
1869-
@Cached com.oracle.graal.python.builtins.objects.list.ListBuiltins.GetItemNode getItemNode,
1870-
@Cached TransformExceptionToNativeNode transformExceptionToNativeNode,
1871-
@Cached GetNativeNullNode getNativeNullNode) {
1872-
return getItemWithInt(frame, list, pos, getItemNode, transformExceptionToNativeNode, getNativeNullNode);
1873-
}
1874-
18751862
@Specialization(guards = "pos >= 0")
18761863
Object getItem(VirtualFrame frame, PList list, long pos,
18771864
@Cached com.oracle.graal.python.builtins.objects.list.ListBuiltins.GetItemNode getItemNode,
18781865
@Cached TransformExceptionToNativeNode transformExceptionToNativeNode,
18791866
@Cached GetNativeNullNode getNativeNullNode) {
1880-
return getItemWithInt(frame, list, (int) pos, getItemNode, transformExceptionToNativeNode, getNativeNullNode);
1881-
}
1882-
1883-
private static Object getItemWithInt(VirtualFrame frame, PList list, int pos, ListBuiltins.GetItemNode getItemNode, TransformExceptionToNativeNode transformExceptionToNativeNode,
1884-
GetNativeNullNode getNativeNullNode) {
18851867
try {
18861868
return getItemNode.execute(frame, list, pos);
18871869
} catch (PException e) {
@@ -2204,17 +2186,6 @@ abstract static class PyListInsertNode extends PythonTernaryBuiltinNode {
22042186
Object append(VirtualFrame frame, PList list, int i, Object item,
22052187
@Cached ListInsertNode insertNode,
22062188
@Cached TransformExceptionToNativeNode transformExceptionToNativeNode) {
2207-
return insert(frame, list, i, item, insertNode, transformExceptionToNativeNode);
2208-
}
2209-
2210-
@Specialization
2211-
Object append(VirtualFrame frame, PList list, long i, Object item,
2212-
@Cached ListInsertNode insertNode,
2213-
@Cached TransformExceptionToNativeNode transformExceptionToNativeNode) {
2214-
return insert(frame, list, (int) i, item, insertNode, transformExceptionToNativeNode);
2215-
}
2216-
2217-
private static int insert(VirtualFrame frame, PList list, int i, Object item, ListInsertNode insertNode, TransformExceptionToNativeNode transformExceptionToNativeNode) {
22182189
try {
22192190
insertNode.execute(frame, list, i, item);
22202191
return 0;

0 commit comments

Comments
 (0)