Skip to content

Commit 89291c4

Browse files
committed
fix(smir): resolve Subslice projection to correct array type
_projected_ty() returned the original array type for Subslice projections, so call_edges missed drop glue for subslice drops like Drop(local.Subslice(1,3,false)) and reduce_to() pruned the required drop_in_place::<[T; M]> function. Compute the result array length from the Subslice parameters (to - from for from_end=false, len - from - to for from_end=true) and search the type table for a matching ArrayType with the same element type and length.
1 parent 3f76113 commit 89291c4

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

kmir/src/kmir/smir.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,30 @@ def _projected_ty(self, ty: Ty, projection: object) -> Ty | None:
353353
return Ty(type_info.element_type)
354354

355355
if 'Subslice' in projection and isinstance(type_info, ArrayT):
356+
sub = projection['Subslice']
357+
from_idx = sub.get('from', 0)
358+
to_idx = sub.get('to', 0)
359+
from_end = sub.get('from_end', False)
360+
361+
if from_end:
362+
# [from .. len-to]: result length depends on runtime size
363+
if type_info.length is not None:
364+
result_len = type_info.length - from_idx - to_idx
365+
else:
366+
result_len = None
367+
else:
368+
# [from .. to]: result length = to - from
369+
result_len = to_idx - from_idx
370+
371+
# Search for an ArrayType with matching element type and length
372+
if result_len is not None:
373+
for candidate_ty, candidate_info in self.types.items():
374+
if (
375+
isinstance(candidate_info, ArrayT)
376+
and candidate_info.element_type == type_info.element_type
377+
and candidate_info.length == result_len
378+
):
379+
return candidate_ty
356380
return ty
357381

358382
if 'OpaqueCast' in projection or 'Subtype' in projection:

0 commit comments

Comments
 (0)