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
d90c2952
Commit
d90c2952
authored
Mar 16, 2021
by
Michael Sammler
Browse files
add alloc_from_start to paper example 1
parent
2cfb268e
Pipeline
#44082
passed with stage
in 33 minutes and 54 seconds
Changes
6
Pipelines
10
Expand all
Hide whitespace changes
Inline
Side-by-side
examples/paper_example_2_1.c
View file @
d90c2952
...
...
@@ -16,21 +16,35 @@
//@Coercion byte_layout : nat >-> layout.
//@rc::end
struct
[[
rc
::
refined_by
(
"a
: nat"
)]]
mem_t
{
struct
[[
rc
::
refined_by
(
"a: nat"
)]]
mem_t
{
[[
rc
::
field
(
"a @ int<size_t>"
)]]
size_t
len
;
[[
rc
::
field
(
"&own<uninit<a>>"
)]]
unsigned
char
*
buffer
;
[[
rc
::
field
(
"&own<uninit<a>>"
)]]
unsigned
char
*
buffer
;
};
[[
rc
::
parameters
(
"a
: nat"
,
"n
: nat"
,
"p
: loc"
)]]
[[
rc
::
parameters
(
"a: nat"
,
"n: nat"
,
"p: loc"
)]]
[[
rc
::
args
(
"p @ &own<a @ mem_t>"
,
"n @ int<size_t>"
)]]
[[
rc
::
returns
(
"{n ≤ a} @ optional<&own<uninit<n>>, null>"
)]]
[[
rc
::
ensures
(
"own p : {n ≤ a ? a - n : a} @ mem_t"
)]]
void
*
alloc
(
struct
mem_t
*
d
,
size_t
s
ize
)
{
if
(
s
ize
>
d
->
len
)
return
NULL
;
d
->
len
-=
s
ize
;
void
*
alloc
(
struct
mem_t
*
d
,
size_t
s
z
)
{
if
(
s
z
>
d
->
len
)
return
NULL
;
d
->
len
-=
s
z
;
return
d
->
buffer
+
d
->
len
;
}
// variant of alloc that allocates from the start of buffer instead of the end
[[
rc
::
parameters
(
"a: nat"
,
"n: nat"
,
"p: loc"
)]]
[[
rc
::
args
(
"p @ &own<a @ mem_t>"
,
"n @ int<size_t>"
)]]
[[
rc
::
returns
(
"{n ≤ a} @ optional<&own<uninit<n>>, null>"
)]]
[[
rc
::
ensures
(
"own p : {n ≤ a ? a - n : a} @ mem_t"
)]]
void
*
alloc_from_start
(
struct
mem_t
*
d
,
size_t
sz
)
{
if
(
sz
>
d
->
len
)
return
NULL
;
d
->
len
-=
sz
;
unsigned
char
*
res
=
d
->
buffer
;
d
->
buffer
+=
sz
;
return
res
;
}
// Thread-safe version (given in appendix).
[[
rc
::
parameters
(
"lid : lock_id"
)]]
...
...
examples/proofs/paper_example_2_1/generated_code.v
View file @
d90c2952
This diff is collapsed.
Click to expand it.
examples/proofs/paper_example_2_1/generated_proof_alloc.v
View file @
d90c2952
...
...
@@ -14,7 +14,7 @@ Section proof_alloc.
⊢
typed_function
impl_alloc
type_of_alloc
.
Proof
.
Open
Scope
printing_sugar
.
start_function
"alloc"
([[
a
n
]
p
])
=>
arg_d
arg_s
ize
.
start_function
"alloc"
([[
a
n
]
p
])
=>
arg_d
arg_s
z
.
split_blocks
((
∅
)%
I
:
gmap
label
(
iProp
Σ
))
((
...
...
examples/proofs/paper_example_2_1/generated_proof_alloc_from_start.v
0 → 100644
View file @
d90c2952
From
refinedc
.
typing
Require
Import
typing
.
From
refinedc
.
examples
.
paper_example_2_1
Require
Import
generated_code
.
From
refinedc
.
examples
.
paper_example_2_1
Require
Import
generated_spec
.
From
refinedc
.
examples
.
spinlock
Require
Import
spinlock_def
.
Set
Default
Proof
Using
"Type"
.
(* Generated from [examples/paper_example_2_1.c]. *)
Section
proof_alloc_from_start
.
Context
`
{!
typeG
Σ
}
`
{!
globalG
Σ
}.
Context
`
{!
lockG
Σ
}.
(* Typing proof for [alloc_from_start]. *)
Lemma
type_alloc_from_start
:
⊢
typed_function
impl_alloc_from_start
type_of_alloc_from_start
.
Proof
.
Open
Scope
printing_sugar
.
start_function
"alloc_from_start"
([[
a
n
]
p
])
=>
arg_d
arg_sz
local_res
.
split_blocks
((
∅
)%
I
:
gmap
label
(
iProp
Σ
))
((
∅
)%
I
:
gmap
label
(
iProp
Σ
)).
-
repeat
liRStep
;
liShow
.
all
:
print_typesystem_goal
"alloc_from_start"
"#0"
.
Unshelve
.
all
:
sidecond_hook
;
prepare_sideconditions
;
normalize_and_simpl_goal
;
try
solve_goal
;
unsolved_sidecond_hook
.
all
:
print_sidecondition_goal
"alloc_from_start"
.
Qed
.
End
proof_alloc_from_start
.
examples/proofs/paper_example_2_1/generated_spec.v
View file @
d90c2952
...
...
@@ -92,6 +92,11 @@ Section spec.
fn
(
∀
(
a
,
n
,
p
)
:
nat
*
nat
*
loc
;
(
p
@
(&
own
(
a
@
(
mem_t
)))),
(
n
@
(
int
(
size_t
)))
;
True
)
→
∃
()
:
(),
((
n
≤
a
)
@
(
optional
(&
own
(
uninit
(
n
)))
(
null
)))
;
(
p
◁ₗ
((
n
≤
a
?
a
-
n
:
a
)
@
(
mem_t
))).
(* Specifications for function [alloc_from_start]. *)
Definition
type_of_alloc_from_start
:
=
fn
(
∀
(
a
,
n
,
p
)
:
nat
*
nat
*
loc
;
(
p
@
(&
own
(
a
@
(
mem_t
)))),
(
n
@
(
int
(
size_t
)))
;
True
)
→
∃
()
:
(),
((
n
≤
a
)
@
(
optional
(&
own
(
uninit
(
n
)))
(
null
)))
;
(
p
◁ₗ
((
n
≤
a
?
a
-
n
:
a
)
@
(
mem_t
))).
(* Specifications for function [thread_safe_alloc]. *)
Definition
type_of_thread_safe_alloc
:
=
fn
(
∀
(
lid
,
n
)
:
lock_id
*
nat
;
(
n
@
(
int
(
size_t
)))
;
(
initialized
"lock"
lid
)
∗
(
initialized
"data"
lid
))
...
...
examples/proofs/paper_example_2_1/proof_files
View file @
d90c2952
generated_proof_alloc.v
generated_proof_alloc_from_start.v
generated_proof_atomic_signal_fence.v
generated_proof_atomic_thread_fence.v
generated_proof_fork.v
...
...
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