|
1 | 1 | module ExtractPulseFnIface |
2 | 2 | #lang-pulse |
3 | 3 |
|
4 | | -(** Interface for ExtractPulseFnIface. |
5 | | - Tests that a Pulse fn declared in .fsti extracts to C correctly. |
6 | | - Regression test: previously, fn declarations in .fsti were not |
7 | | - recognized by the interleaver, causing the implementation to be |
8 | | - tagged KrmlPrivate and silently dropped by KaRaMeL. *) |
| 4 | +(** Regression test for interleaving DeclToBeDesugared (Pulse fn) in .fsti/.fst. |
| 5 | + Tests that all patterns extract to C correctly without KrmlPrivate. |
| 6 | +
|
| 7 | + Patterns tested: |
| 8 | + 1. val + let (basic, always worked) |
| 9 | + 2. fn in .fsti + fn in .fst (basic DeclToBeDesugared matching) |
| 10 | + 3. Private helper in .fst before interface fns (skip, not mark private) |
| 11 | + 4. Out-of-order exposed definitions (fsti: write, assign; fst: assign, let write=assign) |
| 12 | + 5. let alias in .fst implementing fn in .fsti |
| 13 | + 6. fn in .fsti with let definitions before fn declarations *) |
9 | 14 |
|
10 | 15 | open Pulse.Lib.Pervasives |
11 | 16 | open Pulse.Lib.Reference |
12 | 17 | module R = Pulse.Lib.Reference |
13 | 18 |
|
| 19 | +// Pattern 1: val + let (basic) |
14 | 20 | val pure_add (x y : int) : int |
15 | 21 |
|
| 22 | +// Pattern 2: fn in .fsti matched by fn in .fst |
16 | 23 | fn pulse_read_ref |
17 | 24 | (r: ref int) |
18 | 25 | (#v: Ghost.erased int) |
19 | 26 | requires R.pts_to r v |
20 | 27 | returns x: int |
21 | 28 | ensures R.pts_to r v ** pure (x == Ghost.reveal v) |
| 29 | + |
| 30 | +// Pattern 6: let definition in .fsti before fn declarations |
| 31 | +let double (x: int) : int = pure_add x x |
| 32 | + |
| 33 | +// Pattern 3: .fst will have a private helper before this fn |
| 34 | +fn pulse_write_ref |
| 35 | + (r: ref int) |
| 36 | + (v: int) |
| 37 | + (#old: Ghost.erased int) |
| 38 | + requires R.pts_to r old |
| 39 | + ensures R.pts_to r v |
| 40 | + |
| 41 | +// Pattern 4: Out-of-order — .fsti has write_and_return before assign_ref, |
| 42 | +// but .fst defines assign_ref first (as the primary fn) and then |
| 43 | +// let write_and_return = assign_ref as an alias. |
| 44 | +fn write_and_return |
| 45 | + (r: ref int) |
| 46 | + (v: int) |
| 47 | + (#old: Ghost.erased int) |
| 48 | + requires R.pts_to r old |
| 49 | + returns x: int |
| 50 | + ensures R.pts_to r v ** pure (x == v) |
| 51 | + |
| 52 | +fn assign_ref |
| 53 | + (r: ref int) |
| 54 | + (v: int) |
| 55 | + (#old: Ghost.erased int) |
| 56 | + requires R.pts_to r old |
| 57 | + returns x: int |
| 58 | + ensures R.pts_to r v ** pure (x == v) |
| 59 | + |
| 60 | +// Pattern 5: fn in .fsti, let alias in .fst |
| 61 | +fn pulse_read_ref2 |
| 62 | + (r: ref int) |
| 63 | + (#v: Ghost.erased int) |
| 64 | + requires R.pts_to r v |
| 65 | + returns x: int |
| 66 | + ensures R.pts_to r v ** pure (x == Ghost.reveal v) |
0 commit comments