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

Semi-regression (?): generic typeclass not matching #23547

Closed
mratsim opened this issue Apr 29, 2024 · 7 comments · Fixed by #23852
Closed

Semi-regression (?): generic typeclass not matching #23547

mratsim opened this issue Apr 29, 2024 · 7 comments · Fixed by #23852

Comments

@mratsim
Copy link
Collaborator

mratsim commented Apr 29, 2024

Original issue: mratsim/constantine#373

It can be reproduced in its full environment with:

git clone https://github.com/mratsim/constantine
cd constantine
git checkout 976c8bb
nim c --verbosity:0 --hints:off --warnings:off --outdir:build tests/t_hash_to_curve_random.nim

In the original issue, Nim v2.0.4 works but latest version-2-0 branch (v2.0.5) doesn't.

Now here is a single file reproduction. Surprisingly this fails on both Nim v2.0.4 and latest version-2-0

type BigInt[N: static int] = object
  raw: array[N, uint64]

func isZero(a: BigInt): bool =
  discard

func isOne(a: BigInt): bool =
  discard

type
  QuadraticExt*[F] = object
    ## Quadratic Extension field
    coords*: array[2, F]

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

  ExtensionField*[F] = QuadraticExt[F] or CubicExt[F]

func isOne*(a: ExtensionField): bool =
  ## Constant-time check if one
  result = 1'u64
  result = result and a.coords[0].isOne()
  for i in 1 ..< a.coords.len:
    result = result and a.coords[i].isZero()

func mulCheckSparse*(a: var QuadraticExt, b: static QuadraticExt) {.inline.} =
  static:
    debugEcho "QuadraticExt b: ", b is QuadraticExt      # This is true
    debugEcho "ExtensionField b: ", b is ExtensionField  # This is false
  when isOne(b).bool:
    discard
  else:
    debugEcho "a *= b"

type EllipticCurve*[F] = object
  x*, y*, z*: F

template sumImpl[F](
       r: var EllipticCurve[F],
       P, Q: EllipticCurve[F],
       CoefA: typed) {.dirty.} =
  when CoefA is int:
    debugEcho "EC addition with int CoefA"
  else:
    var b = P.x
    b.mulCheckSparse(CoefA)

func sum[F](
       r: var EllipticCurve[F],
       P, Q: EllipticCurve[F],
       CoefA: static F) =
  r.sumImpl(P, Q, CoefA)

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

const h2c_const_ec = QuadraticExt[BigInt[4]](
    coords: [BigInt[4](raw: [uint64 1, 1, 1, 1]),
             BigInt[4](raw: [uint64 1, 1, 1, 1])]
  )

var P = EllipticCurve[QuadraticExt[BigInt[4]]](
  x: QuadraticExt[BigInt[4]](
    coords: [BigInt[4](raw: [uint64 1, 2, 3, 4]),
             BigInt[4](raw: [uint64 1, 2, 3, 4])]
  ),
  y: QuadraticExt[BigInt[4]](
    coords: [BigInt[4](raw: [uint64 1, 2, 3, 4]),
             BigInt[4](raw: [uint64 1, 2, 3, 4])]
  ),
  z: QuadraticExt[BigInt[4]](
    coords: [BigInt[4](raw: [uint64 1, 2, 3, 4]),
             BigInt[4](raw: [uint64 1, 2, 3, 4])]
  )
)
var Q = EllipticCurve[QuadraticExt[BigInt[4]]](
  x: QuadraticExt[BigInt[4]](
    coords: [BigInt[4](raw: [uint64 1, 2, 3, 4]),
             BigInt[4](raw: [uint64 1, 2, 3, 4])]
  ),
  y: QuadraticExt[BigInt[4]](
    coords: [BigInt[4](raw: [uint64 1, 2, 3, 4]),
             BigInt[4](raw: [uint64 1, 2, 3, 4])]
  ),
  z: QuadraticExt[BigInt[4]](
    coords: [BigInt[4](raw: [uint64 1, 2, 3, 4]),
             BigInt[4](raw: [uint64 1, 2, 3, 4])]
  )
)

var R: EllipticCurve[QuadraticExt[BigInt[4]]]

R.sum(P, Q, h2c_const_ec)
nim c --verbosity:0 --hints:off --warnings:off --outdir:build build/t_regression_mul_sparse.nim
QuadraticExt b: true
ExtensionField b: false
/[...]/constantine/build/t_regression_mul_sparse.nim(94, 2) template/generic instantiation of `sum` from here
/[...]/constantine/build/t_regression_mul_sparse.nim(54, 4) template/generic instantiation of `sumImpl` from here
/[...]/constantine/build/t_regression_mul_sparse.nim(48, 6) template/generic instantiation of `mulCheckSparse` from here
/[...]/constantine/build/t_regression_mul_sparse.nim(32, 13) Error: type mismatch
Expression: isOne((coords: [(raw: [1'u, 1'u, 1'u, 1'u]), (raw: [1'u, 1'u, 1'u, 1'u])]))
  [1] (coords: [(raw: [1'u, 1'u, 1'u, 1'u]), (raw: [1'u, 1'u, 1'u, 1'u])]): QuadraticExt

Expected one of (first mismatch at [position]):
[1] func isOne(a: BigInt): bool
[1] func isOne(a: ExtensionField): bool
@ringabout
Copy link
Member

!nim c

type BigInt[N: static int] = object
  raw: array[N, uint64]

func isZero(a: BigInt): bool =
  discard

func isOne(a: BigInt): bool =
  discard

type
  QuadraticExt*[F] = object
    ## Quadratic Extension field
    coords*: array[2, F]

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

  ExtensionField*[F] = QuadraticExt[F] or CubicExt[F]

func isOne*(a: ExtensionField): bool =
  ## Constant-time check if one
  result = 1'u64
  result = result and a.coords[0].isOne()
  for i in 1 ..< a.coords.len:
    result = result and a.coords[i].isZero()

func mulCheckSparse*(a: var QuadraticExt, b: static QuadraticExt) {.inline.} =
  static:
    debugEcho "QuadraticExt b: ", b is QuadraticExt      # This is true
    debugEcho "ExtensionField b: ", b is ExtensionField  # This is false
  when isOne(b).bool:
    discard
  else:
    debugEcho "a *= b"

type EllipticCurve*[F] = object
  x*, y*, z*: F

template sumImpl[F](
       r: var EllipticCurve[F],
       P, Q: EllipticCurve[F],
       CoefA: typed) {.dirty.} =
  when CoefA is int:
    debugEcho "EC addition with int CoefA"
  else:
    var b = P.x
    b.mulCheckSparse(CoefA)

func sum[F](
       r: var EllipticCurve[F],
       P, Q: EllipticCurve[F],
       CoefA: static F) =
  r.sumImpl(P, Q, CoefA)

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

const h2c_const_ec = QuadraticExt[BigInt[4]](
    coords: [BigInt[4](raw: [uint64 1, 1, 1, 1]),
             BigInt[4](raw: [uint64 1, 1, 1, 1])]
  )

var P = EllipticCurve[QuadraticExt[BigInt[4]]](
  x: QuadraticExt[BigInt[4]](
    coords: [BigInt[4](raw: [uint64 1, 2, 3, 4]),
             BigInt[4](raw: [uint64 1, 2, 3, 4])]
  ),
  y: QuadraticExt[BigInt[4]](
    coords: [BigInt[4](raw: [uint64 1, 2, 3, 4]),
             BigInt[4](raw: [uint64 1, 2, 3, 4])]
  ),
  z: QuadraticExt[BigInt[4]](
    coords: [BigInt[4](raw: [uint64 1, 2, 3, 4]),
             BigInt[4](raw: [uint64 1, 2, 3, 4])]
  )
)
var Q = EllipticCurve[QuadraticExt[BigInt[4]]](
  x: QuadraticExt[BigInt[4]](
    coords: [BigInt[4](raw: [uint64 1, 2, 3, 4]),
             BigInt[4](raw: [uint64 1, 2, 3, 4])]
  ),
  y: QuadraticExt[BigInt[4]](
    coords: [BigInt[4](raw: [uint64 1, 2, 3, 4]),
             BigInt[4](raw: [uint64 1, 2, 3, 4])]
  ),
  z: QuadraticExt[BigInt[4]](
    coords: [BigInt[4](raw: [uint64 1, 2, 3, 4]),
             BigInt[4](raw: [uint64 1, 2, 3, 4])]
  )
)

var R: EllipticCurve[QuadraticExt[BigInt[4]]]

R.sum(P, Q, h2c_const_ec)

Copy link
Contributor

🐧 Linux bisect by @ringabout (member)
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(79, 2) template/generic instantiation of `sum` from here
/home/runner/work/Nim/Nim/temp.nim(44, 4) template/generic instantiation of `sumImpl` from here
/home/runner/work/Nim/Nim/temp.nim(39, 6) template/generic instantiation of `mulCheckSparse` from here
/home/runner/work/Nim/Nim/temp.nim(25, 13) Error: type mismatch
Expression: isOne((coords: [(raw: [1'u, 1'u, 1'u, 1'u]), (raw: [1'u, 1'u, 1'u, 1'u])]))
  [1] (coords: [(raw: [1'u, 1'u, 1'u, 1'u]), (raw: [1'u, 1'u, 1'u, 1'u])]): QuadraticExt

Expected one of (first mismatch at [position]):
[1] func isOne(a: BigInt): bool
[1] func isOne(a: ExtensionField): bool

assertions.nim(34)       raiseAssert
Error: unhandled exception: errGenerated [AssertionDefect]

IR

Compiled filesize 0 bytes (0 bytes)

Stats

  • Started 2024-04-29T11:46:09
  • Finished 2024-04-29T11:46:09
  • Duration

AST

nnkStmtList.newTree(
  nnkTypeSection.newTree(
    nnkTypeDef.newTree(
      newIdentNode("BigInt"),
      nnkGenericParams.newTree(
        nnkIdentDefs.newTree(
          newIdentNode("N"),
          nnkCommand.newTree(
            newIdentNode("static"),
            newIdentNode("int")
          ),
          newEmptyNode()
        )
      ),
      nnkObjectTy.newTree(
        newEmptyNode(),
        newEmptyNode(),
        nnkRecList.newTree(
          nnkIdentDefs.newTree(
            newIdentNode("raw"),
            nnkBracketExpr.newTree(
              newIdentNode("array"),
              newIdentNode("N"),
              newIdentNode("uint64")
            ),
            newEmptyNode()
          )
        )
      )
    )
  ),
  nnkFuncDef.newTree(
    newIdentNode("isZero"),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      newIdentNode("bool"),
      nnkIdentDefs.newTree(
        newIdentNode("a"),
        newIdentNode("BigInt"),
        newEmptyNode()
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkDiscardStmt.newTree(
        newEmptyNode()
      )
    )
  ),
  nnkFuncDef.newTree(
    newIdentNode("isOne"),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      newIdentNode("bool"),
      nnkIdentDefs.newTree(
        newIdentNode("a"),
        newIdentNode("BigInt"),
        newEmptyNode()
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkDiscardStmt.newTree(
        newEmptyNode()
      )
    )
  ),
  nnkTypeSection.newTree(
    nnkTypeDef.newTree(
      nnkPostfix.newTree(
        newIdentNode("*"),
        newIdentNode("QuadraticExt")
      ),
      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(2),
              newIdentNode("F")
            ),
            newEmptyNode()
          )
        )
      )
    ),
    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(
      nnkPostfix.newTree(
        newIdentNode("*"),
        newIdentNode("ExtensionField")
      ),
      nnkGenericParams.newTree(
        nnkIdentDefs.newTree(
          newIdentNode("F"),
          newEmptyNode(),
          newEmptyNode()
        )
      ),
      nnkInfix.newTree(
        newIdentNode("or"),
        nnkBracketExpr.newTree(
          newIdentNode("QuadraticExt"),
          newIdentNode("F")
        ),
        nnkBracketExpr.newTree(
          newIdentNode("CubicExt"),
          newIdentNode("F")
        )
      )
    )
  ),
  nnkFuncDef.newTree(
    nnkPostfix.newTree(
      newIdentNode("*"),
      newIdentNode("isOne")
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      newIdentNode("bool"),
      nnkIdentDefs.newTree(
        newIdentNode("a"),
        newIdentNode("ExtensionField"),
        newEmptyNode()
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      newCommentStmtNode("Constant-time check if one"),
      nnkAsgn.newTree(
        newIdentNode("result"),
        nnkUInt64Lit.newTree(
        )
      ),
      nnkAsgn.newTree(
        newIdentNode("result"),
        nnkInfix.newTree(
          newIdentNode("and"),
          newIdentNode("result"),
          nnkCall.newTree(
            nnkDotExpr.newTree(
              nnkBracketExpr.newTree(
                nnkDotExpr.newTree(
                  newIdentNode("a"),
                  newIdentNode("coords")
                ),
                newLit(0)
              ),
              newIdentNode("isOne")
            )
          )
        )
      ),
      nnkForStmt.newTree(
        newIdentNode("i"),
        nnkInfix.newTree(
          newIdentNode("..<"),
          newLit(1),
          nnkDotExpr.newTree(
            nnkDotExpr.newTree(
              newIdentNode("a"),
              newIdentNode("coords")
            ),
            newIdentNode("len")
          )
        ),
        nnkStmtList.newTree(
          nnkAsgn.newTree(
            newIdentNode("result"),
            nnkInfix.newTree(
              newIdentNode("and"),
              newIdentNode("result"),
              nnkCall.newTree(
                nnkDotExpr.newTree(
                  nnkBracketExpr.newTree(
                    nnkDotExpr.newTree(
                      newIdentNode("a"),
                      newIdentNode("coords")
                    ),
                    newIdentNode("i")
                  ),
                  newIdentNode("isZero")
                )
              )
            )
          )
        )
      )
    )
  ),
  nnkFuncDef.newTree(
    nnkPostfix.newTree(
      newIdentNode("*"),
      newIdentNode("mulCheckSparse")
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      newEmptyNode(),
      nnkIdentDefs.newTree(
        newIdentNode("a"),
        nnkVarTy.newTree(
          newIdentNode("QuadraticExt")
        ),
        newEmptyNode()
      ),
      nnkIdentDefs.newTree(
        newIdentNode("b"),
        nnkCommand.newTree(
          newIdentNode("static"),
          newIdentNode("QuadraticExt")
        ),
        newEmptyNode()
      )
    ),
    nnkPragma.newTree(
      newIdentNode("inline")
    ),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkStaticStmt.newTree(
        nnkStmtList.newTree(
          nnkCommand.newTree(
            newIdentNode("debugEcho"),
            newLit("QuadraticExt b: "),
            nnkInfix.newTree(
              newIdentNode("is"),
              newIdentNode("b"),
              newIdentNode("QuadraticExt")
            )
          ),
          nnkCommand.newTree(
            newIdentNode("debugEcho"),
            newLit("ExtensionField b: "),
            nnkInfix.newTree(
              newIdentNode("is"),
              newIdentNode("b"),
              newIdentNode("ExtensionField")
            )
          )
        )
      ),
      nnkWhenStmt.newTree(
        nnkElifBranch.newTree(
          nnkDotExpr.newTree(
            nnkCall.newTree(
              newIdentNode("isOne"),
              newIdentNode("b")
            ),
            newIdentNode("bool")
          ),
          nnkStmtList.newTree(
            nnkDiscardStmt.newTree(
              newEmptyNode()
            )
          )
        ),
        nnkElse.newTree(
          nnkStmtList.newTree(
            nnkCommand.newTree(
              newIdentNode("debugEcho"),
              newLit("a *= b")
            )
          )
        )
      )
    )
  ),
  nnkTypeSection.newTree(
    nnkTypeDef.newTree(
      nnkPostfix.newTree(
        newIdentNode("*"),
        newIdentNode("EllipticCurve")
      ),
      nnkGenericParams.newTree(
        nnkIdentDefs.newTree(
          newIdentNode("F"),
          newEmptyNode(),
          newEmptyNode()
        )
      ),
      nnkObjectTy.newTree(
        newEmptyNode(),
        newEmptyNode(),
        nnkRecList.newTree(
          nnkIdentDefs.newTree(
            nnkPostfix.newTree(
              newIdentNode("*"),
              newIdentNode("x")
            ),
            nnkPostfix.newTree(
              newIdentNode("*"),
              newIdentNode("y")
            ),
            nnkPostfix.newTree(
              newIdentNode("*"),
              newIdentNode("z")
            ),
            newIdentNode("F"),
            newEmptyNode()
          )
        )
      )
    )
  ),
  nnkTemplateDef.newTree(
    newIdentNode("sumImpl"),
    newEmptyNode(),
    nnkGenericParams.newTree(
      nnkIdentDefs.newTree(
        newIdentNode("F"),
        newEmptyNode(),
        newEmptyNode()
      )
    ),
    nnkFormalParams.newTree(
      newEmptyNode(),
      nnkIdentDefs.newTree(
        newIdentNode("r"),
        nnkVarTy.newTree(
          nnkBracketExpr.newTree(
            newIdentNode("EllipticCurve"),
            newIdentNode("F")
          )
        ),
        newEmptyNode()
      ),
      nnkIdentDefs.newTree(
        newIdentNode("P"),
        newIdentNode("Q"),
        nnkBracketExpr.newTree(
          newIdentNode("EllipticCurve"),
          newIdentNode("F")
        ),
        newEmptyNode()
      ),
      nnkIdentDefs.newTree(
        newIdentNode("CoefA"),
        newIdentNode("typed"),
        newEmptyNode()
      )
    ),
    nnkPragma.newTree(
      newIdentNode("dirty")
    ),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkWhenStmt.newTree(
        nnkElifBranch.newTree(
          nnkInfix.newTree(
            newIdentNode("is"),
            newIdentNode("CoefA"),
            newIdentNode("int")
          ),
          nnkStmtList.newTree(
            nnkCommand.newTree(
              newIdentNode("debugEcho"),
              newLit("EC addition with int CoefA")
            )
          )
        ),
        nnkElse.newTree(
          nnkStmtList.newTree(
            nnkVarSection.newTree(
              nnkIdentDefs.newTree(
                newIdentNode("b"),
                newEmptyNode(),
                nnkDotExpr.newTree(
                  newIdentNode("P"),
                  newIdentNode("x")
                )
              )
            ),
            nnkCall.newTree(
              nnkDotExpr.newTree(
                newIdentNode("b"),
                newIdentNode("mulCheckSparse")
              ),
              newIdentNode("CoefA")
            )
          )
        )
      )
    )
  ),
  nnkFuncDef.newTree(
    newIdentNode("sum"),
    newEmptyNode(),
    nnkGenericParams.newTree(
      nnkIdentDefs.newTree(
        newIdentNode("F"),
        newEmptyNode(),
        newEmptyNode()
      )
    ),
    nnkFormalParams.newTree(
      newEmptyNode(),
      nnkIdentDefs.newTree(
        newIdentNode("r"),
        nnkVarTy.newTree(
          nnkBracketExpr.newTree(
            newIdentNode("EllipticCurve"),
            newIdentNode("F")
          )
        ),
        newEmptyNode()
      ),
      nnkIdentDefs.newTree(
        newIdentNode("P"),
        newIdentNode("Q"),
        nnkBracketExpr.newTree(
          newIdentNode("EllipticCurve"),
          newIdentNode("F")
        ),
        newEmptyNode()
      ),
      nnkIdentDefs.newTree(
        newIdentNode("CoefA"),
        nnkCommand.newTree(
          newIdentNode("static"),
          newIdentNode("F")
        ),
        newEmptyNode()
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkCall.newTree(
        nnkDotExpr.newTree(
          newIdentNode("r"),
          newIdentNode("sumImpl")
        ),
        newIdentNode("P"),
        newIdentNode("Q"),
        newIdentNode("CoefA")
      )
    )
  ),
  newCommentStmtNode("----------------------------------"),
  nnkConstSection.newTree(
    nnkConstDef.newTree(
      newIdentNode("h2c_const_ec"),
      newEmptyNode(),
      nnkObjConstr.newTree(
        nnkBracketExpr.newTree(
          newIdentNode("QuadraticExt"),
          nnkBracketExpr.newTree(
            newIdentNode("BigInt"),
            newLit(4)
          )
        ),
        nnkExprColonExpr.newTree(
          newIdentNode("coords"),
          nnkBracket.newTree(
            nnkObjConstr.newTree(
              nnkBracketExpr.newTree(
                newIdentNode("BigInt"),
                newLit(4)
              ),
              nnkExprColonExpr.newTree(
                newIdentNode("raw"),
                nnkBracket.newTree(
                  nnkCommand.newTree(
                    newIdentNode("uint64"),
                    newLit(1)
                  ),
                  newLit(1),
                  newLit(1),
                  newLit(1)
                )
              )
            ),
            nnkObjConstr.newTree(
              nnkBracketExpr.newTree(
                newIdentNode("BigInt"),
                newLit(4)
              ),
              nnkExprColonExpr.newTree(
                newIdentNode("raw"),
                nnkBracket.newTree(
                  nnkCommand.newTree(
                    newIdentNode("uint64"),
                    newLit(1)
                  ),
                  newLit(1),
                  newLit(1),
                  newLit(1)
                )
              )
            )
          )
        )
      )
    )
  ),
  nnkVarSection.newTree(
    nnkIdentDefs.newTree(
      newIdentNode("P"),
      newEmptyNode(),
      nnkObjConstr.newTree(
        nnkBracketExpr.newTree(
          newIdentNode("EllipticCurve"),
          nnkBracketExpr.newTree(
            newIdentNode("QuadraticExt"),
            nnkBracketExpr.newTree(
              newIdentNode("BigInt"),
              newLit(4)
            )
          )
        ),
        nnkExprColonExpr.newTree(
          newIdentNode("x"),
          nnkObjConstr.newTree(
            nnkBracketExpr.newTree(
              newIdentNode("QuadraticExt"),
              nnkBracketExpr.newTree(
                newIdentNode("BigInt"),
                newLit(4)
              )
            ),
            nnkExprColonExpr.newTree(
              newIdentNode("coords"),
              nnkBracket.newTree(
                nnkObjConstr.newTree(
                  nnkBracketExpr.newTree(
                    newIdentNode("BigInt"),
                    newLit(4)
                  ),
                  nnkExprColonExpr.newTree(
                    newIdentNode("raw"),
                    nnkBracket.newTree(
                      nnkCommand.newTree(
                        newIdentNode("uint64"),
                        newLit(1)
                      ),
                      newLit(2),
                      newLit(3),
                      newLit(4)
                    )
                  )
                ),
                nnkObjConstr.newTree(
                  nnkBracketExpr.newTree(
                    newIdentNode("BigInt"),
                    newLit(4)
                  ),
                  nnkExprColonExpr.newTree(
                    newIdentNode("raw"),
                    nnkBracket.newTree(
                      nnkCommand.newTree(
                        newIdentNode("uint64"),
                        newLit(1)
                      ),
                      newLit(2),
                      newLit(3),
                      newLit(4)
                    )
                  )
                )
              )
            )
          )
        ),
        nnkExprColonExpr.newTree(
          newIdentNode("y"),
          nnkObjConstr.newTree(
            nnkBracketExpr.newTree(
              newIdentNode("QuadraticExt"),
              nnkBracketExpr.newTree(
                newIdentNode("BigInt"),
                newLit(4)
              )
            ),
            nnkExprColonExpr.newTree(
              newIdentNode("coords"),
              nnkBracket.newTree(
                nnkObjConstr.newTree(
                  nnkBracketExpr.newTree(
                    newIdentNode("BigInt"),
                    newLit(4)
                  ),
                  nnkExprColonExpr.newTree(
                    newIdentNode("raw"),
                    nnkBracket.newTree(
                      nnkCommand.newTree(
                        newIdentNode("uint64"),
                        newLit(1)
                      ),
                      newLit(2),
                      newLit(3),
                      newLit(4)
                    )
                  )
                ),
                nnkObjConstr.newTree(
                  nnkBracketExpr.newTree(
                    newIdentNode("BigInt"),
                    newLit(4)
                  ),
                  nnkExprColonExpr.newTree(
                    newIdentNode("raw"),
                    nnkBracket.newTree(
                      nnkCommand.newTree(
                        newIdentNode("uint64"),
                        newLit(1)
                      ),
                      newLit(2),
                      newLit(3),
                      newLit(4)
                    )
                  )
                )
              )
            )
          )
        ),
        nnkExprColonExpr.newTree(
          newIdentNode("z"),
          nnkObjConstr.newTree(
            nnkBracketExpr.newTree(
              newIdentNode("QuadraticExt"),
              nnkBracketExpr.newTree(
                newIdentNode("BigInt"),
                newLit(4)
              )
            ),
            nnkExprColonExpr.newTree(
              newIdentNode("coords"),
              nnkBracket.newTree(
                nnkObjConstr.newTree(
                  nnkBracketExpr.newTree(
                    newIdentNode("BigInt"),
                    newLit(4)
                  ),
                  nnkExprColonExpr.newTree(
                    newIdentNode("raw"),
                    nnkBracket.newTree(
                      nnkCommand.newTree(
                        newIdentNode("uint64"),
                        newLit(1)
                      ),
                      newLit(2),
                      newLit(3),
                      newLit(4)
                    )
                  )
                ),
                nnkObjConstr.newTree(
                  nnkBracketExpr.newTree(
                    newIdentNode("BigInt"),
                    newLit(4)
                  ),
                  nnkExprColonExpr.newTree(
                    newIdentNode("raw"),
                    nnkBracket.newTree(
                      nnkCommand.newTree(
                        newIdentNode("uint64"),
                        newLit(1)
                      ),
                      newLit(2),
                      newLit(3),
                      newLit(4)
                    )
                  )
                )
              )
            )
          )
        )
      )
    )
  ),
  nnkVarSection.newTree(
    nnkIdentDefs.newTree(
      newIdentNode("Q"),
      newEmptyNode(),
      nnkObjConstr.newTree(
        nnkBracketExpr.newTree(
          newIdentNode("EllipticCurve"),
          nnkBracketExpr.newTree(
            newIdentNode("QuadraticExt"),
            nnkBracketExpr.newTree(
              newIdentNode("BigInt"),
              newLit(4)
            )
          )
        ),
        nnkExprColonExpr.newTree(
          newIdentNode("x"),
          nnkObjConstr.newTree(
            nnkBracketExpr.newTree(
              newIdentNode("QuadraticExt"),
              nnkBracketExpr.newTree(
                newIdentNode("BigInt"),
                newLit(4)
              )
            ),
            nnkExprColonExpr.newTree(
              newIdentNode("coords"),
              nnkBracket.newTree(
                nnkObjConstr.newTree(
                  nnkBracketExpr.newTree(
                    newIdentNode("BigInt"),
                    newLit(4)
                  ),
                  nnkExprColonExpr.newTree(
                    newIdentNode("raw"),
                    nnkBracket.newTree(
                      nnkCommand.newTree(
                        newIdentNode("uint64"),
                        newLit(1)
                      ),
                      newLit(2),
                      newLit(3),
                      newLit(4)
                    )
                  )
                ),
                nnkObjConstr.newTree(
                  nnkBracketExpr.newTree(
                    newIdentNode("BigInt"),
                    newLit(4)
                  ),
                  nnkExprColonExpr.newTree(
                    newIdentNode("raw"),
                    nnkBracket.newTree(
                      nnkCommand.newTree(
                        newIdentNode("uint64"),
                        newLit(1)
                      ),
                      newLit(2),
                      newLit(3),
                      newLit(4)
                    )
                  )
                )
              )
            )
          )
        ),
        nnkExprColonExpr.newTree(
          newIdentNode("y"),
          nnkObjConstr.newTree(
            nnkBracketExpr.newTree(
              newIdentNode("QuadraticExt"),
              nnkBracketExpr.newTree(
                newIdentNode("BigInt"),
                newLit(4)
              )
            ),
            nnkExprColonExpr.newTree(
              newIdentNode("coords"),
              nnkBracket.newTree(
                nnkObjConstr.newTree(
                  nnkBracketExpr.newTree(
                    newIdentNode("BigInt"),
                    newLit(4)
                  ),
                  nnkExprColonExpr.newTree(
                    newIdentNode("raw"),
                    nnkBracket.newTree(
                      nnkCommand.newTree(
                        newIdentNode("uint64"),
                        newLit(1)
                      ),
                      newLit(2),
                      newLit(3),
                      newLit(4)
                    )
                  )
                ),
                nnkObjConstr.newTree(
                  nnkBracketExpr.newTree(
                    newIdentNode("BigInt"),
                    newLit(4)
                  ),
                  nnkExprColonExpr.newTree(
                    newIdentNode("raw"),
                    nnkBracket.newTree(
                      nnkCommand.newTree(
                        newIdentNode("uint64"),
                        newLit(1)
                      ),
                      newLit(2),
                      newLit(3),
                      newLit(4)
                    )
                  )
                )
              )
            )
          )
        ),
        nnkExprColonExpr.newTree(
          newIdentNode("z"),
          nnkObjConstr.newTree(
            nnkBracketExpr.newTree(
              newIdentNode("QuadraticExt"),
              nnkBracketExpr.newTree(
                newIdentNode("BigInt"),
                newLit(4)
              )
            ),
            nnkExprColonExpr.newTree(
              newIdentNode("coords"),
              nnkBracket.newTree(
                nnkObjConstr.newTree(
                  nnkBracketExpr.newTree(
                    newIdentNode("BigInt"),
                    newLit(4)
                  ),
                  nnkExprColonExpr.newTree(
                    newIdentNode("raw"),
                    nnkBracket.newTree(
                      nnkCommand.newTree(
                        newIdentNode("uint64"),
                        newLit(1)
                      ),
                      newLit(2),
                      newLit(3),
                      newLit(4)
                    )
                  )
                ),
                nnkObjConstr.newTree(
                  nnkBracketExpr.newTree(
                    newIdentNode("BigInt"),
                    newLit(4)
                  ),
                  nnkExprColonExpr.newTree(
                    newIdentNode("raw"),
                    nnkBracket.newTree(
                      nnkCommand.newTree(
                        newIdentNode("uint64"),
                        newLit(1)
                      ),
                      newLit(2),
                      newLit(3),
                      newLit(4)
                    )
                  )
                )
              )
            )
          )
        )
      )
    )
  ),
  nnkVarSection.newTree(
    nnkIdentDefs.newTree(
      newIdentNode("R"),
      nnkBracketExpr.newTree(
        newIdentNode("EllipticCurve"),
        nnkBracketExpr.newTree(
          newIdentNode("QuadraticExt"),
          nnkBracketExpr.newTree(
            newIdentNode("BigInt"),
            newLit(4)
          )
        )
      ),
      newEmptyNode()
    )
  ),
  nnkCall.newTree(
    nnkDotExpr.newTree(
      newIdentNode("R"),
      newIdentNode("sum")
    ),
    newIdentNode("P"),
    newIdentNode("Q"),
    newIdentNode("h2c_const_ec")
  )
)
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(79, 2) template/generic instantiation of `sum` from here
/home/runner/work/Nim/Nim/temp.nim(44, 4) template/generic instantiation of `sumImpl` from here
/home/runner/work/Nim/Nim/temp.nim(39, 6) template/generic instantiation of `mulCheckSparse` from here
/home/runner/work/Nim/Nim/temp.nim(25, 13) Error: type mismatch
Expression: isOne((coords: [(raw: [1'u, 1'u, 1'u, 1'u]), (raw: [1'u, 1'u, 1'u, 1'u])]))
  [1] (coords: [(raw: [1'u, 1'u, 1'u, 1'u]), (raw: [1'u, 1'u, 1'u, 1'u])]): QuadraticExt

