Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,13 @@ jobs:
opam-pin: false

- name: Install opam dependencies
run: |
opam pin add --no-action warblre.0.1.0 https://github.com/epfl-systemf/Warblre.git#a1ffc3f2e47d942ad9e1194dfb71f0783ead6d8a
run: |
# keep the Warblre ref in sync with the README
opam pin add --no-action warblre.0.1.0 https://github.com/epfl-systemf/Warblre.git#c7b021e61d580b6061f0b040ca04d8e1b40e9de4
opam install . --deps-only

- name: Dune build
run: opam exec -- dune build
run: opam exec -- dune build

- name: Check compiled libraries (coqchk)
run: opam exec -- coqchk -silent --output-context $(cat _CoqProject) _build/default/*/*.vo
- name: Check compiled libraries (rocqchk)
run: opam exec -- rocqchk -silent --output-context -R _build/default Linden _build/default/*/*.vo
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ _build
_opam
\#*.*\#
*.v~
_RocqProject
8 changes: 4 additions & 4 deletions Engine/BooleanSemantics.v
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Require Import List Lia.
From Stdlib Require Import List Lia.
Import ListNotations.

From Linden Require Import Regex Chars Groups.
Expand Down Expand Up @@ -138,7 +138,7 @@ Inductive bool_encoding: LoopBool -> input -> actions -> Prop :=
(ENCODE: bool_encoding b str cont),
bool_encoding b str (Aclose gid::cont)
| cons_true:
forall stk str head
forall stk str head
(ENCODE: bool_encoding CanExit str stk)
(STRICT: strict_suffix str head forward),
bool_encoding CanExit str (Acheck head::stk)
Expand Down Expand Up @@ -191,7 +191,7 @@ Proof.
intros b str cont H.
remember (Acheck str::cont) as prevcont.
induction H; intros; auto; inversion Heqprevcont.
subst. apply ss_neq in STRICT. contradiction.
subst. apply ss_neq in STRICT. contradiction.
Qed.

Lemma encode_next:
Expand Down Expand Up @@ -321,7 +321,7 @@ Proof.
intros r str t PIKE H.
eapply encode_equal; eauto.
{ constructor; constructor; auto. }
constructor. constructor.
constructor. constructor.
Qed.


Expand Down
32 changes: 16 additions & 16 deletions Engine/Complexity.v
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(** * Complexity of the PikeVM algorithm *)

Require Import List Lia.
From Stdlib Require Import List Lia.
Import ListNotations.

From Linden Require Import Regex Chars Groups.
Expand Down Expand Up @@ -232,7 +232,7 @@ Proof.
assert (S (length next) > S n) by lia.
specialize (IHn (c::pref) next H0). rewrite advance_S_n.
simpl in IHn. simpl. lia.
Qed.
Qed.


(** * Well-formedness of the code *)
Expand All @@ -245,7 +245,7 @@ Lemma compilation_nonempty:
forall r, nonempty (compilation r).
Proof.
intros. unfold compilation. destruct compile. unfold nonempty, size.
rewrite app_length. simpl. lia.
rewrite length_app. simpl. lia.
Qed.

