@@ -64,7 +64,7 @@ static nanobind::object mlirApiObjectToCapsule(nanobind::handle apiObject) {
6464// / Casts object <-> MlirAffineMap.
6565template <>
6666struct type_caster <MlirAffineMap> {
67- NB_TYPE_CASTER (MlirAffineMap, const_name(" MlirAffineMap" ));
67+ NB_TYPE_CASTER (MlirAffineMap, const_name(" MlirAffineMap" ))
6868 bool from_python (handle src, uint8_t flags, cleanup_list *cleanup) {
6969 nanobind::object capsule = mlirApiObjectToCapsule (src);
7070 value = mlirPythonCapsuleToAffineMap (capsule.ptr ());
@@ -87,7 +87,7 @@ struct type_caster<MlirAffineMap> {
8787// / Casts object <-> MlirAttribute.
8888template <>
8989struct type_caster <MlirAttribute> {
90- NB_TYPE_CASTER (MlirAttribute, const_name(" MlirAttribute" ));
90+ NB_TYPE_CASTER (MlirAttribute, const_name(" MlirAttribute" ))
9191 bool from_python (handle src, uint8_t flags, cleanup_list *cleanup) {
9292 nanobind::object capsule = mlirApiObjectToCapsule (src);
9393 value = mlirPythonCapsuleToAttribute (capsule.ptr ());
@@ -108,7 +108,7 @@ struct type_caster<MlirAttribute> {
108108// / Casts object -> MlirBlock.
109109template <>
110110struct type_caster <MlirBlock> {
111- NB_TYPE_CASTER (MlirBlock, const_name(" MlirBlock" ));
111+ NB_TYPE_CASTER (MlirBlock, const_name(" MlirBlock" ))
112112 bool from_python (handle src, uint8_t flags, cleanup_list *cleanup) {
113113 nanobind::object capsule = mlirApiObjectToCapsule (src);
114114 value = mlirPythonCapsuleToBlock (capsule.ptr ());
@@ -119,7 +119,7 @@ struct type_caster<MlirBlock> {
119119// / Casts object -> MlirContext.
120120template <>
121121struct type_caster <MlirContext> {
122- NB_TYPE_CASTER (MlirContext, const_name(" MlirContext" ));
122+ NB_TYPE_CASTER (MlirContext, const_name(" MlirContext" ))
123123 bool from_python (handle src, uint8_t flags, cleanup_list *cleanup) {
124124 if (src.is_none ()) {
125125 // Gets the current thread-bound context.
@@ -139,7 +139,7 @@ struct type_caster<MlirContext> {
139139// / Casts object <-> MlirDialectRegistry.
140140template <>
141141struct type_caster <MlirDialectRegistry> {
142- NB_TYPE_CASTER (MlirDialectRegistry, const_name(" MlirDialectRegistry" ));
142+ NB_TYPE_CASTER (MlirDialectRegistry, const_name(" MlirDialectRegistry" ))
143143 bool from_python (handle src, uint8_t flags, cleanup_list *cleanup) {
144144 nanobind::object capsule = mlirApiObjectToCapsule (src);
145145 value = mlirPythonCapsuleToDialectRegistry (capsule.ptr ());
@@ -159,7 +159,7 @@ struct type_caster<MlirDialectRegistry> {
159159// / Casts object <-> MlirLocation.
160160template <>
161161struct type_caster <MlirLocation> {
162- NB_TYPE_CASTER (MlirLocation, const_name(" MlirLocation" ));
162+ NB_TYPE_CASTER (MlirLocation, const_name(" MlirLocation" ))
163163 bool from_python (handle src, uint8_t flags, cleanup_list *cleanup) {
164164 if (src.is_none ()) {
165165 // Gets the current thread-bound context.
@@ -185,7 +185,7 @@ struct type_caster<MlirLocation> {
185185// / Casts object <-> MlirModule.
186186template <>
187187struct type_caster <MlirModule> {
188- NB_TYPE_CASTER (MlirModule, const_name(" MlirModule" ));
188+ NB_TYPE_CASTER (MlirModule, const_name(" MlirModule" ))
189189 bool from_python (handle src, uint8_t flags, cleanup_list *cleanup) {
190190 nanobind::object capsule = mlirApiObjectToCapsule (src);
191191 value = mlirPythonCapsuleToModule (capsule.ptr ());
@@ -206,7 +206,7 @@ struct type_caster<MlirModule> {
206206template <>
207207struct type_caster <MlirFrozenRewritePatternSet> {
208208 NB_TYPE_CASTER (MlirFrozenRewritePatternSet,
209- const_name (" MlirFrozenRewritePatternSet" ));
209+ const_name (" MlirFrozenRewritePatternSet" ))
210210 bool from_python(handle src, uint8_t flags, cleanup_list *cleanup) {
211211 nanobind::object capsule = mlirApiObjectToCapsule (src);
212212 value = mlirPythonCapsuleToFrozenRewritePatternSet (capsule.ptr ());
@@ -225,7 +225,7 @@ struct type_caster<MlirFrozenRewritePatternSet> {
225225// / Casts object <-> MlirOperation.
226226template <>
227227struct type_caster <MlirOperation> {
228- NB_TYPE_CASTER (MlirOperation, const_name(" MlirOperation" ));
228+ NB_TYPE_CASTER (MlirOperation, const_name(" MlirOperation" ))
229229 bool from_python (handle src, uint8_t flags, cleanup_list *cleanup) {
230230 nanobind::object capsule = mlirApiObjectToCapsule (src);
231231 value = mlirPythonCapsuleToOperation (capsule.ptr ());
@@ -247,7 +247,7 @@ struct type_caster<MlirOperation> {
247247// / Casts object <-> MlirValue.
248248template <>
249249struct type_caster <MlirValue> {
250- NB_TYPE_CASTER (MlirValue, const_name(" MlirValue" ));
250+ NB_TYPE_CASTER (MlirValue, const_name(" MlirValue" ))
251251 bool from_python (handle src, uint8_t flags, cleanup_list *cleanup) {
252252 nanobind::object capsule = mlirApiObjectToCapsule (src);
253253 value = mlirPythonCapsuleToValue (capsule.ptr ());
@@ -270,7 +270,7 @@ struct type_caster<MlirValue> {
270270// / Casts object -> MlirPassManager.
271271template <>
272272struct type_caster <MlirPassManager> {
273- NB_TYPE_CASTER (MlirPassManager, const_name(" MlirPassManager" ));
273+ NB_TYPE_CASTER (MlirPassManager, const_name(" MlirPassManager" ))
274274 bool from_python (handle src, uint8_t flags, cleanup_list *cleanup) {
275275 nanobind::object capsule = mlirApiObjectToCapsule (src);
276276 value = mlirPythonCapsuleToPassManager (capsule.ptr ());
@@ -281,7 +281,7 @@ struct type_caster<MlirPassManager> {
281281// / Casts object <-> MlirTypeID.
282282template <>
283283struct type_caster <MlirTypeID> {
284- NB_TYPE_CASTER (MlirTypeID, const_name(" MlirTypeID" ));
284+ NB_TYPE_CASTER (MlirTypeID, const_name(" MlirTypeID" ))
285285 bool from_python (handle src, uint8_t flags, cleanup_list *cleanup) {
286286 nanobind::object capsule = mlirApiObjectToCapsule (src);
287287 value = mlirPythonCapsuleToTypeID (capsule.ptr ());
@@ -303,7 +303,7 @@ struct type_caster<MlirTypeID> {
303303// / Casts object <-> MlirType.
304304template <>
305305struct type_caster <MlirType> {
306- NB_TYPE_CASTER (MlirType, const_name(" MlirType" ));
306+ NB_TYPE_CASTER (MlirType, const_name(" MlirType" ))
307307 bool from_python (handle src, uint8_t flags, cleanup_list *cleanup) {
308308 nanobind::object capsule = mlirApiObjectToCapsule (src);
309309 value = mlirPythonCapsuleToType (capsule.ptr ());
@@ -631,40 +631,6 @@ class mlir_value_subclass : public pure_subclass {
631631
632632} // namespace nanobind_adaptors
633633
634- // / RAII scope intercepting all diagnostics into a string. The message must be
635- // / checked before this goes out of scope.
636- class CollectDiagnosticsToStringScope {
637- public:
638- explicit CollectDiagnosticsToStringScope (MlirContext ctx) : context(ctx) {
639- handlerID = mlirContextAttachDiagnosticHandler (ctx, &handler, &errorMessage,
640- /* deleteUserData=*/ nullptr );
641- }
642- ~CollectDiagnosticsToStringScope () {
643- assert (errorMessage.empty () && " unchecked error message" );
644- mlirContextDetachDiagnosticHandler (context, handlerID);
645- }
646-
647- [[nodiscard]] std::string takeMessage () { return std::move (errorMessage); }
648-
649- private:
650- static MlirLogicalResult handler (MlirDiagnostic diag, void *data) {
651- auto printer = +[](MlirStringRef message, void *data) {
652- *static_cast <std::string *>(data) +=
653- llvm::StringRef (message.data , message.length );
654- };
655- MlirLocation loc = mlirDiagnosticGetLocation (diag);
656- *static_cast <std::string *>(data) += " at " ;
657- mlirLocationPrint (loc, printer, data);
658- *static_cast <std::string *>(data) += " : " ;
659- mlirDiagnosticPrint (diag, printer, data);
660- return mlirLogicalResultSuccess ();
661- }
662-
663- MlirContext context;
664- MlirDiagnosticHandlerID handlerID;
665- std::string errorMessage = " " ;
666- };
667-
668634} // namespace python
669635} // namespace mlir
670636
0 commit comments