val field_of_tag_of_field
  (#l: P.union_typ)
  (tgs: tags l)
  (f: P.struct_field l)
: Lemma (field_of_tag #l tgs (tag_of_field #l tgs f) == f)
  [SMTPat (field_of_tag #l tgs (tag_of_field #l tgs f))]
let field_of_tag_of_field
  (#l: P.union_typ)
  (tgs: tags l)
  (f: P.struct_field l)
: Lemma (field_of_tag #l tgs (tag_of_field #l tgs f) == f)
  [SMTPat (field_of_tag #l tgs (tag_of_field #l tgs f))]
= field_of_tag_of_field' tgs f
val field_of_tag_of_field
  (#l: P.union_typ)
  (tgs: tags l)
  (f: P.struct_field l)
: Lemma (field_of_tag #l tgs (tag_of_field #l tgs f) == f)
  [SMTPat (field_of_tag #l tgs (tag_of_field #l tgs f))]
let field_of_tag_of_field (#l: P.union_typ) (tgs: tags l) (f: P.struct_field l)
    : Lemma (field_of_tag #l tgs (tag_of_field #l tgs f) == f)
      [SMTPat (field_of_tag #l tgs (tag_of_field #l tgs f))] =
field_of_tag_of_field' tgs f
FStar.TaggedUnion.fst.checked
prims.fst.checked FStar.UInt32.fsti.checked FStar.Pointer.fst.checked FStar.Pervasives.Native.fst.checked FStar.Pervasives.fsti.checked FStar.List.Tot.fst.checked FStar.HyperStack.ST.fsti.checked FStar.HyperStack.fst.checked
FStar.TaggedUnion.fst
FStar.Pointer.Base.union_typ FStar.TaggedUnion.tags FStar.Pointer.Base.struct_field FStar.TaggedUnion.field_of_tag_of_field' FStar.Pointer.Base.__proj__Mkstruct_typ__item__fields Prims.unit Prims.l_True Prims.squash Prims.eq2 FStar.TaggedUnion.field_of_tag FStar.TaggedUnion.tag_of_field Prims.Cons FStar.Pervasives.pattern FStar.Pervasives.smt_pat Prims.Nil
(*
   Copyright 2008-2018 Microsoft Research

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
*)
module FStar.TaggedUnion

module P = FStar.Pointer
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST

(** Code of a tagged union *)

let typ_l (l: P.union_typ) = {
  P.name = "__tagged__" ^ l.P.name;
  P.fields = P.([("tag", TBase TUInt32); ("union", TUnion l)]);
}

let tag_field (l: P.union_typ) : P.struct_field (typ_l l) = "tag"
let union_field (l: P.union_typ) : P.struct_field (typ_l l) = "union"

let typ (l: P.union_typ) : P.typ = P.TStruct (typ_l l)

(******************************************************************************)

(* Tagging, at the logical level *)

(* Abstract predicate providing a proof that some field matches some tag. *)

let field_matches_tag
  (#l: P.union_typ) (tgs: tags l)
  (f: P.struct_field l) (t: UInt32.t)
: Tot Type0
= tag_of_field tgs f == t

let rec field_of_tag_of_field'
  (#l: P.struct_typ')
  (tgs: tags' l)
  (f: P.struct_field' l)
: Lemma (field_of_tag' #l tgs (tag_of_field' #l tgs f) == f)
  [SMTPat (field_of_tag' #l tgs (tag_of_field' #l tgs f))]
= let ((f', _) :: l') = l in
  let (t' :: tgs') = tgs in
  if f = f' then ()
  else (
    let ff : string = f in
    field_of_tag_of_field' #l' tgs' ff
  )

let field_of_tag_of_field
  (#l: P.union_typ)
  (tgs: tags l)
  (f: P.struct_field l)
: Lemma (field_of_tag #l tgs (tag_of_field #l tgs f) == f)
val field_of_tag_of_field
  (#l: P.union_typ)
  (tgs: tags l)
  (f: P.struct_field l)
: Lemma (field_of_tag #l tgs (tag_of_field #l tgs f) == f)
  [SMTPat (field_of_tag #l tgs (tag_of_field #l tgs f))]
tgs: FStar.TaggedUnion.tags l -> f: FStar.Pointer.Base.struct_field l
  -> FStar.Pervasives.Lemma
      (ensures FStar.TaggedUnion.field_of_tag tgs (FStar.TaggedUnion.tag_of_field tgs f) == f)
      [SMTPat (FStar.TaggedUnion.field_of_tag tgs (FStar.TaggedUnion.tag_of_field tgs f))]