Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
Fengmin Zhu
RefinedC
Commits
c409fe57
Commit
c409fe57
authored
Nov 03, 2020
by
Michael Sammler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add length function for singly linked list
parent
40d34ec3
Changes
5
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
458 additions
and
324 deletions
+458
-324
tutorial/proofs/t03_list/generated_code.v
tutorial/proofs/t03_list/generated_code.v
+401
-324
tutorial/proofs/t03_list/generated_proof_length.v
tutorial/proofs/t03_list/generated_proof_length.v
+34
-0
tutorial/proofs/t03_list/generated_spec.v
tutorial/proofs/t03_list/generated_spec.v
+5
-0
tutorial/proofs/t03_list/proof_files
tutorial/proofs/t03_list/proof_files
+1
-0
tutorial/t03_list.c
tutorial/t03_list.c
+17
-0
No files found.
tutorial/proofs/t03_list/generated_code.v
View file @
c409fe57
This diff is collapsed.
Click to expand it.
tutorial/proofs/t03_list/generated_proof_length.v
0 → 100644
View file @
c409fe57
From
refinedc
.
typing
Require
Import
typing
.
From
refinedc
.
tutorial
.
t03_list
Require
Import
generated_code
.
From
refinedc
.
tutorial
.
t03_list
Require
Import
generated_spec
.
Set
Default
Proof
Using
"Type"
.
(* Generated from [tutorial/t03_list.c]. *)
Section
proof_length
.
Context
`
{!
typeG
Σ
}
`
{!
globalG
Σ
}.
(* Typing proof for [length]. *)
Lemma
type_length
:
⊢
typed_function
impl_length
type_of_length
.
Proof
.
start_function
"length"
([
p
l
])
=>
arg_p
local_len
.
split_blocks
((
<[
"#1"
:
=
∃
q
:
loc
,
∃
l1
:
list
type
,
arg_p
◁ₗ
(
q
@
(&
own
(
l1
@
(
list_t
))))
∗
local_len
◁ₗ
((
length
l
-
length
l1
)
@
(
int
(
size_t
)))
∗
(
p
◁ₗ
(
wand
(
q
◁ₗ
l1
@
list_t
)
(
l
@
(
list_t
))))
]>
$
∅
)%
I
:
gmap
label
(
iProp
Σ
))
((
∅
)%
I
:
gmap
label
(
iProp
Σ
)).
-
repeat
liRStep
;
liShow
.
all
:
print_typesystem_goal
"length"
"#0"
.
-
repeat
liRStep
;
liShow
.
all
:
print_typesystem_goal
"length"
"#1"
.
Unshelve
.
all
:
prepare_sideconditions
;
normalize_and_simpl_goal
;
try
solve_goal
.
all
:
print_sidecondition_goal
"length"
.
Qed
.
End
proof_length
.
tutorial/proofs/t03_list/generated_spec.v
View file @
c409fe57
...
@@ -122,6 +122,11 @@ Section spec.
...
@@ -122,6 +122,11 @@ Section spec.
fn
(
∀
l
:
(
list
type
)
;
(
l
@
(
list_t
))
;
True
)
fn
(
∀
l
:
(
list
type
)
;
(
l
@
(
list_t
))
;
True
)
→
∃
()
:
(),
((
rev
l
)
@
(
list_t
))
;
True
.
→
∃
()
:
(),
((
rev
l
)
@
(
list_t
))
;
True
.
(* Specifications for function [length]. *)
Definition
type_of_length
:
=
fn
(
∀
(
p
,
l
)
:
loc
*
(
list
type
)
;
(
p
@
(&
own
(
l
@
(
list_t
))))
;
⌜
length
l
<=
max_int
size_t
⌝
)
→
∃
()
:
(),
((
length
l
)
@
(
int
(
size_t
)))
;
(
p
◁ₗ
(
l
@
(
list_t
))).
(* Specifications for function [append]. *)
(* Specifications for function [append]. *)
Definition
type_of_append
:
=
Definition
type_of_append
:
=
fn
(
∀
(
p
,
l1
,
l2
)
:
loc
*
(
list
type
)
*
(
list
type
)
;
(
p
@
(&
own
(
l1
@
(
list_t
)))),
(
l2
@
(
list_t
))
;
True
)
fn
(
∀
(
p
,
l1
,
l2
)
:
loc
*
(
list
type
)
*
(
list
type
)
;
(
p
@
(&
own
(
l1
@
(
list_t
)))),
(
l2
@
(
list_t
))
;
True
)
...
...
tutorial/proofs/t03_list/proof_files
View file @
c409fe57
...
@@ -5,6 +5,7 @@ generated_proof_free.v
...
@@ -5,6 +5,7 @@ generated_proof_free.v
generated_proof_free_array.v
generated_proof_free_array.v
generated_proof_init.v
generated_proof_init.v
generated_proof_is_empty.v
generated_proof_is_empty.v
generated_proof_length.v
generated_proof_member.v
generated_proof_member.v
generated_proof_pop.v
generated_proof_pop.v
generated_proof_push.v
generated_proof_push.v
...
...
tutorial/t03_list.c
View file @
c409fe57
...
@@ -80,6 +80,23 @@ list_t reverse (list_t p) {
...
@@ -80,6 +80,23 @@ list_t reverse (list_t p) {
return
w
;
return
w
;
}
}
[[
rc
::
parameters
(
"p : loc"
,
"l : {list type}"
)]]
[[
rc
::
args
(
"p @ &own<l @ list_t>"
)]]
[[
rc
::
requires
(
"{length l <= max_int size_t}"
)]]
[[
rc
::
returns
(
"{length l} @ int<size_t>"
)]]
[[
rc
::
ensures
(
"p @ &own<l @ list_t>"
)]]
size_t
length
(
list_t
*
p
)
{
size_t
len
=
0
;
[[
rc
::
exists
(
"q : loc"
,
"l1 : {list type}"
)]]
[[
rc
::
inv_vars
(
"p : q @ &own<l1 @ list_t>"
,
"len : {length l - length l1} @ int<size_t>"
)]]
[[
rc
::
constraints
(
"p @ &own<wand<{q ◁ₗ l1 @ list_t}, l @ list_t>>"
)]]
while
(
*
p
!=
NULL
)
{
p
=
&
(
*
p
)
->
tail
;
len
+=
1
;
}
return
len
;
}
[[
rc
::
parameters
(
"p : loc"
,
"l1 : {list type}"
,
"l2 : {list type}"
)]]
[[
rc
::
parameters
(
"p : loc"
,
"l1 : {list type}"
,
"l2 : {list type}"
)]]
[[
rc
::
args
(
"p @ &own<l1 @ list_t>"
,
"l2 @ list_t"
)]]
[[
rc
::
args
(
"p @ &own<l1 @ list_t>"
,
"l2 @ list_t"
)]]
[[
rc
::
ensures
(
"p @ &own<{l1 ++ l2} @ list_t>"
)]]
[[
rc
::
ensures
(
"p @ &own<{l1 ++ l2} @ list_t>"
)]]
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment