MLIR 22.0.0git
mlir::python::MLIR_BINDINGS_PYTHON_DOMAIN::PyDiagnosticHandler Class Reference

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

#include "mlir/Bindings/Python/IRCore.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.
nanobind::object contextEnter ()
void contextExit (const nanobind::object &excType, const nanobind::object &excVal, const nanobind::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 407 of file IRCore.h.

Constructor & Destructor Documentation

◆ PyDiagnosticHandler()

mlir::python::MLIR_BINDINGS_PYTHON_DOMAIN::PyDiagnosticHandler::PyDiagnosticHandler ( MlirContext context,
nanobind::object callback )

Definition at line 738 of file IRCore.cpp.

◆ ~PyDiagnosticHandler()

mlir::python::MLIR_BINDINGS_PYTHON_DOMAIN::PyDiagnosticHandler::~PyDiagnosticHandler ( )
default

Member Function Documentation

◆ contextEnter()

nanobind::object mlir::python::MLIR_BINDINGS_PYTHON_DOMAIN::PyDiagnosticHandler::contextEnter ( )
inline

Definition at line 418 of file IRCore.h.

Referenced by mlir::python::MLIR_BINDINGS_PYTHON_DOMAIN::populateIRCore().

◆ contextExit()

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

Definition at line 419 of file IRCore.h.

References detach().

Referenced by mlir::python::MLIR_BINDINGS_PYTHON_DOMAIN::populateIRCore().

◆ detach()

void mlir::python::MLIR_BINDINGS_PYTHON_DOMAIN::PyDiagnosticHandler::detach ( )

Detaches the handler. Does nothing if not attached.

Definition at line 744 of file IRCore.cpp.

Referenced by contextExit(), and mlir::python::MLIR_BINDINGS_PYTHON_DOMAIN::populateIRCore().

◆ getHadError()

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

Definition at line 413 of file IRCore.h.

Referenced by mlir::python::MLIR_BINDINGS_PYTHON_DOMAIN::populateIRCore().

◆ isAttached()

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

Definition at line 412 of file IRCore.h.

Referenced by mlir::python::MLIR_BINDINGS_PYTHON_DOMAIN::populateIRCore().

◆ PyMlirContext

friend class PyMlirContext
friend

Definition at line 430 of file IRCore.h.

References PyMlirContext.

Referenced by PyMlirContext.


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