Skip to content

ARC codegen bug with inline iterators #14219

@ghost

Description

This code works with default GC but fails with --gc:arc at C compiler stage (probably due to some error in handling of inline iterators?).

Found in https://github.com/cheatfate/nimcrypto
Also affects https://github.com/oprypin/nim-random

Compile nim c --gc:arc a.nim

Example

# a.nim
import b
# b.nim
var vectors = @["a", "b", "c", "d", "e"]

iterator testVectors(): string =
  for vector in vectors:
    yield vector

for item in testVectors():
  echo item

Current Output

/home/dian/.cache/nim/a_d/@ma.nim.c: In function 'NimMainModule':
/home/dian/.cache/nim/a_d/@ma.nim.c:153:40: error: 'vector' undeclared (first use in this function)
  153 |  eqdestroy___dS1BF3Vxjg9aJMmmhVJKSpQ((&vector));
      |                                        ^~~~~~
/home/dian/.cache/nim/a_d/@ma.nim.c:153:40: note: each undeclared identifier is reported only once for each function it appears in
Error: execution of an external compiler program 'gcc -c  -w   -I/home/dian/.nim/lib -I/home/dian/Projects/data/nimcrypto -o /home/dian/.cache/nim/a_d/@ma.nim.c.o /home/dian/.cache/nim/a_d/@ma.nim.c' failed with exit code: 1

Expected Output

a
b
c
d
e
$ nim -v
Nim Compiler Version 1.3.1 [Linux: amd64]
Compiled at 2020-05-04
Copyright (c) 2006-2020 by Andreas Rumpf

git hash: 603010f8c9d9655bb0fa3f91dc0bd1b76d3a0bd3
active boot switches: -d:release

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions