Open timotheecour opened 6 years ago
so the root problem is that --define:createNimRtl --app:lib
implies {.rtl.}
implies {. exportc: "nimrtl_$1", dynlib .}
implies {.cdecl.}
and that's incompatible with map
's 2nd argument op
in lib/pure/collections/sequtils.nim:
proc map*[T, S](s: openArray[T], op: proc (x: T): S ): seq[S] =
newSeq(result, s.len)
for i in 0 ..< s.len:
result[i] = op(s[i])
However this works if we use instead:
proc map3*[Fun, T](s: openArray[T], op: Fun ): auto =
result = newSeq[type(op(s[0]))](s.len)
for i in 0 ..< s.len:
result[i] = op(s[i])
workaround in some cases: use mapIt(fun(it))
instead of map(fun)
(now that https://github.com/nim-lang/Nim/pull/8543 was merged)
EDIT => blocked by another issue: https://github.com/nim-lang/Nim/issues/8577
@araq can sigmatch ignore {.cdecl.}, assuming it's only used for name mangling of a declaration?
Oh no, .cdecl
is really a different calling convention (a slower one on 32 bit Windows) and has little to do with mangling.
I was misled by this comment:
# since we'll be loading the dynlib symbols dynamically, we must use
# a calling convention that doesn't introduce custom name mangling
# cdecl is the default - the user can override this explicitly
but the manual indeed says:
decl
The cdecl convention means that a procedure shall use the same convention as the C compiler. Under Windows the generated C procedure is declared with the __cdecl keyword.
reduced from a mysterious error I was seeing here https://travis-ci.org/nim-lang/Nim/jobs/402492005 for this PR: https://github.com/nim-lang/Nim/pull/8272
The code that caused it:
it worked if I wrote instead:
After further investigating and reducing the error it boils down to:
map
somehow can't be used with a proc that's marked as{.rtl.}
(or, after reducing further from the definition of rtl in system/inclrtl, if it's marked as{. exportc: "nimrtl_$1", dynlib .}
)Isn't that a bug?
it makes things work locally but fail on travis/appveyor. (or fail locally when run with
nim c -o:app --define:createNimRtl --app:lib test.nim
instead ofnim c -o:app --app:lib test.nim
(when something uses {.rtl.}))(or fail when using
nim c -o:app bugs/t50_app_lib_map.nim
when something uses{. exportc: "nimrtl_$1", dynlib .}
)[EDIT] workaround in some cases see https://github.com/nim-lang/Nim/issue_comments#issuecomment-411508903