Nim icon indicating copy to clipboard operation
Nim copied to clipboard

generates code gcc 9.4.0 fails to compile with types/generics

Open tersec opened this issue 1 year ago • 0 comments

Description

a.nim

proc readValue(T: type): T =
  mixin readValue
  readValue(result)

import "."/b

type beaconBlocksByRange_v2Obj = object
  x: int

discard readValue(beaconBlocksByRange_v2Obj)

b.nim

import "."/c

proc readValue*(val: var auto)  =
  mixin readSszBytes
  readSszBytes(@[], val)

template toSszType*(v: auto): auto =
  type T = type(v)
  v

proc readSszBytes*[T](data: openArray[byte], val: var T) =
  readSszValue(data, toSszType(val))

c.nim

proc readSszValue*[T](
    input: openArray[byte], val: var T) =
  discard

Nim Version

Nim Compiler Version 1.6.20 [Linux: amd64]
Compiled at 2024-03-28
Copyright (c) 2006-2023 by Andreas Rumpf

git hash: 8f9fde0615c686357774736c0bce6f3c2075a94d
active boot switches: -d:release
Nim Compiler Version 2.0.4 [Linux: amd64]
Compiled at 2024-03-28
Copyright (c) 2006-2023 by Andreas Rumpf

git hash: b47747d31844c6bd9af4322efe55e24fefea544c
active boot switches: -d:release
Nim Compiler Version 2.1.1 [Linux: amd64]
Compiled at 2024-03-28
Copyright (c) 2006-2024 by Andreas Rumpf

git hash: 4b6a9e4add2af2a458d171b23030acb5d1c70ecb
active boot switches: -d:release
gcc (Ubuntu 9.4.0-1ubuntu1~20.04.2) 9.4.0
Copyright (C) 2019 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Current Output

Hint: used config file '/root/nim16/config/nim.cfg' [Conf]
Hint: used config file '/root/nim16/config/config.nims' [Conf]
............................................................
/root/repro/b.nim(8, 8) Hint: 'T`gensym0' is declared but not used [XDeclaredButNotUsed]
CC: ../nim16/lib/std/private/digitsutils.nim
CC: ../nim16/lib/system/dollars.nim
CC: ../nim16/lib/system.nim
CC: c.nim
CC: b.nim
CC: a.nim
/root/.cache/nim/a_d/@mb.nim.c: In function 'readSszBytes__a_u20':
/root/.cache/nim/a_d/@mb.nim.c:73:42: error: dereferencing pointer to incomplete type 'tyObject_beaconBlocksByRange_v2Obj__35aSqJQLcKYIW49cpVFHRpQ' {aka 'struct tyObject_beaconBlocksByRange_v2Obj__35aSqJQLcKYIW49cpVFHRpQ'}
   73 |  readSszValue__a_u27(data, dataLen_0, (&(*val)));
      |                                          ^~~~
Error: execution of an external compiler program 'gcc -c  -w -fmax-errors=3   -I/root/nim16/lib -I/root/repro -o /root/.cache/nim/a_d/@mb.nim.c.o /root/.cache/nim/a_d/@mb.nim.c' failed with exit code: 1


Hint: used config file '/root/nim20/config/nim.cfg' [Conf]
Hint: used config file '/root/nim20/config/config.nims' [Conf]
........................................................................
/root/repro/b.nim(8, 8) Hint: 'T`gensym0' is declared but not used [XDeclaredButNotUsed]
CC: ../nim20/lib/system/exceptions.nim
CC: ../nim20/lib/std/private/digitsutils.nim
CC: ../nim20/lib/system/dollars.nim
CC: ../nim20/lib/system.nim
CC: c.nim
CC: b.nim
CC: a.nim
/root/.cache/nim/a_d/@mb.nim.c: In function 'readSszBytes__a_u20':
/root/.cache/nim/a_d/@mb.nim.c:82:60: error: dereferencing pointer to incomplete type 'tyObject_beaconBlocksByRange_v2Obj__35aSqJQLcKYIW49cpVFHRpQ' {aka 'struct tyObject_beaconBlocksByRange_v2Obj__35aSqJQLcKYIW49cpVFHRpQ'}
   82 |  nimln_(12); readSszValue__a_u27(data_p0, data_p0Len_0, (&(*val_p1)));
      |                                                            ^~~~~~~
Error: execution of an external compiler program 'gcc -c  -w -fmax-errors=3 -pthread   -I/root/nim20/lib -I/root/repro -o /root/.cache/nim/a_d/@mb.nim.c.o /root/.cache/nim/a_d/@mb.nim.c' failed with exit code: 1


Hint: used config file '/root/nimdevel/config/nim.cfg' [Conf]
Hint: used config file '/root/nimdevel/config/config.nims' [Conf]
.......................................................................
/root/repro/b.nim(8, 8) Hint: 'T`gensym0' is declared but not used [XDeclaredButNotUsed]
CC: ../nimdevel/lib/system/exceptions.nim
CC: ../nimdevel/lib/std/private/since.nim
CC: ../nimdevel/lib/system/ctypes.nim
CC: ../nimdevel/lib/std/sysatomics.nim
CC: ../nimdevel/lib/system/ansi_c.nim
CC: ../nimdevel/lib/system/memory.nim
CC: ../nimdevel/lib/std/private/syslocks.nim
CC: ../nimdevel/lib/std/private/threadtypes.nim
CC: ../nimdevel/lib/std/private/digitsutils.nim
CC: ../nimdevel/lib/std/private/miscdollars.nim
CC: ../nimdevel/lib/std/assertions.nim
CC: ../nimdevel/lib/system/iterators.nim
CC: ../nimdevel/lib/system/coro_detection.nim
CC: ../nimdevel/lib/std/private/dragonbox.nim
CC: ../nimdevel/lib/std/private/schubfach.nim
CC: ../nimdevel/lib/std/formatfloat.nim
CC: ../nimdevel/lib/std/objectdollar.nim
CC: ../nimdevel/lib/system/dollars.nim
CC: ../nimdevel/lib/std/typedthreads.nim
CC: ../nimdevel/lib/system/stacktraces.nim
CC: ../nimdevel/lib/std/private/bitops_utils.nim
CC: ../nimdevel/lib/system/countbits_impl.nim
CC: ../nimdevel/lib/system/repr_v2.nim
CC: ../nimdevel/lib/std/widestrs.nim
CC: ../nimdevel/lib/std/syncio.nim
CC: ../nimdevel/lib/system.nim
CC: c.nim
CC: b.nim
CC: a.nim
/root/.cache/nim/a_d/@mb.nim.c: In function 'readSszBytes__a_u20':
/root/.cache/nim/a_d/@mb.nim.c:83:60: error: dereferencing pointer to incomplete type 'tyObject_beaconBlocksByRange_v2Obj__35aSqJQLcKYIW49cpVFHRpQ' {aka 'struct tyObject_beaconBlocksByRange_v2Obj__35aSqJQLcKYIW49cpVFHRpQ'}
   83 |  nimln_(12); readSszValue__a_u27(data_p0, data_p0Len_0, (&(*val_p1)));
      |                                                            ^~~~~~~
Error: execution of an external compiler program 'gcc -c  -w -fmax-errors=3 -pthread   -I/root/nimdevel/lib -I/root/repro -o /root/.cache/nim/a_d/@mb.nim.c.o /root/.cache/nim/a_d/@mb.nim.c' failed with exit code: 1

Expected Output

No "Error: execution of an external compiler program ..." errors

Possible Solution

No response

Additional Information

No response

tersec avatar Mar 28 '24 15:03 tersec