This repository was archived by the owner on Oct 11, 2025. It is now read-only.
Commit a600a09
authored
[MLIR][Python] Add optional
Currently in MLIR python bindings, operations with inferable result
types (e.g. with `InferTypeOpInterface` or `SameOperandsAndResultType`)
will generate such builder functions:
```python
def my_op(arg1, arg2 .. argN, *, loc=None, ip=None):
... # result types will be inferred automatically
```
However, in some cases we may want to provide the result types
explicitly. For example, the implementation of interface method
`inferResultTypes(..)` can return a failure and then we cannot build the
op in that way. Also, in the C++ side we have multiple `build` methods
for both explicitly specify the result types and automatically inferring
them.
In this PR, we change the signature of this builder function to:
```python
def my_op(arg1, arg2 .. argN, *, results=None, loc=None, ip=None):
... # result types will be inferred automatically if results is None
```
If the `results` is not provided, it will be inferred automatically,
otherwise the provided result types will be utilized. Also, `__init__`
methods of the generated op classes are changed correspondingly. Note
that for operations without inferable result types, the signature remain
unchanged, i.e. `def my_op(res1 .. resN, arg1 .. argN, *, loc=None,
ip=None)`.
---
Previously I have considered an approach like `my_op(arg, *, res1=None,
res2=None, loc=None, ip=None)`, but I quickly realized it had some
issues. For example, if the user only provides some of the arguments—say
`my_op(v1, res1=i32)`—this could lead to problems. Moreover, we don’t
seem to have a mechanism for inferring only part of result types. A
unified `results` parameter seems to be more simple and straightforward.results parameter for building op with inferable result types (#156818)1 parent 7b42861 commit a600a09
1 file changed
Lines changed: 27 additions & 19 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
492 | 492 | | |
493 | 493 | | |
494 | 494 | | |
495 | | - | |
496 | 495 | | |
497 | 496 | | |
498 | 497 | | |
| |||
738 | 737 | | |
739 | 738 | | |
740 | 739 | | |
741 | | - | |
742 | | - | |
| 740 | + | |
| 741 | + | |
743 | 742 | | |
744 | | - | |
745 | | - | |
746 | | - | |
| 743 | + | |
| 744 | + | |
| 745 | + | |
| 746 | + | |
| 747 | + | |
747 | 748 | | |
748 | 749 | | |
749 | | - | |
| 750 | + | |
| 751 | + | |
750 | 752 | | |
751 | | - | |
752 | | - | |
| 753 | + | |
| 754 | + | |
| 755 | + | |
| 756 | + | |
| 757 | + | |
753 | 758 | | |
754 | 759 | | |
755 | 760 | | |
| |||
768 | 773 | | |
769 | 774 | | |
770 | 775 | | |
771 | | - | |
772 | | - | |
773 | 776 | | |
774 | | - | |
775 | | - | |
| 777 | + | |
| 778 | + | |
| 779 | + | |
776 | 780 | | |
777 | 781 | | |
778 | 782 | | |
779 | 783 | | |
780 | 784 | | |
781 | 785 | | |
782 | 786 | | |
783 | | - | |
| 787 | + | |
| 788 | + | |
| 789 | + | |
784 | 790 | | |
785 | | - | |
786 | | - | |
787 | | - | |
788 | 791 | | |
789 | 792 | | |
790 | 793 | | |
791 | 794 | | |
792 | 795 | | |
793 | 796 | | |
| 797 | + | |
| 798 | + | |
| 799 | + | |
794 | 800 | | |
795 | 801 | | |
796 | 802 | | |
| |||
909 | 915 | | |
910 | 916 | | |
911 | 917 | | |
| 918 | + | |
| 919 | + | |
| 920 | + | |
912 | 921 | | |
913 | 922 | | |
914 | 923 | | |
| |||
918 | 927 | | |
919 | 928 | | |
920 | 929 | | |
921 | | - | |
922 | | - | |
| 930 | + | |
923 | 931 | | |
924 | 932 | | |
925 | 933 | | |
| |||
0 commit comments