[Mlir-commits] [mlir] [MLIR][Python] remove unnecessary `arg.none() = nb::none()` pattern (PR #157519)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Mon Sep 8 10:36:42 PDT 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-mlir
Author: Maksim Levental (makslevental)
<details>
<summary>Changes</summary>
We have `arg.none() = nb::none()` in a lot of places but this is no longer necessary (as of ~[2022](https://github.com/wjakob/nanobind/commit/62a23bb87b57d939e045f9c9da78a1d7235d2271)).
---
Patch is 55.76 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/157519.diff
13 Files Affected:
- (modified) mlir/lib/Bindings/Python/DialectGPU.cpp (+2-2)
- (modified) mlir/lib/Bindings/Python/DialectLLVM.cpp (+6-6)
- (modified) mlir/lib/Bindings/Python/DialectNVGPU.cpp (+1-1)
- (modified) mlir/lib/Bindings/Python/DialectPDL.cpp (+4-4)
- (modified) mlir/lib/Bindings/Python/DialectSMT.cpp (+2-2)
- (modified) mlir/lib/Bindings/Python/DialectSparseTensor.cpp (+3-3)
- (modified) mlir/lib/Bindings/Python/DialectTransform.cpp (+5-5)
- (modified) mlir/lib/Bindings/Python/IRAffine.cpp (+16-16)
- (modified) mlir/lib/Bindings/Python/IRAttributes.cpp (+24-24)
- (modified) mlir/lib/Bindings/Python/IRCore.cpp (+45-45)
- (modified) mlir/lib/Bindings/Python/IRInterfaces.cpp (+13-13)
- (modified) mlir/lib/Bindings/Python/IRTypes.cpp (+34-34)
- (modified) mlir/lib/Bindings/Python/Pass.cpp (+5-5)
``````````diff
diff --git a/mlir/lib/Bindings/Python/DialectGPU.cpp b/mlir/lib/Bindings/Python/DialectGPU.cpp
index a21176fffb441..2568d535edb5a 100644
--- a/mlir/lib/Bindings/Python/DialectGPU.cpp
+++ b/mlir/lib/Bindings/Python/DialectGPU.cpp
@@ -38,7 +38,7 @@ NB_MODULE(_mlirDialectsGPU, m) {
return cls(mlirGPUAsyncTokenTypeGet(ctx));
},
"Gets an instance of AsyncTokenType in the same context", nb::arg("cls"),
- nb::arg("ctx").none() = nb::none());
+ nb::arg("ctx") = nb::none());
//===-------------------------------------------------------------------===//
// ObjectAttr
@@ -62,7 +62,7 @@ NB_MODULE(_mlirDialectsGPU, m) {
: MlirAttribute{nullptr}));
},
"cls"_a, "target"_a, "format"_a, "object"_a,
- "properties"_a.none() = nb::none(), "kernels"_a.none() = nb::none(),
+ "properties"_a = nb::none(), "kernels"_a = nb::none(),
"Gets a gpu.object from parameters.")
.def_property_readonly(
"target",
diff --git a/mlir/lib/Bindings/Python/DialectLLVM.cpp b/mlir/lib/Bindings/Python/DialectLLVM.cpp
index ee106c0321669..f7cdefee1b8f6 100644
--- a/mlir/lib/Bindings/Python/DialectLLVM.cpp
+++ b/mlir/lib/Bindings/Python/DialectLLVM.cpp
@@ -47,7 +47,7 @@ static void populateDialectLLVMSubmodule(const nanobind::module_ &m) {
return cls(type);
},
"cls"_a, "elements"_a, nb::kw_only(), "packed"_a = false,
- "loc"_a.none() = nb::none());
+ "loc"_a= nb::none());
llvmStructType.def_classmethod(
"get_identified",
@@ -55,7 +55,7 @@ static void populateDialectLLVMSubmodule(const nanobind::module_ &m) {
return cls(mlirLLVMStructTypeIdentifiedGet(
context, mlirStringRefCreate(name.data(), name.size())));
},
- "cls"_a, "name"_a, nb::kw_only(), "context"_a.none() = nb::none());
+ "cls"_a, "name"_a, nb::kw_only(), "context"_a= nb::none());
llvmStructType.def_classmethod(
"get_opaque",
@@ -63,7 +63,7 @@ static void populateDialectLLVMSubmodule(const nanobind::module_ &m) {
return cls(mlirLLVMStructTypeOpaqueGet(
context, mlirStringRefCreate(name.data(), name.size())));
},
- "cls"_a, "name"_a, "context"_a.none() = nb::none());
+ "cls"_a, "name"_a, "context"_a= nb::none());
llvmStructType.def(
"set_body",
@@ -86,7 +86,7 @@ static void populateDialectLLVMSubmodule(const nanobind::module_ &m) {
elements.size(), elements.data(), packed));
},
"cls"_a, "name"_a, "elements"_a, nb::kw_only(), "packed"_a = false,
- "context"_a.none() = nb::none());
+ "context"_a= nb::none());
llvmStructType.def_property_readonly(
"name", [](MlirType type) -> std::optional<std::string> {
@@ -133,8 +133,8 @@ static void populateDialectLLVMSubmodule(const nanobind::module_ &m) {
}
return cls(type);
},
- "cls"_a, "address_space"_a.none() = nb::none(), nb::kw_only(),
- "context"_a.none() = nb::none())
+ "cls"_a, "address_space"_a= nb::none(), nb::kw_only(),
+ "context"_a= nb::none())
.def_property_readonly("address_space", [](MlirType type) {
return mlirLLVMPointerTypeGetAddressSpace(type);
});
diff --git a/mlir/lib/Bindings/Python/DialectNVGPU.cpp b/mlir/lib/Bindings/Python/DialectNVGPU.cpp
index bb3f519c962f7..a113029f4c446 100644
--- a/mlir/lib/Bindings/Python/DialectNVGPU.cpp
+++ b/mlir/lib/Bindings/Python/DialectNVGPU.cpp
@@ -31,7 +31,7 @@ static void populateDialectNVGPUSubmodule(const nb::module_ &m) {
"Gets an instance of TensorMapDescriptorType in the same context",
nb::arg("cls"), nb::arg("tensor_type"), nb::arg("swizzle"),
nb::arg("l2promo"), nb::arg("oob_fill"), nb::arg("interleave"),
- nb::arg("ctx").none() = nb::none());
+ nb::arg("ctx")= nb::none());
}
NB_MODULE(_mlirDialectsNVGPU, m) {
diff --git a/mlir/lib/Bindings/Python/DialectPDL.cpp b/mlir/lib/Bindings/Python/DialectPDL.cpp
index 2acedbc26b072..535e33393f1e6 100644
--- a/mlir/lib/Bindings/Python/DialectPDL.cpp
+++ b/mlir/lib/Bindings/Python/DialectPDL.cpp
@@ -36,7 +36,7 @@ static void populateDialectPDLSubmodule(const nanobind::module_ &m) {
return cls(mlirPDLAttributeTypeGet(ctx));
},
"Get an instance of AttributeType in given context.", nb::arg("cls"),
- nb::arg("context").none() = nb::none());
+ nb::arg("context")= nb::none());
//===-------------------------------------------------------------------===//
// OperationType
@@ -50,7 +50,7 @@ static void populateDialectPDLSubmodule(const nanobind::module_ &m) {
return cls(mlirPDLOperationTypeGet(ctx));
},
"Get an instance of OperationType in given context.", nb::arg("cls"),
- nb::arg("context").none() = nb::none());
+ nb::arg("context")= nb::none());
//===-------------------------------------------------------------------===//
// RangeType
@@ -81,7 +81,7 @@ static void populateDialectPDLSubmodule(const nanobind::module_ &m) {
return cls(mlirPDLTypeTypeGet(ctx));
},
"Get an instance of TypeType in given context.", nb::arg("cls"),
- nb::arg("context").none() = nb::none());
+ nb::arg("context")= nb::none());
//===-------------------------------------------------------------------===//
// ValueType
@@ -94,7 +94,7 @@ static void populateDialectPDLSubmodule(const nanobind::module_ &m) {
return cls(mlirPDLValueTypeGet(ctx));
},
"Get an instance of TypeType in given context.", nb::arg("cls"),
- nb::arg("context").none() = nb::none());
+ nb::arg("context")= nb::none());
}
NB_MODULE(_mlirDialectsPDL, m) {
diff --git a/mlir/lib/Bindings/Python/DialectSMT.cpp b/mlir/lib/Bindings/Python/DialectSMT.cpp
index cab4219fea72b..9c454d6a9149a 100644
--- a/mlir/lib/Bindings/Python/DialectSMT.cpp
+++ b/mlir/lib/Bindings/Python/DialectSMT.cpp
@@ -32,7 +32,7 @@ static void populateDialectSMTSubmodule(nanobind::module_ &m) {
[](const nb::object &, MlirContext context) {
return mlirSMTTypeGetBool(context);
},
- "cls"_a, "context"_a.none() = nb::none());
+ "cls"_a, "context"_a= nb::none());
auto smtBitVectorType =
mlir_type_subclass(m, "BitVectorType", mlirSMTTypeIsABitVector)
.def_classmethod(
@@ -40,7 +40,7 @@ static void populateDialectSMTSubmodule(nanobind::module_ &m) {
[](const nb::object &, int32_t width, MlirContext context) {
return mlirSMTTypeGetBitVector(context, width);
},
- "cls"_a, "width"_a, "context"_a.none() = nb::none());
+ "cls"_a, "width"_a, "context"_a= nb::none());
auto exportSMTLIB = [](MlirOperation module, bool inlineSingleUseValues,
bool indentLetBody) {
diff --git a/mlir/lib/Bindings/Python/DialectSparseTensor.cpp b/mlir/lib/Bindings/Python/DialectSparseTensor.cpp
index 9d7dc110764fb..facbbf3f0c097 100644
--- a/mlir/lib/Bindings/Python/DialectSparseTensor.cpp
+++ b/mlir/lib/Bindings/Python/DialectSparseTensor.cpp
@@ -53,9 +53,9 @@ static void populateDialectSparseTensorSubmodule(const nb::module_ &m) {
},
nb::arg("cls"), nb::arg("lvl_types"), nb::arg("dim_to_lvl").none(),
nb::arg("lvl_to_dim").none(), nb::arg("pos_width"),
- nb::arg("crd_width"), nb::arg("explicit_val").none() = nb::none(),
- nb::arg("implicit_val").none() = nb::none(),
- nb::arg("context").none() = nb::none(),
+ nb::arg("crd_width"), nb::arg("explicit_val")= nb::none(),
+ nb::arg("implicit_val")= nb::none(),
+ nb::arg("context")= nb::none(),
"Gets a sparse_tensor.encoding from parameters.")
.def_classmethod(
"build_level_type",
diff --git a/mlir/lib/Bindings/Python/DialectTransform.cpp b/mlir/lib/Bindings/Python/DialectTransform.cpp
index 1a62b06cd16b7..ded7b4b9448c9 100644
--- a/mlir/lib/Bindings/Python/DialectTransform.cpp
+++ b/mlir/lib/Bindings/Python/DialectTransform.cpp
@@ -33,7 +33,7 @@ static void populateDialectTransformSubmodule(const nb::module_ &m) {
return cls(mlirTransformAnyOpTypeGet(ctx));
},
"Get an instance of AnyOpType in the given context.", nb::arg("cls"),
- nb::arg("context").none() = nb::none());
+ nb::arg("context")= nb::none());
//===-------------------------------------------------------------------===//
// AnyParamType
@@ -48,7 +48,7 @@ static void populateDialectTransformSubmodule(const nb::module_ &m) {
return cls(mlirTransformAnyParamTypeGet(ctx));
},
"Get an instance of AnyParamType in the given context.", nb::arg("cls"),
- nb::arg("context").none() = nb::none());
+ nb::arg("context")= nb::none());
//===-------------------------------------------------------------------===//
// AnyValueType
@@ -63,7 +63,7 @@ static void populateDialectTransformSubmodule(const nb::module_ &m) {
return cls(mlirTransformAnyValueTypeGet(ctx));
},
"Get an instance of AnyValueType in the given context.", nb::arg("cls"),
- nb::arg("context").none() = nb::none());
+ nb::arg("context")= nb::none());
//===-------------------------------------------------------------------===//
// OperationType
@@ -83,7 +83,7 @@ static void populateDialectTransformSubmodule(const nb::module_ &m) {
"Get an instance of OperationType for the given kind in the given "
"context",
nb::arg("cls"), nb::arg("operation_name"),
- nb::arg("context").none() = nb::none());
+ nb::arg("context")= nb::none());
operationType.def_property_readonly(
"operation_name",
[](MlirType type) {
@@ -106,7 +106,7 @@ static void populateDialectTransformSubmodule(const nb::module_ &m) {
return cls(mlirTransformParamTypeGet(ctx, type));
},
"Get an instance of ParamType for the given type in the given context.",
- nb::arg("cls"), nb::arg("type"), nb::arg("context").none() = nb::none());
+ nb::arg("cls"), nb::arg("type"), nb::arg("context")= nb::none());
paramType.def_property_readonly(
"type",
[](MlirType type) {
diff --git a/mlir/lib/Bindings/Python/IRAffine.cpp b/mlir/lib/Bindings/Python/IRAffine.cpp
index a6499c952df6e..bc840deb9a569 100644
--- a/mlir/lib/Bindings/Python/IRAffine.cpp
+++ b/mlir/lib/Bindings/Python/IRAffine.cpp
@@ -142,7 +142,7 @@ class PyAffineConstantExpr : public PyConcreteAffineExpr<PyAffineConstantExpr> {
static void bindDerived(ClassTy &c) {
c.def_static("get", &PyAffineConstantExpr::get, nb::arg("value"),
- nb::arg("context").none() = nb::none());
+ nb::arg("context")= nb::none());
c.def_prop_ro("value", [](PyAffineConstantExpr &self) {
return mlirAffineConstantExprGetValue(self);
});
@@ -162,7 +162,7 @@ class PyAffineDimExpr : public PyConcreteAffineExpr<PyAffineDimExpr> {
static void bindDerived(ClassTy &c) {
c.def_static("get", &PyAffineDimExpr::get, nb::arg("position"),
- nb::arg("context").none() = nb::none());
+ nb::arg("context")= nb::none());
c.def_prop_ro("position", [](PyAffineDimExpr &self) {
return mlirAffineDimExprGetPosition(self);
});
@@ -182,7 +182,7 @@ class PyAffineSymbolExpr : public PyConcreteAffineExpr<PyAffineSymbolExpr> {
static void bindDerived(ClassTy &c) {
c.def_static("get", &PyAffineSymbolExpr::get, nb::arg("position"),
- nb::arg("context").none() = nb::none());
+ nb::arg("context")= nb::none());
c.def_prop_ro("position", [](PyAffineSymbolExpr &self) {
return mlirAffineSymbolExprGetPosition(self);
});
@@ -588,7 +588,7 @@ void mlir::python::populateIRAffine(nb::module_ &m) {
self.getContext(),
mlirAffineExprShiftDims(self, numDims, shift, offset));
},
- nb::arg("num_dims"), nb::arg("shift"), nb::arg("offset").none() = 0)
+ nb::arg("num_dims"), nb::arg("shift"), nb::arg("offset")= 0)
.def(
"shift_symbols",
[](PyAffineExpr &self, uint32_t numSymbols, uint32_t shift,
@@ -598,7 +598,7 @@ void mlir::python::populateIRAffine(nb::module_ &m) {
mlirAffineExprShiftSymbols(self, numSymbols, shift, offset));
},
nb::arg("num_symbols"), nb::arg("shift"),
- nb::arg("offset").none() = 0)
+ nb::arg("offset")= 0)
.def_static(
"simplify_affine_expr",
[](PyAffineExpr &self, uint32_t numDims, uint32_t numSymbols) {
@@ -655,15 +655,15 @@ void mlir::python::populateIRAffine(nb::module_ &m) {
"Gets an affine expression containing the rounded-up result "
"of dividing an expression by a constant.")
.def_static("get_constant", &PyAffineConstantExpr::get, nb::arg("value"),
- nb::arg("context").none() = nb::none(),
+ nb::arg("context")= nb::none(),
"Gets a constant affine expression with the given value.")
.def_static(
"get_dim", &PyAffineDimExpr::get, nb::arg("position"),
- nb::arg("context").none() = nb::none(),
+ nb::arg("context")= nb::none(),
"Gets an affine expression of a dimension at the given position.")
.def_static(
"get_symbol", &PyAffineSymbolExpr::get, nb::arg("position"),
- nb::arg("context").none() = nb::none(),
+ nb::arg("context")= nb::none(),
"Gets an affine expression of a symbol at the given position.")
.def(
"dump", [](PyAffineExpr &self) { mlirAffineExprDump(self); },
@@ -746,7 +746,7 @@ void mlir::python::populateIRAffine(nb::module_ &m) {
return PyAffineMap(context->getRef(), map);
},
nb::arg("dim_count"), nb::arg("symbol_count"), nb::arg("exprs"),
- nb::arg("context").none() = nb::none(),
+ nb::arg("context")= nb::none(),
"Gets a map with the given expressions as results.")
.def_static(
"get_constant",
@@ -755,7 +755,7 @@ void mlir::python::populateIRAffine(nb::module_ &m) {
mlirAffineMapConstantGet(context->get(), value);
return PyAffineMap(context->getRef(), affineMap);
},
- nb::arg("value"), nb::arg("context").none() = nb::none(),
+ nb::arg("value"), nb::arg("context")= nb::none(),
"Gets an affine map with a single constant result")
.def_static(
"get_empty",
@@ -763,7 +763,7 @@ void mlir::python::populateIRAffine(nb::module_ &m) {
MlirAffineMap affineMap = mlirAffineMapEmptyGet(context->get());
return PyAffineMap(context->getRef(), affineMap);
},
- nb::arg("context").none() = nb::none(), "Gets an empty affine map.")
+ nb::arg("context")= nb::none(), "Gets an empty affine map.")
.def_static(
"get_identity",
[](intptr_t nDims, DefaultingPyMlirContext context) {
@@ -771,7 +771,7 @@ void mlir::python::populateIRAffine(nb::module_ &m) {
mlirAffineMapMultiDimIdentityGet(context->get(), nDims);
return PyAffineMap(context->getRef(), affineMap);
},
- nb::arg("n_dims"), nb::arg("context").none() = nb::none(),
+ nb::arg("n_dims"), nb::arg("context")= nb::none(),
"Gets an identity map with the given number of dimensions.")
.def_static(
"get_minor_identity",
@@ -782,7 +782,7 @@ void mlir::python::populateIRAffine(nb::module_ &m) {
return PyAffineMap(context->getRef(), affineMap);
},
nb::arg("n_dims"), nb::arg("n_results"),
- nb::arg("context").none() = nb::none(),
+ nb::arg("context")= nb::none(),
"Gets a minor identity map with the given number of dimensions and "
"results.")
.def_static(
@@ -796,7 +796,7 @@ void mlir::python::populateIRAffine(nb::module_ &m) {
context->get(), permutation.size(), permutation.data());
return PyAffineMap(context->getRef(), affineMap);
},
- nb::arg("permutation"), nb::arg("context").none() = nb::none(),
+ nb::arg("permutation"), nb::arg("context")= nb::none(),
"Gets an affine map that permutes its inputs.")
.def(
"get_submap",
@@ -923,7 +923,7 @@ void mlir::python::populateIRAffine(nb::module_ &m) {
return PyIntegerSet(context->getRef(), set);
},
nb::arg("num_dims"), nb::arg("num_symbols"), nb::arg("exprs"),
- nb::arg("eq_flags"), nb::arg("context").none() = nb::none())
+ nb::arg("eq_flags"), nb::arg("context")= nb::none())
.def_static(
"get_empty",
[](intptr_t numDims, intptr_t numSymbols,
@@ -933,7 +933,7 @@ void mlir::python::populateIRAffine(nb::module_ &m) {
return PyIntegerSet(context->getRef(), set);
},
nb::arg("num_dims"), nb::arg("num_symbols"),
- nb::arg("context").none() = nb::none())
+ nb::arg("context")= nb::none())
.def(
"get_replaced",
[](PyIntegerSet &self, const nb::list &dimExprs,
diff --git a/mlir/lib/Bindings/Python/IRAttributes.cpp b/mlir/lib/Bindings/Python/IRAttributes.cpp
index f2eafa7c2d45c..c3df66c1979e9 100644
--- a/mlir/lib/Bindings/Python/IRAttributes.cpp
+++ b/mlir/lib/Bindings/Python/IRAttributes.cpp
@@ -351,7 +351,7 @@ class PyDenseArrayAttribute : public PyConcreteAttribute<DerivedT> {
}
return getAttribute(values, ctx->getRef());
},
- nb::arg("values"), nb::arg("context").none() = nb::none(),
+ nb::arg("values"), nb::arg("context")= nb::none(),
"Gets a uniqued dense array attribute");
} else {
c.def_static(
@@ -359,7 +359,7 @@ class PyDenseArrayAttribute : public PyConcreteAttribute<DerivedT> {
[](const std::vector<EltTy> &values, DefaultingPyMlirContext ctx) {
return getAttribute(values, ctx->getRef());
},
- nb::arg("values"), nb::arg("context").none() = nb::none(),
+ nb::arg("values"), nb::arg("context")= nb::none(),
"Gets a uniqued dense array attribute");
}
// Bind the array methods.
@@ -515,7 +515,7 @@ class PyArrayAttribute : public PyConcreteAttribute<PyArrayAttribute> {
context->get(), mlirAttributes.size(), mlirAttributes.data());
return PyArrayAttribute(context->getRef(), attr);
},
- nb::arg("attributes"), nb::arg("context").none() = nb::none(),
+ nb::arg("attributes"), nb::arg("context")= nb::none(),
"Gets a uniqued Array attribute");
c.def("__getitem__",
[](PyArrayAttribute &arr, intptr_t i) {
@@ -564,7 +564,7 @@ class PyFloatAttribute : public PyConcreteAttribute<PyFloatAttribute> {
throw MLIRError("Invalid attribute", errors.take());
return PyFloatAttribute(type.getContext(), attr);
},
- nb::arg("type"), nb::arg("value"), nb::arg("loc").none() = nb::none(),
+ nb::arg("type"), nb::arg("value"), nb::arg("loc")= nb::none(),
"Gets an uniqued float point attribute associated to a type");
c.def_static(
"get_f32",
@@ -573,7 +573,7 @@ class PyFloatAttribute : public PyConcreteAttribute<PyFloatAttribute> {
context->get(), mlirF32TypeGet(context->get()), value);
return PyFloatAttribute(context->getRef(), attr);
},
- nb::arg("value"), nb::arg("context").none() = nb::none(),
+ nb::arg("value"), nb::arg("context")= nb::none(),
"Gets an uniqued float point attribute associated to a f32 type");
c.def_static(
"get_f64",
@@ -582,7 +582,7 @@ class PyFloatAttribute : public PyConcreteAttribute<PyFloatAttribute> {
context->get(), mlirF64TypeGet(context->get()), value);
return PyFloatAttribute(context->getRef(), attr);
},
- nb::arg("value"), nb::arg("context").none() = nb::none(),
+ nb::arg("value"), nb::arg("context")= nb::none(),
"Gets an uniqued float point at...
[truncated]
``````````
</details>
https://github.com/llvm/llvm-project/pull/157519
More information about the Mlir-commits
mailing list