Expected one of (first mismatch at [position]):
[1] func isOne(a: BigInt): bool
[1] func isOne(a: ExtensionField): bool

assertions.nim(34)       raiseAssert
Error: unhandled exception: options.nim(681, 5) `false` errGenerated [AssertionDefect]

IR

Compiled filesize 0 bytes (0 bytes)

Stats

  • Started 2024-04-29T11:46:10
  • Finished 2024-04-29T11:46:11
  • Duration

AST

nnkStmtList.newTree(
  nnkTypeSection.newTree(
    nnkTypeDef.newTree(
      newIdentNode("BigInt"),
      nnkGenericParams.newTree(
        nnkIdentDefs.newTree(
          newIdentNode("N"),
          nnkCommand.newTree(
            newIdentNode("static"),
            newIdentNode("int")
          ),
          newEmptyNode()
        )
      ),
      nnkObjectTy.newTree(
        newEmptyNode(),
        newEmptyNode(),
        nnkRecList.newTree(
          nnkIdentDefs.newTree(
            newIdentNode("raw"),
            nnkBracketExpr.newTree(
              newIdentNode("array"),
              newIdentNode("N"),
              newIdentNode("uint64")
            ),
            newEmptyNode()
          )
        )
      )
    )
  ),
  nnkFuncDef.newTree(
    newIdentNode("isZero"),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      newIdentNode("bool"),
      nnkIdentDefs.newTree(
        newIdentNode("a"),
        newIdentNode("BigInt"),
        newEmptyNode()
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkDiscardStmt.newTree(
        newEmptyNode()
      )
    )
  ),
  nnkFuncDef.newTree(
    newIdentNode("isOne"),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      newIdentNode("bool"),
      nnkIdentDefs.newTree(
        newIdentNode("a"),
        newIdentNode("BigInt"),
        newEmptyNode()
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkDiscardStmt.newTree(
        newEmptyNode()
      )
    )
  ),
  nnkTypeSection.newTree(
    nnkTypeDef.newTree(
      nnkPostfix.newTree(
        newIdentNode("*"),
        newIdentNode("QuadraticExt")
      ),
      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(2),
              newIdentNode("F")
            ),
            newEmptyNode()
          )
        )
      )
    ),
    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(
      nnkPostfix.newTree(
        newIdentNode("*"),
        newIdentNode("ExtensionField")
      ),
      nnkGenericParams.newTree(
        nnkIdentDefs.newTree(
          newIdentNode("F"),
          newEmptyNode(),
          newEmptyNode()
        )
      ),
      nnkInfix.newTree(
        newIdentNode("or"),
        nnkBracketExpr.newTree(
          newIdentNode("QuadraticExt"),
          newIdentNode("F")
        ),
        nnkBracketExpr.newTree(
          newIdentNode("CubicExt"),
          newIdentNode("F")
        )
      )
    )
  ),
  nnkFuncDef.newTree(
    nnkPostfix.newTree(
      newIdentNode("*"),
      newIdentNode("isOne")
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      newIdentNode("bool"),
      nnkIdentDefs.newTree(
        newIdentNode("a"),
        newIdentNode("ExtensionField"),
        newEmptyNode()
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      newCommentStmtNode("Constant-time check if one"),
      nnkAsgn.newTree(
        newIdentNode("result"),
        nnkUInt64Lit.newTree(
        )
      ),
      nnkAsgn.newTree(
        newIdentNode("result"),
        nnkInfix.newTree(
          newIdentNode("and"),
          newIdentNode("result"),
          nnkCall.newTree(
            nnkDotExpr.newTree(
              nnkBracketExpr.newTree(
                nnkDotExpr.newTree(
                  newIdentNode("a"),
                  newIdentNode("coords")
                ),
                newLit(0)
              ),
              newIdentNode("isOne")
            )
          )
        )
      ),
      nnkForStmt.newTree(
        newIdentNode("i"),
        nnkInfix.newTree(
          newIdentNode("..<"),
          newLit(1),
          nnkDotExpr.newTree(
            nnkDotExpr.newTree(
              newIdentNode("a"),
              newIdentNode("coords")
            ),
            newIdentNode("len")
          )
        ),
        nnkStmtList.newTree(
          nnkAsgn.newTree(
            newIdentNode("result"),
            nnkInfix.newTree(
              newIdentNode("and"),
              newIdentNode("result"),
              nnkCall.newTree(
                nnkDotExpr.newTree(
                  nnkBracketExpr.newTree(
                    nnkDotExpr.newTree(
                      newIdentNode("a"),
                      newIdentNode("coords")
                    ),
                    newIdentNode("i")
                  ),
                  newIdentNode("isZero")
                )
              )
            )
          )
        )
      )
    )
  ),
  nnkFuncDef.newTree(
    nnkPostfix.newTree(
      newIdentNode("*"),
      newIdentNode("mulCheckSparse")
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      newEmptyNode(),
      nnkIdentDefs.newTree(
        newIdentNode("a"),
        nnkVarTy.newTree(
          newIdentNode("QuadraticExt")
        ),
        newEmptyNode()
      ),
      nnkIdentDefs.newTree(
        newIdentNode("b"),
        nnkCommand.newTree(
          newIdentNode("static"),
          newIdentNode("QuadraticExt")
        ),
        newEmptyNode()
      )
    ),
    nnkPragma.newTree(
      newIdentNode("inline")
    ),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkStaticStmt.newTree(
        nnkStmtList.newTree(
          nnkCommand.newTree(
            newIdentNode("debugEcho"),
            newLit("QuadraticExt b: "),
            nnkInfix.newTree(
              newIdentNode("is"),
              newIdentNode("b"),
              newIdentNode("QuadraticExt")
            )
          ),
          nnkCommand.newTree(
            newIdentNode("debugEcho"),
            newLit("ExtensionField b: "),
            nnkInfix.newTree(
              newIdentNode("is"),
              newIdentNode("b"),
              newIdentNode("ExtensionField")
            )
          )
        )
      ),
      nnkWhenStmt.newTree(
        nnkElifBranch.newTree(
          nnkDotExpr.newTree(
            nnkCall.newTree(
              newIdentNode("isOne"),
              newIdentNode("b")
            ),
            newIdentNode("bool")
          ),
          nnkStmtList.newTree(
            nnkDiscardStmt.newTree(
              newEmptyNode()
            )
          )
        ),
        nnkElse.newTree(
          nnkStmtList.newTree(
            nnkCommand.newTree(
              newIdentNode("debugEcho"),
              newLit("a *= b")
            )
          )
        )
      )
    )
  ),
  nnkTypeSection.newTree(
    nnkTypeDef.newTree(
      nnkPostfix.newTree(
        newIdentNode("*"),
        newIdentNode("EllipticCurve")
      ),
      nnkGenericParams.newTree(
        nnkIdentDefs.newTree(
          newIdentNode("F"),
          newEmptyNode(),
          newEmptyNode()
        )
      ),
      nnkObjectTy.newTree(
        newEmptyNode(),
        newEmptyNode(),
        nnkRecList.newTree(
          nnkIdentDefs.newTree(
            nnkPostfix.newTree(
              newIdentNode("*"),
              newIdentNode("x")
            ),
            nnkPostfix.newTree(
              newIdentNode("*"),
              newIdentNode("y")
            ),
            nnkPostfix.newTree(
              newIdentNode("*"),
              newIdentNode("z")
            ),
            newIdentNode("F"),
            newEmptyNode()
          )
        )
      )
    )
  ),
  nnkTemplateDef.newTree(
    newIdentNode("sumImpl"),
    newEmptyNode(),
    nnkGenericParams.newTree(
      nnkIdentDefs.newTree(
        newIdentNode("F"),
        newEmptyNode(),
        newEmptyNode()
      )
    ),
    nnkFormalParams.newTree(
      newEmptyNode(),
      nnkIdentDefs.newTree(
        newIdentNode("r"),
        nnkVarTy.newTree(
          nnkBracketExpr.newTree(
            newIdentNode("EllipticCurve"),
            newIdentNode("F")
          )
        ),
        newEmptyNode()
      ),
      nnkIdentDefs.newTree(
        newIdentNode("P"),
        newIdentNode("Q"),
        nnkBracketExpr.newTree(
          newIdentNode("EllipticCurve"),
          newIdentNode("F")
        ),
        newEmptyNode()
      ),
      nnkIdentDefs.newTree(
        newIdentNode("CoefA"),
        newIdentNode("typed"),
        newEmptyNode()
      )
    ),
    nnkPragma.newTree(
      newIdentNode("dirty")
    ),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkWhenStmt.newTree(
        nnkElifBranch.newTree(
          nnkInfix.newTree(
            newIdentNode("is"),
            newIdentNode("CoefA"),
            newIdentNode("int")
          ),
          nnkStmtList.newTree(
            nnkCommand.newTree(
              newIdentNode("debugEcho"),
              newLit("EC addition with int CoefA")
            )
          )
        ),
        nnkElse.newTree(
          nnkStmtList.newTree(
            nnkVarSection.newTree(
              nnkIdentDefs.newTree(
                newIdentNode("b"),
                newEmptyNode(),
                nnkDotExpr.newTree(
                  newIdentNode("P"),
                  newIdentNode("x")
                )
              )
            ),
            nnkCall.newTree(
              nnkDotExpr.newTree(
                newIdentNode("b"),
                newIdentNode("mulCheckSparse")
              ),
              newIdentNode("CoefA")
            )
          )
        )
      )
    )
  ),
  nnkFuncDef.newTree(
    newIdentNode("sum"),
    newEmptyNode(),
    nnkGenericParams.newTree(
      nnkIdentDefs.newTree(
        newIdentNode("F"),
        newEmptyNode(),
        newEmptyNode()
      )
    ),
    nnkFormalParams.newTree(
      newEmptyNode(),
      nnkIdentDefs.newTree(
        newIdentNode("r"),
        nnkVarTy.newTree(
          nnkBracketExpr.newTree(
            newIdentNode("EllipticCurve"),
            newIdentNode("F")
          )
        ),
        newEmptyNode()
      ),
      nnkIdentDefs.newTree(
        newIdentNode("P"),
        newIdentNode("Q"),
        nnkBracketExpr.newTree(
          newIdentNode("EllipticCurve"),
          newIdentNode("F")
        ),
        newEmptyNode()
      ),
      nnkIdentDefs.newTree(
        newIdentNode("CoefA"),
        nnkCommand.newTree(
          newIdentNode("static"),
          newIdentNode("F")
        ),
        newEmptyNode()
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkCall.newTree(
        nnkDotExpr.newTree(
          newIdentNode("r"),
          newIdentNode("sumImpl")
        ),
        newIdentNode("P"),
        newIdentNode("Q"),
        newIdentNode("CoefA")
      )
    )
  ),
  newCommentStmtNode("----------------------------------"),
  nnkConstSection.newTree(
    nnkConstDef.newTree(
      newIdentNode("h2c_const_ec"),
      newEmptyNode(),
      nnkObjConstr.newTree(
        nnkBracketExpr.newTree(
          newIdentNode("QuadraticExt"),
          nnkBracketExpr.newTree(
            newIdentNode("BigInt"),
            newLit(4)
          )
        ),
        nnkExprColonExpr.newTree(
          newIdentNode("coords"),
          nnkBracket.newTree(
            nnkObjConstr.newTree(
              nnkBracketExpr.newTree(
                newIdentNode("BigInt"),
                newLit(4)
              ),
              nnkExprColonExpr.newTree(
                newIdentNode("raw"),
                nnkBracket.newTree(
                  nnkCommand.newTree(
                    newIdentNode("uint64"),
                    newLit(1)
                  ),
                  newLit(1),
                  newLit(1),
                  newLit(1)
                )
              )
            ),
            nnkObjConstr.newTree(
              nnkBracketExpr.newTree(
                newIdentNode("BigInt"),
                newLit(4)
              ),
              nnkExprColonExpr.newTree(
                newIdentNode("raw"),
                nnkBracket.newTree(
                  nnkCommand.newTree(
                    newIdentNode("uint64"),
                    newLit(1)
                  ),
                  newLit(1),
                  newLit(1),
                  newLit(1)
                )
              )
            )
          )
        )
      )
    )
  ),
  nnkVarSection.newTree(
    nnkIdentDefs.newTree(
      newIdentNode("P"),
      newEmptyNode(),
      nnkObjConstr.newTree(
        nnkBracketExpr.newTree(
          newIdentNode("EllipticCurve"),
          nnkBracketExpr.newTree(
            newIdentNode("QuadraticExt"),
            nnkBracketExpr.newTree(
              newIdentNode("BigInt"),
              newLit(4)
            )
          )
        ),
        nnkExprColonExpr.newTree(
          newIdentNode("x"),
          nnkObjConstr.newTree(
            nnkBracketExpr.newTree(
              newIdentNode("QuadraticExt"),
              nnkBracketExpr.newTree(
                newIdentNode("BigInt"),
                newLit(4)
              )
            ),
            nnkExprColonExpr.newTree(
              newIdentNode("coords"),
              nnkBracket.newTree(
                nnkObjConstr.newTree(
                  nnkBracketExpr.newTree(
                    newIdentNode("BigInt"),
                    newLit(4)
                  ),
                  nnkExprColonExpr.newTree(
                    newIdentNode("raw"),
                    nnkBracket.newTree(
                      nnkCommand.newTree(
                        newIdentNode("uint64"),
                        newLit(1)
                      ),
                      newLit(2),
                      newLit(3),
                      newLit(4)
                    )
                  )
                ),
                nnkObjConstr.newTree(
                  nnkBracketExpr.newTree(
                    newIdentNode("BigInt"),
                    newLit(4)
                  ),
                  nnkExprColonExpr.newTree(
                    newIdentNode("raw"),
                    nnkBracket.newTree(
                      nnkCommand.newTree(
                        newIdentNode("uint64"),
                        newLit(1)
                      ),
                      newLit(2),
                      newLit(3),
                      newLit(4)
                    )
                  )
                )
              )
            )
          )
        ),
        nnkExprColonExpr.newTree(
          newIdentNode("y"),
          nnkObjConstr.newTree(
            nnkBracketExpr.newTree(
              newIdentNode("QuadraticExt"),
              nnkBracketExpr.newTree(
                newIdentNode("BigInt"),
                newLit(4)
              )
            ),
            nnkExprColonExpr.newTree(
              newIdentNode("coords"),
              nnkBracket.newTree(
                nnkObjConstr.newTree(
                  nnkBracketExpr.newTree(
                    newIdentNode("BigInt"),
                    newLit(4)
                  ),
                  nnkExprColonExpr.newTree(
                    newIdentNode("raw"),
                    nnkBracket.newTree(
                      nnkCommand.newTree(
                        newIdentNode("uint64"),
                        newLit(1)
                      ),
                      newLit(2),
                      newLit(3),
                      newLit(4)
                    )
                  )
                ),
                nnkObjConstr.newTree(
                  nnkBracketExpr.newTree(
                    newIdentNode("BigInt"),
                    newLit(4)
                  ),
                  nnkExprColonExpr.newTree(
                    newIdentNode("raw"),
                    nnkBracket.newTree(
                      nnkCommand.newTree(
                        newIdentNode("uint64"),
                        newLit(1)
                      ),
                      newLit(2),
                      newLit(3),
                      newLit(4)
                    )
                  )
                )
              )
            )
          )
        ),
        nnkExprColonExpr.newTree(
          newIdentNode("z"),
          nnkObjConstr.newTree(
            nnkBracketExpr.newTree(
              newIdentNode("QuadraticExt"),
              nnkBracketExpr.newTree(
                newIdentNode("BigInt"),
                newLit(4)
              )
            ),
            nnkExprColonExpr.newTree(
              newIdentNode("coords"),
              nnkBracket.newTree(
                nnkObjConstr.newTree(
                  nnkBracketExpr.newTree(
                    newIdentNode("BigInt"),
                    newLit(4)
                  ),
                  nnkExprColonExpr.newTree(
                    newIdentNode("raw"),
                    nnkBracket.newTree(
                      nnkCommand.newTree(
                        newIdentNode("uint64"),
                        newLit(1)
                      ),
                      newLit(2),
                      newLit(3),
                      newLit(4)
                    )
                  )
                ),
                nnkObjConstr.newTree(
                  nnkBracketExpr.newTree(
                    newIdentNode("BigInt"),
                    newLit(4)
                  ),
                  nnkExprColonExpr.newTree(
                    newIdentNode("raw"),
                    nnkBracket.newTree(
                      nnkCommand.newTree(
                        newIdentNode("uint64"),
                        newLit(1)
                      ),
                      newLit(2),
                      newLit(3),
                      newLit(4)
                    )
                  )
                )
              )
            )
          )
        )
      )
    )
  ),
  nnkVarSection.newTree(
    nnkIdentDefs.newTree(
      newIdentNode("Q"),
      newEmptyNode(),
      nnkObjConstr.newTree(
        nnkBracketExpr.newTree(
          newIdentNode("EllipticCurve"),
          nnkBracketExpr.newTree(
            newIdentNode("QuadraticExt"),
            nnkBracketExpr.newTree(
              newIdentNode("BigInt"),
              newLit(4)
            )
          )
        ),
        nnkExprColonExpr.newTree(
          newIdentNode("x"),
          nnkObjConstr.newTree(
            nnkBracketExpr.newTree(
              newIdentNode("QuadraticExt"),
              nnkBracketExpr.newTree(
                newIdentNode("BigInt"),
                newLit(4)
              )
            ),
            nnkExprColonExpr.newTree(
              newIdentNode("coords"),
              nnkBracket.newTree(
                nnkObjConstr.newTree(
                  nnkBracketExpr.newTree(
                    newIdentNode("BigInt"),
                    newLit(4)
                  ),
                  nnkExprColonExpr.newTree(
                    newIdentNode("raw"),
                    nnkBracket.newTree(
                      nnkCommand.newTree(
                        newIdentNode("uint64"),
                        newLit(1)
                      ),
                      newLit(2),
                      newLit(3),
                      newLit(4)
                    )
                  )
                ),
                nnkObjConstr.newTree(
                  nnkBracketExpr.newTree(
                    newIdentNode("BigInt"),
                    newLit(4)
                  ),
                  nnkExprColonExpr.newTree(
                    newIdentNode("raw"),
                    nnkBracket.newTree(
                      nnkCommand.newTree(
                        newIdentNode("uint64"),
                        newLit(1)
                      ),
                      newLit(2),
                      newLit(3),
                      newLit(4)
                    )
                  )
                )
              )
            )
          )
        ),
        nnkExprColonExpr.newTree(
          newIdentNode("y"),
          nnkObjConstr.newTree(
            nnkBracketExpr.newTree(
              newIdentNode("QuadraticExt"),
              nnkBracketExpr.newTree(
                newIdentNode("BigInt"),
                newLit(4)
              )
            ),
            nnkExprColonExpr.newTree(
              newIdentNode("coords"),
              nnkBracket.newTree(
                nnkObjConstr.newTree(
                  nnkBracketExpr.newTree(
                    newIdentNode("BigInt"),
                    newLit(4)
                  ),
                  nnkExprColonExpr.newTree(
                    newIdentNode("raw"),
                    nnkBracket.newTree(
                      nnkCommand.newTree(
                        newIdentNode("uint64"),
                        newLit(1)
                      ),
                      newLit(2),
                      newLit(3),
                      newLit(4)
                    )
                  )
                ),
                nnkObjConstr.newTree(
                  nnkBracketExpr.newTree(
                    newIdentNode("BigInt"),
                    newLit(4)
                  ),
                  nnkExprColonExpr.newTree(
                    newIdentNode("raw"),
                    nnkBracket.newTree(
                      nnkCommand.newTree(
                        newIdentNode("uint64"),
                        newLit(1)
                      ),
                      newLit(2),
                      newLit(3),
                      newLit(4)
                    )
                  )
                )
              )
            )
          )
        ),
        nnkExprColonExpr.newTree(
          newIdentNode("z"),
          nnkObjConstr.newTree(
            nnkBracketExpr.newTree(
              newIdentNode("QuadraticExt"),
              nnkBracketExpr.newTree(
                newIdentNode("BigInt"),
                newLit(4)
              )
            ),
            nnkExprColonExpr.newTree(
              newIdentNode("coords"),
              nnkBracket.newTree(
                nnkObjConstr.newTree(
                  nnkBracketExpr.newTree(
                    newIdentNode("BigInt"),
                    newLit(4)
                  ),
                  nnkExprColonExpr.newTree(
                    newIdentNode("raw"),
                    nnkBracket.newTree(
                      nnkCommand.newTree(
                        newIdentNode("uint64"),
                        newLit(1)
                      ),
                      newLit(2),
                      newLit(3),
                      newLit(4)
                    )
                  )
                ),
                nnkObjConstr.newTree(
                  nnkBracketExpr.newTree(
                    newIdentNode("BigInt"),
                    newLit(4)
                  ),
                  nnkExprColonExpr.newTree(
                    newIdentNode("raw"),
                    nnkBracket.newTree(
                      nnkCommand.newTree(
                        newIdentNode("uint64"),
                        newLit(1)
                      ),
                      newLit(2),
                      newLit(3),
                      newLit(4)
                    )
                  )
                )
              )
            )
          )
        )
      )
    )
  ),
  nnkVarSection.newTree(
    nnkIdentDefs.newTree(
      newIdentNode("R"),
      nnkBracketExpr.newTree(
        newIdentNode("EllipticCurve"),
        nnkBracketExpr.newTree(
          newIdentNode("QuadraticExt"),
          nnkBracketExpr.newTree(
            newIdentNode("BigInt"),
            newLit(4)
          )
        )
      ),
      newEmptyNode()
    )
  ),
  nnkCall.newTree(
    nnkDotExpr.newTree(
      newIdentNode("R"),
      newIdentNode("sum")
    ),
    newIdentNode("P"),
    newIdentNode("Q"),
    newIdentNode("h2c_const_ec")
  )
)
2.0.2 👎 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(79, 2) template/generic instantiation of `sum` from here
/home/runner/work/Nim/Nim/temp.nim(44, 4) template/generic instantiation of `sumImpl` from here
/home/runner/work/Nim/Nim/temp.nim(39, 6) template/generic instantiation of `mulCheckSparse` from here
/home/runner/work/Nim/Nim/temp.nim(25, 13) Error: type mismatch
Expression: isOne((coords: [(raw: [1'u, 1'u, 1'u, 1'u]), (raw: [1'u, 1'u, 1'u, 1'u])]))
  [1] (coords: [(raw: [1'u, 1'u, 1'u, 1'u]), (raw: [1'u, 1'u, 1'u, 1'u])]): QuadraticExt

