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
build-dep:
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 pin add coq-iris "$$(pwd)#HEAD" -k git -n -y
opam install coq-iris --deps-only $(YFLAG)
opam pin remove coq-iris
opam pin add opam-builddep-temp "$$(pwd)#HEAD" -k git -n -y
opam install opam-builddep-temp --deps-only $(YFLAG)
opam pin remove opam-builddep-temp
# Some files that do *not* need to be forwarded to Makefile.coq
Makefile: ;
......
......@@ -8,10 +8,11 @@ This version is known to compile with:
- Coq 8.6
- 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
through opam. Coq packages are available on the coq-released repository,
set up by the command:
The easiest way to install the correct versions of the dependencies is through
opam. Coq packages are available on the coq-released repository, set up by the
command:
opam repo add coq-released https://coq.inria.fr/opam/released
......@@ -28,8 +29,6 @@ Run `make` to build the full development.
## 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
constructions as well as the solver for recursive domain equations.
* The folder [base_logic](theories/base_logic) defines the Iris base logic and
......
-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_big_op.v
theories/algebra/cmra_tactics.v
......
......@@ -15,4 +15,5 @@ remove: [ "sh" "-c" "rm -rf '%{lib}%/coq/user-contrib/iris'" ]
depends: [
"coq" { ((>= "8.5.1" & < "8.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 iris.prelude Require Export prelude.
From stdpp Require Export prelude.
Set Default Proof Using "Type".
Global Set Bullet Behavior "Strict Subproofs".
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.prelude Require Import functions gmap gmultiset.
From stdpp Require Import functions gmap gmultiset.
Set Default Proof Using "Type".
(** The operator [ [⋅] Ps ] folds [⋅] over the list [Ps]. This operator is not a
......
From iris.algebra Require Export cmra.
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".
(** This is pretty much the same as algebra/gset, but I was not able to
generalize the construction without breaking canonical structures. *)
......
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.base_logic Require Import base_logic.
Set Default Proof Using "Type".
......
From iris.algebra Require Export cmra.
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".
(* The union CMRA *)
......
From iris.algebra Require Export cmra.
From iris.base_logic Require Import base_logic.
From iris.prelude Require Import finite.
From stdpp Require Import finite.
Set Default Proof Using "Type".
(** * Indexed product *)
......
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.algebra Require Import updates local_updates.
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 Import dra.
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 Import list.
Set Default Proof Using "Type".
......
From iris.algebra Require Export list cmra_big_op.
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".
Import uPred.
......
From iris.prelude Require Export hlist.
From stdpp Require Export hlist.
From iris.base_logic Require Export base_logic.
Set Default Proof Using "Type".
Import uPred.
......
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.algebra Require Import gmap.
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 Import big_op.
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.
Set Default Proof Using "Type".
......
From iris.base_logic Require Export own.
From iris.algebra Require Import agree.
From iris.prelude Require Import gmap.
From stdpp Require Import gmap.
Set Default Proof Using "Type".
Import uPred.
......
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.base_logic Require Import big_op.
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.
Set Default Proof Using "Type".
Import uPred.
......
From iris.program_logic Require Export ectx_language ectxi_language.
From iris.algebra Require Export ofe.
From iris.prelude Require Export strings.
From iris.prelude Require Import gmap.
From stdpp Require Export strings.
From stdpp Require Import gmap.
Set Default Proof Using "Type".
Module heap_lang.
......
From iris.program_logic Require Export weakestpre.
From iris.heap_lang Require Export lang.
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.heap_lang Require Import proofmode.
From iris.heap_lang.lib.barrier Require Import protocol.
......
From iris.algebra Require Export sts.
From iris.base_logic Require Import lib.own.
From iris.prelude Require Export gmap.
From stdpp Require Export gmap.
Set Default Proof Using "Type".
(** 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.
From iris.heap_lang Require Export lang.
From iris.heap_lang 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".
Import uPred.
......
(* Copyright (c) 2012-2017, Robbert Krebbers. *)
(* This file is distributed under the terms of the BSD license. *)
(** This file collects type class interfaces, notations, and general theorems
that are used throughout the whole development. Most importantly it contains
abstract interfaces for ordered structures, collections, and various other data
structures. *)
Global Generalizable All Variables.
Global Set Automatic Coercions Import.
Global Set Asymmetric Patterns.
Global Unset Transparent Obligations.
From Coq Require Export Morphisms RelationClasses List Bool Utf8 Setoid.
Set Default Proof Using "Type".
Export ListNotations.
From Coq.Program Require Export Basics Syntax.
Obligation Tactic := idtac.
(** Sealing off definitions *)
Set Primitive Projections.
Record seal {A} (f : A) := { unseal : A; seal_eq : unseal = f }.
Arguments unseal {_ _} _.
Arguments seal_eq {_ _} _.
Unset Primitive Projections.
(** Throughout this development we use [C_scope] for all general purpose
notations that do not belong to a more specific scope. *)
Delimit Scope C_scope with C.
Global Open Scope C_scope.
(** Change [True] and [False] into notations in order to enable overloading.
We will use this to give [True] and [False] a different interpretation for
embedded logics. *)
Notation "'True'" := True : type_scope.
Notation "'False'" := False : type_scope.
(** * Equality *)
(** Introduce some Haskell style like notations. *)
Notation "(=)" := eq (only parsing) : C_scope.
Notation "( x =)" := (eq x) (only parsing) : C_scope.
Notation "(= x )" := (λ y, eq y x) (only parsing) : C_scope.
Notation "(≠)" := (λ x y, x y) (only parsing) : C_scope.
Notation "( x ≠)" := (λ y, x y) (only parsing) : C_scope.
Notation "(≠ x )" := (λ y, y x) (only parsing) : C_scope.
Hint Extern 0 (_ = _) => reflexivity.
Hint Extern 100 (_ _) => discriminate.
Instance: @PreOrder A (=).
Proof. split; repeat intro; congruence. Qed.
(** ** Setoid equality *)
(** We define an operational type class for setoid equality. This is based on
(Spitters/van der Weegen, 2011). *)
Class Equiv A := equiv: relation A.
Infix "≡" := equiv (at level 70, no associativity) : C_scope.
Notation "(≡)" := equiv (only parsing) : C_scope.
Notation "( X ≡)" := (equiv X) (only parsing) : C_scope.
Notation "(≡ X )" := (λ Y, Y X) (only parsing) : C_scope.
Notation "(≢)" := (λ X Y, ¬X Y) (only parsing) : C_scope.
Notation "X ≢ Y":= (¬X Y) (at level 70, no associativity) : C_scope.
Notation "( X ≢)" := (λ Y, X Y) (only parsing) : C_scope.
Notation "(≢ X )" := (λ Y, Y X) (only parsing) : C_scope.
(** The type class [LeibnizEquiv] collects setoid equalities that coincide
with Leibniz equality. We provide the tactic [fold_leibniz] to transform such
setoid equalities into Leibniz equalities, and [unfold_leibniz] for the
reverse. *)
Class LeibnizEquiv A `{Equiv A} := leibniz_equiv x y : x y x = y.
Lemma leibniz_equiv_iff `{LeibnizEquiv A, !Reflexive (@equiv A _)} (x y : A) :
x y x = y.
Proof. split. apply leibniz_equiv. intros ->; reflexivity. Qed.
Ltac fold_leibniz := repeat
match goal with
| H : context [ @equiv ?A _ _ _ ] |- _ =>
setoid_rewrite (leibniz_equiv_iff (A:=A)) in H
| |- context [ @equiv ?A _ _ _ ] =>
setoid_rewrite (leibniz_equiv_iff (A:=A))
end.
Ltac unfold_leibniz := repeat
match goal with
| H : context [ @eq ?A _ _ ] |- _ =>
setoid_rewrite <-(leibniz_equiv_iff (A:=A)) in H
| |- context [ @eq ?A _ _ ] =>
setoid_rewrite <-(leibniz_equiv_iff (A:=A))
end.
Definition equivL {A} : Equiv A := (=).
(** A [Params f n] instance forces the setoid rewriting mechanism not to
rewrite in the first [n] arguments of the function [f]. We will declare such
instances for all operational type classes in this development. *)
Instance: Params (@equiv) 2.
(** The following instance forces [setoid_replace] to use setoid equality
(for types that have an [Equiv] instance) rather than the standard Leibniz
equality. *)
Instance equiv_default_relation `{Equiv A} : DefaultRelation () | 3.
Hint Extern 0 (_ _) => reflexivity.
Hint Extern 0 (_ _) => symmetry; assumption.
(** * Type classes *)
(** ** Decidable propositions *)
(** This type class by (Spitters/van der Weegen, 2011) collects decidable
propositions. For example to declare a parameter expressing decidable equality
on a type [A] we write [`{∀ x y : A, Decision (x = y)}] and use it by writing
[decide (x = y)]. *)
Class Decision (P : Prop) := decide : {P} + {¬P}.
Arguments decide _ {_}.
Notation EqDecision A := ( x y : A, Decision (x = y)).
(** ** Inhabited types *)
(** This type class collects types that are inhabited. *)
Class Inhabited (A : Type) : Type := populate { inhabitant : A }.
Arguments populate {_} _.
(** ** Proof irrelevant types *)
(** This type class collects types that are proof irrelevant. That means, all
elements of the type are equal. We use this notion only used for propositions,
but by universe polymorphism we can generalize it. *)
Class ProofIrrel (A : Type) : Prop := proof_irrel (x y : A) : x = y.
(** ** Common properties *)
(** These operational type classes allow us to refer to common mathematical
properties in a generic way. For example, for injectivity of [(k ++)] it
allows us to write [inj (k ++)] instead of [app_inv_head k]. *)
Class Inj {A B} (R : relation A) (S : relation B) (f : A B) : Prop :=
inj x y : S (f x) (f y) R x y.
Class Inj2 {A B C} (R1 : relation A) (R2 : relation B)
(S : relation C) (f : A B C) : Prop :=
inj2 x1 x2 y1 y2 : S (f x1 x2) (f y1 y2) R1 x1 y1 R2 x2 y2.
Class Cancel {A B} (S : relation B) (f : A B) (g : B A) : Prop :=
cancel : x, S (f (g x)) x.
Class Surj {A B} (R : relation B) (f : A B) :=
surj y : x, R (f x) y.
Class IdemP {A} (R : relation A) (f : A A A) : Prop :=
idemp x : R (f x x) x.
Class Comm {A B} (R : relation A) (f : B B A) : Prop :=
comm x y : R (f x y) (f y x).
Class LeftId {A} (R : relation A) (i : A) (f : A A A) : Prop :=
left_id x : R (f i x) x.
Class RightId {A} (R : relation A) (i : A) (f : A A A) : Prop :=
right_id x : R (f x i) x.
Class Assoc {A} (R : relation A) (f : A A A) : Prop :=
assoc x y z : R (f x (f y z)) (f (f x y) z).
Class LeftAbsorb {A} (R : relation A) (i : A) (f : A A A) : Prop :=
left_absorb x : R (f i x) i.
Class RightAbsorb {A} (R : relation A) (i : A) (f : A A A) : Prop :=
right_absorb x : R (f x i) i.
Class AntiSymm {A} (R S : relation A) : Prop :=
anti_symm x y : S x y S y x R x y.
Class Total {A} (R : relation A) := total x y : R x y R y x.
Class Trichotomy {A} (R : relation A) :=
trichotomy x y : R x y x = y R y x.
Class TrichotomyT {A} (R : relation A) :=
trichotomyT x y : {R x y} + {x = y} + {R y x}.
Arguments irreflexivity {_} _ {_} _ _.
Arguments inj {_ _ _ _} _ {_} _ _ _.
Arguments inj2 {_ _ _ _ _ _} _ {_} _ _ _ _ _.
Arguments cancel {_ _ _} _ _ {_} _.
Arguments surj {_ _ _} _ {_} _.
Arguments idemp {_ _} _ {_} _.
Arguments comm {_ _ _} _ {_} _ _.
Arguments left_id {_ _} _ _ {_} _.
Arguments right_id {_ _} _ _ {_} _.
Arguments assoc {_ _} _ {_} _ _ _.
Arguments left_absorb {_ _} _ _ {_} _.
Arguments right_absorb {_ _} _ _ {_} _.
Arguments anti_symm {_ _} _ {_} _ _ _ _.
Arguments total {_} _ {_} _ _.
Arguments trichotomy {_} _ {_} _ _.
Arguments trichotomyT {_} _ {_} _ _.
Lemma not_symmetry `{R : relation A, !Symmetric R} x y : ¬R x y ¬R y x.
Proof. intuition. Qed.
Lemma symmetry_iff `(R : relation A) `{!Symmetric R} x y : R x y R y x.
Proof. intuition. Qed.
Lemma not_inj `{Inj A B R R' f} x y : ¬R x y ¬R' (f x) (f y).
Proof. intuition. Qed.
Lemma not_inj2_1 `{Inj2 A B C R R' R'' f} x1 x2 y1 y2 :
¬R x1 x2 ¬R'' (f x1 y1) (f x2 y2).
Proof. intros HR HR''. destruct (inj2 f x1 y1 x2 y2); auto. Qed.
Lemma not_inj2_2 `{Inj2 A B C R R' R'' f} x1 x2 y1 y2 :
¬R' y1 y2 ¬R'' (f x1 y1) (f x2 y2).
Proof. intros HR' HR''. destruct (inj2 f x1 y1 x2 y2); auto. Qed.
Lemma inj_iff {A B} {R : relation A} {S : relation B} (f : A B)
`{!Inj R S f} `{!Proper (R ==> S) f} x y : S (f x) (f y) R x y.
Proof. firstorder. Qed.
Instance inj2_inj_1 `{Inj2 A B C R1 R2 R3 f} y : Inj R1 R3 (λ x, f x y).
Proof. repeat intro; edestruct (inj2 f); eauto. Qed.
Instance inj2_inj_2 `{Inj2 A B C R1 R2 R3 f} x : Inj R2 R3 (f x).
Proof. repeat intro; edestruct (inj2 f); eauto. Qed.
Lemma cancel_inj `{Cancel A B R1 f g, !Equivalence R1, !Proper (R2 ==> R1) f} :
Inj R1 R2 g.
Proof.
intros x y E. rewrite <-(cancel f g x), <-(cancel f g y), E. reflexivity.
Qed.
Lemma cancel_surj `{Cancel A B R1 f g} : Surj R1 f.
Proof. intros y. exists (g y). auto. Qed.
(** The following lemmas are specific versions of the projections of the above
type classes for Leibniz equality. These lemmas allow us to enforce Coq not to
use the setoid rewriting mechanism. *)
Lemma idemp_L {A} f `{!@IdemP A (=) f} x : f x x = x.
Proof. auto. Qed.
Lemma comm_L {A B} f `{!@Comm A B (=) f} x y : f x y = f y x.
Proof. auto. Qed.
Lemma left_id_L {A} i f `{!@LeftId A (=) i f} x : f i x = x.
Proof. auto. Qed.
Lemma right_id_L {A} i f `{!@RightId A (=) i f} x : f x i = x.
Proof. auto. Qed.
Lemma assoc_L {A} f `{!@Assoc A (=) f} x y z : f x (f y z) = f (f x y) z.
Proof. auto. Qed.
Lemma left_absorb_L {A} i f `{!@LeftAbsorb A (=) i f} x : f i x = i.
Proof. auto. Qed.
Lemma right_absorb_L {A} i f `{!@RightAbsorb A (=) i f} x : f x i = i.
Proof. auto. Qed.
(** ** Generic orders *)
(** The classes [PreOrder], [PartialOrder], and [TotalOrder] use an arbitrary
relation [R] instead of [⊆] to support multiple orders on the same type. *)
Definition strict {A} (R : relation A) : relation A := λ X Y, R X Y ¬R Y X.
Instance: Params (@strict) 2.
Class PartialOrder {A} (R : relation A) : Prop := {
partial_order_pre :> PreOrder R;
partial_order_anti_symm :> AntiSymm (=) R
}.
Class TotalOrder {A} (R : relation A) : Prop := {
total_order_partial :> PartialOrder R;
total_order_trichotomy :> Trichotomy (strict R)
}.
(** * Logic *)
Notation "(∧)" := and (only parsing) : C_scope.
Notation "( A ∧)" := (and A) (only parsing) : C_scope.
Notation "(∧ B )" := (λ A, A B) (only parsing) : C_scope.
Notation "(∨)" := or (only parsing) : C_scope.
Notation "( A ∨)" := (or A) (only parsing) : C_scope.
Notation "(∨ B )" := (λ A, A B) (only parsing) : C_scope.
Notation "(↔)" := iff (only parsing) : C_scope.
Notation "( A ↔)" := (iff A) (only parsing) : C_scope.
Notation "(↔ B )" := (λ A, A B) (only parsing) : C_scope.
Hint Extern 0 (_ _) => reflexivity.
Hint Extern 0 (_ _) => symmetry; assumption.
Lemma or_l P Q : ¬Q P Q P.
Proof. tauto. Qed.
Lemma or_r P Q : ¬P P Q Q.
Proof. tauto. Qed.
Lemma and_wlog_l (P Q : Prop) : (Q P) Q (P Q).
Proof. tauto. Qed.
Lemma and_wlog_r (P Q : Prop) : P (P Q) (P Q).
Proof. tauto. Qed.
Lemma impl_transitive (P Q R : Prop) : (P Q) (Q R) (P R).
Proof. tauto. Qed.
Lemma forall_proper {A} (P Q : A Prop) :
( x, P x Q x) ( x, P x) ( x, Q x).
Proof. firstorder. Qed.
Lemma exist_proper {A} (P Q : A Prop) :
( x, P x Q x) ( x, P x) ( x, Q x).
Proof. firstorder. Qed.
Instance: Comm () (@eq A).
Proof. red; intuition. Qed.
Instance: Comm () (λ x y, @eq A y x).
Proof. red; intuition. Qed.
Instance: Comm () ().
Proof. red; intuition. Qed.
Instance: Comm () ().
Proof. red; intuition. Qed.
Instance: Assoc () ().
Proof. red; intuition. Qed.
Instance: IdemP () ().
Proof. red; intuition. Qed.
Instance: Comm () ().
Proof. red; intuition. Qed.
Instance: Assoc () ().
Proof. red; intuition. Qed.
Instance: IdemP () ().
Proof. red; intuition. Qed.
Instance: LeftId () True ().
Proof. red; intuition. Qed.
Instance: RightId () True ().
Proof. red; intuition. Qed.
Instance: LeftAbsorb () False ().
Proof. red; intuition. Qed.
Instance: RightAbsorb () False ().
Proof. red; intuition. Qed.
Instance: LeftId () False ().