Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
L
lambda-rust
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Service Desk
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
lambda-rust
Commits
f4930b01
Commit
f4930b01
authored
7 years ago
by
Jacques-Henri Jourdan
Browse files
Options
Downloads
Patches
Plain Diff
weak_count and strong_count for Arc.
parent
4a90389f
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
theories/lang/lib/arc.v
+39
-1
39 additions, 1 deletion
theories/lang/lib/arc.v
theories/typing/lib/arc.v
+87
-2
87 additions, 2 deletions
theories/typing/lib/arc.v
with
126 additions
and
3 deletions
theories/lang/lib/arc.v
+
39
−
1
View file @
f4930b01
...
...
@@ -7,7 +7,11 @@ From iris.algebra Require Import excl csum frac auth.
From
lrust
.
lang
Require
Import
lang
proofmode
notation
new_delete
.
Set
Default
Proof
Using
"Type"
.
(* TODO : get_mut, make_mut *)
Definition
strong_count
:
val
:=
λ
:
[
"l"
],
!
ˢᶜ
"l"
.
Definition
weak_count
:
val
:=
λ
:
[
"l"
],
!
ˢᶜ
(
"l"
+
ₗ
#
1
)
.
Definition
clone_arc
:
val
:=
rec
:
"clone"
[
"l"
]
:=
...
...
@@ -183,6 +187,40 @@ Section arc.
iExists
_,
_,
_,
_
.
iSplit
=>
//.
simpl
in
*.
destruct
decide
;
[
subst
;
lia
|
eauto
]
.
Qed
.
Lemma
strong_count_spec
(
γ
:
gname
)
(
l
:
loc
)
(
P
:
iProp
Σ
)
:
is_arc
P1
P2
N
γ
l
-∗
arc_tok_acc
γ
P
(
⊤
∖
↑
N
)
-∗
{{{
P
}}}
strong_count
[
#
l
]
{{{
(
c
:
nat
),
RET
#
c
;
P
∗
⌜
(
c
>
0
)
%
nat
⌝
}}}
.
Proof
using
HP1
.
iIntros
"#INV #Hacc !# * HP HΦ"
.
iLöb
as
"IH"
.
wp_rec
.
iInv
N
as
(
st
)
"[>H● H]"
"Hclose1"
.
iMod
(
"Hacc"
with
"HP"
)
as
(?)
"[Hown Hclose2]"
.
iDestruct
(
arc_tok_auth_val
with
"H● Hown"
)
as
%
(?
&
strong
&
?
&
?
&
[
->
_])
.
iDestruct
"H"
as
(?)
"(Hq & HP1 & H↦ & Hw)"
.
wp_read
.
iMod
(
"Hclose2"
with
"Hown"
)
as
"HP"
.
iModIntro
.
iMod
(
"Hclose1"
with
"[-HP HΦ]"
)
as
"_"
;
[
iExists
_;
auto
with
iFrame
|]
.
iModIntro
.
rewrite
-
positive_nat_Z
.
iApply
"HΦ"
.
auto
with
iFrame
lia
.
Qed
.
(* FIXME : in the case the weak count is locked, we can possibly
return -1. This problem already exists in Rust. *)
Lemma
weak_count_spec
(
γ
:
gname
)
(
l
:
loc
)
(
P
:
iProp
Σ
)
:
is_arc
P1
P2
N
γ
l
-∗
arc_tok_acc
γ
P
(
⊤
∖
↑
N
)
-∗
{{{
P
}}}
weak_count
[
#
l
]
{{{
(
c
:
Z
),
RET
#
c
;
P
∗
⌜
c
>=
-1
⌝
}}}
.
Proof
using
HP1
.
iIntros
"#INV #Hacc !# * HP HΦ"
.
iLöb
as
"IH"
.
wp_rec
.
wp_op
.
iInv
N
as
(
st
)
"[>H● H]"
"Hclose1"
.
iMod
(
"Hacc"
with
"HP"
)
as
(?)
"[Hown Hclose2]"
.
iDestruct
(
arc_tok_auth_val
with
"H● Hown"
)
as
%
(?
&
strong
&
wl
&
?
&
[
->
_])
.
iDestruct
"H"
as
(?)
"(Hq & HP1 & H↦ & Hw)"
.
destruct
wl
.
-
iDestruct
"Hw"
as
">[Hw %]"
.
wp_read
.
iMod
(
"Hclose2"
with
"Hown"
)
as
"HP"
.
iModIntro
.
iMod
(
"Hclose1"
with
"[-HP HΦ]"
)
as
"_"
;
[
iExists
_;
auto
with
iFrame
|]
.
iApply
"HΦ"
.
auto
with
iFrame
lia
.
-
wp_read
.
iMod
(
"Hclose2"
with
"Hown"
)
as
"HP"
.
iModIntro
.
iMod
(
"Hclose1"
with
"[-HP HΦ]"
)
as
"_"
;
[
iExists
_;
auto
with
iFrame
|]
.
iApply
"HΦ"
.
auto
with
iFrame
lia
.
Qed
.
Lemma
clone_arc_spec
(
γ
:
gname
)
(
l
:
loc
)
(
P
:
iProp
Σ
)
:
is_arc
P1
P2
N
γ
l
-∗
arc_tok_acc
γ
P
(
⊤
∖
↑
N
)
-∗
{{{
P
}}}
clone_arc
[
#
l
]
...
...
This diff is collapsed.
Click to expand it.
theories/typing/lib/arc.v
+
87
−
2
View file @
f4930b01
...
...
@@ -8,8 +8,6 @@ From lrust.typing Require Export type.
From
lrust
.
typing
Require
Import
typing
option
.
Set
Default
Proof
Using
"Type"
.
(* TODO : make_mut weak_count strong_count *)
Definition
arcN
:=
lrustN
.
@
"arc"
.
Definition
arc_invN
:=
arcN
.
@
"inv"
.
Definition
arc_shrN
:=
arcN
.
@
"shr"
.
...
...
@@ -454,6 +452,93 @@ Section arc.
iApply
type_jump
;
solve_typing
.
Qed
.
(* Code : getters *)
Definition
arc_strong_count
:
val
:=
funrec
:
<>
[
"arc"
]
:=
let
:
"r"
:=
new
[
#
1
]
in
let
:
"arc'"
:=
!
"arc"
in
let
:
"arc''"
:=
!
"arc'"
in
"r"
<-
strong_count
[
"arc''"
];;
delete
[
#
1
;
"arc"
];;
return
:
[
"r"
]
.
Lemma
arc_strong_count_type
ty
`{
!
TyWf
ty
}
:
typed_val
arc_strong_count
(
fn
(
∀
α
,
∅
;
&
shr
{
α
}
arc
ty
)
→
int
)
.
Proof
.
intros
E
L
.
iApply
type_fn
;
[
solve_typing
..|]
.
iIntros
"/= !#"
.
iIntros
(
α
ϝ
ret
arg
)
.
inv_vec
arg
=>
x
.
simpl_subst
.
iApply
(
type_new
1
);
[
solve_typing
..|];
iIntros
(
r
);
simpl_subst
.
iApply
type_deref
;
[
solve_typing
..|];
iIntros
(
rc'
);
simpl_subst
.
iIntros
(
tid
)
"#LFT #HE Hna HL Hk [Hx [Hrc' [Hr _]]]"
.
rewrite
!
tctx_hasty_val
[[
x
]]
lock
[[
r
]]
lock
.
destruct
rc'
as
[[|
lrc
|]|];
try
done
.
iDestruct
"Hrc'"
as
(
l'
)
"[#Hlrc #Hshr]"
.
(* All right, we are done preparing our context. Let's get going. *)
iMod
(
lctx_lft_alive_tok
α
with
"HE HL"
)
as
(
q
)
"([Hα1 Hα2] & HL & Hclose1)"
;
[
solve_typing
..|]
.
wp_bind
(
!
_)
%
E
.
iSpecialize
(
"Hshr"
with
"[] Hα1"
);
last
iApply
(
wp_step_fupd
with
"Hshr"
);
[
done
..|]
.
iMod
(
frac_bor_acc
with
"LFT Hlrc Hα2"
)
as
(
q'
)
"[Hlrc↦ Hclose]"
;
first
solve_ndisj
.
iApply
wp_fupd
.
wp_read
.
iMod
(
"Hclose"
with
"[$Hlrc↦]"
)
as
"Hα2"
.
clear
q'
.
iIntros
"!> [Hα1 Hproto]"
.
iDestruct
"Hproto"
as
(
γ
ν
q'
)
"#(Hαν & Hpersist & Hrctokb)"
.
iModIntro
.
wp_let
.
wp_apply
(
strong_count_spec
(
P1
ν
)
(
P2
l'
ty
.(
ty_size
))
_
_
_
(
q
.[
α
])
%
I
with
"[] [] [$Hα1 $Hα2]"
);
first
by
iDestruct
"Hpersist"
as
"[$ _]"
.
{
iIntros
"!# Hα"
.
iMod
(
shr_bor_acc_tok
with
"LFT Hrctokb Hα"
)
as
"[>Htok Hclose1]"
;
[
solve_ndisj
..|]
.
iExists
_
.
iFrame
.
iMod
fupd_intro_mask'
as
"Hclose2"
;
last
iModIntro
.
set_solver
.
iIntros
"Htok"
.
iMod
"Hclose2"
as
"_"
.
by
iApply
"Hclose1"
.
}
iIntros
(
c
)
"[Hα _]"
.
iMod
(
"Hclose1"
with
"Hα HL"
)
as
"HL"
.
(* Finish up the proof. *)
iApply
(
type_type
_
_
_
[
x
◁
box
(
&
shr
{
α
}
arc
ty
);
#
c
◁
int
;
r
◁
box
(
uninit
1
)]
with
"[] LFT HE Hna HL Hk [-]"
);
last
first
.
{
rewrite
2
!
tctx_interp_cons
tctx_interp_singleton
!
tctx_hasty_val
tctx_hasty_val'
//.
unlock
.
iFrame
.
}
iApply
type_assign
;
[
solve_typing
..|]
.
iApply
type_delete
;
[
solve_typing
..|]
.
iApply
type_jump
;
solve_typing
.
Qed
.
Definition
arc_weak_count
:
val
:=
funrec
:
<>
[
"arc"
]
:=
let
:
"r"
:=
new
[
#
1
]
in
let
:
"arc'"
:=
!
"arc"
in
let
:
"arc''"
:=
!
"arc'"
in
"r"
<-
weak_count
[
"arc''"
];;
delete
[
#
1
;
"arc"
];;
return
:
[
"r"
]
.
Lemma
arc_weak_count_type
ty
`{
!
TyWf
ty
}
:
typed_val
arc_weak_count
(
fn
(
∀
α
,
∅
;
&
shr
{
α
}
arc
ty
)
→
int
)
.
Proof
.
intros
E
L
.
iApply
type_fn
;
[
solve_typing
..|]
.
iIntros
"/= !#"
.
iIntros
(
α
ϝ
ret
arg
)
.
inv_vec
arg
=>
x
.
simpl_subst
.
iApply
(
type_new
1
);
[
solve_typing
..|];
iIntros
(
r
);
simpl_subst
.
iApply
type_deref
;
[
solve_typing
..|];
iIntros
(
rc'
);
simpl_subst
.
iIntros
(
tid
)
"#LFT #HE Hna HL Hk [Hx [Hrc' [Hr _]]]"
.
rewrite
!
tctx_hasty_val
[[
x
]]
lock
[[
r
]]
lock
.
destruct
rc'
as
[[|
lrc
|]|];
try
done
.
iDestruct
"Hrc'"
as
(
l'
)
"[#Hlrc #Hshr]"
.
(* All right, we are done preparing our context. Let's get going. *)
iMod
(
lctx_lft_alive_tok
α
with
"HE HL"
)
as
(
q
)
"([Hα1 Hα2] & HL & Hclose1)"
;
[
solve_typing
..|]
.
wp_bind
(
!
_)
%
E
.
iSpecialize
(
"Hshr"
with
"[] Hα1"
);
last
iApply
(
wp_step_fupd
with
"Hshr"
);
[
done
..|]
.
iMod
(
frac_bor_acc
with
"LFT Hlrc Hα2"
)
as
(
q'
)
"[Hlrc↦ Hclose]"
;
first
solve_ndisj
.
iApply
wp_fupd
.
wp_read
.
iMod
(
"Hclose"
with
"[$Hlrc↦]"
)
as
"Hα2"
.
clear
q'
.
iIntros
"!> [Hα1 Hproto]"
.
iDestruct
"Hproto"
as
(
γ
ν
q'
)
"#(Hαν & Hpersist & Hrctokb)"
.
iModIntro
.
wp_let
.
wp_apply
(
weak_count_spec
(
P1
ν
)
(
P2
l'
ty
.(
ty_size
))
_
_
_
(
q
.[
α
])
%
I
with
"[] [] [$Hα1 $Hα2]"
);
first
by
iDestruct
"Hpersist"
as
"[$ _]"
.
{
iIntros
"!# Hα"
.
iMod
(
shr_bor_acc_tok
with
"LFT Hrctokb Hα"
)
as
"[>Htok Hclose1]"
;
[
solve_ndisj
..|]
.
iExists
_
.
iFrame
.
iMod
fupd_intro_mask'
as
"Hclose2"
;
last
iModIntro
.
set_solver
.
iIntros
"Htok"
.
iMod
"Hclose2"
as
"_"
.
by
iApply
"Hclose1"
.
}
iIntros
(
c
)
"[Hα _]"
.
iMod
(
"Hclose1"
with
"Hα HL"
)
as
"HL"
.
(* Finish up the proof. *)
iApply
(
type_type
_
_
_
[
x
◁
box
(
&
shr
{
α
}
arc
ty
);
#
c
◁
int
;
r
◁
box
(
uninit
1
)]
with
"[] LFT HE Hna HL Hk [-]"
);
last
first
.
{
rewrite
2
!
tctx_interp_cons
tctx_interp_singleton
!
tctx_hasty_val
tctx_hasty_val'
//.
unlock
.
iFrame
.
}
iApply
type_assign
;
[
solve_typing
..|]
.
iApply
type_delete
;
[
solve_typing
..|]
.
iApply
type_jump
;
solve_typing
.
Qed
.
(* Code : clone, [up/down]grade. *)
Definition
arc_clone
:
val
:=
funrec
:
<>
[
"arc"
]
:=
...
...
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