Expected one of (first mismatch at [position]):
[1] func isOne(a: BigInt): bool
[1] func isOne(a: ExtensionField): bool

assertions.nim(34)       raiseAssert
Error: unhandled exception: options.nim(681, 5) `false` errGenerated [AssertionDefect]

IR

Compiled filesize 0 bytes (0 bytes)

Stats

  • Started 2024-04-29T11:46:13
  • Finished 2024-04-29T11:46:13
  • Duration

AST

nnkStmtList.newTree(
  nnkTypeSection.newTree(
    nnkTypeDef.newTree(
      newIdentNode("BigInt"),
      nnkGenericParams.newTree(
        nnkIdentDefs.newTree(
          newIdentNode("N"),
          nnkCommand.newTree(
            newIdentNode("static"),
            newIdentNode("int")
          ),
          newEmptyNode()
        )
      ),
      nnkObjectTy.newTree(
        newEmptyNode(),
        newEmptyNode(),
        nnkRecList.newTree(
          nnkIdentDefs.newTree(
            newIdentNode("raw"),
            nnkBracketExpr.newTree(
              newIdentNode("array"),
              newIdentNode("N"),
              newIdentNode("uint64")
            ),
            newEmptyNode()
          )
        )
      )
    )
  ),
  nnkFuncDef.newTree(
    newIdentNode("isZero"),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      newIdentNode("bool"),
      nnkIdentDefs.newTree(
        newIdentNode("a"),
        newIdentNode("BigInt"),
        newEmptyNode()
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkDiscardStmt.newTree(
        newEmptyNode()
      )
    )
  ),
  nnkFuncDef.newTree(
    newIdentNode("isOne"),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      newIdentNode("bool"),
      nnkIdentDefs.newTree(
        newIdentNode("a"),
        newIdentNode("BigInt"),
        newEmptyNode()
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkDiscardStmt.newTree(
        newEmptyNode()
      )
    )
  ),
  nnkTypeSection.newTree(
    nnkTypeDef.newTree(
      nnkPostfix.newTree(
        newIdentNode("*"),
        newIdentNode("QuadraticExt")
      ),
      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(2),
              newIdentNode("F")
            ),
            newEmptyNode()
          )
        )
      )
    ),
    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(
      nnkPostfix.newTree(
        newIdentNode("*"),
        newIdentNode("ExtensionField")
      ),
      nnkGenericParams.newTree(
        nnkIdentDefs.newTree(
          newIdentNode("F"),
          newEmptyNode(),
          newEmptyNode()
        )
      ),
      nnkInfix.newTree(
        newIdentNode("or"),
        nnkBracketExpr.newTree(
          newIdentNode("QuadraticExt"),
          newIdentNode("F")
        ),
        nnkBracketExpr.newTree(
          newIdentNode("CubicExt"),
          newIdentNode("F")
        )
      )
    )
  ),
  nnkFuncDef.newTree(
    nnkPostfix.newTree(
      newIdentNode("*"),
      newIdentNode("isOne")
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      newIdentNode("bool"),
      nnkIdentDefs.newTree(
        newIdentNode("a"),
        newIdentNode("ExtensionField"),
        newEmptyNode()
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      newCommentStmtNode("Constant-time check if one"),
      nnkAsgn.newTree(
        newIdentNode("result"),
        nnkUInt64Lit.newTree(
        )
      ),
      nnkAsgn.newTree(
        newIdentNode("result"),
        nnkInfix.newTree(
          newIdentNode("and"),
          newIdentNode("result"),
          nnkCall.newTree(
            nnkDotExpr.newTree(
              nnkBracketExpr.newTree(
                nnkDotExpr.newTree(
                  newIdentNode("a"),
                  newIdentNode("coords")
                ),
                newLit(0)
              ),
              newIdentNode("isOne")
            )
          )
        )
      ),
      nnkForStmt.newTree(
        newIdentNode("i"),
        nnkInfix.newTree(
          newIdentNode("..<"),
          newLit(1),
          nnkDotExpr.newTree(
            nnkDotExpr.newTree(
              newIdentNode("a"),
              newIdentNode("coords")
            ),
            newIdentNode("len")
          )
        ),
        nnkStmtList.newTree(
          nnkAsgn.newTree(
            newIdentNode("result"),
            nnkInfix.newTree(
              newIdentNode("and"),
              newIdentNode("result"),
              nnkCall.newTree(
                nnkDotExpr.newTree(
                  nnkBracketExpr.newTree(
                    nnkDotExpr.newTree(
                      newIdentNode("a"),
                      newIdentNode("coords")
                    ),
                    newIdentNode("i")
                  ),
                  newIdentNode("isZero")
                )
              )
            )
          )
        )
      )
    )
  ),
  nnkFuncDef.newTree(
    nnkPostfix.newTree(
      newIdentNode("*"),
      newIdentNode("mulCheckSparse")
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      newEmptyNode(),
      nnkIdentDefs.newTree(
        newIdentNode("a"),
        nnkVarTy.newTree(
          newIdentNode("QuadraticExt")
        ),
        newEmptyNode()
      ),
      nnkIdentDefs.newTree(
        newIdentNode("b"),
        nnkCommand.newTree(
          newIdentNode("static"),
          newIdentNode("QuadraticExt")
        ),
        newEmptyNode()
      )
    ),
    nnkPragma.newTree(
      newIdentNode("inline")
    ),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkStaticStmt.newTree(
        nnkStmtList.newTree(
          nnkCommand.newTree(
            newIdentNode("debugEcho"),
            newLit("QuadraticExt b: "),
            nnkInfix.newTree(
              newIdentNode("is"),
              newIdentNode("b"),
              newIdentNode("QuadraticExt")
            )
          ),
          nnkCommand.newTree(
            newIdentNode("debugEcho"),
            newLit("ExtensionField b: "),
            nnkInfix.newTree(
              newIdentNode("is"),
              newIdentNode("b"),
              newIdentNode("ExtensionField")
            )
          )
        )
      ),
      nnkWhenStmt.newTree(
        nnkElifBranch.newTree(
          nnkDotExpr.newTree(
            nnkCall.newTree(
              newIdentNode("isOne"),
              newIdentNode("b")
            ),
            newIdentNode("bool")
          ),
          nnkStmtList.newTree(
            nnkDiscardStmt.newTree(
              newEmptyNode()
            )
          )
        ),
        nnkElse.newTree(
          nnkStmtList.newTree(
            nnkCommand.newTree(
              newIdentNode("debugEcho"),
              newLit("a *= b")
            )
          )
        )
      )
    )
  ),
  nnkTypeSection.newTree(
    nnkTypeDef.newTree(
      nnkPostfix.newTree(
        newIdentNode("*"),
        newIdentNode("EllipticCurve")
      ),
      nnkGenericParams.newTree(
        nnkIdentDefs.newTree(
          newIdentNode("F"),
          newEmptyNode(),
          newEmptyNode()
        )
      ),
      nnkObjectTy.newTree(
        newEmptyNode(),
        newEmptyNode(),
        nnkRecList.newTree(
          nnkIdentDefs.newTree(
            nnkPostfix.newTree(
              newIdentNode("*"),
              newIdentNode("x")
            ),
            nnkPostfix.newTree(
              newIdentNode("*"),
              newIdentNode("y")
            ),
            nnkPostfix.newTree(
              newIdentNode("*"),
              newIdentNode("z")
            ),
            newIdentNode("F"),
            newEmptyNode()
          )
        )
      )
    )
  ),
  nnkTemplateDef.newTree(
    newIdentNode("sumImpl"),
    newEmptyNode(),
    nnkGenericParams.newTree(
      nnkIdentDefs.newTree(
        newIdentNode("F"),
        newEmptyNode(),
        newEmptyNode()
      )
    ),
    nnkFormalParams.newTree(
      newEmptyNode(),
      nnkIdentDefs.newTree(
        newIdentNode("r"),
        nnkVarTy.newTree(
          nnkBracketExpr.newTree(
            newIdentNode("EllipticCurve"),
            newIdentNode("F")
          )
        ),
        newEmptyNode()
      ),
      nnkIdentDefs.newTree(
        newIdentNode("P"),
        newIdentNode("Q"),
        nnkBracketExpr.newTree(
          newIdentNode("EllipticCurve"),
          newIdentNode("F")
        ),
        newEmptyNode()
      ),
      nnkIdentDefs.newTree(
        newIdentNode("CoefA"),
        newIdentNode("typed"),
        newEmptyNode()
      )
    ),
    nnkPragma.newTree(
      newIdentNode("dirty")
    ),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkWhenStmt.newTree(
        nnkElifBranch.newTree(
          nnkInfix.newTree(
            newIdentNode("is"),
            newIdentNode("CoefA"),
            newIdentNode("int")
          ),
          nnkStmtList.newTree(
            nnkCommand.newTree(
              newIdentNode("debugEcho"),
              newLit("EC addition with int CoefA")
            )
          )
        ),
        nnkElse.newTree(
          nnkStmtList.newTree(
            nnkVarSection.newTree(
              nnkIdentDefs.newTree(
                newIdentNode("b"),
                newEmptyNode(),
                nnkDotExpr.newTree(
                  newIdentNode("P"),
                  newIdentNode("x")
                )
              )
            ),
            nnkCall.newTree(
              nnkDotExpr.newTree(
                newIdentNode("b"),
                newIdentNode("mulCheckSparse")
              ),
              newIdentNode("CoefA")
            )
          )
        )
      )
    )
  ),
  nnkFuncDef.newTree(
    newIdentNode("sum"),
    newEmptyNode(),
    nnkGenericParams.newTree(
      nnkIdentDefs.newTree(
        newIdentNode("F"),
        newEmptyNode(),
        newEmptyNode()
      )
    ),
    nnkFormalParams.newTree(
      newEmptyNode(),
      nnkIdentDefs.newTree(
        newIdentNode("r"),
        nnkVarTy.newTree(
          nnkBracketExpr.newTree(
            newIdentNode("EllipticCurve"),
            newIdentNode("F")
          )
        ),
        newEmptyNode()
      ),
      nnkIdentDefs.newTree(
        newIdentNode("P"),
        newIdentNode("Q"),
        nnkBracketExpr.newTree(
          newIdentNode("EllipticCurve"),
          newIdentNode("F")
        ),
        newEmptyNode()
      ),
      nnkIdentDefs.newTree(
        newIdentNode("CoefA"),
        nnkCommand.newTree(
          newIdentNode("static"),
          newIdentNode("F")
        ),
        newEmptyNode()
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkCall.newTree(
        nnkDotExpr.newTree(
          newIdentNode("r"),
          newIdentNode("sumImpl")
        ),
        newIdentNode("P"),
        newIdentNode("Q"),
        newIdentNode("CoefA")
      )
    )
  ),
  newCommentStmtNode("----------------------------------"),
  nnkConstSection.newTree(
    nnkConstDef.newTree(
      newIdentNode("h2c_const_ec"),
      newEmptyNode(),
      nnkObjConstr.newTree(
        nnkBracketExpr.newTree(
          newIdentNode("QuadraticExt"),
          nnkBracketExpr.newTree(
            newIdentNode("BigInt"),
            newLit(4)
          )
        ),
        nnkExprColonExpr.newTree(
          newIdentNode("coords"),
          nnkBracket.newTree(
            nnkObjConstr.newTree(
              nnkBracketExpr.newTree(
                newIdentNode("BigInt"),
                newLit(4)
              ),
              nnkExprColonExpr.newTree(
                newIdentNode("raw"),
                nnkBracket.newTree(
                  nnkCommand.newTree(
                    newIdentNode("uint64"),
                    newLit(1)
                  ),
                  newLit(1),
                  newLit(1),
                  newLit(1)
                )
              )
            ),
            nnkObjConstr.newTree(
              nnkBracketExpr.newTree(
                newIdentNode("BigInt"),
                newLit(4)
              ),
              nnkExprColonExpr.newTree(
                newIdentNode("raw"),
                nnkBracket.newTree(
                  nnkCommand.newTree(
                    newIdentNode("uint64"),
                    newLit(1)
                  ),
                  newLit(1),
                  newLit(1),
                  newLit(1)
                )
              )
            )
          )
        )
      )
    )
  ),
  nnkVarSection.newTree(
    nnkIdentDefs.newTree(
      newIdentNode("P"),
      newEmptyNode(),
      nnkObjConstr.newTree(
        nnkBracketExpr.newTree(
          newIdentNode("EllipticCurve"),
          nnkBracketExpr.newTree(
            newIdentNode("QuadraticExt"),
            nnkBracketExpr.newTree(
              newIdentNode("BigInt"),
              newLit(4)
            )
          )
        ),
        nnkExprColonExpr.newTree(
          newIdentNode("x"),
          nnkObjConstr.newTree(
            nnkBracketExpr.newTree(
              newIdentNode("QuadraticExt"),
              nnkBracketExpr.newTree(
                newIdentNode("BigInt"),
                newLit(4)
              )
            ),
            nnkExprColonExpr.newTree(
              newIdentNode("coords"),
              nnkBracket.newTree(
                nnkObjConstr.newTree(
                  nnkBracketExpr.newTree(
                    newIdentNode("BigInt"),
                    newLit(4)
                  ),
                  nnkExprColonExpr.newTree(
                    newIdentNode("raw"),
                    nnkBracket.newTree(
                      nnkCommand.newTree(
                        newIdentNode("uint64"),
                        newLit(1)
                      ),
                      newLit(2),
                      newLit(3),
                      newLit(4)
                    )
                  )
                ),
                nnkObjConstr.newTree(
                  nnkBracketExpr.newTree(
                    newIdentNode("BigInt"),
                    newLit(4)
                  ),
                  nnkExprColonExpr.newTree(
                    newIdentNode("raw"),
                    nnkBracket.newTree(
                      nnkCommand.newTree(
                        newIdentNode("uint64"),
                        newLit(1)
                      ),
                      newLit(2),
                      newLit(3),
                      newLit(4)
                    )
                  )
                )
              )
            )
          )
        ),
        nnkExprColonExpr.newTree(
          newIdentNode("y"),
          nnkObjConstr.newTree(
            nnkBracketExpr.newTree(
              newIdentNode("QuadraticExt"),
              nnkBracketExpr.newTree(
                newIdentNode("BigInt"),
                newLit(4)
              )
            ),
            nnkExprColonExpr.newTree(
              newIdentNode("coords"),
              nnkBracket.newTree(
                nnkObjConstr.newTree(
                  nnkBracketExpr.newTree(
                    newIdentNode("BigInt"),
                    newLit(4)
                  ),
                  nnkExprColonExpr.newTree(
                    newIdentNode("raw"),
                    nnkBracket.newTree(
                      nnkCommand.newTree(
                        newIdentNode("uint64"),
                        newLit(1)
                      ),
                      newLit(2),
                      newLit(3),
                      newLit(4)
                    )
                  )
                ),
                nnkObjConstr.newTree(
                  nnkBracketExpr.newTree(
                    newIdentNode("BigInt"),
                    newLit(4)
                  ),
                  nnkExprColonExpr.newTree(
                    newIdentNode("raw"),
                    nnkBracket.newTree(
                      nnkCommand.newTree(
                        newIdentNode("uint64"),
                        newLit(1)
                      ),
                      newLit(2),
                      newLit(3),
                      newLit(4)
                    )
                  )
                )
              )
            )
          )
        ),
        nnkExprColonExpr.newTree(
          newIdentNode("z"),
          nnkObjConstr.newTree(
            nnkBracketExpr.newTree(
              newIdentNode("QuadraticExt"),
              nnkBracketExpr.newTree(
                newIdentNode("BigInt"),
                newLit(4)
              )
            ),
            nnkExprColonExpr.newTree(
              newIdentNode("coords"),
              nnkBracket.newTree(
                nnkObjConstr.newTree(
                  nnkBracketExpr.newTree(
                    newIdentNode("BigInt"),
                    newLit(4)
                  ),
                  nnkExprColonExpr.newTree(
                    newIdentNode("raw"),
                    nnkBracket.newTree(
                      nnkCommand.newTree(
                        newIdentNode("uint64"),
                        newLit(1)
                      ),
                      newLit(2),
                      newLit(3),
                      newLit(4)
                    )
                  )
                ),
                nnkObjConstr.newTree(
                  nnkBracketExpr.newTree(
                    newIdentNode("BigInt"),
                    newLit(4)
                  ),
                  nnkExprColonExpr.newTree(
                    newIdentNode("raw"),
                    nnkBracket.newTree(
                      nnkCommand.newTree(
                        newIdentNode("uint64"),
                        newLit(1)
                      ),
                      newLit(2),
                      newLit(3),
                      newLit(4)
                    )
                  )
                )
              )
            )
          )
        )
      )
    )
  ),
  nnkVarSection.newTree(
    nnkIdentDefs.newTree(
      newIdentNode("Q"),
      newEmptyNode(),
      nnkObjConstr.newTree(
        nnkBracketExpr.newTree(
          newIdentNode("EllipticCurve"),
          nnkBracketExpr.newTree(
            newIdentNode("QuadraticExt"),
            nnkBracketExpr.newTree(
              newIdentNode("BigInt"),
              newLit(4)
            )
          )
        ),
        nnkExprColonExpr.newTree(
          newIdentNode("x"),
          nnkObjConstr.newTree(
            nnkBracketExpr.newTree(
              newIdentNode("QuadraticExt"),
              nnkBracketExpr.newTree(
                newIdentNode("BigInt"),
                newLit(4)
              )
            ),
            nnkExprColonExpr.newTree(
              newIdentNode("coords"),
              nnkBracket.newTree(
                nnkObjConstr.newTree(
                  nnkBracketExpr.newTree(
                    newIdentNode("BigInt"),
                    newLit(4)
                  ),
                  nnkExprColonExpr.newTree(
                    newIdentNode("raw"),
                    nnkBracket.newTree(
                      nnkCommand.newTree(
                        newIdentNode("uint64"),
                        newLit(1)
                      ),
                      newLit(2),
                      newLit(3),
                      newLit(4)
                    )
                  )
                ),
                nnkObjConstr.newTree(
                  nnkBracketExpr.newTree(
                    newIdentNode("BigInt"),
                    newLit(4)
                  ),
                  nnkExprColonExpr.newTree(
                    newIdentNode("raw"),
                    nnkBracket.newTree(
                      nnkCommand.newTree(
                        newIdentNode("uint64"),
                        newLit(1)
                      ),
                      newLit(2),
                      newLit(3),
                      newLit(4)
                    )
                  )
                )
              )
            )
          )
        ),
        nnkExprColonExpr.newTree(
          newIdentNode("y"),
          nnkObjConstr.newTree(
            nnkBracketExpr.newTree(
              newIdentNode("QuadraticExt"),
              nnkBracketExpr.newTree(
                newIdentNode("BigInt"),
                newLit(4)
              )
            ),
            nnkExprColonExpr.newTree(
              newIdentNode("coords"),
              nnkBracket.newTree(
                nnkObjConstr.newTree(
                  nnkBracketExpr.newTree(
                    newIdentNode("BigInt"),
                    newLit(4)
                  ),
                  nnkExprColonExpr.newTree(
                    newIdentNode("raw"),
                    nnkBracket.newTree(
                      nnkCommand.newTree(
                        newIdentNode("uint64"),
                        newLit(1)
                      ),
                      newLit(2),
                      newLit(3),
                      newLit(4)
                    )
                  )
                ),
                nnkObjConstr.newTree(
                  nnkBracketExpr.newTree(
                    newIdentNode("BigInt"),
                    newLit(4)
                  ),
                  nnkExprColonExpr.newTree(
                    newIdentNode("raw"),
                    nnkBracket.newTree(
                      nnkCommand.newTree(
                        newIdentNode("uint64"),
                        newLit(1)
                      ),
                      newLit(2),
                      newLit(3),
                      newLit(4)
                    )
                  )
                )
              )
            )
          )
        ),
        nnkExprColonExpr.newTree(
          newIdentNode("z"),
          nnkObjConstr.newTree(
            nnkBracketExpr.newTree(
              newIdentNode("QuadraticExt"),
              nnkBracketExpr.newTree(
                newIdentNode("BigInt"),
                newLit(4)
              )
            ),
            nnkExprColonExpr.newTree(
              newIdentNode("coords"),
              nnkBracket.newTree(
                nnkObjConstr.newTree(
                  nnkBracketExpr.newTree(
                    newIdentNode("BigInt"),
                    newLit(4)
                  ),
                  nnkExprColonExpr.newTree(
                    newIdentNode("raw"),
                    nnkBracket.newTree(
                      nnkCommand.newTree(
                        newIdentNode("uint64"),
                        newLit(1)
                      ),
                      newLit(2),
                      newLit(3),
                      newLit(4)
                    )
                  )
                ),
                nnkObjConstr.newTree(
                  nnkBracketExpr.newTree(
                    newIdentNode("BigInt"),
                    newLit(4)
                  ),
                  nnkExprColonExpr.newTree(
                    newIdentNode("raw"),
                    nnkBracket.newTree(
                      nnkCommand.newTree(
                        newIdentNode("uint64"),
                        newLit(1)
                      ),
                      newLit(2),
                      newLit(3),
                      newLit(4)
                    )
                  )
                )
              )
            )
          )
        )
      )
    )
  ),
  nnkVarSection.newTree(
    nnkIdentDefs.newTree(
      newIdentNode("R"),
      nnkBracketExpr.newTree(
        newIdentNode("EllipticCurve"),
        nnkBracketExpr.newTree(
          newIdentNode("QuadraticExt"),
          nnkBracketExpr.newTree(
            newIdentNode("BigInt"),
            newLit(4)
          )
        )
      ),
      newEmptyNode()
    )
  ),
  nnkCall.newTree(
    nnkDotExpr.newTree(
      newIdentNode("R"),
      newIdentNode("sum")
    ),
    newIdentNode("P"),
    newIdentNode("Q"),
    newIdentNode("h2c_const_ec")
  )
)
1.6.14 👎 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(79, 2) template/generic instantiation of `sum` from here
/home/runner/work/Nim/Nim/temp.nim(44, 4) template/generic instantiation of `sumImpl` from here
/home/runner/work/Nim/Nim/temp.nim(39, 6) template/generic instantiation of `mulCheckSparse` from here
/home/runner/work/Nim/Nim/temp.nim(25, 13) Error: type mismatch: got <QuadraticExt>
but expected one of:
func isOne(a: BigInt): bool
  first type mismatch at position: 1
  required type for a: BigInt
  but expression '(coords: [(raw: [1'u, 1'u, 1'u, 1'u]), (raw: [1'u, 1'u, 1'u, 1'u])])' is of type: QuadraticExt
