Commit 50a1b62b authored by Ralf Jung's avatar Ralf Jung

use coq-stdpp

parent 2c69c726
...@@ -32,9 +32,9 @@ Makefile.coq: _CoqProject Makefile awk.Makefile ...@@ -32,9 +32,9 @@ Makefile.coq: _CoqProject Makefile awk.Makefile
build-dep: build-dep:
build/opam-pins.sh < opam.pins build/opam-pins.sh < opam.pins
opam upgrade $(YFLAG) # it is not nice that we upgrade *all* packages here, but I found no nice way to upgrade only those that we pinned opam upgrade $(YFLAG) # it is not nice that we upgrade *all* packages here, but I found no nice way to upgrade only those that we pinned
opam pin add coq-iris "$$(pwd)#HEAD" -k git -n -y opam pin add opam-builddep-temp "$$(pwd)#HEAD" -k git -n -y
opam install coq-iris --deps-only $(YFLAG) opam install opam-builddep-temp --deps-only $(YFLAG)
opam pin remove coq-iris opam pin remove opam-builddep-temp
# Some files that do *not* need to be forwarded to Makefile.coq # Some files that do *not* need to be forwarded to Makefile.coq
Makefile: ; Makefile: ;
......
...@@ -8,10 +8,11 @@ This version is known to compile with: ...@@ -8,10 +8,11 @@ This version is known to compile with:
- Coq 8.6 - Coq 8.6
- Ssreflect 1.6.1 - Ssreflect 1.6.1
- A development version of [std++](https://gitlab.mpi-sws.org/robbertkrebbers/coq-stdpp)
The easiest way to install the correct versions of the dependencies is The easiest way to install the correct versions of the dependencies is through
through opam. Coq packages are available on the coq-released repository, opam. Coq packages are available on the coq-released repository, set up by the
set up by the command: command:
opam repo add coq-released https://coq.inria.fr/opam/released opam repo add coq-released https://coq.inria.fr/opam/released
...@@ -28,8 +29,6 @@ Run `make` to build the full development. ...@@ -28,8 +29,6 @@ Run `make` to build the full development.
## Structure ## Structure
* The folder [prelude](theories/prelude) contains an extended "Standard Library"
by [Robbert Krebbers](http://robbertkrebbers.nl/thesis.html).
* The folder [algebra](theories/algebra) contains the COFE and CMRA * The folder [algebra](theories/algebra) contains the COFE and CMRA
constructions as well as the solver for recursive domain equations. constructions as well as the solver for recursive domain equations.
* The folder [base_logic](theories/base_logic) defines the Iris base logic and * The folder [base_logic](theories/base_logic) defines the Iris base logic and
......
-Q theories iris -Q theories iris
theories/prelude/option.v
theories/prelude/fin_map_dom.v
theories/prelude/bset.v
theories/prelude/fin_maps.v
theories/prelude/vector.v
theories/prelude/pmap.v
theories/prelude/stringmap.v
theories/prelude/fin_collections.v
theories/prelude/mapset.v
theories/prelude/proof_irrel.v
theories/prelude/hashset.v
theories/prelude/pretty.v
theories/prelude/countable.v
theories/prelude/orders.v
theories/prelude/natmap.v
theories/prelude/strings.v
theories/prelude/relations.v
theories/prelude/collections.v
theories/prelude/listset.v
theories/prelude/streams.v
theories/prelude/gmap.v
theories/prelude/gmultiset.v
theories/prelude/base.v
theories/prelude/tactics.v
theories/prelude/prelude.v
theories/prelude/listset_nodup.v
theories/prelude/finite.v
theories/prelude/numbers.v
theories/prelude/nmap.v
theories/prelude/zmap.v
theories/prelude/coPset.v
theories/prelude/lexico.v
theories/prelude/set.v
theories/prelude/decidable.v
theories/prelude/list.v
theories/prelude/functions.v
theories/prelude/hlist.v
theories/prelude/sorting.v
theories/algebra/cmra.v theories/algebra/cmra.v
theories/algebra/cmra_big_op.v theories/algebra/cmra_big_op.v
theories/algebra/cmra_tactics.v theories/algebra/cmra_tactics.v
......
...@@ -15,4 +15,5 @@ remove: [ "sh" "-c" "rm -rf '%{lib}%/coq/user-contrib/iris'" ] ...@@ -15,4 +15,5 @@ remove: [ "sh" "-c" "rm -rf '%{lib}%/coq/user-contrib/iris'" ]
depends: [ depends: [
"coq" { ((>= "8.5.1" & < "8.7~") | (= "dev"))} "coq" { ((>= "8.5.1" & < "8.7~") | (= "dev"))}
"coq-mathcomp-ssreflect" { ((>= "1.6.1" & < "1.7~") | (= "dev"))} "coq-mathcomp-ssreflect" { ((>= "1.6.1" & < "1.7~") | (= "dev"))}
"coq-stdpp"
] ]
coq-stdpp https://gitlab.mpi-sws.org/robbertkrebbers/coq-stdpp 2c261344225e46042932f248db87fd1cde04b5cd
From mathcomp Require Export ssreflect. From mathcomp Require Export ssreflect.
From iris.prelude Require Export prelude. From stdpp Require Export prelude.
Set Default Proof Using "Type". Set Default Proof Using "Type".
Global Set Bullet Behavior "Strict Subproofs". Global Set Bullet Behavior "Strict Subproofs".
Global Open Scope general_if_scope. Global Open Scope general_if_scope.
Ltac done := prelude.tactics.done. Ltac done := stdpp.tactics.done.
From iris.algebra Require Export cmra list. From iris.algebra Require Export cmra list.
From iris.prelude Require Import functions gmap gmultiset. From stdpp Require Import functions gmap gmultiset.
Set Default Proof Using "Type". Set Default Proof Using "Type".
(** The operator [ [⋅] Ps ] folds [⋅] over the list [Ps]. This operator is not a (** The operator [ [⋅] Ps ] folds [⋅] over the list [Ps]. This operator is not a
......
From iris.algebra Require Export cmra. From iris.algebra Require Export cmra.
From iris.algebra Require Import updates local_updates. From iris.algebra Require Import updates local_updates.
From iris.prelude Require Export collections coPset. From stdpp Require Export collections coPset.
Set Default Proof Using "Type". Set Default Proof Using "Type".
(** This is pretty much the same as algebra/gset, but I was not able to (** This is pretty much the same as algebra/gset, but I was not able to
generalize the construction without breaking canonical structures. *) generalize the construction without breaking canonical structures. *)
......
From iris.algebra Require Export cmra. From iris.algebra Require Export cmra.
From iris.prelude Require Export gmap. From stdpp Require Export gmap.
From iris.algebra Require Import updates local_updates. From iris.algebra Require Import updates local_updates.
From iris.base_logic Require Import base_logic. From iris.base_logic Require Import base_logic.
Set Default Proof Using "Type". Set Default Proof Using "Type".
......
From iris.algebra Require Export cmra. From iris.algebra Require Export cmra.
From iris.algebra Require Import updates local_updates. From iris.algebra Require Import updates local_updates.
From iris.prelude Require Export collections gmap mapset. From stdpp Require Export collections gmap mapset.
Set Default Proof Using "Type". Set Default Proof Using "Type".
(* The union CMRA *) (* The union CMRA *)
......
From iris.algebra Require Export cmra. From iris.algebra Require Export cmra.
From iris.base_logic Require Import base_logic. From iris.base_logic Require Import base_logic.
From iris.prelude Require Import finite. From stdpp Require Import finite.
Set Default Proof Using "Type". Set Default Proof Using "Type".
(** * Indexed product *) (** * Indexed product *)
......
From iris.algebra Require Export cmra. From iris.algebra Require Export cmra.
From iris.prelude Require Export list. From stdpp Require Export list.
From iris.base_logic Require Import base_logic. From iris.base_logic Require Import base_logic.
From iris.algebra Require Import updates local_updates. From iris.algebra Require Import updates local_updates.
Set Default Proof Using "Type". Set Default Proof Using "Type".
......
From iris.prelude Require Export set. From stdpp Require Export set.
From iris.algebra Require Export cmra. From iris.algebra Require Export cmra.
From iris.algebra Require Import dra. From iris.algebra Require Import dra.
Set Default Proof Using "Type". Set Default Proof Using "Type".
......
From iris.prelude Require Export vector. From stdpp Require Export vector.
From iris.algebra Require Export ofe. From iris.algebra Require Export ofe.
From iris.algebra Require Import list. From iris.algebra Require Import list.
Set Default Proof Using "Type". Set Default Proof Using "Type".
......
From iris.algebra Require Export list cmra_big_op. From iris.algebra Require Export list cmra_big_op.
From iris.base_logic Require Export base_logic. From iris.base_logic Require Export base_logic.
From iris.prelude Require Import gmap fin_collections gmultiset functions. From stdpp Require Import gmap fin_collections gmultiset functions.
Set Default Proof Using "Type". Set Default Proof Using "Type".
Import uPred. Import uPred.
......
From iris.prelude Require Export hlist. From stdpp Require Export hlist.
From iris.base_logic Require Export base_logic. From iris.base_logic Require Export base_logic.
Set Default Proof Using "Type". Set Default Proof Using "Type".
Import uPred. Import uPred.
......
From iris.base_logic.lib Require Export own. From iris.base_logic.lib Require Export own.
From iris.prelude Require Export coPset. From stdpp Require Export coPset.
From iris.base_logic.lib Require Import wsat. From iris.base_logic.lib Require Import wsat.
From iris.algebra Require Import gmap. From iris.algebra Require Import gmap.
From iris.base_logic Require Import big_op. From iris.base_logic Require Import big_op.
......
From iris.prelude Require Import gmap gmultiset. From stdpp Require Import gmap gmultiset.
From iris.base_logic Require Export derived. From iris.base_logic Require Export derived.
From iris.base_logic Require Import big_op. From iris.base_logic Require Import big_op.
From iris.proofmode Require Import classes class_instances. From iris.proofmode Require Import classes class_instances.
......
From iris.prelude Require Export countable coPset. From stdpp Require Export countable coPset.
From iris.algebra Require Export base. From iris.algebra Require Export base.
Set Default Proof Using "Type". Set Default Proof Using "Type".
......
From iris.base_logic Require Export own. From iris.base_logic Require Export own.
From iris.algebra Require Import agree. From iris.algebra Require Import agree.
From iris.prelude Require Import gmap. From stdpp Require Import gmap.
Set Default Proof Using "Type". Set Default Proof Using "Type".
Import uPred. Import uPred.
......
From iris.base_logic.lib Require Export own. From iris.base_logic.lib Require Export own.
From iris.prelude Require Export coPset. From stdpp Require Export coPset.
From iris.algebra Require Import gmap auth agree gset coPset. From iris.algebra Require Import gmap auth agree gset coPset.
From iris.base_logic Require Import big_op. From iris.base_logic Require Import big_op.
From iris.proofmode Require Import tactics. From iris.proofmode Require Import tactics.
......
From iris.prelude Require Import gmap. From stdpp Require Import gmap.
From iris.base_logic Require Export base_logic big_op. From iris.base_logic Require Export base_logic big_op.
Set Default Proof Using "Type". Set Default Proof Using "Type".
Import uPred. Import uPred.
......
From iris.program_logic Require Export ectx_language ectxi_language. From iris.program_logic Require Export ectx_language ectxi_language.
From iris.algebra Require Export ofe. From iris.algebra Require Export ofe.
From iris.prelude Require Export strings. From stdpp Require Export strings.
From iris.prelude Require Import gmap. From stdpp Require Import gmap.
Set Default Proof Using "Type". Set Default Proof Using "Type".
Module heap_lang. Module heap_lang.
......
From iris.program_logic Require Export weakestpre. From iris.program_logic Require Export weakestpre.
From iris.heap_lang Require Export lang. From iris.heap_lang Require Export lang.
From iris.heap_lang.lib.barrier Require Export barrier. From iris.heap_lang.lib.barrier Require Export barrier.
From iris.prelude Require Import functions. From stdpp Require Import functions.
From iris.base_logic Require Import big_op lib.saved_prop lib.sts. From iris.base_logic Require Import big_op lib.saved_prop lib.sts.
From iris.heap_lang Require Import proofmode. From iris.heap_lang Require Import proofmode.
From iris.heap_lang.lib.barrier Require Import protocol. From iris.heap_lang.lib.barrier Require Import protocol.
......
From iris.algebra Require Export sts. From iris.algebra Require Export sts.
From iris.base_logic Require Import lib.own. From iris.base_logic Require Import lib.own.
From iris.prelude Require Export gmap. From stdpp Require Export gmap.
Set Default Proof Using "Type". Set Default Proof Using "Type".
(** The STS describing the main barrier protocol. Every state has an index-set (** The STS describing the main barrier protocol. Every state has an index-set
......
...@@ -4,7 +4,7 @@ From iris.program_logic Require Import ectx_lifting. ...@@ -4,7 +4,7 @@ From iris.program_logic Require Import ectx_lifting.
From iris.heap_lang Require Export lang. From iris.heap_lang Require Export lang.
From iris.heap_lang Require Import tactics. From iris.heap_lang Require Import tactics.
From iris.proofmode Require Import tactics. From iris.proofmode Require Import tactics.
From iris.prelude Require Import fin_maps. From stdpp Require Import fin_maps.
Set Default Proof Using "Type". Set Default Proof Using "Type".
Import uPred. Import uPred.
......
This diff is collapsed.
(* Copyright (c) 2012-2017, Robbert Krebbers. *)
(* This file is distributed under the terms of the BSD license. *)
(** This file implements bsets as functions into Prop. *)
From iris.prelude Require Export prelude.
Set Default Proof Using "Type".
Record bset (A : Type) : Type := mkBSet { bset_car : A bool }.
Arguments mkBSet {_} _.
Arguments bset_car {_} _ _.
Instance bset_top {A} : Top (bset A) := mkBSet (λ _, true).
Instance bset_empty {A} : Empty (bset A) := mkBSet (λ _, false).
Instance bset_singleton `{EqDecision A} : Singleton A (bset A) := λ x,
mkBSet (λ y, bool_decide (y = x)).
Instance bset_elem_of {A} : ElemOf A (bset A) := λ x X, bset_car X x.
Instance bset_union {A} : Union (bset A) := λ X1 X2,
mkBSet (λ x, bset_car X1 x || bset_car X2 x).
Instance bset_intersection {A} : Intersection (bset A) := λ X1 X2,
mkBSet (λ x, bset_car X1 x && bset_car X2 x).
Instance bset_difference {A} : Difference (bset A) := λ X1 X2,
mkBSet (λ x, bset_car X1 x && negb (bset_car X2 x)).
Instance bset_collection `{EqDecision A} : Collection A (bset A).
Proof.
split; [split| |].
- by intros x ?.
- by intros x y; rewrite <-(bool_decide_spec (x = y)).
- split. apply orb_prop_elim. apply orb_prop_intro.
- split. apply andb_prop_elim. apply andb_prop_intro.
- intros X Y x; unfold elem_of, bset_elem_of; simpl.
destruct (bset_car X x), (bset_car Y x); simpl; tauto.
Qed.
Instance bset_elem_of_dec {A} x (X : bset A) : Decision (x X) := _.
Typeclasses Opaque bset_elem_of.
Global Opaque bset_empty bset_singleton bset_union
bset_intersection bset_difference.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
(* Copyright (c) 2012-2017, Robbert Krebbers. *)
(* This file is distributed under the terms of the BSD license. *)
(** This file collects theorems, definitions, tactics, related to propositions
with a decidable equality. Such propositions are collected by the [Decision]
type class. *)
From iris.prelude Require Export proof_irrel.
Set Default Proof Using "Type*".
Hint Extern 200 (Decision _) => progress (lazy beta) : typeclass_instances.
Lemma dec_stable `{Decision P} : ¬¬P P.
Proof. firstorder. Qed.
Lemma Is_true_reflect (b : bool) : reflect b b.
Proof. destruct b. left; constructor. right. intros []. Qed.
Instance: Inj (=) () Is_true.
Proof. intros [] []; simpl; intuition. Qed.
(** We introduce [decide_rel] to avoid inefficienct computation due to eager
evaluation of propositions by [vm_compute]. This inefficiency occurs if
[(x = y) := (f x = f y)] as [decide (x = y)] evaluates to [decide (f x = f y)]
which then might lead to evaluation of [f x] and [f y]. Using [decide_rel]
we hide [f] under a lambda abstraction to avoid this unnecessary evaluation. *)
Definition decide_rel {A B} (R : A B Prop) {dec : x y, Decision (R x y)}
(x : A) (y : B) : Decision (R x y) := dec x y.
Lemma decide_rel_correct {A B} (R : A B Prop) `{ x y, Decision (R x y)}
(x : A) (y : B) : decide_rel R x y = decide (R x y).
Proof. reflexivity. Qed.
Lemma decide_True {A} `{Decision P} (x y : A) :
P (if decide P then x else y) = x.
Proof. destruct (decide P); tauto. Qed.
Lemma decide_False {A} `{Decision P} (x y : A) :
¬P (if decide P then x else y) = y.
Proof. destruct (decide P); tauto. Qed.
Lemma decide_iff {A} P Q `{Decision P, Decision Q} (x y : A) :
(P Q) (if decide P then x else y) = (if decide Q then x else y).
Proof. intros [??]. destruct (decide P), (decide Q); tauto. Qed.
Lemma decide_left`{Decision P, !ProofIrrel P} (HP : P) : decide P = left HP.
Proof. destruct (decide P) as [?|?]; [|contradiction]. f_equal. apply proof_irrel. Qed.
Lemma decide_right`{Decision P} `{!ProofIrrel (¬ P)} (HP : ¬ P) : decide P = right HP.
Proof. destruct (decide P) as [?|?]; [contradiction|]. f_equal. apply proof_irrel. Qed.
(** The tactic [destruct_decide] destructs a sumbool [dec]. If one of the
components is double negated, it will try to remove the double negation. *)
Tactic Notation "destruct_decide" constr(dec) "as" ident(H) :=
destruct dec as [H|H];
try match type of H with
| ¬¬_ => apply dec_stable in H
end.
Tactic Notation "destruct_decide" constr(dec) :=
let H := fresh in destruct_decide dec as H.
(** The tactic [case_decide] performs case analysis on an arbitrary occurrence
of [decide] or [decide_rel] in the conclusion or hypotheses. *)
Tactic Notation "case_decide" "as" ident(Hd) :=
match goal with
| H : context [@decide ?P ?dec] |- _ =>
destruct_decide (@decide P dec) as Hd
| H : context [@decide_rel _ _ ?R ?x ?y ?dec] |- _ =>
destruct_decide (@decide_rel _ _ R x y dec) as Hd
| |- context [@decide ?P ?dec] =>
destruct_decide (@decide P dec) as Hd
| |- context [@decide_rel _ _ ?R ?x ?y ?dec] =>
destruct_decide (@decide_rel _ _ R x y dec) as Hd
end.
Tactic Notation "case_decide" :=
let H := fresh in case_decide as H.
(** The tactic [solve_decision] uses Coq's [decide equality] tactic together
with instance resolution to automatically generate decision procedures. *)
Ltac solve_trivial_decision :=
match goal with
| |- Decision (?P) => apply _
| |- sumbool ?P (¬?P) => change (Decision P); apply _
end.
Ltac solve_decision := intros; first
[ solve_trivial_decision
| unfold Decision; decide equality; solve_trivial_decision ].
(** The following combinators are useful to create Decision proofs in
combination with the [refine] tactic. *)
Notation swap_if S := (match S with left H => right H | right H => left H end).
Notation cast_if S := (if S then left _ else right _).
Notation cast_if_and S1 S2 := (if S1 then cast_if S2 else right _).
Notation cast_if_and3 S1 S2 S3 := (if S1 then cast_if_and S2 S3 else right _).
Notation cast_if_and4 S1 S2 S3 S4 :=
(if S1 then cast_if_and3 S2 S3 S4 else right _).
Notation cast_if_and5 S1 S2 S3 S4 S5 :=
(if S1 then cast_if_and4 S2 S3 S4 S5 else right _).
Notation cast_if_and6 S1 S2 S3 S4 S5 S6 :=
(if S1 then cast_if_and5 S2 S3 S4 S5 S6 else right _).
Notation cast_if_or S1 S2 := (if S1 then left _ else cast_if S2).
Notation cast_if_or3 S1 S2 S3 := (if S1 then left _ else cast_if_or S2 S3).
Notation cast_if_not_or S1 S2 := (if S1 then cast_if S2 else left _).
Notation cast_if_not S := (if S then right _ else left _).
(** We can convert decidable propositions to booleans. *)
Definition bool_decide (P : Prop) {dec : Decision P} : bool :=
if dec then true else false.
Lemma bool_decide_reflect P `{dec : Decision P} : reflect P (bool_decide P).
Proof. unfold bool_decide. destruct dec; [left|right]; assumption. Qed.
Tactic Notation "case_bool_decide" "as" ident (Hd) :=
match goal with
| H : context [@bool_decide ?P ?dec] |- _ =>
destruct_decide (@bool_decide_reflect P dec) as Hd
| |- context [@bool_decide ?P ?dec] =>
destruct_decide (@bool_decide_reflect P dec) as Hd
end.
Tactic Notation "case_bool_decide" :=
let H := fresh in case_bool_decide as H.
Lemma bool_decide_spec (P : Prop) {dec : Decision P} : bool_decide P P.
Proof. unfold bool_decide. destruct dec; simpl; tauto. Qed.
Lemma bool_decide_unpack (P : Prop) {dec : Decision P} : bool_decide P P.
Proof. rewrite bool_decide_spec; trivial. Qed.
Lemma bool_decide_pack (P : Prop) {dec : Decision P} : P bool_decide P.
Proof. rewrite bool_decide_spec; trivial. Qed.
Hint Resolve bool_decide_pack.
Lemma bool_decide_true (P : Prop) `{Decision P} : P bool_decide P = true.
Proof. case_bool_decide; tauto. Qed.
Lemma bool_decide_false (P : Prop) `{Decision P} : ¬P bool_decide P = false.
Proof. case_bool_decide; tauto. Qed.
Lemma bool_decide_iff (P Q : Prop) `{Decision P, Decision Q} :
(P Q) bool_decide P = bool_decide Q.
Proof. repeat case_bool_decide; tauto. Qed.
(** * Decidable Sigma types *)
(** Leibniz equality on Sigma types requires the equipped proofs to be
equal as Coq does not support proof irrelevance. For decidable we
propositions we define the type [dsig P] whose Leibniz equality is proof
irrelevant. That is [∀ x y : dsig P, x = y ↔ `x = `y]. *)
Definition dsig `(P : A Prop) `{ x : A, Decision (P x)} :=
{ x | bool_decide (P x) }.
Definition proj2_dsig `{ x : A, Decision (P x)} (x : dsig P) : P (`x) :=
bool_decide_unpack _ (proj2_sig x).
Definition dexist `{ x : A, Decision (P x)} (x : A) (p : P x) : dsig P :=
xbool_decide_pack _ p.
Lemma dsig_eq `(P : A Prop) `{ x, Decision (P x)}
(x y : dsig P) : x = y `x = `y.
Proof. apply (sig_eq_pi _). Qed.
Lemma dexists_proj1 `(P : A Prop) `{ x, Decision (P x)} (x : dsig P) p :
dexist (`x) p = x.
Proof. apply dsig_eq; reflexivity. Qed.
(** * Instances of Decision *)
(** Instances of [Decision] for operators of propositional logic. *)
Instance True_dec: Decision True := left I.
Instance False_dec: Decision False := right (False_rect False).
Instance Is_true_dec b : Decision (Is_true b).
Proof. destruct b; simpl; apply _. Defined.
Section prop_dec.
Context `(P_dec : Decision P) `(Q_dec : Decision Q).
Global Instance not_dec: Decision (¬P).
Proof. refine (cast_if_not P_dec); intuition. Defined.
Global Instance and_dec: Decision (P Q).
Proof. refine (cast_if_and P_dec Q_dec); intuition. Defined.
Global Instance or_dec: Decision (P Q).
Proof. refine (cast_if_or P_dec Q_dec); intuition. Defined.
Global Instance impl_dec: Decision (P Q).
Proof. refine (if P_dec then cast_if Q_dec else left _); intuition. Defined.
End prop_dec.
Instance iff_dec `(P_dec : Decision P) `(Q_dec : Decision Q) :
Decision (P Q) := and_dec _ _.
(** Instances of [Decision] for common data types. *)
Instance bool_eq_dec : EqDecision bool.
Proof. solve_decision. Defined.
Instance unit_eq_dec : EqDecision unit.
Proof. solve_decision. Defined.