From 9bb8d62df018e0aec7790035173024fe9fbf6a0b Mon Sep 17 00:00:00 2001 From: makslevental Date: Mon, 8 Sep 2025 10:27:39 -0700 Subject: [PATCH 1/3] [MLIR][Python] remove .none() arg descriptor --- mlir/lib/Bindings/Python/DialectGPU.cpp | 4 +- mlir/lib/Bindings/Python/DialectLLVM.cpp | 12 ++-- mlir/lib/Bindings/Python/DialectNVGPU.cpp | 2 +- mlir/lib/Bindings/Python/DialectPDL.cpp | 8 +-- mlir/lib/Bindings/Python/DialectSMT.cpp | 4 +- mlir/lib/Bindings/Python/DialectTransform.cpp | 10 +-- mlir/lib/Bindings/Python/IRAffine.cpp | 70 +++++++++---------- mlir/lib/Bindings/Python/IRAttributes.cpp | 56 +++++++-------- mlir/lib/Bindings/Python/IRInterfaces.cpp | 23 +++--- mlir/lib/Bindings/Python/IRTypes.cpp | 70 +++++++++---------- mlir/lib/Bindings/Python/Pass.cpp | 12 ++-- .../Bindings/Python/TransformInterpreter.cpp | 2 +- mlir/test/python/CMakeLists.txt | 2 +- 13 files changed, 131 insertions(+), 144 deletions(-) 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..55b9331270cdc 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 { @@ -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..18917416412c1 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..ac163b59a0fb5 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..3123e3bdda496 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/DialectTransform.cpp b/mlir/lib/Bindings/Python/DialectTransform.cpp index 1a62b06cd16b7..150c69953d960 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..4739354adfc01 100644 --- a/mlir/lib/Bindings/Python/IRAffine.cpp +++ b/mlir/lib/Bindings/Python/IRAffine.cpp @@ -142,7 +142,7 @@ class PyAffineConstantExpr : public PyConcreteAffineExpr { 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 { 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 { 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, @@ -597,8 +597,7 @@ void mlir::python::populateIRAffine(nb::module_ &m) { self.getContext(), mlirAffineExprShiftSymbols(self, numSymbols, shift, offset)); }, - nb::arg("num_symbols"), nb::arg("shift"), - nb::arg("offset").none() = 0) + nb::arg("num_symbols"), nb::arg("shift"), nb::arg("offset") = 0) .def_static( "simplify_affine_expr", [](PyAffineExpr &self, uint32_t numDims, uint32_t numSymbols) { @@ -655,15 +654,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); }, @@ -707,25 +706,24 @@ void mlir::python::populateIRAffine(nb::module_ &m) { [](PyAffineMap &self) { return static_cast(llvm::hash_value(self.get().ptr)); }) - .def_static("compress_unused_symbols", - [](const nb::list &affineMaps, - DefaultingPyMlirContext context) { - SmallVector maps; - pyListToVector( - affineMaps, maps, "attempting to create an AffineMap"); - std::vector compressed(affineMaps.size()); - auto populate = [](void *result, intptr_t idx, - MlirAffineMap m) { - static_cast(result)[idx] = (m); - }; - mlirAffineMapCompressUnusedSymbols( - maps.data(), maps.size(), compressed.data(), populate); - std::vector res; - res.reserve(compressed.size()); - for (auto m : compressed) - res.emplace_back(context->getRef(), m); - return res; - }) + .def_static( + "compress_unused_symbols", + [](const nb::list &affineMaps, DefaultingPyMlirContext context) { + SmallVector maps; + pyListToVector( + affineMaps, maps, "attempting to create an AffineMap"); + std::vector compressed(affineMaps.size()); + auto populate = [](void *result, intptr_t idx, MlirAffineMap m) { + static_cast(result)[idx] = (m); + }; + mlirAffineMapCompressUnusedSymbols(maps.data(), maps.size(), + compressed.data(), populate); + std::vector res; + res.reserve(compressed.size()); + for (auto m : compressed) + res.emplace_back(context->getRef(), m); + return res; + }) .def_prop_ro( "context", [](PyAffineMap &self) { return self.getContext().getObject(); }, @@ -746,7 +744,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 +753,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 +761,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 +769,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 +780,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 +794,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 +921,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 +931,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..b3c768846c74f 100644 --- a/mlir/lib/Bindings/Python/IRAttributes.cpp +++ b/mlir/lib/Bindings/Python/IRAttributes.cpp @@ -351,7 +351,7 @@ class PyDenseArrayAttribute : public PyConcreteAttribute { } 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 { [](const std::vector &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 { 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 { 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 { 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 { 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 attribute associated to a f64 type"); c.def_prop_ro("value", mlirFloatAttrGetValueDouble, "Returns the value of the float attribute"); @@ -642,7 +642,7 @@ class PyBoolAttribute : public PyConcreteAttribute { MlirAttribute attr = mlirBoolAttrGet(context->get(), value); return PyBoolAttribute(context->getRef(), attr); }, - nb::arg("value"), nb::arg("context").none() = nb::none(), + nb::arg("value"), nb::arg("context") = nb::none(), "Gets an uniqued bool attribute"); c.def_prop_ro("value", mlirBoolAttrGetValue, "Returns the value of the bool attribute"); @@ -679,7 +679,7 @@ class PySymbolRefAttribute : public PyConcreteAttribute { DefaultingPyMlirContext context) { return PySymbolRefAttribute::fromList(symbols, context.resolve()); }, - nb::arg("symbols"), nb::arg("context").none() = nb::none(), + nb::arg("symbols"), nb::arg("context") = nb::none(), "Gets a uniqued SymbolRef attribute from a list of symbol names"); c.def_prop_ro( "value", @@ -713,7 +713,7 @@ class PyFlatSymbolRefAttribute mlirFlatSymbolRefAttrGet(context->get(), toMlirStringRef(value)); return PyFlatSymbolRefAttribute(context->getRef(), attr); }, - nb::arg("value"), nb::arg("context").none() = nb::none(), + nb::arg("value"), nb::arg("context") = nb::none(), "Gets a uniqued FlatSymbolRef attribute"); c.def_prop_ro( "value", @@ -746,7 +746,7 @@ class PyOpaqueAttribute : public PyConcreteAttribute { return PyOpaqueAttribute(context->getRef(), attr); }, nb::arg("dialect_namespace"), nb::arg("buffer"), nb::arg("type"), - nb::arg("context").none() = nb::none(), "Gets an Opaque attribute."); + nb::arg("context") = nb::none(), "Gets an Opaque attribute."); c.def_prop_ro( "dialect_namespace", [](PyOpaqueAttribute &self) { @@ -780,7 +780,7 @@ class PyStringAttribute : public PyConcreteAttribute { mlirStringAttrGet(context->get(), toMlirStringRef(value)); return PyStringAttribute(context->getRef(), attr); }, - nb::arg("value"), nb::arg("context").none() = nb::none(), + nb::arg("value"), nb::arg("context") = nb::none(), "Gets a uniqued string attribute"); c.def_static( "get", @@ -789,7 +789,7 @@ class PyStringAttribute : public PyConcreteAttribute { mlirStringAttrGet(context->get(), toMlirStringRef(value)); return PyStringAttribute(context->getRef(), attr); }, - nb::arg("value"), nb::arg("context").none() = nb::none(), + nb::arg("value"), nb::arg("context") = nb::none(), "Gets a uniqued string attribute"); c.def_static( "get_typed", @@ -1030,13 +1030,12 @@ class PyDenseElementsAttribute c.def("__len__", &PyDenseElementsAttribute::dunderLen) .def_static("get", PyDenseElementsAttribute::getFromBuffer, nb::arg("array"), nb::arg("signless") = true, - nb::arg("type").none() = nb::none(), - nb::arg("shape").none() = nb::none(), - nb::arg("context").none() = nb::none(), + nb::arg("type") = nb::none(), nb::arg("shape") = nb::none(), + nb::arg("context") = nb::none(), kDenseElementsAttrGetDocstring) .def_static("get", PyDenseElementsAttribute::getFromList, - nb::arg("attrs"), nb::arg("type").none() = nb::none(), - nb::arg("context").none() = nb::none(), + nb::arg("attrs"), nb::arg("type") = nb::none(), + nb::arg("context") = nb::none(), kDenseElementsAttrGetFromListDocstring) .def_static("get_splat", PyDenseElementsAttribute::getSplat, nb::arg("shaped_type"), nb::arg("element_attr"), @@ -1505,12 +1504,12 @@ class PyDenseResourceElementsAttribute } static void bindDerived(ClassTy &c) { - c.def_static( - "get_from_buffer", PyDenseResourceElementsAttribute::getFromBuffer, - nb::arg("array"), nb::arg("name"), nb::arg("type"), - nb::arg("alignment").none() = nb::none(), nb::arg("is_mutable") = false, - nb::arg("context").none() = nb::none(), - kDenseResourceElementsAttrGetFromBufferDocstring); + c.def_static("get_from_buffer", + PyDenseResourceElementsAttribute::getFromBuffer, + nb::arg("array"), nb::arg("name"), nb::arg("type"), + nb::arg("alignment") = nb::none(), + nb::arg("is_mutable") = false, nb::arg("context") = nb::none(), + kDenseResourceElementsAttrGetFromBufferDocstring); } }; @@ -1550,7 +1549,7 @@ class PyDictAttribute : public PyConcreteAttribute { mlirNamedAttributes.data()); return PyDictAttribute(context->getRef(), attr); }, - nb::arg("value") = nb::dict(), nb::arg("context").none() = nb::none(), + nb::arg("value") = nb::dict(), nb::arg("context") = nb::none(), "Gets an uniqued dict attribute"); c.def("__getitem__", [](PyDictAttribute &self, const std::string &name) { MlirAttribute attr = @@ -1622,7 +1621,7 @@ class PyTypeAttribute : public PyConcreteAttribute { MlirAttribute attr = mlirTypeAttrGet(value.get()); return PyTypeAttribute(context->getRef(), attr); }, - nb::arg("value"), nb::arg("context").none() = nb::none(), + nb::arg("value"), nb::arg("context") = nb::none(), "Gets a uniqued Type attribute"); c.def_prop_ro("value", [](PyTypeAttribute &self) { return mlirTypeAttrGetValue(self.get()); @@ -1646,7 +1645,7 @@ class PyUnitAttribute : public PyConcreteAttribute { return PyUnitAttribute(context->getRef(), mlirUnitAttrGet(context->get())); }, - nb::arg("context").none() = nb::none(), "Create a Unit attribute."); + nb::arg("context") = nb::none(), "Create a Unit attribute."); } }; @@ -1669,8 +1668,7 @@ class PyStridedLayoutAttribute ctx->get(), offset, strides.size(), strides.data()); return PyStridedLayoutAttribute(ctx->getRef(), attr); }, - nb::arg("offset"), nb::arg("strides"), - nb::arg("context").none() = nb::none(), + nb::arg("offset"), nb::arg("strides"), nb::arg("context") = nb::none(), "Gets a strided layout attribute."); c.def_static( "get_fully_dynamic", @@ -1682,7 +1680,7 @@ class PyStridedLayoutAttribute ctx->get(), dynamic, strides.size(), strides.data()); return PyStridedLayoutAttribute(ctx->getRef(), attr); }, - nb::arg("rank"), nb::arg("context").none() = nb::none(), + nb::arg("rank"), nb::arg("context") = nb::none(), "Gets a strided layout attribute with dynamic offset and strides of " "a " "given rank."); diff --git a/mlir/lib/Bindings/Python/IRInterfaces.cpp b/mlir/lib/Bindings/Python/IRInterfaces.cpp index 9e1fedaab5235..6aa057c2a78aa 100644 --- a/mlir/lib/Bindings/Python/IRInterfaces.cpp +++ b/mlir/lib/Bindings/Python/IRInterfaces.cpp @@ -195,7 +195,7 @@ class PyConcreteOpInterface { static void bind(nb::module_ &m) { nb::class_ cls(m, ConcreteIface::pyClassName); cls.def(nb::init(), nb::arg("object"), - nb::arg("context").none() = nb::none(), constructorDoc) + nb::arg("context") = nb::none(), constructorDoc) .def_prop_ro("operation", &PyConcreteOpInterface::getOperationObject, operationDoc) .def_prop_ro("opview", &PyConcreteOpInterface::getOpView, opviewDoc); @@ -303,12 +303,11 @@ class PyInferTypeOpInterface static void bindDerived(ClassTy &cls) { cls.def("inferReturnTypes", &PyInferTypeOpInterface::inferReturnTypes, - nb::arg("operands").none() = nb::none(), - nb::arg("attributes").none() = nb::none(), - nb::arg("properties").none() = nb::none(), - nb::arg("regions").none() = nb::none(), - nb::arg("context").none() = nb::none(), - nb::arg("loc").none() = nb::none(), inferReturnTypesDoc); + nb::arg("operands") = nb::none(), + nb::arg("attributes") = nb::none(), + nb::arg("properties") = nb::none(), nb::arg("regions") = nb::none(), + nb::arg("context") = nb::none(), nb::arg("loc") = nb::none(), + inferReturnTypesDoc); } }; @@ -463,12 +462,10 @@ class PyInferShapedTypeOpInterface static void bindDerived(ClassTy &cls) { cls.def("inferReturnTypeComponents", &PyInferShapedTypeOpInterface::inferReturnTypeComponents, - nb::arg("operands").none() = nb::none(), - nb::arg("attributes").none() = nb::none(), - nb::arg("regions").none() = nb::none(), - nb::arg("properties").none() = nb::none(), - nb::arg("context").none() = nb::none(), - nb::arg("loc").none() = nb::none(), inferReturnTypeComponentsDoc); + nb::arg("operands") = nb::none(), + nb::arg("attributes") = nb::none(), nb::arg("regions") = nb::none(), + nb::arg("properties") = nb::none(), nb::arg("context") = nb::none(), + nb::arg("loc") = nb::none(), inferReturnTypeComponentsDoc); } }; diff --git a/mlir/lib/Bindings/Python/IRTypes.cpp b/mlir/lib/Bindings/Python/IRTypes.cpp index a9b12590188f8..38da70360ecd6 100644 --- a/mlir/lib/Bindings/Python/IRTypes.cpp +++ b/mlir/lib/Bindings/Python/IRTypes.cpp @@ -49,7 +49,7 @@ class PyIntegerType : public PyConcreteType { MlirType t = mlirIntegerTypeGet(context->get(), width); return PyIntegerType(context->getRef(), t); }, - nb::arg("width"), nb::arg("context").none() = nb::none(), + nb::arg("width"), nb::arg("context") = nb::none(), "Create a signless integer type"); c.def_static( "get_signed", @@ -57,7 +57,7 @@ class PyIntegerType : public PyConcreteType { MlirType t = mlirIntegerTypeSignedGet(context->get(), width); return PyIntegerType(context->getRef(), t); }, - nb::arg("width"), nb::arg("context").none() = nb::none(), + nb::arg("width"), nb::arg("context") = nb::none(), "Create a signed integer type"); c.def_static( "get_unsigned", @@ -65,7 +65,7 @@ class PyIntegerType : public PyConcreteType { MlirType t = mlirIntegerTypeUnsignedGet(context->get(), width); return PyIntegerType(context->getRef(), t); }, - nb::arg("width"), nb::arg("context").none() = nb::none(), + nb::arg("width"), nb::arg("context") = nb::none(), "Create an unsigned integer type"); c.def_prop_ro( "width", @@ -108,7 +108,7 @@ class PyIndexType : public PyConcreteType { MlirType t = mlirIndexTypeGet(context->get()); return PyIndexType(context->getRef(), t); }, - nb::arg("context").none() = nb::none(), "Create a index type."); + nb::arg("context") = nb::none(), "Create a index type."); } }; @@ -142,7 +142,7 @@ class PyFloat4E2M1FNType MlirType t = mlirFloat4E2M1FNTypeGet(context->get()); return PyFloat4E2M1FNType(context->getRef(), t); }, - nb::arg("context").none() = nb::none(), "Create a float4_e2m1fn type."); + nb::arg("context") = nb::none(), "Create a float4_e2m1fn type."); } }; @@ -163,7 +163,7 @@ class PyFloat6E2M3FNType MlirType t = mlirFloat6E2M3FNTypeGet(context->get()); return PyFloat6E2M3FNType(context->getRef(), t); }, - nb::arg("context").none() = nb::none(), "Create a float6_e2m3fn type."); + nb::arg("context") = nb::none(), "Create a float6_e2m3fn type."); } }; @@ -184,7 +184,7 @@ class PyFloat6E3M2FNType MlirType t = mlirFloat6E3M2FNTypeGet(context->get()); return PyFloat6E3M2FNType(context->getRef(), t); }, - nb::arg("context").none() = nb::none(), "Create a float6_e3m2fn type."); + nb::arg("context") = nb::none(), "Create a float6_e3m2fn type."); } }; @@ -205,7 +205,7 @@ class PyFloat8E4M3FNType MlirType t = mlirFloat8E4M3FNTypeGet(context->get()); return PyFloat8E4M3FNType(context->getRef(), t); }, - nb::arg("context").none() = nb::none(), "Create a float8_e4m3fn type."); + nb::arg("context") = nb::none(), "Create a float8_e4m3fn type."); } }; @@ -225,7 +225,7 @@ class PyFloat8E5M2Type : public PyConcreteType { MlirType t = mlirFloat8E5M2TypeGet(context->get()); return PyFloat8E5M2Type(context->getRef(), t); }, - nb::arg("context").none() = nb::none(), "Create a float8_e5m2 type."); + nb::arg("context") = nb::none(), "Create a float8_e5m2 type."); } }; @@ -245,7 +245,7 @@ class PyFloat8E4M3Type : public PyConcreteType { MlirType t = mlirFloat8E4M3TypeGet(context->get()); return PyFloat8E4M3Type(context->getRef(), t); }, - nb::arg("context").none() = nb::none(), "Create a float8_e4m3 type."); + nb::arg("context") = nb::none(), "Create a float8_e4m3 type."); } }; @@ -266,8 +266,7 @@ class PyFloat8E4M3FNUZType MlirType t = mlirFloat8E4M3FNUZTypeGet(context->get()); return PyFloat8E4M3FNUZType(context->getRef(), t); }, - nb::arg("context").none() = nb::none(), - "Create a float8_e4m3fnuz type."); + nb::arg("context") = nb::none(), "Create a float8_e4m3fnuz type."); } }; @@ -288,8 +287,7 @@ class PyFloat8E4M3B11FNUZType MlirType t = mlirFloat8E4M3B11FNUZTypeGet(context->get()); return PyFloat8E4M3B11FNUZType(context->getRef(), t); }, - nb::arg("context").none() = nb::none(), - "Create a float8_e4m3b11fnuz type."); + nb::arg("context") = nb::none(), "Create a float8_e4m3b11fnuz type."); } }; @@ -310,8 +308,7 @@ class PyFloat8E5M2FNUZType MlirType t = mlirFloat8E5M2FNUZTypeGet(context->get()); return PyFloat8E5M2FNUZType(context->getRef(), t); }, - nb::arg("context").none() = nb::none(), - "Create a float8_e5m2fnuz type."); + nb::arg("context") = nb::none(), "Create a float8_e5m2fnuz type."); } }; @@ -331,7 +328,7 @@ class PyFloat8E3M4Type : public PyConcreteType { MlirType t = mlirFloat8E3M4TypeGet(context->get()); return PyFloat8E3M4Type(context->getRef(), t); }, - nb::arg("context").none() = nb::none(), "Create a float8_e3m4 type."); + nb::arg("context") = nb::none(), "Create a float8_e3m4 type."); } }; @@ -352,8 +349,7 @@ class PyFloat8E8M0FNUType MlirType t = mlirFloat8E8M0FNUTypeGet(context->get()); return PyFloat8E8M0FNUType(context->getRef(), t); }, - nb::arg("context").none() = nb::none(), - "Create a float8_e8m0fnu type."); + nb::arg("context") = nb::none(), "Create a float8_e8m0fnu type."); } }; @@ -373,7 +369,7 @@ class PyBF16Type : public PyConcreteType { MlirType t = mlirBF16TypeGet(context->get()); return PyBF16Type(context->getRef(), t); }, - nb::arg("context").none() = nb::none(), "Create a bf16 type."); + nb::arg("context") = nb::none(), "Create a bf16 type."); } }; @@ -393,7 +389,7 @@ class PyF16Type : public PyConcreteType { MlirType t = mlirF16TypeGet(context->get()); return PyF16Type(context->getRef(), t); }, - nb::arg("context").none() = nb::none(), "Create a f16 type."); + nb::arg("context") = nb::none(), "Create a f16 type."); } }; @@ -413,7 +409,7 @@ class PyTF32Type : public PyConcreteType { MlirType t = mlirTF32TypeGet(context->get()); return PyTF32Type(context->getRef(), t); }, - nb::arg("context").none() = nb::none(), "Create a tf32 type."); + nb::arg("context") = nb::none(), "Create a tf32 type."); } }; @@ -433,7 +429,7 @@ class PyF32Type : public PyConcreteType { MlirType t = mlirF32TypeGet(context->get()); return PyF32Type(context->getRef(), t); }, - nb::arg("context").none() = nb::none(), "Create a f32 type."); + nb::arg("context") = nb::none(), "Create a f32 type."); } }; @@ -453,7 +449,7 @@ class PyF64Type : public PyConcreteType { MlirType t = mlirF64TypeGet(context->get()); return PyF64Type(context->getRef(), t); }, - nb::arg("context").none() = nb::none(), "Create a f64 type."); + nb::arg("context") = nb::none(), "Create a f64 type."); } }; @@ -473,7 +469,7 @@ class PyNoneType : public PyConcreteType { MlirType t = mlirNoneTypeGet(context->get()); return PyNoneType(context->getRef(), t); }, - nb::arg("context").none() = nb::none(), "Create a none type."); + nb::arg("context") = nb::none(), "Create a none type."); } }; @@ -639,9 +635,9 @@ class PyVectorType : public PyConcreteType { static void bindDerived(ClassTy &c) { c.def_static("get", &PyVectorType::get, nb::arg("shape"), nb::arg("element_type"), nb::kw_only(), - nb::arg("scalable").none() = nb::none(), - nb::arg("scalable_dims").none() = nb::none(), - nb::arg("loc").none() = nb::none(), "Create a vector type") + nb::arg("scalable") = nb::none(), + nb::arg("scalable_dims") = nb::none(), + nb::arg("loc") = nb::none(), "Create a vector type") .def_prop_ro( "scalable", [](MlirType self) { return mlirVectorTypeIsScalable(self); }) @@ -720,8 +716,8 @@ class PyRankedTensorType return PyRankedTensorType(elementType.getContext(), t); }, nb::arg("shape"), nb::arg("element_type"), - nb::arg("encoding").none() = nb::none(), - nb::arg("loc").none() = nb::none(), "Create a ranked tensor type"); + nb::arg("encoding") = nb::none(), nb::arg("loc") = nb::none(), + "Create a ranked tensor type"); c.def_prop_ro("encoding", [](PyRankedTensorType &self) -> std::optional { MlirAttribute encoding = @@ -753,7 +749,7 @@ class PyUnrankedTensorType throw MLIRError("Invalid type", errors.take()); return PyUnrankedTensorType(elementType.getContext(), t); }, - nb::arg("element_type"), nb::arg("loc").none() = nb::none(), + nb::arg("element_type"), nb::arg("loc") = nb::none(), "Create a unranked tensor type"); } }; @@ -785,9 +781,8 @@ class PyMemRefType : public PyConcreteType { return PyMemRefType(elementType.getContext(), t); }, nb::arg("shape"), nb::arg("element_type"), - nb::arg("layout").none() = nb::none(), - nb::arg("memory_space").none() = nb::none(), - nb::arg("loc").none() = nb::none(), "Create a memref type") + nb::arg("layout") = nb::none(), nb::arg("memory_space") = nb::none(), + nb::arg("loc") = nb::none(), "Create a memref type") .def_prop_ro( "layout", [](PyMemRefType &self) -> MlirAttribute { @@ -882,7 +877,7 @@ class PyTupleType : public PyConcreteType { elements.data()); return PyTupleType(context->getRef(), t); }, - nb::arg("elements"), nb::arg("context").none() = nb::none(), + nb::arg("elements"), nb::arg("context") = nb::none(), "Create a tuple type"); c.def( "get_type", @@ -918,8 +913,7 @@ class PyFunctionType : public PyConcreteType { results.size(), results.data()); return PyFunctionType(context->getRef(), t); }, - nb::arg("inputs"), nb::arg("results"), - nb::arg("context").none() = nb::none(), + nb::arg("inputs"), nb::arg("results"), nb::arg("context") = nb::none(), "Gets a FunctionType from a list of input and result types"); c.def_prop_ro( "inputs", @@ -971,7 +965,7 @@ class PyOpaqueType : public PyConcreteType { return PyOpaqueType(context->getRef(), type); }, nb::arg("dialect_namespace"), nb::arg("buffer"), - nb::arg("context").none() = nb::none(), + nb::arg("context") = nb::none(), "Create an unregistered (opaque) dialect type."); c.def_prop_ro( "dialect_namespace", diff --git a/mlir/lib/Bindings/Python/Pass.cpp b/mlir/lib/Bindings/Python/Pass.cpp index 88e28dca76bb9..72bf8ed8f856f 100644 --- a/mlir/lib/Bindings/Python/Pass.cpp +++ b/mlir/lib/Bindings/Python/Pass.cpp @@ -67,7 +67,7 @@ void mlir::python::populatePassManagerSubmodule(nb::module_ &m) { mlirStringRefCreate(anchorOp.data(), anchorOp.size())); new (&self) PyPassManager(passManager); }, - "anchor_op"_a = nb::str("any"), "context"_a.none() = nb::none(), + "anchor_op"_a = nb::str("any"), "context"_a = nb::none(), "Create a new PassManager for the current (or provided) Context.") .def_prop_ro(MLIR_PYTHON_CAPI_PTR_ATTR, &PyPassManager::getCapsule) .def(MLIR_PYTHON_CAPI_FACTORY_ATTR, &PyPassManager::createFromCapsule) @@ -109,10 +109,10 @@ void mlir::python::populatePassManagerSubmodule(nb::module_ &m) { "print_before_all"_a = false, "print_after_all"_a = true, "print_module_scope"_a = false, "print_after_change"_a = false, "print_after_failure"_a = false, - "large_elements_limit"_a.none() = nb::none(), - "large_resource_limit"_a.none() = nb::none(), - "enable_debug_info"_a = false, "print_generic_op_form"_a = false, - "tree_printing_dir_path"_a.none() = nb::none(), + "large_elements_limit"_a = nb::none(), + "large_resource_limit"_a = nb::none(), "enable_debug_info"_a = false, + "print_generic_op_form"_a = false, + "tree_printing_dir_path"_a = nb::none(), "Enable IR printing, default as mlir-print-ir-after-all.") .def( "enable_verifier", @@ -139,7 +139,7 @@ void mlir::python::populatePassManagerSubmodule(nb::module_ &m) { throw nb::value_error(errorMsg.join().c_str()); return new PyPassManager(passManager); }, - "pipeline"_a, "context"_a.none() = nb::none(), + "pipeline"_a, "context"_a = nb::none(), "Parse a textual pass-pipeline and return a top-level PassManager " "that can be applied on a Module. Throw a ValueError if the pipeline " "can't be parsed") diff --git a/mlir/lib/Bindings/Python/TransformInterpreter.cpp b/mlir/lib/Bindings/Python/TransformInterpreter.cpp index 920bca886f617..81c02e905505a 100644 --- a/mlir/lib/Bindings/Python/TransformInterpreter.cpp +++ b/mlir/lib/Bindings/Python/TransformInterpreter.cpp @@ -14,8 +14,8 @@ #include "mlir-c/IR.h" #include "mlir-c/Support.h" #include "mlir/Bindings/Python/Diagnostics.h" -#include "mlir/Bindings/Python/NanobindAdaptors.h" #include "mlir/Bindings/Python/Nanobind.h" +#include "mlir/Bindings/Python/NanobindAdaptors.h" namespace nb = nanobind; diff --git a/mlir/test/python/CMakeLists.txt b/mlir/test/python/CMakeLists.txt index d68f3ff82e883..e1e82ef367b1e 100644 --- a/mlir/test/python/CMakeLists.txt +++ b/mlir/test/python/CMakeLists.txt @@ -13,7 +13,7 @@ add_subdirectory(lib) set(MLIR_PYTHON_TEST_DEPENDS MLIRPythonModules) if(NOT MLIR_STANDALONE_BUILD) - list(APPEND MLIR_PYTHON_TEST_DEPENDS FileCheck count) + list(APPEND MLIR_PYTHON_TEST_DEPENDS FileCheck count not) endif() add_lit_testsuite(check-mlir-python "Running the MLIR Python regression tests" ${CMAKE_CURRENT_BINARY_DIR} From 58bd31ac1f9e5207315778f0f3620e05416dc8ed Mon Sep 17 00:00:00 2001 From: makslevental Date: Mon, 8 Sep 2025 10:30:15 -0700 Subject: [PATCH 2/3] Revert "[MLIR][Python] remove .none() arg descriptor" This reverts commit 9bb8d62df018e0aec7790035173024fe9fbf6a0b. --- mlir/lib/Bindings/Python/DialectGPU.cpp | 4 +- mlir/lib/Bindings/Python/DialectLLVM.cpp | 12 ++-- mlir/lib/Bindings/Python/DialectNVGPU.cpp | 2 +- mlir/lib/Bindings/Python/DialectPDL.cpp | 8 +-- mlir/lib/Bindings/Python/DialectSMT.cpp | 4 +- mlir/lib/Bindings/Python/DialectTransform.cpp | 10 +-- mlir/lib/Bindings/Python/IRAffine.cpp | 70 ++++++++++--------- mlir/lib/Bindings/Python/IRAttributes.cpp | 56 ++++++++------- mlir/lib/Bindings/Python/IRInterfaces.cpp | 23 +++--- mlir/lib/Bindings/Python/IRTypes.cpp | 70 ++++++++++--------- mlir/lib/Bindings/Python/Pass.cpp | 12 ++-- .../Bindings/Python/TransformInterpreter.cpp | 2 +- mlir/test/python/CMakeLists.txt | 2 +- 13 files changed, 144 insertions(+), 131 deletions(-) diff --git a/mlir/lib/Bindings/Python/DialectGPU.cpp b/mlir/lib/Bindings/Python/DialectGPU.cpp index 2568d535edb5a..a21176fffb441 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") = nb::none()); + nb::arg("ctx").none() = nb::none()); //===-------------------------------------------------------------------===// // ObjectAttr @@ -62,7 +62,7 @@ NB_MODULE(_mlirDialectsGPU, m) { : MlirAttribute{nullptr})); }, "cls"_a, "target"_a, "format"_a, "object"_a, - "properties"_a = nb::none(), "kernels"_a = nb::none(), + "properties"_a.none() = nb::none(), "kernels"_a.none() = 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 55b9331270cdc..ee106c0321669 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 = nb::none()); + "loc"_a.none() = 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 = nb::none()); + "cls"_a, "name"_a, nb::kw_only(), "context"_a.none() = 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 = nb::none()); + "cls"_a, "name"_a, "context"_a.none() = 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 = nb::none()); + "context"_a.none() = nb::none()); llvmStructType.def_property_readonly( "name", [](MlirType type) -> std::optional { @@ -133,8 +133,8 @@ static void populateDialectLLVMSubmodule(const nanobind::module_ &m) { } return cls(type); }, - "cls"_a, "address_space"_a = nb::none(), nb::kw_only(), - "context"_a = nb::none()) + "cls"_a, "address_space"_a.none() = nb::none(), nb::kw_only(), + "context"_a.none() = 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 18917416412c1..bb3f519c962f7 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") = nb::none()); + nb::arg("ctx").none() = nb::none()); } NB_MODULE(_mlirDialectsNVGPU, m) { diff --git a/mlir/lib/Bindings/Python/DialectPDL.cpp b/mlir/lib/Bindings/Python/DialectPDL.cpp index ac163b59a0fb5..2acedbc26b072 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") = nb::none()); + nb::arg("context").none() = 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") = nb::none()); + nb::arg("context").none() = 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") = nb::none()); + nb::arg("context").none() = 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") = nb::none()); + nb::arg("context").none() = nb::none()); } NB_MODULE(_mlirDialectsPDL, m) { diff --git a/mlir/lib/Bindings/Python/DialectSMT.cpp b/mlir/lib/Bindings/Python/DialectSMT.cpp index 3123e3bdda496..cab4219fea72b 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 = nb::none()); + "cls"_a, "context"_a.none() = 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 = nb::none()); + "cls"_a, "width"_a, "context"_a.none() = nb::none()); auto exportSMTLIB = [](MlirOperation module, bool inlineSingleUseValues, bool indentLetBody) { diff --git a/mlir/lib/Bindings/Python/DialectTransform.cpp b/mlir/lib/Bindings/Python/DialectTransform.cpp index 150c69953d960..1a62b06cd16b7 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") = nb::none()); + nb::arg("context").none() = 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") = nb::none()); + nb::arg("context").none() = 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") = nb::none()); + nb::arg("context").none() = 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") = nb::none()); + nb::arg("context").none() = 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") = nb::none()); + nb::arg("cls"), nb::arg("type"), nb::arg("context").none() = 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 4739354adfc01..a6499c952df6e 100644 --- a/mlir/lib/Bindings/Python/IRAffine.cpp +++ b/mlir/lib/Bindings/Python/IRAffine.cpp @@ -142,7 +142,7 @@ class PyAffineConstantExpr : public PyConcreteAffineExpr { static void bindDerived(ClassTy &c) { c.def_static("get", &PyAffineConstantExpr::get, nb::arg("value"), - nb::arg("context") = nb::none()); + nb::arg("context").none() = nb::none()); c.def_prop_ro("value", [](PyAffineConstantExpr &self) { return mlirAffineConstantExprGetValue(self); }); @@ -162,7 +162,7 @@ class PyAffineDimExpr : public PyConcreteAffineExpr { static void bindDerived(ClassTy &c) { c.def_static("get", &PyAffineDimExpr::get, nb::arg("position"), - nb::arg("context") = nb::none()); + nb::arg("context").none() = nb::none()); c.def_prop_ro("position", [](PyAffineDimExpr &self) { return mlirAffineDimExprGetPosition(self); }); @@ -182,7 +182,7 @@ class PyAffineSymbolExpr : public PyConcreteAffineExpr { static void bindDerived(ClassTy &c) { c.def_static("get", &PyAffineSymbolExpr::get, nb::arg("position"), - nb::arg("context") = nb::none()); + nb::arg("context").none() = 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") = 0) + nb::arg("num_dims"), nb::arg("shift"), nb::arg("offset").none() = 0) .def( "shift_symbols", [](PyAffineExpr &self, uint32_t numSymbols, uint32_t shift, @@ -597,7 +597,8 @@ void mlir::python::populateIRAffine(nb::module_ &m) { self.getContext(), mlirAffineExprShiftSymbols(self, numSymbols, shift, offset)); }, - nb::arg("num_symbols"), nb::arg("shift"), nb::arg("offset") = 0) + nb::arg("num_symbols"), nb::arg("shift"), + nb::arg("offset").none() = 0) .def_static( "simplify_affine_expr", [](PyAffineExpr &self, uint32_t numDims, uint32_t numSymbols) { @@ -654,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") = nb::none(), + nb::arg("context").none() = nb::none(), "Gets a constant affine expression with the given value.") .def_static( "get_dim", &PyAffineDimExpr::get, nb::arg("position"), - nb::arg("context") = nb::none(), + nb::arg("context").none() = 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") = nb::none(), + nb::arg("context").none() = nb::none(), "Gets an affine expression of a symbol at the given position.") .def( "dump", [](PyAffineExpr &self) { mlirAffineExprDump(self); }, @@ -706,24 +707,25 @@ void mlir::python::populateIRAffine(nb::module_ &m) { [](PyAffineMap &self) { return static_cast(llvm::hash_value(self.get().ptr)); }) - .def_static( - "compress_unused_symbols", - [](const nb::list &affineMaps, DefaultingPyMlirContext context) { - SmallVector maps; - pyListToVector( - affineMaps, maps, "attempting to create an AffineMap"); - std::vector compressed(affineMaps.size()); - auto populate = [](void *result, intptr_t idx, MlirAffineMap m) { - static_cast(result)[idx] = (m); - }; - mlirAffineMapCompressUnusedSymbols(maps.data(), maps.size(), - compressed.data(), populate); - std::vector res; - res.reserve(compressed.size()); - for (auto m : compressed) - res.emplace_back(context->getRef(), m); - return res; - }) + .def_static("compress_unused_symbols", + [](const nb::list &affineMaps, + DefaultingPyMlirContext context) { + SmallVector maps; + pyListToVector( + affineMaps, maps, "attempting to create an AffineMap"); + std::vector compressed(affineMaps.size()); + auto populate = [](void *result, intptr_t idx, + MlirAffineMap m) { + static_cast(result)[idx] = (m); + }; + mlirAffineMapCompressUnusedSymbols( + maps.data(), maps.size(), compressed.data(), populate); + std::vector res; + res.reserve(compressed.size()); + for (auto m : compressed) + res.emplace_back(context->getRef(), m); + return res; + }) .def_prop_ro( "context", [](PyAffineMap &self) { return self.getContext().getObject(); }, @@ -744,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") = nb::none(), + nb::arg("context").none() = nb::none(), "Gets a map with the given expressions as results.") .def_static( "get_constant", @@ -753,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") = nb::none(), + nb::arg("value"), nb::arg("context").none() = nb::none(), "Gets an affine map with a single constant result") .def_static( "get_empty", @@ -761,7 +763,7 @@ void mlir::python::populateIRAffine(nb::module_ &m) { MlirAffineMap affineMap = mlirAffineMapEmptyGet(context->get()); return PyAffineMap(context->getRef(), affineMap); }, - nb::arg("context") = nb::none(), "Gets an empty affine map.") + nb::arg("context").none() = nb::none(), "Gets an empty affine map.") .def_static( "get_identity", [](intptr_t nDims, DefaultingPyMlirContext context) { @@ -769,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") = nb::none(), + nb::arg("n_dims"), nb::arg("context").none() = nb::none(), "Gets an identity map with the given number of dimensions.") .def_static( "get_minor_identity", @@ -780,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") = nb::none(), + nb::arg("context").none() = nb::none(), "Gets a minor identity map with the given number of dimensions and " "results.") .def_static( @@ -794,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") = nb::none(), + nb::arg("permutation"), nb::arg("context").none() = nb::none(), "Gets an affine map that permutes its inputs.") .def( "get_submap", @@ -921,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") = nb::none()) + nb::arg("eq_flags"), nb::arg("context").none() = nb::none()) .def_static( "get_empty", [](intptr_t numDims, intptr_t numSymbols, @@ -931,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") = nb::none()) + nb::arg("context").none() = 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 b3c768846c74f..f2eafa7c2d45c 100644 --- a/mlir/lib/Bindings/Python/IRAttributes.cpp +++ b/mlir/lib/Bindings/Python/IRAttributes.cpp @@ -351,7 +351,7 @@ class PyDenseArrayAttribute : public PyConcreteAttribute { } return getAttribute(values, ctx->getRef()); }, - nb::arg("values"), nb::arg("context") = nb::none(), + nb::arg("values"), nb::arg("context").none() = nb::none(), "Gets a uniqued dense array attribute"); } else { c.def_static( @@ -359,7 +359,7 @@ class PyDenseArrayAttribute : public PyConcreteAttribute { [](const std::vector &values, DefaultingPyMlirContext ctx) { return getAttribute(values, ctx->getRef()); }, - nb::arg("values"), nb::arg("context") = nb::none(), + nb::arg("values"), nb::arg("context").none() = nb::none(), "Gets a uniqued dense array attribute"); } // Bind the array methods. @@ -515,7 +515,7 @@ class PyArrayAttribute : public PyConcreteAttribute { context->get(), mlirAttributes.size(), mlirAttributes.data()); return PyArrayAttribute(context->getRef(), attr); }, - nb::arg("attributes"), nb::arg("context") = nb::none(), + nb::arg("attributes"), nb::arg("context").none() = nb::none(), "Gets a uniqued Array attribute"); c.def("__getitem__", [](PyArrayAttribute &arr, intptr_t i) { @@ -564,7 +564,7 @@ class PyFloatAttribute : public PyConcreteAttribute { throw MLIRError("Invalid attribute", errors.take()); return PyFloatAttribute(type.getContext(), attr); }, - nb::arg("type"), nb::arg("value"), nb::arg("loc") = nb::none(), + nb::arg("type"), nb::arg("value"), nb::arg("loc").none() = 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 { context->get(), mlirF32TypeGet(context->get()), value); return PyFloatAttribute(context->getRef(), attr); }, - nb::arg("value"), nb::arg("context") = nb::none(), + nb::arg("value"), nb::arg("context").none() = 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 { context->get(), mlirF64TypeGet(context->get()), value); return PyFloatAttribute(context->getRef(), attr); }, - nb::arg("value"), nb::arg("context") = nb::none(), + nb::arg("value"), nb::arg("context").none() = nb::none(), "Gets an uniqued float point attribute associated to a f64 type"); c.def_prop_ro("value", mlirFloatAttrGetValueDouble, "Returns the value of the float attribute"); @@ -642,7 +642,7 @@ class PyBoolAttribute : public PyConcreteAttribute { MlirAttribute attr = mlirBoolAttrGet(context->get(), value); return PyBoolAttribute(context->getRef(), attr); }, - nb::arg("value"), nb::arg("context") = nb::none(), + nb::arg("value"), nb::arg("context").none() = nb::none(), "Gets an uniqued bool attribute"); c.def_prop_ro("value", mlirBoolAttrGetValue, "Returns the value of the bool attribute"); @@ -679,7 +679,7 @@ class PySymbolRefAttribute : public PyConcreteAttribute { DefaultingPyMlirContext context) { return PySymbolRefAttribute::fromList(symbols, context.resolve()); }, - nb::arg("symbols"), nb::arg("context") = nb::none(), + nb::arg("symbols"), nb::arg("context").none() = nb::none(), "Gets a uniqued SymbolRef attribute from a list of symbol names"); c.def_prop_ro( "value", @@ -713,7 +713,7 @@ class PyFlatSymbolRefAttribute mlirFlatSymbolRefAttrGet(context->get(), toMlirStringRef(value)); return PyFlatSymbolRefAttribute(context->getRef(), attr); }, - nb::arg("value"), nb::arg("context") = nb::none(), + nb::arg("value"), nb::arg("context").none() = nb::none(), "Gets a uniqued FlatSymbolRef attribute"); c.def_prop_ro( "value", @@ -746,7 +746,7 @@ class PyOpaqueAttribute : public PyConcreteAttribute { return PyOpaqueAttribute(context->getRef(), attr); }, nb::arg("dialect_namespace"), nb::arg("buffer"), nb::arg("type"), - nb::arg("context") = nb::none(), "Gets an Opaque attribute."); + nb::arg("context").none() = nb::none(), "Gets an Opaque attribute."); c.def_prop_ro( "dialect_namespace", [](PyOpaqueAttribute &self) { @@ -780,7 +780,7 @@ class PyStringAttribute : public PyConcreteAttribute { mlirStringAttrGet(context->get(), toMlirStringRef(value)); return PyStringAttribute(context->getRef(), attr); }, - nb::arg("value"), nb::arg("context") = nb::none(), + nb::arg("value"), nb::arg("context").none() = nb::none(), "Gets a uniqued string attribute"); c.def_static( "get", @@ -789,7 +789,7 @@ class PyStringAttribute : public PyConcreteAttribute { mlirStringAttrGet(context->get(), toMlirStringRef(value)); return PyStringAttribute(context->getRef(), attr); }, - nb::arg("value"), nb::arg("context") = nb::none(), + nb::arg("value"), nb::arg("context").none() = nb::none(), "Gets a uniqued string attribute"); c.def_static( "get_typed", @@ -1030,12 +1030,13 @@ class PyDenseElementsAttribute c.def("__len__", &PyDenseElementsAttribute::dunderLen) .def_static("get", PyDenseElementsAttribute::getFromBuffer, nb::arg("array"), nb::arg("signless") = true, - nb::arg("type") = nb::none(), nb::arg("shape") = nb::none(), - nb::arg("context") = nb::none(), + nb::arg("type").none() = nb::none(), + nb::arg("shape").none() = nb::none(), + nb::arg("context").none() = nb::none(), kDenseElementsAttrGetDocstring) .def_static("get", PyDenseElementsAttribute::getFromList, - nb::arg("attrs"), nb::arg("type") = nb::none(), - nb::arg("context") = nb::none(), + nb::arg("attrs"), nb::arg("type").none() = nb::none(), + nb::arg("context").none() = nb::none(), kDenseElementsAttrGetFromListDocstring) .def_static("get_splat", PyDenseElementsAttribute::getSplat, nb::arg("shaped_type"), nb::arg("element_attr"), @@ -1504,12 +1505,12 @@ class PyDenseResourceElementsAttribute } static void bindDerived(ClassTy &c) { - c.def_static("get_from_buffer", - PyDenseResourceElementsAttribute::getFromBuffer, - nb::arg("array"), nb::arg("name"), nb::arg("type"), - nb::arg("alignment") = nb::none(), - nb::arg("is_mutable") = false, nb::arg("context") = nb::none(), - kDenseResourceElementsAttrGetFromBufferDocstring); + c.def_static( + "get_from_buffer", PyDenseResourceElementsAttribute::getFromBuffer, + nb::arg("array"), nb::arg("name"), nb::arg("type"), + nb::arg("alignment").none() = nb::none(), nb::arg("is_mutable") = false, + nb::arg("context").none() = nb::none(), + kDenseResourceElementsAttrGetFromBufferDocstring); } }; @@ -1549,7 +1550,7 @@ class PyDictAttribute : public PyConcreteAttribute { mlirNamedAttributes.data()); return PyDictAttribute(context->getRef(), attr); }, - nb::arg("value") = nb::dict(), nb::arg("context") = nb::none(), + nb::arg("value") = nb::dict(), nb::arg("context").none() = nb::none(), "Gets an uniqued dict attribute"); c.def("__getitem__", [](PyDictAttribute &self, const std::string &name) { MlirAttribute attr = @@ -1621,7 +1622,7 @@ class PyTypeAttribute : public PyConcreteAttribute { MlirAttribute attr = mlirTypeAttrGet(value.get()); return PyTypeAttribute(context->getRef(), attr); }, - nb::arg("value"), nb::arg("context") = nb::none(), + nb::arg("value"), nb::arg("context").none() = nb::none(), "Gets a uniqued Type attribute"); c.def_prop_ro("value", [](PyTypeAttribute &self) { return mlirTypeAttrGetValue(self.get()); @@ -1645,7 +1646,7 @@ class PyUnitAttribute : public PyConcreteAttribute { return PyUnitAttribute(context->getRef(), mlirUnitAttrGet(context->get())); }, - nb::arg("context") = nb::none(), "Create a Unit attribute."); + nb::arg("context").none() = nb::none(), "Create a Unit attribute."); } }; @@ -1668,7 +1669,8 @@ class PyStridedLayoutAttribute ctx->get(), offset, strides.size(), strides.data()); return PyStridedLayoutAttribute(ctx->getRef(), attr); }, - nb::arg("offset"), nb::arg("strides"), nb::arg("context") = nb::none(), + nb::arg("offset"), nb::arg("strides"), + nb::arg("context").none() = nb::none(), "Gets a strided layout attribute."); c.def_static( "get_fully_dynamic", @@ -1680,7 +1682,7 @@ class PyStridedLayoutAttribute ctx->get(), dynamic, strides.size(), strides.data()); return PyStridedLayoutAttribute(ctx->getRef(), attr); }, - nb::arg("rank"), nb::arg("context") = nb::none(), + nb::arg("rank"), nb::arg("context").none() = nb::none(), "Gets a strided layout attribute with dynamic offset and strides of " "a " "given rank."); diff --git a/mlir/lib/Bindings/Python/IRInterfaces.cpp b/mlir/lib/Bindings/Python/IRInterfaces.cpp index 6aa057c2a78aa..9e1fedaab5235 100644 --- a/mlir/lib/Bindings/Python/IRInterfaces.cpp +++ b/mlir/lib/Bindings/Python/IRInterfaces.cpp @@ -195,7 +195,7 @@ class PyConcreteOpInterface { static void bind(nb::module_ &m) { nb::class_ cls(m, ConcreteIface::pyClassName); cls.def(nb::init(), nb::arg("object"), - nb::arg("context") = nb::none(), constructorDoc) + nb::arg("context").none() = nb::none(), constructorDoc) .def_prop_ro("operation", &PyConcreteOpInterface::getOperationObject, operationDoc) .def_prop_ro("opview", &PyConcreteOpInterface::getOpView, opviewDoc); @@ -303,11 +303,12 @@ class PyInferTypeOpInterface static void bindDerived(ClassTy &cls) { cls.def("inferReturnTypes", &PyInferTypeOpInterface::inferReturnTypes, - nb::arg("operands") = nb::none(), - nb::arg("attributes") = nb::none(), - nb::arg("properties") = nb::none(), nb::arg("regions") = nb::none(), - nb::arg("context") = nb::none(), nb::arg("loc") = nb::none(), - inferReturnTypesDoc); + nb::arg("operands").none() = nb::none(), + nb::arg("attributes").none() = nb::none(), + nb::arg("properties").none() = nb::none(), + nb::arg("regions").none() = nb::none(), + nb::arg("context").none() = nb::none(), + nb::arg("loc").none() = nb::none(), inferReturnTypesDoc); } }; @@ -462,10 +463,12 @@ class PyInferShapedTypeOpInterface static void bindDerived(ClassTy &cls) { cls.def("inferReturnTypeComponents", &PyInferShapedTypeOpInterface::inferReturnTypeComponents, - nb::arg("operands") = nb::none(), - nb::arg("attributes") = nb::none(), nb::arg("regions") = nb::none(), - nb::arg("properties") = nb::none(), nb::arg("context") = nb::none(), - nb::arg("loc") = nb::none(), inferReturnTypeComponentsDoc); + nb::arg("operands").none() = nb::none(), + nb::arg("attributes").none() = nb::none(), + nb::arg("regions").none() = nb::none(), + nb::arg("properties").none() = nb::none(), + nb::arg("context").none() = nb::none(), + nb::arg("loc").none() = nb::none(), inferReturnTypeComponentsDoc); } }; diff --git a/mlir/lib/Bindings/Python/IRTypes.cpp b/mlir/lib/Bindings/Python/IRTypes.cpp index 38da70360ecd6..a9b12590188f8 100644 --- a/mlir/lib/Bindings/Python/IRTypes.cpp +++ b/mlir/lib/Bindings/Python/IRTypes.cpp @@ -49,7 +49,7 @@ class PyIntegerType : public PyConcreteType { MlirType t = mlirIntegerTypeGet(context->get(), width); return PyIntegerType(context->getRef(), t); }, - nb::arg("width"), nb::arg("context") = nb::none(), + nb::arg("width"), nb::arg("context").none() = nb::none(), "Create a signless integer type"); c.def_static( "get_signed", @@ -57,7 +57,7 @@ class PyIntegerType : public PyConcreteType { MlirType t = mlirIntegerTypeSignedGet(context->get(), width); return PyIntegerType(context->getRef(), t); }, - nb::arg("width"), nb::arg("context") = nb::none(), + nb::arg("width"), nb::arg("context").none() = nb::none(), "Create a signed integer type"); c.def_static( "get_unsigned", @@ -65,7 +65,7 @@ class PyIntegerType : public PyConcreteType { MlirType t = mlirIntegerTypeUnsignedGet(context->get(), width); return PyIntegerType(context->getRef(), t); }, - nb::arg("width"), nb::arg("context") = nb::none(), + nb::arg("width"), nb::arg("context").none() = nb::none(), "Create an unsigned integer type"); c.def_prop_ro( "width", @@ -108,7 +108,7 @@ class PyIndexType : public PyConcreteType { MlirType t = mlirIndexTypeGet(context->get()); return PyIndexType(context->getRef(), t); }, - nb::arg("context") = nb::none(), "Create a index type."); + nb::arg("context").none() = nb::none(), "Create a index type."); } }; @@ -142,7 +142,7 @@ class PyFloat4E2M1FNType MlirType t = mlirFloat4E2M1FNTypeGet(context->get()); return PyFloat4E2M1FNType(context->getRef(), t); }, - nb::arg("context") = nb::none(), "Create a float4_e2m1fn type."); + nb::arg("context").none() = nb::none(), "Create a float4_e2m1fn type."); } }; @@ -163,7 +163,7 @@ class PyFloat6E2M3FNType MlirType t = mlirFloat6E2M3FNTypeGet(context->get()); return PyFloat6E2M3FNType(context->getRef(), t); }, - nb::arg("context") = nb::none(), "Create a float6_e2m3fn type."); + nb::arg("context").none() = nb::none(), "Create a float6_e2m3fn type."); } }; @@ -184,7 +184,7 @@ class PyFloat6E3M2FNType MlirType t = mlirFloat6E3M2FNTypeGet(context->get()); return PyFloat6E3M2FNType(context->getRef(), t); }, - nb::arg("context") = nb::none(), "Create a float6_e3m2fn type."); + nb::arg("context").none() = nb::none(), "Create a float6_e3m2fn type."); } }; @@ -205,7 +205,7 @@ class PyFloat8E4M3FNType MlirType t = mlirFloat8E4M3FNTypeGet(context->get()); return PyFloat8E4M3FNType(context->getRef(), t); }, - nb::arg("context") = nb::none(), "Create a float8_e4m3fn type."); + nb::arg("context").none() = nb::none(), "Create a float8_e4m3fn type."); } }; @@ -225,7 +225,7 @@ class PyFloat8E5M2Type : public PyConcreteType { MlirType t = mlirFloat8E5M2TypeGet(context->get()); return PyFloat8E5M2Type(context->getRef(), t); }, - nb::arg("context") = nb::none(), "Create a float8_e5m2 type."); + nb::arg("context").none() = nb::none(), "Create a float8_e5m2 type."); } }; @@ -245,7 +245,7 @@ class PyFloat8E4M3Type : public PyConcreteType { MlirType t = mlirFloat8E4M3TypeGet(context->get()); return PyFloat8E4M3Type(context->getRef(), t); }, - nb::arg("context") = nb::none(), "Create a float8_e4m3 type."); + nb::arg("context").none() = nb::none(), "Create a float8_e4m3 type."); } }; @@ -266,7 +266,8 @@ class PyFloat8E4M3FNUZType MlirType t = mlirFloat8E4M3FNUZTypeGet(context->get()); return PyFloat8E4M3FNUZType(context->getRef(), t); }, - nb::arg("context") = nb::none(), "Create a float8_e4m3fnuz type."); + nb::arg("context").none() = nb::none(), + "Create a float8_e4m3fnuz type."); } }; @@ -287,7 +288,8 @@ class PyFloat8E4M3B11FNUZType MlirType t = mlirFloat8E4M3B11FNUZTypeGet(context->get()); return PyFloat8E4M3B11FNUZType(context->getRef(), t); }, - nb::arg("context") = nb::none(), "Create a float8_e4m3b11fnuz type."); + nb::arg("context").none() = nb::none(), + "Create a float8_e4m3b11fnuz type."); } }; @@ -308,7 +310,8 @@ class PyFloat8E5M2FNUZType MlirType t = mlirFloat8E5M2FNUZTypeGet(context->get()); return PyFloat8E5M2FNUZType(context->getRef(), t); }, - nb::arg("context") = nb::none(), "Create a float8_e5m2fnuz type."); + nb::arg("context").none() = nb::none(), + "Create a float8_e5m2fnuz type."); } }; @@ -328,7 +331,7 @@ class PyFloat8E3M4Type : public PyConcreteType { MlirType t = mlirFloat8E3M4TypeGet(context->get()); return PyFloat8E3M4Type(context->getRef(), t); }, - nb::arg("context") = nb::none(), "Create a float8_e3m4 type."); + nb::arg("context").none() = nb::none(), "Create a float8_e3m4 type."); } }; @@ -349,7 +352,8 @@ class PyFloat8E8M0FNUType MlirType t = mlirFloat8E8M0FNUTypeGet(context->get()); return PyFloat8E8M0FNUType(context->getRef(), t); }, - nb::arg("context") = nb::none(), "Create a float8_e8m0fnu type."); + nb::arg("context").none() = nb::none(), + "Create a float8_e8m0fnu type."); } }; @@ -369,7 +373,7 @@ class PyBF16Type : public PyConcreteType { MlirType t = mlirBF16TypeGet(context->get()); return PyBF16Type(context->getRef(), t); }, - nb::arg("context") = nb::none(), "Create a bf16 type."); + nb::arg("context").none() = nb::none(), "Create a bf16 type."); } }; @@ -389,7 +393,7 @@ class PyF16Type : public PyConcreteType { MlirType t = mlirF16TypeGet(context->get()); return PyF16Type(context->getRef(), t); }, - nb::arg("context") = nb::none(), "Create a f16 type."); + nb::arg("context").none() = nb::none(), "Create a f16 type."); } }; @@ -409,7 +413,7 @@ class PyTF32Type : public PyConcreteType { MlirType t = mlirTF32TypeGet(context->get()); return PyTF32Type(context->getRef(), t); }, - nb::arg("context") = nb::none(), "Create a tf32 type."); + nb::arg("context").none() = nb::none(), "Create a tf32 type."); } }; @@ -429,7 +433,7 @@ class PyF32Type : public PyConcreteType { MlirType t = mlirF32TypeGet(context->get()); return PyF32Type(context->getRef(), t); }, - nb::arg("context") = nb::none(), "Create a f32 type."); + nb::arg("context").none() = nb::none(), "Create a f32 type."); } }; @@ -449,7 +453,7 @@ class PyF64Type : public PyConcreteType { MlirType t = mlirF64TypeGet(context->get()); return PyF64Type(context->getRef(), t); }, - nb::arg("context") = nb::none(), "Create a f64 type."); + nb::arg("context").none() = nb::none(), "Create a f64 type."); } }; @@ -469,7 +473,7 @@ class PyNoneType : public PyConcreteType { MlirType t = mlirNoneTypeGet(context->get()); return PyNoneType(context->getRef(), t); }, - nb::arg("context") = nb::none(), "Create a none type."); + nb::arg("context").none() = nb::none(), "Create a none type."); } }; @@ -635,9 +639,9 @@ class PyVectorType : public PyConcreteType { static void bindDerived(ClassTy &c) { c.def_static("get", &PyVectorType::get, nb::arg("shape"), nb::arg("element_type"), nb::kw_only(), - nb::arg("scalable") = nb::none(), - nb::arg("scalable_dims") = nb::none(), - nb::arg("loc") = nb::none(), "Create a vector type") + nb::arg("scalable").none() = nb::none(), + nb::arg("scalable_dims").none() = nb::none(), + nb::arg("loc").none() = nb::none(), "Create a vector type") .def_prop_ro( "scalable", [](MlirType self) { return mlirVectorTypeIsScalable(self); }) @@ -716,8 +720,8 @@ class PyRankedTensorType return PyRankedTensorType(elementType.getContext(), t); }, nb::arg("shape"), nb::arg("element_type"), - nb::arg("encoding") = nb::none(), nb::arg("loc") = nb::none(), - "Create a ranked tensor type"); + nb::arg("encoding").none() = nb::none(), + nb::arg("loc").none() = nb::none(), "Create a ranked tensor type"); c.def_prop_ro("encoding", [](PyRankedTensorType &self) -> std::optional { MlirAttribute encoding = @@ -749,7 +753,7 @@ class PyUnrankedTensorType throw MLIRError("Invalid type", errors.take()); return PyUnrankedTensorType(elementType.getContext(), t); }, - nb::arg("element_type"), nb::arg("loc") = nb::none(), + nb::arg("element_type"), nb::arg("loc").none() = nb::none(), "Create a unranked tensor type"); } }; @@ -781,8 +785,9 @@ class PyMemRefType : public PyConcreteType { return PyMemRefType(elementType.getContext(), t); }, nb::arg("shape"), nb::arg("element_type"), - nb::arg("layout") = nb::none(), nb::arg("memory_space") = nb::none(), - nb::arg("loc") = nb::none(), "Create a memref type") + nb::arg("layout").none() = nb::none(), + nb::arg("memory_space").none() = nb::none(), + nb::arg("loc").none() = nb::none(), "Create a memref type") .def_prop_ro( "layout", [](PyMemRefType &self) -> MlirAttribute { @@ -877,7 +882,7 @@ class PyTupleType : public PyConcreteType { elements.data()); return PyTupleType(context->getRef(), t); }, - nb::arg("elements"), nb::arg("context") = nb::none(), + nb::arg("elements"), nb::arg("context").none() = nb::none(), "Create a tuple type"); c.def( "get_type", @@ -913,7 +918,8 @@ class PyFunctionType : public PyConcreteType { results.size(), results.data()); return PyFunctionType(context->getRef(), t); }, - nb::arg("inputs"), nb::arg("results"), nb::arg("context") = nb::none(), + nb::arg("inputs"), nb::arg("results"), + nb::arg("context").none() = nb::none(), "Gets a FunctionType from a list of input and result types"); c.def_prop_ro( "inputs", @@ -965,7 +971,7 @@ class PyOpaqueType : public PyConcreteType { return PyOpaqueType(context->getRef(), type); }, nb::arg("dialect_namespace"), nb::arg("buffer"), - nb::arg("context") = nb::none(), + nb::arg("context").none() = nb::none(), "Create an unregistered (opaque) dialect type."); c.def_prop_ro( "dialect_namespace", diff --git a/mlir/lib/Bindings/Python/Pass.cpp b/mlir/lib/Bindings/Python/Pass.cpp index 72bf8ed8f856f..88e28dca76bb9 100644 --- a/mlir/lib/Bindings/Python/Pass.cpp +++ b/mlir/lib/Bindings/Python/Pass.cpp @@ -67,7 +67,7 @@ void mlir::python::populatePassManagerSubmodule(nb::module_ &m) { mlirStringRefCreate(anchorOp.data(), anchorOp.size())); new (&self) PyPassManager(passManager); }, - "anchor_op"_a = nb::str("any"), "context"_a = nb::none(), + "anchor_op"_a = nb::str("any"), "context"_a.none() = nb::none(), "Create a new PassManager for the current (or provided) Context.") .def_prop_ro(MLIR_PYTHON_CAPI_PTR_ATTR, &PyPassManager::getCapsule) .def(MLIR_PYTHON_CAPI_FACTORY_ATTR, &PyPassManager::createFromCapsule) @@ -109,10 +109,10 @@ void mlir::python::populatePassManagerSubmodule(nb::module_ &m) { "print_before_all"_a = false, "print_after_all"_a = true, "print_module_scope"_a = false, "print_after_change"_a = false, "print_after_failure"_a = false, - "large_elements_limit"_a = nb::none(), - "large_resource_limit"_a = nb::none(), "enable_debug_info"_a = false, - "print_generic_op_form"_a = false, - "tree_printing_dir_path"_a = nb::none(), + "large_elements_limit"_a.none() = nb::none(), + "large_resource_limit"_a.none() = nb::none(), + "enable_debug_info"_a = false, "print_generic_op_form"_a = false, + "tree_printing_dir_path"_a.none() = nb::none(), "Enable IR printing, default as mlir-print-ir-after-all.") .def( "enable_verifier", @@ -139,7 +139,7 @@ void mlir::python::populatePassManagerSubmodule(nb::module_ &m) { throw nb::value_error(errorMsg.join().c_str()); return new PyPassManager(passManager); }, - "pipeline"_a, "context"_a = nb::none(), + "pipeline"_a, "context"_a.none() = nb::none(), "Parse a textual pass-pipeline and return a top-level PassManager " "that can be applied on a Module. Throw a ValueError if the pipeline " "can't be parsed") diff --git a/mlir/lib/Bindings/Python/TransformInterpreter.cpp b/mlir/lib/Bindings/Python/TransformInterpreter.cpp index 81c02e905505a..920bca886f617 100644 --- a/mlir/lib/Bindings/Python/TransformInterpreter.cpp +++ b/mlir/lib/Bindings/Python/TransformInterpreter.cpp @@ -14,8 +14,8 @@ #include "mlir-c/IR.h" #include "mlir-c/Support.h" #include "mlir/Bindings/Python/Diagnostics.h" -#include "mlir/Bindings/Python/Nanobind.h" #include "mlir/Bindings/Python/NanobindAdaptors.h" +#include "mlir/Bindings/Python/Nanobind.h" namespace nb = nanobind; diff --git a/mlir/test/python/CMakeLists.txt b/mlir/test/python/CMakeLists.txt index e1e82ef367b1e..d68f3ff82e883 100644 --- a/mlir/test/python/CMakeLists.txt +++ b/mlir/test/python/CMakeLists.txt @@ -13,7 +13,7 @@ add_subdirectory(lib) set(MLIR_PYTHON_TEST_DEPENDS MLIRPythonModules) if(NOT MLIR_STANDALONE_BUILD) - list(APPEND MLIR_PYTHON_TEST_DEPENDS FileCheck count not) + list(APPEND MLIR_PYTHON_TEST_DEPENDS FileCheck count) endif() add_lit_testsuite(check-mlir-python "Running the MLIR Python regression tests" ${CMAKE_CURRENT_BINARY_DIR} From 8d2d18c0092ccfb04486ca5181f73e39a36b5203 Mon Sep 17 00:00:00 2001 From: makslevental Date: Mon, 8 Sep 2025 10:33:34 -0700 Subject: [PATCH 3/3] [MLIR][Python] remove .none() arg descriptor --- mlir/lib/Bindings/Python/DialectGPU.cpp | 4 +- mlir/lib/Bindings/Python/DialectLLVM.cpp | 12 +-- mlir/lib/Bindings/Python/DialectNVGPU.cpp | 2 +- mlir/lib/Bindings/Python/DialectPDL.cpp | 8 +- mlir/lib/Bindings/Python/DialectSMT.cpp | 4 +- .../Bindings/Python/DialectSparseTensor.cpp | 5 +- mlir/lib/Bindings/Python/DialectTransform.cpp | 10 +- mlir/lib/Bindings/Python/IRAffine.cpp | 33 ++++--- mlir/lib/Bindings/Python/IRAttributes.cpp | 56 ++++++----- mlir/lib/Bindings/Python/IRCore.cpp | 93 +++++++++---------- mlir/lib/Bindings/Python/IRInterfaces.cpp | 23 ++--- mlir/lib/Bindings/Python/IRTypes.cpp | 72 +++++++------- mlir/lib/Bindings/Python/Pass.cpp | 12 +-- 13 files changed, 156 insertions(+), 178 deletions(-) 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..55b9331270cdc 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 { @@ -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..18917416412c1 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..ac163b59a0fb5 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..3123e3bdda496 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..00b65ee9745dc 100644 --- a/mlir/lib/Bindings/Python/DialectSparseTensor.cpp +++ b/mlir/lib/Bindings/Python/DialectSparseTensor.cpp @@ -53,9 +53,8 @@ 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..150c69953d960 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..bc6aa0dac6221 100644 --- a/mlir/lib/Bindings/Python/IRAffine.cpp +++ b/mlir/lib/Bindings/Python/IRAffine.cpp @@ -142,7 +142,7 @@ class PyAffineConstantExpr : public PyConcreteAffineExpr { 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 { 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 { 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, @@ -597,8 +597,7 @@ void mlir::python::populateIRAffine(nb::module_ &m) { self.getContext(), mlirAffineExprShiftSymbols(self, numSymbols, shift, offset)); }, - nb::arg("num_symbols"), nb::arg("shift"), - nb::arg("offset").none() = 0) + nb::arg("num_symbols"), nb::arg("shift"), nb::arg("offset") = 0) .def_static( "simplify_affine_expr", [](PyAffineExpr &self, uint32_t numDims, uint32_t numSymbols) { @@ -655,15 +654,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 +745,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 +754,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 +762,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 +770,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 +781,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 +795,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 +922,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 +932,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..b3c768846c74f 100644 --- a/mlir/lib/Bindings/Python/IRAttributes.cpp +++ b/mlir/lib/Bindings/Python/IRAttributes.cpp @@ -351,7 +351,7 @@ class PyDenseArrayAttribute : public PyConcreteAttribute { } 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 { [](const std::vector &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 { 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 { 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 { 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 { 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 attribute associated to a f64 type"); c.def_prop_ro("value", mlirFloatAttrGetValueDouble, "Returns the value of the float attribute"); @@ -642,7 +642,7 @@ class PyBoolAttribute : public PyConcreteAttribute { MlirAttribute attr = mlirBoolAttrGet(context->get(), value); return PyBoolAttribute(context->getRef(), attr); }, - nb::arg("value"), nb::arg("context").none() = nb::none(), + nb::arg("value"), nb::arg("context") = nb::none(), "Gets an uniqued bool attribute"); c.def_prop_ro("value", mlirBoolAttrGetValue, "Returns the value of the bool attribute"); @@ -679,7 +679,7 @@ class PySymbolRefAttribute : public PyConcreteAttribute { DefaultingPyMlirContext context) { return PySymbolRefAttribute::fromList(symbols, context.resolve()); }, - nb::arg("symbols"), nb::arg("context").none() = nb::none(), + nb::arg("symbols"), nb::arg("context") = nb::none(), "Gets a uniqued SymbolRef attribute from a list of symbol names"); c.def_prop_ro( "value", @@ -713,7 +713,7 @@ class PyFlatSymbolRefAttribute mlirFlatSymbolRefAttrGet(context->get(), toMlirStringRef(value)); return PyFlatSymbolRefAttribute(context->getRef(), attr); }, - nb::arg("value"), nb::arg("context").none() = nb::none(), + nb::arg("value"), nb::arg("context") = nb::none(), "Gets a uniqued FlatSymbolRef attribute"); c.def_prop_ro( "value", @@ -746,7 +746,7 @@ class PyOpaqueAttribute : public PyConcreteAttribute { return PyOpaqueAttribute(context->getRef(), attr); }, nb::arg("dialect_namespace"), nb::arg("buffer"), nb::arg("type"), - nb::arg("context").none() = nb::none(), "Gets an Opaque attribute."); + nb::arg("context") = nb::none(), "Gets an Opaque attribute."); c.def_prop_ro( "dialect_namespace", [](PyOpaqueAttribute &self) { @@ -780,7 +780,7 @@ class PyStringAttribute : public PyConcreteAttribute { mlirStringAttrGet(context->get(), toMlirStringRef(value)); return PyStringAttribute(context->getRef(), attr); }, - nb::arg("value"), nb::arg("context").none() = nb::none(), + nb::arg("value"), nb::arg("context") = nb::none(), "Gets a uniqued string attribute"); c.def_static( "get", @@ -789,7 +789,7 @@ class PyStringAttribute : public PyConcreteAttribute { mlirStringAttrGet(context->get(), toMlirStringRef(value)); return PyStringAttribute(context->getRef(), attr); }, - nb::arg("value"), nb::arg("context").none() = nb::none(), + nb::arg("value"), nb::arg("context") = nb::none(), "Gets a uniqued string attribute"); c.def_static( "get_typed", @@ -1030,13 +1030,12 @@ class PyDenseElementsAttribute c.def("__len__", &PyDenseElementsAttribute::dunderLen) .def_static("get", PyDenseElementsAttribute::getFromBuffer, nb::arg("array"), nb::arg("signless") = true, - nb::arg("type").none() = nb::none(), - nb::arg("shape").none() = nb::none(), - nb::arg("context").none() = nb::none(), + nb::arg("type") = nb::none(), nb::arg("shape") = nb::none(), + nb::arg("context") = nb::none(), kDenseElementsAttrGetDocstring) .def_static("get", PyDenseElementsAttribute::getFromList, - nb::arg("attrs"), nb::arg("type").none() = nb::none(), - nb::arg("context").none() = nb::none(), + nb::arg("attrs"), nb::arg("type") = nb::none(), + nb::arg("context") = nb::none(), kDenseElementsAttrGetFromListDocstring) .def_static("get_splat", PyDenseElementsAttribute::getSplat, nb::arg("shaped_type"), nb::arg("element_attr"), @@ -1505,12 +1504,12 @@ class PyDenseResourceElementsAttribute } static void bindDerived(ClassTy &c) { - c.def_static( - "get_from_buffer", PyDenseResourceElementsAttribute::getFromBuffer, - nb::arg("array"), nb::arg("name"), nb::arg("type"), - nb::arg("alignment").none() = nb::none(), nb::arg("is_mutable") = false, - nb::arg("context").none() = nb::none(), - kDenseResourceElementsAttrGetFromBufferDocstring); + c.def_static("get_from_buffer", + PyDenseResourceElementsAttribute::getFromBuffer, + nb::arg("array"), nb::arg("name"), nb::arg("type"), + nb::arg("alignment") = nb::none(), + nb::arg("is_mutable") = false, nb::arg("context") = nb::none(), + kDenseResourceElementsAttrGetFromBufferDocstring); } }; @@ -1550,7 +1549,7 @@ class PyDictAttribute : public PyConcreteAttribute { mlirNamedAttributes.data()); return PyDictAttribute(context->getRef(), attr); }, - nb::arg("value") = nb::dict(), nb::arg("context").none() = nb::none(), + nb::arg("value") = nb::dict(), nb::arg("context") = nb::none(), "Gets an uniqued dict attribute"); c.def("__getitem__", [](PyDictAttribute &self, const std::string &name) { MlirAttribute attr = @@ -1622,7 +1621,7 @@ class PyTypeAttribute : public PyConcreteAttribute { MlirAttribute attr = mlirTypeAttrGet(value.get()); return PyTypeAttribute(context->getRef(), attr); }, - nb::arg("value"), nb::arg("context").none() = nb::none(), + nb::arg("value"), nb::arg("context") = nb::none(), "Gets a uniqued Type attribute"); c.def_prop_ro("value", [](PyTypeAttribute &self) { return mlirTypeAttrGetValue(self.get()); @@ -1646,7 +1645,7 @@ class PyUnitAttribute : public PyConcreteAttribute { return PyUnitAttribute(context->getRef(), mlirUnitAttrGet(context->get())); }, - nb::arg("context").none() = nb::none(), "Create a Unit attribute."); + nb::arg("context") = nb::none(), "Create a Unit attribute."); } }; @@ -1669,8 +1668,7 @@ class PyStridedLayoutAttribute ctx->get(), offset, strides.size(), strides.data()); return PyStridedLayoutAttribute(ctx->getRef(), attr); }, - nb::arg("offset"), nb::arg("strides"), - nb::arg("context").none() = nb::none(), + nb::arg("offset"), nb::arg("strides"), nb::arg("context") = nb::none(), "Gets a strided layout attribute."); c.def_static( "get_fully_dynamic", @@ -1682,7 +1680,7 @@ class PyStridedLayoutAttribute ctx->get(), dynamic, strides.size(), strides.data()); return PyStridedLayoutAttribute(ctx->getRef(), attr); }, - nb::arg("rank"), nb::arg("context").none() = nb::none(), + nb::arg("rank"), nb::arg("context") = nb::none(), "Gets a strided layout attribute with dynamic offset and strides of " "a " "given rank."); diff --git a/mlir/lib/Bindings/Python/IRCore.cpp b/mlir/lib/Bindings/Python/IRCore.cpp index ba00ef712084b..8273a9346e5dd 100644 --- a/mlir/lib/Bindings/Python/IRCore.cpp +++ b/mlir/lib/Bindings/Python/IRCore.cpp @@ -3104,7 +3104,7 @@ void mlir::python::populateIRCore(nb::module_ &m) { return PyLocation(context->getRef(), mlirLocationUnknownGet(context->get())); }, - nb::arg("context").none() = nb::none(), + nb::arg("context") = nb::none(), "Gets a Location representing an unknown location") .def_static( "callsite", @@ -3119,8 +3119,7 @@ void mlir::python::populateIRCore(nb::module_ &m) { return PyLocation(context->getRef(), mlirLocationCallSiteGet(callee.get(), caller)); }, - nb::arg("callee"), nb::arg("frames"), - nb::arg("context").none() = nb::none(), + nb::arg("callee"), nb::arg("frames"), nb::arg("context") = nb::none(), kContextGetCallSiteLocationDocstring) .def("is_a_callsite", mlirLocationIsACallSite) .def_prop_ro("callee", mlirLocationCallSiteGetCallee) @@ -3135,8 +3134,7 @@ void mlir::python::populateIRCore(nb::module_ &m) { context->get(), toMlirStringRef(filename), line, col)); }, nb::arg("filename"), nb::arg("line"), nb::arg("col"), - nb::arg("context").none() = nb::none(), - kContextGetFileLocationDocstring) + nb::arg("context") = nb::none(), kContextGetFileLocationDocstring) .def_static( "file", [](std::string filename, int startLine, int startCol, int endLine, @@ -3148,7 +3146,7 @@ void mlir::python::populateIRCore(nb::module_ &m) { }, nb::arg("filename"), nb::arg("start_line"), nb::arg("start_col"), nb::arg("end_line"), nb::arg("end_col"), - nb::arg("context").none() = nb::none(), kContextGetFileRangeDocstring) + nb::arg("context") = nb::none(), kContextGetFileRangeDocstring) .def("is_a_file", mlirLocationIsAFileLineColRange) .def_prop_ro("filename", [](MlirLocation loc) { @@ -3173,9 +3171,8 @@ void mlir::python::populateIRCore(nb::module_ &m) { metadata ? metadata->get() : MlirAttribute{0}); return PyLocation(context->getRef(), location); }, - nb::arg("locations"), nb::arg("metadata").none() = nb::none(), - nb::arg("context").none() = nb::none(), - kContextGetFusedLocationDocstring) + nb::arg("locations"), nb::arg("metadata") = nb::none(), + nb::arg("context") = nb::none(), kContextGetFusedLocationDocstring) .def("is_a_fused", mlirLocationIsAFused) .def_prop_ro("locations", [](MlirLocation loc) { @@ -3197,9 +3194,8 @@ void mlir::python::populateIRCore(nb::module_ &m) { childLoc ? childLoc->get() : mlirLocationUnknownGet(context->get()))); }, - nb::arg("name"), nb::arg("childLoc").none() = nb::none(), - nb::arg("context").none() = nb::none(), - kContextGetNameLocationDocString) + nb::arg("name"), nb::arg("childLoc") = nb::none(), + nb::arg("context") = nb::none(), kContextGetNameLocationDocString) .def("is_a_name", mlirLocationIsAName) .def_prop_ro("name_str", [](MlirLocation loc) { @@ -3212,7 +3208,7 @@ void mlir::python::populateIRCore(nb::module_ &m) { return PyLocation(context->getRef(), mlirLocationFromAttribute(attribute)); }, - nb::arg("attribute"), nb::arg("context").none() = nb::none(), + nb::arg("attribute"), nb::arg("context") = nb::none(), "Gets a Location from a LocationAttr") .def_prop_ro( "context", @@ -3253,7 +3249,7 @@ void mlir::python::populateIRCore(nb::module_ &m) { throw MLIRError("Unable to parse module assembly", errors.take()); return PyModule::forModule(module).releaseObject(); }, - nb::arg("asm"), nb::arg("context").none() = nb::none(), + nb::arg("asm"), nb::arg("context") = nb::none(), kModuleParseDocstring) .def_static( "parse", @@ -3265,7 +3261,7 @@ void mlir::python::populateIRCore(nb::module_ &m) { throw MLIRError("Unable to parse module assembly", errors.take()); return PyModule::forModule(module).releaseObject(); }, - nb::arg("asm"), nb::arg("context").none() = nb::none(), + nb::arg("asm"), nb::arg("context") = nb::none(), kModuleParseDocstring) .def_static( "parseFile", @@ -3277,7 +3273,7 @@ void mlir::python::populateIRCore(nb::module_ &m) { throw MLIRError("Unable to parse module assembly", errors.take()); return PyModule::forModule(module).releaseObject(); }, - nb::arg("path"), nb::arg("context").none() = nb::none(), + nb::arg("path"), nb::arg("context") = nb::none(), kModuleParseDocstring) .def_static( "create", @@ -3286,7 +3282,7 @@ void mlir::python::populateIRCore(nb::module_ &m) { MlirModule module = mlirModuleCreateEmpty(pyLoc.get()); return PyModule::forModule(module).releaseObject(); }, - nb::arg("loc").none() = nb::none(), "Creates an empty module") + nb::arg("loc") = nb::none(), "Creates an empty module") .def_prop_ro( "context", [](PyModule &self) { return self.getContext().getObject(); }, @@ -3427,31 +3423,31 @@ void mlir::python::populateIRCore(nb::module_ &m) { .def("print", nb::overload_cast( &PyOperationBase::print), - nb::arg("state"), nb::arg("file").none() = nb::none(), + nb::arg("state"), nb::arg("file") = nb::none(), nb::arg("binary") = false, kOperationPrintStateDocstring) .def("print", nb::overload_cast, std::optional, bool, bool, bool, bool, bool, bool, nb::object, bool, bool>(&PyOperationBase::print), // Careful: Lots of arguments must match up with print method. - nb::arg("large_elements_limit").none() = nb::none(), - nb::arg("large_resource_limit").none() = nb::none(), + nb::arg("large_elements_limit") = nb::none(), + nb::arg("large_resource_limit") = nb::none(), nb::arg("enable_debug_info") = false, nb::arg("pretty_debug_info") = false, nb::arg("print_generic_op_form") = false, nb::arg("use_local_scope") = false, nb::arg("use_name_loc_as_prefix") = false, - nb::arg("assume_verified") = false, - nb::arg("file").none() = nb::none(), nb::arg("binary") = false, - nb::arg("skip_regions") = false, kOperationPrintDocstring) + nb::arg("assume_verified") = false, nb::arg("file") = nb::none(), + nb::arg("binary") = false, nb::arg("skip_regions") = false, + kOperationPrintDocstring) .def("write_bytecode", &PyOperationBase::writeBytecode, nb::arg("file"), - nb::arg("desired_version").none() = nb::none(), + nb::arg("desired_version") = nb::none(), kOperationPrintBytecodeDocstring) .def("get_asm", &PyOperationBase::getAsm, // Careful: Lots of arguments must match up with get_asm method. nb::arg("binary") = false, - nb::arg("large_elements_limit").none() = nb::none(), - nb::arg("large_resource_limit").none() = nb::none(), + nb::arg("large_elements_limit") = nb::none(), + nb::arg("large_resource_limit") = nb::none(), nb::arg("enable_debug_info") = false, nb::arg("pretty_debug_info") = false, nb::arg("print_generic_op_form") = false, @@ -3480,7 +3476,7 @@ void mlir::python::populateIRCore(nb::module_ &m) { [](PyOperationBase &self, nb::object ip) { return self.getOperation().clone(ip); }, - nb::arg("ip").none() = nb::none()) + nb::arg("ip") = nb::none()) .def( "detach_from_parent", [](PyOperationBase &self) { @@ -3531,11 +3527,10 @@ void mlir::python::populateIRCore(nb::module_ &m) { successors, regions, pyLoc, maybeIp, inferType); }, - nb::arg("name"), nb::arg("results").none() = nb::none(), - nb::arg("operands").none() = nb::none(), - nb::arg("attributes").none() = nb::none(), - nb::arg("successors").none() = nb::none(), nb::arg("regions") = 0, - nb::arg("loc").none() = nb::none(), nb::arg("ip").none() = nb::none(), + nb::arg("name"), nb::arg("results") = nb::none(), + nb::arg("operands") = nb::none(), nb::arg("attributes") = nb::none(), + nb::arg("successors") = nb::none(), nb::arg("regions") = 0, + nb::arg("loc") = nb::none(), nb::arg("ip") = nb::none(), nb::arg("infer_type") = false, kOperationCreateDocstring) .def_static( "parse", @@ -3545,7 +3540,7 @@ void mlir::python::populateIRCore(nb::module_ &m) { ->createOpView(); }, nb::arg("source"), nb::kw_only(), nb::arg("source_name") = "", - nb::arg("context").none() = nb::none(), + nb::arg("context") = nb::none(), "Parses an operation. Supports both text assembly format and binary " "bytecode format.") .def_prop_ro(MLIR_PYTHON_CAPI_PTR_ATTR, &PyOperation::getCapsule) @@ -3584,15 +3579,13 @@ void mlir::python::populateIRCore(nb::module_ &m) { attributes, successors, regions, pyLoc, maybeIp)); }, nb::arg("name"), nb::arg("opRegionSpec"), - nb::arg("operandSegmentSpecObj").none() = nb::none(), - nb::arg("resultSegmentSpecObj").none() = nb::none(), - nb::arg("results").none() = nb::none(), - nb::arg("operands").none() = nb::none(), - nb::arg("attributes").none() = nb::none(), - nb::arg("successors").none() = nb::none(), - nb::arg("regions").none() = nb::none(), - nb::arg("loc").none() = nb::none(), - nb::arg("ip").none() = nb::none()) + nb::arg("operandSegmentSpecObj") = nb::none(), + nb::arg("resultSegmentSpecObj") = nb::none(), + nb::arg("results") = nb::none(), nb::arg("operands") = nb::none(), + nb::arg("attributes") = nb::none(), + nb::arg("successors") = nb::none(), + nb::arg("regions") = nb::none(), nb::arg("loc") = nb::none(), + nb::arg("ip") = nb::none()) .def_prop_ro("operation", &PyOpView::getOperationObject) .def_prop_ro("opview", [](nb::object self) { return self; }) @@ -3632,12 +3625,10 @@ void mlir::python::populateIRCore(nb::module_ &m) { operandList, attributes, successors, regions, pyLoc, maybeIp); }, - nb::arg("cls"), nb::arg("results").none() = nb::none(), - nb::arg("operands").none() = nb::none(), - nb::arg("attributes").none() = nb::none(), - nb::arg("successors").none() = nb::none(), - nb::arg("regions").none() = nb::none(), - nb::arg("loc").none() = nb::none(), nb::arg("ip").none() = nb::none(), + nb::arg("cls"), nb::arg("results") = nb::none(), + nb::arg("operands") = nb::none(), nb::arg("attributes") = nb::none(), + nb::arg("successors") = nb::none(), nb::arg("regions") = nb::none(), + nb::arg("loc") = nb::none(), nb::arg("ip") = nb::none(), "Builds a specific, generated OpView based on class level attributes."); opViewClass.attr("parse") = classmethod( [](const nb::object &cls, const std::string &sourceStr, @@ -3661,7 +3652,7 @@ void mlir::python::populateIRCore(nb::module_ &m) { return PyOpView::constructDerived(cls, parsed.getObject()); }, nb::arg("cls"), nb::arg("source"), nb::kw_only(), - nb::arg("source_name") = "", nb::arg("context").none() = nb::none(), + nb::arg("source_name") = "", nb::arg("context") = nb::none(), "Parses a specific, generated OpView based on class level attributes"); //---------------------------------------------------------------------------- @@ -3911,7 +3902,7 @@ void mlir::python::populateIRCore(nb::module_ &m) { throw MLIRError("Unable to parse attribute", errors.take()); return attr; }, - nb::arg("asm"), nb::arg("context").none() = nb::none(), + nb::arg("asm"), nb::arg("context") = nb::none(), "Parses an attribute from an assembly form. Raises an MLIRError on " "failure.") .def_prop_ro( @@ -4028,7 +4019,7 @@ void mlir::python::populateIRCore(nb::module_ &m) { throw MLIRError("Unable to parse type", errors.take()); return type; }, - nb::arg("asm"), nb::arg("context").none() = nb::none(), + nb::arg("asm"), nb::arg("context") = nb::none(), kContextParseTypeDocstring) .def_prop_ro( "context", [](PyType &self) { return self.getContext().getObject(); }, diff --git a/mlir/lib/Bindings/Python/IRInterfaces.cpp b/mlir/lib/Bindings/Python/IRInterfaces.cpp index 9e1fedaab5235..6aa057c2a78aa 100644 --- a/mlir/lib/Bindings/Python/IRInterfaces.cpp +++ b/mlir/lib/Bindings/Python/IRInterfaces.cpp @@ -195,7 +195,7 @@ class PyConcreteOpInterface { static void bind(nb::module_ &m) { nb::class_ cls(m, ConcreteIface::pyClassName); cls.def(nb::init(), nb::arg("object"), - nb::arg("context").none() = nb::none(), constructorDoc) + nb::arg("context") = nb::none(), constructorDoc) .def_prop_ro("operation", &PyConcreteOpInterface::getOperationObject, operationDoc) .def_prop_ro("opview", &PyConcreteOpInterface::getOpView, opviewDoc); @@ -303,12 +303,11 @@ class PyInferTypeOpInterface static void bindDerived(ClassTy &cls) { cls.def("inferReturnTypes", &PyInferTypeOpInterface::inferReturnTypes, - nb::arg("operands").none() = nb::none(), - nb::arg("attributes").none() = nb::none(), - nb::arg("properties").none() = nb::none(), - nb::arg("regions").none() = nb::none(), - nb::arg("context").none() = nb::none(), - nb::arg("loc").none() = nb::none(), inferReturnTypesDoc); + nb::arg("operands") = nb::none(), + nb::arg("attributes") = nb::none(), + nb::arg("properties") = nb::none(), nb::arg("regions") = nb::none(), + nb::arg("context") = nb::none(), nb::arg("loc") = nb::none(), + inferReturnTypesDoc); } }; @@ -463,12 +462,10 @@ class PyInferShapedTypeOpInterface static void bindDerived(ClassTy &cls) { cls.def("inferReturnTypeComponents", &PyInferShapedTypeOpInterface::inferReturnTypeComponents, - nb::arg("operands").none() = nb::none(), - nb::arg("attributes").none() = nb::none(), - nb::arg("regions").none() = nb::none(), - nb::arg("properties").none() = nb::none(), - nb::arg("context").none() = nb::none(), - nb::arg("loc").none() = nb::none(), inferReturnTypeComponentsDoc); + nb::arg("operands") = nb::none(), + nb::arg("attributes") = nb::none(), nb::arg("regions") = nb::none(), + nb::arg("properties") = nb::none(), nb::arg("context") = nb::none(), + nb::arg("loc") = nb::none(), inferReturnTypeComponentsDoc); } }; diff --git a/mlir/lib/Bindings/Python/IRTypes.cpp b/mlir/lib/Bindings/Python/IRTypes.cpp index a9b12590188f8..745b9c48c5165 100644 --- a/mlir/lib/Bindings/Python/IRTypes.cpp +++ b/mlir/lib/Bindings/Python/IRTypes.cpp @@ -49,7 +49,7 @@ class PyIntegerType : public PyConcreteType { MlirType t = mlirIntegerTypeGet(context->get(), width); return PyIntegerType(context->getRef(), t); }, - nb::arg("width"), nb::arg("context").none() = nb::none(), + nb::arg("width"), nb::arg("context") = nb::none(), "Create a signless integer type"); c.def_static( "get_signed", @@ -57,7 +57,7 @@ class PyIntegerType : public PyConcreteType { MlirType t = mlirIntegerTypeSignedGet(context->get(), width); return PyIntegerType(context->getRef(), t); }, - nb::arg("width"), nb::arg("context").none() = nb::none(), + nb::arg("width"), nb::arg("context") = nb::none(), "Create a signed integer type"); c.def_static( "get_unsigned", @@ -65,7 +65,7 @@ class PyIntegerType : public PyConcreteType { MlirType t = mlirIntegerTypeUnsignedGet(context->get(), width); return PyIntegerType(context->getRef(), t); }, - nb::arg("width"), nb::arg("context").none() = nb::none(), + nb::arg("width"), nb::arg("context") = nb::none(), "Create an unsigned integer type"); c.def_prop_ro( "width", @@ -108,7 +108,7 @@ class PyIndexType : public PyConcreteType { MlirType t = mlirIndexTypeGet(context->get()); return PyIndexType(context->getRef(), t); }, - nb::arg("context").none() = nb::none(), "Create a index type."); + nb::arg("context") = nb::none(), "Create a index type."); } }; @@ -142,7 +142,7 @@ class PyFloat4E2M1FNType MlirType t = mlirFloat4E2M1FNTypeGet(context->get()); return PyFloat4E2M1FNType(context->getRef(), t); }, - nb::arg("context").none() = nb::none(), "Create a float4_e2m1fn type."); + nb::arg("context") = nb::none(), "Create a float4_e2m1fn type."); } }; @@ -163,7 +163,7 @@ class PyFloat6E2M3FNType MlirType t = mlirFloat6E2M3FNTypeGet(context->get()); return PyFloat6E2M3FNType(context->getRef(), t); }, - nb::arg("context").none() = nb::none(), "Create a float6_e2m3fn type."); + nb::arg("context") = nb::none(), "Create a float6_e2m3fn type."); } }; @@ -184,7 +184,7 @@ class PyFloat6E3M2FNType MlirType t = mlirFloat6E3M2FNTypeGet(context->get()); return PyFloat6E3M2FNType(context->getRef(), t); }, - nb::arg("context").none() = nb::none(), "Create a float6_e3m2fn type."); + nb::arg("context") = nb::none(), "Create a float6_e3m2fn type."); } }; @@ -205,7 +205,7 @@ class PyFloat8E4M3FNType MlirType t = mlirFloat8E4M3FNTypeGet(context->get()); return PyFloat8E4M3FNType(context->getRef(), t); }, - nb::arg("context").none() = nb::none(), "Create a float8_e4m3fn type."); + nb::arg("context") = nb::none(), "Create a float8_e4m3fn type."); } }; @@ -225,7 +225,7 @@ class PyFloat8E5M2Type : public PyConcreteType { MlirType t = mlirFloat8E5M2TypeGet(context->get()); return PyFloat8E5M2Type(context->getRef(), t); }, - nb::arg("context").none() = nb::none(), "Create a float8_e5m2 type."); + nb::arg("context") = nb::none(), "Create a float8_e5m2 type."); } }; @@ -245,7 +245,7 @@ class PyFloat8E4M3Type : public PyConcreteType { MlirType t = mlirFloat8E4M3TypeGet(context->get()); return PyFloat8E4M3Type(context->getRef(), t); }, - nb::arg("context").none() = nb::none(), "Create a float8_e4m3 type."); + nb::arg("context") = nb::none(), "Create a float8_e4m3 type."); } }; @@ -266,8 +266,7 @@ class PyFloat8E4M3FNUZType MlirType t = mlirFloat8E4M3FNUZTypeGet(context->get()); return PyFloat8E4M3FNUZType(context->getRef(), t); }, - nb::arg("context").none() = nb::none(), - "Create a float8_e4m3fnuz type."); + nb::arg("context") = nb::none(), "Create a float8_e4m3fnuz type."); } }; @@ -288,8 +287,7 @@ class PyFloat8E4M3B11FNUZType MlirType t = mlirFloat8E4M3B11FNUZTypeGet(context->get()); return PyFloat8E4M3B11FNUZType(context->getRef(), t); }, - nb::arg("context").none() = nb::none(), - "Create a float8_e4m3b11fnuz type."); + nb::arg("context") = nb::none(), "Create a float8_e4m3b11fnuz type."); } }; @@ -310,8 +308,7 @@ class PyFloat8E5M2FNUZType MlirType t = mlirFloat8E5M2FNUZTypeGet(context->get()); return PyFloat8E5M2FNUZType(context->getRef(), t); }, - nb::arg("context").none() = nb::none(), - "Create a float8_e5m2fnuz type."); + nb::arg("context") = nb::none(), "Create a float8_e5m2fnuz type."); } }; @@ -331,7 +328,7 @@ class PyFloat8E3M4Type : public PyConcreteType { MlirType t = mlirFloat8E3M4TypeGet(context->get()); return PyFloat8E3M4Type(context->getRef(), t); }, - nb::arg("context").none() = nb::none(), "Create a float8_e3m4 type."); + nb::arg("context") = nb::none(), "Create a float8_e3m4 type."); } }; @@ -352,8 +349,7 @@ class PyFloat8E8M0FNUType MlirType t = mlirFloat8E8M0FNUTypeGet(context->get()); return PyFloat8E8M0FNUType(context->getRef(), t); }, - nb::arg("context").none() = nb::none(), - "Create a float8_e8m0fnu type."); + nb::arg("context") = nb::none(), "Create a float8_e8m0fnu type."); } }; @@ -373,7 +369,7 @@ class PyBF16Type : public PyConcreteType { MlirType t = mlirBF16TypeGet(context->get()); return PyBF16Type(context->getRef(), t); }, - nb::arg("context").none() = nb::none(), "Create a bf16 type."); + nb::arg("context") = nb::none(), "Create a bf16 type."); } }; @@ -393,7 +389,7 @@ class PyF16Type : public PyConcreteType { MlirType t = mlirF16TypeGet(context->get()); return PyF16Type(context->getRef(), t); }, - nb::arg("context").none() = nb::none(), "Create a f16 type."); + nb::arg("context") = nb::none(), "Create a f16 type."); } }; @@ -413,7 +409,7 @@ class PyTF32Type : public PyConcreteType { MlirType t = mlirTF32TypeGet(context->get()); return PyTF32Type(context->getRef(), t); }, - nb::arg("context").none() = nb::none(), "Create a tf32 type."); + nb::arg("context") = nb::none(), "Create a tf32 type."); } }; @@ -433,7 +429,7 @@ class PyF32Type : public PyConcreteType { MlirType t = mlirF32TypeGet(context->get()); return PyF32Type(context->getRef(), t); }, - nb::arg("context").none() = nb::none(), "Create a f32 type."); + nb::arg("context") = nb::none(), "Create a f32 type."); } }; @@ -453,7 +449,7 @@ class PyF64Type : public PyConcreteType { MlirType t = mlirF64TypeGet(context->get()); return PyF64Type(context->getRef(), t); }, - nb::arg("context").none() = nb::none(), "Create a f64 type."); + nb::arg("context") = nb::none(), "Create a f64 type."); } }; @@ -473,7 +469,7 @@ class PyNoneType : public PyConcreteType { MlirType t = mlirNoneTypeGet(context->get()); return PyNoneType(context->getRef(), t); }, - nb::arg("context").none() = nb::none(), "Create a none type."); + nb::arg("context") = nb::none(), "Create a none type."); } }; @@ -639,9 +635,9 @@ class PyVectorType : public PyConcreteType { static void bindDerived(ClassTy &c) { c.def_static("get", &PyVectorType::get, nb::arg("shape"), nb::arg("element_type"), nb::kw_only(), - nb::arg("scalable").none() = nb::none(), - nb::arg("scalable_dims").none() = nb::none(), - nb::arg("loc").none() = nb::none(), "Create a vector type") + nb::arg("scalable") = nb::none(), + nb::arg("scalable_dims") = nb::none(), + nb::arg("loc") = nb::none(), "Create a vector type") .def_prop_ro( "scalable", [](MlirType self) { return mlirVectorTypeIsScalable(self); }) @@ -720,8 +716,8 @@ class PyRankedTensorType return PyRankedTensorType(elementType.getContext(), t); }, nb::arg("shape"), nb::arg("element_type"), - nb::arg("encoding").none() = nb::none(), - nb::arg("loc").none() = nb::none(), "Create a ranked tensor type"); + nb::arg("encoding") = nb::none(), nb::arg("loc") = nb::none(), + "Create a ranked tensor type"); c.def_prop_ro("encoding", [](PyRankedTensorType &self) -> std::optional { MlirAttribute encoding = @@ -753,7 +749,7 @@ class PyUnrankedTensorType throw MLIRError("Invalid type", errors.take()); return PyUnrankedTensorType(elementType.getContext(), t); }, - nb::arg("element_type"), nb::arg("loc").none() = nb::none(), + nb::arg("element_type"), nb::arg("loc") = nb::none(), "Create a unranked tensor type"); } }; @@ -785,9 +781,8 @@ class PyMemRefType : public PyConcreteType { return PyMemRefType(elementType.getContext(), t); }, nb::arg("shape"), nb::arg("element_type"), - nb::arg("layout").none() = nb::none(), - nb::arg("memory_space").none() = nb::none(), - nb::arg("loc").none() = nb::none(), "Create a memref type") + nb::arg("layout") = nb::none(), nb::arg("memory_space") = nb::none(), + nb::arg("loc") = nb::none(), "Create a memref type") .def_prop_ro( "layout", [](PyMemRefType &self) -> MlirAttribute { @@ -852,7 +847,7 @@ class PyUnrankedMemRefType return PyUnrankedMemRefType(elementType.getContext(), t); }, nb::arg("element_type"), nb::arg("memory_space").none(), - nb::arg("loc").none() = nb::none(), "Create a unranked memref type") + nb::arg("loc") = nb::none(), "Create a unranked memref type") .def_prop_ro( "memory_space", [](PyUnrankedMemRefType &self) -> std::optional { @@ -882,7 +877,7 @@ class PyTupleType : public PyConcreteType { elements.data()); return PyTupleType(context->getRef(), t); }, - nb::arg("elements"), nb::arg("context").none() = nb::none(), + nb::arg("elements"), nb::arg("context") = nb::none(), "Create a tuple type"); c.def( "get_type", @@ -918,8 +913,7 @@ class PyFunctionType : public PyConcreteType { results.size(), results.data()); return PyFunctionType(context->getRef(), t); }, - nb::arg("inputs"), nb::arg("results"), - nb::arg("context").none() = nb::none(), + nb::arg("inputs"), nb::arg("results"), nb::arg("context") = nb::none(), "Gets a FunctionType from a list of input and result types"); c.def_prop_ro( "inputs", @@ -971,7 +965,7 @@ class PyOpaqueType : public PyConcreteType { return PyOpaqueType(context->getRef(), type); }, nb::arg("dialect_namespace"), nb::arg("buffer"), - nb::arg("context").none() = nb::none(), + nb::arg("context") = nb::none(), "Create an unregistered (opaque) dialect type."); c.def_prop_ro( "dialect_namespace", diff --git a/mlir/lib/Bindings/Python/Pass.cpp b/mlir/lib/Bindings/Python/Pass.cpp index 88e28dca76bb9..72bf8ed8f856f 100644 --- a/mlir/lib/Bindings/Python/Pass.cpp +++ b/mlir/lib/Bindings/Python/Pass.cpp @@ -67,7 +67,7 @@ void mlir::python::populatePassManagerSubmodule(nb::module_ &m) { mlirStringRefCreate(anchorOp.data(), anchorOp.size())); new (&self) PyPassManager(passManager); }, - "anchor_op"_a = nb::str("any"), "context"_a.none() = nb::none(), + "anchor_op"_a = nb::str("any"), "context"_a = nb::none(), "Create a new PassManager for the current (or provided) Context.") .def_prop_ro(MLIR_PYTHON_CAPI_PTR_ATTR, &PyPassManager::getCapsule) .def(MLIR_PYTHON_CAPI_FACTORY_ATTR, &PyPassManager::createFromCapsule) @@ -109,10 +109,10 @@ void mlir::python::populatePassManagerSubmodule(nb::module_ &m) { "print_before_all"_a = false, "print_after_all"_a = true, "print_module_scope"_a = false, "print_after_change"_a = false, "print_after_failure"_a = false, - "large_elements_limit"_a.none() = nb::none(), - "large_resource_limit"_a.none() = nb::none(), - "enable_debug_info"_a = false, "print_generic_op_form"_a = false, - "tree_printing_dir_path"_a.none() = nb::none(), + "large_elements_limit"_a = nb::none(), + "large_resource_limit"_a = nb::none(), "enable_debug_info"_a = false, + "print_generic_op_form"_a = false, + "tree_printing_dir_path"_a = nb::none(), "Enable IR printing, default as mlir-print-ir-after-all.") .def( "enable_verifier", @@ -139,7 +139,7 @@ void mlir::python::populatePassManagerSubmodule(nb::module_ &m) { throw nb::value_error(errorMsg.join().c_str()); return new PyPassManager(passManager); }, - "pipeline"_a, "context"_a.none() = nb::none(), + "pipeline"_a, "context"_a = nb::none(), "Parse a textual pass-pipeline and return a top-level PassManager " "that can be applied on a Module. Throw a ValueError if the pipeline " "can't be parsed")