|
110 | 110 | import com.oracle.truffle.api.dsl.NeverDefault;
|
111 | 111 | import com.oracle.truffle.api.dsl.NodeFactory;
|
112 | 112 | import com.oracle.truffle.api.dsl.Specialization;
|
| 113 | +import com.oracle.truffle.api.frame.Frame; |
113 | 114 | import com.oracle.truffle.api.frame.VirtualFrame;
|
114 | 115 | import com.oracle.truffle.api.nodes.LoopNode;
|
115 | 116 | import com.oracle.truffle.api.nodes.Node;
|
@@ -490,217 +491,97 @@ static PBaseSet doGeneric(VirtualFrame frame, Object self, Object other,
|
490 | 491 | }
|
491 | 492 | }
|
492 | 493 |
|
493 |
| - @Slot(value = SlotKind.nb_and, isComplex = true) |
494 |
| - @GenerateNodeFactory |
495 |
| - abstract static class AndNode extends BinaryOpBuiltinNode { |
| 494 | + @GenerateInline |
| 495 | + @GenerateCached(false) |
| 496 | + abstract static class GetStorageForBinopNode extends Node { |
| 497 | + public abstract HashingStorage execute(Frame frame, Node inliningTarget, Object obj); |
496 | 498 |
|
497 | 499 | @Specialization
|
498 |
| - static PBaseSet doKeysView(VirtualFrame frame, PDictKeysView self, PBaseSet other, |
499 |
| - @Bind("this") Node inliningTarget, |
500 |
| - @Shared("intersect") @Cached HashingStorageIntersect intersectNode, |
501 |
| - @Shared @Cached PythonObjectFactory factory) { |
502 |
| - HashingStorage left = self.getWrappedStorage(); |
503 |
| - HashingStorage right = other.getDictStorage(); |
504 |
| - HashingStorage intersectedStorage = intersectNode.execute(frame, inliningTarget, left, right); |
505 |
| - return factory.createSet(intersectedStorage); |
| 500 | + static HashingStorage doView(PDictKeysView obj) { |
| 501 | + return obj.getWrappedStorage(); |
506 | 502 | }
|
507 | 503 |
|
508 | 504 | @Specialization
|
509 |
| - static PBaseSet doKeysView(VirtualFrame frame, PDictKeysView self, PDictKeysView other, |
510 |
| - @Bind("this") Node inliningTarget, |
511 |
| - @Shared("intersect") @Cached HashingStorageIntersect intersectNode, |
512 |
| - @Shared @Cached PythonObjectFactory factory) { |
513 |
| - HashingStorage left = self.getWrappedStorage(); |
514 |
| - HashingStorage right = other.getWrappedStorage(); |
515 |
| - HashingStorage intersectedStorage = intersectNode.execute(frame, inliningTarget, left, right); |
516 |
| - return factory.createSet(intersectedStorage); |
| 505 | + static HashingStorage doSet(PBaseSet obj) { |
| 506 | + return obj.getDictStorage(); |
517 | 507 | }
|
518 | 508 |
|
519 |
| - @Specialization |
520 |
| - static PBaseSet doKeysView(VirtualFrame frame, PDictKeysView self, Object other, |
521 |
| - @Bind("this") Node inliningTarget, |
522 |
| - @Shared("constrSet") @Cached SetNodes.ConstructSetNode constructSetNode, |
523 |
| - @Shared("intersect") @Cached HashingStorageIntersect intersectNode, |
524 |
| - @Shared @Cached PythonObjectFactory factory) { |
525 |
| - HashingStorage left = self.getWrappedStorage(); |
526 |
| - HashingStorage right = constructSetNode.executeWith(frame, other).getDictStorage(); |
527 |
| - HashingStorage intersectedStorage = intersectNode.execute(frame, inliningTarget, left, right); |
528 |
| - return factory.createSet(intersectedStorage); |
| 509 | + @Fallback |
| 510 | + static HashingStorage doOther(VirtualFrame frame, Object obj, |
| 511 | + @Cached SetNodes.ConstructSetNode constructSetNode) { |
| 512 | + return constructSetNode.executeWith(frame, obj).getDictStorage(); |
529 | 513 | }
|
| 514 | + } |
| 515 | + |
| 516 | + @GenerateInline |
| 517 | + @GenerateCached(false) |
| 518 | + abstract static class GetCopiedStorageForBinopNode extends Node { |
| 519 | + public abstract HashingStorage execute(Frame frame, Node inliningTarget, Object obj); |
530 | 520 |
|
531 | 521 | @Specialization
|
532 |
| - static PBaseSet doItemsView(VirtualFrame frame, PDictItemsView self, PBaseSet other, |
533 |
| - @Bind("this") Node inliningTarget, |
534 |
| - @Shared("intersect") @Cached HashingStorageIntersect intersectNode, |
535 |
| - @Shared("constrSet") @Cached SetNodes.ConstructSetNode constructSetNode, |
536 |
| - @Shared @Cached PythonObjectFactory factory) { |
537 |
| - PSet selfSet = constructSetNode.executeWith(frame, self); |
538 |
| - HashingStorage left = selfSet.getDictStorage(); |
539 |
| - HashingStorage right = other.getDictStorage(); |
540 |
| - HashingStorage intersectedStorage = intersectNode.execute(frame, inliningTarget, left, right); |
541 |
| - return factory.createSet(intersectedStorage); |
| 522 | + static HashingStorage doView(Node inliningTarget, PDictKeysView obj, |
| 523 | + @Shared @Cached HashingStorageCopy copyNode) { |
| 524 | + return copyNode.execute(inliningTarget, obj.getWrappedStorage()); |
542 | 525 | }
|
543 | 526 |
|
544 | 527 | @Specialization
|
545 |
| - static PBaseSet doItemsView(VirtualFrame frame, PDictItemsView self, PDictItemsView other, |
546 |
| - @Bind("this") Node inliningTarget, |
547 |
| - @Shared("intersect") @Cached HashingStorageIntersect intersectNode, |
548 |
| - @Shared("constrSet") @Cached SetNodes.ConstructSetNode constructSetNode, |
549 |
| - @Shared @Cached PythonObjectFactory factory) { |
550 |
| - PSet selfSet = constructSetNode.executeWith(frame, self); |
551 |
| - PSet otherSet = constructSetNode.executeWith(frame, other); |
552 |
| - HashingStorage left = selfSet.getDictStorage(); |
553 |
| - HashingStorage right = otherSet.getDictStorage(); |
554 |
| - HashingStorage intersectedStorage = intersectNode.execute(frame, inliningTarget, left, right); |
555 |
| - return factory.createSet(intersectedStorage); |
| 528 | + static HashingStorage doSet(Node inliningTarget, PBaseSet obj, |
| 529 | + @Shared @Cached HashingStorageCopy copyNode) { |
| 530 | + return copyNode.execute(inliningTarget, obj.getDictStorage()); |
556 | 531 | }
|
557 | 532 |
|
558 |
| - @Specialization |
559 |
| - static PBaseSet doItemsView(VirtualFrame frame, PDictItemsView self, Object other, |
560 |
| - @Bind("this") Node inliningTarget, |
561 |
| - @Shared("constrSet") @Cached SetNodes.ConstructSetNode constructSetNode, |
562 |
| - @Shared("intersect") @Cached HashingStorageIntersect intersectNode, |
563 |
| - @Shared @Cached PythonObjectFactory factory) { |
564 |
| - HashingStorage left = constructSetNode.executeWith(frame, self).getDictStorage(); |
565 |
| - HashingStorage right = constructSetNode.executeWith(frame, other).getDictStorage(); |
566 |
| - HashingStorage intersectedStorage = intersectNode.execute(frame, inliningTarget, left, right); |
567 |
| - return factory.createSet(intersectedStorage); |
| 533 | + @Fallback |
| 534 | + static HashingStorage doOther(VirtualFrame frame, Object obj, |
| 535 | + @Cached SetNodes.ConstructSetNode constructSetNode) { |
| 536 | + return constructSetNode.executeWith(frame, obj).getDictStorage(); |
568 | 537 | }
|
569 | 538 | }
|
570 | 539 |
|
571 |
| - @Slot(value = SlotKind.nb_or, isComplex = true) |
| 540 | + @Slot(value = SlotKind.nb_and, isComplex = true) |
572 | 541 | @GenerateNodeFactory
|
573 |
| - public abstract static class OrNode extends BinaryOpBuiltinNode { |
574 |
| - |
575 |
| - protected static HashingStorage union(Node inliningTarget, HashingStorageCopy copyNode, HashingStorageAddAllToOther addAllToOther, HashingStorage left, HashingStorage right) { |
576 |
| - return left.union(inliningTarget, right, copyNode, addAllToOther); |
577 |
| - } |
578 |
| - |
579 |
| - @Specialization |
580 |
| - static PBaseSet doKeysView(@SuppressWarnings("unused") VirtualFrame frame, PDictKeysView self, PBaseSet other, |
581 |
| - @Bind("this") Node inliningTarget, |
582 |
| - @Shared("copy") @Cached HashingStorageCopy copyNode, |
583 |
| - @Shared("addAll") @Cached HashingStorageAddAllToOther addAllToOther, |
584 |
| - @Shared @Cached PythonObjectFactory factory) { |
585 |
| - return factory.createSet(union(inliningTarget, copyNode, addAllToOther, self.getWrappedStorage(), other.getDictStorage())); |
586 |
| - } |
587 |
| - |
588 |
| - @Specialization |
589 |
| - static PBaseSet doKeysView(@SuppressWarnings("unused") VirtualFrame frame, PDictKeysView self, PDictKeysView other, |
590 |
| - @Bind("this") Node inliningTarget, |
591 |
| - @Shared("copy") @Cached HashingStorageCopy copyNode, |
592 |
| - @Shared("addAll") @Cached HashingStorageAddAllToOther addAllToOther, |
593 |
| - @Shared @Cached PythonObjectFactory factory) { |
594 |
| - return factory.createSet(union(inliningTarget, copyNode, addAllToOther, self.getWrappedStorage(), other.getWrappedStorage())); |
595 |
| - } |
596 |
| - |
597 |
| - @Specialization |
598 |
| - static PBaseSet doKeysView(@SuppressWarnings("unused") VirtualFrame frame, PDictKeysView self, Object other, |
599 |
| - @Bind("this") Node inliningTarget, |
600 |
| - @Shared @Cached SetNodes.ConstructSetNode constructSetNode, |
601 |
| - @Shared("copy") @Cached HashingStorageCopy copyNode, |
602 |
| - @Shared("addAll") @Cached HashingStorageAddAllToOther addAllToOther, |
603 |
| - @Shared @Cached PythonObjectFactory factory) { |
604 |
| - return factory.createSet(union(inliningTarget, copyNode, addAllToOther, self.getWrappedStorage(), constructSetNode.executeWith(frame, other).getDictStorage())); |
605 |
| - } |
| 542 | + abstract static class AndNode extends BinaryOpBuiltinNode { |
606 | 543 |
|
607 | 544 | @Specialization
|
608 |
| - static PBaseSet doItemsView(VirtualFrame frame, PDictItemsView self, PBaseSet other, |
| 545 | + static PBaseSet doGeneric(VirtualFrame frame, Object self, Object other, |
609 | 546 | @Bind("this") Node inliningTarget,
|
610 |
| - @Shared("copy") @Cached HashingStorageCopy copyNode, |
611 |
| - @Shared("addAll") @Cached HashingStorageAddAllToOther addAllToOther, |
612 |
| - @Shared @Cached SetNodes.ConstructSetNode constructSetNode, |
613 |
| - @Shared @Cached PythonObjectFactory factory) { |
614 |
| - PSet selfSet = constructSetNode.executeWith(frame, self); |
615 |
| - return factory.createSet(union(inliningTarget, copyNode, addAllToOther, selfSet.getDictStorage(), other.getDictStorage())); |
| 547 | + @Cached GetStorageForBinopNode getStorage, |
| 548 | + @Cached HashingStorageIntersect intersectNode, |
| 549 | + @Cached PythonObjectFactory factory) { |
| 550 | + HashingStorage left = getStorage.execute(frame, inliningTarget, self); |
| 551 | + HashingStorage right = getStorage.execute(frame, inliningTarget, other); |
| 552 | + return factory.createSet(intersectNode.execute(frame, inliningTarget, left, right)); |
616 | 553 | }
|
| 554 | + } |
617 | 555 |
|
618 |
| - @Specialization |
619 |
| - static PBaseSet doItemsView(VirtualFrame frame, PDictItemsView self, PDictItemsView other, |
620 |
| - @Bind("this") Node inliningTarget, |
621 |
| - @Shared("copy") @Cached HashingStorageCopy copyNode, |
622 |
| - @Shared("addAll") @Cached HashingStorageAddAllToOther addAllToOther, |
623 |
| - @Shared @Cached SetNodes.ConstructSetNode constructSetNode, |
624 |
| - @Shared @Cached PythonObjectFactory factory) { |
625 |
| - PSet selfSet = constructSetNode.executeWith(frame, self); |
626 |
| - PSet otherSet = constructSetNode.executeWith(frame, other); |
627 |
| - return factory.createSet(union(inliningTarget, copyNode, addAllToOther, selfSet.getDictStorage(), otherSet.getDictStorage())); |
628 |
| - } |
| 556 | + @Slot(value = SlotKind.nb_or, isComplex = true) |
| 557 | + @GenerateNodeFactory |
| 558 | + public abstract static class OrNode extends BinaryOpBuiltinNode { |
629 | 559 |
|
630 | 560 | @Specialization
|
631 |
| - static PBaseSet doItemsView(VirtualFrame frame, PDictItemsView self, Object other, |
| 561 | + static PBaseSet doGeneric(VirtualFrame frame, Object self, Object other, |
632 | 562 | @Bind("this") Node inliningTarget,
|
633 |
| - @Shared @Cached SetNodes.ConstructSetNode constructSetNode, |
634 |
| - @Shared("copy") @Cached HashingStorageCopy copyNode, |
635 |
| - @Shared("addAll") @Cached HashingStorageAddAllToOther addAllToOther, |
636 |
| - @Shared @Cached PythonObjectFactory factory) { |
637 |
| - HashingStorage selfStorage = constructSetNode.executeWith(frame, self).getDictStorage(); |
638 |
| - HashingStorage otherStorage = constructSetNode.executeWith(frame, other).getDictStorage(); |
639 |
| - return factory.createSet(union(inliningTarget, copyNode, addAllToOther, selfStorage, otherStorage)); |
| 563 | + @Cached GetCopiedStorageForBinopNode getStorage, |
| 564 | + @Cached HashingStorageAddAllToOther addAllToOther, |
| 565 | + @Cached PythonObjectFactory factory) { |
| 566 | + HashingStorage left = getStorage.execute(frame, inliningTarget, self); |
| 567 | + HashingStorage right = getStorage.execute(frame, inliningTarget, other); |
| 568 | + return factory.createSet(addAllToOther.execute(frame, inliningTarget, left, right)); |
640 | 569 | }
|
641 | 570 | }
|
642 | 571 |
|
643 | 572 | @Slot(value = SlotKind.nb_xor, isComplex = true)
|
644 | 573 | @GenerateNodeFactory
|
645 | 574 | public abstract static class XorNode extends BinaryOpBuiltinNode {
|
646 | 575 |
|
647 |
| - protected static HashingStorage xor(VirtualFrame frame, Node inliningTarget, HashingStorageXor xorNode, HashingStorage left, HashingStorage right) { |
648 |
| - return xorNode.execute(frame, inliningTarget, left, right); |
649 |
| - } |
650 |
| - |
651 |
| - @Specialization |
652 |
| - static PBaseSet doKeysView(VirtualFrame frame, PDictKeysView self, PBaseSet other, |
653 |
| - @Bind("this") Node inliningTarget, |
654 |
| - @Shared("xorNode") @Cached HashingStorageXor xorNode, |
655 |
| - @Shared @Cached PythonObjectFactory factory) { |
656 |
| - return factory.createSet(xor(frame, inliningTarget, xorNode, self.getWrappedStorage(), other.getDictStorage())); |
657 |
| - } |
658 |
| - |
659 | 576 | @Specialization
|
660 |
| - static PBaseSet doKeysView(VirtualFrame frame, PDictKeysView self, PDictKeysView other, |
661 |
| - @Bind("this") Node inliningTarget, |
662 |
| - @Shared("xorNode") @Cached HashingStorageXor xorNode, |
663 |
| - @Shared @Cached PythonObjectFactory factory) { |
664 |
| - return factory.createSet(xor(frame, inliningTarget, xorNode, self.getWrappedStorage(), other.getWrappedStorage())); |
665 |
| - } |
666 |
| - |
667 |
| - @Specialization |
668 |
| - static PBaseSet doKeysView(VirtualFrame frame, PDictKeysView self, Object other, |
669 |
| - @Bind("this") Node inliningTarget, |
670 |
| - @Shared("constructSet") @Cached SetNodes.ConstructSetNode constructSetNode, |
671 |
| - @Shared("xorNode") @Cached HashingStorageXor xorNode, |
672 |
| - @Shared @Cached PythonObjectFactory factory) { |
673 |
| - return factory.createSet(xor(frame, inliningTarget, xorNode, self.getWrappedStorage(), constructSetNode.executeWith(frame, other).getDictStorage())); |
674 |
| - } |
675 |
| - |
676 |
| - @Specialization |
677 |
| - static PBaseSet doItemsView(VirtualFrame frame, PDictItemsView self, PBaseSet other, |
678 |
| - @Bind("this") Node inliningTarget, |
679 |
| - @Shared("xorNode") @Cached HashingStorageXor xorNode, |
680 |
| - @Shared("constructSet") @Cached SetNodes.ConstructSetNode constructSetNode, |
681 |
| - @Shared @Cached PythonObjectFactory factory) { |
682 |
| - PSet selfSet = constructSetNode.executeWith(frame, self); |
683 |
| - return factory.createSet(xor(frame, inliningTarget, xorNode, selfSet.getDictStorage(), other.getDictStorage())); |
684 |
| - } |
685 |
| - |
686 |
| - @Specialization |
687 |
| - static PBaseSet doItemsView(@SuppressWarnings("unused") VirtualFrame frame, PDictItemsView self, PDictItemsView other, |
688 |
| - @Bind("this") Node inliningTarget, |
689 |
| - @Shared("xorNode") @Cached HashingStorageXor xorNode, |
690 |
| - @Shared("constructSet") @Cached SetNodes.ConstructSetNode constructSetNode, |
691 |
| - @Shared @Cached PythonObjectFactory factory) { |
692 |
| - PSet selfSet = constructSetNode.executeWith(frame, self); |
693 |
| - PSet otherSet = constructSetNode.executeWith(frame, other); |
694 |
| - return factory.createSet(xor(frame, inliningTarget, xorNode, selfSet.getDictStorage(), otherSet.getDictStorage())); |
695 |
| - } |
696 |
| - |
697 |
| - @Specialization |
698 |
| - static PBaseSet doItemsView(@SuppressWarnings("unused") VirtualFrame frame, PDictItemsView self, Object other, |
| 577 | + static PBaseSet doGeneric(VirtualFrame frame, Object self, Object other, |
699 | 578 | @Bind("this") Node inliningTarget,
|
700 |
| - @Shared("constructSet") @Cached SetNodes.ConstructSetNode constructSetNode, |
701 |
| - @Shared("xorNode") @Cached HashingStorageXor xorNode, |
702 |
| - @Shared @Cached PythonObjectFactory factory) { |
703 |
| - return factory.createSet(xor(frame, inliningTarget, xorNode, constructSetNode.executeWith(frame, self).getDictStorage(), constructSetNode.executeWith(frame, other).getDictStorage())); |
| 579 | + @Cached GetStorageForBinopNode getStorage, |
| 580 | + @Cached HashingStorageXor xor, |
| 581 | + @Cached PythonObjectFactory factory) { |
| 582 | + HashingStorage left = getStorage.execute(frame, inliningTarget, self); |
| 583 | + HashingStorage right = getStorage.execute(frame, inliningTarget, other); |
| 584 | + return factory.createSet(xor.execute(frame, inliningTarget, left, right)); |
704 | 585 | }
|
705 | 586 | }
|
706 | 587 |
|
|
0 commit comments