nim-lang / Nim

Nim is a statically typed compiled systems programming language. It combines successful concepts from mature languages like Python, Ada and Modula. Its design focuses on efficiency, expressiveness, and elegance (in that order of priority).
https://nim-lang.org
Other
16.22k stars 1.46k forks source link

[Semi-regression] C code contains backtick`gensym #23711

Closed mratsim closed 1 week ago

mratsim commented 2 weeks ago

As mentioned in Discord at https://discord.com/channels/371759389889003530/768367394547957761/1250440092208730152

Using the latest version2-0 branch I have a regression compared to 2.0.4 that leads to backtick of gensym'ed symbols not being translated to X60 as usual due to https://github.com/nim-lang/Nim/pull/22944 being backported.

See CI run: https://github.com/mratsim/constantine/actions/runs/9471919674/job/26096274691?pr=393#step:23:47

image

It seems to also lead to conflicting types using same name variables image

https://github.com/mratsim/constantine/actions/runs/9471919674/job/26096274691?pr=393#step:23:13


Reproducing

git clone https://github.com/mratsim/constantine
cd constantine
nim c --cc:clang --outdir:build -d:danger --hints:off --warnings:off --verbosity:0 --threads:on --noMain --app:lib --nimMainPrefix:ctt_init_ --nimcache:nimcache/X60 bindings/lib_constantine.nim

Note that gcc-14 has issues that might not be backported yet so it's easier to use Clang (https://github.com/nim-lang/Nim/pulls?q=is%3Apr+%22gcc+14%22+is%3Aclosed+ )


Similar bug

If it helps, in the past I used to have those issues in v2.0.4, but only in templates and only with {.noInit.} variables.

I found 2 workarounds:

  1. functions see: https://github.com/mratsim/constantine/pull/338/files#diff-9d369fc072ba230397943805ef3e09f4726cef5166ed8774d71657ee0fe0a6c1L1442 image
  2. Using inject see: https://github.com/mratsim/constantine/pull/346/files#diff-9af16dfbdb13c0086d14ae9290dab7feba9d35fe1e14f3a4f8ca04455aef49b2L68 image

    Unfortunately I tried to minimize the issue to a single file and failed at the time.

mratsim commented 2 weeks ago

Also it's important to note that some errors are generated even in files with no push

image

https://github.com/mratsim/constantine/blob/master/constantine/math/extension_fields/square_root_fp2.nim

The z_NEQ variable comes from this template: https://github.com/mratsim/constantine/blob/6ca7cbf/constantine/platforms/constant_time/ct_routines.nim#L138-L141

image

and the top of the file pushes {.inline.}, which is not applied to templates, and {.raises: [].}