MLIR  17.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)


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 375 of file IRModule.h.

Constructor & Destructor Documentation

◆ PyDiagnosticHandler()

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

Definition at line 858 of file IRCore.cpp.

◆ ~PyDiagnosticHandler()

PyDiagnosticHandler::~PyDiagnosticHandler ( )

Member Function Documentation

◆ contextEnter()

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

Definition at line 386 of file IRModule.h.

◆ contextExit()

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

Definition at line 387 of file IRModule.h.

References detach().

◆ detach()

void PyDiagnosticHandler::detach ( )

Detaches the handler. Does nothing if not attached.

Definition at line 864 of file IRCore.cpp.

References mlirContextDetachDiagnosticHandler().

Referenced by contextExit().

◆ getHadError()

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

Definition at line 381 of file IRModule.h.

◆ isAttached()

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

Definition at line 380 of file IRModule.h.

Friends And Related Function Documentation

◆ PyMlirContext

friend class PyMlirContext

Definition at line 398 of file IRModule.h.

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