[Mlir-commits] [mlir] [MLIR][Python] Add a DSL for defining dialects in Python bindings (PR #169045)
Rolf Morel
llvmlistbot at llvm.org
Thu Jan 22 08:29:01 PST 2026
================
@@ -0,0 +1,422 @@
+# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+# See https://llvm.org/LICENSE.txt for license information.
+# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+
+from typing import (
+ Dict,
+ List,
+ Union,
+ Tuple,
+ Any,
+ Optional,
+ Callable,
+ TypeVar,
+ get_origin,
+ get_args,
+)
+from collections.abc import Sequence
+from dataclasses import dataclass
+from inspect import Parameter, Signature
+from types import UnionType
+from . import irdl
+from ._ods_common import _cext, segmented_accessor
+from .irdl import Variadicity
+from ..passmanager import PassManager
+
+ir = _cext.ir
+
+__all__ = [
+ "Dialect",
+ "Operand",
+ "Result",
+]
+
+Operand = ir.Value
+Result = ir.OpResult
+
+
+class ConstraintLoweringContext:
+ def __init__(self):
+ self._cache: Dict[str, ir.Value] = {}
+
+ def lower(self, type_) -> ir.Value:
+ if type(type_) is TypeVar:
+ if type_.__name__ in self._cache:
+ return self._cache[type_.__name__]
+ v = self._lower(type_.__bound__ or Any)
+ self._cache[type_.__name__] = v
----------------
rolfmorel wrote:
Is this safe? In particular, it is really the case that just because two `TypeVar`s have the same name we expect them to map to the same constraint?
(How about using `id(type_)` instead for caching?)
https://github.com/llvm/llvm-project/pull/169045
More information about the Mlir-commits
mailing list