Skip to content

Commit 6cb300b

Browse files
committed
Update tutorial files
1 parent defa122 commit 6cb300b

34 files changed

+5842
-4311
lines changed

tutorial/ParallelIncrement.fst

+204-140
Large diffs are not rendered by default.

tutorial/PulseByExample.fst

+28-15
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
module PulseByExample
1818

19-
module PM = Pulse.Main
2019
open Pulse.Lib.Core
2120

2221
(*
@@ -27,30 +26,31 @@ open Pulse.Lib.Core
2726
*)
2827

2928
//SNIPPET_START: five
29+
#lang-pulse
30+
3031
let fstar_five : int = 5
3132

32-
```pulse
3333
fn five ()
3434
requires emp
3535
returns n:int
3636
ensures pure (n == 5)
3737
{
3838
fstar_five
3939
}
40-
```
40+
4141

4242
let pulse_five_in_fstar = five ()
4343
//SNIPPET_END: five
4444

45-
```pulse
45+
4646
fn five_alt ()
4747
requires emp
4848
returns n:(n:int { n == 5 })
4949
ensures emp
5050
{
5151
5
5252
}
53-
```
53+
5454

5555
open Pulse.Lib.Reference
5656
module R = Pulse.Lib.Reference
@@ -62,7 +62,7 @@ module R = Pulse.Lib.Reference
6262
- default full permission
6363
- heap reference, read and write
6464
*)
65-
```pulse
65+
6666
fn ref_swap (r1 r2:ref int)
6767
requires
6868
R.pts_to r1 'n1 **
@@ -77,7 +77,7 @@ fn ref_swap (r1 r2:ref int)
7777
r1 := v2;
7878
r2 := v1
7979
}
80-
```
80+
8181

8282
open Pulse.Lib.Array
8383
module A = Pulse.Lib.Array
@@ -91,7 +91,7 @@ open Pulse.Lib.BoundedIntegers
9191
- machine integers, ops on bounded integers
9292
*)
9393

94-
```pulse
94+
9595
fn arr_swap (#t:Type0) (n i j:SZ.t) (a:larray t (v n))
9696
requires
9797
A.pts_to a 's0 **
@@ -109,15 +109,15 @@ fn arr_swap (#t:Type0) (n i j:SZ.t) (a:larray t (v n))
109109
a.(i) <- vj;
110110
a.(j) <- vi;
111111
}
112-
```
112+
113113

114114
(*
115115
Things to note:
116116
- control flow: while loop, if
117117
- mutable local reference, read and write
118118
- variable permission
119119
*)
120-
```pulse
120+
121121
fn max (n:SZ.t) (a:larray nat (v n))
122122
requires
123123
A.pts_to a #'p 's **
@@ -156,10 +156,10 @@ fn max (n:SZ.t) (a:larray nat (v n))
156156
let vmax = !max;
157157
vmax
158158
}
159-
```
160-
// This option may become the default at some point
159+
160+
//this option should become the default, once I shake out the handling of address-taking
161161
#push-options "--ext 'pulse:rvalues'"
162-
```pulse
162+
163163
fn max_alt (n:SZ.t) (a:larray nat (v n))
164164
requires
165165
A.pts_to a #'p 's **
@@ -189,5 +189,18 @@ fn max_alt (n:SZ.t) (a:larray nat (v n))
189189
};
190190
max
191191
}
192-
```
193-
#pop-options
192+
193+
#pop-options
194+
195+
(*
196+
- some more mature example (e.g. sorting alg)
197+
198+
- some simple record data structure along with a library of functions on this DS
199+
(e.g. library of functions on 2D points)
200+
201+
- build up to explaining the pulse implementation of lpht? -- emphasis on connecting
202+
pure implementation to imperative code
203+
- pulse linked list? -- more traditional sep logic example
204+
205+
- concurrency, e.g. par incr of a ctr
206+
*)

tutorial/PulseByExample.md

+14-12
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
# Pulse By Example
22

33
Pulse is a syntax extension and typechecker extension of F*.
4-
A pulse program is embedded in an F* program, delimited by the syntax extension notation ` ```pulse ... ``` `.
4+
A pulse program is embedded in an F* program, delimited by the syntax extension notation ` ... `.
55
The first code snippet demonstrates an embedded Pulse program `five`, which produces the integer 5.
66
The rest of the file is a normal F* program.
77

