MLIR
20.0.0git
|
Represents a diagnostic handler attached to the context. More...
#include "Bindings/Python/IRModule.h"
Public Member Functions | |
PyDiagnosticHandler (MlirContext context, nanobind::object callback) | |
~PyDiagnosticHandler () | |
bool | isAttached () |
bool | getHadError () |
void | detach () |
Detaches the handler. Does nothing if not attached. More... | |
nanobind::object | contextEnter () |
void | contextExit (const nanobind::object &excType, const nanobind::object &excVal, const nanobind::object &excTb) |
Friends | |
class | PyMlirContext |
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 398 of file IRModule.h.
PyDiagnosticHandler::PyDiagnosticHandler | ( | MlirContext | context, |
nanobind::object | callback | ||
) |
Definition at line 950 of file IRCore.cpp.
|
default |
|
inline |
Definition at line 409 of file IRModule.h.
|
inline |
Definition at line 410 of file IRModule.h.
References detach().
void PyDiagnosticHandler::detach | ( | ) |
Detaches the handler. Does nothing if not attached.
Definition at line 956 of file IRCore.cpp.
References mlirContextDetachDiagnosticHandler().
Referenced by contextExit().
|
inline |
Definition at line 404 of file IRModule.h.
|
inline |
Definition at line 403 of file IRModule.h.
|
friend |
Definition at line 421 of file IRModule.h.