[all-commits] [llvm/llvm-project] 9b79f5: [mlir][tblgen][ods][python] Use keyword-only argum...

Jeremy Furtek via All-commits all-commits at lists.llvm.org
Sun May 22 21:24:30 PDT 2022


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 9b79f50b59c671f3a7b0c7654cdd6d59ab6a6bbc
      https://github.com/llvm/llvm-project/commit/9b79f50b59c671f3a7b0c7654cdd6d59ab6a6bbc
  Author: Jeremy Furtek <jfurtek at nvidia.com>
  Date:   2022-05-21 (Sat, 21 May 2022)

  Changed paths:
    M mlir/python/mlir/dialects/_func_ops_ext.py
    M mlir/python/mlir/dialects/_ml_program_ops_ext.py
    M mlir/python/mlir/dialects/_pdl_ops_ext.py
    M mlir/test/mlir-tblgen/op-python-bindings.td
    M mlir/test/python/dialects/python_test.py
    M mlir/test/python/dialects/vector.py
    M mlir/tools/mlir-tblgen/OpPythonBindingGen.cpp

  Log Message:
  -----------
  [mlir][tblgen][ods][python] Use keyword-only arguments for optional builder arguments in generated Python bindings

This diff modifies `mlir-tblgen` to generate Python Operation class `__init__()`
functions that use Python keyword-only arguments.

Previously, all `__init__()` function arguments were positional. Python code to
create MLIR Operations was required to provide values for ALL builder arguments,
including optional arguments (attributes and operands). Callers that did not
provide, for example, an optional attribute would be forced to provide `None`
as an argument for EACH optional attribute. Proposed changes in this diff use
`tblgen` record information (as provided by ODS) to generate keyword arguments
for:
- optional operands
- optional attributes (which includes unit attributes)
- default-valued attributes

These `__init__()` function keyword arguments have default `None` values (i.e.
the argument form is `optionalAttr=None`), allowing callers to create Operations
more easily.

Note that since optional arguments become keyword-only arguments (since they are
placed after the bare `*` argument), this diff will require ALL optional
operands and attributes to be provided using explicit keyword syntax. This may,
in the short term, break any out-of-tree Python code that provided values via
positional arguments. However, in the long term, it seems that requiring
keywords for optional arguments will be more robust to operation changes that
add arguments.

Tests were modified to reflect the updated Operation builder calling convention.

This diff partially addresses the requests made in the github issue below.

https://github.com/llvm/llvm-project/issues/54932

Reviewed By: stellaraccident, mikeurbach

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




More information about the All-commits mailing list