| 1 |
from mypyc.ir.rtypes import ( |
| 2 |
RArray, |
| 3 |
RInstance, |
| 4 |
RPrimitive, |
| 5 |
RStruct, |
| 6 |
RTuple, |
| 7 |
RType, |
| 8 |
RTypeVar, |
| 9 |
RUnion, |
| 10 |
RVec, |
| 11 |
RVoid, |
| 12 |
) |
| 13 |
|
| 14 |
|
| 15 |
def expand_rtype(typ: RType, type_args: list[RType]) -> RType: |
| 16 |
if isinstance(typ, (RPrimitive, RInstance, RVoid)): |
| 17 |
# Atomic types can't contain type variables |
| 18 |
return typ |
| 19 |
elif isinstance(typ, RTypeVar): |
| 20 |
return type_args[typ.id] |
| 21 |
elif isinstance(typ, RVec): |
| 22 |
return RVec(expand_rtype(typ.item_type, type_args)) |
| 23 |
elif isinstance(typ, RUnion): |
| 24 |
return RUnion([expand_rtype(item, type_args) for item in typ.items]) |
| 25 |
elif isinstance(typ, RTuple): |
| 26 |
return RTuple([expand_rtype(item, type_args) for item in typ.types]) |
| 27 |
elif isinstance(typ, RStruct): |
| 28 |
assert False, "Generic RStruct type not supported" |
| 29 |
elif isinstance(typ, RArray): |
| 30 |
assert False, "Generic RArray type not supported" |
| 31 |
else: |
| 32 |
assert False, r"Unexpected type {typ!r}" |