Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

distinct borrow of generics + template in type section + macro type inference issue #23971

Open
mratsim opened this issue Aug 16, 2024 · 4 comments

Comments

@mratsim
Copy link
Collaborator

mratsim commented Aug 16, 2024

A similar starting point to #23784

The following confuses the type inference with the error

[...]/nim-2.0.8/lib/system.nim(700, 10) Error: invalid type: 'typeof(matchingBigInt(C))' in this context: 'proc (x: array[0..2, Fp[Fp3prj.C]]): int{.noSideEffect, gcsafe.}' for proc

Line 700 of system.nim in 2.0.8 corresponds to len of array

image

It seems like the signature func len*(x: (type array)|array): int is buggy with distinct type indirection.

import std/macros
import std/bitops

proc replaceNodes(ast: NimNode, what: NimNode, by: NimNode): NimNode =
  # Replace "what" ident node by "by"
  proc inspect(node: NimNode): NimNode =
    case node.kind:
    of {nnkIdent, nnkSym}:
      if node.eqIdent(what):
        return by
      return node
    of nnkEmpty:
      return node
    of nnkLiterals:
      return node
    else:
      var rTree = node.kind.newTree()
      for child in node:
        rTree.add inspect(child)
      return rTree
  result = inspect(ast)

macro staticFor*(idx: untyped{nkIdent}, start, stopEx: static int, body: untyped): untyped =
  result = newStmtList()
  for i in start ..< stopEx:
    result.add nnkBlockStmt.newTree(
      ident("unrolledIter_" & $idx & $i),
      body.replaceNodes(idx, newLit i))

# --------------------------------------------------------------

type Curve = enum
  BLS12_381

const WordBitWidth* = sizeof(uint64) * 8

func wordsRequired*(bits: int): int {.inline.} =
  const divShiftor = fastLog2(WordBitWidth)
  result = (bits + WordBitWidth - 1) shr divShiftor

type
  BigInt*[bits: static int] = object
    limbs*: array[bits.wordsRequired, uint64]

# --------------------------------------------------------------

const CurveBitWidth = [
  BLS12_381: 381
]

template matchingBigInt*(Name: static Curve): untyped =
  ## BigInt type necessary to store the prime field Fp
  BigInt[CurveBitWidth[Name]]

type
  Fp[C: static Curve] = object
    residue: matchingBigInt(C)

type
  CubicExt*[F] = object
    ## Cubic Extension field
    coords*: array[3, F]

  Fp3[C: static Curve] = CubicExt[Fp[C]]

type
  Fp3prj[C: static Curve] {.borrow: `.`.} = distinct Fp3[C]

func `+=`*(a: var Fp, b: Fp) =
  for i in 0 ..< a.residue.limbs.len:
    a.residue.limbs[i] += b.limbs[i]

func `+=`*(a: var CubicExt, b: CubicExt) =
  ## Addition in the extension field
  staticFor i, 0, a.coords.len:
    a.coords[i] += b.coords[i]

# --------------------------------------------------------------

var a: Fp3prj[BLS12_381]
echo a.coords.len
echo a.coords[0].residue.limbs.len
# Up until there everything works

func `+=`*(a: var Fp3prj, b: Fp3prj) {.borrow.}
  # Comment this out and code compiles
  # Error is:
  #   Error: invalid type: 'typeof(matchingBigInt(C))'
  #   in this context: 'proc (x: array[0..2, Fp[Fp3prj.C]]): int{.noSideEffect, gcsafe.}' for proc
  #
  # The proc name isn't specified but it's `len` in system.nim which does type(array)|array
Copy link
Contributor

🐧 Linux bisect by @juancarlospaco (collaborator)
devel 👎 FAIL

Output

Error: Command failed: nim c --run  -d:nimDebug -d:nimDebugDlOpen -d:ssl -d:nimDisableCertificateValidation --forceBuild:on --colors:off --verbosity:0 --hints:off --lineTrace:off --nimcache:/home/runner/work/Nim/Nim --out:/home/runner/work/Nim/Nim/temp /home/runner/work/Nim/Nim/temp.nim
/home/runner/work/Nim/Nim/temp.nim(66, 6) template/generic instantiation of `+=` from here
/home/runner/work/Nim/Nim/temp.nim(59, 27) template/generic instantiation of `len` from here
/home/runner/.choosenim/toolchains/nim-#devel/lib/system.nim(682, 10) Error: invalid type: 'typeof(matchingBigInt(C))' in this context: 'proc (x: array[0..2, Fp[Fp3prj.C]]): int{.noSideEffect, gcsafe.}' for proc
assertions.nim(34)       raiseAssert
Error: unhandled exception: errGenerated [AssertionDefect]

IR

Compiled filesize 0 (0 bytes)

Stats

  • Started 2024-08-16T16:49:52
  • Finished 2024-08-16T16:49:53
  • Duration

AST

