@@ -109,7 +109,15 @@ protected SpecialMethodSlot getReverseSlot() {
109
109
throw CompilerDirectives .shouldNotReachHere ("abstract method" );
110
110
}
111
111
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 ) {
113
121
throw CompilerDirectives .shouldNotReachHere ("abstract method" );
114
122
}
115
123
@@ -164,13 +172,13 @@ boolean doLD(long a, double b) {
164
172
165
173
@ Specialization (guards = "isBuiltinPInt(b)" , rewriteOn = OverflowException .class )
166
174
boolean doLPNoOVerflow (long a , PInt b ) throws OverflowException {
167
- return op (a , b .intValueExact ());
175
+ return op (a , b .longValueExact ());
168
176
}
169
177
170
178
@ Specialization (guards = "isBuiltinPInt(b)" , replaces = "doLPNoOVerflow" )
171
179
boolean doLP (long a , PInt b ) {
172
180
try {
173
- return op (a , b .intValueExact ());
181
+ return op (a , b .longValueExact ());
174
182
} catch (OverflowException e ) {
175
183
return false ;
176
184
}
@@ -192,13 +200,13 @@ boolean doPI(PInt a, int b) {
192
200
193
201
@ Specialization (guards = "isBuiltinPInt(a)" , rewriteOn = OverflowException .class )
194
202
boolean doPLNoOverflow (PInt a , long b ) throws OverflowException {
195
- return op (a .intValueExact (), b );
203
+ return op (a .longValueExact (), b );
196
204
}
197
205
198
206
@ Specialization (guards = "isBuiltinPInt(a)" , replaces = "doPLNoOverflow" )
199
207
boolean doPL (PInt a , long b ) {
200
208
try {
201
- return op (a .intValueExact (), b );
209
+ return op (a .longValueExact (), b );
202
210
} catch (OverflowException e ) {
203
211
return false ;
204
212
}
@@ -212,6 +220,7 @@ boolean doPP(PInt a, PInt b) {
212
220
213
221
@ Specialization
214
222
boolean doDD (double a , double b ) {
223
+ // nb: Eq subclass handles NaN identity
215
224
return op (a , b );
216
225
}
217
226
@@ -232,6 +241,7 @@ boolean doSS(String a, String b) {
232
241
233
242
@ Specialization
234
243
boolean doGeneric (VirtualFrame frame , Object a , Object b ,
244
+ @ Cached IsExpressionNode .IsNode isNode ,
235
245
@ Cached GetClassNode getClassA ,
236
246
@ Cached GetClassNode getClassB ,
237
247
@ Cached ConditionProfile reversedFirst ,
@@ -242,8 +252,12 @@ boolean doGeneric(VirtualFrame frame, Object a, Object b,
242
252
@ Cached CallBinaryMethodNode callMethod ,
243
253
@ Cached CallBinaryMethodNode callReverseMethod ,
244
254
@ Cached PyObjectIsTrueNode isTrueNode ,
245
- @ Cached IsExpressionNode .IsNode isNode ,
246
255
@ Cached PRaiseNode raiseNode ) {
256
+ if (needsIdentityComparison ()) {
257
+ if (isNode .execute (a , b )) {
258
+ return identityComparisonResult ();
259
+ }
260
+ }
247
261
boolean checkedReverseOp = false ;
248
262
Object aType = getClassA .execute (a );
249
263
Object bType = getClassB .execute (b );
@@ -273,7 +287,7 @@ boolean doGeneric(VirtualFrame frame, Object a, Object b,
273
287
}
274
288
}
275
289
}
276
- return doDefault (raiseNode , isNode , a , b );
290
+ return doDefault (raiseNode , a , b );
277
291
}
278
292
279
293
private Object lookupMethodIgnoreDescriptorError (VirtualFrame frame , LookupSpecialMethodSlotNode lookupMethod , Object aType , Object a ) {
@@ -287,21 +301,6 @@ private Object lookupMethodIgnoreDescriptorError(VirtualFrame frame, LookupSpeci
287
301
288
302
@ GenerateUncached
289
303
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
-
305
304
@ Override
306
305
protected boolean op (boolean a , boolean b ) {
307
306
return a == b ;
@@ -319,7 +318,7 @@ protected boolean op(long a, long b) {
319
318
320
319
@ Override
321
320
protected boolean op (double a , double b ) {
322
- return a == b ;
321
+ return a == b || ( Double . isNaN ( a ) && Double . isNaN ( b )) ;
323
322
}
324
323
325
324
@ Override
@@ -338,8 +337,19 @@ protected SpecialMethodSlot getReverseSlot() {
338
337
}
339
338
340
339
@ 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 ;
343
353
}
344
354
345
355
public static EqNode create () {
@@ -353,16 +363,6 @@ public static EqNode getUncached() {
353
363
354
364
@ GenerateUncached
355
365
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
-
366
366
@ Override
367
367
protected boolean op (boolean a , boolean b ) {
368
368
return a != b ;
@@ -399,8 +399,19 @@ protected SpecialMethodSlot getReverseSlot() {
399
399
}
400
400
401
401
@ 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 ;
404
415
}
405
416
406
417
public static NeNode create () {
@@ -445,7 +456,7 @@ protected SpecialMethodSlot getReverseSlot() {
445
456
}
446
457
447
458
@ Override
448
- protected boolean doDefault (PRaiseNode raiseNode , IsExpressionNode . IsNode isNode , Object a , Object b ) {
459
+ protected boolean doDefault (PRaiseNode raiseNode , Object a , Object b ) {
449
460
throw raiseNode .raise (TypeError , ErrorMessages .NOT_SUPPORTED_BETWEEN_INSTANCES , "<" , a , b );
450
461
}
451
462
@@ -491,7 +502,7 @@ protected SpecialMethodSlot getReverseSlot() {
491
502
}
492
503
493
504
@ Override
494
- protected boolean doDefault (PRaiseNode raiseNode , IsExpressionNode . IsNode isNode , Object a , Object b ) {
505
+ protected boolean doDefault (PRaiseNode raiseNode , Object a , Object b ) {
495
506
throw raiseNode .raise (TypeError , ErrorMessages .NOT_SUPPORTED_BETWEEN_INSTANCES , "<=" , a , b );
496
507
}
497
508
@@ -537,7 +548,7 @@ protected SpecialMethodSlot getReverseSlot() {
537
548
}
538
549
539
550
@ Override
540
- protected boolean doDefault (PRaiseNode raiseNode , IsExpressionNode . IsNode isNode , Object a , Object b ) {
551
+ protected boolean doDefault (PRaiseNode raiseNode , Object a , Object b ) {
541
552
throw raiseNode .raise (TypeError , ErrorMessages .NOT_SUPPORTED_BETWEEN_INSTANCES , ">" , a , b );
542
553
}
543
554
@@ -583,7 +594,7 @@ protected SpecialMethodSlot getReverseSlot() {
583
594
}
584
595
585
596
@ Override
586
- protected boolean doDefault (PRaiseNode raiseNode , IsExpressionNode . IsNode isNode , Object a , Object b ) {
597
+ protected boolean doDefault (PRaiseNode raiseNode , Object a , Object b ) {
587
598
throw raiseNode .raise (TypeError , ErrorMessages .NOT_SUPPORTED_BETWEEN_INSTANCES , ">=" , a , b );
588
599
}
589
600
0 commit comments