Documentation

GaudisCrypt.Language.Programs

Instances

    The state a statement runs in: the global program state together with the local state l (procedure parameters + local variables). Replaces the former State × l product so that the two halves are named.

    Instances For

      Lens onto the global part of a ProcedureState.

      Equations
      • One or more equations did not get rendered due to their size.
      Instances For

        Lens onto the local part of a ProcedureState.

        Equations
        • One or more equations did not get rendered due to their size.
        Instances For
          Instances For
            Instances
              structure GaudisCrypt.LocalVariableState (paramTypes : List Type) (locals : List ((t : Type) × Inhabited t)) :

              The local state of a procedure: parameter values (params) and local-variable values (vars). Indexed by the parameter types and the local declarations only (not the return type), so it can be formed before the return type is known — this is what lets a proc with an omitted return type elaborate.

              Instances For
                @[reducible]

                The local state for a full signature (delegates to LocalVariableState; reducible so sig.LocalVariableState locals is defeq to LocalVariableState sig.params locals).

                Equations
                Instances For
                  def GaudisCrypt.LocalVariableState.paramsL {paramTypes : List Type} {locals : List ((t : Type) × Inhabited t)} :
                  Lens (paramListToTuple paramTypes) (LocalVariableState paramTypes locals)

                  Lens onto the parameter tuple of a LocalVariableState.

                  Equations
                  • One or more equations did not get rendered due to their size.
                  Instances For
                    def GaudisCrypt.LocalVariableState.varsL {paramTypes : List Type} {locals : List ((t : Type) × Inhabited t)} :
                    Lens (paramListToTuple (List.map (fun (x : (t : Type) × Inhabited t) => x.fst) locals)) (LocalVariableState paramTypes locals)

                    Lens onto the local-variable tuple of a LocalVariableState.

                    Equations
                    • One or more equations did not get rendered due to their size.
                    Instances For
                      def GaudisCrypt.Lens.intoParams [ProgramSpec] {a : Type} {paramTypes : List Type} {locals : List ((t : Type) × Inhabited t)} (lens : Lens a (paramListToTuple paramTypes)) :
                      Lens a (ProcedureState (LocalVariableState paramTypes locals))

                      Lift a lens into the parameter tuple to a lens into the full procedure state (localL ∘ paramsL). Analogous to Lens.ofst. (Defined in the Lens namespace via _root_ so dot notation lens.intoParams resolves.)

                      Equations
                      Instances For
                        def GaudisCrypt.Lens.intoVars [ProgramSpec] {a : Type} {paramTypes : List Type} {locals : List ((t : Type) × Inhabited t)} (lens : Lens a (paramListToTuple (List.map (fun (x : (t : Type) × Inhabited t) => x.fst) locals))) :
                        Lens a (ProcedureState (LocalVariableState paramTypes locals))

                        Lift a lens into the local-variable tuple to a lens into the full procedure state (localL ∘ varsL). Analogous to Lens.ofst.

                        Equations
                        Instances For
                          instance GaudisCrypt.Programs.disjoint_intoVars [ProgramSpec] {a b : Type} {paramTypes : List Type} {locals : List ((t : Type) × Inhabited t)} {x : Lens a (paramListToTuple (List.map (fun (x : (t : Type) × Inhabited t) => x.fst) locals))} {y : Lens b (paramListToTuple (List.map (fun (x : (t : Type) × Inhabited t) => x.fst) locals))} [disjoint x y] :

                          Local program variables are Lens.intoVars of their slot projections; distinct slots are disjoint, and intoVars (two chain layers) preserves that.

                          Equations
                          Instances For

                            A sequences of procedure signatures, intended to be used to describe the type of holes in a program

                            Instances For
                              Instances For
                                def GaudisCrypt.HoleIndex.toFin {holes : HoleSigs} {sig : ProcedureSignature} :
                                HoleIndex holes sig → Fin holes.length
                                Equations
                                Instances For
                                  theorem GaudisCrypt.HoleIndex.toFin_inj [ProgramSpec] {holes : HoleSigs} {sig : ProcedureSignature} (i1 i2 : HoleIndex holes sig) :
                                  i1.toFin = i2.toFin → i1 = i2
                                  @[reducible, inline]
                                  abbrev GaudisCrypt.Var [ProgramSpec] (a : Type u_2) :
                                  Type (max u_2 u_1)
                                  Equations
                                  Instances For
                                    @[reducible, inline]
                                    abbrev GaudisCrypt.Expr [ProgramSpec] (a : Type u_2) :
                                    Type (max u_2 u_1)
                                    Equations
                                    Instances For
                                      inductive GaudisCrypt.StmtWithHoles [ProgramSpec] :
                                      HoleSigs → Type → Type (max 1 u_1)

                                      Syntactic program (with arbitrary Lean terms as expressions)

                                      Instances For
                                        structure GaudisCrypt.ProcedureWithHoles [ProgramSpec] (holeSigs : HoleSigs) (sig : ProcedureSignature) :
                                        Type (max 1 u_1)
                                        Instances For
                                          @[reducible, inline]

                                          The signature of a procedure-with-holes as a term — sig is otherwise only reachable as an implicit argument of the type, which makes it awkward to name in generated code.

                                          Equations
                                          Instances For
                                            @[match_pattern]
                                            Equations
                                            Instances For
                                              def GaudisCrypt.Stmt.call {l : Type} [ProgramSpec] {sig : ProcedureSignature} (x : Setter sig.ret (ProcedureState l)) (proc : Procedure sig) (params : Getter sig.ParamType (ProcedureState l)) :
                                              Equations
                                              Instances For

                                                The only instantiation of no holes at all.

                                                Instances For

                                                  Extend an instantiation by one more procedure, for one more (last-appended) hole. Written in the order the holes were appended, nil.push p₀ |>.push p₁ …, this is how an instantiation is built up from concrete procedures — note HoleIndex.zero is the last one pushed.

                                                  Equations
                                                  Instances For
                                                    @[simp]

                                                    Looking up the hole a push was made for.

                                                    @[simp]
                                                    theorem GaudisCrypt.HoleSigs.Instantiation.push_succ [ProgramSpec] {holes : HoleSigs} {sig sig' : ProcedureSignature} (inst : holes.Instantiation) (p : Procedure sig) (i : HoleIndex holes sig') :
                                                    push (fun {sig : ProcedureSignature} => inst) p i.succ = inst i

                                                    Looking up any other hole of a push falls through to the instantiation it extends.

                                                    Convert an instantiation into a plain list of procedures (tagged by their signature), in the same right-nested order as HoleSigs.Instantiation.toModuleTuple.

                                                    The head of the list corresponds to the most-recently appended hole signature.

                                                    Equations
                                                    • One or more equations did not get rendered due to their size.
                                                    • x_2.toList = []
                                                    Instances For
                                                      def GaudisCrypt.StmtWithHoles.instantiate [ProgramSpec] {holes : HoleSigs} {l : Type} (stmt : StmtWithHoles holes l) (instantiation : holes.Instantiation) :

                                                      Instantiate all holes in a statement using resolve, turning each .hole into a .call' of the resolved procedure. Hole-free constructors are simply re-typed.

                                                      Equations
                                                      Instances For
                                                        Equations
                                                        Instances For

                                                          A structural size measure used to justify termination of programDenotation. The auto-generated sizeOf for StmtWithHoles is trivially 0 (the inductive lives in a higher universe because its constructors quantify over a : Type), so we define our own.

                                                          Equations
                                                          Instances For

                                                            A hole-free statement has nothing to instantiate: every constructor is re-typed as itself, and the .hole case cannot occur (HoleIndex .empty _ is empty). Recursion is on depth — the statement's own index HoleSigs.empty is not a variable, so the equation compiler cannot recurse on it structurally.

                                                            @[simp]

                                                            Instantiating a procedure that has no holes leaves it alone.

                                                            @[irreducible]
                                                            Equations
                                                            • One or more equations did not get rendered due to their size.
                                                            Instances For

                                                              The procedure denotation as an explicit wrapper: initialise locals, run the body, extract (return_val, global).

                                                              Equations
                                                              Instances For

                                                                procedureDenotation of an instantiated procedure is procWrap of its body (generic over the holes and their instantiation).