Skip to content

Commit 76a31be

Browse files
committed
Checkpoint
1 parent f6d4abc commit 76a31be

File tree

4 files changed

+44
-50
lines changed

4 files changed

+44
-50
lines changed

new/golang/defn/postlang.v

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,8 @@ Inductive is_primitive_zero_val : go.type → ∀ {V} `{!IntoVal V}, V → Prop
104104

105105
#[warning="-uniform-inheritance"]
106106
Local Coercion GoInstruction : go_op >-> val.
107-
(** [go.ValidCore] defines when a GoContext is valid, excludin
108-
slice, map, and
109-
channel stuff. *)
107+
(** [go.CoreSemantics] defines when a GoContext is valid, excluding slice, map,
108+
and channel stuff. *)
110109
Class CoreSemantics `{!GoContext} :=
111110
{
112111
alloc_underlying t : alloc t = alloc (to_underlying t);

new/golang/theory/predeclared.v

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,14 @@ Program Global Instance typed_pointsto_foo : TypedPointsto foo_t :=
181181
("a" ∷ struct_field_ref foo "a"%go l ↦{dq} v.(a) ∗
182182
"b" ∷ struct_field_ref foo "b"%go l ↦{dq} v.(b)
183183
)%I |}.
184+
Final Obligation.
185+
Proof.
186+
simpl. intros. iNamedSuffix 1 "1". iNamedSuffix 1 "2".
187+
destruct v1, v2; simpl.
188+
iCombine "a1 a2" gives %->.
189+
iCombine "b1 b2" gives %->.
190+
done.
191+
Qed.
184192

185193
Global Instance settable_foo : Settable foo_t :=
186194
settable! mk < a; b >.

new/golang/theory/slice.v

Lines changed: 32 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@ End def.
2323
End slice.
2424

2525
Section defns_and_lemmas.
26-
Context `{ffi_sem: ffi_semantics} `{!ffi_interp ffi} `{!heapGS Σ}.
26+
Context `{ffi_sem: ffi_semantics} `{!ffi_interp ffi} `{!heapGS Σ} `{!go.CoreSemantics}.
2727

2828
Definition own_slice_def {V} t `{!IntoVal V} `{!TypedPointsto V} `{!IntoValTyped V t}
29-
(s : slice.t) (dq : dfrac) vs
29+
(s : slice.t) (dq : dfrac) (vs : list V)
3030
: iProp Σ :=
31-
([∗ list] i ↦ v ∈ vs, (slice_index_ref t i s) ↦{dq} v ) ∗
32-
length vs = sint.nat s.(slice.len) ∧ 0 ≤ sint.Z s.(slice.len) ≤ sint.Z s.(slice.cap) ⌝.
31+
(s.(slice.ptr) ↦{dq} (array.mk t (sint.Z s.(slice.len)) vs)) ∗
32+
⌜ sint.Z s.(slice.len) ≤ sint.Z s.(slice.cap) ⌝.
3333
Program Definition own_slice := sealed @own_slice_def.
3434
Definition own_slice_unseal : own_slice = _ := seal_eq _.
3535

@@ -62,10 +62,22 @@ Definition own_slice_cap_unseal : own_slice_cap = _ := seal_eq _.
6262
Ltac unseal := rewrite ?own_slice_unseal /own_slice_def
6363
?own_slice_cap_unseal /own_slice_cap_def.
6464

65+
Lemma own_array_nil ptr dq :
66+
⊢ ptr ↦{dq} (array.mk t 0 []).
67+
Proof.
68+
rewrite typed_pointsto_unseal. simpl. iPureIntro. done.
69+
Qed.
70+
71+
Lemma own_array_len ptr dq n vs :
72+
ptr ↦{dq} (array.mk t n vs) -∗ ⌜ n = Z.of_nat $ length vs ⌝.
73+
Proof.
74+
rewrite typed_pointsto_unseal. simpl. iIntros "[% _] !%". done.
75+
Qed.
76+
6577
Lemma own_slice_nil dq :
6678
⊢ slice.nil ↦[t]*{dq} ([] : list V).
6779
Proof.
68-
unseal. simpl. iPureIntro. split_and!; done.
80+
unseal. simpl. iDestruct own_array_nil as "$". done.
6981
Qed.
7082

7183
Lemma own_slice_empty dq s :
@@ -74,7 +86,7 @@ Lemma own_slice_empty dq s :
7486
⊢ s ↦[t]*{dq} ([] : list V).
7587
Proof.
7688
unseal. intros Hsz Hcap. destruct s. simpl in *.
77-
iPureIntro. split_and!; [done|word|word|word].
89+
rewrite Hsz. iDestruct own_array_nil as "$". word.
7890
Qed.
7991

8092
Lemma own_slice_cap_none s :
@@ -93,65 +105,40 @@ Qed.
93105
Lemma own_slice_len s dq vs :
94106
s ↦[t]*{dq} vs -∗ ⌜length vs = sint.nat s.(slice.len) ∧ 0 ≤ sint.Z s.(slice.len)⌝.
95107
Proof.
96-
unseal. iIntros "(_&[%%]) !%"; word.
108+
unseal. iIntros "(H&%)". iDestruct (own_array_len with "H") as %?. word.
97109
Qed.
98110

99-
Lemma array_index_ref_add i j l :
100-
array_index_ref t (i + j) l = array_index_ref t j (array_index_ref t i l).
101-
Proof.
102-
Admitted. (* FIXME: assumption. *)
103-
104111
Lemma own_slice_agree s dq1 dq2 vs1 vs2 :
105112
s ↦[t]*{dq1} vs1 -∗
106113
s ↦[t]*{dq2} vs2 -∗
107114
⌜vs1 = vs2⌝.
108115
Proof.
109-
unseal.
110-
iIntros "[Hs1 [%%]] [Hs2 [%%]]".
111-
assert (length vs1 = length vs2) by congruence.
112-
unfold slice_index_ref.
113-
generalize (slice.ptr s). intros l.
114-
assert (length vs1 = length vs2) as Hlen by done.
115-
clear -Hlen IntoValTyped0.
116-
(iInduction vs1 as [|v1 vs1] "IH" forall (l vs2 Hlen)).
117-
{ simpl in Hlen.
118-
destruct vs2; simpl in Hlen; try congruence.
119-
auto. }
120-
destruct vs2; simpl in Hlen; first by congruence.
121-
simpl.
122-
iDestruct "Hs1" as "[Hx1 Ha1]".
123-
iDestruct "Hs2" as "[Hx2 Ha2]".
124-
Set Typeclasses Debug.
125-
eassert (CombineSepGives (array_index_ref t 0%nat l ↦{dq1} v1) (array_index_ref t 0%nat l ↦{dq2} v)
126-
?[R']).
127-
{
128-
Print Hint.
129-
Search CombineSepGives.
130-
apply _.
131-
autoapply with typeclass_instances.
132-
}
133-
iCombine "Hx1 Hx2" gives "H". %[_ ->]. (* FIXME: AsDFractional? *)
134-
setoid_rewrite loc_add_stride_Sn.
135-
iDestruct ("IH" $! _ vs2 with "[] Ha1 Ha2") as %->; auto.
116+
unseal. iIntros "[Hs1 %] [Hs2 %]".
117+
iCombine "Hs1 Hs2" gives %[=->]. done.
136118
Qed.
137119

138-
Global Instance own_slice_persistent s vs : Persistent (s ↦*□ vs).
139-
Proof. unseal; apply _. Qed.
120+
Global Instance own_slice_persistent s vs : Persistent (s ↦[t]*□ vs).
121+
Proof. unseal. apply _. Qed.
140122

141123
#[global]
142124
Instance own_slice_dfractional s vs :
143-
DFractional (λ dq, s ↦*{dq} vs).
125+
DFractional (λ dq, s ↦[t]*{dq} vs).
144126
Proof. unseal; apply _. Qed.
145127

146128
#[global]
147129
Instance own_slice_as_dfractional s dq vs :
148-
AsDFractional (s ↦*{dq} vs) (λ dq, s ↦*{dq} vs) dq.
130+
AsDFractional (s ↦[t]*{dq} vs) (λ dq, s ↦[t]*{dq} vs) dq.
149131
Proof. auto. Qed.
150132

151133
#[global]
152134
Instance own_slice_as_fractional s q vs :
153-
fractional.AsFractional (s ↦*{#q} vs) (λ q, s ↦*{#q} vs) q.
154-
Proof. unseal; split; auto; apply _. Qed.
135+
fractional.AsFractional (s ↦[t]*{#q} vs) (λ q, s ↦[t]*{#q} vs) q.
136+
Proof.
137+
split; auto.
138+
change (λ q0 : Qp, s ↦[t]*{#q0} vs) with (λ q : Qp, (λ dq, s ↦[t]*{dq} vs) (DfracOwn q)).
139+
apply fractional_of_dfractional.
140+
apply _.
141+
Qed.
155142

156143
Lemma own_slice_valid s dq (vs: list V) :
157144
go_type_size t > 0 →

src/goose_lang/lang.v

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -592,7 +592,7 @@ Record t (ty : go.type) (V : Type) (n : Z) :=
592592
mk { arr : list V }.
593593
End goose_lang.
594594
End array.
595-
Arguments array.mk (ty) {_ _} (_).
595+
Arguments array.mk (ty) {_} (n arr).
596596
Arguments array.arr {_ _ _} (_).
597597

598598
Section external.
@@ -674,7 +674,7 @@ Global Instance into_val_func : IntoVal func.t :=
674674
Global Instance into_val_array t `{!IntoVal V} n : IntoVal (array.t t V n) :=
675675
{|
676676
into_val_def v := ArrayV (into_val <$> v.(array.arr));
677-
zero_val := array.mk t $ replicate (Z.to_nat n) (zero_val V);
677+
zero_val := array.mk t n $ replicate (Z.to_nat n) (zero_val V);
678678
|}.
679679

680680
Global Instance into_val_slice : IntoVal slice.t :=

0 commit comments

Comments
 (0)