Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Iris
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
Package Registry
Model registry
Operate
Terraform modules
Monitor
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
Pierre Roux
Iris
Commits
1635ac6c
Commit
1635ac6c
authored
4 years ago
by
Dan Frumin
Committed by
Robbert Krebbers
4 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Improve array_init doc.
parent
f3d9b2db
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/heap_lang/lib/array.v
+11
-5
11 additions, 5 deletions
theories/heap_lang/lib/array.v
with
11 additions
and
5 deletions
theories/heap_lang/lib/array.v
+
11
−
5
View file @
1635ac6c
...
@@ -10,6 +10,9 @@ From iris Require Import options.
...
@@ -10,6 +10,9 @@ From iris Require Import options.
* [array_copy_to], a function which copies to an array in-place.
* [array_copy_to], a function which copies to an array in-place.
* Using [array_copy_to] we also implement [array_clone], which allocates a fresh
* Using [array_copy_to] we also implement [array_clone], which allocates a fresh
array and copies to it.
array and copies to it.
* [array_init], to create and initialize an array with a given
function. Specifically, [array_init n f] creates a new array of size
[n] in which the [i]th element is initialized with [f #i]
*)
*)
...
@@ -31,13 +34,15 @@ Definition array_clone : val :=
...
@@ -31,13 +34,15 @@ Definition array_clone : val :=
array_copy_to
"dst"
"src"
"n"
;;
array_copy_to
"dst"
"src"
"n"
;;
"dst"
.
"dst"
.
Definition
array_init_loop
:
val
:=
(* [array_init_loop src i n f] initializes elements
[i], [i+1], ..., [n] of the array [src] to
[f #i], [f #(i+1)], ..., [f #n] *)
Local
Definition
array_init_loop
:
val
:=
rec
:
"loop"
"src"
"i"
"n"
"f"
:=
rec
:
"loop"
"src"
"i"
"n"
"f"
:=
if
:
"i"
=
"n"
then
#
()
if
:
"i"
=
"n"
then
#
()
else
"src"
+
ₗ
"i"
<-
"f"
"i"
;;
else
"src"
+
ₗ
"i"
<-
"f"
"i"
;;
"loop"
"src"
(
"i"
+
#
1
)
"n"
"f"
.
"loop"
"src"
(
"i"
+
#
1
)
"n"
"f"
.
(* similar to [Array.init] in OCaml's stdlib *)
Definition
array_init
:
val
:=
Definition
array_init
:
val
:=
λ
:
"n"
"f"
,
λ
:
"n"
"f"
,
let
:
"src"
:=
AllocN
"n"
#
()
in
let
:
"src"
:=
AllocN
"n"
#
()
in
...
@@ -121,11 +126,11 @@ Section proof.
...
@@ -121,11 +126,11 @@ Section proof.
Qed
.
Qed
.
(* TODO: move to std++? *)
(* TODO: move to std++? *)
Lemma
insert_0_replicate
{
A
:
Type
}
(
x
y
:
A
)
n
:
Local
Lemma
insert_0_replicate
{
A
:
Type
}
(
x
y
:
A
)
n
:
<
[
0
:=
y
]
>
(
replicate
(
S
n
)
x
)
=
y
::
replicate
n
x
.
<
[
0
:=
y
]
>
(
replicate
(
S
n
)
x
)
=
y
::
replicate
n
x
.
Proof
.
by
induction
n
;
eauto
.
Qed
.
Proof
.
by
induction
n
;
eauto
.
Qed
.
Lemma
wp_array_init_loop
{
A
:
Type
}
(
g
:
A
→
val
)
(
Q
:
nat
→
A
→
iProp
Σ
)
Local
Lemma
wp_array_init_loop
{
A
:
Type
}
(
g
:
A
→
val
)
(
Q
:
nat
→
A
→
iProp
Σ
)
(
xs
:
list
A
)
i
n
l
(
f
:
val
)
stk
E
:
(
xs
:
list
A
)
i
n
l
(
f
:
val
)
stk
E
:
(
0
<
n
)
→
(
0
<
n
)
→
length
xs
=
i
→
length
xs
=
i
→
...
@@ -177,7 +182,7 @@ Section proof.
...
@@ -177,7 +182,7 @@ Section proof.
(
0
<
n
)
%
Z
→
(
0
<
n
)
%
Z
→
{{{
(
□
∀
i
:
nat
,
WP
f
#
i
@
stk
;
E
{{
v
,
∃
x
:
A
,
⌜
v
=
g
x
⌝
∗
Q
i
x
}})
}}}
{{{
(
□
∀
i
:
nat
,
WP
f
#
i
@
stk
;
E
{{
v
,
∃
x
:
A
,
⌜
v
=
g
x
⌝
∗
Q
i
x
}})
}}}
array_init
#
n
f
@
stk
;
E
array_init
#
n
f
@
stk
;
E
{{{
l
xs
,
RET
#
l
;
l
↦∗
(
g
<$>
xs
)
∗
⌜
Z
.
of_nat
(
length
xs
)
=
n
⌝
∗
([
∗
list
]
k
↦
x
∈
xs
,
Q
k
x
)
}}}
.
{{{
l
xs
,
RET
#
l
;
l
↦∗
(
g
<$>
xs
)
∗
⌜
Z
.
of_nat
(
length
xs
)
=
n
⌝
∗
([
∗
list
]
k
↦
x
∈
xs
,
Q
k
x
)
}}}
.
Proof
.
Proof
.
intros
Hn
.
iIntros
(
Φ
)
"#Hf HΦ"
.
intros
Hn
.
iIntros
(
Φ
)
"#Hf HΦ"
.
wp_rec
.
wp_pures
.
wp_alloc
l
as
"Hl"
;
first
done
.
wp_rec
.
wp_pures
.
wp_alloc
l
as
"Hl"
;
first
done
.
...
@@ -192,6 +197,7 @@ Section proof.
...
@@ -192,6 +197,7 @@ Section proof.
iFrame
"Hl HQs"
.
iPureIntro
.
lia
.
iFrame
"Hl HQs"
.
iPureIntro
.
lia
.
Qed
.
Qed
.
(* Version of [wp_array_init] with the auxiliary type [A] set to [val]. *)
Lemma
wp_array_init'
(
Q
:
nat
→
val
→
iProp
Σ
)
n
(
f
:
val
)
stk
E
:
Lemma
wp_array_init'
(
Q
:
nat
→
val
→
iProp
Σ
)
n
(
f
:
val
)
stk
E
:
(
0
<
n
)
%
Z
→
(
0
<
n
)
%
Z
→
{{{
(
□
∀
i
:
nat
,
WP
f
#
i
@
stk
;
E
{{
v
,
Q
i
v
}})
}}}
{{{
(
□
∀
i
:
nat
,
WP
f
#
i
@
stk
;
E
{{
v
,
Q
i
v
}})
}}}
...
...
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