func isOne(a: ExtensionField): bool
  first type mismatch at position: 1
  required type for a: ExtensionField
  but expression '(coords: [(raw: [1'u, 1'u, 1'u, 1'u]), (raw: [1'u, 1'u, 1'u, 1'u])])' is of type: QuadraticExt

expression: isOne((coords: [(raw: [1'u, 1'u, 1'u, 1'u]), (raw: [1'u, 1'u, 1'u, 1'u])]))
fatal.nim(54)            sysFatal
Error: unhandled exception: options.nim(645, 14) `false` errGenerated [AssertionDefect]

IR

Compiled filesize 0 bytes (0 bytes)

Stats

  • Started 2024-04-29T11:46:16
  • Finished 2024-04-29T11:46:16
  • Duration

AST

nnkStmtList.newTree(
  nnkTypeSection.newTree(
    nnkTypeDef.newTree(
      newIdentNode("BigInt"),
      nnkGenericParams.newTree(
        nnkIdentDefs.newTree(
          newIdentNode("N"),
          nnkCommand.newTree(
            newIdentNode("static"),
            newIdentNode("int")
          ),
          newEmptyNode()
        )
      ),
      nnkObjectTy.newTree(
        newEmptyNode(),
        newEmptyNode(),
        nnkRecList.newTree(
          nnkIdentDefs.newTree(
            newIdentNode("raw"),
            nnkBracketExpr.newTree(
              newIdentNode("array"),
              newIdentNode("N"),
              newIdentNode("uint64")
            ),
            newEmptyNode()
          )
        )
      )
    )
  ),
  nnkFuncDef.newTree(
    newIdentNode("isZero"),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      newIdentNode("bool"),
      nnkIdentDefs.newTree(
        newIdentNode("a"),
        newIdentNode("BigInt"),
        newEmptyNode()
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkDiscardStmt.newTree(
        newEmptyNode()
      )
    )
  ),
  nnkFuncDef.newTree(
    newIdentNode("isOne"),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      newIdentNode("bool"),
      nnkIdentDefs.newTree(
        newIdentNode("a"),
        newIdentNode("BigInt"),
        newEmptyNode()
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkDiscardStmt.newTree(
        newEmptyNode()
      )
    )
  ),
  nnkTypeSection.newTree(
    nnkTypeDef.newTree(
      nnkPostfix.newTree(
        newIdentNode("*"),
        newIdentNode("QuadraticExt")
      ),
      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(2),
              newIdentNode("F")
            ),
            newEmptyNode()
          )
        )
      )
    ),
    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(
      nnkPostfix.newTree(
        newIdentNode("*"),
        newIdentNode("ExtensionField")
      ),
      nnkGenericParams.newTree(
        nnkIdentDefs.newTree(
          newIdentNode("F"),
          newEmptyNode(),
          newEmptyNode()
        )
      ),
      nnkInfix.newTree(
        newIdentNode("or"),
        nnkBracketExpr.newTree(
          newIdentNode("QuadraticExt"),
          newIdentNode("F")
        ),
        nnkBracketExpr.newTree(
          newIdentNode("CubicExt"),
          newIdentNode("F")
        )
      )
    )
  ),
  nnkFuncDef.newTree(
    nnkPostfix.newTree(
      newIdentNode("*"),
      newIdentNode("isOne")
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      newIdentNode("bool"),
      nnkIdentDefs.newTree(
        newIdentNode("a"),
        newIdentNode("ExtensionField"),
        newEmptyNode()
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      newCommentStmtNode("Constant-time check if one"),
      nnkAsgn.newTree(
        newIdentNode("result"),
        nnkUInt64Lit.newTree(
        )
      ),
      nnkAsgn.newTree(
        newIdentNode("result"),
        nnkInfix.newTree(
          newIdentNode("and"),
          newIdentNode("result"),
          nnkCall.newTree(
            nnkDotExpr.newTree(
              nnkBracketExpr.newTree(
                nnkDotExpr.newTree(
                  newIdentNode("a"),
                  newIdentNode("coords")
                ),
                newLit(0)
              ),
              newIdentNode("isOne")
            )
          )
        )
      ),
      nnkForStmt.newTree(
        newIdentNode("i"),
        nnkInfix.newTree(
          newIdentNode("..<"),
          newLit(1),
          nnkDotExpr.newTree(
            nnkDotExpr.newTree(
              newIdentNode("a"),
              newIdentNode("coords")
            ),
            newIdentNode("len")
          )
        ),
        nnkStmtList.newTree(
          nnkAsgn.newTree(
            newIdentNode("result"),
            nnkInfix.newTree(
              newIdentNode("and"),
              newIdentNode("result"),
              nnkCall.newTree(
                nnkDotExpr.newTree(
                  nnkBracketExpr.newTree(
                    nnkDotExpr.newTree(
                      newIdentNode("a"),
                      newIdentNode("coords")
                    ),
                    newIdentNode("i")
                  ),
                  newIdentNode("isZero")
                )
              )
            )
          )
        )
      )
    )
  ),
  nnkFuncDef.newTree(
    nnkPostfix.newTree(
      newIdentNode("*"),
      newIdentNode("mulCheckSparse")
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      newEmptyNode(),
      nnkIdentDefs.newTree(
        newIdentNode("a"),
        nnkVarTy.newTree(
          newIdentNode("QuadraticExt")
        ),
        newEmptyNode()
      ),
      nnkIdentDefs.newTree(
        newIdentNode("b"),
        nnkCommand.newTree(
          newIdentNode("static"),
          newIdentNode("QuadraticExt")
        ),
        newEmptyNode()
      )
    ),
    nnkPragma.newTree(
      newIdentNode("inline")
    ),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkStaticStmt.newTree(
        nnkStmtList.newTree(
          nnkCommand.newTree(
            newIdentNode("debugEcho"),
            newLit("QuadraticExt b: "),
            nnkInfix.newTree(
              newIdentNode("is"),
              newIdentNode("b"),
              newIdentNode("QuadraticExt")
            )
          ),
          nnkCommand.newTree(
            newIdentNode("debugEcho"),
            newLit("ExtensionField b: "),
            nnkInfix.newTree(
              newIdentNode("is"),
              newIdentNode("b"),
              newIdentNode("ExtensionField")
            )
          )
        )
      ),
      nnkWhenStmt.newTree(
        nnkElifBranch.newTree(
          nnkDotExpr.newTree(
            nnkCall.newTree(
              newIdentNode("isOne"),
              newIdentNode("b")
            ),
            newIdentNode("bool")
          ),
          nnkStmtList.newTree(
            nnkDiscardStmt.newTree(
              newEmptyNode()
            )
          )
        ),
        nnkElse.newTree(
          nnkStmtList.newTree(
            nnkCommand.newTree(
              newIdentNode("debugEcho"),
              newLit("a *= b")
            )
          )
        )
      )
    )
  ),
  nnkTypeSection.newTree(
    nnkTypeDef.newTree(
      nnkPostfix.newTree(
        newIdentNode("*"),
        newIdentNode("EllipticCurve")
      ),
      nnkGenericParams.newTree(
        nnkIdentDefs.newTree(
          newIdentNode("F"),
          newEmptyNode(),
          newEmptyNode()
        )
      ),
      nnkObjectTy.newTree(
        newEmptyNode(),
        newEmptyNode(),
        nnkRecList.newTree(
          nnkIdentDefs.newTree(
            nnkPostfix.newTree(
              newIdentNode("*"),
              newIdentNode("x")
            ),
            nnkPostfix.newTree(
              newIdentNode("*"),
              newIdentNode("y")
            ),
            nnkPostfix.newTree(
              newIdentNode("*"),
              newIdentNode("z")
            ),
            newIdentNode("F"),
            newEmptyNode()
          )
        )
      )
    )
  ),
  nnkTemplateDef.newTree(
    newIdentNode("sumImpl"),
    newEmptyNode(),
    nnkGenericParams.newTree(
      nnkIdentDefs.newTree(
        newIdentNode("F"),
        newEmptyNode(),
        newEmptyNode()
      )
    ),
    nnkFormalParams.newTree(
      newEmptyNode(),
      nnkIdentDefs.newTree(
        newIdentNode("r"),
        nnkVarTy.newTree(
          nnkBracketExpr.newTree(
            newIdentNode("EllipticCurve"),
            newIdentNode("F")
          )
        ),
        newEmptyNode()
      ),
      nnkIdentDefs.newTree(
        newIdentNode("P"),
        newIdentNode("Q"),
        nnkBracketExpr.newTree(
          newIdentNode("EllipticCurve"),
          newIdentNode("F")
        ),
        newEmptyNode()
      ),
      nnkIdentDefs.newTree(
        newIdentNode("CoefA"),
        newIdentNode("typed"),
        newEmptyNode()
      )
    ),
    nnkPragma.newTree(
      newIdentNode("dirty")
    ),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkWhenStmt.newTree(
        nnkElifBranch.newTree(
          nnkInfix.newTree(
            newIdentNode("is"),
            newIdentNode("CoefA"),
            newIdentNode("int")
          ),
          nnkStmtList.newTree(
            nnkCommand.newTree(
              newIdentNode("debugEcho"),
              newLit("EC addition with int CoefA")
            )
          )
        ),
        nnkElse.newTree(
          nnkStmtList.newTree(
            nnkVarSection.newTree(
              nnkIdentDefs.newTree(
                newIdentNode("b"),
                newEmptyNode(),
                nnkDotExpr.newTree(
                  newIdentNode("P"),
                  newIdentNode("x")
                )
              )
            ),
            nnkCall.newTree(
              nnkDotExpr.newTree(
                newIdentNode("b"),
                newIdentNode("mulCheckSparse")
              ),
              newIdentNode("CoefA")
            )
          )
        )
      )
    )
  ),
  nnkFuncDef.newTree(
    newIdentNode("sum"),
    newEmptyNode(),
    nnkGenericParams.newTree(
      nnkIdentDefs.newTree(
        newIdentNode("F"),
        newEmptyNode(),
        newEmptyNode()
      )
    ),
    nnkFormalParams.newTree(
      newEmptyNode(),
      nnkIdentDefs.newTree(
        newIdentNode("r"),
        nnkVarTy.newTree(
          nnkBracketExpr.newTree(
            newIdentNode("EllipticCurve"),
            newIdentNode("F")
          )
        ),
        newEmptyNode()
      ),
      nnkIdentDefs.newTree(
        newIdentNode("P"),
        newIdentNode("Q"),
        nnkBracketExpr.newTree(
          newIdentNode("EllipticCurve"),
          newIdentNode("F")
        ),
        newEmptyNode()
      ),
      nnkIdentDefs.newTree(
        newIdentNode("CoefA"),
        nnkCommand.newTree(
          newIdentNode("static"),
          newIdentNode("F")
        ),
        newEmptyNode()
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkCall.newTree(
        nnkDotExpr.newTree(
          newIdentNode("r"),
          newIdentNode("sumImpl")
        ),
        newIdentNode("P"),
        newIdentNode("Q"),
        newIdentNode("CoefA")
      )
    )
  ),
  newCommentStmtNode("----------------------------------"),
  nnkConstSection.newTree(
    nnkConstDef.newTree(
      newIdentNode("h2c_const_ec"),
      newEmptyNode(),
      nnkObjConstr.newTree(
        nnkBracketExpr.newTree(
          newIdentNode("QuadraticExt"),
          nnkBracketExpr.newTree(
            newIdentNode("BigInt"),
            newLit(4)
          )
        ),
        nnkExprColonExpr.newTree(
          newIdentNode("coords"),
          nnkBracket.newTree(
            nnkObjConstr.newTree(
              nnkBracketExpr.newTree(
                newIdentNode("BigInt"),
                newLit(4)
              ),
              nnkExprColonExpr.newTree(
                newIdentNode("raw"),
                nnkBracket.newTree(
                  nnkCommand.newTree(
                    newIdentNode("uint64"),
                    newLit(1)
                  ),
                  newLit(1),
                  newLit(1),
                  newLit(1)
                )
              )
            ),
            nnkObjConstr.newTree(
              nnkBracketExpr.newTree(
                newIdentNode("BigInt"),
                newLit(4)
              ),
              nnkExprColonExpr.newTree(
                newIdentNode("raw"),
                nnkBracket.newTree(
                  nnkCommand.newTree(
                    newIdentNode("uint64"),
                    newLit(1)
                  ),
                  newLit(1),
                  newLit(1),
                  newLit(1)
                )
              )
            )
          )
        )
      )
    )
  ),
  nnkVarSection.newTree(
    nnkIdentDefs.newTree(
      newIdentNode("P"),
      newEmptyNode(),
      nnkObjConstr.newTree(
        nnkBracketExpr.newTree(
          newIdentNode("EllipticCurve"),
          nnkBracketExpr.newTree(
            newIdentNode("QuadraticExt"),
            nnkBracketExpr.newTree(
              newIdentNode("BigInt"),
              newLit(4)
            )
          )
        ),
        nnkExprColonExpr.newTree(
          newIdentNode("x"),
          nnkObjConstr.newTree(
            nnkBracketExpr.newTree(
              newIdentNode("QuadraticExt"),
              nnkBracketExpr.newTree(
                newIdentNode("BigInt"),
                newLit(4)
              )
            ),
            nnkExprColonExpr.newTree(
              newIdentNode("coords"),
              nnkBracket.newTree(
                nnkObjConstr.newTree(
                  nnkBracketExpr.newTree(
                    newIdentNode("BigInt"),
                    newLit(4)
                  ),
                  nnkExprColonExpr.newTree(
                    newIdentNode("raw"),
                    nnkBracket.newTree(
                      nnkCommand.newTree(
                        newIdentNode("uint64"),
                        newLit(1)
                      ),
                      newLit(2),
                      newLit(3),
                      newLit(4)
                    )
                  )
                ),
                nnkObjConstr.newTree(
                  nnkBracketExpr.newTree(
                    newIdentNode("BigInt"),
                    newLit(4)
                  ),
                  nnkExprColonExpr.newTree(
                    newIdentNode("raw"),
                    nnkBracket.newTree(
                      nnkCommand.newTree(
                        newIdentNode("uint64"),
                        newLit(1)
                      ),
                      newLit(2),
                      newLit(3),
                      newLit(4)
                    )
                  )
                )
              )
            )
          )
        ),
        nnkExprColonExpr.newTree(
          newIdentNode("y"),
          nnkObjConstr.newTree(
            nnkBracketExpr.newTree(
              newIdentNode("QuadraticExt"),
              nnkBracketExpr.newTree(
                newIdentNode("BigInt"),
                newLit(4)
              )
            ),
            nnkExprColonExpr.newTree(
              newIdentNode("coords"),
              nnkBracket.newTree(
                nnkObjConstr.newTree(
                  nnkBracketExpr.newTree(
                    newIdentNode("BigInt"),
                    newLit(4)
                  ),
                  nnkExprColonExpr.newTree(
                    newIdentNode("raw"),
                    nnkBracket.newTree(
                      nnkCommand.newTree(
                        newIdentNode("uint64"),
                        newLit(1)
                      ),
                      newLit(2),
                      newLit(3),
                      newLit(4)
                    )
                  )
                ),
                nnkObjConstr.newTree(
                  nnkBracketExpr.newTree(
                    newIdentNode("BigInt"),
                    newLit(4)
                  ),
                  nnkExprColonExpr.newTree(
                    newIdentNode("raw"),
                    nnkBracket.newTree(
                      nnkCommand.newTree(
                        newIdentNode("uint64"),
                        newLit(1)
                      ),
                      newLit(2),
                      newLit(3),
                      newLit(4)
                    )
                  )
                )
              )
            )
          )
        ),
        nnkExprColonExpr.newTree(
          newIdentNode("z"),
          nnkObjConstr.newTree(
            nnkBracketExpr.newTree(
              newIdentNode("QuadraticExt"),
              nnkBracketExpr.newTree(
                newIdentNode("BigInt"),
                newLit(4)
              )
            ),
            nnkExprColonExpr.newTree(
              newIdentNode("coords"),
              nnkBracket.newTree(
                nnkObjConstr.newTree(
                  nnkBracketExpr.newTree(
                    newIdentNode("BigInt"),
                    newLit(4)
                  ),
                  nnkExprColonExpr.newTree(
                    newIdentNode("raw"),
                    nnkBracket.newTree(
                      nnkCommand.newTree(
                        newIdentNode("uint64"),
                        newLit(1)
                      ),
                      newLit(2),
                      newLit(3),
                      newLit(4)
                    )
                  )
                ),
                nnkObjConstr.newTree(
                  nnkBracketExpr.newTree(
                    newIdentNode("BigInt"),
                    newLit(4)
                  ),
                  nnkExprColonExpr.newTree(
                    newIdentNode("raw"),
                    nnkBracket.newTree(
                      nnkCommand.newTree(
                        newIdentNode("uint64"),
                        newLit(1)
                      ),
                      newLit(2),
                      newLit(3),
                      newLit(4)
                    )
                  )
                )
              )
            )
          )
        )
      )
    )
  ),
  nnkVarSection.newTree(
    nnkIdentDefs.newTree(
      newIdentNode("Q"),
      newEmptyNode(),
      nnkObjConstr.newTree(
        nnkBracketExpr.newTree(
          newIdentNode("EllipticCurve"),
          nnkBracketExpr.newTree(
            newIdentNode("QuadraticExt"),
            nnkBracketExpr.newTree(
              newIdentNode("BigInt"),
              newLit(4)
            )
          )
        ),
        nnkExprColonExpr.newTree(
          newIdentNode("x"),
          nnkObjConstr.newTree(
            nnkBracketExpr.newTree(
              newIdentNode("QuadraticExt"),
              nnkBracketExpr.newTree(
                newIdentNode("BigInt"),
                newLit(4)
              )
            ),
            nnkExprColonExpr.newTree(
              newIdentNode("coords"),
              nnkBracket.newTree(
                nnkObjConstr.newTree(
                  nnkBracketExpr.newTree(
                    newIdentNode("BigInt"),
                    newLit(4)
                  ),
                  nnkExprColonExpr.newTree(
                    newIdentNode("raw"),
                    nnkBracket.newTree(
                      nnkCommand.newTree(
                        newIdentNode("uint64"),
                        newLit(1)
                      ),
                      newLit(2),
                      newLit(3),
                      newLit(4)
                    )
                  )
                ),
                nnkObjConstr.newTree(
                  nnkBracketExpr.newTree(
                    newIdentNode("BigInt"),
                    newLit(4)
                  ),
                  nnkExprColonExpr.newTree(
                    newIdentNode("raw"),
                    nnkBracket.newTree(
                      nnkCommand.newTree(
                        newIdentNode("uint64"),
                        newLit(1)
                      ),
                      newLit(2),
                      newLit(3),
                      newLit(4)
                    )
                  )
                )
              )
            )
          )
        ),
        nnkExprColonExpr.newTree(
          newIdentNode("y"),
          nnkObjConstr.newTree(
            nnkBracketExpr.newTree(
              newIdentNode("QuadraticExt"),
              nnkBracketExpr.newTree(
                newIdentNode("BigInt"),
                newLit(4)
              )
            ),
            nnkExprColonExpr.newTree(
              newIdentNode("coords"),
              nnkBracket.newTree(
                nnkObjConstr.newTree(
                  nnkBracketExpr.newTree(
                    newIdentNode("BigInt"),
                    newLit(4)
                  ),
                  nnkExprColonExpr.newTree(
                    newIdentNode("raw"),
                    nnkBracket.newTree(
                      nnkCommand.newTree(
                        newIdentNode("uint64"),
                        newLit(1)
                      ),
                      newLit(2),
                      newLit(3),
                      newLit(4)
                    )
                  )
                ),
                nnkObjConstr.newTree(
                  nnkBracketExpr.newTree(
                    newIdentNode("BigInt"),
                    newLit(4)
                  ),
                  nnkExprColonExpr.newTree(
                    newIdentNode("raw"),
                    nnkBracket.newTree(
                      nnkCommand.newTree(
                        newIdentNode("uint64"),
                        newLit(1)
                      ),
                      newLit(2),
                      newLit(3),
                      newLit(4)
                    )
                  )
                )
              )
            )
          )
        ),
        nnkExprColonExpr.newTree(
          newIdentNode("z"),
          nnkObjConstr.newTree(
            nnkBracketExpr.newTree(
              newIdentNode("QuadraticExt"),
              nnkBracketExpr.newTree(
                newIdentNode("BigInt"),
                newLit(4)
              )
            ),
            nnkExprColonExpr.newTree(
              newIdentNode("coords"),
              nnkBracket.newTree(
                nnkObjConstr.newTree(
                  nnkBracketExpr.newTree(
                    newIdentNode("BigInt"),
                    newLit(4)
                  ),
                  nnkExprColonExpr.newTree(
                    newIdentNode("raw"),
                    nnkBracket.newTree(
                      nnkCommand.newTree(
                        newIdentNode("uint64"),
                        newLit(1)
                      ),
                      newLit(2),
                      newLit(3),
                      newLit(4)
                    )
                  )
                ),
                nnkObjConstr.newTree(
                  nnkBracketExpr.newTree(
                    newIdentNode("BigInt"),
                    newLit(4)
                  ),
                  nnkExprColonExpr.newTree(
                    newIdentNode("raw"),
                    nnkBracket.newTree(
                      nnkCommand.newTree(
                        newIdentNode("uint64"),
                        newLit(1)
                      ),
                      newLit(2),
                      newLit(3),
                      newLit(4)
                    )
                  )
                )
              )
            )
          )
        )
      )
    )
  ),
  nnkVarSection.newTree(
    nnkIdentDefs.newTree(
      newIdentNode("R"),
      nnkBracketExpr.newTree(
        newIdentNode("EllipticCurve"),
        nnkBracketExpr.newTree(
          newIdentNode("QuadraticExt"),
          nnkBracketExpr.newTree(
            newIdentNode("BigInt"),
            newLit(4)
          )
        )
      ),
      newEmptyNode()
    )
  ),
  nnkCall.newTree(
    nnkDotExpr.newTree(
      newIdentNode("R"),
      newIdentNode("sum")
    ),
    newIdentNode("P"),
    newIdentNode("Q"),
    newIdentNode("h2c_const_ec")
  )
)
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(79, 2) template/generic instantiation of `sum` from here
/home/runner/work/Nim/Nim/temp.nim(44, 4) template/generic instantiation of `sumImpl` from here
/home/runner/work/Nim/Nim/temp.nim(39, 6) template/generic instantiation of `mulCheckSparse` from here
/home/runner/work/Nim/Nim/temp.nim(25, 13) Error: type mismatch: got <QuadraticExt>
but expected one of: 
func isOne(a: BigInt): bool
  first type mismatch at position: 1
  required type for a: BigInt
  but expression '(coords: [(raw: [1'u, 1'u, 1'u, 1'u]), (raw: [1'u, 1'u, 1'u, 1'u])])' is of type: QuadraticExt
