Nim: [regression] Importing more than one module with same name from different packages produce bad codegen

Created on 12 Oct 2019  路  5Comments  路  Source: nim-lang/Nim


One of the module have to contains initialization code.
The other one contains procs.
The importer import the two or more modules with same name directly or indirectly via another module.
It will trigger bad codegen.

Example

# module a/utils.nim
proc burnMem*(a: int) =
  discard
# module b/utils.nim
let x = 10
import b/utils, a/utils as autils

burnMem(10)

Current Output

F:\nimcache\bug\debug\utils.nim.c.o:utils.nim.c:(.text+0xaa): multiple definition of `burnMem__1hiCVbSm2i9a2dZa7QJ9aihg'
F:\nimcache\bug\debug\utils.nim.c.o:utils.nim.c:(.text+0xaa): first defined here
F:\nimcache\bug\debug\bug.nim.c.o:bug.nim.c:(.text+0xd4): undefined reference to `unknown_utilsInit000'
collect2.exe: error: ld returned 1 exit status
Error: execution of an external program failed: 'gcc.exe   -o F:\projects\bug\bug.exe  F:\nimcache\bug\debug\stdlib_io.nim.c.o F:\nimcache\bug\debug\stdlib_system.nim.c.o F:\nimcache\bug\debug\utils.nim.c.o F:\nimcache\bug\debug\utils.nim.c.o F:\nimcache\bug\debug\bug.nim.c.o    '

Additional Information

$ nim -v
Nim Compiler Version 1.0.99 [Windows: amd64]
Compiled at 2019-10-12
Copyright (c) 2006-2019 by Andreas Rumpf

git hash: eeffa0163fba932f5e0a16023ef3c4b833b36358
active boot switches: -d:release
Showstopper

Most helpful comment

Sorry for wasting your time. After I remove all nimcache and rebuild the compiler with latest devel branch the problem is gone. Somehow the nimcache messed up with the compiler binary.
Thanks again for your hard work. We will soon move to Nim 1.0.2.

All 5 comments

hi @araq, thank you for fixing this one. but I still encounter the same problem if the modules are located in nimble install dir and not located in local subdir. could you please take a look?

How to reproduce?

the easiest perhaps follow this steps:

$> nimble install eth
$> nimble install nimcrypto

then compile this file with nim c -threads:on -d:metrics bug

# bug.nim
import eth/common/utils as autils, nimcrypto/utils

var x: array[100, byte]
burnMem(x)

But this compiles for me...

Sorry for wasting your time. After I remove all nimcache and rebuild the compiler with latest devel branch the problem is gone. Somehow the nimcache messed up with the compiler binary.
Thanks again for your hard work. We will soon move to Nim 1.0.2.

Was this page helpful?
0 / 5 - 0 ratings