44from collections import defaultdict
55from contextlib import contextmanager
66from dataclasses import dataclass
7- from typing import Any , Callable , Sequence , cast
7+ from typing import Any , Callable , Sequence , cast , Coroutine , TYPE_CHECKING
8+
9+ # Type aliases for MLIR types - backends will use their specific ir modules
10+ IRContext = Any
11+ IRType = Any
12+ IRLocation = Any
13+ IRInsertionPoint = Any
814
915
1016from sealir import ase
@@ -70,8 +76,8 @@ class BackendInterface(ABC):
7076 """
7177
7278 # Class attributes for MLIR context management
73- Location : type # Set to ir.Location by implementations
74- InsertionPoint : type # Set to ir.InsertionPoint by implementations
79+ Location : Any # Set to ir.Location by implementations
80+ InsertionPoint : Any # Set to ir.InsertionPoint by implementations
7581
7682 @classmethod
7783 @abstractmethod
@@ -87,47 +93,47 @@ def run_passes(self, module: Any, transforms: Any) -> Any: ...
8793 # Type Constants - Properties for clean access pattern
8894 @property
8995 @abstractmethod
90- def context (self ) -> ir . Context :
96+ def context (self ) -> "IRContext" :
9197 """MLIR context for creating types and operations."""
9298
9399 @property
94100 @abstractmethod
95- def i32 (self ) -> ir . Type :
101+ def i32 (self ) -> "IRType" :
96102 """32-bit integer type."""
97103
98104 @property
99105 @abstractmethod
100- def i64 (self ) -> ir . Type :
106+ def i64 (self ) -> "IRType" :
101107 """64-bit integer type."""
102108
103109 @property
104110 @abstractmethod
105- def f64 (self ) -> ir . Type :
111+ def f64 (self ) -> "IRType" :
106112 """64-bit float type."""
107113
108114 @property
109115 @abstractmethod
110- def boolean (self ) -> ir . Type :
116+ def boolean (self ) -> "IRType" :
111117 """Boolean (1-bit integer) type."""
112118
113119 @property
114120 @abstractmethod
115- def none_type (self ) -> ir . Type :
121+ def none_type (self ) -> "IRType" :
116122 """None/void type representation."""
117123
118124 @property
119125 @abstractmethod
120- def io_type (self ) -> ir . Type :
126+ def io_type (self ) -> "IRType" :
121127 """IO token type for sequencing."""
122128
123129 @property
124130 @abstractmethod
125- def llvm_ptr (self ) -> ir . Type :
131+ def llvm_ptr (self ) -> "IRType" :
126132 """LLVM pointer type for memory operations."""
127133
128134 # Core Methods
129135 @abstractmethod
130- def lower_type (self , ty ) -> tuple [ir . Type , ...]:
136+ def lower_type (self , ty ) -> tuple ["IRType" , ...]:
131137 """Convert SealIR types to backend IR types.
132138
133139 Returns a tuple of MLIR types. For single types, returns (type,).
@@ -136,7 +142,7 @@ def lower_type(self, ty) -> tuple[ir.Type, ...]:
136142 """
137143
138144 @abstractmethod
139- def get_ll_type (self , expr , mdmap ) -> ir . Type | None :
145+ def get_ll_type (self , expr , mdmap ) -> "IRType | None" :
140146 """Get backend type for expression with metadata."""
141147
142148 @abstractmethod
@@ -280,7 +286,7 @@ def lower(self, root: rg.Func) -> Any:
280286 """
281287 context = self .be .context
282288 self .loc = loc = self .be .Location .name (
283- f"{ self } .lower()" , context = context
289+ f"{ self . __class__ . __name__ } .lower()" , context = context
284290 )
285291 module = self .module
286292
0 commit comments