|
73 | 73 | import com.oracle.graal.python.builtins.objects.object.PythonBuiltinObject;
|
74 | 74 | import com.oracle.graal.python.builtins.objects.object.PythonObject;
|
75 | 75 | import com.oracle.graal.python.builtins.objects.object.PythonObjectLibrary;
|
76 |
| -import com.oracle.graal.python.builtins.objects.object.PythonTypeLibrary; |
77 | 76 | import com.oracle.graal.python.builtins.objects.str.PString;
|
78 | 77 | import com.oracle.graal.python.builtins.objects.tuple.PTuple;
|
79 | 78 | import com.oracle.graal.python.builtins.objects.type.LazyPythonClass;
|
@@ -571,14 +570,62 @@ private static void addKeysFromObject(HashSet<String> keys, PythonObject o, bool
|
571 | 570 | }
|
572 | 571 | }
|
573 | 572 |
|
| 573 | + @ExportMessage |
| 574 | + public boolean isSequence(@Shared("thisObject") @Cached GetLazyClassNode getClassNode, |
| 575 | + @CachedLibrary(limit = "1") PythonObjectLibrary pythonTypeLibrary) { |
| 576 | + return pythonTypeLibrary.isSequenceType(getClassNode.execute(this)); |
| 577 | + } |
| 578 | + |
| 579 | + @ExportMessage |
| 580 | + public boolean isMapping(@Shared("thisObject") @Cached GetLazyClassNode getClassNode, |
| 581 | + @CachedLibrary(limit = "1") PythonObjectLibrary pythonTypeLibrary) { |
| 582 | + return pythonTypeLibrary.isMappingType(getClassNode.execute(this)); |
| 583 | + } |
| 584 | + |
| 585 | + @ExportMessage |
| 586 | + public boolean isSequenceType( |
| 587 | + @Shared("hasGetItemNode") @Cached LookupAttributeInMRONode.Dynamic hasGetItemNode, |
| 588 | + @Shared("hasLenNode") @Cached LookupAttributeInMRONode.Dynamic hasLenNode, |
| 589 | + @Shared("isLazyClass") @Cached("createBinaryProfile()") ConditionProfile isLazyClass, |
| 590 | + @Shared("lenProfile") @Cached("createBinaryProfile()") ConditionProfile lenProfile, |
| 591 | + @Shared("getItemProfile") @Cached("createBinaryProfile()") ConditionProfile getItemProfile) { |
| 592 | + if (isLazyClass.profile(this instanceof LazyPythonClass)) { |
| 593 | + LazyPythonClass type = (LazyPythonClass) this; // guaranteed to succeed because of guard |
| 594 | + if (lenProfile.profile(hasLenNode.execute(type, SpecialMethodNames.__LEN__) != PNone.NO_VALUE)) { |
| 595 | + return getItemProfile.profile(hasGetItemNode.execute(type, SpecialMethodNames.__GETITEM__) != PNone.NO_VALUE); |
| 596 | + } |
| 597 | + } |
| 598 | + return false; |
| 599 | + } |
| 600 | + |
| 601 | + @ExportMessage |
| 602 | + public boolean isMappingType( |
| 603 | + @Shared("hasGetItemNode") @Cached LookupAttributeInMRONode.Dynamic hasGetItemNode, |
| 604 | + @Shared("hasLenNode") @Cached LookupAttributeInMRONode.Dynamic hasLenNode, |
| 605 | + @Shared("isLazyClass") @Cached("createBinaryProfile()") ConditionProfile isLazyClass, |
| 606 | + @Shared("lenProfile") @Cached("createBinaryProfile()") ConditionProfile lenProfile, |
| 607 | + @Shared("getItemProfile") @Cached("createBinaryProfile()") ConditionProfile getItemProfile, |
| 608 | + @Exclusive @Cached LookupAttributeInMRONode.Dynamic hasKeysNode, |
| 609 | + @Exclusive @Cached LookupAttributeInMRONode.Dynamic hasItemsNode, |
| 610 | + @Exclusive @Cached LookupAttributeInMRONode.Dynamic hasValuesNode, |
| 611 | + @Exclusive @Cached("createBinaryProfile()") ConditionProfile profile) { |
| 612 | + if (isSequenceType(hasGetItemNode, hasLenNode, isLazyClass, lenProfile, getItemProfile)) { |
| 613 | + LazyPythonClass type = (LazyPythonClass) this; // guaranteed to succeed b/c it's a sequence type |
| 614 | + return profile.profile(hasKeysNode.execute(type, SpecialMethodNames.KEYS) != PNone.NO_VALUE && |
| 615 | + hasItemsNode.execute(type, SpecialMethodNames.ITEMS) != PNone.NO_VALUE && |
| 616 | + hasValuesNode.execute(type, SpecialMethodNames.VALUES) != PNone.NO_VALUE); |
| 617 | + } |
| 618 | + return false; |
| 619 | + } |
| 620 | + |
574 | 621 | @ExportMessage
|
575 | 622 | public final boolean isIterable(@Shared("thisObject") @Cached GetLazyClassNode getClassNode,
|
576 |
| - @Cached LookupAttributeInMRONode.Dynamic getIterNode, |
577 |
| - @Cached LookupAttributeInMRONode.Dynamic getGetItemNode, |
578 |
| - @Cached LookupAttributeInMRONode.Dynamic hasNextNode, |
| 623 | + @Exclusive @Cached LookupAttributeInMRONode.Dynamic getIterNode, |
| 624 | + @Shared("hasGetItemNode") @Cached LookupAttributeInMRONode.Dynamic getGetItemNode, |
| 625 | + @Exclusive @Cached LookupAttributeInMRONode.Dynamic hasNextNode, |
579 | 626 | @CachedLibrary(limit = "1") PythonObjectLibrary dataModelLibrary,
|
580 | 627 | @Exclusive @Cached("createBinaryProfile()") ConditionProfile profileIter,
|
581 |
| - @Exclusive @Cached("createBinaryProfile()") ConditionProfile profileGetItem, |
| 628 | + @Shared("getItemProfile") @Cached("createBinaryProfile()") ConditionProfile profileGetItem, |
582 | 629 | @Exclusive @Cached("createBinaryProfile()") ConditionProfile profileNext) {
|
583 | 630 | LazyPythonClass klass = getClassNode.execute(this);
|
584 | 631 | Object iterMethod = getIterNode.execute(klass, __ITER__);
|
@@ -621,18 +668,6 @@ public final boolean isContextManager(@Exclusive @Cached HasInheritedAttributeNo
|
621 | 668 | return profile.profile(hasEnterNode.execute(this, __ENTER__) && hasExitNode.execute(this, __EXIT__));
|
622 | 669 | }
|
623 | 670 |
|
624 |
| - @ExportMessage |
625 |
| - public boolean isSequence(@Shared("thisObject") @Cached GetLazyClassNode getClassNode, |
626 |
| - @CachedLibrary(limit = "1") PythonTypeLibrary pythonTypeLibrary) { |
627 |
| - return pythonTypeLibrary.isSequenceType(getClassNode.execute(this)); |
628 |
| - } |
629 |
| - |
630 |
| - @ExportMessage |
631 |
| - public boolean isMapping(@Shared("thisObject") @Cached GetLazyClassNode getClassNode, |
632 |
| - @CachedLibrary(limit = "1") PythonTypeLibrary pythonTypeLibrary) { |
633 |
| - return pythonTypeLibrary.isMappingType(getClassNode.execute(this)); |
634 |
| - } |
635 |
| - |
636 | 671 | @GenerateUncached
|
637 | 672 | public abstract static class PKeyInfoNode extends Node {
|
638 | 673 | private static final int NONE = 0;
|
|
0 commit comments