func isOne(a: ExtensionField): bool
  first type mismatch at position: 1
  required type for a: ExtensionField
  but expression '(coords: [(raw: [1'u, 1'u, 1'u, 1'u]), (raw: [1'u, 1'u, 1'u, 1'u])])' is of type: QuadraticExt

expression: isOne((coords: [(raw: [1'u, 1'u, 1'u, 1'u]), (raw: [1'u, 1'u, 1'u, 1'u])]))

IR

Compiled filesize 0 bytes (0 bytes)

Stats

  • Started 2024-04-29T11:46:19
  • Finished 2024-04-29T11:46:19
  • Duration

AST

nnkStmtList.newTree(
  nnkTypeSection.newTree(
    nnkTypeDef.newTree(
      newIdentNode("BigInt"),
      nnkGenericParams.newTree(
        nnkIdentDefs.newTree(
          newIdentNode("N"),
          nnkCommand.newTree(
            newIdentNode("static"),
            newIdentNode("int")
          ),
          newEmptyNode()
        )
      ),
      nnkObjectTy.newTree(
        newEmptyNode(),
        newEmptyNode(),
        nnkRecList.newTree(
          nnkIdentDefs.newTree(
            newIdentNode("raw"),
            nnkBracketExpr.newTree(
              newIdentNode("array"),
              newIdentNode("N"),
              newIdentNode("uint64")
            ),
            newEmptyNode()
          )
        )
      )
    )
  ),
  nnkFuncDef.newTree(
    newIdentNode("isZero"),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      newIdentNode("bool"),
      nnkIdentDefs.newTree(
        newIdentNode("a"),
        newIdentNode("BigInt"),
        newEmptyNode()
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkDiscardStmt.newTree(
        newEmptyNode()
      )
    )
  ),
  nnkFuncDef.newTree(
    newIdentNode("isOne"),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      newIdentNode("bool"),
      nnkIdentDefs.newTree(
        newIdentNode("a"),
        newIdentNode("BigInt"),
        newEmptyNode()
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkDiscardStmt.newTree(
        newEmptyNode()
      )
    )
  ),
  nnkTypeSection.newTree(
    nnkTypeDef.newTree(
      nnkPostfix.newTree(
        newIdentNode("*"),
        newIdentNode("QuadraticExt")
      ),
      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(2),
              newIdentNode("F")
            ),
            newEmptyNode()
          )
        )
      )
    ),
    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(
      nnkPostfix.newTree(
        newIdentNode("*"),
        newIdentNode("ExtensionField")
      ),
      nnkGenericParams.newTree(
        nnkIdentDefs.newTree(
          newIdentNode("F"),
          newEmptyNode(),
          newEmptyNode()
        )
      ),
      nnkInfix.newTree(
        newIdentNode("or"),
        nnkBracketExpr.newTree(
          newIdentNode("QuadraticExt"),
          newIdentNode("F")
        ),
        nnkBracketExpr.newTree(
          newIdentNode("CubicExt"),
          newIdentNode("F")
        )
      )
    )
  ),
  nnkFuncDef.newTree(
    nnkPostfix.newTree(
      newIdentNode("*"),
      newIdentNode("isOne")
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      newIdentNode("bool"),
      nnkIdentDefs.newTree(
        newIdentNode("a"),
        newIdentNode("ExtensionField"),
        newEmptyNode()
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      newCommentStmtNode("Constant-time check if one"),
      nnkAsgn.newTree(
        newIdentNode("result"),
        nnkUInt64Lit.newTree(
        )
      ),
      nnkAsgn.newTree(
        newIdentNode("result"),
        nnkInfix.newTree(
          newIdentNode("and"),
          newIdentNode("result"),
          nnkCall.newTree(
            nnkDotExpr.newTree(
              nnkBracketExpr.newTree(
                nnkDotExpr.newTree(
                  newIdentNode("a"),
                  newIdentNode("coords")
                ),
                newLit(0)
              ),
              newIdentNode("isOne")
            )
          )
        )
      ),
      nnkForStmt.newTree(
        newIdentNode("i"),
        nnkInfix.newTree(
          newIdentNode("..<"),
          newLit(1),
          nnkDotExpr.newTree(
            nnkDotExpr.newTree(
              newIdentNode("a"),
              newIdentNode("coords")
            ),
            newIdentNode("len")
          )
        ),
        nnkStmtList.newTree(
          nnkAsgn.newTree(
            newIdentNode("result"),
            nnkInfix.newTree(
              newIdentNode("and"),
              newIdentNode("result"),
              nnkCall.newTree(
                nnkDotExpr.newTree(
                  nnkBracketExpr.newTree(
                    nnkDotExpr.newTree(
                      newIdentNode("a"),
                      newIdentNode("coords")
                    ),
                    newIdentNode("i")
                  ),
                  newIdentNode("isZero")
                )
              )
            )
          )
        )
      )
    )
  ),
  nnkFuncDef.newTree(
    nnkPostfix.newTree(
      newIdentNode("*"),
      newIdentNode("mulCheckSparse")
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      newEmptyNode(),
      nnkIdentDefs.newTree(
        newIdentNode("a"),
        nnkVarTy.newTree(
          newIdentNode("QuadraticExt")
        ),
        newEmptyNode()
      ),
      nnkIdentDefs.newTree(
        newIdentNode("b"),
        nnkCommand.newTree(
          newIdentNode("static"),
          newIdentNode("QuadraticExt")
        ),
        newEmptyNode()
      )
    ),
    nnkPragma.newTree(
      newIdentNode("inline")
    ),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkStaticStmt.newTree(
        nnkStmtList.newTree(
          nnkCommand.newTree(
            newIdentNode("debugEcho"),
            newLit("QuadraticExt b: "),
            nnkInfix.newTree(
              newIdentNode("is"),
              newIdentNode("b"),
              newIdentNode("QuadraticExt")
            )
          ),
          nnkCommand.newTree(
            newIdentNode("debugEcho"),
            newLit("ExtensionField b: "),
            nnkInfix.newTree(
              newIdentNode("is"),
              newIdentNode("b"),
              newIdentNode("ExtensionField")
            )
          )
        )
      ),
      nnkWhenStmt.newTree(
        nnkElifBranch.newTree(
          nnkDotExpr.newTree(
            nnkCall.newTree(
              newIdentNode("isOne"),
              newIdentNode("b")
            ),
            newIdentNode("bool")
          ),
          nnkStmtList.newTree(
            nnkDiscardStmt.newTree(
              newEmptyNode()
            )
          )
        ),
        nnkElse.newTree(
          nnkStmtList.newTree(
            nnkCommand.newTree(
              newIdentNode("debugEcho"),
              newLit("a *= b")
            )
          )
        )
      )
    )
  ),
  nnkTypeSection.newTree(
    nnkTypeDef.newTree(
      nnkPostfix.newTree(
        newIdentNode("*"),
        newIdentNode("EllipticCurve")
      ),
      nnkGenericParams.newTree(
        nnkIdentDefs.newTree(
          newIdentNode("F"),
          newEmptyNode(),
          newEmptyNode()
        )
      ),
      nnkObjectTy.newTree(
        newEmptyNode(),
        newEmptyNode(),
        nnkRecList.newTree(
          nnkIdentDefs.newTree(
            nnkPostfix.newTree(
              newIdentNode("*"),
              newIdentNode("x")
            ),
            nnkPostfix.newTree(
              newIdentNode("*"),
              newIdentNode("y")
            ),
            nnkPostfix.newTree(
              newIdentNode("*"),
              newIdentNode("z")
            ),
            newIdentNode("F"),
            newEmptyNode()
          )
        )
      )
    )
  ),
  nnkTemplateDef.newTree(
    newIdentNode("sumImpl"),
    newEmptyNode(),
    nnkGenericParams.newTree(
      nnkIdentDefs.newTree(
        newIdentNode("F"),
        newEmptyNode(),
        newEmptyNode()
      )
    ),
    nnkFormalParams.newTree(
      newEmptyNode(),
      nnkIdentDefs.newTree(
        newIdentNode("r"),
        nnkVarTy.newTree(
          nnkBracketExpr.newTree(
            newIdentNode("EllipticCurve"),
            newIdentNode("F")
          )
        ),
        newEmptyNode()
      ),
      nnkIdentDefs.newTree(
        newIdentNode("P"),
        newIdentNode("Q"),
        nnkBracketExpr.newTree(
          newIdentNode("EllipticCurve"),
          newIdentNode("F")
        ),
        newEmptyNode()
      ),
      nnkIdentDefs.newTree(
        newIdentNode("CoefA"),
        newIdentNode("typed"),
        newEmptyNode()
      )
    ),
    nnkPragma.newTree(
      newIdentNode("dirty")
    ),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkWhenStmt.newTree(
        nnkElifBranch.newTree(
          nnkInfix.newTree(
            newIdentNode("is"),
            newIdentNode("CoefA"),
            newIdentNode("int")
          ),
          nnkStmtList.newTree(
            nnkCommand.newTree(
              newIdentNode("debugEcho"),
              newLit("EC addition with int CoefA")
            )
          )
        ),
        nnkElse.newTree(
          nnkStmtList.newTree(
            nnkVarSection.newTree(
              nnkIdentDefs.newTree(
                newIdentNode("b"),
                newEmptyNode(),
                nnkDotExpr.newTree(
                  newIdentNode("P"),
                  newIdentNode("x")
                )
              )
            ),
            nnkCall.newTree(
              nnkDotExpr.newTree(
                newIdentNode("b"),
                newIdentNode("mulCheckSparse")
              ),
              newIdentNode("CoefA")
            )
          )
        )
      )
    )
  ),
  nnkFuncDef.newTree(
    newIdentNode("sum"),
    newEmptyNode(),
    nnkGenericParams.newTree(
      nnkIdentDefs.newTree(
        newIdentNode("F"),
        newEmptyNode(),
        newEmptyNode()
      )
    ),
    nnkFormalParams.newTree(
      newEmptyNode(),
      nnkIdentDefs.newTree(
        newIdentNode("r"),
        nnkVarTy.newTree(
          nnkBracketExpr.newTree(
            newIdentNode("EllipticCurve"),
            newIdentNode("F")
          )
        ),
        newEmptyNode()
      ),
      nnkIdentDefs.newTree(
        newIdentNode("P"),
        newIdentNode("Q"),
        nnkBracketExpr.newTree(
          newIdentNode("EllipticCurve"),
          newIdentNode("F")
        ),
        newEmptyNode()
      ),
      nnkIdentDefs.newTree(
        newIdentNode("CoefA"),
        nnkCommand.newTree(
          newIdentNode("static"),
          newIdentNode("F")
        ),
        newEmptyNode()
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkCall.newTree(
        nnkDotExpr.newTree(
          newIdentNode("r"),
          newIdentNode("sumImpl")
        ),
        newIdentNode("P"),
        newIdentNode("Q"),
        newIdentNode("CoefA")
      )
    )
  ),
  newCommentStmtNode("----------------------------------"),
  nnkConstSection.newTree(
    nnkConstDef.newTree(
      newIdentNode("h2c_const_ec"),
      newEmptyNode(),
      nnkObjConstr.newTree(
        nnkBracketExpr.newTree(
          newIdentNode("QuadraticExt"),
          nnkBracketExpr.newTree(
            newIdentNode("BigInt"),
            newLit(4)
          )
        ),
        nnkExprColonExpr.newTree(
          newIdentNode("coords"),
          nnkBracket.newTree(
            nnkObjConstr.newTree(
              nnkBracketExpr.newTree(
                newIdentNode("BigInt"),
                newLit(4)
              ),
              nnkExprColonExpr.newTree(
                newIdentNode("raw"),
                nnkBracket.newTree(
                  nnkCommand.newTree(
                    newIdentNode("uint64"),
                    newLit(1)
                  ),
                  newLit(1),
                  newLit(1),
                  newLit(1)
                )
              )
            ),
            nnkObjConstr.newTree(
              nnkBracketExpr.newTree(
                newIdentNode("BigInt"),
                newLit(4)
              ),
              nnkExprColonExpr.newTree(
                newIdentNode("raw"),
                nnkBracket.newTree(
                  nnkCommand.newTree(
                    newIdentNode("uint64"),
                    newLit(1)
                  ),
                  newLit(1),
                  newLit(1),
                  newLit(1)
                )
              )
            )
          )
        )
      )
    )
  ),
  nnkVarSection.newTree(
    nnkIdentDefs.newTree(
      newIdentNode("P"),
      newEmptyNode(),
      nnkObjConstr.newTree(
        nnkBracketExpr.newTree(
          newIdentNode("EllipticCurve"),
          nnkBracketExpr.newTree(
            newIdentNode("QuadraticExt"),
            nnkBracketExpr.newTree(
              newIdentNode("BigInt"),
              newLit(4)
            )
          )
        ),
        nnkExprColonExpr.newTree(
          newIdentNode("x"),
          nnkObjConstr.newTree(
            nnkBracketExpr.newTree(
              newIdentNode("QuadraticExt"),
              nnkBracketExpr.newTree(
                newIdentNode("BigInt"),
                newLit(4)
              )
            ),
            nnkExprColonExpr.newTree(
              newIdentNode("coords"),
              nnkBracket.newTree(
                nnkObjConstr.newTree(
                  nnkBracketExpr.newTree(
                    newIdentNode("BigInt"),
                    newLit(4)
                  ),
                  nnkExprColonExpr.newTree(
                    newIdentNode("raw"),
                    nnkBracket.newTree(
                      nnkCommand.newTree(
                        newIdentNode("uint64"),
                        newLit(1)
                      ),
                      newLit(2),
                      newLit(3),
                      newLit(4)
                    )
                  )
                ),
                nnkObjConstr.newTree(
                  nnkBracketExpr.newTree(
                    newIdentNode("BigInt"),
                    newLit(4)
                  ),
                  nnkExprColonExpr.newTree(
                    newIdentNode("raw"),
                    nnkBracket.newTree(
                      nnkCommand.newTree(
                        newIdentNode("uint64"),
                        newLit(1)
                      ),
                      newLit(2),
                      newLit(3),
                      newLit(4)
                    )
                  )
                )
              )
            )
          )
        ),
        nnkExprColonExpr.newTree(
          newIdentNode("y"),
          nnkObjConstr.newTree(
            nnkBracketExpr.newTree(
              newIdentNode("QuadraticExt"),
              nnkBracketExpr.newTree(
                newIdentNode("BigInt"),
                newLit(4)
              )
            ),
            nnkExprColonExpr.newTree(
              newIdentNode("coords"),
              nnkBracket.newTree(
                nnkObjConstr.newTree(
                  nnkBracketExpr.newTree(
                    newIdentNode("BigInt"),
                    newLit(4)
                  ),
                  nnkExprColonExpr.newTree(
                    newIdentNode("raw"),
                    nnkBracket.newTree(
                      nnkCommand.newTree(
                        newIdentNode("uint64"),
                        newLit(1)
                      ),
                      newLit(2),
                      newLit(3),
                      newLit(4)
                    )
                  )
                ),
                nnkObjConstr.newTree(
                  nnkBracketExpr.newTree(
                    newIdentNode("BigInt"),
                    newLit(4)
                  ),
                  nnkExprColonExpr.newTree(
                    newIdentNode("raw"),
                    nnkBracket.newTree(
                      nnkCommand.newTree(
                        newIdentNode("uint64"),
                        newLit(1)
                      ),
                      newLit(2),
                      newLit(3),
                      newLit(4)
                    )
                  )
                )
              )
            )
          )
        ),
        nnkExprColonExpr.newTree(
          newIdentNode("z"),
          nnkObjConstr.newTree(
            nnkBracketExpr.newTree(
              newIdentNode("QuadraticExt"),
              nnkBracketExpr.newTree(
                newIdentNode("BigInt"),
                newLit(4)
              )
            ),
            nnkExprColonExpr.newTree(
              newIdentNode("coords"),
              nnkBracket.newTree(
                nnkObjConstr.newTree(
                  nnkBracketExpr.newTree(
                    newIdentNode("BigInt"),
                    newLit(4)
                  ),
                  nnkExprColonExpr.newTree(
                    newIdentNode("raw"),
                    nnkBracket.newTree(
                      nnkCommand.newTree(
                        newIdentNode("uint64"),
                        newLit(1)
                      ),
                      newLit(2),
                      newLit(3),
                      newLit(4)
                    )
                  )
                ),
                nnkObjConstr.newTree(
                  nnkBracketExpr.newTree(
                    newIdentNode("BigInt"),
                    newLit(4)
                  ),
                  nnkExprColonExpr.newTree(
                    newIdentNode("raw"),
                    nnkBracket.newTree(
                      nnkCommand.newTree(
                        newIdentNode("uint64"),
                        newLit(1)
                      ),
                      newLit(2),
                      newLit(3),
                      newLit(4)
                    )
                  )
                )
              )
            )
          )
        )
      )
    )
  ),
  nnkVarSection.newTree(
    nnkIdentDefs.newTree(
      newIdentNode("Q"),
      newEmptyNode(),
      nnkObjConstr.newTree(
        nnkBracketExpr.newTree(
          newIdentNode("EllipticCurve"),
          nnkBracketExpr.newTree(
            newIdentNode("QuadraticExt"),
            nnkBracketExpr.newTree(
              newIdentNode("BigInt"),
              newLit(4)
            )
          )
        ),
        nnkExprColonExpr.newTree(
          newIdentNode("x"),
          nnkObjConstr.newTree(
            nnkBracketExpr.newTree(
              newIdentNode("QuadraticExt"),
              nnkBracketExpr.newTree(
                newIdentNode("BigInt"),
                newLit(4)
              )
            ),
            nnkExprColonExpr.newTree(
              newIdentNode("coords"),
              nnkBracket.newTree(
                nnkObjConstr.newTree(
                  nnkBracketExpr.newTree(
                    newIdentNode("BigInt"),
                    newLit(4)
                  ),
                  nnkExprColonExpr.newTree(
                    newIdentNode("raw"),
                    nnkBracket.newTree(
                      nnkCommand.newTree(
                        newIdentNode("uint64"),
                        newLit(1)
                      ),
                      newLit(2),
                      newLit(3),
                      newLit(4)
                    )
                  )
                ),
                nnkObjConstr.newTree(
                  nnkBracketExpr.newTree(
                    newIdentNode("BigInt"),
                    newLit(4)
                  ),
                  nnkExprColonExpr.newTree(
                    newIdentNode("raw"),
                    nnkBracket.newTree(
                      nnkCommand.newTree(
                        newIdentNode("uint64"),
                        newLit(1)
                      ),
                      newLit(2),
                      newLit(3),
                      newLit(4)
                    )
                  )
                )
              )
            )
          )
        ),
        nnkExprColonExpr.newTree(
          newIdentNode("y"),
          nnkObjConstr.newTree(
            nnkBracketExpr.newTree(
              newIdentNode("QuadraticExt"),
              nnkBracketExpr.newTree(
                newIdentNode("BigInt"),
                newLit(4)
              )
            ),
            nnkExprColonExpr.newTree(
              newIdentNode("coords"),
              nnkBracket.newTree(
                nnkObjConstr.newTree(
                  nnkBracketExpr.newTree(
                    newIdentNode("BigInt"),
                    newLit(4)
                  ),
                  nnkExprColonExpr.newTree(
                    newIdentNode("raw"),
                    nnkBracket.newTree(
                      nnkCommand.newTree(
                        newIdentNode("uint64"),
                        newLit(1)
                      ),
                      newLit(2),
                      newLit(3),
                      newLit(4)
                    )
                  )
                ),
                nnkObjConstr.newTree(
                  nnkBracketExpr.newTree(
                    newIdentNode("BigInt"),
                    newLit(4)
                  ),
                  nnkExprColonExpr.newTree(
                    newIdentNode("raw"),
                    nnkBracket.newTree(
                      nnkCommand.newTree(
                        newIdentNode("uint64"),
                        newLit(1)
                      ),
                      newLit(2),
                      newLit(3),
                      newLit(4)
                    )
                  )
                )
              )
            )
          )
        ),
        nnkExprColonExpr.newTree(
          newIdentNode("z"),
          nnkObjConstr.newTree(
            nnkBracketExpr.newTree(
              newIdentNode("QuadraticExt"),
              nnkBracketExpr.newTree(
                newIdentNode("BigInt"),
                newLit(4)
              )
            ),
            nnkExprColonExpr.newTree(
              newIdentNode("coords"),
              nnkBracket.newTree(
                nnkObjConstr.newTree(
                  nnkBracketExpr.newTree(
                    newIdentNode("BigInt"),
                    newLit(4)
                  ),
                  nnkExprColonExpr.newTree(
                    newIdentNode("raw"),
                    nnkBracket.newTree(
                      nnkCommand.newTree(
                        newIdentNode("uint64"),
                        newLit(1)
                      ),
                      newLit(2),
                      newLit(3),
                      newLit(4)
                    )
                  )
                ),
                nnkObjConstr.newTree(
                  nnkBracketExpr.newTree(
                    newIdentNode("BigInt"),
                    newLit(4)
                  ),
                  nnkExprColonExpr.newTree(
                    newIdentNode("raw"),
                    nnkBracket.newTree(
                      nnkCommand.newTree(
                        newIdentNode("uint64"),
                        newLit(1)
                      ),
                      newLit(2),
                      newLit(3),
                      newLit(4)
                    )
                  )
                )
              )
            )
          )
        )
      )
    )
  ),
  nnkVarSection.newTree(
    nnkIdentDefs.newTree(
      newIdentNode("R"),
      nnkBracketExpr.newTree(
        newIdentNode("EllipticCurve"),
        nnkBracketExpr.newTree(
          newIdentNode("QuadraticExt"),
          nnkBracketExpr.newTree(
            newIdentNode("BigInt"),
            newLit(4)
          )
        )
      ),
      newEmptyNode()
    )
  ),
  nnkCall.newTree(
    nnkDotExpr.newTree(
      newIdentNode("R"),
      newIdentNode("sum")
    ),
    newIdentNode("P"),
    newIdentNode("Q"),
    newIdentNode("h2c_const_ec")
  )
)
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(79, 2) Error: type mismatch: got <EllipticCurve[QuadraticExt[BigInt[4]]], EllipticCurve[QuadraticExt[BigInt[4]]], EllipticCurve[QuadraticExt[BigInt[4]]], static[QuadraticExt[BigInt[4]]]((coords: [(raw: [1'u, 1'u, 1'u, 1'u]), (raw: [1'u, 1'u, 1'u, 1'u])]))>
but expected one of: 
func sum[F](r: var EllipticCurve[F]; P, Q: EllipticCurve[F]; CoefA: static F)
  first type mismatch at position: 4
  required type for CoefA: static[F]
  but expression 'h2c_const_ec' is of type: static[QuadraticExt[BigInt[4]]]((coords: [(raw: [1'u, 1'u, 1'u, 1'u]), (raw: [1'u, 1'u, 1'u, 1'u])]))

