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
c5d99607
Commit
c5d99607
authored
Apr 29, 2021
by
Rodolphe Lepigre
Browse files
Learn side-conditions in the continuation.
parent
4ad473f2
Pipeline
#45879
passed with stage
in 16 minutes and 33 seconds
Changes
7
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
examples/binary_search.c
View file @
c5d99607
...
...
@@ -51,7 +51,7 @@ bool compare_int(void *x, void *y) {
[[
rc
::
requires
(
"[alloc_initialized]"
)]]
[[
rc
::
tactics
(
"all: try by repeat constructor; lia."
)]]
[[
rc
::
tactics
(
"all: try by apply _."
)]]
[[
rc
::
tactics
(
"all: try by do 4 (destruct x'; [ naive_solver lia |]); exfalso; apply: (H
0
3%nat) => //; lia."
)]]
[[
rc
::
tactics
(
"all: try by do 4 (destruct x'; [ naive_solver lia |]); exfalso; apply: (H
3
3%nat) => //; lia."
)]]
void
test
()
{
size_t
*
ptrs
[
5
];
ptrs
[
0
]
=
alloc
(
sizeof
(
size_t
));
...
...
examples/btree.c
View file @
c5d99607
...
...
@@ -45,18 +45,19 @@ void free_btree(btree_t* t){
[[
rc
::
ensures
(
"{¬ k ∈ l → StronglySorted (<) (take s l ++ k :: drop s l)}"
)]]
[[
rc
::
ensures
(
"own p : array<{it_layout i32}, {(l `at_type` int i32) ++ "
"replicate (sz - n)%nat (uninit i32 : type)}>"
)]]
[[
rc
::
tactics
(
"destruct (decide (i = s)); by naive_solver lia."
)]]
[[
rc
::
tactics
(
//FIXME
"destruct (decide (i = s)); last eapply H0 => //; by naive_solver lia."
)]]
[[
rc
::
tactics
(
// FIXME
"move: (elem_of_list_lookup_1 _ _ H1
4
) => [i Hi]. "
"move: (elem_of_list_lookup_1 _ _ H1
6
) => [i Hi]. "
"destruct (decide (y = k)); [ done | exfalso ]. "
"assert (k < y) as Hky by lia. "
"assert (i < s)%nat as Hle by by eapply StronglySorted_lookup_index_lt. "
"assert (i < s) as His by lia. assert (k < k) by by eapply H0. by lia."
)]]
[[
rc
::
tactics
(
// FIXME
"apply StronglySorted_insert_drop_take; last done. "
"* move => z Hz. destruct (l !! z) eqn:?
; naive_solver
lia. "
"* move: (elem_of_list_lookup_2 l s y H
7
) => Hy. rewrite H
7
/=. "
"
assert (k ≠ y); [ by set_solver | by lia ]."
)]]
"* move => z Hz. destruct (l !! z) eqn:?
=> //=. eapply H0 => //;
lia. "
"* move: (elem_of_list_lookup_2 l s y H
9
) => Hy. rewrite H
9
/=. "
"assert (k ≠ y); [ by set_solver | by lia ]."
)]]
[[
rc
::
tactics
(
// FIXME
"assert (s = length l) as -> by lia. assert (k < k); last by lia. "
"move: (elem_of_list_lookup_1 _ _ H7) => [i Hi]. "
...
...
@@ -87,9 +88,9 @@ int key_index(int* ar, int n, int k){
[[
rc
::
tactics
(
"apply: (btree_invariant_in_range_child H2); naive_solver lia."
)]]
[[
rc
::
tactics
(
"rewrite H1; apply: (btree_invariant_lookup_child H2); by naive_solver."
)]]
[[
rc
::
tactics
(
"do 2 rewrite list_insert_id //; by destruct y0."
)]]
[[
rc
::
tactics
(
"assert (k ∉ x0) as Hx1. { move => /H
7
Hk. apply lookup_lt_Some in Hk. lia. } "
[[
rc
::
tactics
(
"assert (k ∉ x0) as Hx1. { move => /H
8
Hk. apply lookup_lt_Some in Hk. lia. } "
"apply: (btree_invariant_in_range_child H2); by naive_solver."
)]]
[[
rc
::
tactics
(
"assert (k ∉ x0) as Hx1. { move => /H
7
Hk. apply lookup_lt_Some in Hk. lia. } "
[[
rc
::
tactics
(
"assert (k ∉ x0) as Hx1. { move => /H
8
Hk. apply lookup_lt_Some in Hk. lia. } "
"rewrite H1. apply: (btree_invariant_lookup_child H2); by naive_solver."
)]]
[[
rc
::
tactics
(
"rewrite list_insert_id //; by destruct y."
)]]
bool
btree_member
(
btree_t
*
t
,
int
k
){
...
...
examples/proofs/binary_search/generated_proof_test.v
View file @
c5d99607
...
...
@@ -28,7 +28,7 @@ Section proof_test.
Unshelve
.
all
:
sidecond_hook
;
prepare_sideconditions
;
normalize_and_simpl_goal
;
try
solve_goal
;
unsolved_sidecond_hook
.
all
:
try
by
repeat
constructor
;
lia
.
all
:
try
by
apply
_
.
all
:
try
by
do
4
(
destruct
x'
;
[
naive_solver
lia
|])
;
exfalso
;
apply
:
(
H
0
3
%
nat
)
=>
//
;
lia
.
all
:
try
by
do
4
(
destruct
x'
;
[
naive_solver
lia
|])
;
exfalso
;
apply
:
(
H
3
3
%
nat
)
=>
//
;
lia
.
all
:
print_sidecondition_goal
"test"
.
Qed
.
End
proof_test
.
examples/proofs/btree/generated_code.v
View file @
c5d99607
This source diff could not be displayed because it is too large. You can
view the blob
instead.
examples/proofs/btree/generated_proof_btree_member.v
View file @
c5d99607
...
...
@@ -46,8 +46,8 @@ Section proof_btree_member.
+
apply
:
(
btree_invariant_in_range_child
H2
)
;
naive_solver
lia
.
+
rewrite
H1
;
apply
:
(
btree_invariant_lookup_child
H2
)
;
by
naive_solver
.
+
do
2
rewrite
list_insert_id
//
;
by
destruct
y0
.
+
assert
(
k
∉
x0
)
as
Hx1
.
{
move
=>
/
H
7
Hk
.
apply
lookup_lt_Some
in
Hk
.
lia
.
}
apply
:
(
btree_invariant_in_range_child
H2
)
;
by
naive_solver
.
+
assert
(
k
∉
x0
)
as
Hx1
.
{
move
=>
/
H
7
Hk
.
apply
lookup_lt_Some
in
Hk
.
lia
.
}
rewrite
H1
.
apply
:
(
btree_invariant_lookup_child
H2
)
;
by
naive_solver
.
+
assert
(
k
∉
x0
)
as
Hx1
.
{
move
=>
/
H
8
Hk
.
apply
lookup_lt_Some
in
Hk
.
lia
.
}
apply
:
(
btree_invariant_in_range_child
H2
)
;
by
naive_solver
.
+
assert
(
k
∉
x0
)
as
Hx1
.
{
move
=>
/
H
8
Hk
.
apply
lookup_lt_Some
in
Hk
.
lia
.
}
rewrite
H1
.
apply
:
(
btree_invariant_lookup_child
H2
)
;
by
naive_solver
.
+
rewrite
list_insert_id
//
;
by
destruct
y
.
all
:
print_sidecondition_goal
"btree_member"
.
Qed
.
...
...
examples/proofs/btree/generated_proof_key_index.v
View file @
c5d99607
...
...
@@ -34,9 +34,9 @@ Section proof_key_index.
-
repeat
liRStep
;
liShow
.
all
:
print_typesystem_goal
"key_index"
"#1"
.
Unshelve
.
all
:
sidecond_hook
;
prepare_sideconditions
;
normalize_and_simpl_goal
;
try
solve_goal
;
unsolved_sidecond_hook
.
+
destruct
(
decide
(
i
=
s
))
;
by
naive_solver
lia
.
+
move
:
(
elem_of_list_lookup_1
_
_
H1
4
)
=>
[
i
Hi
].
destruct
(
decide
(
y
=
k
))
;
[
done
|
exfalso
].
assert
(
k
<
y
)
as
Hky
by
lia
.
assert
(
i
<
s
)%
nat
as
Hle
by
by
eapply
StronglySorted_lookup_index_lt
.
assert
(
i
<
s
)
as
His
by
lia
.
assert
(
k
<
k
)
by
by
eapply
H0
.
by
lia
.
+
apply
StronglySorted_insert_drop_take
;
last
done
.
*
move
=>
z
Hz
.
destruct
(
l
!!
z
)
eqn
:
?
;
naive_solver
lia
.
*
move
:
(
elem_of_list_lookup_2
l
s
y
H
7
)
=>
Hy
.
rewrite
H
7
/=.
assert
(
k
≠
y
)
;
[
by
set_solver
|
by
lia
].
+
destruct
(
decide
(
i
=
s
))
;
last
eapply
H0
=>
//
;
by
naive_solver
lia
.
+
move
:
(
elem_of_list_lookup_1
_
_
H1
6
)
=>
[
i
Hi
].
destruct
(
decide
(
y
=
k
))
;
[
done
|
exfalso
].
assert
(
k
<
y
)
as
Hky
by
lia
.
assert
(
i
<
s
)%
nat
as
Hle
by
by
eapply
StronglySorted_lookup_index_lt
.
assert
(
i
<
s
)
as
His
by
lia
.
assert
(
k
<
k
)
by
by
eapply
H0
.
by
lia
.
+
apply
StronglySorted_insert_drop_take
;
last
done
.
*
move
=>
z
Hz
.
destruct
(
l
!!
z
)
eqn
:
?
=>
//=.
eapply
H0
=>
//
;
lia
.
*
move
:
(
elem_of_list_lookup_2
l
s
y
H
9
)
=>
Hy
.
rewrite
H
9
/=.
assert
(
k
≠
y
)
;
[
by
set_solver
|
by
lia
].
+
assert
(
s
=
length
l
)
as
->
by
lia
.
assert
(
k
<
k
)
;
last
by
lia
.
move
:
(
elem_of_list_lookup_1
_
_
H7
)
=>
[
i
Hi
].
move
:
(
lookup_lt_Some
_
_
_
Hi
)
=>
Hlt
.
naive_solver
lia
.
+
assert
(
s
=
length
l
)
as
->
by
lia
.
rewrite
drop_all
.
apply
StronglySorted_app
;
[
..
|
done
|
by
do
2
constructor
].
move
=>
x
y
Hx
Hy
.
assert
(
y
=
k
)
as
->
by
set_solver
.
move
:
(
elem_of_list_lookup_1
_
_
Hx
)
=>
[
i
Hi
].
move
:
(
lookup_lt_Some
_
_
_
Hi
)
=>
Hlt
.
naive_solver
lia
.
all
:
print_sidecondition_goal
"key_index"
.
...
...
theories/lithium/interpreter.v
View file @
c5d99607
...
...
@@ -14,6 +14,10 @@ Definition EVAR_ID {A} (x : A) : A := x.
Arguments
EVAR_ID
:
simpl
never
.
(** * Lemmas used by tactics *)
Lemma
tac_and_learn
{
P
T
:
Prop
}
:
P
→
(
P
→
T
)
→
P
∧
T
.
Proof
.
naive_solver
.
Qed
.
Section
coq_tactics
.
Context
{
Σ
:
gFunctors
}.
...
...
@@ -645,7 +649,8 @@ Ltac liSideCond :=
|
_
=>
fail
"could not simplify goal with evar"
end
]
|
_
=>
split
;
[
first
[
fast_done
|
shelve
]
|
]
(* Non-trivila side-conditions are added to the context for the continuation. *)
|
_
=>
first
[
split
;
[
fast_done
|
]
|
apply
tac_and_learn
;
[
shelve
|
]
]
end
]
end
|
_
=>
fail
"do_side_cond: unknown goal"
end
.
...
...
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