Documentation

Core.TypedPlusCal.Syntax

The output of PlusCal statement checking. ElaboratedPlusCal.Statement/Block/Branches/ Declarations/Process/Algorithm mirror CorePlusCal's shape node-for-node, but parameterized over (τ ε : Type) rather than CorePlusCal's (α β : Type): Ref carries an extra resolved type : τ, and Statement.receive an extra coe : TypedTLAPlus.Coercion, so a later pass (WellFormedness/Restrictions.lean check 1) can tell whether a bare Ref position (assign's LHS, receive's destination) is Channel-shaped without Γ, which is gone by then. Coercion isn't a third parameter — its shape is TLA⁺-expression-specific regardless of instantiation.

TypedPlusCal pins this layer at τ := TypedTLAPlus.Typ, ε := TypedTLAPlus.Expression TypedTLAPlus.Typ. Core/ComputablePlusCal/Syntax.lean pins the same layer at ComputableTLAPlus's types, reusing these definitions rather than re-copying them: neither Ref.type nor receive's Coercion field change shape across the two, so no second monomorphic copy is needed. Multicast is reused generically from CorePlusCal (its target is a bare String, not a Ref, so no type to carry either way).

structure ElaboratedPlusCal.Ref (τ ε : Type) :

Carries its own resolved baseType (unlike CorePlusCal.Ref). args follows CorePlusCal.Ref's shape: one entry per path segment, .inl for a .field segment, .inr for a (unary) bracket-index segment.

baseType is the base variable's type (name's Γ-lookup result), before any .args segment is applied — kept this way rather than the result type because the result type is always cheap to recompute from baseType (Ref.stepType/.resultType below), but recovering baseType from the result type isn't possible in general (a record access or tuple projection isn't invertible).