expression: sum(R, P, Q, h2c_const_ec)

IR

Compiled filesize 0 bytes (0 bytes)

Stats

  • Started 2024-04-29T11:46:21
  • Finished 2024-04-29T11:46:21
  • Duration

AST

nnkStmtList.newTree(
  nnkTypeSection.newTree(
    nnkTypeDef.newTree(
      newIdentNode("BigInt"),
      nnkGenericParams.newTree(
        nnkIdentDefs.newTree(
          newIdentNode("N"),
          nnkCommand.newTree(
            newIdentNode("static"),
            newIdentNode("int")
          ),
          newEmptyNode()
        )
      ),
      nnkObjectTy.newTree(
        newEmptyNode(),
        newEmptyNode(),
        nnkRecList.newTree(
          nnkIdentDefs.newTree(
            newIdentNode("raw"),
            nnkBracketExpr.newTree(
              newIdentNode("array"),
              newIdentNode("N"),
              newIdentNode("uint64")
            ),
            newEmptyNode()
          )
        )
      )
    )
  ),
  nnkFuncDef.newTree(
    newIdentNode("isZero"),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      newIdentNode("bool"),
      nnkIdentDefs.newTree(
        newIdentNode("a"),
        newIdentNode("BigInt"),
        newEmptyNode()
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkDiscardStmt.newTree(
        newEmptyNode()
      )
    )
  ),
  nnkFuncDef.newTree(
    newIdentNode("isOne"),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      newIdentNode("bool"),
      nnkIdentDefs.newTree(
        newIdentNode("a"),
        newIdentNode("BigInt"),
        newEmptyNode()
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkDiscardStmt.newTree(
        newEmptyNode()
      )
    )
  ),
  nnkTypeSection.newTree(
    nnkTypeDef.newTree(
      nnkPostfix.newTree(
        newIdentNode("*"),
        newIdentNode("QuadraticExt")
      ),
      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(2),
              newIdentNode("F")
            ),
            newEmptyNode()
          )
        )
      )
    ),
    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(
      nnkPostfix.newTree(
        newIdentNode("*"),
        newIdentNode("ExtensionField")
      ),
      nnkGenericParams.newTree(
        nnkIdentDefs.newTree(
          newIdentNode("F"),
          newEmptyNode(),
          newEmptyNode()
        )
      ),
      nnkInfix.newTree(
        newIdentNode("or"),
        nnkBracketExpr.newTree(
          newIdentNode("QuadraticExt"),
          newIdentNode("F")
        ),
        nnkBracketExpr.newTree(
          newIdentNode("CubicExt"),
          newIdentNode("F")
        )
      )
    )
  ),
  nnkFuncDef.newTree(
    nnkPostfix.newTree(
      newIdentNode("*"),
      newIdentNode("isOne")
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      newIdentNode("bool"),
      nnkIdentDefs.newTree(
        newIdentNode("a"),
        newIdentNode("ExtensionField"),
        newEmptyNode()
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      newCommentStmtNode("Constant-time check if one"),
      nnkAsgn.newTree(
        newIdentNode("result"),
        nnkUInt64Lit.newTree(
        )
      ),
      nnkAsgn.newTree(
        newIdentNode("result"),
        nnkInfix.newTree(
          newIdentNode("and"),
          newIdentNode("result"),
          nnkCall.newTree(
            nnkDotExpr.newTree(
              nnkBracketExpr.newTree(
                nnkDotExpr.newTree(
                  newIdentNode("a"),
                  newIdentNode("coords")
                ),
                newLit(0)
              ),
              newIdentNode("isOne")
            )
          )
        )
      ),
      nnkForStmt.newTree(
        newIdentNode("i"),
        nnkInfix.newTree(
          newIdentNode("..<"),
          newLit(1),
          nnkDotExpr.newTree(
            nnkDotExpr.newTree(
              newIdentNode("a"),
              newIdentNode("coords")
            ),
            newIdentNode("len")
          )
        ),
        nnkStmtList.newTree(
          nnkAsgn.newTree(
            newIdentNode("result"),
            nnkInfix.newTree(
              newIdentNode("and"),
              newIdentNode("result"),
              nnkCall.newTree(
                nnkDotExpr.newTree(
                  nnkBracketExpr.newTree(
                    nnkDotExpr.newTree(
                      newIdentNode("a"),
                      newIdentNode("coords")
                    ),
                    newIdentNode("i")
                  ),
                  newIdentNode("isZero")
                )
              )
            )
          )
        )
      )
    )
  ),
  nnkFuncDef.newTree(
    nnkPostfix.newTree(
      newIdentNode("*"),
      newIdentNode("mulCheckSparse")
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      newEmptyNode(),
      nnkIdentDefs.newTree(
        newIdentNode("a"),
        nnkVarTy.newTree(
          newIdentNode("QuadraticExt")
        ),
        newEmptyNode()
      ),
      nnkIdentDefs.newTree(
        newIdentNode("b"),
        nnkCommand.newTree(
          newIdentNode("static"),
          newIdentNode("QuadraticExt")
        ),
        newEmptyNode()
      )
    ),
    nnkPragma.newTree(
      newIdentNode("inline")
    ),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkStaticStmt.newTree(
        nnkStmtList.newTree(
          nnkCommand.newTree(
            newIdentNode("debugEcho"),
            newLit("QuadraticExt b: "),
            nnkInfix.newTree(
              newIdentNode("is"),
              newIdentNode("b"),
              newIdentNode("QuadraticExt")
            )
          ),
          nnkCommand.newTree(
            newIdentNode("debugEcho"),
            newLit("ExtensionField b: "),
            nnkInfix.newTree(
              newIdentNode("is"),
              newIdentNode("b"),
              newIdentNode("ExtensionField")
            )
          )
        )
      ),
      nnkWhenStmt.newTree(
        nnkElifBranch.newTree(
          nnkDotExpr.newTree(
            nnkCall.newTree(
              newIdentNode("isOne"),
              newIdentNode("b")
            ),
            newIdentNode("bool")
          ),
          nnkStmtList.newTree(
            nnkDiscardStmt.newTree(
              newEmptyNode()
            )
          )
        ),
        nnkElse.newTree(
          nnkStmtList.newTree(
            nnkCommand.newTree(
              newIdentNode("debugEcho"),
              newLit("a *= b")
            )
          )
        )
      )
    )
  ),
  nnkTypeSection.newTree(
    nnkTypeDef.newTree(
      nnkPostfix.newTree(
        newIdentNode("*"),
        newIdentNode("EllipticCurve")
      ),
      nnkGenericParams.newTree(
        nnkIdentDefs.newTree(
          newIdentNode("F"),
          newEmptyNode(),
          newEmptyNode()
        )
      ),
      nnkObjectTy.newTree(
        newEmptyNode(),
        newEmptyNode(),
        nnkRecList.newTree(
          nnkIdentDefs.newTree(
            nnkPostfix.newTree(
              newIdentNode("*"),
              newIdentNode("x")
            ),
            nnkPostfix.newTree(
              newIdentNode("*"),
              newIdentNode("y")
            ),
            nnkPostfix.newTree(
              newIdentNode("*"),
              newIdentNode("z")
            ),
            newIdentNode("F"),
            newEmptyNode()
          )
        )
      )
    )
  ),
  nnkTemplateDef.newTree(
    newIdentNode("sumImpl"),
    newEmptyNode(),
    nnkGenericParams.newTree(
      nnkIdentDefs.newTree(
        newIdentNode("F"),
        newEmptyNode(),
        newEmptyNode()
      )
    ),
    nnkFormalParams.newTree(
      newEmptyNode(),
      nnkIdentDefs.newTree(
        newIdentNode("r"),
        nnkVarTy.newTree(
          nnkBracketExpr.newTree(
            newIdentNode("EllipticCurve"),
            newIdentNode("F")
          )
        ),
        newEmptyNode()
      ),
      nnkIdentDefs.newTree(
        newIdentNode("P"),
        newIdentNode("Q"),
        nnkBracketExpr.newTree(
          newIdentNode("EllipticCurve"),
          newIdentNode("F")
        ),
        newEmptyNode()
      ),
      nnkIdentDefs.newTree(
        newIdentNode("CoefA"),
        newIdentNode("typed"),
        newEmptyNode()
      )
    ),
    nnkPragma.newTree(
      newIdentNode("dirty")
    ),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkWhenStmt.newTree(
        nnkElifBranch.newTree(
          nnkInfix.newTree(
            newIdentNode("is"),
            newIdentNode("CoefA"),
            newIdentNode("int")
          ),
          nnkStmtList.newTree(
            nnkCommand.newTree(
              newIdentNode("debugEcho"),
              newLit("EC addition with int CoefA")
            )
          )
        ),
        nnkElse.newTree(
          nnkStmtList.newTree(
            nnkVarSection.newTree(
              nnkIdentDefs.newTree(
                newIdentNode("b"),
                newEmptyNode(),
                nnkDotExpr.newTree(
                  newIdentNode("P"),
                  newIdentNode("x")
                )
              )
            ),
            nnkCall.newTree(
              nnkDotExpr.newTree(
                newIdentNode("b"),
                newIdentNode("mulCheckSparse")
              ),
              newIdentNode("CoefA")
            )
          )
        )
      )
    )
  ),
  nnkFuncDef.newTree(
    newIdentNode("sum"),
    newEmptyNode(),
    nnkGenericParams.newTree(
      nnkIdentDefs.newTree(
        newIdentNode("F"),
        newEmptyNode(),
        newEmptyNode()
      )
    ),
    nnkFormalParams.newTree(
      newEmptyNode(),
      nnkIdentDefs.newTree(
        newIdentNode("r"),
        nnkVarTy.newTree(
          nnkBracketExpr.newTree(
            newIdentNode("EllipticCurve"),
            newIdentNode("F")
          )
        ),
        newEmptyNode()
      ),
      nnkIdentDefs.newTree(
        newIdentNode("P"),
        newIdentNode("Q"),
        nnkBracketExpr.newTree(
          newIdentNode("EllipticCurve"),
          newIdentNode("F")
        ),
        newEmptyNode()
      ),
      nnkIdentDefs.newTree(
        newIdentNode("CoefA"),
        nnkCommand.newTree(
          newIdentNode("static"),
          newIdentNode("F")
        ),
        newEmptyNode()
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkCall.newTree(
        nnkDotExpr.newTree(
          newIdentNode("r"),
          newIdentNode("sumImpl")
        ),
        newIdentNode("P"),
        newIdentNode("Q"),
        newIdentNode("CoefA")
      )
    )
  ),
  newCommentStmtNode("----------------------------------"),
  nnkConstSection.newTree(
    nnkConstDef.newTree(
      newIdentNode("h2c_const_ec"),
      newEmptyNode(),
      nnkObjConstr.newTree(
        nnkBracketExpr.newTree(
          newIdentNode("QuadraticExt"),
          nnkBracketExpr.newTree(
            newIdentNode("BigInt"),
            newLit(4)
          )
        ),
        nnkExprColonExpr.newTree(
          newIdentNode("coords"),
          nnkBracket.newTree(
            nnkObjConstr.newTree(
              nnkBracketExpr.newTree(
                newIdentNode("BigInt"),
                newLit(4)
              ),
              nnkExprColonExpr.newTree(
                newIdentNode("raw"),
                nnkBracket.newTree(
                  nnkCommand.newTree(
                    newIdentNode("uint64"),
                    newLit(1)
                  ),
                  newLit(1),
                  newLit(1),
                  newLit(1)
                )
              )
            ),
            nnkObjConstr.newTree(
              nnkBracketExpr.newTree(
                newIdentNode("BigInt"),
                newLit(4)
              ),
              nnkExprColonExpr.newTree(
                newIdentNode("raw"),
                nnkBracket.newTree(
                  nnkCommand.newTree(
                    newIdentNode("uint64"),
                    newLit(1)
                  ),
                  newLit(1),
                  newLit(1),
                  newLit(1)
                )
              )
            )
          )
        )
      )
    )
  ),
  nnkVarSection.newTree(
    nnkIdentDefs.newTree(
      newIdentNode("P"),
      newEmptyNode(),
      nnkObjConstr.newTree(
        nnkBracketExpr.newTree(
          newIdentNode("EllipticCurve"),
          nnkBracketExpr.newTree(
            newIdentNode("QuadraticExt"),
            nnkBracketExpr.newTree(
              newIdentNode("BigInt"),
              newLit(4)
            )
          )
        ),
        nnkExprColonExpr.newTree(
          newIdentNode("x"),
          nnkObjConstr.newTree(
            nnkBracketExpr.newTree(
              newIdentNode("QuadraticExt"),
              nnkBracketExpr.newTree(
                newIdentNode("BigInt"),
                newLit(4)
              )
            ),
            nnkExprColonExpr.newTree(
              newIdentNode("coords"),
              nnkBracket.newTree(
                nnkObjConstr.newTree(
                  nnkBracketExpr.newTree(
                    newIdentNode("BigInt"),
                    newLit(4)
                  ),
                  nnkExprColonExpr.newTree(
                    newIdentNode("raw"),
                    nnkBracket.newTree(
                      nnkCommand.newTree(
                        newIdentNode("uint64"),
                        newLit(1)
                      ),
                      newLit(2),
                      newLit(3),
                      newLit(4)
                    )
                  )
                ),
                nnkObjConstr.newTree(
                  nnkBracketExpr.newTree(
                    newIdentNode("BigInt"),
                    newLit(4)
                  ),
                  nnkExprColonExpr.newTree(
                    newIdentNode("raw"),
                    nnkBracket.newTree(
                      nnkCommand.newTree(
                        newIdentNode("uint64"),
                        newLit(1)
                      ),
                      newLit(2),
                      newLit(3),
                      newLit(4)
                    )
                  )
                )
              )
            )
          )
        ),
        nnkExprColonExpr.newTree(
          newIdentNode("y"),
          nnkObjConstr.newTree(
            nnkBracketExpr.newTree(
              newIdentNode("QuadraticExt"),
              nnkBracketExpr.newTree(
                newIdentNode("BigInt"),
                newLit(4)
              )
            ),
            nnkExprColonExpr.newTree(
              newIdentNode("coords"),
              nnkBracket.newTree(
                nnkObjConstr.newTree(
                  nnkBracketExpr.newTree(
                    newIdentNode("BigInt"),
                    newLit(4)
                  ),
                  nnkExprColonExpr.newTree(
                    newIdentNode("raw"),
                    nnkBracket.newTree(
                      nnkCommand.newTree(
                        newIdentNode("uint64"),
                        newLit(1)
                      ),
                      newLit(2),
                      newLit(3),
                      newLit(4)
                    )
                  )
                ),
                nnkObjConstr.newTree(
                  nnkBracketExpr.newTree(
                    newIdentNode("BigInt"),
                    newLit(4)
                  ),
                  nnkExprColonExpr.newTree(
                    newIdentNode("raw"),
                    nnkBracket.newTree(
                      nnkCommand.newTree(
                        newIdentNode("uint64"),
                        newLit(1)
                      ),
                      newLit(2),
                      newLit(3),
                      newLit(4)
                    )
                  )
                )
              )
            )
          )
        ),
        nnkExprColonExpr.newTree(
          newIdentNode("z"),
          nnkObjConstr.newTree(
            nnkBracketExpr.newTree(
              newIdentNode("QuadraticExt"),
              nnkBracketExpr.newTree(
                newIdentNode("BigInt"),
                newLit(4)
              )
            ),
            nnkExprColonExpr.newTree(
              newIdentNode("coords"),
              nnkBracket.newTree(
                nnkObjConstr.newTree(
                  nnkBracketExpr.newTree(
                    newIdentNode("BigInt"),
                    newLit(4)
                  ),
                  nnkExprColonExpr.newTree(
                    newIdentNode("raw"),
                    nnkBracket.newTree(
                      nnkCommand.newTree(
                        newIdentNode("uint64"),
                        newLit(1)
                      ),
                      newLit(2),
                      newLit(3),
                      newLit(4)
                    )
                  )
                ),
                nnkObjConstr.newTree(
                  nnkBracketExpr.newTree(
                    newIdentNode("BigInt"),
                    newLit(4)
                  ),
                  nnkExprColonExpr.newTree(
                    newIdentNode("raw"),
                    nnkBracket.newTree(
                      nnkCommand.newTree(
                        newIdentNode("uint64"),
                        newLit(1)
                      ),
                      newLit(2),
                      newLit(3),
                      newLit(4)
                    )
                  )
                )
              )
            )
          )
        )
      )
    )
  ),
  nnkVarSection.newTree(
    nnkIdentDefs.newTree(
      newIdentNode("Q"),
      newEmptyNode(),
      nnkObjConstr.newTree(
        nnkBracketExpr.newTree(
          newIdentNode("EllipticCurve"),
          nnkBracketExpr.newTree(
            newIdentNode("QuadraticExt"),
            nnkBracketExpr.newTree(
              newIdentNode("BigInt"),
              newLit(4)
            )
          )
        ),
        nnkExprColonExpr.newTree(
          newIdentNode("x"),
          nnkObjConstr.newTree(
            nnkBracketExpr.newTree(
              newIdentNode("QuadraticExt"),
              nnkBracketExpr.newTree(
                newIdentNode("BigInt"),
                newLit(4)
              )
            ),
            nnkExprColonExpr.newTree(
              newIdentNode("coords"),
              nnkBracket.newTree(
                nnkObjConstr.newTree(
                  nnkBracketExpr.newTree(
                    newIdentNode("BigInt"),
                    newLit(4)
                  ),
                  nnkExprColonExpr.newTree(
                    newIdentNode("raw"),
                    nnkBracket.newTree(
                      nnkCommand.newTree(
                        newIdentNode("uint64"),
                        newLit(1)
                      ),
                      newLit(2),
                      newLit(3),
                      newLit(4)
                    )
                  )
                ),
                nnkObjConstr.newTree(
                  nnkBracketExpr.newTree(
                    newIdentNode("BigInt"),
                    newLit(4)
                  ),
                  nnkExprColonExpr.newTree(
                    newIdentNode("raw"),
                    nnkBracket.newTree(
                      nnkCommand.newTree(
                        newIdentNode("uint64"),
                        newLit(1)
                      ),
                      newLit(2),
                      newLit(3),
                      newLit(4)
                    )
                  )
                )
              )
            )
          )
        ),
        nnkExprColonExpr.newTree(
          newIdentNode("y"),
          nnkObjConstr.newTree(
            nnkBracketExpr.newTree(
              newIdentNode("QuadraticExt"),
              nnkBracketExpr.newTree(
                newIdentNode("BigInt"),
                newLit(4)
              )
            ),
            nnkExprColonExpr.newTree(
              newIdentNode("coords"),
              nnkBracket.newTree(
                nnkObjConstr.newTree(
                  nnkBracketExpr.newTree(
                    newIdentNode("BigInt"),
                    newLit(4)
                  ),
                  nnkExprColonExpr.newTree(
                    newIdentNode("raw"),
                    nnkBracket.newTree(
                      nnkCommand.newTree(
                        newIdentNode("uint64"),
                        newLit(1)
                      ),
                      newLit(2),
                      newLit(3),
                      newLit(4)
                    )
                  )
                ),
                nnkObjConstr.newTree(
                  nnkBracketExpr.newTree(
                    newIdentNode("BigInt"),
                    newLit(4)
                  ),
                  nnkExprColonExpr.newTree(
                    newIdentNode("raw"),
                    nnkBracket.newTree(
                      nnkCommand.newTree(
                        newIdentNode("uint64"),
                        newLit(1)
                      ),
                      newLit(2),
                      newLit(3),
                      newLit(4)
                    )
                  )
                )
              )
            )
          )
        ),
        nnkExprColonExpr.newTree(
          newIdentNode("z"),
          nnkObjConstr.newTree(
            nnkBracketExpr.newTree(
              newIdentNode("QuadraticExt"),
              nnkBracketExpr.newTree(
                newIdentNode("BigInt"),
                newLit(4)
              )
            ),
            nnkExprColonExpr.newTree(
              newIdentNode("coords"),
              nnkBracket.newTree(
                nnkObjConstr.newTree(
                  nnkBracketExpr.newTree(
                    newIdentNode("BigInt"),
                    newLit(4)
                  ),
                  nnkExprColonExpr.newTree(
                    newIdentNode("raw"),
                    nnkBracket.newTree(
                      nnkCommand.newTree(
                        newIdentNode("uint64"),
                        newLit(1)
                      ),
                      newLit(2),
                      newLit(3),
                      newLit(4)
                    )
                  )
                ),
                nnkObjConstr.newTree(
                  nnkBracketExpr.newTree(
                    newIdentNode("BigInt"),
                    newLit(4)
                  ),
                  nnkExprColonExpr.newTree(
                    newIdentNode("raw"),
                    nnkBracket.newTree(
                      nnkCommand.newTree(
                        newIdentNode("uint64"),
                        newLit(1)
                      ),
                      newLit(2),
                      newLit(3),
                      newLit(4)
                    )
                  )
                )
              )
            )
          )
        )
      )
    )
  ),
  nnkVarSection.newTree(
    nnkIdentDefs.newTree(
      newIdentNode("R"),
      nnkBracketExpr.newTree(
        newIdentNode("EllipticCurve"),
        nnkBracketExpr.newTree(
          newIdentNode("QuadraticExt"),
          nnkBracketExpr.newTree(
            newIdentNode("BigInt"),
            newLit(4)
          )
        )
      ),
      newEmptyNode()
    )
  ),
  nnkCall.newTree(
    nnkDotExpr.newTree(
      newIdentNode("R"),
      newIdentNode("sum")
    ),
    newIdentNode("P"),
    newIdentNode("Q"),
    newIdentNode("h2c_const_ec")
  )
)
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(79, 2) Error: type mismatch: got <EllipticCurve[QuadraticExt[BigInt[4]]], EllipticCurve[QuadraticExt[BigInt[4]]], EllipticCurve[QuadraticExt[BigInt[4]]], static[QuadraticExt[BigInt[4]]]((coords: [(raw: [1'u, 1'u, 1'u, 1'u]), (raw: [1'u, 1'u, 1'u, 1'u])]))>
but expected one of: 
func sum[F](r: var EllipticCurve[F]; P, Q: EllipticCurve[F]; CoefA: static F)
  first type mismatch at position: 4
  required type for CoefA: static[F]
  but expression 'h2c_const_ec' is of type: static[QuadraticExt[BigInt[4]]]((coords: [(raw: [1'u, 1'u, 1'u, 1'u]), (raw: [1'u, 1'u, 1'u, 1'u])]))

