val update_pointer_directly_maintains_variable_among_gvars
      (v: var_id_t)
      (p: Armada.Pointer.t)
      (new_storage: valid_object_storage_t)
      (mem: Armada.Memory.t)
    : Lemma (requires variable_among_gvars mem v)
      (ensures
        (match update_pointer_directly p new_storage mem with
          | ComputationProduces mem' -> variable_among_gvars mem' v
          | _ -> True))
val update_pointer_directly_maintains_variable_among_gvars
      (v: var_id_t)
      (p: Armada.Pointer.t)
      (new_storage: valid_object_storage_t)
      (mem: Armada.Memory.t)
    : Lemma (requires variable_among_gvars mem v)
      (ensures
        (match update_pointer_directly p new_storage mem with
          | ComputationProduces mem' -> variable_among_gvars mem' v
          | _ -> True))
let rec update_pointer_directly_maintains_variable_among_gvars
  (v: var_id_t)
  (p: Armada.Pointer.t)
  (new_storage: valid_object_storage_t)
  (mem: Armada.Memory.t)
  : Lemma (requires variable_among_gvars mem v)
          (ensures  (match update_pointer_directly p new_storage mem with
                     | ComputationProduces mem' -> variable_among_gvars mem' v
                     | _ -> True)) =
  match update_pointer_directly p new_storage mem with
  | ComputationImpossible | ComputationUndefined -> ()
  | ComputationProduces mem' ->
      (match p with
       | PointerField struct_ptr field_id ->
           let parent = ComputationProduces?.result (dereference_computation struct_ptr mem) in
           (match parent with
            | ObjectStorageStruct fields ->
                let new_parent = update_storage_child parent field_id new_storage in
                update_pointer_directly_maintains_variable_among_gvars v struct_ptr new_parent mem)
       | PointerIndex array_ptr idx ->
           let parent = ComputationProduces?.result (dereference_computation array_ptr mem) in
           (match parent with
            | ObjectStorageArray element_td elements ->
                let new_parent = update_storage_child parent idx new_storage in
                update_pointer_directly_maintains_variable_among_gvars v array_ptr new_parent mem)
       | PointerRoot root_id -> ()
       | _ -> ())
module Strategies.GlobalVars.Permanent

open Armada.Action
open Armada.Base
open Armada.Computation
open Armada.Expression
open Armada.Init
open Armada.Memory
open Armada.Pointer
open Armada.Program
open Armada.State
open Armada.Statement
open Armada.Thread
open Armada.Transition
open Armada.Type
open FStar.Sequence.Base
open FStar.Tactics.V2
open Spec.List
open Spec.Map
open Spec.Ubool
open Strategies.ArmadaStatement
open Util.List
open Util.Tactics

let variable_among_gvars (mem: Armada.Memory.t) (v: var_id_t) : GTot bool =
  let root_id = RootIdGlobal v in
  let root = mem root_id in
  RootGlobal? root

let all_variables_among_gvars (mem: Armada.Memory.t) (vs: list var_id_t) : GTot bool =
  for_all_ghost (variable_among_gvars mem) vs
/
Util.Tactics.fst.checked Util.List.fst.checked Strategies.ArmadaStatement.fst.checked Spec.Ubool.fst.checked Spec.Map.fst.checked Spec.List.fst.checked prims.fst.checked FStar.Tactics.V2.fst.checked FStar.Sequence.Base.fsti.checked FStar.Pervasives.Native.fst.checked FStar.Pervasives.fsti.checked FStar.Classical.Sugar.fsti.checked Armada.Type.fst.checked Armada.Transition.fst.checked Armada.Thread.fst.checked Armada.Step.fst.checked Armada.Statement.fst.checked Armada.State.fst.checked Armada.Program.fst.checked Armada.Pointer.fst.checked Armada.Memory.fst.checked Armada.Init.fst.checked Armada.Expression.fst.checked Armada.Computation.fst.checked Armada.Base.fst.checked Armada.Action.fst.checked
Strategies.GlobalVars.Permanent.fst

    v: Armada.Base.var_id_t ->
    p: Armada.Pointer.t ->
    new_storage: Armada.Memory.valid_object_storage_t ->
    mem: Armada.Memory.t
  -> FStar.Pervasives.Lemma (requires Strategies.GlobalVars.Permanent.variable_among_gvars mem v)
      (ensures
        ((match Armada.Memory.update_pointer_directly p new_storage mem with
            | Armada.Computation.ComputationProduces #_ mem' ->
              Strategies.GlobalVars.Permanent.variable_among_gvars mem' v
            | _ -> Prims.l_True)
          <:
          Type0))
Armada.Base.var_id_t Armada.Pointer.t Armada.Memory.valid_object_storage_t Armada.Memory.t Armada.Memory.update_pointer_directly Prims.nat FStar.Sequence.Base.seq Armada.Memory.object_storage_t Strategies.GlobalVars.Permanent.update_pointer_directly_maintains_variable_among_gvars Armada.Memory.update_storage_child Prims.unit Armada.Computation.__proj__ComputationProduces__item__result Armada.Memory.dereference_computation Armada.Type.object_td_t Armada.Base.root_id_t Prims.b2t Strategies.GlobalVars.Permanent.variable_among_gvars Prims.squash Armada.Computation.conditional_computation_t Prims.l_True Prims.Nil FStar.Pervasives.pattern
let rec update_pointer_directly_maintains_variable_among_gvars
      (v: var_id_t)
      (p: Armada.Pointer.t)
      (new_storage: valid_object_storage_t)
      (mem: Armada.Memory.t)
    : Lemma (requires variable_among_gvars mem v)
      (ensures
        (match update_pointer_directly p new_storage mem with
          | ComputationProduces mem' -> variable_among_gvars mem' v
          | _ -> True)) =
  
match update_pointer_directly p new_storage mem with
| ComputationImpossible | ComputationUndefined -> ()
| ComputationProduces mem' ->
  (match p with
    | PointerField struct_ptr field_id ->
      let parent = ComputationProduces?.result (dereference_computation struct_ptr mem) in
      (match parent with
        | ObjectStorageStruct fields ->
          let new_parent = update_storage_child parent field_id new_storage in
          update_pointer_directly_maintains_variable_among_gvars v struct_ptr new_parent mem)
    | PointerIndex array_ptr idx ->
      let parent = ComputationProduces?.result (dereference_computation array_ptr mem) in
      (match parent with
        | ObjectStorageArray element_td elements ->
          let new_parent = update_storage_child parent idx new_storage in
          update_pointer_directly_maintains_variable_among_gvars v array_ptr new_parent mem)
    | PointerRoot root_id -> ()
    | _ -> ())