Library MetaCoq.PCUIC.PCUICProgram

Definition of programs in template-coq, well-typed terms and provided transformations

From Coq Require Import ssreflect.
From MetaCoq.Template Require Import utils config EnvMap.
From MetaCoq.PCUIC Require Import PCUICAstUtils PCUICAst PCUICGlobalEnv PCUICTyping.

Global environment with a map for efficient lookups

Record global_env_map :=
  { trans_env_env :> global_env;
    trans_env_map : EnvMap.t global_decl;
    trans_env_repr : EnvMap.repr trans_env_env.(declarations) trans_env_map }.

Program Definition build_global_env_map (g : global_env) : global_env_map :=
  {| trans_env_env := g;
     trans_env_map := EnvMap.EnvMap.of_global_env g.(declarations) |}.

Definition global_env_ext_map := global_env_map × universes_decl.

Definition pcuic_program : Type := global_env_ext_map × term.

Definition global_env_ext_map_global_env_ext (g : global_env_ext_map) : global_env_ext :=
  (trans_env_env (fst g), g.2).
Coercion global_env_ext_map_global_env_ext : global_env_ext_map >-> global_env_ext.

Definition global_env_ext_map_global_env_map : global_env_ext_map global_env_map := fst.
Coercion global_env_ext_map_global_env_map : global_env_ext_map >-> global_env_map.


Definition wt_pcuic_program {cf : checker_flags} (p : pcuic_program) :=
  wf_ext p.1 × T, typing p.1 [] p.2 T.

Module TransLookup.
  Definition lookup_minductive (Σ : global_env_map) mind :=
    match EnvMap.lookup mind Σ.(trans_env_map) with
    | Some (InductiveDecl decl) ⇒ Some decl
    | _None
    end.

  Definition lookup_inductive Σ ind :=
    match lookup_minductive Σ (inductive_mind ind) with
    | Some mdecl
      match nth_error mdecl.(ind_bodies) (inductive_ind ind) with
      | Some ideclSome (mdecl, idecl)
      | NoneNone
      end
    | NoneNone
    end.
End TransLookup.