expression: sum(R, P, Q, h2c_const_ec)

IR

Compiled filesize 0 bytes (0 bytes)

Stats

  • Started 2024-04-29T11:46:23
  • Finished 2024-04-29T11:46:23
  • Duration

AST

nnkStmtList.newTree(
  nnkTypeSection.newTree(
    nnkTypeDef.newTree(
      newIdentNode("BigInt"),
      nnkGenericParams.newTree(
        nnkIdentDefs.newTree(
          newIdentNode("N"),
          nnkCommand.newTree(
            newIdentNode("static"),
            newIdentNode("int")
          ),
          newEmptyNode()
        )
      ),
      nnkObjectTy.newTree(
        newEmptyNode(),
        newEmptyNode(),
        nnkRecList.newTree(
          nnkIdentDefs.newTree(
            newIdentNode("raw"),
            nnkBracketExpr.newTree(
              newIdentNode("array"),
              newIdentNode("N"),
              newIdentNode("uint64")
            ),
            newEmptyNode()
          )
        )
      )
    )
  ),
  nnkFuncDef.newTree(
    newIdentNode("isZero"),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      newIdentNode("bool"),
      nnkIdentDefs.newTree(
        newIdentNode("a"),
        newIdentNode("BigInt"),
        newEmptyNode()
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkDiscardStmt.newTree(
        newEmptyNode()
      )
    )
  ),
  nnkFuncDef.newTree(
    newIdentNode("isOne"),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      newIdentNode("bool"),
      nnkIdentDefs.newTree(
        newIdentNode("a"),
        newIdentNode("BigInt"),
        newEmptyNode()
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkDiscardStmt.newTree(
        newEmptyNode()
      )
    )
  ),
  nnkTypeSection.newTree(
    nnkTypeDef.newTree(
      nnkPostfix.newTree(
        newIdentNode("*"),
        newIdentNode("QuadraticExt")
      ),
      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(2),
              newIdentNode("F")
            ),
            newEmptyNode()
          )
        )
      )
    ),
    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(
      nnkPostfix.newTree(
        newIdentNode("*"),
        newIdentNode("ExtensionField")
      ),
      nnkGenericParams.newTree(
        nnkIdentDefs.newTree(
          newIdentNode("F"),
          newEmptyNode(),
          newEmptyNode()
        )
      ),
      nnkInfix.newTree(
        newIdentNode("or"),
        nnkBracketExpr.newTree(
          newIdentNode("QuadraticExt"),
          newIdentNode("F")
        ),
        nnkBracketExpr.newTree(
          newIdentNode("CubicExt"),
          newIdentNode("F")
        )
      )
    )
  ),
  nnkFuncDef.newTree(
    nnkPostfix.newTree(
      newIdentNode("*"),
      newIdentNode("isOne")
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      newIdentNode("bool"),
      nnkIdentDefs.newTree(
        newIdentNode("a"),
        newIdentNode("ExtensionField"),
        newEmptyNode()
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      newCommentStmtNode("Constant-time check if one"),
      nnkAsgn.newTree(
        newIdentNode("result"),
        nnkUInt64Lit.newTree(
        )
      ),
      nnkAsgn.newTree(
        newIdentNode("result"),
        nnkInfix.newTree(
          newIdentNode("and"),
          newIdentNode("result"),
          nnkCall.newTree(
            nnkDotExpr.newTree(
              nnkBracketExpr.newTree(
                nnkDotExpr.newTree(
                  newIdentNode("a"),
                  newIdentNode("coords")
                ),
                newLit(0)
              ),
              newIdentNode("isOne")
            )
          )
        )
      ),
      nnkForStmt.newTree(
        newIdentNode("i"),
        nnkInfix.newTree(
          newIdentNode("..<"),
          newLit(1),
          nnkDotExpr.newTree(
            nnkDotExpr.newTree(
              newIdentNode("a"),
              newIdentNode("coords")
            ),
            newIdentNode("len")
          )
        ),
        nnkStmtList.newTree(
          nnkAsgn.newTree(
            newIdentNode("result"),
            nnkInfix.newTree(
              newIdentNode("and"),
              newIdentNode("result"),
              nnkCall.newTree(
                nnkDotExpr.newTree(
                  nnkBracketExpr.newTree(
                    nnkDotExpr.newTree(
                      newIdentNode("a"),
                      newIdentNode("coords")
                    ),
                    newIdentNode("i")
                  ),
                  newIdentNode("isZero")
                )
              )
            )
          )
        )
      )
    )
  ),
  nnkFuncDef.newTree(
    nnkPostfix.newTree(
      newIdentNode("*"),
      newIdentNode("mulCheckSparse")
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      newEmptyNode(),
      nnkIdentDefs.newTree(
        newIdentNode("a"),
        nnkVarTy.newTree(
          newIdentNode("QuadraticExt")
        ),
        newEmptyNode()
      ),
      nnkIdentDefs.newTree(
        newIdentNode("b"),
        nnkCommand.newTree(
          newIdentNode("static"),
          newIdentNode("QuadraticExt")
        ),
        newEmptyNode()
      )
    ),
    nnkPragma.newTree(
      newIdentNode("inline")
    ),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkStaticStmt.newTree(
        nnkStmtList.newTree(
          nnkCommand.newTree(
            newIdentNode("debugEcho"),
            newLit("QuadraticExt b: "),
            nnkInfix.newTree(
              newIdentNode("is"),
              newIdentNode("b"),
              newIdentNode("QuadraticExt")
            )
          ),
          nnkCommand.newTree(
            newIdentNode("debugEcho"),
            newLit("ExtensionField b: "),
            nnkInfix.newTree(
              newIdentNode("is"),
              newIdentNode("b"),
              newIdentNode("ExtensionField")
            )
          )
        )
      ),
      nnkWhenStmt.newTree(
        nnkElifBranch.newTree(
          nnkDotExpr.newTree(
            nnkCall.newTree(
              newIdentNode("isOne"),
              newIdentNode("b")
            ),
            newIdentNode("bool")
          ),
          nnkStmtList.newTree(
            nnkDiscardStmt.newTree(
              newEmptyNode()
            )
          )
        ),
        nnkElse.newTree(
          nnkStmtList.newTree(
            nnkCommand.newTree(
              newIdentNode("debugEcho"),
              newLit("a *= b")
            )
          )
        )
      )
    )
  ),
  nnkTypeSection.newTree(
    nnkTypeDef.newTree(
      nnkPostfix.newTree(
        newIdentNode("*"),
        newIdentNode("EllipticCurve")
      ),
      nnkGenericParams.newTree(
        nnkIdentDefs.newTree(
          newIdentNode("F"),
          newEmptyNode(),
          newEmptyNode()
        )
      ),
      nnkObjectTy.newTree(
        newEmptyNode(),
        newEmptyNode(),
        nnkRecList.newTree(
          nnkIdentDefs.newTree(
            nnkPostfix.newTree(
              newIdentNode("*"),
              newIdentNode("x")
            ),
            nnkPostfix.newTree(
              newIdentNode("*"),
              newIdentNode("y")
            ),
            nnkPostfix.newTree(
              newIdentNode("*"),
              newIdentNode("z")
            ),
            newIdentNode("F"),
            newEmptyNode()
          )
        )
      )
    )
  ),
  nnkTemplateDef.newTree(
    newIdentNode("sumImpl"),
    newEmptyNode(),
    nnkGenericParams.newTree(
      nnkIdentDefs.newTree(
        newIdentNode("F"),
        newEmptyNode(),
        newEmptyNode()
      )
    ),
    nnkFormalParams.newTree(
      newEmptyNode(),
      nnkIdentDefs.newTree(
        newIdentNode("r"),
        nnkVarTy.newTree(
          nnkBracketExpr.newTree(
            newIdentNode("EllipticCurve"),
            newIdentNode("F")
          )
        ),
        newEmptyNode()
      ),
      nnkIdentDefs.newTree(
        newIdentNode("P"),
        newIdentNode("Q"),
        nnkBracketExpr.newTree(
          newIdentNode("EllipticCurve"),
          newIdentNode("F")
        ),
        newEmptyNode()
      ),
      nnkIdentDefs.newTree(
        newIdentNode("CoefA"),
        newIdentNode("typed"),
        newEmptyNode()
      )
    ),
    nnkPragma.newTree(
      newIdentNode("dirty")
    ),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkWhenStmt.newTree(
        nnkElifBranch.newTree(
          nnkInfix.newTree(
            newIdentNode("is"),
            newIdentNode("CoefA"),
            newIdentNode("int")
          ),
          nnkStmtList.newTree(
            nnkCommand.newTree(
              newIdentNode("debugEcho"),
              newLit("EC addition with int CoefA")
            )
          )
        ),
        nnkElse.newTree(
          nnkStmtList.newTree(
            nnkVarSection.newTree(
              nnkIdentDefs.newTree(
                newIdentNode("b"),
                newEmptyNode(),
                nnkDotExpr.newTree(
                  newIdentNode("P"),
                  newIdentNode("x")
                )
              )
            ),
            nnkCall.newTree(
              nnkDotExpr.newTree(
                newIdentNode("b"),
                newIdentNode("mulCheckSparse")
              ),
              newIdentNode("CoefA")
            )
          )
        )
      )
    )
  ),
  nnkFuncDef.newTree(
    newIdentNode("sum"),
    newEmptyNode(),
    nnkGenericParams.newTree(
      nnkIdentDefs.newTree(
        newIdentNode("F"),
        newEmptyNode(),
        newEmptyNode()
      )
    ),
    nnkFormalParams.newTree(
      newEmptyNode(),
      nnkIdentDefs.newTree(
        newIdentNode("r"),
        nnkVarTy.newTree(
          nnkBracketExpr.newTree(
            newIdentNode("EllipticCurve"),
            newIdentNode("F")
          )
        ),
        newEmptyNode()
      ),
      nnkIdentDefs.newTree(
        newIdentNode("P"),
        newIdentNode("Q"),
        nnkBracketExpr.newTree(
          newIdentNode("EllipticCurve"),
          newIdentNode("F")
        ),
        newEmptyNode()
      ),
      nnkIdentDefs.newTree(
        newIdentNode("CoefA"),
        nnkCommand.newTree(
          newIdentNode("static"),
          newIdentNode("F")
        ),
        newEmptyNode()
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkCall.newTree(
        nnkDotExpr.newTree(
          newIdentNode("r"),
          newIdentNode("sumImpl")
        ),
        newIdentNode("P"),
        newIdentNode("Q"),
        newIdentNode("CoefA")
      )
    )
  ),
  newCommentStmtNode("----------------------------------"),
  nnkConstSection.newTree(
    nnkConstDef.newTree(
      newIdentNode("h2c_const_ec"),
      newEmptyNode(),
      nnkObjConstr.newTree(
        nnkBracketExpr.newTree(
          newIdentNode("QuadraticExt"),
          nnkBracketExpr.newTree(
            newIdentNode("BigInt"),
            newLit(4)
          )
        ),
        nnkExprColonExpr.newTree(
          newIdentNode("coords"),
          nnkBracket.newTree(
            nnkObjConstr.newTree(
              nnkBracketExpr.newTree(
                newIdentNode("BigInt"),
                newLit(4)
              ),
              nnkExprColonExpr.newTree(
                newIdentNode("raw"),
                nnkBracket.newTree(
                  nnkCommand.newTree(
                    newIdentNode("uint64"),
                    newLit(1)
                  ),
                  newLit(1),
                  newLit(1),
                  newLit(1)
                )
              )
            ),
            nnkObjConstr.newTree(
              nnkBracketExpr.newTree(
                newIdentNode("BigInt"),
                newLit(4)
              ),
              nnkExprColonExpr.newTree(
                newIdentNode("raw"),
                nnkBracket.newTree(
                  nnkCommand.newTree(
                    newIdentNode("uint64"),
                    newLit(1)
                  ),
                  newLit(1),
                  newLit(1),
                  newLit(1)
                )
              )
            )
          )
        )
      )
    )
  ),
  nnkVarSection.newTree(
    nnkIdentDefs.newTree(
      newIdentNode("P"),
      newEmptyNode(),
      nnkObjConstr.newTree(
        nnkBracketExpr.newTree(
          newIdentNode("EllipticCurve"),
          nnkBracketExpr.newTree(
            newIdentNode("QuadraticExt"),
            nnkBracketExpr.newTree(
              newIdentNode("BigInt"),
              newLit(4)
            )
          )
        ),
        nnkExprColonExpr.newTree(
          newIdentNode("x"),
          nnkObjConstr.newTree(
            nnkBracketExpr.newTree(
              newIdentNode("QuadraticExt"),
              nnkBracketExpr.newTree(
                newIdentNode("BigInt"),
                newLit(4)
              )
            ),
            nnkExprColonExpr.newTree(
              newIdentNode("coords"),
              nnkBracket.newTree(
                nnkObjConstr.newTree(
                  nnkBracketExpr.newTree(
                    newIdentNode("BigInt"),
                    newLit(4)
                  ),
                  nnkExprColonExpr.newTree(
                    newIdentNode("raw"),
                    nnkBracket.newTree(
                      nnkCommand.newTree(
                        newIdentNode("uint64"),
                        newLit(1)
                      ),
                      newLit(2),
                      newLit(3),
                      newLit(4)
                    )
                  )
                ),
                nnkObjConstr.newTree(
                  nnkBracketExpr.newTree(
                    newIdentNode("BigInt"),
                    newLit(4)
                  ),
                  nnkExprColonExpr.newTree(
                    newIdentNode("raw"),
                    nnkBracket.newTree(
                      nnkCommand.newTree(
                        newIdentNode("uint64"),
                        newLit(1)
                      ),
                      newLit(2),
                      newLit(3),
                      newLit(4)
                    )
                  )
                )
              )
            )
          )
        ),
        nnkExprColonExpr.newTree(
          newIdentNode("y"),
          nnkObjConstr.newTree(
            nnkBracketExpr.newTree(
              newIdentNode("QuadraticExt"),
              nnkBracketExpr.newTree(
                newIdentNode("BigInt"),
                newLit(4)
              )
            ),
            nnkExprColonExpr.newTree(
              newIdentNode("coords"),
              nnkBracket.newTree(
                nnkObjConstr.newTree(
                  nnkBracketExpr.newTree(
                    newIdentNode("BigInt"),
                    newLit(4)
                  ),
                  nnkExprColonExpr.newTree(
                    newIdentNode("raw"),
                    nnkBracket.newTree(
                      nnkCommand.newTree(
                        newIdentNode("uint64"),
                        newLit(1)
                      ),
                      newLit(2),
                      newLit(3),
                      newLit(4)
                    )
                  )
                ),
                nnkObjConstr.newTree(
                  nnkBracketExpr.newTree(
                    newIdentNode("BigInt"),
                    newLit(4)
                  ),
                  nnkExprColonExpr.newTree(
                    newIdentNode("raw"),
                    nnkBracket.newTree(
                      nnkCommand.newTree(
                        newIdentNode("uint64"),
                        newLit(1)
                      ),
                      newLit(2),
                      newLit(3),
                      newLit(4)
                    )
                  )
                )
              )
            )
          )
        ),
        nnkExprColonExpr.newTree(
          newIdentNode("z"),
          nnkObjConstr.newTree(
            nnkBracketExpr.newTree(
              newIdentNode("QuadraticExt"),
              nnkBracketExpr.newTree(
                newIdentNode("BigInt"),
                newLit(4)
              )
            ),
            nnkExprColonExpr.newTree(
              newIdentNode("coords"),
              nnkBracket.newTree(
                nnkObjConstr.newTree(
                  nnkBracketExpr.newTree(
                    newIdentNode("BigInt"),
                    newLit(4)
                  ),
                  nnkExprColonExpr.newTree(
                    newIdentNode("raw"),
                    nnkBracket.newTree(
                      nnkCommand.newTree(
                        newIdentNode("uint64"),
                        newLit(1)
                      ),
                      newLit(2),
                      newLit(3),
                      newLit(4)
                    )
                  )
                ),
                nnkObjConstr.newTree(
                  nnkBracketExpr.newTree(
                    newIdentNode("BigInt"),
                    newLit(4)
                  ),
                  nnkExprColonExpr.newTree(
                    newIdentNode("raw"),
                    nnkBracket.newTree(
                      nnkCommand.newTree(
                        newIdentNode("uint64"),
                        newLit(1)
                      ),
                      newLit(2),
                      newLit(3),
                      newLit(4)
                    )
                  )
                )
              )
            )
          )
        )
      )
    )
  ),
  nnkVarSection.newTree(
    nnkIdentDefs.newTree(
      newIdentNode("Q"),
      newEmptyNode(),
      nnkObjConstr.newTree(
        nnkBracketExpr.newTree(
          newIdentNode("EllipticCurve"),
          nnkBracketExpr.newTree(
            newIdentNode("QuadraticExt"),
            nnkBracketExpr.newTree(
              newIdentNode("BigInt"),
              newLit(4)
            )
          )
        ),
        nnkExprColonExpr.newTree(
          newIdentNode("x"),
          nnkObjConstr.newTree(
            nnkBracketExpr.newTree(
              newIdentNode("QuadraticExt"),
              nnkBracketExpr.newTree(
                newIdentNode("BigInt"),
                newLit(4)
              )
            ),
            nnkExprColonExpr.newTree(
              newIdentNode("coords"),
              nnkBracket.newTree(
                nnkObjConstr.newTree(
                  nnkBracketExpr.newTree(
                    newIdentNode("BigInt"),
                    newLit(4)
                  ),
                  nnkExprColonExpr.newTree(
                    newIdentNode("raw"),
                    nnkBracket.newTree(
                      nnkCommand.newTree(
                        newIdentNode("uint64"),
                        newLit(1)
                      ),
                      newLit(2),
                      newLit(3),
                      newLit(4)
                    )
                  )
                ),
                nnkObjConstr.newTree(
                  nnkBracketExpr.newTree(
                    newIdentNode("BigInt"),
                    newLit(4)
                  ),
                  nnkExprColonExpr.newTree(
                    newIdentNode("raw"),
                    nnkBracket.newTree(
                      nnkCommand.newTree(
                        newIdentNode("uint64"),
                        newLit(1)
                      ),
                      newLit(2),
                      newLit(3),
                      newLit(4)
                    )
                  )
                )
              )
            )
          )
        ),
        nnkExprColonExpr.newTree(
          newIdentNode("y"),
          nnkObjConstr.newTree(
            nnkBracketExpr.newTree(
              newIdentNode("QuadraticExt"),
              nnkBracketExpr.newTree(
                newIdentNode("BigInt"),
                newLit(4)
              )
            ),
            nnkExprColonExpr.newTree(
              newIdentNode("coords"),
              nnkBracket.newTree(
                nnkObjConstr.newTree(
                  nnkBracketExpr.newTree(
                    newIdentNode("BigInt"),
                    newLit(4)
                  ),
                  nnkExprColonExpr.newTree(
                    newIdentNode("raw"),
                    nnkBracket.newTree(
                      nnkCommand.newTree(
                        newIdentNode("uint64"),
                        newLit(1)
                      ),
                      newLit(2),
                      newLit(3),
                      newLit(4)
                    )
                  )
                ),
                nnkObjConstr.newTree(
                  nnkBracketExpr.newTree(
                    newIdentNode("BigInt"),
                    newLit(4)
                  ),
                  nnkExprColonExpr.newTree(
                    newIdentNode("raw"),
                    nnkBracket.newTree(
                      nnkCommand.newTree(
                        newIdentNode("uint64"),
                        newLit(1)
                      ),
                      newLit(2),
                      newLit(3),
                      newLit(4)
                    )
                  )
                )
              )
            )
          )
        ),
        nnkExprColonExpr.newTree(
          newIdentNode("z"),
          nnkObjConstr.newTree(
            nnkBracketExpr.newTree(
              newIdentNode("QuadraticExt"),
              nnkBracketExpr.newTree(
                newIdentNode("BigInt"),
                newLit(4)
              )
            ),
            nnkExprColonExpr.newTree(
              newIdentNode("coords"),
              nnkBracket.newTree(
                nnkObjConstr.newTree(
                  nnkBracketExpr.newTree(
                    newIdentNode("BigInt"),
                    newLit(4)
                  ),
                  nnkExprColonExpr.newTree(
                    newIdentNode("raw"),
                    nnkBracket.newTree(
                      nnkCommand.newTree(
                        newIdentNode("uint64"),
                        newLit(1)
                      ),
                      newLit(2),
                      newLit(3),
                      newLit(4)
                    )
                  )
                ),
                nnkObjConstr.newTree(
                  nnkBracketExpr.newTree(
                    newIdentNode("BigInt"),
                    newLit(4)
                  ),
                  nnkExprColonExpr.newTree(
                    newIdentNode("raw"),
                    nnkBracket.newTree(
                      nnkCommand.newTree(
                        newIdentNode("uint64"),
                        newLit(1)
                      ),
                      newLit(2),
                      newLit(3),
                      newLit(4)
                    )
                  )
                )
              )
            )
          )
        )
      )
    )
  ),
  nnkVarSection.newTree(
    nnkIdentDefs.newTree(
      newIdentNode("R"),
      nnkBracketExpr.newTree(
        newIdentNode("EllipticCurve"),
        nnkBracketExpr.newTree(
          newIdentNode("QuadraticExt"),
          nnkBracketExpr.newTree(
            newIdentNode("BigInt"),
            newLit(4)
          )
        )
      ),
      newEmptyNode()
    )
  ),
  nnkCall.newTree(
    nnkDotExpr.newTree(
      newIdentNode("R"),
      newIdentNode("sum")
    ),
    newIdentNode("P"),
    newIdentNode("Q"),
    newIdentNode("h2c_const_ec")
  )
)
Stats
  • GCC 11.4.0
  • Clang 14.0.0
  • NodeJS 20.2
  • Created 2024-04-29T11:45:44Z
  • 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 17 minutes bisecting 7 commits at 0 commits per second

