Skip to content

Commit 08ac961

Browse files
committed
Merge branch 'master' into bugfix/GR-16588
# Conflicts: # graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/PythonAbstractObject.java
2 parents eeb8cbc + b6bbe48 commit 08ac961

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+532
-636
lines changed

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import java.util.HashSet;
2929

3030
import com.oracle.graal.python.PythonLanguage;
31+
import com.oracle.graal.python.builtins.objects.object.PythonObjectLibrary;
3132
import com.oracle.graal.python.builtins.objects.type.LazyPythonClass;
3233
import com.oracle.graal.python.nodes.BuiltinNames;
3334
import com.oracle.graal.python.runtime.PythonContext;
@@ -45,6 +46,7 @@
4546
import com.oracle.truffle.api.object.Shape;
4647

4748
@ExportLibrary(InteropLibrary.class)
49+
@ExportLibrary(PythonObjectLibrary.class)
4850
public enum PythonBuiltinClassType implements LazyPythonClass {
4951

5052
ForeignObject(BuiltinNames.FOREIGN),
@@ -441,4 +443,23 @@ public boolean hasMemberWriteSideEffects(String key,
441443
@CachedContext(PythonLanguage.class) PythonContext context) {
442444
return lib.hasMemberWriteSideEffects(context.getCore().lookupType(this), key);
443445
}
446+
447+
@ExportMessage
448+
static boolean isSequenceType(PythonBuiltinClassType type,
449+
@CachedContext(PythonLanguage.class) PythonContext context,
450+
@CachedLibrary(limit = "1") PythonObjectLibrary lib) {
451+
return lib.isSequenceType(context.getCore().lookupType(type));
452+
}
453+
454+
@ExportMessage
455+
static boolean isMappingType(PythonBuiltinClassType type,
456+
@CachedContext(PythonLanguage.class) PythonContext context,
457+
@CachedLibrary(limit = "1") PythonObjectLibrary lib) {
458+
return lib.isMappingType(context.getCore().lookupType(type));
459+
}
460+
461+
@ExportMessage
462+
static LazyPythonClass getLazyPythonClass(@SuppressWarnings("unused") PythonBuiltinClassType type) {
463+
return PythonClass;
464+
}
444465
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ PArray arrayByteInitializer(VirtualFrame frame, LazyPythonClass cls, @SuppressWa
152152
}
153153

154154
@Specialization(guards = "isCharArray(typeCode)")
155-
PArray arrayCharInitializer(VirtualFrame frame, LazyPythonClass cls, @SuppressWarnings("unused") String typeCode, PSequence initializer,
155+
PArray arrayCharInitializer(LazyPythonClass cls, @SuppressWarnings("unused") String typeCode, PSequence initializer,
156156
@Cached SequenceNodes.GetSequenceStorageNode getSequenceStorageNode,
157157
@Cached SequenceStorageNodes.ToByteArrayNode toByteArrayNode) {
158158
byte[] byteArray = toByteArrayNode.execute(getSequenceStorageNode.execute(initializer));

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

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@
8484
import com.oracle.graal.python.builtins.objects.bytes.PByteArray;
8585
import com.oracle.graal.python.builtins.objects.bytes.PBytes;
8686
import com.oracle.graal.python.builtins.objects.bytes.PIBytesLike;
87-
import com.oracle.graal.python.builtins.objects.bytes.PythonBufferLibrary;
8887
import com.oracle.graal.python.builtins.objects.cell.PCell;
8988
import com.oracle.graal.python.builtins.objects.cext.CExtNodes;
9089
import com.oracle.graal.python.builtins.objects.cext.CExtNodes.PCallCapiFunction;
@@ -119,8 +118,8 @@
119118
import com.oracle.graal.python.builtins.objects.memoryview.PBuffer;
120119
import com.oracle.graal.python.builtins.objects.memoryview.PMemoryView;
121120
import com.oracle.graal.python.builtins.objects.module.PythonModule;
122-
import com.oracle.graal.python.builtins.objects.object.PythonDataModelLibrary;
123121
import com.oracle.graal.python.builtins.objects.object.PythonObject;
122+
import com.oracle.graal.python.builtins.objects.object.PythonObjectLibrary;
124123
import com.oracle.graal.python.builtins.objects.range.PRange;
125124
import com.oracle.graal.python.builtins.objects.set.PFrozenSet;
126125
import com.oracle.graal.python.builtins.objects.set.PSet;
@@ -237,7 +236,7 @@ public Object bytearray(LazyPythonClass cls, @SuppressWarnings("unused") PNone s
237236

238237
@Specialization(guards = {"lib.canBeIndex(capObj)", "isNoValue(encoding)", "isNoValue(errors)"})
239238
public Object bytearray(VirtualFrame frame, LazyPythonClass cls, Object capObj, @SuppressWarnings("unused") PNone encoding, @SuppressWarnings("unused") PNone errors,
240-
@SuppressWarnings("unused") @CachedLibrary(limit = "1") PythonDataModelLibrary lib) {
239+
@SuppressWarnings("unused") @CachedLibrary(limit = "1") PythonObjectLibrary lib) {
241240
int cap = getCastToIndexNode().execute(frame, capObj);
242241
return create(cls, BytesUtils.fromSize(getCore(), cap));
243242
}
@@ -277,7 +276,7 @@ public Object bytearray(VirtualFrame frame, LazyPythonClass cls, Object iterable
277276
@Cached("create()") GetNextNode getNextNode,
278277
@Cached("create()") IsBuiltinClassProfile stopIterationProfile,
279278
@Cached("create()") CastToByteNode castToByteNode,
280-
@SuppressWarnings("unused") @CachedLibrary(limit = "1") PythonDataModelLibrary lib) {
279+
@SuppressWarnings("unused") @CachedLibrary(limit = "1") PythonObjectLibrary lib) {
281280

282281
Object it = getIteratorNode.executeWith(frame, iterable);
283282
byte[] arr = new byte[16];
@@ -2656,7 +2655,7 @@ Object methodBuiltin(@SuppressWarnings("unused") LazyPythonClass cls, PBuiltinFu
26562655

26572656
@Specialization
26582657
Object methodGeneric(VirtualFrame frame, @SuppressWarnings("unused") LazyPythonClass cls, Object func, Object self,
2659-
@CachedLibrary(limit = "3") PythonDataModelLibrary dataModelLibrary) {
2658+
@CachedLibrary(limit = "3") PythonObjectLibrary dataModelLibrary) {
26602659
PythonContext context = getContextRef().get();
26612660
PException caughtException = IndirectCallContext.enter(frame, context, this);
26622661
try {
@@ -2710,8 +2709,8 @@ Object call(VirtualFrame frame, LazyPythonClass cls, int argcount, int kwonlyarg
27102709
PTuple varnames, Object filename, Object name,
27112710
int firstlineno, Object lnotab,
27122711
PTuple freevars, PTuple cellvars,
2713-
@CachedLibrary("codestring") PythonBufferLibrary codestringBufferLib,
2714-
@CachedLibrary("lnotab") PythonBufferLibrary lnotabBufferLib,
2712+
@CachedLibrary("codestring") PythonObjectLibrary codestringBufferLib,
2713+
@CachedLibrary("lnotab") PythonObjectLibrary lnotabBufferLib,
27152714
@Cached CodeNodes.CreateCodeNode createCodeNode,
27162715
@Cached GetObjectArrayNode getObjectArrayNode) throws UnsupportedMessageException {
27172716
byte[] codeBytes = codestringBufferLib.getBufferBytes(codestring);
@@ -2788,7 +2787,7 @@ Object doMapping(LazyPythonClass klass, PHashingCollection obj) {
27882787
@Specialization(guards = {"isSequence(frame, obj, lib)", "!isBuiltinMapping(obj)"})
27892788
Object doMapping(VirtualFrame frame, LazyPythonClass klass, PythonObject obj,
27902789
@Cached("create()") HashingStorageNodes.InitNode initNode,
2791-
@SuppressWarnings("unused") @CachedLibrary(limit = "1") PythonDataModelLibrary lib) {
2790+
@SuppressWarnings("unused") @CachedLibrary(limit = "1") PythonObjectLibrary lib) {
27922791
return factory().createMappingproxy(klass, initNode.execute(frame, obj, PKeyword.EMPTY_KEYWORDS));
27932792
}
27942793

@@ -2800,15 +2799,15 @@ Object doMissing(LazyPythonClass klass, PNone none) {
28002799

28012800
@Specialization(guards = {"!isSequence(frame, obj, lib)", "!isNoValue(obj)"})
28022801
Object doInvalid(@SuppressWarnings("unused") VirtualFrame frame, @SuppressWarnings("unused") LazyPythonClass klass, Object obj,
2803-
@SuppressWarnings("unused") @CachedLibrary(limit = "1") PythonDataModelLibrary lib) {
2802+
@SuppressWarnings("unused") @CachedLibrary(limit = "1") PythonObjectLibrary lib) {
28042803
throw raise(TypeError, "mappingproxy() argument must be a mapping, not %p", obj);
28052804
}
28062805

28072806
protected boolean isBuiltinMapping(Object o) {
28082807
return o instanceof PHashingCollection;
28092808
}
28102809

2811-
protected boolean isSequence(VirtualFrame frame, Object o, PythonDataModelLibrary library) {
2810+
protected boolean isSequence(VirtualFrame frame, Object o, PythonObjectLibrary library) {
28122811
PythonContext context = getContextRef().get();
28132812
PException caughtException = IndirectCallContext.enter(frame, context, this);
28142813
try {

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,6 @@
110110
import com.oracle.graal.python.builtins.objects.ints.PInt;
111111
import com.oracle.graal.python.builtins.objects.method.PMethod;
112112
import com.oracle.graal.python.builtins.objects.module.PythonModule;
113-
import com.oracle.graal.python.builtins.objects.object.PythonDataModelLibrary;
114113
import com.oracle.graal.python.builtins.objects.object.PythonObject;
115114
import com.oracle.graal.python.builtins.objects.object.PythonObjectLibrary;
116115
import com.oracle.graal.python.builtins.objects.set.PFrozenSet;
@@ -506,7 +505,7 @@ protected boolean isPException(Object object) {
506505
Object hash(VirtualFrame frame, Object object,
507506
@Cached("create(__DIR__)") LookupInheritedAttributeNode lookupDirNode,
508507
@Cached("create(__HASH__)") LookupInheritedAttributeNode lookupHash,
509-
@CachedLibrary(limit = "1") PythonDataModelLibrary dataModelLibrary,
508+
@CachedLibrary(limit = "1") PythonObjectLibrary dataModelLibrary,
510509
@Cached CallUnaryMethodNode callUnary,
511510
@Cached("createIfTrueNode()") CastToBooleanNode trueNode,
512511
@Cached IsInstanceNode isInstanceNode) {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -589,13 +589,13 @@ abstract static class RawDecodeNode extends EncodeBaseNode {
589589
@Child private GetInternalByteArrayNode toByteArrayNode;
590590

591591
@Specialization
592-
Object decode(VirtualFrame frame, PIBytesLike bytes, @SuppressWarnings("unused") PNone errors) {
592+
Object decode(PIBytesLike bytes, @SuppressWarnings("unused") PNone errors) {
593593
String string = decodeBytes(getBytesBuffer(bytes), "strict");
594594
return factory().createTuple(new Object[]{string, string.length()});
595595
}
596596

597597
@Specialization(guards = {"isString(errors)"})
598-
Object decode(VirtualFrame frame, PIBytesLike bytes, Object errors,
598+
Object decode(PIBytesLike bytes, Object errors,
599599
@Cached("createClassProfile()") ValueProfile errorsTypeProfile) {
600600
Object profiledErrors = errorsTypeProfile.profile(errors);
601601
String string = decodeBytes(getBytesBuffer(bytes), profiledErrors.toString());

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
import com.oracle.graal.python.builtins.objects.ints.PInt;
5858
import com.oracle.graal.python.builtins.objects.lzma.PLZMACompressor;
5959
import com.oracle.graal.python.builtins.objects.lzma.PLZMADecompressor;
60-
import com.oracle.graal.python.builtins.objects.object.PythonDataModelLibrary;
60+
import com.oracle.graal.python.builtins.objects.object.PythonObjectLibrary;
6161
import com.oracle.graal.python.builtins.objects.type.LazyPythonClass;
6262
import com.oracle.graal.python.nodes.PGuards;
6363
import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
@@ -81,8 +81,8 @@
8181
import com.oracle.truffle.api.dsl.Specialization;
8282
import com.oracle.truffle.api.dsl.TypeSystemReference;
8383
import com.oracle.truffle.api.frame.VirtualFrame;
84-
8584
import com.oracle.truffle.api.library.CachedLibrary;
85+
8686
import org.tukaani.xz.ARMOptions;
8787
import org.tukaani.xz.ARMThumbOptions;
8888
import org.tukaani.xz.DeltaOptions;
@@ -195,7 +195,7 @@ protected static LZMA2Options parseLZMAOptions(int preset) {
195195
}
196196

197197
// corresponds to 'parse_filter_chain_spec' in '_lzmamodule.c'
198-
protected FilterOptions[] parseFilterChainSpec(VirtualFrame frame, Object filters, PythonDataModelLibrary library) {
198+
protected FilterOptions[] parseFilterChainSpec(VirtualFrame frame, Object filters, PythonObjectLibrary library) {
199199
int n = len(frame, filters);
200200
FilterOptions[] optionsChain = new FilterOptions[n];
201201
for (int i = 0; i < n; i++) {
@@ -205,7 +205,7 @@ protected FilterOptions[] parseFilterChainSpec(VirtualFrame frame, Object filter
205205
}
206206

207207
// corresponds to 'lzma_filter_converter' in '_lzmamodule.c'
208-
private FilterOptions convertLZMAFilter(VirtualFrame frame, Object spec, PythonDataModelLibrary library) {
208+
private FilterOptions convertLZMAFilter(VirtualFrame frame, Object spec, PythonObjectLibrary library) {
209209
if (!isSequence(frame, getContextRef(), spec, library)) {
210210
throw raise(PythonBuiltinClassType.TypeError, "Filter specifier must be a dict or dict-like object");
211211
}
@@ -252,7 +252,7 @@ private static FilterOptions createFilterById(int id) {
252252
}
253253
}
254254

255-
private boolean isSequence(VirtualFrame frame, ContextReference<PythonContext> contextRef, Object obj, PythonDataModelLibrary library) {
255+
private boolean isSequence(VirtualFrame frame, ContextReference<PythonContext> contextRef, Object obj, PythonObjectLibrary library) {
256256
PythonContext context = contextRef.get();
257257
PException caughtException = IndirectCallContext.enter(frame, context, this);
258258
try {
@@ -313,7 +313,7 @@ PLZMACompressor doCreate(VirtualFrame frame, LazyPythonClass cls, Object formatO
313313
@Cached CastToIndexNode castFormatToIntNode,
314314
@Cached CastToIndexNode castCheckToIntNode,
315315
@Cached CastToIndexNode castToIntNode,
316-
@CachedLibrary(limit = "1") PythonDataModelLibrary dataModelLibrary) {
316+
@CachedLibrary(limit = "1") PythonObjectLibrary dataModelLibrary) {
317317

318318
int format = FORMAT_XZ;
319319
int check = -1;

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,8 @@
130130
import com.oracle.graal.python.builtins.objects.iterator.PSequenceIterator;
131131
import com.oracle.graal.python.builtins.objects.list.PList;
132132
import com.oracle.graal.python.builtins.objects.module.PythonModule;
133-
import com.oracle.graal.python.builtins.objects.object.PythonDataModelLibrary;
134133
import com.oracle.graal.python.builtins.objects.object.PythonObject;
134+
import com.oracle.graal.python.builtins.objects.object.PythonObjectLibrary;
135135
import com.oracle.graal.python.builtins.objects.set.PBaseSet;
136136
import com.oracle.graal.python.builtins.objects.str.PString;
137137
import com.oracle.graal.python.builtins.objects.traceback.PTraceback;
@@ -1976,7 +1976,7 @@ Object upcall(VirtualFrame frame, PythonModule cextModule, Object[] args, @Suppr
19761976
abstract static class UpcallLNode extends UpcallLandingNode {
19771977

19781978
@Specialization
1979-
long upcall(VirtualFrame frame, Object self, Object[] args, @SuppressWarnings("unused") PKeyword[] kwargs,
1979+
long upcall(VirtualFrame frame, @SuppressWarnings("unused") Object self, Object[] args, @SuppressWarnings("unused") PKeyword[] kwargs,
19801980
@Cached CExtNodes.CastToNativeLongNode asLongNode,
19811981
@Cached CExtNodes.ObjectUpcallNode upcallNode,
19821982
@Cached TransformExceptionToNativeNode transformExceptionToNativeNode) {
@@ -2682,7 +2682,7 @@ abstract static class PyTruffle_IsSequence extends PythonUnaryBuiltinNode {
26822682

26832683
@Specialization
26842684
boolean doGeneric(VirtualFrame frame, Object object,
2685-
@CachedLibrary(limit = "1") PythonDataModelLibrary dataModelLibrary,
2685+
@CachedLibrary(limit = "1") PythonObjectLibrary dataModelLibrary,
26862686
@CachedContext(PythonLanguage.class) ContextReference<PythonContext> contextRef) {
26872687
PythonContext context = contextRef.get();
26882688
PException caughtException = IndirectCallContext.enter(frame, context, this);

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ private CastToIntegerFromIntNode getCastToIntNode() {
232232
}
233233

234234
@Specialization
235-
public long doit(VirtualFrame frame, Object data, @SuppressWarnings("unused") PNone value,
235+
public long doitNone(VirtualFrame frame, Object data, @SuppressWarnings("unused") PNone value,
236236
@Cached ToBytesNode toBytesNode) {
237237
return doCRC32(toBytesNode.execute(frame, data));
238238
}
@@ -245,7 +245,7 @@ private static long doCRC32(byte[] data) {
245245
}
246246

247247
@Specialization
248-
public long doit(VirtualFrame frame, Object data, long value,
248+
public long doitLong(VirtualFrame frame, Object data, long value,
249249
@Cached ToBytesNode toBytesNode) {
250250
// lost magnitude is ok here.
251251
int initValue = (int) value;
@@ -321,13 +321,13 @@ private static long doAdler32(byte[] data) {
321321
}
322322

323323
@Specialization
324-
public long doit(VirtualFrame frame, Object data, @SuppressWarnings("unused") PNone value,
324+
public long doitNone(VirtualFrame frame, Object data, @SuppressWarnings("unused") PNone value,
325325
@Cached ToBytesNode toBytesNode) {
326326
return doAdler32(toBytesNode.execute(frame, data));
327327
}
328328

329329
@Specialization
330-
public long doit(VirtualFrame frame, Object data, long value,
330+
public long doitLong(VirtualFrame frame, Object data, long value,
331331
@Cached ToBytesNode toBytesNode) {
332332
// lost magnitude is ok here.
333333
int initValue = (int) value;
@@ -560,13 +560,13 @@ private static byte[] compress(byte[] input, int level) {
560560
}
561561

562562
@Specialization
563-
public PBytes doit(PIBytesLike data, @SuppressWarnings("unused") PNone level) {
563+
public PBytes doitNone(PIBytesLike data, @SuppressWarnings("unused") PNone level) {
564564
byte[] array = getToArrayNode().execute(data.getSequenceStorage());
565565
return factory().createBytes(compress(array, -1));
566566
}
567567

568568
@Specialization
569-
public PBytes doit(PIBytesLike data, long level,
569+
public PBytes doitLong(PIBytesLike data, long level,
570570
@Cached("createBinaryProfile()") ConditionProfile wrongLevelProfile) {
571571
if (wrongLevelProfile.profile(level < -1 || 9 < level)) {
572572
throw raise(ZLibError, "Bad compression level");
@@ -636,12 +636,12 @@ public PBytes doit(PIBytesLike data, @SuppressWarnings("unused") PNone wbits, @S
636636
}
637637

638638
@Specialization
639-
public PBytes decompress(VirtualFrame frame, PIBytesLike data, byte wbits, int bufsize) {
640-
return decompress(frame, data, (long) wbits, bufsize);
639+
public PBytes decompress(PIBytesLike data, byte wbits, int bufsize) {
640+
return decompress(data, (long) wbits, bufsize);
641641
}
642642

643643
@Specialization
644-
public PBytes decompress(VirtualFrame frame, PIBytesLike data, long wbits, int bufsize) {
644+
public PBytes decompress(PIBytesLike data, long wbits, int bufsize) {
645645
// checking bufsize
646646
if (bufSizeProfile.profile(bufsize < 0)) {
647647
throw raise(ZLibError, "bufsize must be non-negative");

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ public int compareTo(Object o) {
6666
return this.hashCode() - o.hashCode();
6767
}
6868

69+
@Override
6970
@ExportMessage
7071
@SuppressWarnings("static-method")
7172
public LazyPythonClass getLazyPythonClass() {

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ static boolean isNull(@SuppressWarnings("unused") PNone self) {
5959
return true;
6060
}
6161

62+
@Override
6263
@ExportMessage
6364
@SuppressWarnings("static-method")
6465
public LazyPythonClass getLazyPythonClass() {

0 commit comments

Comments
 (0)