Documentation

Core.Go.Syntax

The target of Network2Go: the fragment of Go the thesis gives a denotational semantics to, extended with what the compilation listings actually emit.

inductive Go.Typ :

Go types, per the cases the semantics' zero value is defined over, plus named/var for the generic runtime types.

  • int : Typ
  • str : Typ
  • bool : Typ
  • chan (τ : Typ) : Typ

    chan τ

  • slice (τ : Typ) : Typ

    []τ

  • array (n : ) (τ : Typ) : Typ

    [n]τ

  • map (key value : Typ) : Typ

    map[κ]τ

  • struct (fields : List (String × Typ)) : Typ

    struct {x₁ τ₁, …, xₙ τₙ}

  • func (params returns : List Typ) : Typ

    func(τ₁, …, τₙ) (τ'₁, …, τ'ₘ) — parameter names aren't part of the type.

  • named (name : String) (args : List Typ) : Typ

    A named type, applied to type arguments when generic: Address, Network, Lock[τ], Receiver[τ], Set[τ], LazyFunction[τ, τ'].

  • var (name : String) : Typ

    A generic type parameter, bound by the enclosing Function.typeParams.

Instances For
    @[implicit_reducible]
    Equations
    @[implicit_reducible]
    Equations
    @[implicit_reducible]
    Equations
    partial def Go.instBEqTyp.beq :
    TypTypBool
    Instances For

      Binary operators, including the short-circuiting &&/||. Their non-strictness is a fact about the semantic rule for and/or, not about the syntax, so they live here rather than as separate Expression constructors — a denotation case-splits on the operator either way.

      Instances For
        Equations
        Instances For
          inductive Go.Builtin :

          Go's builtin functions, kept out of Expression.call so that a user-chosen name colliding with one of them is a non-issue.

          Instances For
            @[implicit_reducible]
            Equations
            Equations
            Instances For
              Equations
              Instances For
                @[implicit_reducible]
                Equations
                inductive Go.Ref (Expr : Type) :

                An assignable reference. No type annotation, unlike GuardedPlusCal.Ref.

                Generic over Expr rather than a member of the Expression/Statement mutual family below: a reference contains expressions but never statements, so nothing in it needs the knot tied.

                Instances For
                  def Go.instReprRef.repr {Expr✝ : Type} [Repr Expr✝] :
                  Ref Expr✝Std.Format
                  Equations
                  Instances For
                    @[implicit_reducible]
                    instance Go.instReprRef {Expr✝ : Type} [Repr Expr✝] :
                    Repr (Ref Expr✝)
                    Equations
                    @[implicit_reducible]
                    instance Go.instInhabitedRef {a✝ : Type} :
                    Inhabited (Ref a✝)
                    Equations
                    structure Go.SelectClause (α : Type) :

                    One g → {S} arm of a select. guard is itself a statement — in practice a send or receive. Generic over the statement type so that Statement below can nest it.

                    • guard : α
                    • body : List α
                    Instances For
                      @[implicit_reducible]
                      instance Go.instReprSelectClause {α✝ : Type} [Repr α✝] :
                      Equations
                      def Go.instReprSelectClause.repr {α✝ : Type} [Repr α✝] :
                      Equations
                      • One or more equations did not get rendered due to their size.
                      Instances For
                        structure Go.SwitchClause (Expr α : Type) :

                        One v → {S} arm of a switch.

                        • head : Expr
                        • body : List α
                        Instances For
                          def Go.instReprSwitchClause.repr {Expr✝ α✝ : Type} [Repr Expr✝] [Repr α✝] :
                          SwitchClause Expr✝ α✝Std.Format
                          Equations
                          • One or more equations did not get rendered due to their size.
                          Instances For
                            @[implicit_reducible]
                            instance Go.instReprSwitchClause {Expr✝ α✝ : Type} [Repr Expr✝] [Repr α✝] :
                            Repr (SwitchClause Expr✝ α✝)
                            Equations
                            @[implicit_reducible]
                            instance Go.instInhabitedSwitchClause {a✝ : Type} [Inhabited a✝] {a✝¹ : Type} :
                            Inhabited (SwitchClause a✝ a✝¹)
                            Equations
                            inductive Go.Expression (α : Type) :

                            Go expressions, plus funcLit. α carries type annotations at the sites that need one — the same role it plays in ComputableTLAPlus.Expression.

                            Instances For
                              @[implicit_reducible]
                              instance Go.instReprExpression {α✝ : Type} [Repr α✝] :
                              Equations
                              partial def Go.instReprExpression.repr_2 {α✝ : Type} [Repr α✝] :
                              Statement α✝Std.Format
                              @[implicit_reducible]
                              instance Go.instReprStatement {α✝ : Type} [Repr α✝] :
                              Repr (Statement α✝)
                              Equations
                              partial def Go.instReprStatement.repr_1 {α✝ : Type} [Repr α✝] :
                              Expression α✝Std.Format
                              partial def Go.instReprExpression.repr_1 {α✝ : Type} [Repr α✝] :
                              Expression α✝Std.Format
                              partial def Go.instReprStatement.repr_2 {α✝ : Type} [Repr α✝] :
                              Statement α✝Std.Format
                              inductive Go.Statement (α : Type) :

                              Go statements. Blocks are List Statement — see the module doc.

                              Instances For
                                @[implicit_reducible]
                                Equations
                                @[implicit_reducible]
                                Equations
                                structure Go.Function (α : Type) :

                                A top-level function, plus typeParams for the generic functions the compiler emits. Each type parameter carries its constraint, which is an ordinary type: any, comparable, or one of the runtime library's own interfaces (Eq[T], Ord[T]).

                                Instances For
                                  @[implicit_reducible]
                                  instance Go.instReprFunction {α✝ : Type} [Repr α✝] :
                                  Repr (Function α✝)
                                  Equations
                                  def Go.instReprFunction.repr {α✝ : Type} [Repr α✝] :
                                  Function α✝Std.Format
                                  Equations
                                  • One or more equations did not get rendered due to their size.
                                  Instances For
                                    @[implicit_reducible]
                                    Equations
                                    def Go.Ref.map {Expr Expr' : Type} (g : ExprExpr') :
                                    Ref ExprRef Expr'
                                    Equations
                                    Instances For
                                      def Go.Ref.traverse {m : TypeType} [Applicative m] {Expr Expr' : Type} (g : Exprm Expr') :
                                      Ref Exprm (Ref Expr')
                                      Equations
                                      Instances For
                                        @[implicit_reducible]
                                        Equations
                                        @[implicit_reducible]
                                        Equations
                                        partial def Go.Expression.map {α β : Type} (f : αβ) :

                                        partial rather than structurally recursive: α occurs under List/Prod in most constructors, the same situation Core/CorePlusCal/Syntax.lean's own instances are partial for.

                                        partial def Go.Statement.map {α β : Type} (f : αβ) :
                                        @[implicit_reducible]
                                        Equations
                                        @[implicit_reducible]
                                        Equations
                                        @[implicit_reducible]
                                        def Go.instInhabitedOfApplicative_core {F : Type u_1 → Type u_2} [Applicative F] {α : Type u_1} [Inhabited α] :
                                        Inhabited (F α)
                                        Equations
                                        Instances For
                                          partial def Go.Expression.traverse {F : TypeType} [Applicative F] {α β : Type} (f : αF β) :
                                          Expression αF (Expression β)
                                          partial def Go.Statement.traverse {F : TypeType} [Applicative F] {α β : Type} (f : αF β) :
                                          Statement αF (Statement β)
                                          @[implicit_reducible]
                                          Equations
                                          @[implicit_reducible]
                                          Equations
                                          @[implicit_reducible]
                                          Equations
                                          • One or more equations did not get rendered due to their size.
                                          @[implicit_reducible]
                                          Equations
                                          • One or more equations did not get rendered due to their size.
                                          inductive Go.Declaration (α : Type) :

                                          A top-level declaration: what a generated .go file is a list of.

                                          Function alone is enough for the statement layer, but definition compilation turns a parameter-less operator and every function definition into a package-level var — the former because Go's const accepts only a small class of types, none of which a TLA⁺ definition generally has, the latter because a function is a LazyFunction value rather than a Go func.

                                          A package-level var cannot be generic in Go, which is what forces both forms to reject a type variable in their type; only Function carries typeParams.

                                          • function {α : Type} (F : Function α) : Declaration α
                                          • var {α : Type} (name : String) (τ : α) (value : Option (Expression α)) : Declaration α

                                            var x τ = e, with e absent for a zero-initialized declaration.

                                          • typ {α : Type} (name : String) (τ : α) : Declaration α

                                            type N τ — a defined type, not an alias (type N = τ).

                                            Beyond the semantics' fragment, which has no top-level type declarations, but process compilation needs one: the Network struct every generated function takes a parameter of is an anonymous struct type otherwise, and Go would then require it spelled out identically at every signature that mentions it.

                                          Instances For
                                            @[implicit_reducible]
                                            instance Go.instReprDeclaration {α✝ : Type} [Repr α✝] :
                                            Equations
                                            def Go.instReprDeclaration.repr {α✝ : Type} [Repr α✝] :
                                            Declaration α✝Std.Format
                                            Equations
                                            • One or more equations did not get rendered due to their size.
                                            Instances For
                                              @[implicit_reducible]
                                              Equations
                                              • One or more equations did not get rendered due to their size.
                                              @[implicit_reducible]
                                              Equations
                                              • One or more equations did not get rendered due to their size.
                                              @[reducible, inline]
                                              Equations
                                              Instances For
                                                @[reducible, inline]
                                                Equations
                                                Instances For
                                                  @[reducible, inline]
                                                  Equations
                                                  Instances For
                                                    @[reducible, inline]
                                                    Equations
                                                    Instances For
                                                      @[reducible, inline]
                                                      Equations
                                                      Instances For
                                                        @[reducible, inline]
                                                        Equations
                                                        Instances For