Closed mratsim closed 3 months ago
!nim c
import std/macros
type
Algebra* = enum
BN254_Snarks
BLS12_381
Fp*[Name: static Algebra] = object
limbs*: array[4, uint64]
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]
Fp2*[Name: static Algebra] =
QuadraticExt[Fp[Name]]
Fp4*[Name: static Algebra] =
QuadraticExt[Fp2[Name]]
Fp6*[Name: static Algebra] =
CubicExt[Fp2[Name]]
Fp12*[Name: static Algebra] =
CubicExt[Fp4[Name]]
# QuadraticExt[Fp6[Name]]
template Name*(E: type ExtensionField): Algebra =
E.F.Name
const BLS12_381_Order = [uint64 0x1, 0x2, 0x3, 0x4]
const BLS12_381_Modulus = [uint64 0x5, 0x6, 0x7, 0x8]
{.experimental: "dynamicBindSym".}
macro baseFieldModulus*(Name: static Algebra): untyped =
result = bindSym($Name & "_Modulus")
macro scalarFieldModulus*(Name: static Algebra): untyped =
result = bindSym($Name & "_Order")
type FieldKind* = enum
kBaseField
kScalarField
template getBigInt*(Name: static Algebra, kind: static FieldKind): untyped =
when kind == kBaseField:
Name.baseFieldModulus().typeof()
else:
Name.scalarFieldModulus().typeof()
type BenchMultiexpContext*[GT] = object
elems: seq[GT]
exponents: seq[getBigInt(GT.Name, kScalarField)]
proc createBenchMultiExpContext*(GT: typedesc, inputSizes: openArray[int]): BenchMultiexpContext[GT] =
discard
proc main() =
let ctx = createBenchMultiExpContext(Fp12[BLS12_381], [2, 4, 8, 16])
main()
0 (0 bytes)
```cpp
```
2024-07-18T00:50:23
2024-07-18T00:50:24
0 (0 bytes)
```cpp
```
2024-07-18T00:50:27
2024-07-18T00:50:28
91.05 Kb (93,232 bytes)
```cpp
#define NIM_INTBITS 64
#include "nimbase.h"
#include 2024-07-18T00:50:31
2024-07-18T00:50:32
91.05 Kb (93,232 bytes)
```cpp
#define NIM_INTBITS 64
#include "nimbase.h"
#include 2024-07-18T00:50:34
2024-07-18T00:50:35
95.74 Kb (98,040 bytes)
```cpp
#define NIM_INTBITS 64
#include "nimbase.h"
#include 2024-07-18T00:50:37
2024-07-18T00:50:38
91.43 Kb (93,624 bytes)
```cpp
#define NIM_INTBITS 64
#include "nimbase.h"
#include 2024-07-18T00:50:40
2024-07-18T00:50:40
91.47 Kb (93,664 bytes)
```cpp
#define NIM_INTBITS 64
#include "nimbase.h"
#include 2024-07-18T00:50:42
2024-07-18T00:50:42
87.59 Kb (89,688 bytes)
```cpp
#define NIM_INTBITS 64
#include "nimbase.h"
#include 2024-07-18T00:50:44
2024-07-18T00:50:45
2023-09-01 10:00:15 +0300
on commit #f1789cc46 with message:
```
resolve local symbols in generic type call RHS (#22610)
resolve local symbols in generic type call
fixes #14509
```
The bug is in the files:
```
compiler/semtypes.nim
tests/generics/m14509.nim
tests/generics/t14509.nim
```
The bug can be in the commits:
(Diagnostics sometimes off-by-one).11.4.0
14.0.0
20.4
2024-07-18T00:49:54Z
1
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
:robot: Bug found in 28 minutes
bisecting 709
commits at 25
commits per second
Simplified
type
QuadraticExt[F] = object
coords: array[2, F]
template Name(E: type QuadraticExt): int =
123
template getBigInt(Name: static int): untyped =
int
type Foo[GT] = object
a: getBigInt(GT.Name)
var x: Foo[QuadraticExt[int]]
In my full example
reordering
type BenchMultiexpContext*[GT] = object
tp: Threadpool
numInputs: int
elems: seq[GT]
exponents: seq[getBigInt(GT.Name, kScalarField)]
to
type BenchMultiexpContext*[GT] = object
tp: Threadpool
numInputs: int
exponents: seq[getBigInt(GT.Name(), kScalarField)]
elems: seq[GT]
makes things compile
https://github.com/mratsim/constantine/pull/436/commits/70a27fc38cab42e1a04a78c444879d94ed4ba26b
EDIT: actually it's the parenthesis that mattered
Here is a regression between Nim 2.0.4 and Nim 2.0.6 that also affects devel and Nim v2.2.0 RC1
This compiles on Nim 2.0.4 but not on Nim 2.0.6 or later, error is
Error: cannot instantiate: 'ExtensionField[F]'; Maybe generic arguments are missing?
The issue comes from the usage of the getBigInt template in an object. However, I tried 2 other approaches and couldn't make them work for type parameter in functions.