Skip to content

Commit 3f8f1c5

Browse files
committed
Put PLDI talk example in the right branch
1 parent 2d54aa8 commit 3f8f1c5

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

PosMonotonicCounter.v

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
Require Import Coq.Arith.Arith.
2+
Require Import RGref.DSL.DSL.
3+
4+
(** * A Strictly Positive Monotonic Counter
5+
A monotonically increasing non-zero counter.
6+
A slightly better basic example than the plain monotonic counter since this one has a nontrivial refinement. *)
7+
8+
Definition increasing : hrel nat := (fun n n' _ _ => n <= n').
9+
Hint Unfold increasing.
10+
11+
Definition pos : hpred nat := (fun n _ => n > 0).
12+
13+
(** We'll give the Program extension some hints for this module *)
14+
Local Obligation Tactic := intros; eauto with arith; compute; eauto with arith.
15+
16+
(** Now the definition of a verified monotonically increasing counter is
17+
barely more work than a completely unchecked counter. *)
18+
Program Definition posmonotonic_counter := ref{nat|pos}[increasing,increasing].
19+
20+
Program Definition read_counter (c:posmonotonic_counter) : nat := !c.
21+
22+
Program Definition inc_monotonic { Γ } (p:posmonotonic_counter) : rgref Γ unit Γ :=
23+
[p]:= !p + 1.
24+
25+
Program Definition mkCounter { Γ } (u:unit) : rgref Γ posmonotonic_counter Γ :=
26+
Alloc 1.
27+
28+
Program Example test_counter { Γ } (u:unit) : rgref Γ unit Γ :=
29+
x <- mkCounter tt;
30+
inc_monotonic x.

compile.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/bash
22
export CORE="RGref/DSL/LinearEnv.v RGref/DSL/DSL.v RGref/DSL/Theories.v RGref/DSL/Core.v RGref/DSL/Monad.v"
3-
export EXAMPLES="AppendOnlyLinkedList.v MonotonicCounter.v PrependOnlyPureList.v CounterModule.v RCC.v ReferenceImmutability.v LinkedList.v"
3+
export EXAMPLES="PosMonotonicCounter.v AppendOnlyLinkedList.v MonotonicCounter.v PrependOnlyPureList.v CounterModule.v RCC.v ReferenceImmutability.v LinkedList.v"
44
export BUGS="KnownUnsoundnessExamples.v"
55
coq_makefile -arg -impredicative-set -R RGref RGref $CORE $EXAMPLES $BUGS > Makefile
66
touch .depend

0 commit comments

Comments
 (0)