[all-commits] [llvm/llvm-project] e0ca7e: [MLIR][python bindings] Fix inferReturnTypes + Att...

Maksim Levental via All-commits all-commits at lists.llvm.org
Fri May 26 12:52:06 PDT 2023


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: e0ca7e99914609bbed0f30f4834a93d33dcef085
      https://github.com/llvm/llvm-project/commit/e0ca7e99914609bbed0f30f4834a93d33dcef085
  Author: max <maksim.levental at gmail.com>
  Date:   2023-05-26 (Fri, 26 May 2023)

  Changed paths:
    M mlir/lib/Bindings/Python/IRInterfaces.cpp
    M mlir/test/python/dialects/python_test.py
    M mlir/test/python/python_test_ops.td

  Log Message:
  -----------
  [MLIR][python bindings] Fix inferReturnTypes + AttrSizedOperandSegments for optional operands

Right now `inferTypeOpInterface.inferReturnTypes` fails because there's a cast in there to `py::sequence` which throws a `TypeError` when it tries to cast the `None`s. Note `None`s are inserted into `operands` for omitted operands passed to the generated builder:

```
    operands.append(_get_op_result_or_value(start) if start is not None else None)
    operands.append(_get_op_result_or_value(stop) if stop is not None else None)
    operands.append(_get_op_result_or_value(step) if step is not None else None)
```

Note also that skipping appending to the list operands doesn't work either because [[ https://github.com/llvm/llvm-project/blob/27c37327da67020f938aabf0f6405f57d688441e/mlir/lib/Bindings/Python/IRCore.cpp#L1585 | build generic ]] checks against the number of operand segments expected.

Currently the only way around is to handroll through `ir.Operation.create`.

Reviewed By: rkayaith

Differential Revision: https://reviews.llvm.org/D151409




More information about the All-commits mailing list