Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
Actris
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Iris
Actris
Commits
7b66c532
Commit
7b66c532
authored
1 year ago
by
Jonas Kastberg
Browse files
Options
Downloads
Patches
Plain Diff
Refactoring
parent
206ac1d7
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!39
Multiparty synchronous
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
multi_actris/examples/leader_election.v
+32
-32
32 additions, 32 deletions
multi_actris/examples/leader_election.v
with
32 additions
and
32 deletions
multi_actris/examples/leader_election.v
+
32
−
32
View file @
7b66c532
...
...
@@ -4,29 +4,29 @@ From iris.heap_lang.lib Require Import assert.
(** Inspired by https://en.wikipedia.org/wiki/Chang_and_Roberts_algorithm *)
Definition
process
:
val
:=
rec
:
"go"
"c"
"idl"
"id
r
"
"id"
"i
d_max"
"is_participant
"
:=
rec
:
"go"
"c"
"idl"
"id"
"id
r
"
"i
sp"
"id_max
"
:=
if
:
recv
"c"
"idr"
then
let
:
"id'"
:=
recv
"c"
"idr"
in
if
:
"id_max"
<
"id'"
(** Case 1 *)
then
send
"c"
"idl"
#
true
;;
send
"c"
"idl"
"id'"
;;
"go"
"c"
"idl"
"id
r
"
"id"
"i
d'
"
"i
s_participant
"
"go"
"c"
"idl"
"id"
"id
r
"
"i
sp
"
"i
d'
"
else
if
:
"id_max"
=
"id'"
(** Case 4 *)
then
send
"c"
"idl"
#
false
;;
send
"c"
"idl"
"id_max"
;;
"go"
"c"
"idl"
"id
r
"
"id"
"id_max"
#
false
else
if
:
"is
_participant
"
(** Case 3 *)
then
"go"
"c"
"idl"
"id
r
"
"id"
"i
d_max"
"is_participant
"
(** Case 2 *)
"go"
"c"
"idl"
"id"
"id
r
"
#
false
"id_max"
else
if
:
"is
p
"
(** Case 3 *)
then
"go"
"c"
"idl"
"id"
"id
r
"
"i
sp"
"id_max
"
(** Case 2 *)
else
send
"c"
"idl"
#
true
;;
send
"c"
"idl"
"id_max"
;;
"go"
"c"
"idl"
"id
r
"
"id"
"id_max"
#
true
"go"
"c"
"idl"
"id"
"id
r
"
#
true
"id_max"
else
let
:
"id'"
:=
recv
"c"
"idr"
in
assert
:
(
"id_max"
=
"id'"
);;
if
:
"id"
=
"id'"
then
"id'"
else
send
"c"
"idl"
#
false
;;
send
"c"
"idl"
"id_max"
;;
"id_max"
.
Definition
init
:
val
:=
λ
:
"c"
"idl"
"id
r
"
"id"
,
λ
:
"c"
"idl"
"id"
"id
r
"
,
(* Notice missing leader *)
send
"c"
"idl"
#
true
;;
send
"c"
"idl"
"id"
;;
process
"c"
"idl"
"idr"
"id"
"id"
#
true
.
process
"c"
"idl"
"id"
"id
r
"
#
true
"id"
.
Definition
program
:
val
:=
λ
:
<>
,
...
...
@@ -35,10 +35,10 @@ Definition program : val :=
let
:
"c1"
:=
get_chan
"cs"
#
1
in
let
:
"c2"
:=
get_chan
"cs"
#
2
in
let
:
"c3"
:=
get_chan
"cs"
#
3
in
Fork
(
let
:
"id_max"
:=
init
"c1"
#
3
#
2
#
1
in
send
"c1"
#
0
"id_max"
);;
Fork
(
let
:
"id_max"
:=
process
"c2"
#
1
#
3
#
2
#
2
#
false
in
Fork
(
let
:
"id_max"
:=
init
"c1"
#
3
#
1
#
2
in
send
"c1"
#
0
"id_max"
);;
Fork
(
let
:
"id_max"
:=
process
"c2"
#
1
#
2
#
3
#
false
#
2
in
send
"c2"
#
0
"id_max"
);;
Fork
(
let
:
"id_max"
:=
init
"c3"
#
2
#
1
#
3
in
send
"c3"
#
0
"id_max"
);;
Fork
(
let
:
"id_max"
:=
init
"c3"
#
2
#
3
#
1
in
send
"c3"
#
0
"id_max"
);;
let
:
"res1"
:=
recv
"c0"
#
1
in
let
:
"res2"
:=
recv
"c0"
#
2
in
let
:
"res3"
:=
recv
"c0"
#
3
in
...
...
@@ -51,7 +51,7 @@ Notation iProto_choice a p1 p2 :=
Section
ring_leader_election_example
.
Context
`{
!
heapGS
Σ
,
chanG
Σ
,
spawnG
Σ
,
mono_natG
Σ
}
.
Definition
my_recv_prot
(
il
i
r
i
:
nat
)
(
p
:
nat
→
iProto
Σ
)
Definition
my_recv_prot
(
il
i
i
r
:
nat
)
(
p
:
nat
→
iProto
Σ
)
(
rec
:
bool
-
d
>
nat
-
d
>
iProto
Σ
)
:
bool
-
d
>
nat
-
d
>
iProto
Σ
:=
λ
(
isp
:
bool
)
(
i_max
:
nat
),
iProto_choice
(
Recv
,
ir
)
...
...
@@ -68,25 +68,25 @@ Section ring_leader_election_example.
if
(
bool_decide
(
i
=
i_max
))
then
p
i_max
else
<
(
Send
,
il
)
>
MSG
#
false
;
<
(
Send
,
il
)
>
MSG
#
i_max
;
p
i_max
)
%
proto
.
Instance
rle_prot_aux_contractive
il
i
r
i
p
:
Contractive
(
my_recv_prot
il
i
r
i
p
)
.
Instance
rle_prot_aux_contractive
il
i
i
r
p
:
Contractive
(
my_recv_prot
il
i
i
r
p
)
.
Proof
.
rewrite
/
my_recv_prot
.
solve_proto_contractive
.
Qed
.
Definition
rle_prot
il
i
r
i
p
:=
fixpoint
(
my_recv_prot
il
i
r
i
p
)
.
Instance
rle_prot_unfold
il
i
r
i
isp
max_id
p
:
ProtoUnfold
(
rle_prot
il
i
r
i
p
isp
max_id
)
(
my_recv_prot
il
i
r
i
p
(
rle_prot
il
i
r
i
p
)
isp
max_id
)
.
Proof
.
apply
proto_unfold_eq
,
(
fixpoint_unfold
(
my_recv_prot
il
i
r
i
p
))
.
Qed
.
Lemma
rle_prot_unfold'
il
i
r
i
isp
max_id
p
:
(
rle_prot
il
i
r
i
p
isp
max_id
)
≡
(
my_recv_prot
il
i
r
i
p
(
rle_prot
il
i
r
i
p
)
isp
max_id
)
.
Proof
.
apply
(
fixpoint_unfold
(
my_recv_prot
il
i
r
i
p
))
.
Qed
.
Definition
rle_prot
il
i
i
r
p
:=
fixpoint
(
my_recv_prot
il
i
i
r
p
)
.
Instance
rle_prot_unfold
il
i
i
r
isp
max_id
p
:
ProtoUnfold
(
rle_prot
il
i
i
r
p
isp
max_id
)
(
my_recv_prot
il
i
i
r
p
(
rle_prot
il
i
i
r
p
)
isp
max_id
)
.
Proof
.
apply
proto_unfold_eq
,
(
fixpoint_unfold
(
my_recv_prot
il
i
i
r
p
))
.
Qed
.
Lemma
rle_prot_unfold'
il
i
i
r
isp
max_id
p
:
(
rle_prot
il
i
i
r
p
isp
max_id
)
≡
(
my_recv_prot
il
i
i
r
p
(
rle_prot
il
i
i
r
p
)
isp
max_id
)
.
Proof
.
apply
(
fixpoint_unfold
(
my_recv_prot
il
i
i
r
p
))
.
Qed
.
Definition
rle_preprot
(
il
i
r
i
:
nat
)
p
:
iProto
Σ
:=
Definition
rle_preprot
(
il
i
i
r
:
nat
)
p
:
iProto
Σ
:=
(
<
(
Send
,
il
)
>
MSG
#
true
;
<
(
Send
,
il
)
>
MSG
#
i
;
rle_prot
il
i
r
i
p
true
i
)
%
proto
.
rle_prot
il
i
i
r
p
true
i
)
%
proto
.
Lemma
process_spec
il
i
r
i
p
i_max
c
(
isp
:
bool
)
:
Lemma
process_spec
il
i
i
r
p
i_max
c
(
isp
:
bool
)
:
i
<=
i_max
→
{{{
c
↣
(
rle_prot
il
i
r
i
p
isp
i_max
)
}}}
process
c
#
il
#
ir
#
i
#
i_max
#
isp
{{{
c
↣
(
rle_prot
il
i
i
r
p
isp
i_max
)
}}}
process
c
#
il
#
i
#
ir
#
i
sp
#
i_max
{{{
i'
,
RET
#
i'
;
c
↣
p
i'
}}}
.
Proof
.
iIntros
(
Hle
Φ
)
"Hc HΦ"
.
...
...
@@ -135,9 +135,9 @@ Section ring_leader_election_example.
wp_send
with
"[//]"
.
wp_send
with
"[//]"
.
wp_pures
.
by
iApply
"HΦ"
.
Qed
.
Lemma
init_spec
c
il
i
r
i
p
:
{{{
c
↣
rle_preprot
il
i
r
i
p
}}}
init
c
#
il
#
i
r
#
i
Lemma
init_spec
c
il
i
i
r
p
:
{{{
c
↣
rle_preprot
il
i
i
r
p
}}}
init
c
#
il
#
i
#
i
r
{{{
res
,
RET
#
res
;
c
↣
p
res
}}}
.
Proof
.
iIntros
(
Φ
)
"Hc HΦ"
.
wp_lam
.
wp_send
with
"[//]"
.
wp_send
with
"[//]"
.
...
...
@@ -165,9 +165,9 @@ Section ring_leader_election_example.
<
(
Recv
,
2
)
>
MSG
#
id_max
;
<
(
Recv
,
3
)
>
MSG
#
id_max
;
END
)
%
proto
]
>
(
<
[
1
:=
rle_preprot
3
2
1
prot_tail
]
>
(
<
[
2
:=
rle_prot
1
3
2
prot_tail
false
2
]
>
(
<
[
3
:=
rle_preprot
2
1
3
prot_tail
]
>
∅
)))
.
(
<
[
1
:=
rle_preprot
3
1
2
prot_tail
]
>
(
<
[
2
:=
rle_prot
1
2
3
prot_tail
false
2
]
>
(
<
[
3
:=
rle_preprot
2
3
1
prot_tail
]
>
∅
)))
.
Lemma
prot_pool_consistent
:
⊢
iProto_consistent
prot_pool
.
Proof
.
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment