Skip to content

Commit b6dd540

Browse files
committed
Fix test failures
1 parent 39cb4c2 commit b6dd540

File tree

5 files changed

+60
-67
lines changed

5 files changed

+60
-67
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ HashingStorage delItemWithState(Object key, ThreadState state,
321321
@Shared("gotState") @Cached ConditionProfile gotState) {
322322
VirtualFrame frame = gotState.profile(state == null) ? null : PArguments.frameForCall(state);
323323
DictKey newKey = new DictKey(key, hashNode.execute(frame, key));
324-
map.removeKey(newKey, eqNode);
324+
map.removeKey(frame, newKey, eqNode);
325325
return this;
326326
}
327327

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -571,17 +571,16 @@ private boolean hasHashArray() {
571571
return hashArray != null;
572572
}
573573

574-
@TruffleBoundary
575-
public Object removeKey(DictKey key, PyObjectRichCompareBool.EqNode eqNode) {
574+
public Object removeKey(VirtualFrame frame, DictKey key, PyObjectRichCompareBool.EqNode eqNode) {
576575
if (key == null) {
577576
CompilerDirectives.transferToInterpreterAndInvalidate();
578577
throw new UnsupportedOperationException("null not supported as key!");
579578
}
580579
int index;
581580
if (hasHashArray()) {
582-
index = this.findAndRemoveHash(null, key, eqNode);
581+
index = this.findAndRemoveHash(frame, key, eqNode);
583582
} else {
584-
index = this.findLinear(null, key, eqNode);
583+
index = this.findLinear(frame, key, eqNode);
585584
}
586585

587586
if (index != -1) {
@@ -596,6 +595,7 @@ public Object removeKey(DictKey key, PyObjectRichCompareBool.EqNode eqNode) {
596595
* Removes the element at the specific index and returns the index of the next element. This can
597596
* be a different value if graph compression was triggered.
598597
*/
598+
@TruffleBoundary
599599
private int remove(int indexToRemove) {
600600
int index = indexToRemove;
601601
int entriesAfterIndex = totalEntries - index - 1;

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyObjectRichCompareBool.java

Lines changed: 52 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,15 @@ protected SpecialMethodSlot getReverseSlot() {
109109
throw CompilerDirectives.shouldNotReachHere("abstract method");
110110
}
111111

112-
protected boolean doDefault(PRaiseNode raiseNode, IsExpressionNode.IsNode isNode, Object a, Object b) {
112+
protected boolean needsIdentityComparison() {
113+
return false;
114+
}
115+
116+
protected boolean identityComparisonResult() {
117+
throw CompilerDirectives.shouldNotReachHere("abstract method");
118+
}
119+
120+
protected boolean doDefault(PRaiseNode raiseNode, Object a, Object b) {
113121
throw CompilerDirectives.shouldNotReachHere("abstract method");
114122
}
115123

@@ -164,13 +172,13 @@ boolean doLD(long a, double b) {
164172

165173
@Specialization(guards = "isBuiltinPInt(b)", rewriteOn = OverflowException.class)
166174
boolean doLPNoOVerflow(long a, PInt b) throws OverflowException {
167-
return op(a, b.intValueExact());
175+
return op(a, b.longValueExact());
168176
}
169177

170178
@Specialization(guards = "isBuiltinPInt(b)", replaces = "doLPNoOVerflow")
171179
boolean doLP(long a, PInt b) {
172180
try {
173-
return op(a, b.intValueExact());
181+
return op(a, b.longValueExact());
174182
} catch (OverflowException e) {
175183
return false;
176184
}
@@ -192,13 +200,13 @@ boolean doPI(PInt a, int b) {
192200

193201
@Specialization(guards = "isBuiltinPInt(a)", rewriteOn = OverflowException.class)
194202
boolean doPLNoOverflow(PInt a, long b) throws OverflowException {
195-
return op(a.intValueExact(), b);
203+
return op(a.longValueExact(), b);
196204
}
197205

198206
@Specialization(guards = "isBuiltinPInt(a)", replaces = "doPLNoOverflow")
199207
boolean doPL(PInt a, long b) {
200208
try {
201-
return op(a.intValueExact(), b);
209+
return op(a.longValueExact(), b);
202210
} catch (OverflowException e) {
203211
return false;
204212
}
@@ -212,6 +220,7 @@ boolean doPP(PInt a, PInt b) {
212220

213221
@Specialization
214222
boolean doDD(double a, double b) {
223+
// nb: Eq subclass handles NaN identity
215224
return op(a, b);
216225
}
217226

@@ -232,6 +241,7 @@ boolean doSS(String a, String b) {
232241

233242
@Specialization
234243
boolean doGeneric(VirtualFrame frame, Object a, Object b,
244+
@Cached IsExpressionNode.IsNode isNode,
235245
@Cached GetClassNode getClassA,
236246
@Cached GetClassNode getClassB,
237247
@Cached ConditionProfile reversedFirst,
@@ -242,8 +252,12 @@ boolean doGeneric(VirtualFrame frame, Object a, Object b,
242252
@Cached CallBinaryMethodNode callMethod,
243253
@Cached CallBinaryMethodNode callReverseMethod,
244254
@Cached PyObjectIsTrueNode isTrueNode,
245-
@Cached IsExpressionNode.IsNode isNode,
246255
@Cached PRaiseNode raiseNode) {
256+
if (needsIdentityComparison()) {
257+
if (isNode.execute(a, b)) {
258+
return identityComparisonResult();
259+
}
260+
}
247261
boolean checkedReverseOp = false;
248262
Object aType = getClassA.execute(a);
249263
Object bType = getClassB.execute(b);
@@ -273,7 +287,7 @@ boolean doGeneric(VirtualFrame frame, Object a, Object b,
273287
}
274288
}
275289
}
276-
return doDefault(raiseNode, isNode, a, b);
290+
return doDefault(raiseNode, a, b);
277291
}
278292

279293
private Object lookupMethodIgnoreDescriptorError(VirtualFrame frame, LookupSpecialMethodSlotNode lookupMethod, Object aType, Object a) {
@@ -287,21 +301,6 @@ private Object lookupMethodIgnoreDescriptorError(VirtualFrame frame, LookupSpeci
287301

288302
@GenerateUncached
289303
public abstract static class EqNode extends ComparisonBaseNode {
290-
@Override
291-
public boolean execute(Frame frame, Object a, Object b) {
292-
/*
293-
* CPython uses pointer equality here, so we should technically use IsNode. But since
294-
* that haves a lot of logic that only applies to corner cases, we compare references
295-
* here and use IsNode later as a fallback if there is no __eq__.
296-
*/
297-
if (a == b) {
298-
return true;
299-
}
300-
return executeInternal(frame, a, b);
301-
}
302-
303-
protected abstract boolean executeInternal(Frame frame, Object a, Object b);
304-
305304
@Override
306305
protected boolean op(boolean a, boolean b) {
307306
return a == b;
@@ -319,7 +318,7 @@ protected boolean op(long a, long b) {
319318

320319
@Override
321320
protected boolean op(double a, double b) {
322-
return a == b;
321+
return a == b || (Double.isNaN(a) && Double.isNaN(b));
323322
}
324323

325324
@Override
@@ -338,8 +337,19 @@ protected SpecialMethodSlot getReverseSlot() {
338337
}
339338

340339
@Override
341-
protected boolean doDefault(PRaiseNode raiseNode, IsExpressionNode.IsNode isNode, Object a, Object b) {
342-
return isNode.execute(a, b);
340+
protected boolean needsIdentityComparison() {
341+
return true;
342+
}
343+
344+
@Override
345+
protected boolean identityComparisonResult() {
346+
return true;
347+
}
348+
349+
@Override
350+
protected boolean doDefault(PRaiseNode raiseNode, Object a, Object b) {
351+
// Already compared for identity
352+
return false;
343353
}
344354

345355
public static EqNode create() {
@@ -353,16 +363,6 @@ public static EqNode getUncached() {
353363

354364
@GenerateUncached
355365
public abstract static class NeNode extends ComparisonBaseNode {
356-
@Override
357-
public boolean execute(Frame frame, Object a, Object b) {
358-
if (a == b) {
359-
return false;
360-
}
361-
return executeInternal(frame, a, b);
362-
}
363-
364-
protected abstract boolean executeInternal(Frame frame, Object a, Object b);
365-
366366
@Override
367367
protected boolean op(boolean a, boolean b) {
368368
return a != b;
@@ -399,8 +399,19 @@ protected SpecialMethodSlot getReverseSlot() {
399399
}
400400

401401
@Override
402-
protected boolean doDefault(PRaiseNode raiseNode, IsExpressionNode.IsNode isNode, Object a, Object b) {
403-
return !isNode.execute(a, b);
402+
protected boolean needsIdentityComparison() {
403+
return true;
404+
}
405+
406+
@Override
407+
protected boolean identityComparisonResult() {
408+
return false;
409+
}
410+
411+
@Override
412+
protected boolean doDefault(PRaiseNode raiseNode, Object a, Object b) {
413+
// Already compared for identity
414+
return true;
404415
}
405416

406417
public static NeNode create() {
@@ -445,7 +456,7 @@ protected SpecialMethodSlot getReverseSlot() {
445456
}
446457

447458
@Override
448-
protected boolean doDefault(PRaiseNode raiseNode, IsExpressionNode.IsNode isNode, Object a, Object b) {
459+
protected boolean doDefault(PRaiseNode raiseNode, Object a, Object b) {
449460
throw raiseNode.raise(TypeError, ErrorMessages.NOT_SUPPORTED_BETWEEN_INSTANCES, "<", a, b);
450461
}
451462

@@ -491,7 +502,7 @@ protected SpecialMethodSlot getReverseSlot() {
491502
}
492503

493504
@Override
494-
protected boolean doDefault(PRaiseNode raiseNode, IsExpressionNode.IsNode isNode, Object a, Object b) {
505+
protected boolean doDefault(PRaiseNode raiseNode, Object a, Object b) {
495506
throw raiseNode.raise(TypeError, ErrorMessages.NOT_SUPPORTED_BETWEEN_INSTANCES, "<=", a, b);
496507
}
497508

@@ -537,7 +548,7 @@ protected SpecialMethodSlot getReverseSlot() {
537548
}
538549

539550
@Override
540-
protected boolean doDefault(PRaiseNode raiseNode, IsExpressionNode.IsNode isNode, Object a, Object b) {
551+
protected boolean doDefault(PRaiseNode raiseNode, Object a, Object b) {
541552
throw raiseNode.raise(TypeError, ErrorMessages.NOT_SUPPORTED_BETWEEN_INSTANCES, ">", a, b);
542553
}
543554

@@ -583,7 +594,7 @@ protected SpecialMethodSlot getReverseSlot() {
583594
}
584595

585596
@Override
586-
protected boolean doDefault(PRaiseNode raiseNode, IsExpressionNode.IsNode isNode, Object a, Object b) {
597+
protected boolean doDefault(PRaiseNode raiseNode, Object a, Object b) {
587598
throw raiseNode.raise(TypeError, ErrorMessages.NOT_SUPPORTED_BETWEEN_INSTANCES, ">=", a, b);
588599
}
589600

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyUnicodeFSDecoderNode.java

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@
4343
import static com.oracle.graal.python.builtins.PythonBuiltinClassType.ValueError;
4444

4545
import com.oracle.graal.python.builtins.objects.buffer.PythonBufferAccessLibrary;
46-
import com.oracle.graal.python.builtins.objects.buffer.PythonBufferAcquireLibrary;
4746
import com.oracle.graal.python.builtins.objects.bytes.PBytes;
4847
import com.oracle.graal.python.builtins.objects.str.PString;
4948
import com.oracle.graal.python.nodes.ErrorMessages;
@@ -82,32 +81,15 @@ String doPString(PString object,
8281
@Specialization(limit = "1")
8382
String doBytes(PBytes object,
8483
@CachedLibrary("object") PythonBufferAccessLibrary bufferLib) {
85-
return checkString(fromBuffer(object, bufferLib));
86-
}
87-
88-
private static String fromBuffer(Object object, PythonBufferAccessLibrary bufferLib) {
8984
// TODO PyUnicode_DecodeFSDefault
90-
return PythonUtils.newString(bufferLib.getInternalOrCopiedByteArray(object), 0, bufferLib.getBufferLength(object));
85+
return checkString(PythonUtils.newString(bufferLib.getInternalOrCopiedByteArray(object), 0, bufferLib.getBufferLength(object)));
9186
}
9287

9388
@Fallback
9489
String doPathLike(VirtualFrame frame, Object object,
95-
@CachedLibrary(limit = "3") PythonBufferAcquireLibrary bufferAcquireLib,
96-
@CachedLibrary(limit = "3") PythonBufferAccessLibrary bufferLib,
9790
@Cached PyOSFSPathNode fspathNode,
9891
@Cached PyUnicodeFSDecoderNode recursive) {
99-
Object path;
100-
if (bufferAcquireLib.hasBuffer(object)) {
101-
Object buffer = bufferAcquireLib.acquireReadonly(object);
102-
try {
103-
path = fromBuffer(buffer, bufferLib);
104-
} finally {
105-
bufferLib.release(buffer);
106-
}
107-
} else {
108-
// The node ensures that it is a string or bytes
109-
path = fspathNode.execute(frame, object);
110-
}
92+
Object path = fspathNode.execute(frame, object);
11193
assert path instanceof String || path instanceof PString || path instanceof PBytes;
11294
return recursive.execute(frame, path);
11395
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/classes/IsSubtypeNode.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ boolean issubTypeGeneric(Object derived, Object cls,
283283
return false;
284284
}
285285

286-
@Specialization(guards = {"!isTypeDerived.execute(derived)", "!isTypeCls.execute(cls)"}, limit = "1")
286+
@Specialization(guards = {"!isTypeDerived.execute(derived) || !isTypeCls.execute(cls)"}, limit = "1")
287287
@Megamorphic
288288
boolean fallback(VirtualFrame frame, Object derived, Object cls,
289289
@SuppressWarnings("unused") @Cached TypeNodes.IsTypeNode isTypeDerived,

0 commit comments

Comments
 (0)