Documentation

SSA.Projects.LeanMlirCommon.SimplyTyped.WellTyped

Simple Intrinsically WellTyped MLIR programs #

This module sets up a simple typesystem for MLIR programs, where the only terminator is "return a value".

In particular:

We use VarName as the type of terminators, so that each terminator gives us exactly the variable we should return.

The type of a region specifies the number and types of arguments to its entry block and the region return type

  • arguments : List Ty
  • returnType : Ty
Instances For

    The signature of a specific operation specifies:

    • The number and types of its arguments,
    • The number and types of its regions, and
    • The type of it's return value
    Instances For

      To implement OpSignature for a type of Operations, we specify the signature of each operation op : Op

      Instances

        For each expression e in lets, add e.varName, (signature e).returnType to the context

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

          WellTyped #

          We define what it means for an untyped program to be well-formed under a specific context

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

                  Note that because we don't have branches between basic block, only the entry block to a region actually matters. Any other blocks, if specified, are unreachable and may be ignored. Also, regions are closed from above, so the well-formedness of a region does not depend on the context of the outer region

                  Equations
                  Instances For
                    @[irreducible]

                    RegionList.WellTyped regions regionTypes holds when regions and regionTypes are of the same length, and each region in the first list is welltyped according to the corresponing type of the second list. Morally, this can be expressed as regions.length = rgnTys.length ∧ ∀ r ∈ regions.zip rgnTys, Region.WellTyped r.fst r.snd However, we inline the definition to make the termination checker happy

                    Equations
                    Instances For

                      Theorems #

                      There exists an output context for which a Lets is well-typed iff it is well-typed for Lets.outContext lets _. This justifies the choice of this particular context in Body.WellTyped

                      @[simp]
                      theorem MLIR.SimplyTyped.RegionList.WellTyped.iff {Op : Type} {Ty : Type} [MLIR.SimplyTyped.OpSignature Op Ty] (regions : List (MLIR.UnTyped.Region Op MLIR.VarName)) (regionTypes : List (MLIR.SimplyTyped.RegionType Ty)) :
                      MLIR.SimplyTyped.RegionList.WellTyped regions regionTypes regions.length = regionTypes.length ∀ (r : MLIR.UnTyped.Region Op MLIR.VarName × MLIR.SimplyTyped.RegionType Ty), r regions.zip regionTypesMLIR.SimplyTyped.Region.WellTyped r.fst r.snd

                      Justify the RegionList.WellTyped definition

                      Congr #

                      Show that well-typedness is preserved by extensionally equivalent contexts TODO: this is no longer true, now that we've switched Lets.WellTyped to use equality