Skip to content

Commit 7cb38ae

Browse files
committed
[GR-21590] Update imports
PullRequest: graalpython/3330
2 parents db44e52 + 789d78a commit 7cb38ae

File tree

17 files changed

+128
-58
lines changed

17 files changed

+128
-58
lines changed

ci.jsonnet

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{ "overlay": "6d170b8abc2a32d4754de9fd3f9a42d2fc50b326" }
1+
{ "overlay": "73fcc2d1867f06242f46b4f2622f1857a6419993" }

graalpython/com.oracle.graal.python.processor/src/com/oracle/graal/python/processor/CApiBuiltinsProcessor.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -599,9 +599,9 @@ private void generateCApiHeader(List<CApiBuiltinDesc> javaBuiltins, Map<String,
599599
}
600600
}
601601

602-
/**
603-
* Adding constants for methods flags checks in
604-
* {@link NativeCAPISymbol.FUN_GET_METHODS_FLAGS}
602+
/*
603+
* Adding constants for methods flags checks in {@link
604+
* NativeCAPISymbol.FUN_GET_METHODS_FLAGS}
605605
*/
606606
lines.add("");
607607
methodFlags.entrySet().stream().sorted((a, b) -> a.getValue().compareTo(b.getValue())).forEach(e -> lines.add("#define " + e.getKey() + " " + e.getValue()));

graalpython/com.oracle.graal.python.test.integration/src/com/oracle/graal/python/test/integration/interop/JavaInteropTest.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -595,6 +595,25 @@ public void writableBindings() {
595595
assertEquals(javaObj.asInt(), 42);
596596
}
597597