88
Pulse programs accept one or more arguments, where the `unit` type can be used to thunk a computation.
99
The specification of a Pulse program includes a precondition (`requires ...`), postcondition (`ensures ...`), and (optional) return type.
1010
The pre- and post-conditions are propositions, like F* propositions but with a twise: Pulse leverages [separation logic](https://en.wikipedia.org/wiki/Separation_logic) to simplify reasoning about heap mutation.
1111

12-
Propositions in Pulse (called `vprop`s) enjoy separation logic operators like `**`, the separating conjunction.
13-
A `vprop` may include a traditional F* `prop` by surrounding it with the `pure` keyword.
14-
Generally, pure `prop`s are used to specify mathematical/logical constraints and anything having to do with references or memory sits outside in the surrounding `vprop`.
12+
Propositions in Pulse (called `slprop`s) enjoy separation logic operators like `**`, the separating conjunction.
13+
A `slprop` may include a traditional F* `prop` by surrounding it with the `pure` keyword.
14+
Generally, pure `prop`s are used to specify mathematical/logical constraints and anything having to do with references or memory sits outside in the surrounding `slprop`.
1515

1616
Returning to our code snippet, the separation logic proposition `emp` means that the program does not own any resources or have any knowledge.
1717
So the Pulse program `five` begins with no resources/knowledge and returns with the knowledge that the return value is logically equal to 5.
1818

19-
```ocaml
19+
ocaml
2020
module PM = Pulse.Main
2121
open Pulse.Lib.Core
2222

@@ -31,7 +31,7 @@ fn five ()
3131
5
3232
}
3333
``
34-
```
34+
3535

3636
Let's make things more interesting.
3737
The next code snippet `ref_swap` swaps the values of two integer references.
@@ -47,7 +47,7 @@ Pulse syntax spotlight: The program body demonstrates Pulse syntax for
4747
- reference read: `!r1`
4848
- reference write: `r1 := ...`
4949

50-
```ocaml
50+
ocaml
5151
open Pulse.Lib.Reference
5252
module R = Pulse.Lib.Reference
5353

@@ -64,12 +64,14 @@ fn ref_swap (r1 r2:ref int)
6464
r2 := v1
6565
}
6666
``
67-
```
67+
6868

6969
You've seen references; now we'll introduce arrays.
7070
But first, a note on integers.
7171
In the following code snippet, we use non-primitive integers for the first time: `FStar.SizeT` is a module for machine integers of at least 16 bits, depending on the machine.
72+
#lang-pulse
7273
The module `Pulse.Class.BoundedIntegers` offers arithmetic operations on various types of bounded integers, including `FStar.SizeT` and `FStar.U32`.
74+
#lang-pulse
7375
The bounded integer class overloads arithmetic operators, like `<`, to allow, e.g., the comparison of `SizeT`s `i < n` on line X and comparison of `nat`s `k < v n` on line X (`v` elaborates to `SZ.v` and converts a `SizeT` to a nat).
7476

7577
Let's get back to arrays.
@@ -85,7 +87,7 @@ Pulse syntax spotlight: The program body demonstrates Pulse syntax for
8587
- array read: `a.(i)`
8688
- array write: `a.(i) <- ...`
8789

88-
```ocaml
90+
ocaml
8991
open Pulse.Lib.Array
9092
module A = Pulse.Lib.Array
9193
module SZ = FStar.SizeT
@@ -109,7 +111,7 @@ fn arr_swap (#t:Type0) (n i j:SZ.t) (a:larray t (v n))
109111
a.(j) <- vi;
110112
}
111113
``
112-
```
114+
113115

114116
The last example introduces loops.
115117
The Pulse program `max` computes the maximum value in an array of `nat`s.
@@ -147,7 +149,7 @@ Pulse syntax spotlight: The program body demonstrates Pulse syntax for
147149
- loop invariant: `invariant b ...`
148150
- custom proof syntax: `with ... assert ...`
149151

150-
```ocaml
152+
ocaml
151153
``pulse
152154
fn max (n:SZ.t) (a:larray nat (v n))
153155
requires A.pts_to a #'p 's ** pure (Seq.length 's == v n)
@@ -185,7 +187,7 @@ fn max (n:SZ.t) (a:larray nat (v n))
185187
vmax
186188
}
187189
``
188-
```
190+
189191

190192
In this tutorial, you have seen custom Pulse proof syntax:
191193
- `requires`, `ensures`

0 commit comments

Comments
 (0)