Source file src/cmd/compile/internal/contraire/doc.go

     1  // Copyright 2026 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  // Package contraire defines a tool (of the same name) which is a
     6  // syntax-directed fuzzer for randomly generating Go programs with the goal of
     7  // tripping up the type checkers.
     8  package contraire
     9  
    10  /*
    11  Programs generated by Contraire adhere to the below grammar:
    12  
    13  Prog = ConstDecl+ TypeDecl+ MethodDecl*
    14  
    15  // Declarations
    16  ConstDecl     = "const" constName "=" ConstExpr
    17  TypeDecl      = "type" typeDeclName [ "[" TypeParamDecl+ "]" ] [ "=" ] TypeExpr
    18  TypeParamDecl = typeParamName TypeExpr
    19  MethodDecl    = "func" "(" [ "*" ] typeDeclName [ "[" typeParamName+ "]" ] ")" methodName [ "[" TypeParamDecl+ "]" ] "(" TypeExpr* ")" [ "(" TypeExpr+ ")" ] "{" "panic(1)" "}"
    20  
    21  // Constant Expressions
    22  ConstExpr         = constName | constLtrl | ConstUnsafeSizeof
    23  constLtrl         = "1"
    24  ConstUnsafeSizeof = "unsafe.Sizeof(*new(" TypeExpr "))"
    25  
    26  // Type Expressions
    27  TypeExpr = TypeName | TypeLtrl
    28  TypeName = typeParamName | typeDeclName [ "[" TypeExpr+ "]" ]
    29  
    30  TypeLtrl      = typeAny | TypeMap | typeBasic | TypeArray | TypeSlice | TypeStruct | TypePointer | TypeFunction | TypeInterface
    31  typeAny       = "any"
    32  TypeMap       = "map" "[" TypeExpr "]" TypeExpr
    33  typeBasic     = "int"
    34  TypeArray     = "[" ConstExpr "]" TypeExpr
    35  TypeSlice     = "[" "]" TypeExpr
    36  TypeStruct    = "struct" "{" ( [ "*" ] TypeName | fieldName TypeExpr )* "}"
    37  TypePointer   = "*" TypeExpr
    38  TypeFunction  = "func" "(" TypeExpr* ")" [ "(" TypeExpr+ ")" ]
    39  TypeInterface = "interface" "{" ( methodName "(" TypeExpr* ")" [ "(" TypeExpr+ ")" ] )* "}"
    40  
    41  constName     = (* a name defined by a constant       declaration *)
    42  typeDeclName  = (* a name defined by a type           declaration *)
    43  typeParamName = (* a name defined by a type parameter declaration *)
    44  methodName    = (* a name defined by a method         declaration *)
    45  fieldName     = (* a name defined by a field          declaration *)
    46  */
    47  

View as plain text