Skip to content

Commit 47b4e21

Browse files
authored
Merge pull request #487 from FStarLang/gebner_ghost_null
Null ghost references.
2 parents 6dcbf79 + 07f5c79 commit 47b4e21

18 files changed

+136
-0
lines changed

lib/common/Pulse.Lib.Core.fsti

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,8 @@ val later_equiv (p q: slprop) : squash (later (equiv p q) == equiv (later p) (la
498498
[@@erasable]
499499
val slprop_ref : Type0
500500

501+
val null_slprop_ref : slprop_ref
502+
501503
val slprop_ref_pts_to ([@@@mkey]x: slprop_ref) (y: slprop) : slprop
502504

503505
val slprop_ref_alloc (y: slprop)
@@ -765,6 +767,8 @@ val gather
765767
[@@erasable]
766768
val core_ghost_pcm_ref : Type0
767769

770+
val null_core_ghost_pcm_ref : core_ghost_pcm_ref
771+
768772
let ghost_pcm_ref
769773
(#a:Type u#a)
770774
(p:FStar.PCM.pcm a)
@@ -790,6 +794,16 @@ val timeless_ghost_pcm_pts_to
790794
: Lemma (timeless (ghost_pcm_pts_to r v))
791795
[SMTPat (timeless (ghost_pcm_pts_to r v))]
792796

797+
val ghost_pts_to_not_null
798+
(#a:Type)
799+
(#p:pcm a)
800+
(r:ghost_pcm_ref p)
801+
(v:a)
802+
: stt_ghost (squash (r =!= null_core_ghost_pcm_ref))
803+
emp_inames
804+
(ghost_pcm_pts_to r v)
805+
(fun _ -> ghost_pcm_pts_to r v)
806+
793807
val ghost_alloc
794808
(#a:Type u#1)
795809
(#pcm:pcm a)

lib/core/Pulse.Lib.Core.fst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,7 @@ let later_equiv = Sep.later_equiv
239239

240240
// TODO: these are write-once for now, though it's possible to construct fractional permission variables out of this
241241
let slprop_ref = PulseCore.Action.slprop_ref
242+
let null_slprop_ref = PulseCore.Action.null_slprop_ref
242243
let slprop_ref_pts_to x y = PulseCore.Action.slprop_ref_pts_to x y
243244
let slprop_ref_alloc x = A.slprop_ref_alloc x
244245
let slprop_ref_share x #y = A.slprop_ref_share x y
@@ -358,12 +359,15 @@ let gather = A.gather
358359
////////////////////////////////////////////////////////
359360
let core_ghost_pcm_ref = PulseCore.Action.core_ghost_ref
360361

362+
let null_core_ghost_pcm_ref = PulseCore.Action.core_ghost_ref_null
363+
361364
instance non_informative_ghost_pcm_ref a p = {
362365
reveal = (fun r -> Ghost.reveal r) <: NonInformative.revealer (ghost_pcm_ref p);
363366
}
364367

365368
let ghost_pcm_pts_to #a #p r v = PulseCore.Action.ghost_pts_to #a #p r v
366369
let timeless_ghost_pcm_pts_to #a #p r v = PulseCore.Action.timeless_ghost_pts_to #a #p r v
370+
let ghost_pts_to_not_null #a #p r v = A.ghost_pts_to_not_null #a #p r v
367371
let ghost_alloc = A.ghost_alloc
368372
let ghost_read = A.ghost_read
369373
let ghost_write = A.ghost_write

lib/core/PulseCore.Action.fst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -726,8 +726,12 @@ let elim_exists (#a:Type u#a) (p:a -> slprop)
726726
let drop p = lift_pre_act0_act fun #ictx -> ITA.drop #ictx p
727727

728728
let core_ghost_ref = Mem.core_ghost_ref
729+
let core_ghost_ref_null = Mem.core_ghost_ref_null
729730
let ghost_pts_to #a #pcm r x = Sep.lift (Mem.ghost_pts_to #a #pcm r x)
730731
let timeless_ghost_pts_to #a #p r x = Sep.timeless_lift (Mem.ghost_pts_to #a #p r x)
732+
let ghost_pts_to_not_null #a #p r v =
733+
lift_pre_act0_act fun #ictx ->
734+
ITA.lift_mem_action (Mem.ghost_pts_to_not_null_action #a #p r v)
731735
let ghost_alloc #a #pcm x = let open Mem in lift_eqs (); lift_pre_act0_act fun #ictx -> ITA.lift_mem_action <| ghost_alloc #a #pcm x
732736
let ghost_read #a #p r x f = let open Mem in lift_eqs(); lift_pre_act1_act fun #ictx -> ITA.lift_mem_action <| ghost_read #a #p r x f
733737
let ghost_write #a #p r x y f = let open Mem in lift_eqs(); lift_pre_act0_act fun #ictx -> ITA.lift_mem_action <| ghost_write #a #p r x y f
@@ -770,6 +774,7 @@ let equiv_elim (a b:slprop) =
770774
lift_pre_act0_act fun #ictx -> ITA.equiv_elim #ictx a b
771775

772776
let slprop_ref = Sep.slprop_ref
777+
let null_slprop_ref = Sep.null_slprop_ref
773778
let slprop_ref_pts_to = Sep.slprop_ref_pts_to
774779
let slprop_ref_alloc y = lift_pre_act0_act fun #ictx -> ITA.slprop_ref_alloc #ictx y
775780
let slprop_ref_share x y = lift_pre_act0_act fun #ictx -> ITA.slprop_ref_share #ictx x y

lib/core/PulseCore.Action.fsti

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -465,6 +465,7 @@ val drop (p:slprop)
465465
////////////////////////////////////////////////////////////////////////
466466
[@@erasable]
467467
val core_ghost_ref : Type u#0
468+
val core_ghost_ref_null : core_ghost_ref
468469
let ghost_ref (#a:Type u#a) (p:pcm a) : Type u#0 = core_ghost_ref
469470
val ghost_pts_to (#a:Type u#1) (#p:pcm a) (r:ghost_ref p) (v:a) : slprop
470471

@@ -475,6 +476,13 @@ val timeless_ghost_pts_to
475476
(v:a)
476477
: Lemma (timeless (ghost_pts_to r v))
477478

479+
val ghost_pts_to_not_null (#a:Type u#1) (#p:FStar.PCM.pcm a) (r:ghost_ref p) (v:a)
480+
: act (squash (r =!= core_ghost_ref_null))
481+
Ghost
482+
emp_inames
483+
(ghost_pts_to r v)
484+
(fun _ -> ghost_pts_to r v)
485+
478486
val ghost_alloc
479487
(#a:Type u#1)
480488
(#pcm:pcm a)
@@ -675,6 +683,8 @@ val equiv_elim (a b:slprop)
675683
[@@erasable]
676684
val slprop_ref : Type0
677685

686+
val null_slprop_ref : slprop_ref
687+
678688
val slprop_ref_pts_to (x: slprop_ref) (y: slprop) : slprop
679689

680690
val slprop_ref_alloc (y: slprop)

lib/core/PulseCore.Atomic.fst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,7 @@ let write r x y f = A.write r x y f
296296
let share #a #pcm r v0 v1 = lift_neutral_ghost (A.share r v0 v1)
297297
let gather #a #pcm r v0 v1 = lift_neutral_ghost (A.gather r v0 v1)
298298

299+
let ghost_pts_to_not_null #a #p r v = lift_neutral_ghost (A.ghost_pts_to_not_null #a #p r v)
299300
let ghost_alloc #a #pcm x = lift_neutral_ghost <| A.ghost_alloc #a #pcm x
300301
let ghost_read
301302
(#a:Type)

lib/core/PulseCore.Atomic.fsti

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,16 @@ val gather
382382
////////////////////////////////////////////////////////////////////////
383383
// Ghost References
384384
////////////////////////////////////////////////////////////////////////
385+
val ghost_pts_to_not_null
386+
(#a:Type u#1)
387+
(#p:FStar.PCM.pcm a)
388+
(r:ghost_ref p)
389+
(v:a)
390+
: stt_ghost (squash (r =!= core_ghost_ref_null))
391+
emp_inames
392+
(ghost_pts_to r v)
393+
(fun _ -> ghost_pts_to r v)
394+
385395
val ghost_alloc
386396
(#a:Type u#1)
387397
(#pcm:pcm a)

lib/core/PulseCore.BaseHeapSig.fst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,9 @@ let ghost_share #a #p r x y =
230230
let ghost_gather #a #p r x y =
231231
lift_heap_action (H2.ghost_gather #a #p r x y)
232232
#(fun _ -> ghost_pts_to r (op p x y))
233+
let ghost_pts_to_not_null_action #a #p r x =
234+
lift_heap_action (H2.ghost_pts_to_not_null_action #a #p r x)
235+
#(fun _ -> ghost_pts_to #a #p r x)
233236

234237
let extend #a #pcm x = fun frame m0 ->
235238
let (| y, m1 |) = H2.apply_action (H2.extend #a #pcm x) frame m0 in
@@ -267,6 +270,9 @@ let ghost_share' #a #p r x y =
267270
let ghost_gather' #a #p r x y =
268271
ghost_gather #_ #(R.raise p) r (U.raise_val (reveal x)) (U.raise_val (reveal y))
269272

273+
let ghost_pts_to_not_null_action' #a #p r v =
274+
ghost_pts_to_not_null_action #_ #(R.raise p) r (U.raise_val (reveal v))
275+
270276
let pts_to' #a #p r x =
271277
H2.pts_to #(U.raise_t a) #(R.raise p) r (U.raise_val x)
272278

lib/core/PulseCore.BaseHeapSig.fsti

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ let is_null : core_ref -> GTot bool = H2.core_ref_is_null
2222
let ref (a:Type u#a) (p:pcm a) = core_ref
2323

2424
let core_ghost_ref : Type u#0 = H2.core_ghost_ref
25+
let core_ghost_ref_null = H2.core_ghost_ref_null
2526
let ghost_ref (a:Type u#a) (p:pcm a) = core_ghost_ref
2627
let add (#a:Type) (f:Set.decide_eq a) (x:a) (y:Set.set a) = Set.union (Set.singleton f x) y
2728

@@ -181,6 +182,15 @@ val ghost_gather
181182
(ghost_pts_to r v0 `star` ghost_pts_to r v1)
182183
(fun _ -> ghost_pts_to r (op pcm v0 v1))
183184

185+
val ghost_pts_to_not_null_action
186+
(#a:Type)
187+
(#pcm:pcm a)
188+
(r:ghost_ref a pcm)
189+
(v:Ghost.erased a)
190+
: ghost_action_except (squash (r =!= core_ghost_ref_null))
191+
(ghost_pts_to r v)
192+
(fun _ -> ghost_pts_to r v)
193+
184194
val extend
185195
(#a:Type)
186196
(#pcm:pcm a)
@@ -288,6 +298,15 @@ val ghost_gather'
288298
(ghost_pts_to' u#a u#b r v0 `star` ghost_pts_to' u#a u#b r v1)
289299
(fun _ -> ghost_pts_to' u#a u#b r (op pcm v0 v1))
290300

301+
val ghost_pts_to_not_null_action'
302+
(#a:Type u#a)
303+
(#pcm:pcm a)
304+
(r:ghost_ref a pcm)
305+
(v:Ghost.erased a)
306+
: ghost_action_except (squash (r =!= core_ghost_ref_null))
307+
(ghost_pts_to' u#a u#b r v)
308+
(fun _ -> ghost_pts_to' u#a u#b r v)
309+
291310
val pts_to' (#a:Type u#a) (#p:pcm a) (r:ref a p) (x:a) : slprop u#(max a b)
292311

293312
val extend'

lib/core/PulseCore.Heap2.fst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,7 @@ let lift_erased
471471
refined_pre_action_as_action g
472472

473473
let core_ghost_ref = erased H.core_ref
474+
let core_ghost_ref_null = H.core_ref_null
474475
let core_ghost_ref_eq x y = H.core_ref_eq (reveal x) (reveal y)
475476
let ghost_pts_to #a #p r v = llift GHOST (H.pts_to #a #p r v)
476477

@@ -652,3 +653,6 @@ let ghost_gather
652653
(Ghost.hide <|
653654
lift_action_ghost ni_squash (H.gather_action #a #pcm r v0 v1))
654655
#pop-options
656+
657+
let ghost_pts_to_not_null_action #a #p r v =
658+
lift_action_ghost ni_squash (H.pts_to_not_null_action #a #p r v)

lib/core/PulseCore.Heap2.fsti

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -630,6 +630,7 @@ val lift_erased
630630

631631
[@@erasable]
632632
val core_ghost_ref : Type0
633+
val core_ghost_ref_null : core_ghost_ref
633634
val core_ghost_ref_eq (x y:core_ghost_ref) : GTot (b:bool{b <==> (x==y)})
634635
let ghost_ref (#[@@@unused] a:Type u#a) ([@@@unused]p:pcm a) : Type0 = core_ghost_ref
635636
val ghost_pts_to (#a:Type u#a) (#p:pcm a) (r:ghost_ref p) (v:a) : slprop u#a
@@ -728,3 +729,13 @@ val ghost_gather
728729
(ghost_pts_to r v0 `star` ghost_pts_to r v1)
729730
(squash (composable pcm v0 v1))
730731
(fun _ -> ghost_pts_to r (op pcm v0 v1))
732+
733+
val ghost_pts_to_not_null_action
734+
(#a:Type u#a)
735+
(#pcm:pcm a)
736+
(r:ghost_ref pcm)
737+
(v:Ghost.erased a)
738+
: action #IMMUTABLE
739+
(ghost_pts_to r v)
740+
(squash (r =!= core_ghost_ref_null))
741+
(fun _ -> ghost_pts_to r v)

0 commit comments

Comments
 (0)