(* Some bytecode is well-formed if every target label belongs in some range *)
Expand Down Expand Up @@ -361,7 +361,7 @@ Proof.
intros pc i next GET IN.
assert (HL: pc < length (c ++ [Accept])).
{ eapply nth_error_Some. unfold get_pc in GET. rewrite GET. intros HI. inversion HI. }
rewrite app_length in HL. simpl in HL.
rewrite length_app in HL. simpl in HL.
assert (pc = length c \/ pc < length c) as [ACC|H1] by lia.
(* accept *)
{ subst. assert (get_pc (c ++ [Accept]) (length c) = get_pc [Accept] 0).
Expand All @@ -373,7 +373,7 @@ Proof.
{ unfold get_pc in GET. rewrite nth_error_app1 in GET; auto. }
assert (POS: pc >= 0) by lia.
specialize (nfa_wf r c 0 (length c) pc next i REP POS H1 GETI IN) as WF.
unfold size. rewrite app_length. simpl. lia.
unfold size. rewrite length_app. simpl. lia.
Qed.

Lemma eps_step_blocked_wf:
Expand Down Expand Up @@ -477,7 +477,7 @@ Proof.
subst. unfold pike_vm_initial_thread. simpl. auto.
+ constructor.
+ intros n0 lit0 H. eapply search_in_range; eauto.
+ unfold measure. simpl. rewrite free_initial. specialize (advance_n_inpsize inp n RANGEPREF)as ADV.
+ unfold measure. simpl. rewrite free_initial. specialize (advance_n_inpsize inp n RANGEPREF)as ADV.
apply increase_mult with (x:= 4 * size code) in ADV as NEXT. simpl in NEXT. lia.
(* end *)
- exists 0. split.
Expand All @@ -498,7 +498,7 @@ Proof.
+ intros n lit0 H. eapply search_in_range; eauto.
+ unfold measure. simpl. rewrite free_initial. apply advance_input_decreases in ADVANCE.
apply increase_mult with (x:= 4 * size code) in ADVANCE as NEXT. simpl in NEXT.
rewrite app_length. simpl. lia.
rewrite length_app. simpl. lia.
(* nextchar_filter: we might add (2*codesize) free slots, but we lose an input length *)
- exists (measure (size code) [] (thr::blocked) [] inp2). split; [constructor|]; auto.
+ constructor.
Expand All @@ -520,7 +520,7 @@ Proof.
+ unfold add_thread. apply wf_new; auto.
+ specialize (free_add seen (size code) dist (pc,gm,b) SEENWF UNSEEN) as FREE.
apply wf_size in FREE; auto. apply eps_step_active in STEP0.
unfold measure, free. rewrite app_length. simpl. simpl in FREE. lia.
unfold measure, free. rewrite length_app. simpl. simpl in FREE. lia.
(* match: we lose a thread and a free slot *)
- assert (RANGE: pc < size code).
{ specialize (ACTIVEWF (pc,gm,b) ltac:(simpl;left;auto)). simpl in ACTIVEWF. auto. }
Expand All @@ -541,7 +541,7 @@ Proof.
eapply eps_step_blocked_wf in STEP0 as [i [GET IN]]; eauto.
+ unfold add_thread. apply wf_new; auto.
+ specialize (free_add seen (size code) dist (pc,gm,b) SEENWF UNSEEN RANGE) as FREE.
apply wf_size in FREE. unfold measure, free. rewrite app_length. simpl. simpl in FREE. lia.
apply wf_size in FREE. unfold measure, free. rewrite length_app. simpl. simpl in FREE. lia.
Qed.

(** * Code Size *)
Expand Down Expand Up @@ -579,23 +579,23 @@ Proof.
- destruct (compile r1 (S start)) eqn:C1. destruct (compile r2 (S l)) eqn:C2.
erewrite <- IHr1; eauto. 2: pike_subset.
erewrite <- IHr2; eauto. 2: pike_subset.
inversion COMP. subst. simpl. rewrite app_length. simpl. lia.
inversion COMP. subst. simpl. rewrite length_app. simpl. lia.
- destruct (compile r1 start) eqn:C1. destruct (compile r2 l) eqn:C2.
erewrite <- IHr1; eauto. 2: pike_subset.
erewrite <- IHr2; eauto. 2: pike_subset.
inversion COMP. subst. simpl. rewrite app_length. simpl. lia.
inversion COMP. subst. simpl. rewrite length_app. simpl. lia.
- destruct min; destruct (destruct_delta delta) as [DZ | [D1 | [DINF | [delta' [DUN N3]]]]]; subst; try solve[pike_subset].
+ inversion COMP. auto.
+ destruct (compile r (S (S (S start)))) eqn:C1.
erewrite <- IHr; eauto. 2: pike_subset.
inversion COMP. subst. simpl. rewrite app_length. simpl. lia.
inversion COMP. subst. simpl. rewrite length_app. simpl. lia.
+ destruct (compile r (S (S (S start)))) eqn:C1.
erewrite <- IHr; eauto. 2: pike_subset.
inversion COMP. subst. simpl. rewrite app_length. simpl. lia.
inversion COMP. subst. simpl. rewrite length_app. simpl. lia.
+ inversion SUBSET; subst; lia.
- destruct (compile r (S start)) eqn:C1.
erewrite <- IHr; eauto. 2: pike_subset.
inversion COMP. subst. simpl. rewrite app_length. simpl. lia.
inversion COMP. subst. simpl. rewrite length_app. simpl. lia.
Qed.

Theorem compilation_size:
Expand All @@ -604,7 +604,7 @@ Theorem compilation_size:
size (compilation r) = codesize r.
Proof.
unfold codesize, size, compilation. intros r H. destruct (compile r 0) eqn:COMP.
apply compile_size in COMP; auto. rewrite <- COMP. rewrite app_length. simpl. lia.
apply compile_size in COMP; auto. rewrite <- COMP. rewrite length_app. simpl. lia.
Qed.

(* relating this compilation size to the size of the regex *)
Expand Down Expand Up @@ -642,7 +642,7 @@ Proof.
- unfold pike_vm_initial_state. rewrite <- compilation_size; auto.
constructor; auto.
+ intros t H. destruct H. 2: inversion H.
subst. simpl. unfold compilation. destruct (compile r 0) eqn:C. unfold size. rewrite app_length.
subst. simpl. unfold compilation. destruct (compile r 0) eqn:C. unfold size. rewrite length_app.
simpl. lia.
+ intros t H. inversion H.
+ constructor.
Expand Down
6 changes: 3 additions & 3 deletions Engine/Correctness.v
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(** * Correctness theorems for the PikeVM engine *)

Require Import List Lia.
From Stdlib Require Import List Lia.
Import ListNotations.

From Linden Require Import Regex Chars Groups.
Expand Down Expand Up @@ -254,7 +254,7 @@ Qed.
(* Any execution of MemoBT to a final state corresponds to an execution of MemoTree *)
Theorem memobt_to_memotree:
forall r inp tree result,
pike_regex r ->
pike_regex r ->
bool_tree rer [Areg r] inp CanExit tree ->
trc_memo_bt (compilation r) (MemoBT.initial_state inp) (MBT_final result) ->
trc_memo_tree (initial_tree_state tree inp) (MTree_final result).
Expand All @@ -279,7 +279,7 @@ Proof.
apply IHTRC. eapply memotree_preservation; eauto.
Qed.


(** * Correctness Theorem of the PikeVM result *)

Theorem memobt_correct:
Expand Down
6 changes: 3 additions & 3 deletions Engine/FunctionalPikeVM.v
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(* The PikeVm algorithm, expressed as a fuel-based function *)

Require Import List Lia.
From Stdlib Require Import List Lia.
Import ListNotations.

From Linden Require Import Regex Chars Groups.
Expand Down Expand Up @@ -76,7 +76,7 @@ Fixpoint pike_vm_loop (c:code) (pvs:pike_vm_state) (fuel:nat) : pike_vm_state :=

(* an upper bound for the fuel necessary to compute a result *)
Definition vm_fuel (r:regex) (inp:input) : nat :=
complexity r inp.
complexity r inp.

Inductive matchres : Type :=
| OutOfFuel
Expand Down Expand Up @@ -206,7 +206,7 @@ End FunctionalPikeVM.

From Linden Require Import Inst.
From Warblre Require Import Inst.
Require Import Coq.Strings.Ascii Coq.Strings.String.
Require Import Stdlib.Strings.Ascii Stdlib.Strings.String.
Open Scope string_scope.

Section Example.
Expand Down
8 changes: 4 additions & 4 deletions Engine/MemoBT.v
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
(** * MemoBT algorithm *)
(* A backtracking algorithm on the extended NFA, with memoization *)

Require Import List Lia.
From Stdlib Require Import List Lia.
Import ListNotations.

From Linden Require Import Regex Chars Groups.
Expand Down Expand Up @@ -35,7 +35,7 @@ Section MemoBT.
MBT [(0, GroupMap.empty, CanExit, inp)] initial_memoset.

(** * MemoBT small-step semantics *)

Inductive exec_result : Type :=
| FoundMatch: leaf -> exec_result
| Explore: stack -> exec_result.
Expand Down Expand Up @@ -77,7 +77,7 @@ Section MemoBT.
end
end.


Inductive memobt_step (c:code) : mbt_state -> mbt_state -> Prop :=
(* we exhausted all configurations, there is no match *)
| mbt_nomatch: forall ms,
Expand All @@ -102,7 +102,7 @@ Section MemoBT.

(** * MemoBT properties *)

Theorem memobt_deterministic:
Theorem memobt_deterministic:
forall c mbs mbs1 mbs2
(STEP1: memobt_step c mbs mbs1)
(STEP2: memobt_step c mbs mbs2),
Expand Down
Loading