Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

internal error for auto iterator #12487

Open
pb-cdunn opened this issue Oct 22, 2019 · 4 comments
Open

internal error for auto iterator #12487

pb-cdunn opened this issue Oct 22, 2019 · 4 comments

Comments

@pb-cdunn
Copy link
Contributor

pb-cdunn commented Oct 22, 2019

EDIT by @narimiran - simplified example at the top, so our tools can pick it up:

iterator FaiReader(): string {.closure.} =
  yield "something"

template toClosure(i): auto =
  iterator j: string {.closure.} =
    for x in FaiReader():
      yield x
  j

proc main = 
  var reader = toClosure(FaiReader())

main()

Somewhat related: #5859

I am trying to pass an iterator to another proc. To do that, I've tried using the toClosure() template from @def- : https://forum.nim-lang.org/t/2027

Example

https://github.com/bio-nim/pb/blob/internal-error/src/falconcpkg/rotate.nim

(Hopefully that file will compile for you if you copy/paste, as I've commented out the dependencies.)

Current Output

rotate.nim(182, 9) Error: internal error: expr: var not init FaiReader_932476
No stack traceback available
180 template toClosure(i): auto =
181   iterator j: type(i) {.closure.} =
182     for x in i:
183       yield x
184   j
...
199     var reader = toClosure(FaiReader(fin, full_sequence))

Expected Output

I am willing to do this a different way. I just can't figure out how to pass an "iterator" to another proc, the way I would pass a "generator" in Python.

I thought toClosure() would at least allow me to see the type it returns, using typetraits, but I cannot get this to compile at all.

Possible Solution

No idea. For now, I will simply avoid passing an iterator. But it's a useful pattern if it can work. Again, here is info on passing iterators: https://forum.nim-lang.org/t/2027

Additional Information

$ nim -v
Nim Compiler Version 1.0.99 [Linux: amd64]
Compiled at 2019-09-28

also fails for

Nim Compiler Version 0.20.2 [Linux: amd64]
Compiled at 2019-07-17

I'm on Linux.

@pb-cdunn
Copy link
Contributor Author

Some discussion at https://forum.nim-lang.org/t/5384

This might be a subtle compiler bug.

@ghost
Copy link

ghost commented Jul 27, 2020

Short example to reproduce:

iterator FaiReader(): string {.closure.} =
  yield "something"

template toClosure(i): auto =
  iterator j: string {.closure.} =
    for x in FaiReader():
      yield x
  j

proc main = 
  var reader = toClosure(FaiReader())

main()

@metagn
Copy link
Collaborator

metagn commented Aug 29, 2024

Works in devel but not in 2.0?

Araq pushed a commit that referenced this issue Aug 30, 2024
closes #1969, closes #7547, closes #7737, closes #11838, closes #12283,
closes #12714, closes #12720, closes #14053, closes #16118, closes
#19670, closes #22645

I was going to wait on these but regression tests even for recent PRs
are turning out to be important in wide reaching PRs like #24010.

The other issues with the working label felt either finnicky (#7385,
#9156, #12732, #15247), excessive to test (#12405, #12424, #17527), or I
just don't know what fixed them/what the issue was (#16128: the PR link
gives a server error by Github, #12457, #12487).
@metagn
Copy link
Collaborator

metagn commented Sep 16, 2024

Fails again since #24108 and works with -d:nimOptIter, meaning #23787 fixed it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants