Skip to content

Commit 3071a95

Browse files
committed
[GR-11006] Provide more specific return types in builtins.
PullRequest: graalpython/129
2 parents 680d09a + 2f06132 commit 3071a95

File tree

14 files changed

+132
-136
lines changed

14 files changed

+132
-136
lines changed

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -755,10 +755,13 @@ private Object getId(PythonObject obj) {
755755
if (readId == null) {
756756
CompilerDirectives.transferToInterpreterAndInvalidate();
757757
readId = insert(ReadAttributeFromObjectNode.create());
758-
writeId = insert(WriteAttributeToObjectNode.create());
759758
}
760759
Object id = readId.execute(obj, ID_KEY);
761760
if (id == NO_VALUE) {
761+
if (writeId == null) {
762+
CompilerDirectives.transferToInterpreterAndInvalidate();
763+
writeId = insert(WriteAttributeToObjectNode.create());
764+
}
762765
id = getContext().getNextGlobalId();
763766
writeId.execute(obj, ID_KEY, id);
764767
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/complex/ComplexBuiltins.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ PComplex doComplex(PComplex left, PComplex right) {
249249

250250
@SuppressWarnings("unused")
251251
@Fallback
252-
Object doComplex(Object left, Object right) {
252+
PNotImplemented doComplex(Object left, Object right) {
253253
return PNotImplemented.NOT_IMPLEMENTED;
254254
}
255255
}
@@ -281,7 +281,7 @@ PComplex doComplex(PComplex left, PComplex right) {
281281

282282
@SuppressWarnings("unused")
283283
@Fallback
284-
Object doComplex(Object left, Object right) {
284+
PNotImplemented doComplex(Object left, Object right) {
285285
return PNotImplemented.NOT_IMPLEMENTED;
286286
}
287287
}
@@ -300,7 +300,7 @@ PComplex doComplexDouble(PComplex right, double left) {
300300

301301
@SuppressWarnings("unused")
302302
@Fallback
303-
Object doComplex(Object left, Object right) {
303+
PNotImplemented doComplex(Object left, Object right) {
304304
return PNotImplemented.NOT_IMPLEMENTED;
305305
}
306306
}
@@ -333,7 +333,7 @@ PComplex doComplexPInt(PComplex left, PInt right) {
333333

334334
@SuppressWarnings("unused")
335335
@Fallback
336-
Object doGeneric(Object left, Object right) {
336+
PNotImplemented doGeneric(Object left, Object right) {
337337
return PNotImplemented.NOT_IMPLEMENTED;
338338
}
339339
}
@@ -359,7 +359,7 @@ PComplex doComplex(PComplex left, PComplex right) {
359359

360360
@SuppressWarnings("unused")
361361
@Fallback
362-
Object doComplex(Object left, Object right) {
362+
PNotImplemented doComplex(Object left, Object right) {
363363
return PNotImplemented.NOT_IMPLEMENTED;
364364
}
365365
}
@@ -374,7 +374,7 @@ boolean doComplex(PComplex left, PComplex right) {
374374

375375
@SuppressWarnings("unused")
376376
@Fallback
377-
Object doGeneric(Object left, Object right) {
377+
PNotImplemented doGeneric(Object left, Object right) {
378378
return PNotImplemented.NOT_IMPLEMENTED;
379379
}
380380
}
@@ -389,7 +389,7 @@ boolean doComplex(PComplex left, PComplex right) {
389389

390390
@SuppressWarnings("unused")
391391
@Fallback
392-
Object doGeneric(Object left, Object right) {
392+
PNotImplemented doGeneric(Object left, Object right) {
393393
return PNotImplemented.NOT_IMPLEMENTED;
394394
}
395395
}
@@ -404,7 +404,7 @@ boolean doComplex(PComplex left, PComplex right) {
404404

405405
@SuppressWarnings("unused")
406406
@Fallback
407-
Object doGeneric(Object left, Object right) {
407+
PNotImplemented doGeneric(Object left, Object right) {
408408
return PNotImplemented.NOT_IMPLEMENTED;
409409
}
410410
}
@@ -419,7 +419,7 @@ boolean doComplex(PComplex left, PComplex right) {
419419

420420
@SuppressWarnings("unused")
421421
@Fallback
422-
Object doGeneric(Object left, Object right) {
422+
PNotImplemented doGeneric(Object left, Object right) {
423423
return PNotImplemented.NOT_IMPLEMENTED;
424424
}
425425
}
@@ -434,7 +434,7 @@ boolean doComplex(PComplex left, PComplex right) {
434434

435435
@SuppressWarnings("unused")
436436
@Fallback
437-
Object doGeneric(Object left, Object right) {
437+
PNotImplemented doGeneric(Object left, Object right) {
438438
return PNotImplemented.NOT_IMPLEMENTED;
439439
}
440440
}
@@ -449,7 +449,7 @@ boolean doComplex(PComplex left, PComplex right) {
449449

450450
@SuppressWarnings("unused")
451451
@Fallback
452-
Object doGeneric(Object left, Object right) {
452+
PNotImplemented doGeneric(Object left, Object right) {
453453
return PNotImplemented.NOT_IMPLEMENTED;
454454
}
455455
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/dict/DictBuiltins.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@
6262
import com.oracle.graal.python.nodes.call.special.LookupAndCallUnaryNode;
6363
import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
6464
import com.oracle.graal.python.nodes.function.PythonBuiltinNode;
65+
import com.oracle.graal.python.nodes.function.builtins.PythonBinaryBuiltinNode;
66+
import com.oracle.graal.python.nodes.function.builtins.PythonTernaryBuiltinNode;
6567
import com.oracle.graal.python.nodes.function.builtins.PythonUnaryBuiltinNode;
6668
import com.oracle.graal.python.runtime.exception.PythonErrorType;
6769
import com.oracle.truffle.api.CompilerDirectives;
@@ -255,7 +257,7 @@ private HashingStorageNodes.GetItemNode getGetItemNode() {
255257

256258
@Builtin(name = __GETITEM__, fixedNumOfArguments = 2)
257259
@GenerateNodeFactory
258-
public abstract static class GetItemNode extends PythonBuiltinNode {
260+
public abstract static class GetItemNode extends PythonBinaryBuiltinNode {
259261
@Specialization
260262
Object getItem(PDict self, Object key,
261263
@Cached("create()") HashingStorageNodes.GetItemNode getItemNode,
@@ -297,7 +299,7 @@ Object run(Object self, Object key,
297299

298300
@Builtin(name = __SETITEM__, fixedNumOfArguments = 3)
299301
@GenerateNodeFactory
300-
public abstract static class SetItemNode extends PythonBuiltinNode {
302+
public abstract static class SetItemNode extends PythonTernaryBuiltinNode {
301303
@Specialization
302304
Object run(PDict self, Object key, Object value,
303305
@Cached("create()") HashingStorageNodes.SetItemNode setItemNode) {
@@ -339,7 +341,7 @@ Object doDictDict(PDict self, PDict other,
339341

340342
@Fallback
341343
@SuppressWarnings("unused")
342-
Object doGeneric(Object self, Object other) {
344+
PNotImplemented doGeneric(Object self, Object other) {
343345
return PNotImplemented.NOT_IMPLEMENTED;
344346
}
345347
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/dict/DictValuesBuiltins.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ boolean doItemsView(PDictValuesView self, PDictValuesView other,
9393

9494
@Fallback
9595
@SuppressWarnings("unused")
96-
Object doGeneric(Object self, Object other) {
96+
PNotImplemented doGeneric(Object self, Object other) {
9797
return PNotImplemented.NOT_IMPLEMENTED;
9898
}
9999
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/dict/DictViewBuiltins.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ boolean doItemsView(PDictItemsView self, PBaseSet other,
180180

181181
@Fallback
182182
@SuppressWarnings("unused")
183-
Object doGeneric(Object self, Object other) {
183+
PNotImplemented doGeneric(Object self, Object other) {
184184
return PNotImplemented.NOT_IMPLEMENTED;
185185
}
186186
}
@@ -210,7 +210,7 @@ public boolean notEqual(PDictView self, PBaseSet other) {
210210

211211
@Fallback
212212
@SuppressWarnings("unused")
213-
Object doGeneric(Object self, Object other) {
213+
PNotImplemented doGeneric(Object self, Object other) {
214214
return PNotImplemented.NOT_IMPLEMENTED;
215215
}
216216
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/floats/FloatBuiltins.java

Lines changed: 27 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ abstract static class AddNode extends PythonBinaryBuiltinNode {
215215

216216
@SuppressWarnings("unused")
217217
@Fallback
218-
Object doGeneric(Object left, Object right) {
218+
PNotImplemented doGeneric(Object left, Object right) {
219219
return PNotImplemented.NOT_IMPLEMENTED;
220220
}
221221
}
@@ -246,7 +246,7 @@ abstract static class SubNode extends PythonBinaryBuiltinNode {
246246

247247
@SuppressWarnings("unused")
248248
@Fallback
249-
Object doGeneric(Object left, Object right) {
249+
PNotImplemented doGeneric(Object left, Object right) {
250250
return PNotImplemented.NOT_IMPLEMENTED;
251251
}
252252
}
@@ -272,7 +272,7 @@ abstract static class RSubNode extends PythonBinaryBuiltinNode {
272272

273273
@SuppressWarnings("unused")
274274
@Fallback
275-
Object doGeneric(Object left, Object right) {
275+
PNotImplemented doGeneric(Object left, Object right) {
276276
return PNotImplemented.NOT_IMPLEMENTED;
277277
}
278278
}
@@ -313,7 +313,7 @@ Object doDP(PythonNativeObject left, double right,
313313

314314
@SuppressWarnings("unused")
315315
@Fallback
316-
Object doGeneric(Object left, Object right) {
316+
PNotImplemented doGeneric(Object left, Object right) {
317317
return PNotImplemented.NOT_IMPLEMENTED;
318318
}
319319
}
@@ -342,54 +342,54 @@ abstract static class PowerNode extends PythonTernaryBuiltinNode {
342342
return Math.pow(left, right);
343343
}
344344

345-
@Specialization(guards = "!isNone(mod)")
345+
@Specialization
346346
double doDL(double left, long right, long mod) {
347347
return Math.pow(left, right) % mod;
348348
}
349349

350-
@Specialization(guards = "!isNone(mod)")
350+
@Specialization
351351
double doDPi(double left, PInt right, long mod) {
352352
return Math.pow(left, right.doubleValue()) % mod;
353353
}
354354

355-
@Specialization(guards = "!isNone(mod)")
355+
@Specialization
356356
double doDD(double left, double right, long mod) {
357357
return Math.pow(left, right) % mod;
358358
}
359359

360-
@Specialization(guards = "!isNone(mod)")
360+
@Specialization
361361
double doDL(double left, long right, PInt mod) {
362362
return Math.pow(left, right) % mod.doubleValue();
363363
}
364364

365-
@Specialization(guards = "!isNone(mod)")
365+
@Specialization
366366
double doDPi(double left, PInt right, PInt mod) {
367367
return Math.pow(left, right.doubleValue()) % mod.doubleValue();
368368
}
369369

370-
@Specialization(guards = "!isNone(mod)")
370+
@Specialization
371371
double doDD(double left, double right, PInt mod) {
372372
return Math.pow(left, right) % mod.doubleValue();
373373
}
374374

375-
@Specialization(guards = "!isNone(mod)")
375+
@Specialization
376376
double doDL(double left, long right, double mod) {
377377
return Math.pow(left, right) % mod;
378378
}
379379

380-
@Specialization(guards = "!isNone(mod)")
380+
@Specialization
381381
double doDPi(double left, PInt right, double mod) {
382382
return Math.pow(left, right.doubleValue()) % mod;
383383
}
384384

385-
@Specialization(guards = "!isNone(mod)")
385+
@Specialization
386386
double doDD(double left, double right, double mod) {
387387
return Math.pow(left, right) % mod;
388388
}
389389

390390
@SuppressWarnings("unused")
391391
@Fallback
392-
Object doGeneric(Object left, Object right, Object none) {
392+
PNotImplemented doGeneric(Object left, Object right, Object none) {
393393
return PNotImplemented.NOT_IMPLEMENTED;
394394
}
395395
}
@@ -418,7 +418,7 @@ abstract static class FloorDivNode extends FloatBinaryBuiltinNode {
418418

419419
@SuppressWarnings("unused")
420420
@Fallback
421-
Object doGeneric(Object left, Object right) {
421+
PNotImplemented doGeneric(Object left, Object right) {
422422
return PNotImplemented.NOT_IMPLEMENTED;
423423
}
424424
}
@@ -490,9 +490,7 @@ public double fromhexFloat(PythonClass cl, String arg) {
490490
public Object fromhexO(PythonClass cl, String arg,
491491
@Cached("create(__CALL__)") LookupAndCallVarargsNode constr) {
492492
double value = fromHex(arg);
493-
Object result = constr.execute(cl, new Object[]{cl, value});
494-
495-
return result;
493+
return constr.execute(cl, new Object[]{cl, value});
496494
}
497495

498496
@Fallback
@@ -576,7 +574,7 @@ abstract static class RFloorDivNode extends FloatBinaryBuiltinNode {
576574

577575
@SuppressWarnings("unused")
578576
@Fallback
579-
Object doGeneric(Object right, Object left) {
577+
PNotImplemented doGeneric(Object right, Object left) {
580578
return PNotImplemented.NOT_IMPLEMENTED;
581579
}
582580
}
@@ -605,7 +603,7 @@ abstract static class ModNode extends FloatBinaryBuiltinNode {
605603

606604
@SuppressWarnings("unused")
607605
@Fallback
608-
Object doGeneric(Object right, Object left) {
606+
PNotImplemented doGeneric(Object right, Object left) {
609607
return PNotImplemented.NOT_IMPLEMENTED;
610608
}
611609
}
@@ -634,7 +632,7 @@ abstract static class RModNode extends FloatBinaryBuiltinNode {
634632

635633
@SuppressWarnings("unused")
636634
@Fallback
637-
Object doGeneric(Object right, Object left) {
635+
PNotImplemented doGeneric(Object right, Object left) {
638636
return PNotImplemented.NOT_IMPLEMENTED;
639637
}
640638
}
@@ -660,7 +658,7 @@ abstract static class DivNode extends FloatBinaryBuiltinNode {
660658

661659
@SuppressWarnings("unused")
662660
@Fallback
663-
Object doGeneric(Object left, Object right) {
661+
PNotImplemented doGeneric(Object left, Object right) {
664662
return PNotImplemented.NOT_IMPLEMENTED;
665663
}
666664
}
@@ -686,7 +684,7 @@ abstract static class RDivNode extends PythonBinaryBuiltinNode {
686684

687685
@SuppressWarnings("unused")
688686
@Fallback
689-
Object doGeneric(Object right, Object left) {
687+
PNotImplemented doGeneric(Object right, Object left) {
690688
return PNotImplemented.NOT_IMPLEMENTED;
691689
}
692690
}
@@ -769,7 +767,7 @@ boolean eqDbPI(double a, PInt b) {
769767

770768
@Fallback
771769
@SuppressWarnings("unused")
772-
Object eq(Object a, Object b) {
770+
PNotImplemented eq(Object a, Object b) {
773771
return PNotImplemented.NOT_IMPLEMENTED;
774772
}
775773
}
@@ -795,7 +793,7 @@ boolean eqDbPI(double a, PInt b) {
795793

796794
@Fallback
797795
@SuppressWarnings("unused")
798-
Object eq(Object a, Object b) {
796+
PNotImplemented eq(Object a, Object b) {
799797
return PNotImplemented.NOT_IMPLEMENTED;
800798
}
801799
}
@@ -816,7 +814,7 @@ boolean doDL(double x, long y) {
816814

817815
@Fallback
818816
@SuppressWarnings("unused")
819-
Object doGeneric(Object a, Object b) {
817+
PNotImplemented doGeneric(Object a, Object b) {
820818
return PNotImplemented.NOT_IMPLEMENTED;
821819
}
822820
}
@@ -837,7 +835,7 @@ boolean doDL(double x, long y) {
837835

838836
@Fallback
839837
@SuppressWarnings("unused")
840-
Object doGeneric(Object a, Object b) {
838+
PNotImplemented doGeneric(Object a, Object b) {
841839
return PNotImplemented.NOT_IMPLEMENTED;
842840
}
843841
}
@@ -858,7 +856,7 @@ boolean doDL(double x, long y) {
858856

859857
@Fallback
860858
@SuppressWarnings("unused")
861-
Object doGeneric(Object a, Object b) {
859+
PNotImplemented doGeneric(Object a, Object b) {
862860
return PNotImplemented.NOT_IMPLEMENTED;
863861
}
864862
}
@@ -879,7 +877,7 @@ boolean doDL(double x, long y) {
879877

880878
@Fallback
881879
@SuppressWarnings("unused")
882-
Object doGeneric(Object a, Object b) {
880+
PNotImplemented doGeneric(Object a, Object b) {
883881
return PNotImplemented.NOT_IMPLEMENTED;
884882
}
885883
}

0 commit comments

Comments
 (0)