[MLIR] [Python] Add a method to clear live operations map
authorJohn Demme <john.demme@microsoft.com>
Tue, 19 Apr 2022 22:03:15 +0000 (15:03 -0700)
committerJohn Demme <john.demme@microsoft.com>
Tue, 19 Apr 2022 22:14:09 +0000 (15:14 -0700)
commit6b0bed7ea563624622c3c1fb1a3c90cd32c78db6
tree8e2c8d2896fb67bc3e9b30d940df7195cba9e902
parent6db0afb44e13cf5f3d3261387079b32358966a61
[MLIR] [Python] Add a method to clear live operations map

Introduce a method on PyMlirContext (and plumb it through to Python) to
invalidate all of the operations in the live operations map and clear
it. Since Python has no notion of private data, an end-developer could
reach into some 3rd party API which uses the MLIR Python API (that is
behaving correctly with regard to holding references) and grab a
reference to an MLIR Python Operation, preventing it from being
deconstructed out of the live operations map. This allows the API
developer to clear the map when it calls C++ code which could delete
operations, protecting itself from its users.

Reviewed By: ftynse

Differential Revision: https://reviews.llvm.org/D123895
mlir/lib/Bindings/Python/IRCore.cpp
mlir/lib/Bindings/Python/IRModule.h
mlir/test/python/ir/module.py