Instances For
    def ElaboratedPlusCal.instReprRef.repr {τ✝ ε✝ : Type} [Repr τ✝] [Repr ε✝] :
    Ref τ✝ ε✝Std.Format
    Equations
    • One or more equations did not get rendered due to their size.
    Instances For
      @[implicit_reducible]
      instance ElaboratedPlusCal.instReprRef {τ✝ ε✝ : Type} [Repr τ✝] [Repr ε✝] :
      Repr (Ref τ✝ ε✝)
      Equations
      @[reducible, inline]

      CorePlusCal.Multicast, reused generically.

      Equations
      Instances For
        inductive ElaboratedPlusCal.Statement (τ ε : Type) :

        A fresh copy of CorePlusCal.Statement's shape, not an abbrev over it: parameterized over (τ ε : Type) instead of (α β : Type), since receive needs an extra field CorePlusCal.Statement.receive has no room for.

        Instances For
          @[implicit_reducible]
          instance ElaboratedPlusCal.instReprBranches {τ✝ ε✝ : Type} {a✝ : Bool} [Repr τ✝] [Repr ε✝] :
          Repr (Branches τ✝ ε✝ a✝)
          Equations
          partial def ElaboratedPlusCal.instReprBranches.repr_2 {τ✝ ε✝ : Type} {a✝ : Bool} [Repr τ✝] [Repr ε✝] :
          Block τ✝ ε✝ a✝Std.Format
          partial def ElaboratedPlusCal.instReprBlock.repr_1 {τ✝ ε✝ : Type} {a✝ : Bool} [Repr τ✝] [Repr ε✝] :
          Statement τ✝ ε✝ a✝Std.Format
          partial def ElaboratedPlusCal.instReprStatement.repr_1 {τ✝ ε✝ : Type} {a✝ : Bool} [Repr τ✝] [Repr ε✝] :
          Statement τ✝ ε✝ a✝Std.Format
          partial def ElaboratedPlusCal.instReprBranches.repr_1 {τ✝ ε✝ : Type} {a✝ : Bool} [Repr τ✝] [Repr ε✝] :
          Statement τ✝ ε✝ a✝Std.Format
          @[implicit_reducible]
          instance ElaboratedPlusCal.instReprStatement {τ✝ ε✝ : Type} {a✝ : Bool} [Repr τ✝] [Repr ε✝] :
          Repr (Statement τ✝ ε✝ a✝)
          Equations
          partial def ElaboratedPlusCal.instReprStatement.repr_2 {τ✝ ε✝ : Type} {a✝ : Bool} [Repr τ✝] [Repr ε✝] :
          Block τ✝ ε✝ a✝Std.Format
          partial def ElaboratedPlusCal.instReprBlock.repr_3 {τ✝ ε✝ : Type} {a✝ : Bool} [Repr τ✝] [Repr ε✝] :
          Branches τ✝ ε✝ a✝Std.Format
          partial def ElaboratedPlusCal.instReprBranches.repr_3 {τ✝ ε✝ : Type} {a✝ : Bool} [Repr τ✝] [Repr ε✝] :
          Branches τ✝ ε✝ a✝Std.Format
          @[implicit_reducible]
          instance ElaboratedPlusCal.instReprBlock {τ✝ ε✝ : Type} {a✝ : Bool} [Repr τ✝] [Repr ε✝] :
          Repr (Block τ✝ ε✝ a✝)
          Equations
          partial def ElaboratedPlusCal.instReprBlock.repr_2 {τ✝ ε✝ : Type} {a✝ : Bool} [Repr τ✝] [Repr ε✝] :
          Block τ✝ ε✝ a✝Std.Format
          partial def ElaboratedPlusCal.instReprStatement.repr_3 {τ✝ ε✝ : Type} {a✝ : Bool} [Repr τ✝] [Repr ε✝] :
          Branches τ✝ ε✝ a✝Std.Format
          inductive ElaboratedPlusCal.Block (τ ε : Type) :

          A fresh copy of CorePlusCal.Block's shape.

          Instances For
            inductive ElaboratedPlusCal.Branches (τ ε : Type) :

            A fresh copy of CorePlusCal.Branches's shape.

            Instances For
              @[reducible, inline]
              abbrev ElaboratedPlusCal.Block.begin {τ ε : Type} {b : Bool} :
              Block τ ε bList (Statement τ ε false)
              Equations
              Instances For
                @[reducible, inline]
                abbrev ElaboratedPlusCal.Block.end {τ ε : Type} {b : Bool} :
                Block τ ε bStatement τ ε b
                Equations
                Instances For
                  def ElaboratedPlusCal.Block.forStatements {τ ε : Type} {b : Bool} {m : TypeType} [Monad m] (act : {b' : Bool} → Statement τ ε b'm Unit) (B : Block τ ε b) :

                  Runs act over every non-terminal statement in B (B.begin, in order), then its terminal one (B.end). Shared shape for WellFormedness's per-check walkers (Restrictions.checkRestrictions, WellScoped.checkWellScoped, Labelling.checkGotoTargets), each supplying its own act.

                  Equations
                  Instances For
                    def ElaboratedPlusCal.Branches.forStatements {τ ε : Type} {b : Bool} {m : TypeType} [Monad m] (act : {b' : Bool} → Statement τ ε b'm Unit) :
                    Branches τ ε bm Unit

                    Block.forStatements, distributed over either/or branches.

                    Equations
                    Instances For
                      partial def ElaboratedPlusCal.Statement.forEachNode {τ ε : Type} {b : Bool} {m : TypeType} [Monad m] (act : {b' : Bool} → Statement τ ε b'm Unit) (s : Statement τ ε b) :

                      Pre-order recursion over s and every statement nested inside it: act s first, then the same over whatever if/either/while/with nest below — the four constructors that embed a Block/Branches; every other statement is a leaf. The structural half of what a per-node check needs, so a check that has no context to thread supplies only the check itself (WellFormedness/Labelling.lean) rather than restating this recursion.

                      A check whose per-node work depends on where it is in the tree can't use this — WellFormedness/ WellScoped/TypedPlusCal.lean extends its in-scope set at every with binder, which needs the recursion and the check interleaved, so it keeps its own copy.

                      partial: the recursion isn't visibly decreasing to Lean through the Block/Branches nesting, same as every other walker over this type.

                      A fresh copy of CorePlusCal.Declarations's shape.

                      Instances For
                        def ElaboratedPlusCal.instReprDeclarations.repr {τ✝ ε✝ : Type} [Repr τ✝] [Repr ε✝] :
                        Declarations τ✝ ε✝Std.Format
                        Equations
                        • One or more equations did not get rendered due to their size.
                        Instances For
                          @[implicit_reducible]
                          instance ElaboratedPlusCal.instReprDeclarations {τ✝ ε✝ : Type} [Repr τ✝] [Repr ε✝] :
                          Repr (Declarations τ✝ ε✝)
                          Equations
                          structure ElaboratedPlusCal.Process (τ ε : Type) :

                          A fresh copy of CorePlusCal.Process's shape.

                          Instances For
                            @[implicit_reducible]
                            instance ElaboratedPlusCal.instReprProcess {τ✝ ε✝ : Type} [Repr τ✝] [Repr ε✝] :
                            Repr (Process τ✝ ε✝)
                            Equations
                            def ElaboratedPlusCal.instReprProcess.repr {τ✝ ε✝ : Type} [Repr τ✝] [Repr ε✝] :
                            Process τ✝ ε✝Std.Format
                            Equations
                            • One or more equations did not get rendered due to their size.
                            Instances For

                              A fresh copy of CorePlusCal.Algorithm's shape.

                              Instances For
                                @[implicit_reducible]
                                instance ElaboratedPlusCal.instReprAlgorithm {τ✝ ε✝ : Type} [Repr τ✝] [Repr ε✝] :
                                Repr (Algorithm τ✝ ε✝)
                                Equations
                                def ElaboratedPlusCal.instReprAlgorithm.repr {τ✝ ε✝ : Type} [Repr τ✝] [Repr ε✝] :
                                Algorithm τ✝ ε✝Std.Format
                                Equations
                                • One or more equations did not get rendered due to their size.
                                Instances For
                                  def ElaboratedPlusCal.Process.forStatements {τ ε : Type} {m : TypeType} [Monad m] (act : {b' : Bool} → Statement τ ε b'm Unit) (p : Process τ ε) :

                                  Runs act over the top-level statements of every labelled block of every thread of p — the threads/(label, Block) nesting flattened away. Only the top-level statements: act is whatever the caller wants per block, Statement.forEachNode if it wants the whole subtree.

                                  Per process, not per algorithm, because all three callers need it that way: labels (WellFormedness/Labelling.lean) and in-scope names (WellFormedness/WellScoped/TypedPlusCal. lean) are both process-scoped, and WellFormedness/Reachability.lean visits a process's own id/mailbox/localState expressions in the same loop.

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

                                    Checked PlusCal expressions — always TypedTLAPlus.Expression at the checker's own Typ.

                                    Equations
                                    Instances For

                                      The type after one Ref path segment, given the type before it. A pure structural pattern match — every segment is already elaborated, so this replays the same step-rule Elaborator/Expressions.lean's stepInto/indexInto use at check time, without re-checking. Total: the fallback (τ unchanged) only triggers on a Ref no well-typed input can produce.

                                      Equations
                                      Instances For

                                        A Ref's final/result type — what assign r e/receive c r check e's type against — recomputed from baseType by walking args left to right via stepType.

                                        Equations
                                        Instances For