Skip to content

Commit 42b4b08

Browse files
authored
Updates from master (#799)
* `run_smir` correction for `seed=0` * offset deref for single elements
2 parents 9008307 + 4b3f481 commit 42b4b08

23 files changed

+35549
-35
lines changed

kmir/src/kmir/kdist/mir-semantics/kmir.md

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,16 +167,29 @@ will be `129`.
167167
168168
rule <k> #selectBlock(switchTargets(.Branches, BBIDX), _) => #execBlockIdx(BBIDX) ... </k>
169169
170-
rule <k> #selectBlock(switchTargets(branch(MI, BBIDX) _, _), V) => #execBlockIdx(BBIDX) ... </k> requires #switchMatch(MI, V) [preserves-definedness]
170+
rule <k> #selectBlock(switchTargets(branch(MI, BBIDX) _, _), V) => #execBlockIdx(BBIDX) ... </k>
171+
requires #switchMatch(MI, V)
172+
andBool #switchCanUse(V)
173+
[preserves-definedness]
171174
172-
rule <k> #selectBlock(switchTargets(branch(MI, _) BRANCHES => BRANCHES, _), V) ... </k> requires notBool #switchMatch(MI, V) [preserves-definedness]
175+
rule <k> #selectBlock(switchTargets(branch(MI, _) BRANCHES => BRANCHES, _), V) ... </k>
176+
requires notBool #switchMatch(MI, V)
177+
andBool #switchCanUse(V)
178+
[preserves-definedness]
173179
174180
syntax Bool ::= #switchMatch ( MIRInt , Value ) [function]
175181
176182
rule #switchMatch(0, BoolVal(B) ) => notBool B
177183
rule #switchMatch(1, BoolVal(B) ) => B
178184
rule #switchMatch(I, Integer(I2, WIDTH, _)) => I ==Int truncate(I2, WIDTH, Unsigned) requires 0 <Int WIDTH
179185
rule #switchMatch(I, Integer(I2, 0 , _)) => I ==Int I2
186+
187+
syntax Bool ::= #switchCanUse ( Value ) [function, total]
188+
// ------------------------------------------------------
189+
rule #switchCanUse(Integer(_, _, _)) => true
190+
rule #switchCanUse( BoolVal( _ ) ) => true
191+
rule #switchCanUse( thunk( _ ) ) => true
192+
rule #switchCanUse( _OTHER ) => false [owise]
180193
```
181194

182195
`Return` simply returns from a function call, using the information

kmir/src/kmir/kdist/mir-semantics/rt/data.md

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -613,11 +613,19 @@ An attempt to read more elements than the length of the accessed array is undefi
613613
// helper rewrite to implement truncating slices to required size
614614
syntax KItem ::= #derefTruncate ( MetadataSize , ProjectionElems )
615615
// ----------------------------------------------------------------------------------------
616-
// no metadata, no change to the value
617-
rule <k> #traverseProjection( DEST, VAL, .ProjectionElems, CTXTS) ~> #derefTruncate(noMetadataSize, PROJS)
616+
// values other than `Range` do not have metadata anyway, they are passed along unchanged
617+
rule <k> #traverseProjection( DEST, VAL , .ProjectionElems, CTXTS) ~> #derefTruncate(noMetadataSize, PROJS)
618618
=> #traverseProjection(DEST, VAL, PROJS, CTXTS)
619619
...
620620
</k>
621+
requires notBool isRange(VAL)
622+
623+
// TODO move these to value.md
624+
syntax Bool ::= isRange ( Value ) [function, total]
625+
// ------------------------------------------------
626+
rule isRange(Range(_)) => true
627+
rule isRange( _OTHER ) => false [owise]
628+
621629
// staticSize metadata requires an array of suitable length and truncates it
622630
rule <k> #traverseProjection( DEST, Range(ELEMS), .ProjectionElems, CTXTS) ~> #derefTruncate(staticSize(SIZE), PROJS)
623631
=> #traverseProjection(DEST, Range(range(ELEMS, 0, size(ELEMS) -Int SIZE)), PROJS, CTXTS)
@@ -630,6 +638,12 @@ An attempt to read more elements than the length of the accessed array is undefi
630638
...
631639
</k>
632640
requires 0 <=Int SIZE andBool SIZE <=Int size(ELEMS) [preserves-definedness] // range parameters checked
641+
// If an array was projected to but no metadata is available, use the head element
642+
rule <k> #traverseProjection( DEST, Range(ListItem(VAL) _:List), .ProjectionElems, CTXTS) ~> #derefTruncate(noMetadataSize, PROJS)
643+
=> #traverseProjection(DEST, VAL, PROJS, CTXTS)
644+
...
645+
</k>
646+
[preserves-definedness]
633647
634648
// Ref, 0 < OFFSET, 0 < PTR_OFFSET, ToStack
635649
rule <k> #traverseProjection(

kmir/src/kmir/kmir.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ def run_smir(
154154
seed: int | None = None,
155155
) -> Pattern:
156156
smir_info = smir_info.reduce_to(start_symbol)
157-
mode = RandomMode(seed) if seed else ConcreteMode()
157+
mode = RandomMode(seed) if seed is not None else ConcreteMode()
158158
init_config, _ = make_call_config(
159159
self.definition,
160160
smir_info=smir_info,
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
fn main() {
2+
let arr = [11, 22, 33];
3+
let mid_ref = unsafe { arr.get_unchecked(1) };
4+
let mid = *mid_ref;
5+
assert!(mid == 22);
6+
let last = unsafe { arr.get_unchecked(2) };
7+
assert!(*last == 33);
8+
}

0 commit comments

Comments
 (0)