Skip to content

Commit 6be5824

Browse files
authored
Hotfix discriminant refactor 2 (#930)
* reverts the rewrite counts in the golden files (by removing the rewrite symbol introduced in #923 * new helper functions to ensure definedness of discriminant/variantIdx lookup * Fixes p-token proofs (while still passing sync_native in SPL token)
1 parent 7bc6312 commit 6be5824

9 files changed

Lines changed: 29 additions & 19 deletions

File tree

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,14 @@ For symbolic enum values, the variant index remains unevaluated but the original
8686
#And {true #Equals I <Int size(DISCRS)}
8787
[simplification]
8888
89-
rule #lookupDiscrAux(DISCRS, #findVariantIdxAux(DISCR, DISCRS, _IDX)) => DISCR
89+
rule #lookupDiscrAux(_, #findVariantIdxAux(DISCR, DISCRS, _IDX)) => DISCR
9090
requires isOneOf(DISCR, DISCRS)
9191
[simplification, preserves-definedness, symbolic(DISCR)]
9292
93+
rule asInt(#findVariantIdxAux(DISCR, DISCRS, C)) <Int X => size(DISCRS) +Int C <=Int X
94+
requires isOneOf(DISCR, DISCRS)
95+
[simplification, symbolic(DISCR)]
96+
9397
syntax Bool ::= isOneOf ( Int , Discriminants ) [function, total]
9498
// --------------------------------------------------------------
9599
rule isOneOf( _, .Discriminants ) => false

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

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1111,31 +1111,37 @@ The `getTyOf` helper applies the projections from the `Place` to determine the `
11111111
[preserves-definedness] // valid indexing and sort coercion
11121112
11131113
syntax Evaluation ::= #discriminant ( Evaluation , MaybeTy ) [strict(1)]
1114-
| #discriminantFor ( VariantIdx , TypeInfo )
11151114
// ----------------------------------------------------------------
11161115
rule <k> #discriminant(Aggregate(IDX, _), TY:Ty)
1117-
=> #discriminantFor(IDX, lookupTy(TY))
1118-
...
1119-
</k>
1120-
1121-
rule <k> #discriminantFor(variantIdx(I) #as IDX, typeInfoEnumType(_, _, DISCRIMINANTS:Discriminants, _, _))
1122-
=> Integer(#lookupDiscrAux(DISCRIMINANTS, IDX), 0, false) // HACK: bit width 0 means "flexible"
1116+
=> Integer(#lookupDiscrAux(discriminantsOf(lookupTy(TY)), IDX), 0, false) // HACK: bit width 0 means "flexible"
11231117
...
11241118
</k>
1125-
requires I <=Int size(DISCRIMINANTS)
1119+
requires asInt(IDX) <Int size(discriminantsOf(lookupTy(TY)))
1120+
andBool 0 <=Int asInt(IDX) // must not be `err(_)`
1121+
andBool 0 <Int size(discriminantsOf(lookupTy(TY))) // must be an enum
11261122
[preserves-definedness]
11271123
1124+
// // default 0 for non-enum types. May be undefined behaviour, though.
1125+
// rule #discriminant(_, _) => Integer(0, 0, false) [priority(100)]
1126+
1127+
syntax Int ::= asInt( VariantIdx ) [function, total]
1128+
// -------------------------------------------------
1129+
rule asInt(variantIdx(I)) => I
1130+
rule asInt(err(_)) => -1 // HAAAAAAACK
1131+
11281132
syntax Int ::= size(Discriminants) [function, total]
11291133
rule size(.Discriminants) => 0
11301134
rule size(discriminant(_) REST) => 1 +Int size(REST)
11311135
1132-
// default 0 for non-enum types. May be undefined behaviour, though.
1133-
// rule #discriminant(_, _) => 0 [owise]
1136+
syntax Discriminants ::= discriminantsOf( TypeInfo ) [function, total]
1137+
// -------------------------------------------------------------------
1138+
rule discriminantsOf(typeInfoEnumType(_, _, DISCRIMINANTS, _, _)) => DISCRIMINANTS
1139+
rule discriminantsOf( _OTHER_ ) => .Discriminants [owise]
11341140
11351141
syntax Int ::= #lookupDiscrAux ( Discriminants , VariantIdx ) [function]
11361142
// --------------------------------------------------------------------
11371143
rule #lookupDiscrAux( discriminant(RESULT) _ , variantIdx(I)) => RESULT requires I ==Int 0
1138-
rule #lookupDiscrAux( _:Discriminant MORE:Discriminants, variantIdx(I)) => #lookupDiscrAux(MORE, variantIdx(I -Int 1)) requires 0 <Int I [owise]
1144+
rule #lookupDiscrAux( _:Discriminant MORE:Discriminants, variantIdx(I)) => #lookupDiscrAux(MORE, variantIdx(I -Int 1)) requires 0 <Int I
11391145
```
11401146

11411147
```k

kmir/src/tests/integration/data/crate-tests/two-crate-bin/crate2::main.expected

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
┌─ 1 (root, init)
33
│ #execTerminator ( terminator ( ... kind: terminatorKindCall ( ... func: operandC
44
5-
│ (741 steps)
5+
│ (736 steps)
66
├─ 3 (terminal)
77
│ #EndProgram ~> .K
88

kmir/src/tests/integration/data/crate-tests/two-crate-dylib/crate2::test_crate1_with.expected

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
┌─ 1 (root, init)
33
│ #execTerminator ( terminator ( ... kind: terminatorKindCall ( ... func: operandC
44
5-
│ (217 steps)
5+
│ (216 steps)
66
├─ 3 (terminal)
77
│ #EndProgram ~> .K
88

kmir/src/tests/integration/data/prove-rs/show/interior-mut-fail.main.expected

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
│ #execTerminator ( terminator ( ... kind: terminatorKindCall ( ... func: operandC
44
│ span: 0
55
6-
│ (879 steps)
6+
│ (877 steps)
77
└─ 3 (stuck, leaf)
88
#setUpCalleeData ( monoItemFn ( ... name: symbol ( "** UNKNOWN FUNCTION **" ) ,
99
span: 32

kmir/src/tests/integration/data/prove-rs/show/iter_next_2-fail.main.expected

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
│ #execTerminator ( terminator ( ... kind: terminatorKindCall ( ... func: operandC
44
│ span: 0
55
6-
│ (2003 steps)
6+
│ (2000 steps)
77
└─ 3 (stuck, leaf)
88
#traverseProjection ( toStack ( 1 , local ( 1 ) ) , Range ( .List ) , .Projectio
99
span: 146

kmir/src/tests/integration/data/prove-rs/show/niche-enum.main.expected

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
│ #execTerminator ( terminator ( ... kind: terminatorKindCall ( ... func: operandC
44
│ span: 0
55
6-
│ (750 steps)
6+
│ (740 steps)
77
├─ 3 (terminal)
88
│ #EndProgram ~> .K
99
│ function: main

kmir/src/tests/integration/data/prove-rs/show/transmute-u8-to-enum-changed-discriminant-signed-fail.main.expected

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
│ #execTerminator ( terminator ( ... kind: terminatorKindCall ( ... func: operandC
44
│ span: 0
55
6-
│ (103 steps)
6+
│ (102 steps)
77
└─ 3 (stuck, leaf)
88
#traverseProjection ( toLocal ( 2 ) , thunk ( #decodeConstant ( constantKindAllo
99
span: 153

kmir/src/tests/integration/test_integration.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ def test_crate_examples(main_crate: Path, kmir: KMIR, update_expected_output: bo
246246
EXEC_DATA_DIR / 'references' / 'weirdRefs.state',
247247
None,
248248
),
249-
('enum-discriminants', EXEC_DATA_DIR / 'enum' / 'enum.smir.json', EXEC_DATA_DIR / 'enum' / 'enum.state', 139),
249+
('enum-discriminants', EXEC_DATA_DIR / 'enum' / 'enum.smir.json', EXEC_DATA_DIR / 'enum' / 'enum.state', 136),
250250
(
251251
'Array-indexing',
252252
EXEC_DATA_DIR / 'arrays' / 'array_indexing.smir.json',

0 commit comments

Comments
 (0)