diff --git a/kmir/src/kmir/kdist/mir-semantics/rt/data.md b/kmir/src/kmir/kdist/mir-semantics/rt/data.md index 5839521b4..5dbd3fb09 100644 --- a/kmir/src/kmir/kdist/mir-semantics/rt/data.md +++ b/kmir/src/kmir/kdist/mir-semantics/rt/data.md @@ -492,6 +492,20 @@ The situation typically arises when the stored value is a pointer (`NonNull`) bu ) => #traverseProjection(DEST, Aggregate(variantIdx(0), ListItem(VALUE)), PROJS, CtxWrapStruct CTXTS) ... [preserves-definedness, priority(100)] + + rule #traverseProjection( + DEST, + Aggregate(variantIdx(0), ListItem(Range(ELEMS))), + projectionElemConstantIndex(I, MIN_LENGTH, FROM_END) PROJS, + CTXTS + ) + => #traverseProjection( + DEST, + Range(ELEMS), + projectionElemConstantIndex(I, MIN_LENGTH, FROM_END) PROJS, + CTXTS + ) ... + [preserves-definedness, priority(100)] ``` A somewhat dual case to this rule can occur when a pointer into an array of data elements has been offset and is then dereferenced. diff --git a/kmir/src/kmir/kdist/mir-semantics/rt/types.md b/kmir/src/kmir/kdist/mir-semantics/rt/types.md index aaf854c13..cd9557c27 100644 --- a/kmir/src/kmir/kdist/mir-semantics/rt/types.md +++ b/kmir/src/kmir/kdist/mir-semantics/rt/types.md @@ -113,14 +113,11 @@ the source should be wrapped rather than unwrapped (e.g., `*const [u8;2] → *co ) requires #zeroFieldOffset(LAYOUT) - rule #pointeeProjection(SRC:TypeInfo, typeInfoStructType(_NAME, _ADTDEF, FIELD .Tys, LAYOUT)) - => maybeConcatProj( - projectionElemWrapStruct, - #pointeeProjection(SRC, lookupTy(FIELD)) - ) + rule #pointeeProjection(SRC:TypeInfo, TGT) + => #pointeeProjectionTarget(SRC, TGT) requires #isArrayType(SRC) - andBool #zeroFieldOffset(LAYOUT) - andBool lookupTy(FIELD) ==K SRC + andBool #wholeArrayTargetCompatible(SRC, TGT) + andBool SRC =/=K TGT [priority(42)] rule #pointeeProjection(typeInfoArrayType(TY1, _), TY2) @@ -189,6 +186,20 @@ the source-first strategy. rule #layoutOffsets(someLayoutShape(layoutShape(fieldsShapeArbitrary(mk(OFFSETS)), _, _, _, _))) => OFFSETS rule #layoutOffsets(noLayoutShape) => .MachineSizes rule #layoutOffsets(_) => .MachineSizes [owise] + + syntax Bool ::= #wholeArrayTargetCompatible ( TypeInfo , TypeInfo ) [function, total] + // ---------------------------------------------------------------------------- + rule #wholeArrayTargetCompatible(SRC, SRC) => true + + rule #wholeArrayTargetCompatible(SRC, typeInfoStructType(_, _, FIELD .Tys, LAYOUT)) + => #wholeArrayTargetCompatible(SRC, lookupTy(FIELD)) + requires #zeroFieldOffset(LAYOUT) + + rule #wholeArrayTargetCompatible(SRC, typeInfoArrayType(ELEM_TY, someTyConst(tyConst(KIND, _)))) + => #wholeArrayTargetCompatible(SRC, lookupTy(ELEM_TY)) + requires readTyConstInt(KIND) ==Int 1 + + rule #wholeArrayTargetCompatible(_, _) => false [owise] ``` --------------------------------------------------