nnkStmtList.newTree(
  nnkImportStmt.newTree(
    nnkInfix.newTree(
      newIdentNode("/"),
      newIdentNode("std"),
      newIdentNode("macros")
    )
  ),
  nnkImportStmt.newTree(
    nnkInfix.newTree(
      newIdentNode("/"),
      newIdentNode("std"),
      newIdentNode("bitops")
    )
  ),
  nnkProcDef.newTree(
    newIdentNode("replaceNodes"),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      newIdentNode("NimNode"),
      nnkIdentDefs.newTree(
        newIdentNode("ast"),
        newIdentNode("NimNode"),
        newEmptyNode()
      ),
      nnkIdentDefs.newTree(
        newIdentNode("what"),
        newIdentNode("NimNode"),
        newEmptyNode()
      ),
      nnkIdentDefs.newTree(
        newIdentNode("by"),
        newIdentNode("NimNode"),
        newEmptyNode()
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkProcDef.newTree(
        newIdentNode("inspect"),
        newEmptyNode(),
        newEmptyNode(),
        nnkFormalParams.newTree(
          newIdentNode("NimNode"),
          nnkIdentDefs.newTree(
            newIdentNode("node"),
            newIdentNode("NimNode"),
            newEmptyNode()
          )
        ),
        newEmptyNode(),
        newEmptyNode(),
        nnkStmtList.newTree(
          nnkCaseStmt.newTree(
            nnkDotExpr.newTree(
              newIdentNode("node"),
              newIdentNode("kind")
            ),
            nnkOfBranch.newTree(
              nnkCurly.newTree(
                newIdentNode("nnkIdent"),
                newIdentNode("nnkSym")
              ),
              nnkStmtList.newTree(
                nnkIfStmt.newTree(
                  nnkElifBranch.newTree(
                    nnkCall.newTree(
                      nnkDotExpr.newTree(
                        newIdentNode("node"),
                        newIdentNode("eqIdent")
                      ),
                      newIdentNode("what")
                    ),
                    nnkStmtList.newTree(
                      nnkReturnStmt.newTree(
                        newIdentNode("by")
                      )
                    )
                  )
                ),
                nnkReturnStmt.newTree(
                  newIdentNode("node")
                )
              )
            ),
            nnkOfBranch.newTree(
              newIdentNode("nnkEmpty"),
              nnkStmtList.newTree(
                nnkReturnStmt.newTree(
                  newIdentNode("node")
                )
              )
            ),
            nnkOfBranch.newTree(
              newIdentNode("nnkLiterals"),
              nnkStmtList.newTree(
                nnkReturnStmt.newTree(
                  newIdentNode("node")
                )
              )
            ),
            nnkElse.newTree(
              nnkStmtList.newTree(
                nnkVarSection.newTree(
                  nnkIdentDefs.newTree(
                    newIdentNode("rTree"),
                    newEmptyNode(),
                    nnkCall.newTree(
                      nnkDotExpr.newTree(
                        nnkDotExpr.newTree(
                          newIdentNode("node"),
                          newIdentNode("kind")
                        ),
                        newIdentNode("newTree")
                      )
                    )
                  )
                ),
                nnkForStmt.newTree(
                  newIdentNode("child"),
                  newIdentNode("node"),
                  nnkStmtList.newTree(
                    nnkCommand.newTree(
                      nnkDotExpr.newTree(
                        newIdentNode("rTree"),
                        newIdentNode("add")
                      ),
                      nnkCall.newTree(
                        newIdentNode("inspect"),
                        newIdentNode("child")
                      )
                    )
                  )
                ),
                nnkReturnStmt.newTree(
                  newIdentNode("rTree")
                )
              )
            )
          )
        )
      ),
      nnkAsgn.newTree(
        newIdentNode("result"),
        nnkCall.newTree(
          newIdentNode("inspect"),
          newIdentNode("ast")
        )
      )
    )
  ),
  nnkMacroDef.newTree(
    nnkPostfix.newTree(
      newIdentNode("*"),
      newIdentNode("staticFor")
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      newIdentNode("untyped"),
      nnkIdentDefs.newTree(
        newIdentNode("idx"),
        nnkCurlyExpr.newTree(
          newIdentNode("untyped"),
          newIdentNode("nkIdent")
        ),
        newEmptyNode()
      ),
      nnkIdentDefs.newTree(
        newIdentNode("start"),
        newIdentNode("stopEx"),
        nnkCommand.newTree(
          newIdentNode("static"),
          newIdentNode("int")
        ),
        newEmptyNode()
      ),
      nnkIdentDefs.newTree(
        newIdentNode("body"),
        newIdentNode("untyped"),
        newEmptyNode()
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkAsgn.newTree(
        newIdentNode("result"),
        nnkCall.newTree(
          newIdentNode("newStmtList")
        )
      ),
      nnkForStmt.newTree(
        newIdentNode("i"),
        nnkInfix.newTree(
          newIdentNode("..<"),
          newIdentNode("start"),
          newIdentNode("stopEx")
        ),
        nnkStmtList.newTree(
          nnkCommand.newTree(
            nnkDotExpr.newTree(
              newIdentNode("result"),
              newIdentNode("add")
            ),
            nnkCall.newTree(
              nnkDotExpr.newTree(
                newIdentNode("nnkBlockStmt"),
                newIdentNode("newTree")
              ),
              nnkCall.newTree(
                newIdentNode("ident"),
                nnkInfix.newTree(
                  newIdentNode("&"),
                  nnkInfix.newTree(
                    newIdentNode("&"),
                    newLit("unrolledIter_"),
                    nnkPrefix.newTree(
                      newIdentNode("$"),
                      newIdentNode("idx")
                    )
                  ),
                  nnkPrefix.newTree(
                    newIdentNode("$"),
                    newIdentNode("i")
                  )
                )
              ),
              nnkCall.newTree(
                nnkDotExpr.newTree(
                  newIdentNode("body"),
                  newIdentNode("replaceNodes")
                ),
                newIdentNode("idx"),
                nnkCommand.newTree(
                  newIdentNode("newLit"),
                  newIdentNode("i")
                )
              )
            )
          )
        )
      )
    )
  ),
  nnkTypeSection.newTree(
    nnkTypeDef.newTree(
      newIdentNode("Curve"),
      newEmptyNode(),
      nnkEnumTy.newTree(
        newEmptyNode(),
        newIdentNode("BLS12_381")
      )
    )
  ),
  nnkConstSection.newTree(
    nnkConstDef.newTree(
      nnkPostfix.newTree(
        newIdentNode("*"),
        newIdentNode("WordBitWidth")
      ),
      newEmptyNode(),
      nnkInfix.newTree(
        newIdentNode("*"),
        nnkCall.newTree(
          newIdentNode("sizeof"),
          newIdentNode("uint64")
        ),
        newLit(8)
      )
    )
  ),
  nnkFuncDef.newTree(
    nnkPostfix.newTree(
      newIdentNode("*"),
      newIdentNode("wordsRequired")
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      newIdentNode("int"),
      nnkIdentDefs.newTree(
        newIdentNode("bits"),
        newIdentNode("int"),
        newEmptyNode()
      )
    ),
    nnkPragma.newTree(
      newIdentNode("inline")
    ),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkConstSection.newTree(
        nnkConstDef.newTree(
          newIdentNode("divShiftor"),
          newEmptyNode(),
          nnkCall.newTree(
            newIdentNode("fastLog2"),
            newIdentNode("WordBitWidth")
          )
        )
      ),
      nnkAsgn.newTree(
        newIdentNode("result"),
        nnkInfix.newTree(
          newIdentNode("shr"),
          nnkPar.newTree(
            nnkInfix.newTree(
              newIdentNode("-"),
              nnkInfix.newTree(
                newIdentNode("+"),
                newIdentNode("bits"),
                newIdentNode("WordBitWidth")
              ),
              newLit(1)
            )
          ),
          newIdentNode("divShiftor")
        )
      )
    )
  ),
  nnkTypeSection.newTree(
    nnkTypeDef.newTree(
      nnkPostfix.newTree(
        newIdentNode("*"),
        newIdentNode("BigInt")
      ),
      nnkGenericParams.newTree(
        nnkIdentDefs.newTree(
          newIdentNode("bits"),
          nnkCommand.newTree(
            newIdentNode("static"),
            newIdentNode("int")
          ),
          newEmptyNode()
        )
      ),
      nnkObjectTy.newTree(
        newEmptyNode(),
        newEmptyNode(),
        nnkRecList.newTree(
          nnkIdentDefs.newTree(
            nnkPostfix.newTree(
              newIdentNode("*"),
              newIdentNode("limbs")
            ),
            nnkBracketExpr.newTree(
              newIdentNode("array"),
              nnkDotExpr.newTree(
                newIdentNode("bits"),
                newIdentNode("wordsRequired")
              ),
              newIdentNode("uint64")
            ),
            newEmptyNode()
          )
        )
      )
    )
  ),
  nnkConstSection.newTree(
    nnkConstDef.newTree(
      newIdentNode("CurveBitWidth"),
      newEmptyNode(),
      nnkBracket.newTree(
        nnkExprColonExpr.newTree(
          newIdentNode("BLS12_381"),
          newLit(381)
        )
      )
    )
  ),
  nnkTemplateDef.newTree(
    nnkPostfix.newTree(
      newIdentNode("*"),
      newIdentNode("matchingBigInt")
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      newIdentNode("untyped"),
      nnkIdentDefs.newTree(
        newIdentNode("Name"),
        nnkCommand.newTree(
          newIdentNode("static"),
          newIdentNode("Curve")
        ),
        newEmptyNode()
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      newCommentStmtNode("BigInt type necessary to store the prime field Fp"),
      nnkBracketExpr.newTree(
        newIdentNode("BigInt"),
        nnkBracketExpr.newTree(
          newIdentNode("CurveBitWidth"),
          newIdentNode("Name")
        )
      )
    )
  ),
  nnkTypeSection.newTree(
    nnkTypeDef.newTree(
      newIdentNode("Fp"),
      nnkGenericParams.newTree(
        nnkIdentDefs.newTree(
          newIdentNode("C"),
          nnkCommand.newTree(
            newIdentNode("static"),
            newIdentNode("Curve")
          ),
          newEmptyNode()
        )
      ),
      nnkObjectTy.newTree(
        newEmptyNode(),
        newEmptyNode(),
        nnkRecList.newTree(
          nnkIdentDefs.newTree(
            newIdentNode("residue"),
            nnkCall.newTree(
              newIdentNode("matchingBigInt"),
              newIdentNode("C")
            ),
            newEmptyNode()
          )
        )
      )
    )
  ),
  nnkTypeSection.newTree(
    nnkTypeDef.newTree(
      nnkPostfix.newTree(
        newIdentNode("*"),
        newIdentNode("CubicExt")
      ),
      nnkGenericParams.newTree(
        nnkIdentDefs.newTree(
          newIdentNode("F"),
          newEmptyNode(),
          newEmptyNode()
        )
      ),
      nnkObjectTy.newTree(
        newEmptyNode(),
        newEmptyNode(),
        nnkRecList.newTree(
          nnkIdentDefs.newTree(
            nnkPostfix.newTree(
              newIdentNode("*"),
              newIdentNode("coords")
            ),
            nnkBracketExpr.newTree(
              newIdentNode("array"),
              newLit(3),
              newIdentNode("F")
            ),
            newEmptyNode()
          )
        )
      )
    ),
    nnkTypeDef.newTree(
      newIdentNode("Fp3"),
      nnkGenericParams.newTree(
        nnkIdentDefs.newTree(
          newIdentNode("C"),
          nnkCommand.newTree(
            newIdentNode("static"),
            newIdentNode("Curve")
          ),
          newEmptyNode()
        )
      ),
      nnkBracketExpr.newTree(
        newIdentNode("CubicExt"),
        nnkBracketExpr.newTree(
          newIdentNode("Fp"),
          newIdentNode("C")
        )
      )
    )
  ),
  nnkTypeSection.newTree(
    nnkTypeDef.newTree(
      nnkPragmaExpr.newTree(
        newIdentNode("Fp3prj"),
        nnkPragma.newTree(
          nnkExprColonExpr.newTree(
            newIdentNode("borrow"),
            nnkAccQuoted.newTree(
              newIdentNode(".")
            )
          )
        )
      ),
      nnkGenericParams.newTree(
        nnkIdentDefs.newTree(
          newIdentNode("C"),
          nnkCommand.newTree(
            newIdentNode("static"),
            newIdentNode("Curve")
          ),
          newEmptyNode()
        )
      ),
      nnkDistinctTy.newTree(
        nnkBracketExpr.newTree(
          newIdentNode("Fp3"),
          newIdentNode("C")
        )
      )
    )
  ),
  nnkFuncDef.newTree(
    nnkPostfix.newTree(
      newIdentNode("*"),
      nnkAccQuoted.newTree(
        newIdentNode("+=")
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      newEmptyNode(),
      nnkIdentDefs.newTree(
        newIdentNode("a"),
        nnkVarTy.newTree(
          newIdentNode("Fp")
        ),
        newEmptyNode()
      ),
      nnkIdentDefs.newTree(
        newIdentNode("b"),
        newIdentNode("Fp"),
        newEmptyNode()
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkForStmt.newTree(
        newIdentNode("i"),
        nnkInfix.newTree(
          newIdentNode("..<"),
          newLit(0),
          nnkDotExpr.newTree(
            nnkDotExpr.newTree(
              nnkDotExpr.newTree(
                newIdentNode("a"),
                newIdentNode("residue")
              ),
              newIdentNode("limbs")
            ),
            newIdentNode("len")
          )
        ),
        nnkStmtList.newTree(
          nnkInfix.newTree(
            newIdentNode("+="),
            nnkBracketExpr.newTree(
              nnkDotExpr.newTree(
                nnkDotExpr.newTree(
                  newIdentNode("a"),
                  newIdentNode("residue")
                ),
                newIdentNode("limbs")
              ),
              newIdentNode("i")
            ),
            nnkBracketExpr.newTree(
              nnkDotExpr.newTree(
                newIdentNode("b"),
                newIdentNode("limbs")
              ),
              newIdentNode("i")
            )
          )
        )
      )
    )
  ),
  nnkFuncDef.newTree(
    nnkPostfix.newTree(
      newIdentNode("*"),
      nnkAccQuoted.newTree(
        newIdentNode("+=")
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      newEmptyNode(),
      nnkIdentDefs.newTree(
        newIdentNode("a"),
        nnkVarTy.newTree(
          newIdentNode("CubicExt")
        ),
        newEmptyNode()
      ),
      nnkIdentDefs.newTree(
        newIdentNode("b"),
        newIdentNode("CubicExt"),
        newEmptyNode()
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      newCommentStmtNode("Addition in the extension field"),
      nnkCommand.newTree(
        newIdentNode("staticFor"),
        newIdentNode("i"),
        newLit(0),
        nnkDotExpr.newTree(
          nnkDotExpr.newTree(
            newIdentNode("a"),
            newIdentNode("coords")
          ),
          newIdentNode("len")
        ),
        nnkStmtList.newTree(
          nnkInfix.newTree(
            newIdentNode("+="),
            nnkBracketExpr.newTree(
              nnkDotExpr.newTree(
                newIdentNode("a"),
                newIdentNode("coords")
              ),
              newIdentNode("i")
            ),
            nnkBracketExpr.newTree(
              nnkDotExpr.newTree(
                newIdentNode("b"),
                newIdentNode("coords")
              ),
              newIdentNode("i")
            )
          )
        )
      )
    )
  ),
  nnkVarSection.newTree(
    nnkIdentDefs.newTree(
      newIdentNode("a"),
      nnkBracketExpr.newTree(
        newIdentNode("Fp3prj"),
        newIdentNode("BLS12_381")
      ),
      newEmptyNode()
    )
  ),
  nnkCommand.newTree(
    newIdentNode("echo"),
    nnkDotExpr.newTree(
      nnkDotExpr.newTree(
        newIdentNode("a"),
        newIdentNode("coords")
      ),
      newIdentNode("len")
    )
  ),
  nnkCommand.newTree(
    newIdentNode("echo"),
    nnkDotExpr.newTree(
      nnkDotExpr.newTree(
        nnkDotExpr.newTree(
          nnkBracketExpr.newTree(
            nnkDotExpr.newTree(
              newIdentNode("a"),
              newIdentNode("coords")
            ),
            newLit(0)
          ),
          newIdentNode("residue")
        ),
        newIdentNode("limbs")
      ),
      newIdentNode("len")
    )
  ),
  nnkFuncDef.newTree(
    nnkPostfix.newTree(
      newIdentNode("*"),
      nnkAccQuoted.newTree(
        newIdentNode("+=")
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      newEmptyNode(),
      nnkIdentDefs.newTree(
        newIdentNode("a"),
        nnkVarTy.newTree(
          newIdentNode("Fp3prj")
        ),
        newEmptyNode()
      ),
      nnkIdentDefs.newTree(
        newIdentNode("b"),
        newIdentNode("Fp3prj"),
        newEmptyNode()
      )
    ),
    nnkPragma.newTree(
      newIdentNode("borrow")
    ),
    newEmptyNode(),
    newEmptyNode()
  )
)
stable 👎 FAIL

Output

Error: Command failed: nim c --run  -d:nimDebug -d:nimDebugDlOpen -d:ssl -d:nimDisableCertificateValidation --forceBuild:on --colors:off --verbosity:0 --hints:off --lineTrace:off --nimcache:/home/runner/work/Nim/Nim --out:/home/runner/work/Nim/Nim/temp /home/runner/work/Nim/Nim/temp.nim
/home/runner/work/Nim/Nim/temp.nim(66, 6) template/generic instantiation of `+=` from here
/home/runner/work/Nim/Nim/temp.nim(59, 27) template/generic instantiation of `len` from here
/home/runner/.choosenim/toolchains/nim-2.0.8/lib/system.nim(700, 10) Error: invalid type: 'typeof(matchingBigInt(C))' in this context: 'proc (x: array[0..2, Fp[Fp3prj.C]]): int{.noSideEffect, gcsafe.}' for proc
assertions.nim(34)       raiseAssert
Error: unhandled exception: options.nim(682, 5) `false` errGenerated [AssertionDefect]

IR

Compiled filesize 0 (0 bytes)

Stats

  • Started 2024-08-16T16:49:56
  • Finished 2024-08-16T16:49:56
  • Duration

AST

nnkStmtList.newTree(
  nnkImportStmt.newTree(
    nnkInfix.newTree(
      newIdentNode("/"),
      newIdentNode("std"),
      newIdentNode("macros")
    )
  ),
  nnkImportStmt.newTree(
    nnkInfix.newTree(
      newIdentNode("/"),
      newIdentNode("std"),
      newIdentNode("bitops")
    )
  ),
  nnkProcDef.newTree(
    newIdentNode("replaceNodes"),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      newIdentNode("NimNode"),
      nnkIdentDefs.newTree(
        newIdentNode("ast"),
        newIdentNode("NimNode"),
        newEmptyNode()
      ),
      nnkIdentDefs.newTree(
        newIdentNode("what"),
        newIdentNode("NimNode"),
        newEmptyNode()
      ),
      nnkIdentDefs.newTree(
        newIdentNode("by"),
        newIdentNode("NimNode"),
        newEmptyNode()
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkProcDef.newTree(
        newIdentNode("inspect"),
        newEmptyNode(),
        newEmptyNode(),
        nnkFormalParams.newTree(
          newIdentNode("NimNode"),
          nnkIdentDefs.newTree(
            newIdentNode("node"),
            newIdentNode("NimNode"),
            newEmptyNode()
          )
        ),
        newEmptyNode(),
        newEmptyNode(),
        nnkStmtList.newTree(
          nnkCaseStmt.newTree(
            nnkDotExpr.newTree(
              newIdentNode("node"),
              newIdentNode("kind")
            ),
            nnkOfBranch.newTree(
              nnkCurly.newTree(
                newIdentNode("nnkIdent"),
                newIdentNode("nnkSym")
              ),
              nnkStmtList.newTree(
                nnkIfStmt.newTree(
                  nnkElifBranch.newTree(
                    nnkCall.newTree(
                      nnkDotExpr.newTree(
                        newIdentNode("node"),
                        newIdentNode("eqIdent")
                      ),
                      newIdentNode("what")
                    ),
                    nnkStmtList.newTree(
                      nnkReturnStmt.newTree(
                        newIdentNode("by")
                      )
                    )
                  )
                ),
                nnkReturnStmt.newTree(
                  newIdentNode("node")
                )
              )
            ),
            nnkOfBranch.newTree(
              newIdentNode("nnkEmpty"),
              nnkStmtList.newTree(
                nnkReturnStmt.newTree(
                  newIdentNode("node")
                )
              )
            ),
            nnkOfBranch.newTree(
              newIdentNode("nnkLiterals"),
              nnkStmtList.newTree(
                nnkReturnStmt.newTree(
                  newIdentNode("node")
                )
              )
            ),
            nnkElse.newTree(
              nnkStmtList.newTree(
                nnkVarSection.newTree(
                  nnkIdentDefs.newTree(
                    newIdentNode("rTree"),
                    newEmptyNode(),
                    nnkCall.newTree(
                      nnkDotExpr.newTree(
                        nnkDotExpr.newTree(
                          newIdentNode("node"),
                          newIdentNode("kind")
                        ),
                        newIdentNode("newTree")
                      )
                    )
                  )
                ),
                nnkForStmt.newTree(
                  newIdentNode("child"),
                  newIdentNode("node"),
                  nnkStmtList.newTree(
                    nnkCommand.newTree(
                      nnkDotExpr.newTree(
                        newIdentNode("rTree"),
                        newIdentNode("add")
                      ),
                      nnkCall.newTree(
                        newIdentNode("inspect"),
                        newIdentNode("child")
                      )
                    )
                  )
                ),
                nnkReturnStmt.newTree(
                  newIdentNode("rTree")
                )
              )
            )
          )
        )
      ),
      nnkAsgn.newTree(
        newIdentNode("result"),
        nnkCall.newTree(
          newIdentNode("inspect"),
          newIdentNode("ast")
        )
      )
    )
  ),
  nnkMacroDef.newTree(
    nnkPostfix.newTree(
      newIdentNode("*"),
      newIdentNode("staticFor")
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      newIdentNode("untyped"),
      nnkIdentDefs.newTree(
        newIdentNode("idx"),
        nnkCurlyExpr.newTree(
          newIdentNode("untyped"),
          newIdentNode("nkIdent")
        ),
        newEmptyNode()
      ),
      nnkIdentDefs.newTree(
        newIdentNode("start"),
        newIdentNode("stopEx"),
        nnkCommand.newTree(
          newIdentNode("static"),
          newIdentNode("int")
        ),
        newEmptyNode()
      ),
      nnkIdentDefs.newTree(
        newIdentNode("body"),
        newIdentNode("untyped"),
        newEmptyNode()
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkAsgn.newTree(
        newIdentNode("result"),
        nnkCall.newTree(
          newIdentNode("newStmtList")
        )
      ),
      nnkForStmt.newTree(
        newIdentNode("i"),
        nnkInfix.newTree(
          newIdentNode("..<"),
          newIdentNode("start"),
          newIdentNode("stopEx")
        ),
        nnkStmtList.newTree(
          nnkCommand.newTree(
            nnkDotExpr.newTree(
              newIdentNode("result"),
              newIdentNode("add")
            ),
            nnkCall.newTree(
              nnkDotExpr.newTree(
                newIdentNode("nnkBlockStmt"),
                newIdentNode("newTree")
              ),
              nnkCall.newTree(
                newIdentNode("ident"),
                nnkInfix.newTree(
                  newIdentNode("&"),
                  nnkInfix.newTree(
                    newIdentNode("&"),
                    newLit("unrolledIter_"),
                    nnkPrefix.newTree(
                      newIdentNode("$"),
                      newIdentNode("idx")
                    )
                  ),
                  nnkPrefix.newTree(
                    newIdentNode("$"),
                    newIdentNode("i")
                  )
                )
              ),
              nnkCall.newTree(
                nnkDotExpr.newTree(
                  newIdentNode("body"),
                  newIdentNode("replaceNodes")
                ),
                newIdentNode("idx"),
                nnkCommand.newTree(
                  newIdentNode("newLit"),
                  newIdentNode("i")
                )
              )
            )
          )
        )
      )
    )
  ),
  nnkTypeSection.newTree(
    nnkTypeDef.newTree(
      newIdentNode("Curve"),
      newEmptyNode(),
      nnkEnumTy.newTree(
        newEmptyNode(),
        newIdentNode("BLS12_381")
      )
    )
  ),
  nnkConstSection.newTree(
    nnkConstDef.newTree(
      nnkPostfix.newTree(
        newIdentNode("*"),
        newIdentNode("WordBitWidth")
      ),
      newEmptyNode(),
      nnkInfix.newTree(
        newIdentNode("*"),
        nnkCall.newTree(
          newIdentNode("sizeof"),
          newIdentNode("uint64")
        ),
        newLit(8)
      )
    )
  ),
  nnkFuncDef.newTree(
    nnkPostfix.newTree(
      newIdentNode("*"),
      newIdentNode("wordsRequired")
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      newIdentNode("int"),
      nnkIdentDefs.newTree(
        newIdentNode("bits"),
        newIdentNode("int"),
        newEmptyNode()
      )
    ),
    nnkPragma.newTree(
      newIdentNode("inline")
    ),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkConstSection.newTree(
        nnkConstDef.newTree(
          newIdentNode("divShiftor"),
          newEmptyNode(),
          nnkCall.newTree(
            newIdentNode("fastLog2"),
            newIdentNode("WordBitWidth")
          )
        )
      ),
      nnkAsgn.newTree(
        newIdentNode("result"),
        nnkInfix.newTree(
          newIdentNode("shr"),
          nnkPar.newTree(
            nnkInfix.newTree(
              newIdentNode("-"),
              nnkInfix.newTree(
                newIdentNode("+"),
                newIdentNode("bits"),
                newIdentNode("WordBitWidth")
              ),
              newLit(1)
            )
          ),
          newIdentNode("divShiftor")
        )
      )
    )
  ),
  nnkTypeSection.newTree(
    nnkTypeDef.newTree(
      nnkPostfix.newTree(
        newIdentNode("*"),
        newIdentNode("BigInt")
      ),
      nnkGenericParams.newTree(
        nnkIdentDefs.newTree(
          newIdentNode("bits"),
          nnkCommand.newTree(
            newIdentNode("static"),
            newIdentNode("int")
          ),
          newEmptyNode()
        )
      ),
      nnkObjectTy.newTree(
        newEmptyNode(),
        newEmptyNode(),
        nnkRecList.newTree(
          nnkIdentDefs.newTree(
            nnkPostfix.newTree(
              newIdentNode("*"),
              newIdentNode("limbs")
            ),
            nnkBracketExpr.newTree(
              newIdentNode("array"),
              nnkDotExpr.newTree(
                newIdentNode("bits"),
                newIdentNode("wordsRequired")
              ),
              newIdentNode("uint64")
            ),
            newEmptyNode()
          )
        )
      )
    )
  ),
  nnkConstSection.newTree(
    nnkConstDef.newTree(
      newIdentNode("CurveBitWidth"),
      newEmptyNode(),
      nnkBracket.newTree(
        nnkExprColonExpr.newTree(
          newIdentNode("BLS12_381"),
          newLit(381)
        )
      )
    )
  ),
  nnkTemplateDef.newTree(
    nnkPostfix.newTree(
      newIdentNode("*"),
      newIdentNode("matchingBigInt")
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      newIdentNode("untyped"),
      nnkIdentDefs.newTree(
        newIdentNode("Name"),
        nnkCommand.newTree(
          newIdentNode("static"),
          newIdentNode("Curve")
        ),
        newEmptyNode()
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      newCommentStmtNode("BigInt type necessary to store the prime field Fp"),
      nnkBracketExpr.newTree(
        newIdentNode("BigInt"),
        nnkBracketExpr.newTree(
          newIdentNode("CurveBitWidth"),
          newIdentNode("Name")
        )
      )
    )
  ),
  nnkTypeSection.newTree(
    nnkTypeDef.newTree(
      newIdentNode("Fp"),
      nnkGenericParams.newTree(
        nnkIdentDefs.newTree(
          newIdentNode("C"),
          nnkCommand.newTree(
            newIdentNode("static"),
            newIdentNode("Curve")
          ),
          newEmptyNode()
        )
      ),
      nnkObjectTy.newTree(
        newEmptyNode(),
        newEmptyNode(),
        nnkRecList.newTree(
          nnkIdentDefs.newTree(
            newIdentNode("residue"),
            nnkCall.newTree(
              newIdentNode("matchingBigInt"),
              newIdentNode("C")
            ),
            newEmptyNode()
          )
        )
      )
    )
  ),
  nnkTypeSection.newTree(
    nnkTypeDef.newTree(
      nnkPostfix.newTree(
        newIdentNode("*"),
        newIdentNode("CubicExt")
      ),
      nnkGenericParams.newTree(
        nnkIdentDefs.newTree(
          newIdentNode("F"),
          newEmptyNode(),
          newEmptyNode()
        )
      ),
      nnkObjectTy.newTree(
        newEmptyNode(),
        newEmptyNode(),
        nnkRecList.newTree(
          nnkIdentDefs.newTree(
            nnkPostfix.newTree(
              newIdentNode("*"),
              newIdentNode("coords")
            ),
            nnkBracketExpr.newTree(
              newIdentNode("array"),
              newLit(3),
              newIdentNode("F")
            ),
            newEmptyNode()
          )
        )
      )
    ),
    nnkTypeDef.newTree(
      newIdentNode("Fp3"),
      nnkGenericParams.newTree(
        nnkIdentDefs.newTree(
          newIdentNode("C"),
          nnkCommand.newTree(
            newIdentNode("static"),
            newIdentNode("Curve")
          ),
          newEmptyNode()
        )
      ),
      nnkBracketExpr.newTree(
        newIdentNode("CubicExt"),
        nnkBracketExpr.newTree(
          newIdentNode("Fp"),
          newIdentNode("C")
        )
      )
    )
  ),
  nnkTypeSection.newTree(
    nnkTypeDef.newTree(
      nnkPragmaExpr.newTree(
        newIdentNode("Fp3prj"),
        nnkPragma.newTree(
          nnkExprColonExpr.newTree(
            newIdentNode("borrow"),
            nnkAccQuoted.newTree(
              newIdentNode(".")
            )
          )
        )
      ),
      nnkGenericParams.newTree(
        nnkIdentDefs.newTree(
          newIdentNode("C"),
          nnkCommand.newTree(
            newIdentNode("static"),
            newIdentNode("Curve")
          ),
          newEmptyNode()
        )
      ),
      nnkDistinctTy.newTree(
        nnkBracketExpr.newTree(
          newIdentNode("Fp3"),
          newIdentNode("C")
        )
      )
    )
  ),
  nnkFuncDef.newTree(
    nnkPostfix.newTree(
      newIdentNode("*"),
      nnkAccQuoted.newTree(
        newIdentNode("+=")
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      newEmptyNode(),
      nnkIdentDefs.newTree(
        newIdentNode("a"),
        nnkVarTy.newTree(
          newIdentNode("Fp")
        ),
        newEmptyNode()
      ),
      nnkIdentDefs.newTree(
        newIdentNode("b"),
        newIdentNode("Fp"),
        newEmptyNode()
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkForStmt.newTree(
        newIdentNode("i"),
        nnkInfix.newTree(
          newIdentNode("..<"),
          newLit(0),
          nnkDotExpr.newTree(
            nnkDotExpr.newTree(
              nnkDotExpr.newTree(
                newIdentNode("a"),
                newIdentNode("residue")
              ),
              newIdentNode("limbs")
            ),
            newIdentNode("len")
          )
        ),
        nnkStmtList.newTree(
          nnkInfix.newTree(
            newIdentNode("+="),
            nnkBracketExpr.newTree(
              nnkDotExpr.newTree(
                nnkDotExpr.newTree(
                  newIdentNode("a"),
                  newIdentNode("residue")
                ),
                newIdentNode("limbs")
              ),
              newIdentNode("i")
            ),
            nnkBracketExpr.newTree(
              nnkDotExpr.newTree(
                newIdentNode("b"),
                newIdentNode("limbs")
              ),
              newIdentNode("i")
            )
          )
        )
      )
    )
  ),
  nnkFuncDef.newTree(
    nnkPostfix.newTree(
      newIdentNode("*"),
      nnkAccQuoted.newTree(
        newIdentNode("+=")
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      newEmptyNode(),
      nnkIdentDefs.newTree(
        newIdentNode("a"),
        nnkVarTy.newTree(
          newIdentNode("CubicExt")
        ),
        newEmptyNode()
      ),
      nnkIdentDefs.newTree(
        newIdentNode("b"),
        newIdentNode("CubicExt"),
        newEmptyNode()
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      newCommentStmtNode("Addition in the extension field"),
      nnkCommand.newTree(
        newIdentNode("staticFor"),
        newIdentNode("i"),
        newLit(0),
        nnkDotExpr.newTree(
          nnkDotExpr.newTree(
            newIdentNode("a"),
            newIdentNode("coords")
          ),
          newIdentNode("len")
        ),
        nnkStmtList.newTree(
          nnkInfix.newTree(
            newIdentNode("+="),
            nnkBracketExpr.newTree(
              nnkDotExpr.newTree(
                newIdentNode("a"),
                newIdentNode("coords")
              ),
              newIdentNode("i")
            ),
            nnkBracketExpr.newTree(
              nnkDotExpr.newTree(
                newIdentNode("b"),
                newIdentNode("coords")
              ),
              newIdentNode("i")
            )
          )
        )
      )
    )
  ),
  nnkVarSection.newTree(
    nnkIdentDefs.newTree(
      newIdentNode("a"),
      nnkBracketExpr.newTree(
        newIdentNode("Fp3prj"),
        newIdentNode("BLS12_381")
      ),
      newEmptyNode()
    )
  ),
  nnkCommand.newTree(
    newIdentNode("echo"),
    nnkDotExpr.newTree(
      nnkDotExpr.newTree(
        newIdentNode("a"),
        newIdentNode("coords")
      ),
      newIdentNode("len")
    )
  ),
  nnkCommand.newTree(
    newIdentNode("echo"),
    nnkDotExpr.newTree(
      nnkDotExpr.newTree(
        nnkDotExpr.newTree(
          nnkBracketExpr.newTree(
            nnkDotExpr.newTree(
              newIdentNode("a"),
              newIdentNode("coords")
            ),
            newLit(0)
          ),
          newIdentNode("residue")
        ),
        newIdentNode("limbs")
      ),
      newIdentNode("len")
    )
  ),
  nnkFuncDef.newTree(
    nnkPostfix.newTree(
      newIdentNode("*"),
      nnkAccQuoted.newTree(
        newIdentNode("+=")
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      newEmptyNode(),
      nnkIdentDefs.newTree(
        newIdentNode("a"),
        nnkVarTy.newTree(
          newIdentNode("Fp3prj")
        ),
        newEmptyNode()
      ),
      nnkIdentDefs.newTree(
        newIdentNode("b"),
        newIdentNode("Fp3prj"),
        newEmptyNode()
      )
    ),
    nnkPragma.newTree(
      newIdentNode("borrow")
    ),
    newEmptyNode(),
    newEmptyNode()
  )
)
2.0.4 👎 FAIL

Output

Error: Command failed: nim c --run  -d:nimDebug -d:nimDebugDlOpen -d:ssl -d:nimDisableCertificateValidation --forceBuild:on --colors:off --verbosity:0 --hints:off --lineTrace:off --nimcache:/home/runner/work/Nim/Nim --out:/home/runner/work/Nim/Nim/temp /home/runner/work/Nim/Nim/temp.nim
/home/runner/work/Nim/Nim/temp.nim(66, 6) template/generic instantiation of `+=` from here
/home/runner/work/Nim/Nim/temp.nim(59, 27) template/generic instantiation of `len` from here
/home/runner/.choosenim/toolchains/nim-2.0.4/lib/system.nim(698, 10) Error: invalid type: 'typeof(matchingBigInt(C))' in this context: 'proc (x: array[0..2, Fp[Fp3prj.C]]): int{.noSideEffect, gcsafe.}' for proc
assertions.nim(34)       raiseAssert
Error: unhandled exception: options.nim(681, 5) `false` errGenerated [AssertionDefect]

IR

Compiled filesize 0 (0 bytes)

Stats

  • Started 2024-08-16T16:49:59
  • Finished 2024-08-16T16:50:00
  • Duration

AST

nnkStmtList.newTree(
  nnkImportStmt.newTree(
    nnkInfix.newTree(
      newIdentNode("/"),
      newIdentNode("std"),
      newIdentNode("macros")
    )
  ),
  nnkImportStmt.newTree(
    nnkInfix.newTree(
      newIdentNode("/"),
      newIdentNode("std"),
      newIdentNode("bitops")
    )
  ),
  nnkProcDef.newTree(
    newIdentNode("replaceNodes"),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      newIdentNode("NimNode"),
      nnkIdentDefs.newTree(
        newIdentNode("ast"),
        newIdentNode("NimNode"),
        newEmptyNode()
      ),
      nnkIdentDefs.newTree(
        newIdentNode("what"),
        newIdentNode("NimNode"),
        newEmptyNode()
      ),
      nnkIdentDefs.newTree(
        newIdentNode("by"),
        newIdentNode("NimNode"),
        newEmptyNode()
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkProcDef.newTree(
        newIdentNode("inspect"),
        newEmptyNode(),
        newEmptyNode(),
        nnkFormalParams.newTree(
          newIdentNode("NimNode"),
          nnkIdentDefs.newTree(
            newIdentNode("node"),
            newIdentNode("NimNode"),
            newEmptyNode()
          )
        ),
        newEmptyNode(),
        newEmptyNode(),
        nnkStmtList.newTree(
          nnkCaseStmt.newTree(
            nnkDotExpr.newTree(
              newIdentNode("node"),
              newIdentNode("kind")
            ),
            nnkOfBranch.newTree(
              nnkCurly.newTree(
                newIdentNode("nnkIdent"),
                newIdentNode("nnkSym")
              ),
              nnkStmtList.newTree(
                nnkIfStmt.newTree(
                  nnkElifBranch.newTree(
                    nnkCall.newTree(
                      nnkDotExpr.newTree(
                        newIdentNode("node"),
                        newIdentNode("eqIdent")
                      ),
                      newIdentNode("what")
                    ),
                    nnkStmtList.newTree(
                      nnkReturnStmt.newTree(
                        newIdentNode("by")
                      )
                    )
                  )
                ),
                nnkReturnStmt.newTree(
                  newIdentNode("node")
                )
              )
            ),
            nnkOfBranch.newTree(
              newIdentNode("nnkEmpty"),
              nnkStmtList.newTree(
                nnkReturnStmt.newTree(
                  newIdentNode("node")
                )
              )
            ),
            nnkOfBranch.newTree(
              newIdentNode("nnkLiterals"),
              nnkStmtList.newTree(
                nnkReturnStmt.newTree(
                  newIdentNode("node")
                )
              )
            ),
            nnkElse.newTree(
              nnkStmtList.newTree(
                nnkVarSection.newTree(
                  nnkIdentDefs.newTree(
                    newIdentNode("rTree"),
                    newEmptyNode(),
                    nnkCall.newTree(
                      nnkDotExpr.newTree(
                        nnkDotExpr.newTree(
                          newIdentNode("node"),
                          newIdentNode("kind")
                        ),
                        newIdentNode("newTree")
                      )
                    )
                  )
                ),
                nnkForStmt.newTree(
                  newIdentNode("child"),
                  newIdentNode("node"),
                  nnkStmtList.newTree(
                    nnkCommand.newTree(
                      nnkDotExpr.newTree(
                        newIdentNode("rTree"),
                        newIdentNode("add")
                      ),
                      nnkCall.newTree(
                        newIdentNode("inspect"),
                        newIdentNode("child")
                      )
                    )
                  )
                ),
                nnkReturnStmt.newTree(
                  newIdentNode("rTree")
                )
              )
            )
          )
        )
      ),
      nnkAsgn.newTree(
        newIdentNode("result"),
        nnkCall.newTree(
          newIdentNode("inspect"),
          newIdentNode("ast")
        )
      )
    )
  ),
  nnkMacroDef.newTree(
    nnkPostfix.newTree(
      newIdentNode("*"),
      newIdentNode("staticFor")
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      newIdentNode("untyped"),
      nnkIdentDefs.newTree(
        newIdentNode("idx"),
        nnkCurlyExpr.newTree(
          newIdentNode("untyped"),
          newIdentNode("nkIdent")
        ),
        newEmptyNode()
      ),
      nnkIdentDefs.newTree(
        newIdentNode("start"),
        newIdentNode("stopEx"),
        nnkCommand.newTree(
          newIdentNode("static"),
          newIdentNode("int")
        ),
        newEmptyNode()
      ),
      nnkIdentDefs.newTree(
        newIdentNode("body"),
        newIdentNode("untyped"),
        newEmptyNode()
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkAsgn.newTree(
        newIdentNode("result"),
        nnkCall.newTree(
          newIdentNode("newStmtList")
        )
      ),
      nnkForStmt.newTree(
        newIdentNode("i"),
        nnkInfix.newTree(
          newIdentNode("..<"),
          newIdentNode("start"),
          newIdentNode("stopEx")
        ),
        nnkStmtList.newTree(
          nnkCommand.newTree(
            nnkDotExpr.newTree(
              newIdentNode("result"),
              newIdentNode("add")
            ),
            nnkCall.newTree(
              nnkDotExpr.newTree(
                newIdentNode("nnkBlockStmt"),
                newIdentNode("newTree")
              ),
              nnkCall.newTree(
                newIdentNode("ident"),
                nnkInfix.newTree(
                  newIdentNode("&"),
                  nnkInfix.newTree(
                    newIdentNode("&"),
                    newLit("unrolledIter_"),
                    nnkPrefix.newTree(
                      newIdentNode("$"),
                      newIdentNode("idx")
                    )
                  ),
                  nnkPrefix.newTree(
                    newIdentNode("$"),
                    newIdentNode("i")
                  )
                )
              ),
              nnkCall.newTree(
                nnkDotExpr.newTree(
                  newIdentNode("body"),
                  newIdentNode("replaceNodes")
                ),
                newIdentNode("idx"),
                nnkCommand.newTree(
                  newIdentNode("newLit"),
                  newIdentNode("i")
                )
              )
            )
          )
        )
      )
    )
  ),
  nnkTypeSection.newTree(
    nnkTypeDef.newTree(
      newIdentNode("Curve"),
      newEmptyNode(),
      nnkEnumTy.newTree(
        newEmptyNode(),
        newIdentNode("BLS12_381")
      )
    )
  ),
  nnkConstSection.newTree(
    nnkConstDef.newTree(
      nnkPostfix.newTree(
        newIdentNode("*"),
        newIdentNode("WordBitWidth")
      ),
      newEmptyNode(),
      nnkInfix.newTree(
        newIdentNode("*"),
        nnkCall.newTree(
          newIdentNode("sizeof"),
          newIdentNode("uint64")
        ),
        newLit(8)
      )
    )
  ),
  nnkFuncDef.newTree(
    nnkPostfix.newTree(
      newIdentNode("*"),
      newIdentNode("wordsRequired")
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      newIdentNode("int"),
      nnkIdentDefs.newTree(
        newIdentNode("bits"),
        newIdentNode("int"),
        newEmptyNode()
      )
    ),
    nnkPragma.newTree(
      newIdentNode("inline")
    ),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkConstSection.newTree(
        nnkConstDef.newTree(
          newIdentNode("divShiftor"),
          newEmptyNode(),
          nnkCall.newTree(
            newIdentNode("fastLog2"),
            newIdentNode("WordBitWidth")
          )
        )
      ),
      nnkAsgn.newTree(
        newIdentNode("result"),
        nnkInfix.newTree(
          newIdentNode("shr"),
          nnkPar.newTree(
            nnkInfix.newTree(
              newIdentNode("-"),
              nnkInfix.newTree(
                newIdentNode("+"),
                newIdentNode("bits"),
                newIdentNode("WordBitWidth")
              ),
              newLit(1)
            )
          ),
          newIdentNode("divShiftor")
        )
      )
    )
  ),
  nnkTypeSection.newTree(
    nnkTypeDef.newTree(
      nnkPostfix.newTree(
        newIdentNode("*"),
        newIdentNode("BigInt")
      ),
      nnkGenericParams.newTree(
        nnkIdentDefs.newTree(
          newIdentNode("bits"),
          nnkCommand.newTree(
            newIdentNode("static"),
            newIdentNode("int")
          ),
          newEmptyNode()
        )
      ),
      nnkObjectTy.newTree(
        newEmptyNode(),
        newEmptyNode(),
        nnkRecList.newTree(
          nnkIdentDefs.newTree(
            nnkPostfix.newTree(
              newIdentNode("*"),
              newIdentNode("limbs")
            ),
            nnkBracketExpr.newTree(
              newIdentNode("array"),
              nnkDotExpr.newTree(
                newIdentNode("bits"),
                newIdentNode("wordsRequired")
              ),
              newIdentNode("uint64")
            ),
            newEmptyNode()
          )
        )
      )
    )
  ),
  nnkConstSection.newTree(
    nnkConstDef.newTree(
      newIdentNode("CurveBitWidth"),
      newEmptyNode(),
      nnkBracket.newTree(
        nnkExprColonExpr.newTree(
          newIdentNode("BLS12_381"),
          newLit(381)
        )
      )
    )
  ),
  nnkTemplateDef.newTree(
    nnkPostfix.newTree(
      newIdentNode("*"),
      newIdentNode("matchingBigInt")
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      newIdentNode("untyped"),
      nnkIdentDefs.newTree(
        newIdentNode("Name"),
        nnkCommand.newTree(
          newIdentNode("static"),
          newIdentNode("Curve")
        ),
        newEmptyNode()
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      newCommentStmtNode("BigInt type necessary to store the prime field Fp"),
      nnkBracketExpr.newTree(
        newIdentNode("BigInt"),
        nnkBracketExpr.newTree(
          newIdentNode("CurveBitWidth"),
          newIdentNode("Name")
        )
      )
    )
  ),
  nnkTypeSection.newTree(
    nnkTypeDef.newTree(
      newIdentNode("Fp"),
      nnkGenericParams.newTree(
        nnkIdentDefs.newTree(
          newIdentNode("C"),
          nnkCommand.newTree(
            newIdentNode("static"),
            newIdentNode("Curve")
          ),
          newEmptyNode()
        )
      ),
      nnkObjectTy.newTree(
        newEmptyNode(),
        newEmptyNode(),
        nnkRecList.newTree(
          nnkIdentDefs.newTree(
            newIdentNode("residue"),
            nnkCall.newTree(
              newIdentNode("matchingBigInt"),
              newIdentNode("C")
            ),
            newEmptyNode()
          )
        )
      )
    )
  ),
  nnkTypeSection.newTree(
    nnkTypeDef.newTree(
      nnkPostfix.newTree(
        newIdentNode("*"),
        newIdentNode("CubicExt")
      ),
      nnkGenericParams.newTree(
        nnkIdentDefs.newTree(
          newIdentNode("F"),
          newEmptyNode(),
          newEmptyNode()
        )
      ),
      nnkObjectTy.newTree(
        newEmptyNode(),
        newEmptyNode(),
        nnkRecList.newTree(
          nnkIdentDefs.newTree(
            nnkPostfix.newTree(
              newIdentNode("*"),
              newIdentNode("coords")
            ),
            nnkBracketExpr.newTree(
              newIdentNode("array"),
              newLit(3),
              newIdentNode("F")
            ),
            newEmptyNode()
          )
        )
      )
    ),
    nnkTypeDef.newTree(
      newIdentNode("Fp3"),
      nnkGenericParams.newTree(
        nnkIdentDefs.newTree(
          newIdentNode("C"),
          nnkCommand.newTree(
            newIdentNode("static"),
            newIdentNode("Curve")
          ),
          newEmptyNode()
        )
      ),
      nnkBracketExpr.newTree(
        newIdentNode("CubicExt"),
        nnkBracketExpr.newTree(
          newIdentNode("Fp"),
          newIdentNode("C")
        )
      )
    )
  ),
  nnkTypeSection.newTree(
    nnkTypeDef.newTree(
      nnkPragmaExpr.newTree(
        newIdentNode("Fp3prj"),
        nnkPragma.newTree(
          nnkExprColonExpr.newTree(
            newIdentNode("borrow"),
            nnkAccQuoted.newTree(
              newIdentNode(".")
            )
          )
        )
      ),
      nnkGenericParams.newTree(
        nnkIdentDefs.newTree(
          newIdentNode("C"),
          nnkCommand.newTree(
            newIdentNode("static"),
            newIdentNode("Curve")
          ),
          newEmptyNode()
        )
      ),
      nnkDistinctTy.newTree(
        nnkBracketExpr.newTree(
          newIdentNode("Fp3"),
          newIdentNode("C")
        )
      )
    )
  ),
  nnkFuncDef.newTree(
    nnkPostfix.newTree(
      newIdentNode("*"),
      nnkAccQuoted.newTree(
        newIdentNode("+=")
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      newEmptyNode(),
      nnkIdentDefs.newTree(
        newIdentNode("a"),
        nnkVarTy.newTree(
          newIdentNode("Fp")
        ),
        newEmptyNode()
      ),
      nnkIdentDefs.newTree(
        newIdentNode("b"),
        newIdentNode("Fp"),
        newEmptyNode()
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkForStmt.newTree(
        newIdentNode("i"),
        nnkInfix.newTree(
          newIdentNode("..<"),
          newLit(0),
          nnkDotExpr.newTree(
            nnkDotExpr.newTree(
              nnkDotExpr.newTree(
                newIdentNode("a"),
                newIdentNode("residue")
              ),
              newIdentNode("limbs")
            ),
            newIdentNode("len")
          )
        ),
        nnkStmtList.newTree(
          nnkInfix.newTree(
            newIdentNode("+="),
            nnkBracketExpr.newTree(
              nnkDotExpr.newTree(
                nnkDotExpr.newTree(
                  newIdentNode("a"),
                  newIdentNode("residue")
                ),
                newIdentNode("limbs")
              ),
              newIdentNode("i")
            ),
            nnkBracketExpr.newTree(
              nnkDotExpr.newTree(
                newIdentNode("b"),
                newIdentNode("limbs")
              ),
              newIdentNode("i")
            )
          )
        )
      )
    )
  ),
  nnkFuncDef.newTree(
    nnkPostfix.newTree(
      newIdentNode("*"),
      nnkAccQuoted.newTree(
        newIdentNode("+=")
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      newEmptyNode(),
      nnkIdentDefs.newTree(
        newIdentNode("a"),
        nnkVarTy.newTree(
          newIdentNode("CubicExt")
        ),
        newEmptyNode()
      ),
      nnkIdentDefs.newTree(
        newIdentNode("b"),
        newIdentNode("CubicExt"),
        newEmptyNode()
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      newCommentStmtNode("Addition in the extension field"),
      nnkCommand.newTree(
        newIdentNode("staticFor"),
        newIdentNode("i"),
        newLit(0),
        nnkDotExpr.newTree(
          nnkDotExpr.newTree(
            newIdentNode("a"),
            newIdentNode("coords")
          ),
          newIdentNode("len")
        ),
        nnkStmtList.newTree(
          nnkInfix.newTree(
            newIdentNode("+="),
            nnkBracketExpr.newTree(
              nnkDotExpr.newTree(
                newIdentNode("a"),
                newIdentNode("coords")
              ),
              newIdentNode("i")
            ),
            nnkBracketExpr.newTree(
              nnkDotExpr.newTree(
                newIdentNode("b"),
                newIdentNode("coords")
              ),
              newIdentNode("i")
            )
          )
        )
      )
    )
  ),
  nnkVarSection.newTree(
    nnkIdentDefs.newTree(
      newIdentNode("a"),
      nnkBracketExpr.newTree(
        newIdentNode("Fp3prj"),
        newIdentNode("BLS12_381")
      ),
      newEmptyNode()
    )
  ),
  nnkCommand.newTree(
    newIdentNode("echo"),
    nnkDotExpr.newTree(
      nnkDotExpr.newTree(
        newIdentNode("a"),
        newIdentNode("coords")
      ),
      newIdentNode("len")
    )
  ),
  nnkCommand.newTree(
    newIdentNode("echo"),
    nnkDotExpr.newTree(
      nnkDotExpr.newTree(
        nnkDotExpr.newTree(
          nnkBracketExpr.newTree(
            nnkDotExpr.newTree(
              newIdentNode("a"),
              newIdentNode("coords")
            ),
            newLit(0)
          ),
          newIdentNode("residue")
        ),
        newIdentNode("limbs")
      ),
      newIdentNode("len")
    )
  ),
  nnkFuncDef.newTree(
    nnkPostfix.newTree(
      newIdentNode("*"),
      nnkAccQuoted.newTree(
        newIdentNode("+=")
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      newEmptyNode(),
      nnkIdentDefs.newTree(
        newIdentNode("a"),
        nnkVarTy.newTree(
          newIdentNode("Fp3prj")
        ),
        newEmptyNode()
      ),
      nnkIdentDefs.newTree(
        newIdentNode("b"),
        newIdentNode("Fp3prj"),
        newEmptyNode()
      )
    ),
    nnkPragma.newTree(
      newIdentNode("borrow")
    ),
    newEmptyNode(),
    newEmptyNode()
  )
)
2.0.0 👎 FAIL

Output

Error: Command failed: nim c --run  -d:nimDebug -d:nimDebugDlOpen -d:ssl -d:nimDisableCertificateValidation --forceBuild:on --colors:off --verbosity:0 --hints:off --lineTrace:off --nimcache:/home/runner/work/Nim/Nim --out:/home/runner/work/Nim/Nim/temp /home/runner/work/Nim/Nim/temp.nim
/home/runner/work/Nim/Nim/temp.nim(66, 6) template/generic instantiation of `+=` from here
/home/runner/work/Nim/Nim/temp.nim(59, 27) template/generic instantiation of `len` from here
/home/runner/.choosenim/toolchains/nim-2.0.0/lib/system.nim(702, 10) Error: invalid type: 'typeof(matchingBigInt(C))' in this context: 'proc (x: array[0..2, Fp[Fp3prj.C]]): int{.noSideEffect, gcsafe.}' for proc
assertions.nim(34)       raiseAssert
Error: unhandled exception: options.nim(664, 5) `false` errGenerated [AssertionDefect]

IR

Compiled filesize 0 (0 bytes)

Stats

  • Started 2024-08-16T16:50:04
  • Finished 2024-08-16T16:50:04
  • Duration

AST

nnkStmtList.newTree(
  nnkImportStmt.newTree(
    nnkInfix.newTree(
      newIdentNode("/"),
      newIdentNode("std"),
      newIdentNode("macros")
    )
  ),
  nnkImportStmt.newTree(
    nnkInfix.newTree(
      newIdentNode("/"),
      newIdentNode("std"),
      newIdentNode("bitops")
    )
  ),
  nnkProcDef.newTree(
    newIdentNode("replaceNodes"),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      newIdentNode("NimNode"),
      nnkIdentDefs.newTree(
        newIdentNode("ast"),
        newIdentNode("NimNode"),
        newEmptyNode()
      ),
      nnkIdentDefs.newTree(
        newIdentNode("what"),
        newIdentNode("NimNode"),
        newEmptyNode()
      ),
      nnkIdentDefs.newTree(
        newIdentNode("by"),
        newIdentNode("NimNode"),
        newEmptyNode()
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkProcDef.newTree(
        newIdentNode("inspect"),
        newEmptyNode(),
        newEmptyNode(),
        nnkFormalParams.newTree(
          newIdentNode("NimNode"),
          nnkIdentDefs.newTree(
            newIdentNode("node"),
            newIdentNode("NimNode"),
            newEmptyNode()
          )
        ),
        newEmptyNode(),
        newEmptyNode(),
        nnkStmtList.newTree(
          nnkCaseStmt.newTree(
            nnkDotExpr.newTree(
              newIdentNode("node"),
              newIdentNode("kind")
            ),
            nnkOfBranch.newTree(
              nnkCurly.newTree(
                newIdentNode("nnkIdent"),
                newIdentNode("nnkSym")
              ),
              nnkStmtList.newTree(
                nnkIfStmt.newTree(
                  nnkElifBranch.newTree(
                    nnkCall.newTree(
                      nnkDotExpr.newTree(
                        newIdentNode("node"),
                        newIdentNode("eqIdent")
                      ),
                      newIdentNode("what")
                    ),
                    nnkStmtList.newTree(
                      nnkReturnStmt.newTree(
                        newIdentNode("by")
                      )
                    )
                  )
                ),
                nnkReturnStmt.newTree(
                  newIdentNode("node")
                )
              )
            ),
            nnkOfBranch.newTree(
              newIdentNode("nnkEmpty"),
              nnkStmtList.newTree(
                nnkReturnStmt.newTree(
                  newIdentNode("node")
                )
              )
            ),
            nnkOfBranch.newTree(
              newIdentNode("nnkLiterals"),
              nnkStmtList.newTree(
                nnkReturnStmt.newTree(
                  newIdentNode("node")
                )
              )
            ),
            nnkElse.newTree(
              nnkStmtList.newTree(
                nnkVarSection.newTree(
                  nnkIdentDefs.newTree(
                    newIdentNode("rTree"),
                    newEmptyNode(),
                    nnkCall.newTree(
                      nnkDotExpr.newTree(
                        nnkDotExpr.newTree(
                          newIdentNode("node"),
                          newIdentNode("kind")
                        ),
                        newIdentNode("newTree")
                      )
                    )
                  )
                ),
                nnkForStmt.newTree(
                  newIdentNode("child"),
                  newIdentNode("node"),
                  nnkStmtList.newTree(
                    nnkCommand.newTree(
                      nnkDotExpr.newTree(
                        newIdentNode("rTree"),
                        newIdentNode("add")
                      ),
                      nnkCall.newTree(
                        newIdentNode("inspect"),
                        newIdentNode("child")
                      )
                    )
                  )
                ),
                nnkReturnStmt.newTree(
                  newIdentNode("rTree")
                )
              )
            )
          )
        )
      ),
      nnkAsgn.newTree(
        newIdentNode("result"),
        nnkCall.newTree(
          newIdentNode("inspect"),
          newIdentNode("ast")
        )
      )
    )
  ),
  nnkMacroDef.newTree(
    nnkPostfix.newTree(
      newIdentNode("*"),
      newIdentNode("staticFor")
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      newIdentNode("untyped"),
      nnkIdentDefs.newTree(
        newIdentNode("idx"),
        nnkCurlyExpr.newTree(
          newIdentNode("untyped"),
          newIdentNode("nkIdent")
        ),
        newEmptyNode()
      ),
      nnkIdentDefs.newTree(
        newIdentNode("start"),
        newIdentNode("stopEx"),
        nnkCommand.newTree(
          newIdentNode("static"),
          newIdentNode("int")
        ),
        newEmptyNode()
      ),
      nnkIdentDefs.newTree(
        newIdentNode("body"),
        newIdentNode("untyped"),
        newEmptyNode()
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkAsgn.newTree(
        newIdentNode("result"),
        nnkCall.newTree(
          newIdentNode("newStmtList")
        )
      ),
      nnkForStmt.newTree(
        newIdentNode("i"),
        nnkInfix.newTree(
          newIdentNode("..<"),
          newIdentNode("start"),
          newIdentNode("stopEx")
        ),
        nnkStmtList.newTree(
          nnkCommand.newTree(
            nnkDotExpr.newTree(
              newIdentNode("result"),
              newIdentNode("add")
            ),
            nnkCall.newTree(
              nnkDotExpr.newTree(
                newIdentNode("nnkBlockStmt"),
                newIdentNode("newTree")
              ),
              nnkCall.newTree(
                newIdentNode("ident"),
                nnkInfix.newTree(
                  newIdentNode("&"),
                  nnkInfix.newTree(
                    newIdentNode("&"),
                    newLit("unrolledIter_"),
                    nnkPrefix.newTree(
                      newIdentNode("$"),
                      newIdentNode("idx")
                    )
                  ),
                  nnkPrefix.newTree(
                    newIdentNode("$"),
                    newIdentNode("i")
                  )
                )
              ),
              nnkCall.newTree(
                nnkDotExpr.newTree(
                  newIdentNode("body"),
                  newIdentNode("replaceNodes")
                ),
                newIdentNode("idx"),
                nnkCommand.newTree(
                  newIdentNode("newLit"),
                  newIdentNode("i")
                )
              )
            )
          )
        )
      )
    )
  ),
  nnkTypeSection.newTree(
    nnkTypeDef.newTree(
      newIdentNode("Curve"),
      newEmptyNode(),
      nnkEnumTy.newTree(
        newEmptyNode(),
        newIdentNode("BLS12_381")
      )
    )
  ),
  nnkConstSection.newTree(
    nnkConstDef.newTree(
      nnkPostfix.newTree(
        newIdentNode("*"),
        newIdentNode("WordBitWidth")
      ),
      newEmptyNode(),
      nnkInfix.newTree(
        newIdentNode("*"),
        nnkCall.newTree(
          newIdentNode("sizeof"),
          newIdentNode("uint64")
        ),
        newLit(8)
      )
    )
  ),
  nnkFuncDef.newTree(
    nnkPostfix.newTree(
      newIdentNode("*"),
      newIdentNode("wordsRequired")
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      newIdentNode("int"),
      nnkIdentDefs.newTree(
        newIdentNode("bits"),
        newIdentNode("int"),
        newEmptyNode()
      )
    ),
    nnkPragma.newTree(
      newIdentNode("inline")
    ),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkConstSection.newTree(
        nnkConstDef.newTree(
          newIdentNode("divShiftor"),
          newEmptyNode(),
          nnkCall.newTree(
            newIdentNode("fastLog2"),
            newIdentNode("WordBitWidth")
          )
        )
      ),
      nnkAsgn.newTree(
        newIdentNode("result"),
        nnkInfix.newTree(
          newIdentNode("shr"),
          nnkPar.newTree(
            nnkInfix.newTree(
              newIdentNode("-"),
              nnkInfix.newTree(
                newIdentNode("+"),
                newIdentNode("bits"),
                newIdentNode("WordBitWidth")
              ),
              newLit(1)
            )
          ),
          newIdentNode("divShiftor")
        )
      )
    )
  ),
  nnkTypeSection.newTree(
    nnkTypeDef.newTree(
      nnkPostfix.newTree(
        newIdentNode("*"),
        newIdentNode("BigInt")
      ),
      nnkGenericParams.newTree(
        nnkIdentDefs.newTree(
          newIdentNode("bits"),
          nnkCommand.newTree(
            newIdentNode("static"),
            newIdentNode("int")
          ),
          newEmptyNode()
        )
      ),
      nnkObjectTy.newTree(
        newEmptyNode(),
        newEmptyNode(),
        nnkRecList.newTree(
          nnkIdentDefs.newTree(
            nnkPostfix.newTree(
              newIdentNode("*"),
              newIdentNode("limbs")
            ),
            nnkBracketExpr.newTree(
              newIdentNode("array"),
              nnkDotExpr.newTree(
                newIdentNode("bits"),
                newIdentNode("wordsRequired")
              ),
              newIdentNode("uint64")
            ),
            newEmptyNode()
          )
        )
      )
    )
  ),
  nnkConstSection.newTree(
    nnkConstDef.newTree(
      newIdentNode("CurveBitWidth"),
      newEmptyNode(),
      nnkBracket.newTree(
        nnkExprColonExpr.newTree(
          newIdentNode("BLS12_381"),
          newLit(381)
        )
      )
    )
  ),
  nnkTemplateDef.newTree(
    nnkPostfix.newTree(
      newIdentNode("*"),
      newIdentNode("matchingBigInt")
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      newIdentNode("untyped"),
      nnkIdentDefs.newTree(
        newIdentNode("Name"),
        nnkCommand.newTree(
          newIdentNode("static"),
          newIdentNode("Curve")
        ),
        newEmptyNode()
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      newCommentStmtNode("BigInt type necessary to store the prime field Fp"),
      nnkBracketExpr.newTree(
        newIdentNode("BigInt"),
        nnkBracketExpr.newTree(
          newIdentNode("CurveBitWidth"),
          newIdentNode("Name")
        )
      )
    )
  ),
  nnkTypeSection.newTree(
    nnkTypeDef.newTree(
      newIdentNode("Fp"),
      nnkGenericParams.newTree(
        nnkIdentDefs.newTree(
          newIdentNode("C"),
          nnkCommand.newTree(
            newIdentNode("static"),
            newIdentNode("Curve")
          ),
          newEmptyNode()
        )
      ),
      nnkObjectTy.newTree(
        newEmptyNode(),
        newEmptyNode(),
        nnkRecList.newTree(
          nnkIdentDefs.newTree(
            newIdentNode("residue"),
            nnkCall.newTree(
              newIdentNode("matchingBigInt"),
              newIdentNode("C")
            ),
            newEmptyNode()
          )
        )
      )
    )
  ),
  nnkTypeSection.newTree(
    nnkTypeDef.newTree(
      nnkPostfix.newTree(
        newIdentNode("*"),
        newIdentNode("CubicExt")
      ),
      nnkGenericParams.newTree(
        nnkIdentDefs.newTree(
          newIdentNode("F"),
          newEmptyNode(),
          newEmptyNode()
        )
      ),
      nnkObjectTy.newTree(
        newEmptyNode(),
        newEmptyNode(),
        nnkRecList.newTree(
          nnkIdentDefs.newTree(
            nnkPostfix.newTree(
              newIdentNode("*"),
              newIdentNode("coords")
            ),
            nnkBracketExpr.newTree(
              newIdentNode("array"),
              newLit(3),
              newIdentNode("F")
            ),
            newEmptyNode()
          )
        )
      )
    ),
    nnkTypeDef.newTree(
      newIdentNode("Fp3"),
      nnkGenericParams.newTree(
        nnkIdentDefs.newTree(
          newIdentNode("C"),
          nnkCommand.newTree(
            newIdentNode("static"),
            newIdentNode("Curve")
          ),
          newEmptyNode()
        )
      ),
      nnkBracketExpr.newTree(
        newIdentNode("CubicExt"),
        nnkBracketExpr.newTree(
          newIdentNode("Fp"),
          newIdentNode("C")
        )
      )
    )
  ),
  nnkTypeSection.newTree(
    nnkTypeDef.newTree(
      nnkPragmaExpr.newTree(
        newIdentNode("Fp3prj"),
        nnkPragma.newTree(
          nnkExprColonExpr.newTree(
            newIdentNode("borrow"),
            nnkAccQuoted.newTree(
              newIdentNode(".")
            )
          )
        )
      ),
      nnkGenericParams.newTree(
        nnkIdentDefs.newTree(
          newIdentNode("C"),
          nnkCommand.newTree(
            newIdentNode("static"),
            newIdentNode("Curve")
          ),
          newEmptyNode()
        )
      ),
      nnkDistinctTy.newTree(
        nnkBracketExpr.newTree(
          newIdentNode("Fp3"),
          newIdentNode("C")
        )
      )
    )
  ),
  nnkFuncDef.newTree(
    nnkPostfix.newTree(
      newIdentNode("*"),
      nnkAccQuoted.newTree(
        newIdentNode("+=")
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      newEmptyNode(),
      nnkIdentDefs.newTree(
        newIdentNode("a"),
        nnkVarTy.newTree(
          newIdentNode("Fp")
        ),
        newEmptyNode()
      ),
      nnkIdentDefs.newTree(
        newIdentNode("b"),
        newIdentNode("Fp"),
        newEmptyNode()
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkForStmt.newTree(
        newIdentNode("i"),
        nnkInfix.newTree(
          newIdentNode("..<"),
          newLit(0),
          nnkDotExpr.newTree(
            nnkDotExpr.newTree(
              nnkDotExpr.newTree(
                newIdentNode("a"),
                newIdentNode("residue")
              ),
              newIdentNode("limbs")
            ),
            newIdentNode("len")
          )
        ),
        nnkStmtList.newTree(
          nnkInfix.newTree(
            newIdentNode("+="),
            nnkBracketExpr.newTree(
              nnkDotExpr.newTree(
                nnkDotExpr.newTree(
                  newIdentNode("a"),
                  newIdentNode("residue")
                ),
                newIdentNode("limbs")
              ),
              newIdentNode("i")
            ),
            nnkBracketExpr.newTree(
              nnkDotExpr.newTree(
                newIdentNode("b"),
                newIdentNode("limbs")
              ),
              newIdentNode("i")
            )
          )
        )
      )
    )
  ),
  nnkFuncDef.newTree(
    nnkPostfix.newTree(
      newIdentNode("*"),
      nnkAccQuoted.newTree(
        newIdentNode("+=")
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      newEmptyNode(),
      nnkIdentDefs.newTree(
        newIdentNode("a"),
        nnkVarTy.newTree(
          newIdentNode("CubicExt")
        ),
        newEmptyNode()
      ),
      nnkIdentDefs.newTree(
        newIdentNode("b"),
        newIdentNode("CubicExt"),
        newEmptyNode()
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      newCommentStmtNode("Addition in the extension field"),
      nnkCommand.newTree(
        newIdentNode("staticFor"),
        newIdentNode("i"),
        newLit(0),
        nnkDotExpr.newTree(
          nnkDotExpr.newTree(
            newIdentNode("a"),
            newIdentNode("coords")
          ),
          newIdentNode("len")
        ),
        nnkStmtList.newTree(
          nnkInfix.newTree(
            newIdentNode("+="),
            nnkBracketExpr.newTree(
              nnkDotExpr.newTree(
                newIdentNode("a"),
                newIdentNode("coords")
              ),
              newIdentNode("i")
            ),
            nnkBracketExpr.newTree(
              nnkDotExpr.newTree(
                newIdentNode("b"),
                newIdentNode("coords")
              ),
              newIdentNode("i")
            )
          )
        )
      )
    )
  ),
  nnkVarSection.newTree(
    nnkIdentDefs.newTree(
      newIdentNode("a"),
      nnkBracketExpr.newTree(
        newIdentNode("Fp3prj"),
        newIdentNode("BLS12_381")
      ),
      newEmptyNode()
    )
  ),
  nnkCommand.newTree(
    newIdentNode("echo"),
    nnkDotExpr.newTree(
      nnkDotExpr.newTree(
        newIdentNode("a"),
        newIdentNode("coords")
      ),
      newIdentNode("len")
    )
  ),
  nnkCommand.newTree(
    newIdentNode("echo"),
    nnkDotExpr.newTree(
      nnkDotExpr.newTree(
        nnkDotExpr.newTree(
          nnkBracketExpr.newTree(
            nnkDotExpr.newTree(
              newIdentNode("a"),
              newIdentNode("coords")
            ),
            newLit(0)
          ),
          newIdentNode("residue")
        ),
        newIdentNode("limbs")
      ),
      newIdentNode("len")
    )
  ),
  nnkFuncDef.newTree(
    nnkPostfix.newTree(
      newIdentNode("*"),
      nnkAccQuoted.newTree(
        newIdentNode("+=")
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      newEmptyNode(),
      nnkIdentDefs.newTree(
        newIdentNode("a"),
        nnkVarTy.newTree(
          newIdentNode("Fp3prj")
        ),
        newEmptyNode()
      ),
      nnkIdentDefs.newTree(
        newIdentNode("b"),
        newIdentNode("Fp3prj"),
        newEmptyNode()
      )
    ),
    nnkPragma.newTree(
      newIdentNode("borrow")
    ),
    newEmptyNode(),
    newEmptyNode()
  )
)
1.6.20 👎 FAIL

Output

Error: Command failed: nim c --run  -d:nimDebug -d:nimDebugDlOpen -d:ssl -d:nimDisableCertificateValidation --forceBuild:on --colors:off --verbosity:0 --hints:off --lineTrace:off --nimcache:/home/runner/work/Nim/Nim --out:/home/runner/work/Nim/Nim/temp /home/runner/work/Nim/Nim/temp.nim
/home/runner/work/Nim/Nim/temp.nim(66, 6) template/generic instantiation of `+=` from here
/home/runner/work/Nim/Nim/temp.nim(59, 27) template/generic instantiation of `len` from here
/home/runner/.choosenim/toolchains/nim-1.6.20/lib/system.nim(746, 10) Error: invalid type: 'typeof(matchingBigInt(C))' in this context: 'proc (x: array[0..2, Fp[Fp3prj.C]]): int{.noSideEffect, gcsafe, locks: 0.}' for proc
fatal.nim(54)            sysFatal
Error: unhandled exception: options.nim(662, 14) `false` errGenerated [AssertionDefect]

IR

Compiled filesize 0 (0 bytes)

Stats

  • Started 2024-08-16T16:50:06
  • Finished 2024-08-16T16:50:07
  • Duration

AST

nnkStmtList.newTree(
  nnkImportStmt.newTree(
    nnkInfix.newTree(
      newIdentNode("/"),
      newIdentNode("std"),
      newIdentNode("macros")
    )
  ),
  nnkImportStmt.newTree(
    nnkInfix.newTree(
      newIdentNode("/"),
      newIdentNode("std"),
      newIdentNode("bitops")
    )
  ),
  nnkProcDef.newTree(
    newIdentNode("replaceNodes"),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      newIdentNode("NimNode"),
      nnkIdentDefs.newTree(
        newIdentNode("ast"),
        newIdentNode("NimNode"),
        newEmptyNode()
      ),
      nnkIdentDefs.newTree(
        newIdentNode("what"),
        newIdentNode("NimNode"),
        newEmptyNode()
      ),
      nnkIdentDefs.newTree(
        newIdentNode("by"),
        newIdentNode("NimNode"),
        newEmptyNode()
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkProcDef.newTree(
        newIdentNode("inspect"),
        newEmptyNode(),
        newEmptyNode(),
        nnkFormalParams.newTree(
          newIdentNode("NimNode"),
          nnkIdentDefs.newTree(
            newIdentNode("node"),
            newIdentNode("NimNode"),
            newEmptyNode()
          )
        ),
        newEmptyNode(),
        newEmptyNode(),
        nnkStmtList.newTree(
          nnkCaseStmt.newTree(
            nnkDotExpr.newTree(
              newIdentNode("node"),
              newIdentNode("kind")
            ),
            nnkOfBranch.newTree(
              nnkCurly.newTree(
                newIdentNode("nnkIdent"),
                newIdentNode("nnkSym")
              ),
              nnkStmtList.newTree(
                nnkIfStmt.newTree(
                  nnkElifBranch.newTree(
                    nnkCall.newTree(
                      nnkDotExpr.newTree(
                        newIdentNode("node"),
                        newIdentNode("eqIdent")
                      ),
                      newIdentNode("what")
                    ),
                    nnkStmtList.newTree(
                      nnkReturnStmt.newTree(
                        newIdentNode("by")
                      )
                    )
                  )
                ),
                nnkReturnStmt.newTree(
                  newIdentNode("node")
                )
              )
            ),
            nnkOfBranch.newTree(
              newIdentNode("nnkEmpty"),
              nnkStmtList.newTree(
                nnkReturnStmt.newTree(
                  newIdentNode("node")
                )
              )
            ),
            nnkOfBranch.newTree(
              newIdentNode("nnkLiterals"),
              nnkStmtList.newTree(
                nnkReturnStmt.newTree(
                  newIdentNode("node")
                )
              )
            ),
            nnkElse.newTree(
              nnkStmtList.newTree(
                nnkVarSection.newTree(
                  nnkIdentDefs.newTree(
                    newIdentNode("rTree"),
                    newEmptyNode(),
                    nnkCall.newTree(
                      nnkDotExpr.newTree(
                        nnkDotExpr.newTree(
                          newIdentNode("node"),
                          newIdentNode("kind")
                        ),
                        newIdentNode("newTree")
                      )
                    )
                  )
                ),
                nnkForStmt.newTree(
                  newIdentNode("child"),
                  newIdentNode("node"),
                  nnkStmtList.newTree(
                    nnkCommand.newTree(
                      nnkDotExpr.newTree(
                        newIdentNode("rTree"),
                        newIdentNode("add")
                      ),
                      nnkCall.newTree(
                        newIdentNode("inspect"),
                        newIdentNode("child")
                      )
                    )
                  )
                ),
                nnkReturnStmt.newTree(
                  newIdentNode("rTree")
                )
              )
            )
          )
        )
      ),
      nnkAsgn.newTree(
        newIdentNode("result"),
        nnkCall.newTree(
          newIdentNode("inspect"),
          newIdentNode("ast")
        )
      )
    )
  ),
  nnkMacroDef.newTree(
    nnkPostfix.newTree(
      newIdentNode("*"),
      newIdentNode("staticFor")
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      newIdentNode("untyped"),
      nnkIdentDefs.newTree(
        newIdentNode("idx"),
        nnkCurlyExpr.newTree(
          newIdentNode("untyped"),
          newIdentNode("nkIdent")
        ),
        newEmptyNode()
      ),
      nnkIdentDefs.newTree(
        newIdentNode("start"),
        newIdentNode("stopEx"),
        nnkCommand.newTree(
          newIdentNode("static"),
          newIdentNode("int")
        ),
        newEmptyNode()
      ),
      nnkIdentDefs.newTree(
        newIdentNode("body"),
        newIdentNode("untyped"),
        newEmptyNode()
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkAsgn.newTree(
        newIdentNode("result"),
        nnkCall.newTree(
          newIdentNode("newStmtList")
        )
      ),
      nnkForStmt.newTree(
        newIdentNode("i"),
        nnkInfix.newTree(
          newIdentNode("..<"),
          newIdentNode("start"),
          newIdentNode("stopEx")
        ),
        nnkStmtList.newTree(
          nnkCommand.newTree(
            nnkDotExpr.newTree(
              newIdentNode("result"),
              newIdentNode("add")
            ),
            nnkCall.newTree(
              nnkDotExpr.newTree(
                newIdentNode("nnkBlockStmt"),
                newIdentNode("newTree")
              ),
              nnkCall.newTree(
                newIdentNode("ident"),
                nnkInfix.newTree(
                  newIdentNode("&"),
                  nnkInfix.newTree(
                    newIdentNode("&"),
                    newLit("unrolledIter_"),
                    nnkPrefix.newTree(
                      newIdentNode("$"),
                      newIdentNode("idx")
                    )
                  ),
                  nnkPrefix.newTree(
                    newIdentNode("$"),
                    newIdentNode("i")
                  )
                )
              ),
              nnkCall.newTree(
                nnkDotExpr.newTree(
                  newIdentNode("body"),
                  newIdentNode("replaceNodes")
                ),
                newIdentNode("idx"),
                nnkCommand.newTree(
                  newIdentNode("newLit"),
                  newIdentNode("i")
                )
              )
            )
          )
        )
      )
    )
  ),
  nnkTypeSection.newTree(
    nnkTypeDef.newTree(
      newIdentNode("Curve"),
      newEmptyNode(),
      nnkEnumTy.newTree(
        newEmptyNode(),
        newIdentNode("BLS12_381")
      )
    )
  ),
  nnkConstSection.newTree(
    nnkConstDef.newTree(
      nnkPostfix.newTree(
        newIdentNode("*"),
        newIdentNode("WordBitWidth")
      ),
      newEmptyNode(),
      nnkInfix.newTree(
        newIdentNode("*"),
        nnkCall.newTree(
          newIdentNode("sizeof"),
          newIdentNode("uint64")
        ),
        newLit(8)
      )
    )
  ),
  nnkFuncDef.newTree(
    nnkPostfix.newTree(
      newIdentNode("*"),
      newIdentNode("wordsRequired")
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      newIdentNode("int"),
      nnkIdentDefs.newTree(
        newIdentNode("bits"),
        newIdentNode("int"),
        newEmptyNode()
      )
    ),
    nnkPragma.newTree(
      newIdentNode("inline")
    ),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkConstSection.newTree(
        nnkConstDef.newTree(
          newIdentNode("divShiftor"),
          newEmptyNode(),
          nnkCall.newTree(
            newIdentNode("fastLog2"),
            newIdentNode("WordBitWidth")
          )
        )
      ),
      nnkAsgn.newTree(
        newIdentNode("result"),
        nnkInfix.newTree(
          newIdentNode("shr"),
          nnkPar.newTree(
            nnkInfix.newTree(
              newIdentNode("-"),
              nnkInfix.newTree(
                newIdentNode("+"),
                newIdentNode("bits"),
                newIdentNode("WordBitWidth")
              ),
              newLit(1)
            )
          ),
          newIdentNode("divShiftor")
        )
      )
    )
  ),
  nnkTypeSection.newTree(
    nnkTypeDef.newTree(
      nnkPostfix.newTree(
        newIdentNode("*"),
        newIdentNode("BigInt")
      ),
      nnkGenericParams.newTree(
        nnkIdentDefs.newTree(
          newIdentNode("bits"),
          nnkCommand.newTree(
            newIdentNode("static"),
            newIdentNode("int")
          ),
          newEmptyNode()
        )
      ),
      nnkObjectTy.newTree(
        newEmptyNode(),
        newEmptyNode(),
        nnkRecList.newTree(
          nnkIdentDefs.newTree(
            nnkPostfix.newTree(
              newIdentNode("*"),
              newIdentNode("limbs")
            ),
            nnkBracketExpr.newTree(
              newIdentNode("array"),
              nnkDotExpr.newTree(
                newIdentNode("bits"),
                newIdentNode("wordsRequired")
              ),
              newIdentNode("uint64")
            ),
            newEmptyNode()
          )
        )
      )
    )
  ),
  nnkConstSection.newTree(
    nnkConstDef.newTree(
      newIdentNode("CurveBitWidth"),
      newEmptyNode(),
      nnkBracket.newTree(
        nnkExprColonExpr.newTree(
          newIdentNode("BLS12_381"),
          newLit(381)
        )
      )
    )
  ),
  nnkTemplateDef.newTree(
    nnkPostfix.newTree(
      newIdentNode("*"),
      newIdentNode("matchingBigInt")
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      newIdentNode("untyped"),
      nnkIdentDefs.newTree(
        newIdentNode("Name"),
        nnkCommand.newTree(
          newIdentNode("static"),
          newIdentNode("Curve")
        ),
        newEmptyNode()
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      newCommentStmtNode("BigInt type necessary to store the prime field Fp"),
      nnkBracketExpr.newTree(
        newIdentNode("BigInt"),
        nnkBracketExpr.newTree(
          newIdentNode("CurveBitWidth"),
          newIdentNode("Name")
        )
      )
    )
  ),
  nnkTypeSection.newTree(
    nnkTypeDef.newTree(
      newIdentNode("Fp"),
      nnkGenericParams.newTree(
        nnkIdentDefs.newTree(
          newIdentNode("C"),
          nnkCommand.newTree(
            newIdentNode("static"),
            newIdentNode("Curve")
          ),
          newEmptyNode()
        )
      ),
      nnkObjectTy.newTree(
        newEmptyNode(),
        newEmptyNode(),
        nnkRecList.newTree(
          nnkIdentDefs.newTree(
            newIdentNode("residue"),
            nnkCall.newTree(
              newIdentNode("matchingBigInt"),
              newIdentNode("C")
            ),
            newEmptyNode()
          )
        )
      )
    )
  ),
  nnkTypeSection.newTree(
    nnkTypeDef.newTree(
      nnkPostfix.newTree(
        newIdentNode("*"),
        newIdentNode("CubicExt")
      ),
      nnkGenericParams.newTree(
        nnkIdentDefs.newTree(
          newIdentNode("F"),
          newEmptyNode(),
          newEmptyNode()
        )
      ),
      nnkObjectTy.newTree(
        newEmptyNode(),
        newEmptyNode(),
        nnkRecList.newTree(
          nnkIdentDefs.newTree(
            nnkPostfix.newTree(
              newIdentNode("*"),
              newIdentNode("coords")
            ),
            nnkBracketExpr.newTree(
              newIdentNode("array"),
              newLit(3),
              newIdentNode("F")
            ),
            newEmptyNode()
          )
        )
      )
    ),
    nnkTypeDef.newTree(
      newIdentNode("Fp3"),
      nnkGenericParams.newTree(
        nnkIdentDefs.newTree(
          newIdentNode("C"),
          nnkCommand.newTree(
            newIdentNode("static"),
            newIdentNode("Curve")
          ),
          newEmptyNode()
        )
      ),
      nnkBracketExpr.newTree(
        newIdentNode("CubicExt"),
        nnkBracketExpr.newTree(
          newIdentNode("Fp"),
          newIdentNode("C")
        )
      )
    )
  ),
  nnkTypeSection.newTree(
    nnkTypeDef.newTree(
      nnkPragmaExpr.newTree(
        newIdentNode("Fp3prj"),
        nnkPragma.newTree(
          nnkExprColonExpr.newTree(
            newIdentNode("borrow"),
            nnkAccQuoted.newTree(
              newIdentNode(".")
            )
          )
        )
      ),
      nnkGenericParams.newTree(
        nnkIdentDefs.newTree(
          newIdentNode("C"),
          nnkCommand.newTree(
            newIdentNode("static"),
            newIdentNode("Curve")
          ),
          newEmptyNode()
        )
      ),
      nnkDistinctTy.newTree(
        nnkBracketExpr.newTree(
          newIdentNode("Fp3"),
          newIdentNode("C")
        )
      )
    )
  ),
  nnkFuncDef.newTree(
    nnkPostfix.newTree(
      newIdentNode("*"),
      nnkAccQuoted.newTree(
        newIdentNode("+=")
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      newEmptyNode(),
      nnkIdentDefs.newTree(
        newIdentNode("a"),
        nnkVarTy.newTree(
          newIdentNode("Fp")
        ),
        newEmptyNode()
      ),
      nnkIdentDefs.newTree(
        newIdentNode("b"),
        newIdentNode("Fp"),
        newEmptyNode()
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkForStmt.newTree(
        newIdentNode("i"),
        nnkInfix.newTree(
          newIdentNode("..<"),
          newLit(0),
          nnkDotExpr.newTree(
            nnkDotExpr.newTree(
              nnkDotExpr.newTree(
                newIdentNode("a"),
                newIdentNode("residue")
              ),
              newIdentNode("limbs")
            ),
            newIdentNode("len")
          )
        ),
        nnkStmtList.newTree(
          nnkInfix.newTree(
            newIdentNode("+="),
            nnkBracketExpr.newTree(
              nnkDotExpr.newTree(
                nnkDotExpr.newTree(
                  newIdentNode("a"),
                  newIdentNode("residue")
                ),
                newIdentNode("limbs")
              ),
              newIdentNode("i")
            ),
            nnkBracketExpr.newTree(
              nnkDotExpr.newTree(
                newIdentNode("b"),
                newIdentNode("limbs")
              ),
              newIdentNode("i")
            )
          )
        )
      )
    )
  ),
  nnkFuncDef.newTree(
    nnkPostfix.newTree(
      newIdentNode("*"),
      nnkAccQuoted.newTree(
        newIdentNode("+=")
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      newEmptyNode(),
      nnkIdentDefs.newTree(
        newIdentNode("a"),
        nnkVarTy.newTree(
          newIdentNode("CubicExt")
        ),
        newEmptyNode()
      ),
      nnkIdentDefs.newTree(
        newIdentNode("b"),
        newIdentNode("CubicExt"),
        newEmptyNode()
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      newCommentStmtNode("Addition in the extension field"),
      nnkCommand.newTree(
        newIdentNode("staticFor"),
        newIdentNode("i"),
        newLit(0),
        nnkDotExpr.newTree(
          nnkDotExpr.newTree(
            newIdentNode("a"),
            newIdentNode("coords")
          ),
          newIdentNode("len")
        ),
        nnkStmtList.newTree(
          nnkInfix.newTree(
            newIdentNode("+="),
            nnkBracketExpr.newTree(
              nnkDotExpr.newTree(
                newIdentNode("a"),
                newIdentNode("coords")
              ),
              newIdentNode("i")
            ),
            nnkBracketExpr.newTree(
              nnkDotExpr.newTree(
                newIdentNode("b"),
                newIdentNode("coords")
              ),
              newIdentNode("i")
            )
          )
        )
      )
    )
  ),
  nnkVarSection.newTree(
    nnkIdentDefs.newTree(
      newIdentNode("a"),
      nnkBracketExpr.newTree(
        newIdentNode("Fp3prj"),
        newIdentNode("BLS12_381")
      ),
      newEmptyNode()
    )
  ),
  nnkCommand.newTree(
    newIdentNode("echo"),
    nnkDotExpr.newTree(
      nnkDotExpr.newTree(
        newIdentNode("a"),
        newIdentNode("coords")
      ),
      newIdentNode("len")
    )
  ),
  nnkCommand.newTree(
    newIdentNode("echo"),
    nnkDotExpr.newTree(
      nnkDotExpr.newTree(
        nnkDotExpr.newTree(
          nnkBracketExpr.newTree(
            nnkDotExpr.newTree(
              newIdentNode("a"),
              newIdentNode("coords")
            ),
            newLit(0)
          ),
          newIdentNode("residue")
        ),
        newIdentNode("limbs")
      ),
      newIdentNode("len")
    )
  ),
  nnkFuncDef.newTree(
    nnkPostfix.newTree(
      newIdentNode("*"),
      nnkAccQuoted.newTree(
        newIdentNode("+=")
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      newEmptyNode(),
      nnkIdentDefs.newTree(
        newIdentNode("a"),
        nnkVarTy.newTree(
          newIdentNode("Fp3prj")
        ),
        newEmptyNode()
      ),
      nnkIdentDefs.newTree(
        newIdentNode("b"),
        newIdentNode("Fp3prj"),
        newEmptyNode()
      )
    ),
    nnkPragma.newTree(
      newIdentNode("borrow")
    ),
    newEmptyNode(),
    newEmptyNode()
  )
)
1.4.8 👎 FAIL

Output

Error: Command failed: nim c --run  -d:nimDebug -d:nimDebugDlOpen -d:ssl -d:nimDisableCertificateValidation --forceBuild:on --colors:off --verbosity:0 --hints:off --lineTrace:off --nimcache:/home/runner/work/Nim/Nim --out:/home/runner/work/Nim/Nim/temp /home/runner/work/Nim/Nim/temp.nim
/home/runner/work/Nim/Nim/temp.nim(53, 3) Error: only a 'distinct' type can borrow `.`

IR

Compiled filesize 0 (0 bytes)

Stats

  • Started 2024-08-16T16:50:09
  • Finished 2024-08-16T16:50:09
  • Duration

AST

nnkStmtList.newTree(
  nnkImportStmt.newTree(
    nnkInfix.newTree(
      newIdentNode("/"),
      newIdentNode("std"),
      newIdentNode("macros")
    )
  ),
  nnkImportStmt.newTree(
    nnkInfix.newTree(
      newIdentNode("/"),
      newIdentNode("std"),
      newIdentNode("bitops")
    )
  ),
  nnkProcDef.newTree(
    newIdentNode("replaceNodes"),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      newIdentNode("NimNode"),
      nnkIdentDefs.newTree(
        newIdentNode("ast"),
        newIdentNode("NimNode"),
        newEmptyNode()
      ),
      nnkIdentDefs.newTree(
        newIdentNode("what"),
        newIdentNode("NimNode"),
        newEmptyNode()
      ),
      nnkIdentDefs.newTree(
        newIdentNode("by"),
        newIdentNode("NimNode"),
        newEmptyNode()
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkProcDef.newTree(
        newIdentNode("inspect"),
        newEmptyNode(),
        newEmptyNode(),
        nnkFormalParams.newTree(
          newIdentNode("NimNode"),
          nnkIdentDefs.newTree(
            newIdentNode("node"),
            newIdentNode("NimNode"),
            newEmptyNode()
          )
        ),
        newEmptyNode(),
        newEmptyNode(),
        nnkStmtList.newTree(
          nnkCaseStmt.newTree(
            nnkDotExpr.newTree(
              newIdentNode("node"),
              newIdentNode("kind")
            ),
            nnkOfBranch.newTree(
              nnkCurly.newTree(
                newIdentNode("nnkIdent"),
                newIdentNode("nnkSym")
              ),
              nnkStmtList.newTree(
                nnkIfStmt.newTree(
                  nnkElifBranch.newTree(
                    nnkCall.newTree(
                      nnkDotExpr.newTree(
                        newIdentNode("node"),
                        newIdentNode("eqIdent")
                      ),
                      newIdentNode("what")
                    ),
                    nnkStmtList.newTree(
                      nnkReturnStmt.newTree(
                        newIdentNode("by")
                      )
                    )
                  )
                ),
                nnkReturnStmt.newTree(
                  newIdentNode("node")
                )
              )
            ),
            nnkOfBranch.newTree(
              newIdentNode("nnkEmpty"),
              nnkStmtList.newTree(
                nnkReturnStmt.newTree(
                  newIdentNode("node")
                )
              )
            ),
            nnkOfBranch.newTree(
              newIdentNode("nnkLiterals"),
              nnkStmtList.newTree(
                nnkReturnStmt.newTree(
                  newIdentNode("node")
                )
              )
            ),
            nnkElse.newTree(
              nnkStmtList.newTree(
                nnkVarSection.newTree(
                  nnkIdentDefs.newTree(
                    newIdentNode("rTree"),
                    newEmptyNode(),
                    nnkCall.newTree(
                      nnkDotExpr.newTree(
                        nnkDotExpr.newTree(
                          newIdentNode("node"),
                          newIdentNode("kind")
                        ),
                        newIdentNode("newTree")
                      )
                    )
                  )
                ),
                nnkForStmt.newTree(
                  newIdentNode("child"),
                  newIdentNode("node"),
                  nnkStmtList.newTree(
                    nnkCommand.newTree(
                      nnkDotExpr.newTree(
                        newIdentNode("rTree"),
                        newIdentNode("add")
                      ),
                      nnkCall.newTree(
                        newIdentNode("inspect"),
                        newIdentNode("child")
                      )
                    )
                  )
                ),
                nnkReturnStmt.newTree(
                  newIdentNode("rTree")
                )
              )
            )
          )
        )
      ),
      nnkAsgn.newTree(
        newIdentNode("result"),
        nnkCall.newTree(
          newIdentNode("inspect"),
          newIdentNode("ast")
        )
      )
    )
  ),
  nnkMacroDef.newTree(
    nnkPostfix.newTree(
      newIdentNode("*"),
      newIdentNode("staticFor")
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      newIdentNode("untyped"),
      nnkIdentDefs.newTree(
        newIdentNode("idx"),
        nnkCurlyExpr.newTree(
          newIdentNode("untyped"),
          newIdentNode("nkIdent")
        ),
        newEmptyNode()
      ),
      nnkIdentDefs.newTree(
        newIdentNode("start"),
        newIdentNode("stopEx"),
        nnkCommand.newTree(
          newIdentNode("static"),
          newIdentNode("int")
        ),
        newEmptyNode()
      ),
      nnkIdentDefs.newTree(
        newIdentNode("body"),
        newIdentNode("untyped"),
        newEmptyNode()
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkAsgn.newTree(
        newIdentNode("result"),
        nnkCall.newTree(
          newIdentNode("newStmtList")
        )
      ),
      nnkForStmt.newTree(
        newIdentNode("i"),
        nnkInfix.newTree(
          newIdentNode("..<"),
          newIdentNode("start"),
          newIdentNode("stopEx")
        ),
        nnkStmtList.newTree(
          nnkCommand.newTree(
            nnkDotExpr.newTree(
              newIdentNode("result"),
              newIdentNode("add")
            ),
            nnkCall.newTree(
              nnkDotExpr.newTree(
                newIdentNode("nnkBlockStmt"),
                newIdentNode("newTree")
              ),
              nnkCall.newTree(
                newIdentNode("ident"),
                nnkInfix.newTree(
                  newIdentNode("&"),
                  nnkInfix.newTree(
                    newIdentNode("&"),
                    newLit("unrolledIter_"),
                    nnkPrefix.newTree(
                      newIdentNode("$"),
                      newIdentNode("idx")
                    )
                  ),
                  nnkPrefix.newTree(
                    newIdentNode("$"),
                    newIdentNode("i")
                  )
                )
              ),
              nnkCall.newTree(
                nnkDotExpr.newTree(
                  newIdentNode("body"),
                  newIdentNode("replaceNodes")
                ),
                newIdentNode("idx"),
                nnkCommand.newTree(
                  newIdentNode("newLit"),
                  newIdentNode("i")
                )
              )
            )
          )
        )
      )
    )
  ),
  nnkTypeSection.newTree(
    nnkTypeDef.newTree(
      newIdentNode("Curve"),
      newEmptyNode(),
      nnkEnumTy.newTree(
        newEmptyNode(),
        newIdentNode("BLS12_381")
      )
    )
  ),
  nnkConstSection.newTree(
    nnkConstDef.newTree(
      nnkPostfix.newTree(
        newIdentNode("*"),
        newIdentNode("WordBitWidth")
      ),
      newEmptyNode(),
      nnkInfix.newTree(
        newIdentNode("*"),
        nnkCall.newTree(
          newIdentNode("sizeof"),
          newIdentNode("uint64")
        ),
        newLit(8)
      )
    )
  ),
  nnkFuncDef.newTree(
    nnkPostfix.newTree(
      newIdentNode("*"),
      newIdentNode("wordsRequired")
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      newIdentNode("int"),
      nnkIdentDefs.newTree(
        newIdentNode("bits"),
        newIdentNode("int"),
        newEmptyNode()
      )
    ),
    nnkPragma.newTree(
      newIdentNode("inline")
    ),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkConstSection.newTree(
        nnkConstDef.newTree(
          newIdentNode("divShiftor"),
          newEmptyNode(),
          nnkCall.newTree(
            newIdentNode("fastLog2"),
            newIdentNode("WordBitWidth")
          )
        )
      ),
      nnkAsgn.newTree(
        newIdentNode("result"),
        nnkInfix.newTree(
          newIdentNode("shr"),
          nnkPar.newTree(
            nnkInfix.newTree(
              newIdentNode("-"),
              nnkInfix.newTree(
                newIdentNode("+"),
                newIdentNode("bits"),
                newIdentNode("WordBitWidth")
              ),
              newLit(1)
            )
          ),
          newIdentNode("divShiftor")
        )
      )
    )
  ),
  nnkTypeSection.newTree(
    nnkTypeDef.newTree(
      nnkPostfix.newTree(
        newIdentNode("*"),
        newIdentNode("BigInt")
      ),
      nnkGenericParams.newTree(
        nnkIdentDefs.newTree(
          newIdentNode("bits"),
          nnkCommand.newTree(
            newIdentNode("static"),
            newIdentNode("int")
          ),
          newEmptyNode()
        )
      ),
      nnkObjectTy.newTree(
        newEmptyNode(),
        newEmptyNode(),
        nnkRecList.newTree(
          nnkIdentDefs.newTree(
            nnkPostfix.newTree(
              newIdentNode("*"),
              newIdentNode("limbs")
            ),
            nnkBracketExpr.newTree(
              newIdentNode("array"),
              nnkDotExpr.newTree(
                newIdentNode("bits"),
                newIdentNode("wordsRequired")
              ),
              newIdentNode("uint64")
            ),
            newEmptyNode()
          )
        )
      )
    )
  ),
  nnkConstSection.newTree(
    nnkConstDef.newTree(
      newIdentNode("CurveBitWidth"),
      newEmptyNode(),
      nnkBracket.newTree(
        nnkExprColonExpr.newTree(
          newIdentNode("BLS12_381"),
          newLit(381)
        )
      )
    )
  ),
  nnkTemplateDef.newTree(
    nnkPostfix.newTree(
      newIdentNode("*"),
      newIdentNode("matchingBigInt")
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      newIdentNode("untyped"),
      nnkIdentDefs.newTree(
        newIdentNode("Name"),
        nnkCommand.newTree(
          newIdentNode("static"),
          newIdentNode("Curve")
        ),
        newEmptyNode()
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      newCommentStmtNode("BigInt type necessary to store the prime field Fp"),
      nnkBracketExpr.newTree(
        newIdentNode("BigInt"),
        nnkBracketExpr.newTree(
          newIdentNode("CurveBitWidth"),
          newIdentNode("Name")
        )
      )
    )
  ),
  nnkTypeSection.newTree(
    nnkTypeDef.newTree(
      newIdentNode("Fp"),
      nnkGenericParams.newTree(
        nnkIdentDefs.newTree(
          newIdentNode("C"),
          nnkCommand.newTree(
            newIdentNode("static"),
            newIdentNode("Curve")
          ),
          newEmptyNode()
        )
      ),
      nnkObjectTy.newTree(
        newEmptyNode(),
        newEmptyNode(),
        nnkRecList.newTree(
          nnkIdentDefs.newTree(
            newIdentNode("residue"),
            nnkCall.newTree(
              newIdentNode("matchingBigInt"),
              newIdentNode("C")
            ),
            newEmptyNode()
          )
        )
      )
    )
  ),
  nnkTypeSection.newTree(
    nnkTypeDef.newTree(
      nnkPostfix.newTree(
        newIdentNode("*"),
        newIdentNode("CubicExt")
      ),
      nnkGenericParams.newTree(
        nnkIdentDefs.newTree(
          newIdentNode("F"),
          newEmptyNode(),
          newEmptyNode()
        )
      ),
      nnkObjectTy.newTree(
        newEmptyNode(),
        newEmptyNode(),
        nnkRecList.newTree(
          nnkIdentDefs.newTree(
            nnkPostfix.newTree(
              newIdentNode("*"),
              newIdentNode("coords")
            ),
            nnkBracketExpr.newTree(
              newIdentNode("array"),
              newLit(3),
              newIdentNode("F")
            ),
            newEmptyNode()
          )
        )
      )
    ),
    nnkTypeDef.newTree(
      newIdentNode("Fp3"),
      nnkGenericParams.newTree(
        nnkIdentDefs.newTree(
          newIdentNode("C"),
          nnkCommand.newTree(
            newIdentNode("static"),
            newIdentNode("Curve")
          ),
          newEmptyNode()
        )
      ),
      nnkBracketExpr.newTree(
        newIdentNode("CubicExt"),
        nnkBracketExpr.newTree(
          newIdentNode("Fp"),
          newIdentNode("C")
        )
      )
    )
  ),
  nnkTypeSection.newTree(
    nnkTypeDef.newTree(
      nnkPragmaExpr.newTree(
        newIdentNode("Fp3prj"),
        nnkPragma.newTree(
          nnkExprColonExpr.newTree(
            newIdentNode("borrow"),
            nnkAccQuoted.newTree(
              newIdentNode(".")
            )
          )
        )
      ),
      nnkGenericParams.newTree(
        nnkIdentDefs.newTree(
          newIdentNode("C"),
          nnkCommand.newTree(
            newIdentNode("static"),
            newIdentNode("Curve")
          ),
          newEmptyNode()
        )
      ),
      nnkDistinctTy.newTree(
        nnkBracketExpr.newTree(
          newIdentNode("Fp3"),
          newIdentNode("C")
        )
      )
    )
  ),
  nnkFuncDef.newTree(
    nnkPostfix.newTree(
      newIdentNode("*"),
      nnkAccQuoted.newTree(
        newIdentNode("+=")
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      newEmptyNode(),
      nnkIdentDefs.newTree(
        newIdentNode("a"),
        nnkVarTy.newTree(
          newIdentNode("Fp")
        ),
        newEmptyNode()
      ),
      nnkIdentDefs.newTree(
        newIdentNode("b"),
        newIdentNode("Fp"),
        newEmptyNode()
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkForStmt.newTree(
        newIdentNode("i"),
        nnkInfix.newTree(
          newIdentNode("..<"),
          newLit(0),
          nnkDotExpr.newTree(
            nnkDotExpr.newTree(
              nnkDotExpr.newTree(
                newIdentNode("a"),
                newIdentNode("residue")
              ),
              newIdentNode("limbs")
            ),
            newIdentNode("len")
          )
        ),
        nnkStmtList.newTree(
          nnkInfix.newTree(
            newIdentNode("+="),
            nnkBracketExpr.newTree(
              nnkDotExpr.newTree(
                nnkDotExpr.newTree(
                  newIdentNode("a"),
                  newIdentNode("residue")
                ),
                newIdentNode("limbs")
              ),
              newIdentNode("i")
            ),
            nnkBracketExpr.newTree(
              nnkDotExpr.newTree(
                newIdentNode("b"),
                newIdentNode("limbs")
              ),
              newIdentNode("i")
            )
          )
        )
      )
    )
  ),
  nnkFuncDef.newTree(
    nnkPostfix.newTree(
      newIdentNode("*"),
      nnkAccQuoted.newTree(
        newIdentNode("+=")
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      newEmptyNode(),
      nnkIdentDefs.newTree(
        newIdentNode("a"),
        nnkVarTy.newTree(
          newIdentNode("CubicExt")
        ),
        newEmptyNode()
      ),
      nnkIdentDefs.newTree(
        newIdentNode("b"),
        newIdentNode("CubicExt"),
        newEmptyNode()
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      newCommentStmtNode("Addition in the extension field"),
      nnkCommand.newTree(
        newIdentNode("staticFor"),
        newIdentNode("i"),
        newLit(0),
        nnkDotExpr.newTree(
          nnkDotExpr.newTree(
            newIdentNode("a"),
            newIdentNode("coords")
          ),
          newIdentNode("len")
        ),
        nnkStmtList.newTree(
          nnkInfix.newTree(
            newIdentNode("+="),
            nnkBracketExpr.newTree(
              nnkDotExpr.newTree(
                newIdentNode("a"),
                newIdentNode("coords")
              ),
              newIdentNode("i")
            ),
            nnkBracketExpr.newTree(
              nnkDotExpr.newTree(
                newIdentNode("b"),
                newIdentNode("coords")
              ),
              newIdentNode("i")
            )
          )
        )
      )
    )
  ),
  nnkVarSection.newTree(
    nnkIdentDefs.newTree(
      newIdentNode("a"),
      nnkBracketExpr.newTree(
        newIdentNode("Fp3prj"),
        newIdentNode("BLS12_381")
      ),
      newEmptyNode()
    )
  ),
  nnkCommand.newTree(
    newIdentNode("echo"),
    nnkDotExpr.newTree(
      nnkDotExpr.newTree(
        newIdentNode("a"),
        newIdentNode("coords")
      ),
      newIdentNode("len")
    )
  ),
  nnkCommand.newTree(
    newIdentNode("echo"),
    nnkDotExpr.newTree(
      nnkDotExpr.newTree(
        nnkDotExpr.newTree(
          nnkBracketExpr.newTree(
            nnkDotExpr.newTree(
              newIdentNode("a"),
              newIdentNode("coords")
            ),
            newLit(0)
          ),
          newIdentNode("residue")
        ),
        newIdentNode("limbs")
      ),
      newIdentNode("len")
    )
  ),
  nnkFuncDef.newTree(
    nnkPostfix.newTree(
      newIdentNode("*"),
      nnkAccQuoted.newTree(
        newIdentNode("+=")
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      newEmptyNode(),
      nnkIdentDefs.newTree(
        newIdentNode("a"),
        nnkVarTy.newTree(
          newIdentNode("Fp3prj")
        ),
        newEmptyNode()
      ),
      nnkIdentDefs.newTree(
        newIdentNode("b"),
        newIdentNode("Fp3prj"),
        newEmptyNode()
      )
    ),
    nnkPragma.newTree(
      newIdentNode("borrow")
    ),
    newEmptyNode(),
    newEmptyNode()
  )
)
1.2.18 👎 FAIL

Output

Error: Command failed: nim c --run  -d:nimDebug -d:nimDebugDlOpen -d:ssl -d:nimDisableCertificateValidation --forceBuild:on --colors:off --verbosity:0 --hints:off --lineTrace:off --nimcache:/home/runner/work/Nim/Nim --out:/home/runner/work/Nim/Nim/temp /home/runner/work/Nim/Nim/temp.nim
/home/runner/work/Nim/Nim/temp.nim(53, 3) Error: only a 'distinct' type can borrow `.`

IR

Compiled filesize 0 (0 bytes)

Stats

  • Started 2024-08-16T16:50:11
  • Finished 2024-08-16T16:50:11
  • Duration

AST

nnkStmtList.newTree(
  nnkImportStmt.newTree(
    nnkInfix.newTree(
      newIdentNode("/"),
      newIdentNode("std"),
      newIdentNode("macros")
    )
  ),
  nnkImportStmt.newTree(
    nnkInfix.newTree(
      newIdentNode("/"),
      newIdentNode("std"),
      newIdentNode("bitops")
    )
  ),
  nnkProcDef.newTree(
    newIdentNode("replaceNodes"),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      newIdentNode("NimNode"),
      nnkIdentDefs.newTree(
        newIdentNode("ast"),
        newIdentNode("NimNode"),
        newEmptyNode()
      ),
      nnkIdentDefs.newTree(
        newIdentNode("what"),
        newIdentNode("NimNode"),
        newEmptyNode()
      ),
      nnkIdentDefs.newTree(
        newIdentNode("by"),
        newIdentNode("NimNode"),
        newEmptyNode()
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkProcDef.newTree(
        newIdentNode("inspect"),
        newEmptyNode(),
        newEmptyNode(),
        nnkFormalParams.newTree(
          newIdentNode("NimNode"),
          nnkIdentDefs.newTree(
            newIdentNode("node"),
            newIdentNode("NimNode"),
            newEmptyNode()
          )
        ),
        newEmptyNode(),
        newEmptyNode(),
        nnkStmtList.newTree(
          nnkCaseStmt.newTree(
            nnkDotExpr.newTree(
              newIdentNode("node"),
              newIdentNode("kind")
            ),
            nnkOfBranch.newTree(
              nnkCurly.newTree(
                newIdentNode("nnkIdent"),
                newIdentNode("nnkSym")
              ),
              nnkStmtList.newTree(
                nnkIfStmt.newTree(
                  nnkElifBranch.newTree(
                    nnkCall.newTree(
                      nnkDotExpr.newTree(
                        newIdentNode("node"),
                        newIdentNode("eqIdent")
                      ),
                      newIdentNode("what")
                    ),
                    nnkStmtList.newTree(
                      nnkReturnStmt.newTree(
                        newIdentNode("by")
                      )
                    )
                  )
                ),
                nnkReturnStmt.newTree(
                  newIdentNode("node")
                )
              )
            ),
            nnkOfBranch.newTree(
              newIdentNode("nnkEmpty"),
              nnkStmtList.newTree(
                nnkReturnStmt.newTree(
                  newIdentNode("node")
                )
              )
            ),
            nnkOfBranch.newTree(
              newIdentNode("nnkLiterals"),
              nnkStmtList.newTree(
                nnkReturnStmt.newTree(
                  newIdentNode("node")
                )
              )
            ),
            nnkElse.newTree(
              nnkStmtList.newTree(
                nnkVarSection.newTree(
                  nnkIdentDefs.newTree(
                    newIdentNode("rTree"),
                    newEmptyNode(),
                    nnkCall.newTree(
                      nnkDotExpr.newTree(
                        nnkDotExpr.newTree(
                          newIdentNode("node"),
                          newIdentNode("kind")
                        ),
                        newIdentNode("newTree")
                      )
                    )
                  )
                ),
                nnkForStmt.newTree(
                  newIdentNode("child"),
                  newIdentNode("node"),
                  nnkStmtList.newTree(
                    nnkCommand.newTree(
                      nnkDotExpr.newTree(
                        newIdentNode("rTree"),
                        newIdentNode("add")
                      ),
                      nnkCall.newTree(
                        newIdentNode("inspect"),
                        newIdentNode("child")
                      )
                    )
                  )
                ),
                nnkReturnStmt.newTree(
                  newIdentNode("rTree")
                )
              )
            )
          )
        )
      ),
      nnkAsgn.newTree(
        newIdentNode("result"),
        nnkCall.newTree(
          newIdentNode("inspect"),
          newIdentNode("ast")
        )
      )
    )
  ),
  nnkMacroDef.newTree(
    nnkPostfix.newTree(
      newIdentNode("*"),
      newIdentNode("staticFor")
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      newIdentNode("untyped"),
      nnkIdentDefs.newTree(
        newIdentNode("idx"),
        nnkCurlyExpr.newTree(
          newIdentNode("untyped"),
          newIdentNode("nkIdent")
        ),
        newEmptyNode()
      ),
      nnkIdentDefs.newTree(
        newIdentNode("start"),
        newIdentNode("stopEx"),
        nnkCommand.newTree(
          newIdentNode("static"),
          newIdentNode("int")
        ),
        newEmptyNode()
      ),
      nnkIdentDefs.newTree(
        newIdentNode("body"),
        newIdentNode("untyped"),
        newEmptyNode()
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkAsgn.newTree(
        newIdentNode("result"),
        nnkCall.newTree(
          newIdentNode("newStmtList")
        )
      ),
      nnkForStmt.newTree(
        newIdentNode("i"),
        nnkInfix.newTree(
          newIdentNode("..<"),
          newIdentNode("start"),
          newIdentNode("stopEx")
        ),
        nnkStmtList.newTree(
          nnkCommand.newTree(
            nnkDotExpr.newTree(
              newIdentNode("result"),
              newIdentNode("add")
            ),
            nnkCall.newTree(
              nnkDotExpr.newTree(
                newIdentNode("nnkBlockStmt"),
                newIdentNode("newTree")
              ),
              nnkCall.newTree(
                newIdentNode("ident"),
                nnkInfix.newTree(
                  newIdentNode("&"),
                  nnkInfix.newTree(
                    newIdentNode("&"),
                    newLit("unrolledIter_"),
                    nnkPrefix.newTree(
                      newIdentNode("$"),
                      newIdentNode("idx")
                    )
                  ),
                  nnkPrefix.newTree(
                    newIdentNode("$"),
                    newIdentNode("i")
                  )
                )
              ),
              nnkCall.newTree(
                nnkDotExpr.newTree(
                  newIdentNode("body"),
                  newIdentNode("replaceNodes")
                ),
                newIdentNode("idx"),
                nnkCommand.newTree(
                  newIdentNode("newLit"),
                  newIdentNode("i")
                )
              )
            )
          )
        )
      )
    )
  ),
  nnkTypeSection.newTree(
    nnkTypeDef.newTree(
      newIdentNode("Curve"),
      newEmptyNode(),
      nnkEnumTy.newTree(
        newEmptyNode(),
        newIdentNode("BLS12_381")
      )
    )
  ),
  nnkConstSection.newTree(
    nnkConstDef.newTree(
      nnkPostfix.newTree(
        newIdentNode("*"),
        newIdentNode("WordBitWidth")
      ),
      newEmptyNode(),
      nnkInfix.newTree(
        newIdentNode("*"),
        nnkCall.newTree(
          newIdentNode("sizeof"),
          newIdentNode("uint64")
        ),
        newLit(8)
      )
    )
  ),
  nnkFuncDef.newTree(
    nnkPostfix.newTree(
      newIdentNode("*"),
      newIdentNode("wordsRequired")
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      newIdentNode("int"),
      nnkIdentDefs.newTree(
        newIdentNode("bits"),
        newIdentNode("int"),
        newEmptyNode()
      )
    ),
    nnkPragma.newTree(
      newIdentNode("inline")
    ),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkConstSection.newTree(
        nnkConstDef.newTree(
          newIdentNode("divShiftor"),
          newEmptyNode(),
          nnkCall.newTree(
            newIdentNode("fastLog2"),
            newIdentNode("WordBitWidth")
          )
        )
      ),
      nnkAsgn.newTree(
        newIdentNode("result"),
        nnkInfix.newTree(
          newIdentNode("shr"),
          nnkPar.newTree(
            nnkInfix.newTree(
              newIdentNode("-"),
              nnkInfix.newTree(
                newIdentNode("+"),
                newIdentNode("bits"),
                newIdentNode("WordBitWidth")
              ),
              newLit(1)
            )
          ),
          newIdentNode("divShiftor")
        )
      )
    )
  ),
  nnkTypeSection.newTree(
    nnkTypeDef.newTree(
      nnkPostfix.newTree(
        newIdentNode("*"),
        newIdentNode("BigInt")
      ),
      nnkGenericParams.newTree(
        nnkIdentDefs.newTree(
          newIdentNode("bits"),
          nnkCommand.newTree(
            newIdentNode("static"),
            newIdentNode("int")
          ),
          newEmptyNode()
        )
      ),
      nnkObjectTy.newTree(
        newEmptyNode(),
        newEmptyNode(),
        nnkRecList.newTree(
          nnkIdentDefs.newTree(
            nnkPostfix.newTree(
              newIdentNode("*"),
              newIdentNode("limbs")
            ),
            nnkBracketExpr.newTree(
              newIdentNode("array"),
              nnkDotExpr.newTree(
                newIdentNode("bits"),
                newIdentNode("wordsRequired")
              ),
              newIdentNode("uint64")
            ),
            newEmptyNode()
          )
        )
      )
    )
  ),
  nnkConstSection.newTree(
    nnkConstDef.newTree(
      newIdentNode("CurveBitWidth"),
      newEmptyNode(),
      nnkBracket.newTree(
        nnkExprColonExpr.newTree(
          newIdentNode("BLS12_381"),
          newLit(381)
        )
      )
    )
  ),
  nnkTemplateDef.newTree(
    nnkPostfix.newTree(
      newIdentNode("*"),
      newIdentNode("matchingBigInt")
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      newIdentNode("untyped"),
      nnkIdentDefs.newTree(
        newIdentNode("Name"),
        nnkCommand.newTree(
          newIdentNode("static"),
          newIdentNode("Curve")
        ),
        newEmptyNode()
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      newCommentStmtNode("BigInt type necessary to store the prime field Fp"),
      nnkBracketExpr.newTree(
        newIdentNode("BigInt"),
        nnkBracketExpr.newTree(
          newIdentNode("CurveBitWidth"),
          newIdentNode("Name")
        )
      )
    )
  ),
  nnkTypeSection.newTree(
    nnkTypeDef.newTree(
      newIdentNode("Fp"),
      nnkGenericParams.newTree(
        nnkIdentDefs.newTree(
          newIdentNode("C"),
          nnkCommand.newTree(
            newIdentNode("static"),
            newIdentNode("Curve")
          ),
          newEmptyNode()
        )
      ),
      nnkObjectTy.newTree(
        newEmptyNode(),
        newEmptyNode(),
        nnkRecList.newTree(
          nnkIdentDefs.newTree(
            newIdentNode("residue"),
            nnkCall.newTree(
              newIdentNode("matchingBigInt"),
              newIdentNode("C")
            ),
            newEmptyNode()
          )
        )
      )
    )
  ),
  nnkTypeSection.newTree(
    nnkTypeDef.newTree(
      nnkPostfix.newTree(
        newIdentNode("*"),
        newIdentNode("CubicExt")
      ),
      nnkGenericParams.newTree(
        nnkIdentDefs.newTree(
          newIdentNode("F"),
          newEmptyNode(),
          newEmptyNode()
        )
      ),
      nnkObjectTy.newTree(
        newEmptyNode(),
        newEmptyNode(),
        nnkRecList.newTree(
          nnkIdentDefs.newTree(
            nnkPostfix.newTree(
              newIdentNode("*"),
              newIdentNode("coords")
            ),
            nnkBracketExpr.newTree(
              newIdentNode("array"),
              newLit(3),
              newIdentNode("F")
            ),
            newEmptyNode()
          )
        )
      )
    ),
    nnkTypeDef.newTree(
      newIdentNode("Fp3"),
      nnkGenericParams.newTree(
        nnkIdentDefs.newTree(
          newIdentNode("C"),
          nnkCommand.newTree(
            newIdentNode("static"),
            newIdentNode("Curve")
          ),
          newEmptyNode()
        )
      ),
      nnkBracketExpr.newTree(
        newIdentNode("CubicExt"),
        nnkBracketExpr.newTree(
          newIdentNode("Fp"),
          newIdentNode("C")
        )
      )
    )
  ),
  nnkTypeSection.newTree(
    nnkTypeDef.newTree(
      nnkPragmaExpr.newTree(
        newIdentNode("Fp3prj"),
        nnkPragma.newTree(
          nnkExprColonExpr.newTree(
            newIdentNode("borrow"),
            nnkAccQuoted.newTree(
              newIdentNode(".")
            )
          )
        )
      ),
      nnkGenericParams.newTree(
        nnkIdentDefs.newTree(
          newIdentNode("C"),
          nnkCommand.newTree(
            newIdentNode("static"),
            newIdentNode("Curve")
          ),
          newEmptyNode()
        )
      ),
      nnkDistinctTy.newTree(
        nnkBracketExpr.newTree(
          newIdentNode("Fp3"),
          newIdentNode("C")
        )
      )
    )
  ),
  nnkFuncDef.newTree(
    nnkPostfix.newTree(
      newIdentNode("*"),
      nnkAccQuoted.newTree(
        newIdentNode("+=")
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      newEmptyNode(),
      nnkIdentDefs.newTree(
        newIdentNode("a"),
        nnkVarTy.newTree(
          newIdentNode("Fp")
        ),
        newEmptyNode()
      ),
      nnkIdentDefs.newTree(
        newIdentNode("b"),
        newIdentNode("Fp"),
        newEmptyNode()
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkForStmt.newTree(
        newIdentNode("i"),
        nnkInfix.newTree(
          newIdentNode("..<"),
          newLit(0),
          nnkDotExpr.newTree(
            nnkDotExpr.newTree(
              nnkDotExpr.newTree(
                newIdentNode("a"),
                newIdentNode("residue")
              ),
              newIdentNode("limbs")
            ),
            newIdentNode("len")
          )
        ),
        nnkStmtList.newTree(
          nnkInfix.newTree(
            newIdentNode("+="),
            nnkBracketExpr.newTree(
              nnkDotExpr.newTree(
                nnkDotExpr.newTree(
                  newIdentNode("a"),
                  newIdentNode("residue")
                ),
                newIdentNode("limbs")
              ),
              newIdentNode("i")
            ),
            nnkBracketExpr.newTree(
              nnkDotExpr.newTree(
                newIdentNode("b"),
                newIdentNode("limbs")
              ),
              newIdentNode("i")
            )
          )
        )
      )
    )
  ),
  nnkFuncDef.newTree(
    nnkPostfix.newTree(
      newIdentNode("*"),
      nnkAccQuoted.newTree(
        newIdentNode("+=")
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      newEmptyNode(),
      nnkIdentDefs.newTree(
        newIdentNode("a"),
        nnkVarTy.newTree(
          newIdentNode("CubicExt")
        ),
        newEmptyNode()
      ),
      nnkIdentDefs.newTree(
        newIdentNode("b"),
        newIdentNode("CubicExt"),
        newEmptyNode()
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      newCommentStmtNode("Addition in the extension field"),
      nnkCommand.newTree(
        newIdentNode("staticFor"),
        newIdentNode("i"),
        newLit(0),
        nnkDotExpr.newTree(
          nnkDotExpr.newTree(
            newIdentNode("a"),
            newIdentNode("coords")
          ),
          newIdentNode("len")
        ),
        nnkStmtList.newTree(
          nnkInfix.newTree(
            newIdentNode("+="),
            nnkBracketExpr.newTree(
              nnkDotExpr.newTree(
                newIdentNode("a"),
                newIdentNode("coords")
              ),
              newIdentNode("i")
            ),
            nnkBracketExpr.newTree(
              nnkDotExpr.newTree(
                newIdentNode("b"),
                newIdentNode("coords")
              ),
              newIdentNode("i")
            )
          )
        )
      )
    )
  ),
  nnkVarSection.newTree(
    nnkIdentDefs.newTree(
      newIdentNode("a"),
      nnkBracketExpr.newTree(
        newIdentNode("Fp3prj"),
        newIdentNode("BLS12_381")
      ),
      newEmptyNode()
    )
  ),
  nnkCommand.newTree(
    newIdentNode("echo"),
    nnkDotExpr.newTree(
      nnkDotExpr.newTree(
        newIdentNode("a"),
        newIdentNode("coords")
      ),
      newIdentNode("len")
    )
  ),
  nnkCommand.newTree(
    newIdentNode("echo"),
    nnkDotExpr.newTree(
      nnkDotExpr.newTree(
        nnkDotExpr.newTree(
          nnkBracketExpr.newTree(
            nnkDotExpr.newTree(
              newIdentNode("a"),
              newIdentNode("coords")
            ),
            newLit(0)
          ),
          newIdentNode("residue")
        ),
        newIdentNode("limbs")
      ),
      newIdentNode("len")
    )
  ),
  nnkFuncDef.newTree(
    nnkPostfix.newTree(
      newIdentNode("*"),
      nnkAccQuoted.newTree(
        newIdentNode("+=")
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      newEmptyNode(),
      nnkIdentDefs.newTree(
        newIdentNode("a"),
        nnkVarTy.newTree(
          newIdentNode("Fp3prj")
        ),
        newEmptyNode()
      ),
      nnkIdentDefs.newTree(
        newIdentNode("b"),
        newIdentNode("Fp3prj"),
        newEmptyNode()
      )
    ),
    nnkPragma.newTree(
      newIdentNode("borrow")
    ),
    newEmptyNode(),
    newEmptyNode()
  )
)
1.0.10 👎 FAIL

Output

Error: Command failed: nim c --run  -d:nimDebug -d:nimDebugDlOpen -d:ssl -d:nimDisableCertificateValidation --forceBuild:on --colors:off --verbosity:0 --hints:off --lineTrace:off --nimcache:/home/runner/work/Nim/Nim --out:/home/runner/work/Nim/Nim/temp /home/runner/work/Nim/Nim/temp.nim
/home/runner/work/Nim/Nim/temp.nim(53, 3) Error: only a 'distinct' type can borrow `.`

IR

Compiled filesize 0 (0 bytes)

Stats

  • Started 2024-08-16T16:50:13
  • Finished 2024-08-16T16:50:13
  • Duration

AST

nnkStmtList.newTree(
  nnkImportStmt.newTree(
    nnkInfix.newTree(
      newIdentNode("/"),
      newIdentNode("std"),
      newIdentNode("macros")
    )
  ),
  nnkImportStmt.newTree(
    nnkInfix.newTree(
      newIdentNode("/"),
      newIdentNode("std"),
      newIdentNode("bitops")
    )
  ),
  nnkProcDef.newTree(
    newIdentNode("replaceNodes"),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      newIdentNode("NimNode"),
      nnkIdentDefs.newTree(
        newIdentNode("ast"),
        newIdentNode("NimNode"),
        newEmptyNode()
      ),
      nnkIdentDefs.newTree(
        newIdentNode("what"),
        newIdentNode("NimNode"),
        newEmptyNode()
      ),
      nnkIdentDefs.newTree(
        newIdentNode("by"),
        newIdentNode("NimNode"),
        newEmptyNode()
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkProcDef.newTree(
        newIdentNode("inspect"),
        newEmptyNode(),
        newEmptyNode(),
        nnkFormalParams.newTree(
          newIdentNode("NimNode"),
          nnkIdentDefs.newTree(
            newIdentNode("node"),
            newIdentNode("NimNode"),
            newEmptyNode()
          )
        ),
        newEmptyNode(),
        newEmptyNode(),
        nnkStmtList.newTree(
          nnkCaseStmt.newTree(
            nnkDotExpr.newTree(
              newIdentNode("node"),
              newIdentNode("kind")
            ),
            nnkOfBranch.newTree(
              nnkCurly.newTree(
                newIdentNode("nnkIdent"),
                newIdentNode("nnkSym")
              ),
              nnkStmtList.newTree(
                nnkIfStmt.newTree(
                  nnkElifBranch.newTree(
                    nnkCall.newTree(
                      nnkDotExpr.newTree(
                        newIdentNode("node"),
                        newIdentNode("eqIdent")
                      ),
                      newIdentNode("what")
                    ),
                    nnkStmtList.newTree(
                      nnkReturnStmt.newTree(
                        newIdentNode("by")
                      )
                    )
                  )
                ),
                nnkReturnStmt.newTree(
                  newIdentNode("node")
                )
              )
            ),
            nnkOfBranch.newTree(
              newIdentNode("nnkEmpty"),
              nnkStmtList.newTree(
                nnkReturnStmt.newTree(
                  newIdentNode("node")
                )
              )
            ),
            nnkOfBranch.newTree(
              newIdentNode("nnkLiterals"),
              nnkStmtList.newTree(
                nnkReturnStmt.newTree(
                  newIdentNode("node")
                )
              )
            ),
            nnkElse.newTree(
              nnkStmtList.newTree(
                nnkVarSection.newTree(
                  nnkIdentDefs.newTree(
                    newIdentNode("rTree"),
                    newEmptyNode(),
                    nnkCall.newTree(
                      nnkDotExpr.newTree(
                        nnkDotExpr.newTree(
                          newIdentNode("node"),
                          newIdentNode("kind")
                        ),
                        newIdentNode("newTree")
                      )
                    )
                  )
                ),
                nnkForStmt.newTree(
                  newIdentNode("child"),
                  newIdentNode("node"),
                  nnkStmtList.newTree(
                    nnkCommand.newTree(
                      nnkDotExpr.newTree(
                        newIdentNode("rTree"),
                        newIdentNode("add")
                      ),
                      nnkCall.newTree(
                        newIdentNode("inspect"),
                        newIdentNode("child")
                      )
                    )
                  )
                ),
                nnkReturnStmt.newTree(
                  newIdentNode("rTree")
                )
              )
            )
          )
        )
      ),
      nnkAsgn.newTree(
        newIdentNode("result"),
        nnkCall.newTree(
          newIdentNode("inspect"),
          newIdentNode("ast")
        )
      )
    )
  ),
  nnkMacroDef.newTree(
    nnkPostfix.newTree(
      newIdentNode("*"),
      newIdentNode("staticFor")
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      newIdentNode("untyped"),
      nnkIdentDefs.newTree(
        newIdentNode("idx"),
        nnkCurlyExpr.newTree(
          newIdentNode("untyped"),
          newIdentNode("nkIdent")
        ),
        newEmptyNode()
      ),
      nnkIdentDefs.newTree(
        newIdentNode("start"),
        newIdentNode("stopEx"),
        nnkCommand.newTree(
          newIdentNode("static"),
          newIdentNode("int")
        ),
        newEmptyNode()
      ),
      nnkIdentDefs.newTree(
        newIdentNode("body"),
        newIdentNode("untyped"),
        newEmptyNode()
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkAsgn.newTree(
        newIdentNode("result"),
        nnkCall.newTree(
          newIdentNode("newStmtList")
        )
      ),
      nnkForStmt.newTree(
        newIdentNode("i"),
        nnkInfix.newTree(
          newIdentNode("..<"),
          newIdentNode("start"),
          newIdentNode("stopEx")
        ),
        nnkStmtList.newTree(
          nnkCommand.newTree(
            nnkDotExpr.newTree(
              newIdentNode("result"),
              newIdentNode("add")
            ),
            nnkCall.newTree(
              nnkDotExpr.newTree(
                newIdentNode("nnkBlockStmt"),
                newIdentNode("newTree")
              ),
              nnkCall.newTree(
                newIdentNode("ident"),
                nnkInfix.newTree(
                  newIdentNode("&"),
                  nnkInfix.newTree(
                    newIdentNode("&"),
                    newLit("unrolledIter_"),
                    nnkPrefix.newTree(
                      newIdentNode("$"),
                      newIdentNode("idx")
                    )
                  ),
                  nnkPrefix.newTree(
                    newIdentNode("$"),
                    newIdentNode("i")
                  )
                )
              ),
              nnkCall.newTree(
                nnkDotExpr.newTree(
                  newIdentNode("body"),
                  newIdentNode("replaceNodes")
                ),
                newIdentNode("idx"),
                nnkCommand.newTree(
                  newIdentNode("newLit"),
                  newIdentNode("i")
                )
              )
            )
          )
        )
      )
    )
  ),
  nnkTypeSection.newTree(
    nnkTypeDef.newTree(
      newIdentNode("Curve"),
      newEmptyNode(),
      nnkEnumTy.newTree(
        newEmptyNode(),
        newIdentNode("BLS12_381")
      )
    )
  ),
  nnkConstSection.newTree(
    nnkConstDef.newTree(
      nnkPostfix.newTree(
        newIdentNode("*"),
        newIdentNode("WordBitWidth")
      ),
      newEmptyNode(),
      nnkInfix.newTree(
        newIdentNode("*"),
        nnkCall.newTree(
          newIdentNode("sizeof"),
          newIdentNode("uint64")
        ),
        newLit(8)
      )
    )
  ),
  nnkFuncDef.newTree(
    nnkPostfix.newTree(
      newIdentNode("*"),
      newIdentNode("wordsRequired")
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      newIdentNode("int"),
      nnkIdentDefs.newTree(
        newIdentNode("bits"),
        newIdentNode("int"),
        newEmptyNode()
      )
    ),
    nnkPragma.newTree(
      newIdentNode("inline")
    ),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkConstSection.newTree(
        nnkConstDef.newTree(
          newIdentNode("divShiftor"),
          newEmptyNode(),
          nnkCall.newTree(
            newIdentNode("fastLog2"),
            newIdentNode("WordBitWidth")
          )
        )
      ),
      nnkAsgn.newTree(
        newIdentNode("result"),
        nnkInfix.newTree(
          newIdentNode("shr"),
          nnkPar.newTree(
            nnkInfix.newTree(
              newIdentNode("-"),
              nnkInfix.newTree(
                newIdentNode("+"),
                newIdentNode("bits"),
                newIdentNode("WordBitWidth")
              ),
              newLit(1)
            )
          ),
          newIdentNode("divShiftor")
        )
      )
    )
  ),
  nnkTypeSection.newTree(
    nnkTypeDef.newTree(
      nnkPostfix.newTree(
        newIdentNode("*"),
        newIdentNode("BigInt")
      ),
      nnkGenericParams.newTree(
        nnkIdentDefs.newTree(
          newIdentNode("bits"),
          nnkCommand.newTree(
            newIdentNode("static"),
            newIdentNode("int")
          ),
          newEmptyNode()
        )
      ),
      nnkObjectTy.newTree(
        newEmptyNode(),
        newEmptyNode(),
        nnkRecList.newTree(
          nnkIdentDefs.newTree(
            nnkPostfix.newTree(
              newIdentNode("*"),
              newIdentNode("limbs")
            ),
            nnkBracketExpr.newTree(
              newIdentNode("array"),
              nnkDotExpr.newTree(
                newIdentNode("bits"),
                newIdentNode("wordsRequired")
              ),
              newIdentNode("uint64")
            ),
            newEmptyNode()
          )
        )
      )
    )
  ),
  nnkConstSection.newTree(
    nnkConstDef.newTree(
      newIdentNode("CurveBitWidth"),
      newEmptyNode(),
      nnkBracket.newTree(
        nnkExprColonExpr.newTree(
          newIdentNode("BLS12_381"),
          newLit(381)
        )
      )
    )
  ),
  nnkTemplateDef.newTree(
    nnkPostfix.newTree(
      newIdentNode("*"),
      newIdentNode("matchingBigInt")
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      newIdentNode("untyped"),
      nnkIdentDefs.newTree(
        newIdentNode("Name"),
        nnkCommand.newTree(
          newIdentNode("static"),
          newIdentNode("Curve")
        ),
        newEmptyNode()
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      newCommentStmtNode("BigInt type necessary to store the prime field Fp"),
      nnkBracketExpr.newTree(
        newIdentNode("BigInt"),
        nnkBracketExpr.newTree(
          newIdentNode("CurveBitWidth"),
          newIdentNode("Name")
        )
      )
    )
  ),
  nnkTypeSection.newTree(
    nnkTypeDef.newTree(
      newIdentNode("Fp"),
      nnkGenericParams.newTree(
        nnkIdentDefs.newTree(
          newIdentNode("C"),
          nnkCommand.newTree(
            newIdentNode("static"),
            newIdentNode("Curve")
          ),
          newEmptyNode()
        )
      ),
      nnkObjectTy.newTree(
        newEmptyNode(),
        newEmptyNode(),
        nnkRecList.newTree(
          nnkIdentDefs.newTree(
            newIdentNode("residue"),
            nnkCall.newTree(
              newIdentNode("matchingBigInt"),
              newIdentNode("C")
            ),
            newEmptyNode()
          )
        )
      )
    )
  ),
  nnkTypeSection.newTree(
    nnkTypeDef.newTree(
      nnkPostfix.newTree(
        newIdentNode("*"),
        newIdentNode("CubicExt")
      ),
      nnkGenericParams.newTree(
        nnkIdentDefs.newTree(
          newIdentNode("F"),
          newEmptyNode(),
          newEmptyNode()
        )
      ),
      nnkObjectTy.newTree(
        newEmptyNode(),
        newEmptyNode(),
        nnkRecList.newTree(
          nnkIdentDefs.newTree(
            nnkPostfix.newTree(
              newIdentNode("*"),
              newIdentNode("coords")
            ),
            nnkBracketExpr.newTree(
              newIdentNode("array"),
              newLit(3),
              newIdentNode("F")
            ),
            newEmptyNode()
          )
        )
      )
    ),
    nnkTypeDef.newTree(
      newIdentNode("Fp3"),
      nnkGenericParams.newTree(
        nnkIdentDefs.newTree(
          newIdentNode("C"),
          nnkCommand.newTree(
            newIdentNode("static"),
            newIdentNode("Curve")
          ),
          newEmptyNode()
        )
      ),
      nnkBracketExpr.newTree(
        newIdentNode("CubicExt"),
        nnkBracketExpr.newTree(
          newIdentNode("Fp"),
          newIdentNode("C")
        )
      )
    )
  ),
  nnkTypeSection.newTree(
    nnkTypeDef.newTree(
      nnkPragmaExpr.newTree(
        newIdentNode("Fp3prj"),
        nnkPragma.newTree(
          nnkExprColonExpr.newTree(
            newIdentNode("borrow"),
            nnkAccQuoted.newTree(
              newIdentNode(".")
            )
          )
        )
      ),
      nnkGenericParams.newTree(
        nnkIdentDefs.newTree(
          newIdentNode("C"),
          nnkCommand.newTree(
            newIdentNode("static"),
            newIdentNode("Curve")
          ),
          newEmptyNode()
        )
      ),
      nnkDistinctTy.newTree(
        nnkBracketExpr.newTree(
          newIdentNode("Fp3"),
          newIdentNode("C")
        )
      )
    )
  ),
  nnkFuncDef.newTree(
    nnkPostfix.newTree(
      newIdentNode("*"),
      nnkAccQuoted.newTree(
        newIdentNode("+=")
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      newEmptyNode(),
      nnkIdentDefs.newTree(
        newIdentNode("a"),
        nnkVarTy.newTree(
          newIdentNode("Fp")
        ),
        newEmptyNode()
      ),
      nnkIdentDefs.newTree(
        newIdentNode("b"),
        newIdentNode("Fp"),
        newEmptyNode()
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkForStmt.newTree(
        newIdentNode("i"),
        nnkInfix.newTree(
          newIdentNode("..<"),
          newLit(0),
          nnkDotExpr.newTree(
            nnkDotExpr.newTree(
              nnkDotExpr.newTree(
                newIdentNode("a"),
                newIdentNode("residue")
              ),
              newIdentNode("limbs")
            ),
            newIdentNode("len")
          )
        ),
        nnkStmtList.newTree(
          nnkInfix.newTree(
            newIdentNode("+="),
            nnkBracketExpr.newTree(
              nnkDotExpr.newTree(
                nnkDotExpr.newTree(
                  newIdentNode("a"),
                  newIdentNode("residue")
                ),
                newIdentNode("limbs")
              ),
              newIdentNode("i")
            ),
            nnkBracketExpr.newTree(
              nnkDotExpr.newTree(
                newIdentNode("b"),
                newIdentNode("limbs")
              ),
              newIdentNode("i")
            )
          )
        )
      )
    )
  ),
  nnkFuncDef.newTree(
    nnkPostfix.newTree(
      newIdentNode("*"),
      nnkAccQuoted.newTree(
        newIdentNode("+=")
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      newEmptyNode(),
      nnkIdentDefs.newTree(
        newIdentNode("a"),
        nnkVarTy.newTree(
          newIdentNode("CubicExt")
        ),
        newEmptyNode()
      ),
      nnkIdentDefs.newTree(
        newIdentNode("b"),
        newIdentNode("CubicExt"),
        newEmptyNode()
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      newCommentStmtNode("Addition in the extension field"),
      nnkCommand.newTree(
        newIdentNode("staticFor"),
        newIdentNode("i"),
        newLit(0),
        nnkDotExpr.newTree(
          nnkDotExpr.newTree(
            newIdentNode("a"),
            newIdentNode("coords")
          ),
          newIdentNode("len")
        ),
        nnkStmtList.newTree(
          nnkInfix.newTree(
            newIdentNode("+="),
            nnkBracketExpr.newTree(
              nnkDotExpr.newTree(
                newIdentNode("a"),
                newIdentNode("coords")
              ),
              newIdentNode("i")
            ),
            nnkBracketExpr.newTree(
              nnkDotExpr.newTree(
                newIdentNode("b"),
                newIdentNode("coords")
              ),
              newIdentNode("i")
            )
          )
        )
      )
    )
  ),
  nnkVarSection.newTree(
    nnkIdentDefs.newTree(
      newIdentNode("a"),
      nnkBracketExpr.newTree(
        newIdentNode("Fp3prj"),
        newIdentNode("BLS12_381")
      ),
      newEmptyNode()
    )
  ),
  nnkCommand.newTree(
    newIdentNode("echo"),
    nnkDotExpr.newTree(
      nnkDotExpr.newTree(
        newIdentNode("a"),
        newIdentNode("coords")
      ),
      newIdentNode("len")
    )
  ),
  nnkCommand.newTree(
    newIdentNode("echo"),
    nnkDotExpr.newTree(
      nnkDotExpr.newTree(
        nnkDotExpr.newTree(
          nnkBracketExpr.newTree(
            nnkDotExpr.newTree(
              newIdentNode("a"),
              newIdentNode("coords")
            ),
            newLit(0)
          ),
          newIdentNode("residue")
        ),
        newIdentNode("limbs")
      ),
      newIdentNode("len")
    )
  ),
  nnkFuncDef.newTree(
    nnkPostfix.newTree(
      newIdentNode("*"),
      nnkAccQuoted.newTree(
        newIdentNode("+=")
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      newEmptyNode(),
      nnkIdentDefs.newTree(
        newIdentNode("a"),
        nnkVarTy.newTree(
          newIdentNode("Fp3prj")
        ),
        newEmptyNode()
      ),
      nnkIdentDefs.newTree(
        newIdentNode("b"),
        newIdentNode("Fp3prj"),
        newEmptyNode()
      )
    ),
    nnkPragma.newTree(
      newIdentNode("borrow")
    ),
    newEmptyNode(),
    newEmptyNode()
  )
)
Stats
  • GCC 11.4.0
  • Clang 14.0.0
  • NodeJS 20.4
  • Created 2024-08-16T16:49:28Z
  • Comments 1
  • Commands nim c --run -d:nimDebug -d:nimDebugDlOpen -d:ssl -d:nimDisableCertificateValidation --forceBuild:on --colors:off --verbosity:0 --hints:off --lineTrace:off --nimcache:/home/runner/work/Nim/Nim --out:/home/runner/work/Nim/Nim/temp /home/runner/work/Nim/Nim/temp.nim

🤖 Bug found in 24 minutes bisecting 8 commits at 0 commits per second

@juancarlospaco
Copy link
Collaborator

It says "Error: only a 'distinct' type can borrow '.'" 🤔

@metagn
Copy link
Collaborator

metagn commented Sep 11, 2024

Simplified (may be more issues in full test case)

template matchingBigInt(Name: static int): untyped = int

type
  Fp3[C: static int] = object
    residue: matchingBigInt(C)

  Fp3prj[C: static int] = distinct Fp3[C]

func `+=`(a: var Fp3, b: Fp3) = discard

func `+=`(a: var Fp3prj, b: Fp3prj) {.borrow.}

@mratsim
Copy link
Collaborator Author

mratsim commented Sep 25, 2024

@juancarlospaco before 1.6 generics didn't work at all with distinct borrows.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants