MLIR  18.0.0git
Public Member Functions | Friends | List of all members
mlir::python::PyDiagnosticHandler Class Reference

Represents a diagnostic handler attached to the context. More...

#include "Bindings/Python/IRModule.h"

Public Member Functions

 PyDiagnosticHandler (MlirContext context, pybind11::object callback)
 
 ~PyDiagnosticHandler ()
 
bool isAttached ()
 
bool getHadError ()
 
void detach ()
 Detaches the handler. Does nothing if not attached. More...
 
pybind11::object contextEnter ()
 
void contextExit (const pybind11::object &excType, const pybind11::object &excVal, const pybind11::object &excTb)
 

Friends

class PyMlirContext
 

Detailed Description

Represents a diagnostic handler attached to the context.

The handler's callback will be invoked with PyDiagnostic instances until the detach() method is called or the context is destroyed. A diagnostic handler can be the subject of a with block, which will detach it when the block exits.

Since diagnostic handlers can call back into Python code which can do unsafe things (i.e. recursively emitting diagnostics, raising exceptions, etc), this is generally not deemed to be a great user-level API. Users should generally use some form of DiagnosticCollector. If the handler raises any exceptions, they will just be emitted to stderr and dropped.

The unique usage of this class means that its lifetime management is different from most other parts of the API. Instances are always created in an attached state and can transition to a detached state by either: a) The context being destroyed and unregistering all handlers. b) An explicit call to detach(). The object may remain live from a Python perspective for an arbitrary time after detachment, but there is nothing the user can do with it (since there is no way to attach an existing handler object).

Definition at line 386 of file IRModule.h.

Constructor & Destructor Documentation

◆ PyDiagnosticHandler()

PyDiagnosticHandler::PyDiagnosticHandler ( MlirContext  context,
pybind11::object  callback 
)

Definition at line 908 of file IRCore.cpp.

◆ ~PyDiagnosticHandler()

PyDiagnosticHandler::~PyDiagnosticHandler ( )
default

Member Function Documentation

◆ contextEnter()

pybind11::object mlir::python::PyDiagnosticHandler::contextEnter ( )
inline

Definition at line 397 of file IRModule.h.

◆ contextExit()

void mlir::python::PyDiagnosticHandler::contextExit ( const pybind11::object &  excType,
const pybind11::object &  excVal,
const pybind11::object &  excTb 
)
inline

Definition at line 398 of file IRModule.h.

References detach().

◆ detach()

void PyDiagnosticHandler::detach ( )

Detaches the handler. Does nothing if not attached.

Definition at line 914 of file IRCore.cpp.

References mlirContextDetachDiagnosticHandler().

Referenced by contextExit().

◆ getHadError()

bool mlir::python::PyDiagnosticHandler::getHadError ( )
inline

Definition at line 392 of file IRModule.h.

◆ isAttached()

bool mlir::python::PyDiagnosticHandler::isAttached ( )
inline

Definition at line 391 of file IRModule.h.

Friends And Related Function Documentation

◆ PyMlirContext

friend class PyMlirContext
friend

Definition at line 409 of file IRModule.h.


The documentation for this class was generated from the following files: