Skip to content

Commit

Permalink
Support typed atomic load and store
Browse files Browse the repository at this point in the history
  • Loading branch information
upamanyus committed Feb 12, 2025
1 parent ec2036b commit e98c778
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 12 deletions.
41 changes: 41 additions & 0 deletions new/golang/theory/mem.v
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,47 @@ Section goose_lang.
iIntros; iApply "HΦ"; iFrame; done.
Qed.

Lemma wp_typed_Load (l : loc) (v : V) dq :
is_primitive_type t →
{{{ l ↦{dq} v }}}
! #l
{{{ RET #v; l ↦{dq} v }}}.
Proof using Type*.
intros Hprim.
pose proof (to_val_has_go_type v) as Hty.
unseal.
generalize dependent (#v).
clear dependent V.
intros.
iIntros "Hl HΦ".
destruct t; try by exfalso.
all: inversion Hty; subst;
inversion Hty; subst;
simpl; rewrite to_val_unseal /= loc_add_0 !right_id;
iApply (wp_load with "[$Hl]"); iFrame.
Qed.

Lemma wp_typed_AtomicStore (l : loc) (v v' : V) :
is_primitive_type t →
{{{ l ↦ v }}}
AtomicStore #l #v'
{{{ RET #(); l ↦ v' }}}.
Proof using Type*.
intros Hprim.
pose proof (to_val_has_go_type v) as Hty_old.
pose proof (to_val_has_go_type v') as Hty.
unseal.
generalize dependent (#v). generalize dependent (#v').
clear dependent V.
intros.
iIntros "Hl HΦ".
destruct t; try by exfalso.
all: inversion Hty; subst;
inversion Hty_old; inversion Hty; subst;
simpl; rewrite to_val_unseal /= loc_add_0 !right_id;
iApply (wp_atomic_store with "[$Hl]"); iFrame.
Qed.

End goose_lang.

Notation "l ↦ dq v" := (typed_pointsto l dq v%V)
Expand Down
15 changes: 3 additions & 12 deletions new/proof/sync/atomic.v
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,7 @@ Proof.
iIntros (?) "#? HΦ".
wp_func_call. wp_call.
iMod "HΦ" as (?) "[Haddr HΦ]".
rewrite to_val_unseal.
iApply (wp_load with "[Haddr]").
{ rewrite typed_pointsto_unseal /typed_pointsto_def to_val_unseal /= right_id loc_add_0 //. }
iNext. iIntros "H". iApply "HΦ".
rewrite typed_pointsto_unseal /typed_pointsto_def to_val_unseal /= right_id loc_add_0 //.
unshelve iApply (wp_typed_Load with "[$]"); try tc_solve; done.

Check failure on line 23 in new/proof/sync/atomic.v

View workflow job for this annotation

GitHub Actions / build (dev)

Tactic failure: iApply: cannot apply (▷ (addr ↦{dq} v -∗ ?Goal0 (# v)) -∗ WP ! (# addr) {{ v, ?Goal0 v }})%I.

Check failure on line 23 in new/proof/sync/atomic.v

View workflow job for this annotation

GitHub Actions / build (8.20)

Tactic failure: iApply: cannot apply (▷ (addr ↦{dq} v -∗ ?Goal0 (# v)) -∗ WP ! (# addr) {{ v, ?Goal0 v }})%I.
Qed.

Lemma wp_StoreUint64 (addr : loc) (v : w64) :
Expand All @@ -36,11 +32,7 @@ Proof.
iIntros (?) "#? HΦ".
wp_func_call. wp_call.
iMod "HΦ" as (?) "[Haddr HΦ]".
rewrite to_val_unseal.
iApply (wp_atomic_store with "[Haddr]").
{ rewrite typed_pointsto_unseal /typed_pointsto_def to_val_unseal /= right_id loc_add_0 //. }
iNext. iIntros "H". iApply "HΦ".
rewrite typed_pointsto_unseal /typed_pointsto_def to_val_unseal /= right_id loc_add_0 //.
unshelve iApply (wp_typed_AtomicStore with "[$]"); try tc_solve; done.
Qed.

Lemma wp_AddUint64 (addr : loc) (v : w64) :
Expand All @@ -52,8 +44,7 @@ Proof.
Admitted.

Definition own_Uint64 (u : loc) dq (v : w64) : iProp Σ :=
u ↦{dq} atomic.Uint64.mk (default_val _) (default_val _) v
.
u ↦{dq} atomic.Uint64.mk (default_val _) (default_val _) v.

Lemma wp_Uint64__Load u dq :
∀ Φ,
Expand Down

0 comments on commit e98c778

Please sign in to comment.