Marker for explicit LetStmt. Created by T.let or T.let[type]. Usage in TVMScript: x: T.let[T.int32] = expr # LetStmt with explicit type x: T.let = expr # LetStmt with auto-typed RHS
| 1475 | |
| 1476 | |
| 1477 | class LetAnnotation: |
| 1478 | """Marker for explicit LetStmt. Created by T.let or T.let[type]. |
| 1479 | Usage in TVMScript: |
| 1480 | x: T.let[T.int32] = expr # LetStmt with explicit type |
| 1481 | x: T.let = expr # LetStmt with auto-typed RHS |
| 1482 | """ |
| 1483 | |
| 1484 | def __init__(self, type_spec=None): |
| 1485 | self.type_spec = type_spec |
| 1486 | |
| 1487 | def __class_getitem__(cls, item): |
| 1488 | return LetAnnotation(item) |
| 1489 | |
| 1490 | def __getitem__(self, item): |
| 1491 | return LetAnnotation(item) |
| 1492 | |
| 1493 | def as_var(self, rhs_dtype=None): |
| 1494 | """Resolve to a tir.Var.""" |
| 1495 | if self.type_spec is not None: |
| 1496 | if isinstance(self.type_spec, Var): |
| 1497 | return self.type_spec # Already a Var (e.g. T.handle(...)) |
| 1498 | elif callable(self.type_spec): |
| 1499 | return self.type_spec() # e.g. T.int32() -> Var |
| 1500 | elif isinstance(self.type_spec, Type): |
| 1501 | return Var("", self.type_spec) |
| 1502 | else: |
| 1503 | raise TypeError(f"Invalid type for T.let: {self.type_spec}") |
| 1504 | elif rhs_dtype is not None: |
| 1505 | return Var("", ir.PrimType(rhs_dtype)) |
| 1506 | else: |
| 1507 | raise TypeError("T.let requires either a type or an RHS value") |
| 1508 | |
| 1509 | |
| 1510 | let = LetAnnotation() # Singleton for T.let (no subscript) |
no outgoing calls
no test coverage detected
searching dependent graphs…