open Prims
let pp_bv : FStarC_Syntax_Syntax.bv FStarC_Class_PP.pretty=
  {
    FStarC_Class_PP.pp =
      (fun bv ->
         let uu___ =
           FStarC_Class_Show.show FStarC_Syntax_Print.showable_bv bv in
         FStar_Pprint.arbitrary_string uu___)
  }
let pp_set (uu___ : 'a FStarC_Class_Ord.ord)
  (uu___1 : 'a FStarC_Class_PP.pretty) :
  'a FStarC_FlatSet.t FStarC_Class_PP.pretty=
  {
    FStarC_Class_PP.pp =
      (fun s ->
         let doclist ds =
           FStar_Pprint.surround_separate (Prims.of_int 2) Prims.int_zero
             (FStar_Pprint.doc_of_string "[]") FStar_Pprint.lbracket
             (FStar_Pprint.op_Hat_Hat FStar_Pprint.semi
                (FStar_Pprint.break_ Prims.int_one)) FStar_Pprint.rbracket ds in
         let uu___2 =
           let uu___3 =
             FStarC_Class_Setlike.elems ()
               (Obj.magic (FStarC_FlatSet.setlike_flat_set uu___))
               (Obj.magic s) in
           FStarC_List.map (FStarC_Class_PP.pp uu___1) uu___3 in
         doclist uu___2)
  }
let __def_check_scoped (uu___ : 'envut FStarC_Class_Binders.hasBinders)
  (uu___1 : 'thingut FStarC_Class_Binders.hasNames)
  (uu___2 : 'thingut FStarC_Class_PP.pretty) (rng : FStarC_Range_Type.range)
  (msg : Prims.string) (env : 'envut) (thing : 'thingut) : unit=
  let free = FStarC_Class_Binders.freeNames uu___1 thing in
  let scope = FStarC_Class_Binders.boundNames uu___ env in
  let uu___3 =
    let uu___4 =
      FStarC_Class_Setlike.subset ()
        (Obj.magic
           (FStarC_FlatSet.setlike_flat_set FStarC_Syntax_Syntax.ord_bv))
        (Obj.magic free) (Obj.magic scope) in
    Prims.op_Negation uu___4 in
  if uu___3
  then
    let uu___4 =
      let uu___5 =
        let uu___6 =
          let uu___7 = FStarC_Class_PP.pp uu___2 thing in
          FStar_Pprint.op_Hat_Slash_Hat (FStarC_Errors_Msg.text "t =") uu___7 in
        let uu___7 =
          let uu___8 =
            let uu___9 =
              FStarC_Class_PP.pp (pp_set FStarC_Syntax_Syntax.ord_bv pp_bv)
                free in
            FStar_Pprint.op_Hat_Slash_Hat (FStarC_Errors_Msg.text "FVs =")
              uu___9 in
          let uu___9 =
            let uu___10 =
              let uu___11 =
                FStarC_Class_PP.pp (pp_set FStarC_Syntax_Syntax.ord_bv pp_bv)
                  scope in
              FStar_Pprint.op_Hat_Slash_Hat
                (FStarC_Errors_Msg.text "Scope =") uu___11 in
            let uu___11 =
              let uu___12 =
                let uu___13 =
                  let uu___14 =
                    Obj.magic
                      (FStarC_Class_Setlike.diff ()
                         (Obj.magic
                            (FStarC_FlatSet.setlike_flat_set
                               FStarC_Syntax_Syntax.ord_bv)) (Obj.magic free)
                         (Obj.magic scope)) in
                  FStarC_Class_PP.pp
                    (pp_set FStarC_Syntax_Syntax.ord_bv pp_bv) uu___14 in
                FStar_Pprint.op_Hat_Slash_Hat
                  (FStarC_Errors_Msg.text "Diff =") uu___13 in
              [uu___12] in
            uu___10 :: uu___11 in
          uu___8 :: uu___9 in
        uu___6 :: uu___7 in
      (FStar_Pprint.op_Hat_Slash_Hat
         (FStarC_Errors_Msg.text "Internal: term is not well-scoped ")
         (FStar_Pprint.parens (FStar_Pprint.doc_of_string msg)))
        :: uu___5 in
    FStarC_Errors.log_issue FStarC_Class_HasRange.hasRange_range rng
      FStarC_Errors_Codes.Warning_Defensive ()
      (Obj.magic FStarC_Errors_Msg.is_error_message_list_doc)
      (Obj.magic uu___4)
  else ()
let def_check_scoped (uu___ : 'envut FStarC_Class_Binders.hasBinders)
  (uu___1 : 'thingut FStarC_Class_Binders.hasNames)
  (uu___2 : 'thingut FStarC_Class_PP.pretty) (rng : FStarC_Range_Type.range)
  (msg : Prims.string) (env : 'envut) (thing : 'thingut) : unit=
  let uu___3 = FStarC_Options.defensive () in
  if uu___3
  then __def_check_scoped uu___ uu___1 uu___2 rng msg env thing
  else ()
