Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
iGPS
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
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
FP
iGPS
Commits
966bf03d
Commit
966bf03d
authored
7 years ago
by
Janno
Browse files
Options
Downloads
Patches
Plain Diff
Port sc_stack.v.
parent
7cd72123
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
theories/examples/sc_stack.v
+89
-96
89 additions, 96 deletions
theories/examples/sc_stack.v
with
89 additions
and
96 deletions
theories/examples/sc_stack.v
+
89
−
96
View file @
966bf03d
...
@@ -10,6 +10,7 @@ Import uPred.
...
@@ -10,6 +10,7 @@ Import uPred.
Section
SCStack
.
Section
SCStack
.
Open
Scope
Z_scope
.
Local
Notation
next
:=
0.
Local
Notation
next
:=
0.
Local
Notation
data
:=
1.
Local
Notation
data
:=
1.
...
@@ -42,166 +43,158 @@ Section SCStack.
...
@@ -42,166 +43,158 @@ Section SCStack.
Section
proof
.
Section
proof
.
Context
`
{
fG
:
foundationG
Σ
}
.
Context
`
{
fG
:
foundationG
Σ
}
.
Set
Default
Proof
Using
"Type"
.
Set
Default
Proof
Using
"Type"
.
Notation
vPred
:=
(
@
vPr
ed
Σ
).
Notation
vPred
:=
(
vPr
op
Σ
).
Context
(
P
:
Z
→
vPred
).
Context
(
P
:
Z
→
vPred
).
Local
Open
Scope
VP
.
Definition
SCStack
'
:
(
loc
-
c
>
list
Z
-
c
>
vProp
Σ
)
-
c
>
loc
-
c
>
list
Z
-
c
>
vProp
Σ
Definition
SCStack
'
:
(
loc
-
c
>
list
Z
-
c
>
@
vPred_ofe
Σ
)
-
c
>
loc
-
c
>
list
Z
-
c
>
@
vPred_ofe
Σ
:=
(
fun
F
l
A
=>
:=
(
fun
F
l
A
=>
∃
l
'
,
ZplusPos
next
l
↦
l
'
∗
∃
l
'
,
ZplusPos
next
l
↦
l
'
∗
match
A
with
match
A
with
|
nil
=>
l
'
=
0
|
nil
=>
⌜
l
'
=
0
⌝
|
v
::
A
'
=>
■
(
0
<
l
'
)
∗
Z
.
to_pos
(
l
'
+
data
)
↦
v
∗
P
v
|
v
::
A
'
=>
⌜
0
<
l
'
⌝
∗
Z
.
to_pos
(
l
'
+
data
)
↦
v
∗
P
v
∗
▷
F
(
Z
.
to_pos
l
'
)
A
'
∗
▷
F
(
Z
.
to_pos
l
'
)
A
'
end
).
end
)
%
I
.
Close
Scope
VP
.
Instance
SCStack
'_
inhabited
:
Inhabited
(
loc
-
c
>
list
Z
-
c
>
vProp
Σ
)
Instance
SCStack
'_
inhabited
:
Inhabited
(
loc
-
c
>
list
Z
-
c
>
@
vPred_ofe
Σ
)
:=
populate
(
λ
_
_
,
True
)
%
I
.
:=
populate
(
λ
_
_
,
True
%
VP
).
Instance
SCStack
'_
contractive
:
Instance
SCStack
'_
contractive
:
Contractive
(
SCStack
'
).
Contractive
(
SCStack
'
).
Proof
.
Proof
.
intros
?
?
?
H
?
A
?
.
intros
?
?
?
H
?
A
.
repeat
(
apply
uPred
.
exist_ne
=>
?
).
repeat
(
apply
bi
.
exist_ne
=>
?
).
apply
uPred
.
sep_ne
;
[
done
|
].
apply
bi
.
sep_ne
;
[
done
|
].
destruct
A
as
[
|
v
A
];
[
done
|
].
destruct
A
as
[
|
v
A
];
[
done
|
].
repeat
(
apply
uPred
.
sep_ne
;
[
done
|
]).
repeat
(
apply
bi
.
sep_ne
;
[
done
|
]).
apply
later_contractive
.
destruct
n
=>
//. by apply (H).
apply
later_contractive
.
destruct
n
=>
//. by apply (H).
Qed
.
Qed
.
Definition
SCStack
:=
fixpoint
(
SCStack
'
).
Definition
SCStack
:=
fixpoint
(
SCStack
'
).
Lemma
newStack_spec
:
Lemma
newStack_spec
:
{{{
{
True
}
}}}
{{{
⎡
PSCtx
⎤
}}}
newStack
#()
newStack
#()
{{{
{
(
s
:
loc
),
RET
#
s
;
SCStack
s
nil
}
}}}
.
{{{
(
s
:
loc
),
RET
#
s
;
SCStack
s
nil
}}}
.
Proof
.
Proof
.
i
ntros
.
iViewUp
.
iIntros
"#kI kS _
Post"
.
i
Intros
(
Φ
)
"#kI
Post"
.
wp_seq
.
iNext
.
wp_bind
Alloc
.
wp_seq
.
wp_bind
Alloc
.
iA
pply
(
alloc
with
"
[%] kI kS []"
);
[
done
|
done
|
done
|
].
wp_a
pply
(
alloc
with
"
kI"
);
[
done
|
].
iNext
.
iViewUp
.
iIntros
(
x
)
"
kS
os"
.
iIntros
(
x
)
"os"
.
wp_seq
.
iNext
.
wp_seq
.
wp_bind
([
_
]
_
na
<-
_
)
%
E
.
wp_bind
([
_
]
_
na
<-
_
)
%
E
.
iA
pply
(
na_write
with
"[
%] kI kS [
$os]"
);
[
done
|
done
|
].
wp_a
pply
(
na_write
with
"[
$kI
$os]"
);
[
done
|
].
iNext
.
iViewUp
;
iIntros
"
kS
os"
.
iIntros
"os"
.
wp_seq
.
iNext
.
wp_value
.
wp_seq
.
iApply
(
"Post"
with
"[
%] kS [os]"
);
first
done
.
iApply
(
"Post"
with
"[
os]"
)
.
rewrite
(
fixpoint_unfold
(
SCStack
'
)
_
_
_
).
rewrite
/
SCStack
(
fixpoint_unfold
(
SCStack
'
)
_
_
).
iExists
_.
by
iFrame
"os"
.
iExists
_.
by
iFrame
"os"
.
Qed
.
Qed
.
Lemma
push_spec
s
v
A
:
Lemma
push_spec
s
v
A
:
{{{
{
SCStack
s
A
∗
P
v
}}}
}
{{{
⎡
PSCtx
⎤
∗
SCStack
s
A
∗
P
v
}}}
push
#
s
#
v
push
#
s
#
v
{{{
{
RET
#();
SCStack
s
(
v
::
A
)
}
}}}
.
{{{
RET
#();
SCStack
s
(
v
::
A
)
}}}
.
Proof
.
Proof
.
intros
.
iViewUp
.
iIntros
"#kI
kS
(Stack & P) Post"
.
intros
.
iIntros
"
[
#kI (Stack & P)
]
Post"
.
wp_lam
.
iNext
.
wp_value
.
wp_let
.
iNex
t
.
wp_lam
.
wp_le
t
.
wp_bind
(
malloc
_
).
wp_bind
(
malloc
_
).
iApply
(
wp_mask_mono
);
first
auto
.
iApply
(
wp_mask_mono
);
first
auto
.
iApply
(
malloc_spec
with
"[%] kI kS []"
);
[
omega
|
done
|
done
|
].
wp_apply
(
malloc_spec
with
"kI []"
);
[
omega
|
done
|
].
iNext
.
iViewUp
.
iIntros
(
n
)
"kS oLs"
.
iIntros
(
n
)
"oLs"
.
rewrite
-
bigop
.
vPred_big_opL_fold
iDestruct
"oLs"
as
"(ol & od & _)"
.
big_op
.
big_sepL_cons
big_op
.
big_opL_singleton
.
wp_let
.
wp_bind
([
_
]
_
na
<-
_
)
%
E
.
wp_op
.
iDestruct
"oLs"
as
"(ol & od)"
.
wp_apply
(
na_write
with
"[$kI $od]"
);
[
done
|
].
wp_let
.
iNext
.
wp_bind
([
_
]
_
na
<-
_
)
%
E
.
wp_op
.
iNext
.
iIntros
"od"
.
iApply
(
na_write
with
"[%] kI kS od"
);
[
done
|
done
|
].
wp_seq
.
wp_bind
([
_
]
_
na
)
%
E
.
iNext
.
iViewUp
.
iIntros
"kS od"
.
wp_seq
.
iNext
.
wp_bind
([
_
]
_
na
)
%
E
.
rewrite
/
SCStack
(
fixpoint_unfold
(
SCStack
'
)
_
_
).
rewrite
(
fixpoint_unfold
(
SCStack
'
)
_
_
_
).
iDestruct
"Stack"
as
(
h
)
"[oH oT]"
.
iDestruct
"Stack"
as
(
h
)
"[oH oT]"
.
iA
pply
(
na_read
with
"[
%] kI kS
oH"
);
[
done
|
done
|
].
wp_a
pply
(
na_read
with
"[
$kI $
oH
]
"
);
[
done
|
].
iNext
.
iViewUp
.
iIntros
(
z
)
"
kS
[% oH]"
.
subst
z
.
iIntros
(
z
)
"[% oH]"
.
subst
z
.
wp_seq
.
iNext
.
wp_bind
([
_
]
_
na
<-
_
)
%
E
.
wp_op
.
iNext
.
wp_seq
.
wp_bind
([
_
]
_
na
<-
_
)
%
E
.
wp_op
.
iA
pply
(
na_write
with
"[
%] kI kS
ol"
);
[
done
|
done
|
].
wp_a
pply
(
na_write
with
"[
$kI $
ol
]
"
);
[
done
|
].
iNext
.
iViewUp
.
iIntros
"
kS
ol"
.
iIntros
"ol"
.
wp_seq
.
iNext
.
wp_op
.
iNext
.
wp_seq
.
wp_op
.
iA
pply
(
na_write
with
"[
%] kI kS [
$oH]"
);
[
done
|
done
|
].
wp_a
pply
(
na_write
with
"[
$kI
$oH]"
);
[
done
|
].
iNext
.
iViewUp
.
iIntros
"
kS
oH"
.
iIntros
"oH"
.
iApply
(
"Post"
with
"[%] kS"
);
first
done
.
iApply
(
"Post"
)
.
rewrite
(
fixpoint_unfold
(
SCStack
'
)
_
_
_
).
rewrite
/
SCStack
(
fixpoint_unfold
(
SCStack
'
)
_
_
).
iExists
_.
iFrame
"oH P"
.
iSplitL
""
;
first
(
iPureIntro
;
lia
).
iExists
_.
iFrame
"oH P"
.
iSplitL
""
;
first
(
iPureIntro
;
lia
).
iSplitL
"od"
.
iSplitL
"od"
.
-
rewrite
(
_
:
Z
.
to_pos
(
Z
.
pos
n
+
data
)
=
ZplusPos
data
n
);
first
done
.
-
rewrite
(
_
:
Z
.
to_pos
(
Z
.
pos
n
+
data
)
=
ZplusPos
data
n
);
first
done
.
rewrite
/
ZplusPos
.
f_equal
.
omega
.
rewrite
/
ZplusPos
.
f_equal
.
omega
.
-
iNext
.
rewrite
(
fixpoint_unfold
(
SCStack
'
)
_
_
_
).
-
iNext
.
rewrite
/
SCStack
(
fixpoint_unfold
(
SCStack
'
)
_
_
).
iExists
h
.
iFrame
"oT ol"
.
iExists
h
.
iFrame
"oT ol"
.
Qed
.
Qed
.
Lemma
pop_spec
s
A
:
Lemma
pop_spec
s
A
:
{{{
{
SCStack
s
A
}}}
}
{{{
⎡
PSCtx
⎤
∗
SCStack
s
A
}}}
pop
#
s
pop
#
s
{{{
{
(
z
:
Z
),
RET
#
z
;
{{{
(
z
:
Z
),
RET
#
z
;
match
A
with
match
A
with
|
nil
=>
■
(
z
=
0
)
∗
SCStack
s
A
|
nil
=>
⌜
z
=
0
⌝
∗
SCStack
s
A
|
v
::
A
'
=>
■
(
z
=
v
)
∗
SCStack
s
A
'
∗
P
v
|
v
::
A
'
=>
⌜
z
=
v
⌝
∗
SCStack
s
A
'
∗
P
v
end
}}}
}
.
end
}}}
.
Proof
.
Proof
.
intros
.
iViewUp
.
iIntros
"#kI
kS
Stack Post"
.
intros
.
iIntros
"
[
#kI Stack
]
Post"
.
wp_lam
.
iNext
.
wp_lam
.
wp_bind
([
_
]
_
na
)
%
E
.
wp_bind
([
_
]
_
na
)
%
E
.
rewrite
(
fixpoint_unfold
(
SCStack
'
)
_
_
_
).
rewrite
{
1
}/
SCStack
(
fixpoint_unfold
(
SCStack
'
)
_
_
).
iDestruct
"Stack"
as
(
h
)
"[oH oT]"
.
iDestruct
"Stack"
as
(
h
)
"[oH oT]"
.
iA
pply
(
na_read
with
"[
%] kI kS
oH"
);
[
done
|
done
|
].
wp_a
pply
(
na_read
with
"[
$kI $
oH
]
"
);
[
done
|
].
iNext
.
iViewUp
.
iIntros
(
z
)
"
kS
[% oH]"
.
subst
z
.
iIntros
(
z
)
"[% oH]"
.
subst
z
.
wp_seq
.
iNext
.
wp_seq
.
destruct
A
as
[
|
v
A
'
].
destruct
A
as
[
|
v
A
'
].
-
iDestruct
"oT"
as
"%"
.
subst
h
.
-
iDestruct
"oT"
as
"%"
.
subst
h
.
wp_op
=>
[
_
|
//]. iNext.
wp_op
.
wp_if
.
iApply
wp_if_true
.
iNext
.
iApply
(
"Post"
).
wp_value
.
iApply
(
"Post"
with
"[%] kS"
);
first
done
.
iSplitL
""
;
first
done
.
iSplitL
""
;
first
done
.
rewrite
(
fixpoint_unfold
(
SCStack
'
)
_
_
_
).
iExists
_.
by
iFrame
"oH"
.
rewrite
/
SCStack
(
fixpoint_unfold
(
SCStack
'
)
_
_
).
iExists
_.
by
iFrame
"oH"
.
-
iDestruct
"oT"
as
"(% & od & P & oT)"
.
-
iDestruct
"oT"
as
"(% & od & P & oT)"
.
wp_op
=>
[
?|
_
]
;
first
omega
.
iNext
.
wp_op
.
case_bool_decide
;
first
omega
.
iApply
wp_if_false
.
iNext
.
wp_if
.
wp_bind
([
_
]
_
na
)
%
E
.
wp_op
.
iNext
.
wp_op
.
iNext
.
wp_bind
([
_
]
_
na
)
%
E
.
wp_op
.
wp_op
.
rewrite
(
_
:
ZplusPos
data
(
Z
.
to_pos
h
)
=
Z
.
to_pos
(
h
+
1
));
last
first
.
rewrite
(
_
:
ZplusPos
data
(
Z
.
to_pos
h
)
=
Z
.
to_pos
(
h
+
1
));
last
first
.
{
rewrite
/
ZplusPos
.
f_equal
.
rewrite
Z2Pos
.
id
;
[
omega
|
auto
].
}
{
rewrite
/
ZplusPos
.
f_equal
.
rewrite
Z2Pos
.
id
;
[
omega
|
auto
].
}
iA
pply
(
na_read
with
"[
%] kI kS
od"
);
[
done
|
done
|
].
wp_a
pply
(
na_read
with
"[
$kI $
od
]
"
);
[
done
|
].
iNext
.
iViewUp
.
iIntros
(
z
)
"
kS
[% od]"
.
subst
z
.
iIntros
(
z
)
"[% od]"
.
subst
z
.
wp_seq
.
iNext
.
wp_seq
.
wp_bind
([
_
]
_
na
)
%
E
.
wp_op
.
iNext
.
wp_op
.
iNext
.
wp_bind
([
_
]
_
na
)
%
E
.
wp_op
.
wp_op
.
rewrite
(
fixpoint_unfold
(
SCStack
'
)
_
_
_
).
rewrite
/
SCStack
(
fixpoint_unfold
(
SCStack
'
)
_
_
).
iDestruct
"oT"
as
(
h
'
)
"[oP oT]"
.
iDestruct
"oT"
as
(
h
'
)
"[oP oT]"
.
iA
pply
(
na_read
with
"[
%] kI kS
oP"
);
[
done
|
done
|
].
wp_a
pply
(
na_read
with
"[
$kI $
oP
]
"
);
[
done
|
].
iNext
.
iViewUp
.
iIntros
(
z
)
"
kS
[% oP]"
.
subst
z
.
iIntros
(
z
)
"[% oP]"
.
subst
z
.
wp_seq
.
iNext
.
wp_bind
([
_
]
_
na
<-
_
)
%
E
.
wp_seq
.
wp_bind
([
_
]
_
na
<-
_
)
%
E
.
iA
pply
(
na_write
with
"[
%] kI kS [
$oH]"
);
[
done
|
done
|
..
].
wp_a
pply
(
na_write
with
"[
$kI
$oH]"
);
[
done
|
].
iNext
.
iViewUp
.
iIntros
"
kS
oH"
.
iIntros
"oH"
.
wp_seq
.
iNext
.
wp_seq
.
wp_bind
(
Dealloc
_
).
wp_op
.
iNext
.
wp_op
.
iNext
.
wp_bind
(
Dealloc
_
).
wp_op
.
wp_op
.
iApply
(
wp_mask_mono
);
first
auto
.
iApply
(
wp_mask_mono
);
first
auto
.
rewrite
(
_
:
ZplusPos
data
(
Z
.
to_pos
h
)
=
Z
.
to_pos
(
h
+
data
));
last
first
.
rewrite
(
_
:
ZplusPos
data
(
Z
.
to_pos
h
)
=
Z
.
to_pos
(
h
+
data
));
last
first
.
{
rewrite
/
ZplusPos
.
f_equal
.
rewrite
Z2Pos
.
id
;
[
omega
|
auto
].
}
{
rewrite
/
ZplusPos
.
f_equal
.
rewrite
Z2Pos
.
id
;
[
omega
|
auto
].
}
iA
pply
(
dealloc
with
"[
%] kI kS [$od]"
);
first
done
.
wp_a
pply
(
dealloc
with
"[
$kI $od]"
)
.
iNext
.
iViewUp
.
iIntros
"
kS
_"
.
iIntros
"_"
.
wp_seq
.
iNext
.
wp_seq
.
wp_bind
(
Dealloc
_
).
wp_op
.
iNext
.
wp_op
.
iNext
.
wp_bind
(
Dealloc
_
).
wp_op
.
wp_op
.
iApply
(
wp_mask_mono
);
first
auto
.
iApply
(
wp_mask_mono
);
first
auto
.
iA
pply
(
dealloc
with
"[
%] kI kS [$oP]"
);
first
done
.
wp_a
pply
(
dealloc
with
"[
$kI $oP]"
)
.
iNext
.
iViewUp
.
iIntros
"
kS
_"
.
iIntros
"_"
.
wp_seq
.
iNext
.
wp_seq
.
wp_value
.
iApply
(
"Post"
).
iApply
(
"Post"
with
"[%] kS"
);
first
done
.
iSplitL
""
;
first
done
.
iFrame
"P"
.
iSplitL
""
;
first
done
.
iFrame
"P"
.
rewrite
(
fixpoint_unfold
(
SCStack
'
)
_
_
_
).
rewrite
/
SCStack
(
fixpoint_unfold
(
SCStack
'
)
_
_
).
iExists
_.
by
iFrame
.
iExists
_.
by
iFrame
.
Qed
.
Qed
.
End
proof
.
End
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