This is an archive of the discontinued LLVM Phabricator instance.

[MLIR][python bindings] Fix inferReturnTypes + AttrSizedOperandSegments for optional operands
ClosedPublic

Authored by makslevental on May 24 2023, 11:39 PM.

Details

Summary

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 Nones. Note Nones 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 build generic checks against the number of operand segments expected.

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

Diff Detail

Event Timeline

makslevental created this revision.May 24 2023, 11:39 PM
Herald added a project: Restricted Project. · View Herald Transcript
makslevental published this revision for review.May 24 2023, 11:53 PM
makslevental retitled this revision from [MLIR][python bindings] Fix inferReturnTypes + AttrSizedOperandSegments to [MLIR][python bindings] Fix inferReturnTypes + AttrSizedOperandSegments for optional operands.
makslevental edited the summary of this revision. (Show Details)
makslevental edited the summary of this revision. (Show Details)
makslevental added inline comments.
mlir/lib/Bindings/Python/IRInterfaces.cpp
72

This cast fails.

Herald added a project: Restricted Project. · View Herald TranscriptMay 24 2023, 11:54 PM
makslevental edited the summary of this revision. (Show Details)May 25 2023, 7:33 AM
makslevental edited the summary of this revision. (Show Details)May 25 2023, 7:40 AM
makslevental edited the summary of this revision. (Show Details)May 25 2023, 8:27 AM
makslevental edited the summary of this revision. (Show Details)
makslevental edited the summary of this revision. (Show Details)May 25 2023, 8:32 AM
rkayaith accepted this revision.May 25 2023, 8:33 AM

makes sense to me

This revision is now accepted and ready to land.May 25 2023, 8:33 AM
rkayaith added inline comments.May 25 2023, 9:48 AM
mlir/test/python/dialects/python_test.py
425
446

can you fix the missing newline

fix CHECK-LABEL

This revision was landed with ongoing or failed builds.May 26 2023, 12:52 PM
This revision was automatically updated to reflect the committed changes.