598+
@Test
599+
public void testDictTypeConversion() {
600+
Value bindings = context.getBindings("python");
601+
bindings.putMember("foo", "32");
602+
bindings.putMember("bar", (short) 32);
603+
Value intValue = context.eval("python", "int(foo) + int(bar)");
604+
assertEquals(intValue.asInt(), 64);
605+
}
606+
607+
@Test
608+
public void testListTypeConversions() {
609+
Value intConversion = context.eval("python", "int");
610+
Value list = context.eval("python", "[1]");
611+
list.setArrayElement(0, "32");
612+
assertEquals(intConversion.execute(list.getArrayElement(0)).asInt(), 32);
613+
list.setArrayElement(0, (short) 3);
614+
assertEquals(intConversion.execute(list.getArrayElement(0)).asInt(), 3);
615+
}
616+
598617
public class UnsupportedProxyHashMap implements ProxyHashMap {
599618
@Override
600619
public long getHashSize() {

graalpython/com.oracle.graal.python.test/src/tests/unittest_tags/test_module.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
*graalpython.lib-python.3.test.test_module.ModuleTests.test_unicode_docstring
3131
*graalpython.lib-python.3.test.test_module.ModuleTests.test_uninitialized
3232
*graalpython.lib-python.3.test.test_module.ModuleTests.test_uninitialized_missing_getattr
33-
*graalpython.lib-python.3.test.test_module.ModuleTests.test_weakref
3433
*graalpython.lib-python.3.test.test_module.__init__.ModuleTests.test_annotations_are_created_correctly
3534
*graalpython.lib-python.3.test.test_module.__init__.ModuleTests.test_annotations_getset_raises
3635
*graalpython.lib-python.3.test.test_module.__init__.ModuleTests.test_ascii_docstring

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/PythonAbstractObject.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,13 +227,14 @@ public final void clearNativeWrapper() {
227227
public void writeMember(String key, Object value,
228228
@Bind("$node") Node inliningTarget,
229229
@Exclusive @Cached TruffleString.FromJavaStringNode fromJavaStringNode,
230+
@Shared @Cached PForeignToPTypeNode convert,
230231
@Exclusive @Cached PyObjectSetAttr setAttributeNode,
231232
// GR-44020: make shared:
232233
@Exclusive @Cached IsBuiltinObjectProfile attrErrorProfile,
233234
@Exclusive @Cached GilNode gil) throws UnsupportedMessageException, UnknownIdentifierException {
234235
boolean mustRelease = gil.acquire();
235236
try {
236-
setAttributeNode.execute(null, inliningTarget, this, fromJavaStringNode.execute(key, TS_ENCODING), value);
237+
setAttributeNode.execute(null, inliningTarget, this, fromJavaStringNode.execute(key, TS_ENCODING), convert.executeConvert(value));
237238
} catch (PException e) {
238239
e.expectAttributeError(inliningTarget, attrErrorProfile);
239240
// TODO(fa) not accurate; distinguish between read-only and non-existing
@@ -325,10 +326,12 @@ public void writeArrayElement(long key, Object value,
325326
@Bind("$node") Node inliningTarget,
326327
@Shared("getBehavior") @Cached GetInteropBehaviorNode getBehavior,
327328
@Shared("getValue") @Cached GetInteropBehaviorValueNode getValue,
329+
@Shared @Cached PForeignToPTypeNode convert,
328330
@Cached PySequenceSetItemNode sequenceSetItemNode,
329331
@Exclusive @Cached GilNode gil) throws UnsupportedMessageException, InvalidArrayIndexException {
330332
boolean mustRelease = gil.acquire();
331333
try {
334+
value = convert.executeConvert(value);
332335
InteropBehaviorMethod method = InteropBehaviorMethod.write_array_element;
333336
InteropBehavior behavior = getBehavior.execute(inliningTarget, this, method);
334337
if (behavior != null) {
@@ -1520,7 +1523,7 @@ public static String objectHashCodeAsHexString(Object value) {
15201523

15211524
@ExportMessage
15221525
public TriState isIdenticalOrUndefined(Object otherInterop,
1523-
@Cached PForeignToPTypeNode convert,
1526+
@Shared @Cached PForeignToPTypeNode convert,
15241527
@Exclusive @CachedLibrary(limit = "3") InteropLibrary otherLib,
15251528
@Cached IsNode isNode,
15261529
@Exclusive @Cached GilNode gil) {

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/array/PArray.java

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
import com.oracle.graal.python.builtins.objects.object.PythonBuiltinObject;
4444
import com.oracle.graal.python.nodes.ErrorMessages;
4545
import com.oracle.graal.python.nodes.PRaiseNode;
46+
import com.oracle.graal.python.nodes.interop.PForeignToPTypeNode;
4647
import com.oracle.graal.python.runtime.GilNode;
4748
import com.oracle.graal.python.runtime.sequence.storage.ByteSequenceStorage;
4849
import com.oracle.graal.python.runtime.sequence.storage.NativeByteSequenceStorage;
@@ -55,6 +56,7 @@
5556
import com.oracle.truffle.api.CompilerDirectives.CompilationFinal;
5657
import com.oracle.truffle.api.dsl.Bind;
5758
import com.oracle.truffle.api.dsl.Cached;
59+
import com.oracle.truffle.api.dsl.Cached.Exclusive;
5860
import com.oracle.truffle.api.dsl.Cached.Shared;
5961
import com.oracle.truffle.api.interop.InteropLibrary;
6062
import com.oracle.truffle.api.interop.InvalidArrayIndexException;
@@ -345,8 +347,8 @@ public long getArraySize() {
345347
@ExportMessage
346348
public Object readArrayElement(long index,
347349
@Bind("$node") Node inliningTarget,
348-
@Cached.Exclusive @Cached SequenceStorageNodes.GetItemScalarNode getItem,
349-
@Cached.Exclusive @Cached GilNode gil) throws InvalidArrayIndexException {
350+
@Exclusive @Cached SequenceStorageNodes.GetItemScalarNode getItem,
351+
@Exclusive @Cached GilNode gil) throws InvalidArrayIndexException {
350352
boolean mustRelease = gil.acquire();
351353
try {
352354
try {
@@ -363,12 +365,13 @@ public Object readArrayElement(long index,
363365
@ExportMessage
364366
public void writeArrayElement(long index, Object value,
365367
@Bind("$node") Node inliningTarget,
366-
@Cached.Exclusive @Cached SequenceStorageNodes.SetItemScalarNode setItem,
367-
@Cached.Exclusive @Cached GilNode gil) throws InvalidArrayIndexException {
368+
@Exclusive @Cached SequenceStorageNodes.SetItemScalarNode setItem,
369+
@Exclusive @Cached PForeignToPTypeNode convert,
370+
@Exclusive @Cached GilNode gil) throws InvalidArrayIndexException {
368371
boolean mustRelease = gil.acquire();
369372
try {
370373
try {
371-
setItem.execute(inliningTarget, storage, PInt.intValueExact(index), value);
374+
setItem.execute(inliningTarget, storage, PInt.intValueExact(index), convert.executeConvert(value));
372375
} catch (OverflowException e) {
373376
CompilerDirectives.transferToInterpreterAndInvalidate();
374377
throw InvalidArrayIndexException.create(index);
@@ -381,8 +384,8 @@ public void writeArrayElement(long index, Object value,
381384
@ExportMessage
382385
public void removeArrayElement(long index,
383386
@Bind("$node") Node inliningTarget,
384-
@Cached.Exclusive @Cached SequenceStorageNodes.DeleteItemNode delItem,
385-
@Cached.Exclusive @Cached GilNode gil) throws InvalidArrayIndexException {
387+
@Exclusive @Cached SequenceStorageNodes.DeleteItemNode delItem,
388+
@Exclusive @Cached GilNode gil) throws InvalidArrayIndexException {
386389
boolean mustRelease = gil.acquire();
387390
try {
388391
try {

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/bytes/PByteArray.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import com.oracle.graal.python.builtins.objects.ints.PInt;
3636
import com.oracle.graal.python.nodes.ErrorMessages;
3737
import com.oracle.graal.python.nodes.PRaiseNode;
38+
import com.oracle.graal.python.nodes.interop.PForeignToPTypeNode;
3839
import com.oracle.graal.python.runtime.GilNode;
3940
import com.oracle.graal.python.runtime.exception.PException;
4041
import com.oracle.graal.python.runtime.sequence.storage.ByteSequenceStorage;
@@ -150,11 +151,12 @@ public boolean isArrayElementRemovable(long index,
150151
public void writeArrayElement(long index, Object value,
151152
@Bind("$node") Node inliningTarget,
152153
@Exclusive @Cached SequenceStorageNodes.SetItemScalarNode setItem,
154+
@Exclusive @Cached PForeignToPTypeNode convert,
153155
@Exclusive @Cached GilNode gil) throws InvalidArrayIndexException {
154156
boolean mustRelease = gil.acquire();
155157
try {
156158
try {
157-
setItem.execute(inliningTarget, store, PInt.intValueExact(index), value);
159+
setItem.execute(inliningTarget, store, PInt.intValueExact(index), convert.executeConvert(value));
158160
} catch (OverflowException e) {
159161
CompilerDirectives.transferToInterpreterAndInvalidate();
160162
throw InvalidArrayIndexException.create(index);

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

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,14 @@
6767
import com.oracle.graal.python.builtins.objects.common.SequenceStorageNodesFactory.GetItemSliceNodeGen;
6868
import com.oracle.graal.python.builtins.objects.common.SequenceStorageNodesFactory.InsertItemNodeGen;
6969
import com.oracle.graal.python.builtins.objects.common.SequenceStorageNodesFactory.ListGeneralizationNodeGen;
70+
import com.oracle.graal.python.builtins.objects.common.SequenceStorageNodesFactory.MemMoveNodeGen;
7071
import com.oracle.graal.python.builtins.objects.common.SequenceStorageNodesFactory.NoGeneralizationCustomMessageNodeGen;
7172
import com.oracle.graal.python.builtins.objects.common.SequenceStorageNodesFactory.NoGeneralizationNodeGen;
7273
import com.oracle.graal.python.builtins.objects.common.SequenceStorageNodesFactory.RepeatNodeGen;
7374
import com.oracle.graal.python.builtins.objects.common.SequenceStorageNodesFactory.SetItemDynamicNodeGen;
7475
import com.oracle.graal.python.builtins.objects.common.SequenceStorageNodesFactory.SetItemNodeGen;
75-
import com.oracle.graal.python.builtins.objects.common.SequenceStorageNodesFactory.ToByteArrayNodeGen;
7676
import com.oracle.graal.python.builtins.objects.common.SequenceStorageNodesFactory.StorageToNativeNodeGen;
77-
import com.oracle.graal.python.builtins.objects.common.SequenceStorageNodesFactory.MemMoveNodeGen;
77+
import com.oracle.graal.python.builtins.objects.common.SequenceStorageNodesFactory.ToByteArrayNodeGen;
7878
import com.oracle.graal.python.builtins.objects.ints.PInt;
7979
import com.oracle.graal.python.builtins.objects.iterator.IteratorBuiltins.NextHelperNode;
8080
import com.oracle.graal.python.builtins.objects.iterator.IteratorNodes.BuiltinIteratorLengthHint;
@@ -1076,6 +1076,34 @@ protected static void doNative(NativeSequenceStorage storage, int idx, Object va
10761076
}
10771077
}
10781078

1079+
@GenerateUncached
1080+
@GenerateInline
1081+
@GenerateCached(false)
1082+
public abstract static class SetItemScalarGeneralizingNode extends Node {
1083+
public abstract SequenceStorage execute(Node inliningTarget, SequenceStorage storage, int idx, Object value, GenNodeSupplier genNodeSupplier);
1084+
1085+
@Specialization
1086+
static SequenceStorage set(Node inliningTarget, SequenceStorage storage, int idx, Object value, GenNodeSupplier genNodeSupplier,
1087+
@Cached InlinedBranchProfile generalizeProfile,
1088+
@Cached SetItemScalarNode setItemScalarNode,
1089+
@Cached DoGeneralizationNode doGeneralizationNode) {
1090+
try {
1091+
setItemScalarNode.execute(inliningTarget, storage, idx, value);
1092+
return storage;
1093+
} catch (SequenceStoreException e) {
1094+
generalizeProfile.enter(inliningTarget);
1095+
SequenceStorage generalized = doGeneralizationNode.execute(inliningTarget, genNodeSupplier, storage, e.getIndicationValue());
1096+
try {
1097+
setItemScalarNode.execute(inliningTarget, generalized, idx, value);
1098+
} catch (SequenceStoreException e1) {
1099+
CompilerDirectives.transferToInterpreterAndInvalidate();
1100+
throw new IllegalStateException();
1101+
}
1102+
return generalized;
1103+
}
1104+
}
1105+
}
1106+
10791107
@GenerateUncached
10801108
@GenerateInline
10811109
@GenerateCached(false)

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/list/ListBuiltins.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -983,14 +983,14 @@ boolean doPListObjectStorage(VirtualFrame frame, PList left, PList right,
983983
final SequenceStorage leftStorage = left.getSequenceStorage();
984984
final SequenceStorage rightStorage = right.getSequenceStorage();
985985
final boolean result = neNode.execute(frame, leftStorage, rightStorage);
986-
/**
986+
/*
987987
* This will check if the underlying storage has been modified and if so, we do the
988988
* check again.
989989
*/
990990
if (leftStorage == left.getSequenceStorage() && rightStorage == right.getSequenceStorage()) {
991991
return result;
992992
}
993-
/**
993+
/*
994994
* To avoid possible infinite recursion case, we call the default specialization.
995995
*/
996996
return doPList(frame, left, right, neNode);

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/list/PList.java

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
import com.oracle.truffle.api.library.ExportMessage;
5151
import com.oracle.truffle.api.nodes.Node;
5252
import com.oracle.truffle.api.object.Shape;
53+
import com.oracle.truffle.api.profiles.InlinedBranchProfile;
5354
import com.oracle.truffle.api.source.SourceSection;
5455

5556
@SuppressWarnings("truffle-abstract-export")
@@ -115,7 +116,7 @@ public boolean hasSourceLocation() {
115116

116117
@ExportMessage
117118
public boolean isArrayElementModifiable(long index,
118-
@Cached.Exclusive @Cached IndexNodes.NormalizeIndexCustomMessageNode normalize,
119+
@Exclusive @Cached IndexNodes.NormalizeIndexCustomMessageNode normalize,
119120
@Exclusive @Cached GilNode gil) {
120121
boolean mustRelease = gil.acquire();
121122
try {
@@ -145,7 +146,7 @@ public boolean isArrayElementInsertable(long index,
145146

146147
@ExportMessage
147148
public boolean isArrayElementRemovable(long index,
148-
@Cached.Exclusive @Cached IndexNodes.NormalizeIndexCustomMessageNode normalize,
149+
@Exclusive @Cached IndexNodes.NormalizeIndexCustomMessageNode normalize,
149150
@Exclusive @Cached GilNode gil) {
150151
boolean mustRelease = gil.acquire();
151152
try {
@@ -165,17 +166,24 @@ public boolean isArrayElementRemovable(long index,
165166
public void writeArrayElement(long index, Object value,
166167
@Bind("$node") Node inliningTarget,
167168
@Cached PForeignToPTypeNode convert,
168-
@Cached.Exclusive @Cached SequenceStorageNodes.SetItemScalarNode setItem,
169+
@Exclusive @Cached SequenceStorageNodes.SetItemScalarGeneralizingNode setItem,
169170
@Cached SequenceStorageNodes.AppendNode appendNode,
171+
@Cached InlinedBranchProfile generalizedProfile,
170172
@Exclusive @Cached GilNode gil) throws InvalidArrayIndexException {
171173
boolean mustRelease = gil.acquire();
172174
try {
173175
final int len = store.length();
176+
value = convert.executeConvert(value);
174177
try {
178+
SequenceStorage newStorage;
175179
if (index == len) {
176-
appendNode.execute(inliningTarget, store, convert.executeConvert(value), SequenceStorageNodes.ListGeneralizationNode.SUPPLIER);
180+
newStorage = appendNode.execute(inliningTarget, store, value, SequenceStorageNodes.ListGeneralizationNode.SUPPLIER);
177181
} else {
178-
setItem.execute(inliningTarget, store, PInt.intValueExact(index), convert.executeConvert(value));
182+
newStorage = setItem.execute(inliningTarget, store, PInt.intValueExact(index), value, SequenceStorageNodes.ListGeneralizationNode.SUPPLIER);
183+
}
184+
if (newStorage != store) {
185+
generalizedProfile.enter(inliningTarget);
186+
store = newStorage;
179187
}
180188
} catch (OverflowException e) {
181189
CompilerDirectives.transferToInterpreterAndInvalidate();

0 commit comments

Comments
 (0)