Skip to content

Commit

Permalink
feat(nim-v2.2.0 RC1): compatibility fix for nim-lang/Nim#23547
Browse files Browse the repository at this point in the history
  • Loading branch information
mratsim committed Jul 17, 2024
1 parent 4f31dcb commit 6a9a334
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 12 deletions.
8 changes: 3 additions & 5 deletions constantine/math/endomorphisms/split_scalars.nim
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,8 @@ template decomposeEndoImpl[scalBits: static int](
static: doAssert L >= ceilDiv_vartime(frBits, M) + 1
const w = frBits.wordsRequired()

# Upstream bug:
# {.noInit.} variables must be {.inject.} as well
# or they'll be mangled as foo`gensym12345 instead of fooX60gensym12345 in C codegen

when M == 2:
# inject works around alphas'gensym codegen in Nim v2.0.8 (not necessary in Nim v2.2.x) - https://github.com/nim-lang/Nim/pull/23801#issue-2393452970
var alphas{.noInit, inject.}: (
BigInt[frBits + babai(Name, G)[0][0].bits],
BigInt[frBits + babai(Name, G)[1][0].bits]
Expand All @@ -76,7 +73,8 @@ template decomposeEndoImpl[scalBits: static int](
# We have k0 = s - 𝛼0 b00 - 𝛼1 b10 ... - 𝛼m bm0
# and kj = 0 - 𝛼j b0j - 𝛼1 b1j ... - 𝛼m bmj
var
k {.inject.}: array[M, BigInt[frBits]] # zero-init required
k {.inject.}: array[M, BigInt[frBits]] # zero-init required, and inject for caller visibility
# inject works around alphas'gensym codegen in Nim v2.0.8 (not necessary in Nim v2.2.x) - https://github.com/nim-lang/Nim/pull/23801#issue-2393452970
alphaB {.noInit, inject.}: BigInt[frBits]
k[0].copyTruncatedFrom(scalar)
staticFor miniScalarIdx, 0, M:
Expand Down
12 changes: 5 additions & 7 deletions constantine/math/extension_fields/towers.nim
Original file line number Diff line number Diff line change
Expand Up @@ -1436,15 +1436,14 @@ func mul_sparse_by_x0*(a: var QuadraticExt, sparseB: QuadraticExt) =
## Sparse in-place multiplication
a.mul_sparse_by_x0(a, sparseB)

func mulCheckSparse*(a: var QuadraticExt, b: static QuadraticExt) {.inline.} =
template mulCheckSparse*(a: var QuadraticExt, b: QuadraticExt) =
when isOne(b).bool:
discard
elif isMinusOne(b).bool:
a.neg()
elif isZero(c0(b)).bool and isOne(c1(b)).bool:
# TODO: raise upstream, in Nim v2 templates {.noInit.} temporaries use incorrect t`gensymXXXX
# hence we use an inline function with static argument
var t {.noInit.}: type(a.c0)
# inject works around t'gensym codegen in Nim v2.0.8 (not necessary in Nim v2.2.x) - https://github.com/nim-lang/Nim/pull/23801#issue-2393452970
var t {.noInit, inject.}: type(a.c0)
when fromComplexExtension(b):
t.neg(a.c1)
a.c1 = a.c0
Expand All @@ -1454,9 +1453,8 @@ func mulCheckSparse*(a: var QuadraticExt, b: static QuadraticExt) {.inline.} =
a.c1 = a.c0
a.c0 = t
elif isZero(c0(b)).bool and isMinusOne(c1(b)).bool:
# TODO: raise upstream, in Nim v2 templates {.noInit.} temporaries use incorrect t`gensymXXXX
# hence we use an inline function with static argument
var t {.noInit.}: type(a.c0)
# inject works around t'gensym codegen in Nim v2.0.8 (not necessary in Nim v2.2.x) - https://github.com/nim-lang/Nim/pull/23801#issue-2393452970
var t {.noInit, inject.}: type(a.c0)
when fromComplexExtension(b):
t = a.c1
a.c1.neg(a.c0)
Expand Down

0 comments on commit 6a9a334

Please sign in to comment.