* Fixes a rather egregious bug with respect to the inability to return arbitrary objects from py::init (was causing aliasing of multiple py::object -> native instance). * Makes Modules and Operations referencable types so that they can be reliably depended on. * Uniques python operation instances within a context. Opens the door for further accounting. * Next I will retrofit region and block to be dependent on the operation, and I will attempt to model the API to avoid detached regions/blocks, which will simplify things a lot (in that world, only operations can be detached). * Added quite a bit of test coverage to check for leaks and reference issues. * Supercedes: https://reviews.llvm.org/D87213 Differential Revision: https://reviews.llvm.org/D87958
40 lines
815 B
Python
40 lines
815 B
Python
# RUN: %PYTHON %s | FileCheck %s
|
|
|
|
import gc
|
|
import mlir
|
|
|
|
def run(f):
|
|
print("\nTEST:", f.__name__)
|
|
f()
|
|
gc.collect()
|
|
assert mlir.ir.Context._get_live_count() == 0
|
|
|
|
|
|
# CHECK-LABEL: TEST: testUnknown
|
|
def testUnknown():
|
|
ctx = mlir.ir.Context()
|
|
loc = ctx.get_unknown_location()
|
|
ctx = None
|
|
gc.collect()
|
|
# CHECK: unknown str: loc(unknown)
|
|
print("unknown str:", str(loc))
|
|
# CHECK: unknown repr: loc(unknown)
|
|
print("unknown repr:", repr(loc))
|
|
|
|
run(testUnknown)
|
|
|
|
|
|
# CHECK-LABEL: TEST: testFileLineCol
|
|
def testFileLineCol():
|
|
ctx = mlir.ir.Context()
|
|
loc = ctx.get_file_location("foo.txt", 123, 56)
|
|
ctx = None
|
|
gc.collect()
|
|
# CHECK: file str: loc("foo.txt":123:56)
|
|
print("file str:", str(loc))
|
|
# CHECK: file repr: loc("foo.txt":123:56)
|
|
print("file repr:", repr(loc))
|
|
|
|
run(testFileLineCol)
|
|
|