val tag_of_field_of_tag' (#l: P.struct_typ') (tgs: tags' l) (t: UInt32.t)
    : Lemma (requires (List.Tot.mem t tgs))
      (ensures (List.Tot.mem t tgs /\ tag_of_field' #l tgs (field_of_tag' #l tgs t) == t))
      [SMTPat (tag_of_field' #l tgs (field_of_tag' #l tgs t))]
let rec tag_of_field_of_tag'
  (#l: P.struct_typ')
  (tgs: tags' l)
  (t: UInt32.t)
: Lemma
  (requires (List.Tot.mem t tgs))
  (ensures (
    List.Tot.mem t tgs /\
    tag_of_field' #l tgs (field_of_tag' #l tgs t) == t
  ))
  [SMTPat (tag_of_field' #l tgs (field_of_tag' #l tgs t))]
= let ((f', _) :: l') = l in
  let (t' :: tgs') = tgs in
  if t = t' then ()
  else (
    tag_of_field_of_tag' #l' tgs' t
  )
val tag_of_field_of_tag' (#l: P.struct_typ') (tgs: tags' l) (t: UInt32.t)
    : Lemma (requires (List.Tot.mem t tgs))
      (ensures (List.Tot.mem t tgs /\ tag_of_field' #l tgs (field_of_tag' #l tgs t) == t))
      [SMTPat (tag_of_field' #l tgs (field_of_tag' #l tgs t))]
let rec tag_of_field_of_tag' (#l: P.struct_typ') (tgs: tags' l) (t: UInt32.t)
    : Lemma (requires (List.Tot.mem t tgs))
      (ensures (List.Tot.mem t tgs /\ tag_of_field' #l tgs (field_of_tag' #l tgs t) == t))
      [SMTPat (tag_of_field' #l tgs (field_of_tag' #l tgs t))] =
let (f', _) :: l' = l in
let t' :: tgs' = tgs in
if t = t' then () else (tag_of_field_of_tag' #l' tgs' t)
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.struct_typ' FStar.TaggedUnion.tags' FStar.UInt32.t Prims.string FStar.Pointer.Base.typ Prims.list FStar.Pervasives.Native.tuple2 Prims.op_Equality Prims.bool FStar.TaggedUnion.tag_of_field_of_tag' Prims.unit Prims.b2t FStar.List.Tot.Base.mem Prims.squash Prims.l_and Prims.eq2 FStar.TaggedUnion.tag_of_field' FStar.TaggedUnion.field_of_tag' 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)
  [SMTPat (field_of_tag #l tgs (tag_of_field #l tgs f))]
= field_of_tag_of_field' tgs f

let rec tag_of_field_of_tag'
  (#l: P.struct_typ')
  (tgs: tags' l)
  (t: UInt32.t)
: Lemma
  (requires (List.Tot.mem t tgs))
  (ensures (
    List.Tot.mem t tgs /\
    tag_of_field' #l tgs (field_of_tag' #l tgs t) == t
  ))
val tag_of_field_of_tag' (#l: P.struct_typ') (tgs: tags' l) (t: UInt32.t)
    : Lemma (requires (List.Tot.mem t tgs))
      (ensures (List.Tot.mem t tgs /\ tag_of_field' #l tgs (field_of_tag' #l tgs t) == t))
      [SMTPat (tag_of_field' #l tgs (field_of_tag' #l tgs t))]
tgs: FStar.TaggedUnion.tags' l -> t: FStar.UInt32.t
  -> FStar.Pervasives.Lemma (requires FStar.List.Tot.Base.mem t tgs)
      (ensures
        FStar.List.Tot.Base.mem t tgs /\
        FStar.TaggedUnion.tag_of_field' tgs (FStar.TaggedUnion.field_of_tag' tgs t) == t)
      [SMTPat (FStar.TaggedUnion.tag_of_field' tgs (FStar.TaggedUnion.field_of_tag' tgs t))]