Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Iris
RefinedC
Commits
c409fe57
Commit
c409fe57
authored
Nov 03, 2020
by
Michael Sammler
Browse files
add length function for singly linked list
parent
40d34ec3
Pipeline
#36877
passed with stage
in 34 minutes and 15 seconds
Changes
5
Pipelines
2
Expand all
Hide whitespace changes
Inline
Side-by-side
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.
fn
(
∀
l
:
(
list
type
)
;
(
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]. *)
Definition
type_of_append
:
=
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
generated_proof_free_array.v
generated_proof_init.v
generated_proof_is_empty.v
generated_proof_length.v
generated_proof_member.v
generated_proof_pop.v
generated_proof_push.v
...
...
tutorial/t03_list.c
View file @
c409fe57
...
...
@@ -80,6 +80,23 @@ list_t reverse (list_t p) {
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
::
args
(
"p @ &own<l1 @ list_t>"
,
"l2 @ list_t"
)]]
[[
rc
::
ensures
(
"p @ &own<{l1 ++ l2} @ list_t>"
)]]
...
...
Write
Preview
Supports
Markdown
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