@mratsim
Copy link
Collaborator Author

mratsim commented Apr 30, 2024

Bisecting with the full Constantine lib.

The regression happened in 5e20e93 / #22828 that was trying to fix #22826

I assume #22828 fixed a caching issue that happened to make my full-blown library work and that fix surfaced the long-standing underlying bug.

I also assume that the test case @alaviss mentioned being broken is related

import macros

type
  A[T] = T

macro eqTyp(x, y: typed) =
  # NOTE: the `or` is due to sameType not being commutative: https://github.com/nim-lang/Nim/issues/18867
  doAssert sameType(x, y) or sameType(y, x), "nim does not consider these to be the same!"

eqTyp(A[float], float)

mratsim added a commit to mratsim/constantine that referenced this issue Apr 30, 2024
mratsim added a commit to mratsim/constantine that referenced this issue Apr 30, 2024
* ci: temporarily deactivate non-working CI pending nim-lang/Nim#23547 and nim-lang/nightlies#82

* remove macos from matrix include as well
mratsim added a commit to mratsim/constantine that referenced this issue Jun 11, 2024
@Araq
Copy link
Member

Araq commented Jun 12, 2024

This compiles:

type BigInt[N: static int] = object
  raw: array[N, uint64]

func isZero(a: BigInt): bool =
  discard

func isOne(a: BigInt): bool =
  discard

type
  QuadraticExt*[F] = object
    ## Quadratic Extension field
    coords*: array[2, F]

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

  ExtensionField*[F] = QuadraticExt[F] | CubicExt[F]

func isOne*[T](a: ExtensionField[T]): bool =
  ## Constant-time check if one
  result = a.coords[0].isOne()
  for i in 1 ..< a.coords.len:
    result = result and a.coords[i].isZero()

template mulCheckSparse*[T](a: var QuadraticExt[T], b: QuadraticExt[T]) =
  static:
    debugEcho "QuadraticExt b: ", b is QuadraticExt      # This is true
    debugEcho "ExtensionField b: ", b is ExtensionField  # This is false
  when isOne(b).bool:
    discard
  else:
    debugEcho "a *= b"

type EllipticCurve*[F] = object
  x*, y*, z*: F

template sumImpl[F](
       r: var EllipticCurve[F],
       P, Q: EllipticCurve[F],
       CoefA: F) {.dirty.} =
  when CoefA is int:
    debugEcho "EC addition with int CoefA"
  else:
    var b = P.x
    b.mulCheckSparse(CoefA)

func sum[F](
       r: var EllipticCurve[F],
       P, Q: EllipticCurve[F],
       CoefA: static F) =
  r.sumImpl(P, Q, CoefA)

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

const h2c_const_ec = QuadraticExt[BigInt[4]](
    coords: [BigInt[4](raw: [uint64 1, 1, 1, 1]),
             BigInt[4](raw: [uint64 1, 1, 1, 1])]
  )

var P = EllipticCurve[QuadraticExt[BigInt[4]]](
  x: QuadraticExt[BigInt[4]](
    coords: [BigInt[4](raw: [uint64 1, 2, 3, 4]),
             BigInt[4](raw: [uint64 1, 2, 3, 4])]
  ),
  y: QuadraticExt[BigInt[4]](
    coords: [BigInt[4](raw: [uint64 1, 2, 3, 4]),
             BigInt[4](raw: [uint64 1, 2, 3, 4])]
  ),
  z: QuadraticExt[BigInt[4]](
    coords: [BigInt[4](raw: [uint64 1, 2, 3, 4]),
             BigInt[4](raw: [uint64 1, 2, 3, 4])]
  )
)
var Q = EllipticCurve[QuadraticExt[BigInt[4]]](
  x: QuadraticExt[BigInt[4]](
    coords: [BigInt[4](raw: [uint64 1, 2, 3, 4]),
             BigInt[4](raw: [uint64 1, 2, 3, 4])]
  ),
  y: QuadraticExt[BigInt[4]](
    coords: [BigInt[4](raw: [uint64 1, 2, 3, 4]),
             BigInt[4](raw: [uint64 1, 2, 3, 4])]
  ),
  z: QuadraticExt[BigInt[4]](
    coords: [BigInt[4](raw: [uint64 1, 2, 3, 4]),
             BigInt[4](raw: [uint64 1, 2, 3, 4])]
  )
)

var R: EllipticCurve[QuadraticExt[BigInt[4]]]

R.sum(P, Q, h2c_const_ec)

mratsim added a commit to mratsim/constantine that referenced this issue Jun 23, 2024
mratsim added a commit to mratsim/constantine that referenced this issue Jun 26, 2024
mratsim added a commit to mratsim/constantine that referenced this issue Jun 27, 2024
@mratsim
Copy link
Collaborator Author

mratsim commented Jun 27, 2024

So the only difference is

func isOne*(a: ExtensionField): bool =
  ## Constant-time check if one
  result = 1'u64
  result = result and a.coords[0].isOne()
  for i in 1 ..< a.coords.len:
    result = result and a.coords[i].isZero()

was changed to

func isOne*[T](a: ExtensionField[T]): bool =
  ## Constant-time check if one
  result = a.coords[0].isOne()
  for i in 1 ..< a.coords.len:
    result = result and a.coords[i].isZero()

?

@mratsim
Copy link
Collaborator Author

mratsim commented Jul 6, 2024

Ah there was the change back to templates as well.

@SirOlaf
Copy link
Contributor

SirOlaf commented Jul 17, 2024

Real issue seems to be that typed arguments lose info about generic params for some reason. Before that related fix, type checking would also lose the same info so it "worked".

type
  A[T] = object
    x: T

proc mulCheckSparse[F](dummy: var A[F], x: static A[F]) =
  static:
    echo "mulCheckSparse: ", typeof(dummy), ", ", typeof(x) # when generic params not specified: A[system.int], A

template sumImpl(x: typed) =
  static:
    echo "sumImpl: ", typeof(x) # A
  var a = A[int]()
  mulCheckSparse(a, x) # fails here

proc sum[T](x: static T) =
  static:
    echo "sum: ", typeof(x) # A[system.int]
  sumImpl(x)

const a = A[int]()
sum[A[int]](a)

mratsim added a commit to mratsim/constantine that referenced this issue Jul 17, 2024
Araq pushed a commit that referenced this issue Jul 17, 2024
This adds Constantine to the important packages. Release announcements:
- https://forum.nim-lang.org/t/11935
- https://github.com/mratsim/constantine/releases/tag/v0.1.0

Unfortunately at the moment I'm in a conundrum.

- Constantine cannot compile on devel due to
#23547
- The workaround is changing 
  ```Nim
func mulCheckSparse*(a: var QuadraticExt, b: static QuadraticExt)
{.inline.} =
  ```
  to
  ```Nim
  template mulCheckSparse*(a: var QuadraticExt, b: QuadraticExt) =
  ```
but this does not compile on v2.0.8 due to `gensym` issues despite
#23716

![image](https://github.com/nim-lang/Nim/assets/22738317/21c875d7-512f-4c21-8547-d12534e93a58).
i.e. as mentioned in the issue
#23711 there is another gensym bug
within templates that was fixed in devel but not the v2.0.x series and
that is not fixed by #23716
Araq pushed a commit that referenced this issue Jul 17, 2024
Fix #23547

Tested locally with the included test, the test from constantine and the
original issue.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants