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: not part of closure object type #19984

Open
HJarausch opened this issue Jul 7, 2022 · 7 comments
Open

internal error: not part of closure object type #19984

HJarausch opened this issue Jul 7, 2022 · 7 comments

Comments

@HJarausch
Copy link

HJarausch commented Jul 7, 2022

I am trying the new recursive closure iterators.
A simple example works just fine.
But a larger one fails with
internal error: not part of closure object type

Unfortunately trying to come up with a smaller example source file (just the iterator is reference in the error message)
doesn't show the error.

So, I have to attach the full file with more than 2700 lines.

The error message is

Sudoku.nim(592, 18) Error: internal error: not part of closure object type

Nim Compiler Version 1.7.1 [Linux: amd64]
Compiled at 2022-07-07
git hash: 430a179

@HJarausch
Copy link
Author

Sudoku_D.nim.gz
I have reduced the failing example.
Now, commenting only two lines of code make the compiler error vanish.
Nim Compiler Version 1.7.3 [Linux: amd64]
Compiled at 2022-11-12
git hash: 852cf59
active boot switches: -d:release

@bung87
Copy link
Collaborator

bung87 commented Nov 19, 2022

the problem is Loop_next call itsself.

@HJarausch
Copy link
Author

Why is this a problem? Due to a recent patch, closure iterators are recursive.
I have tried simpler examples which all work just fine.
Thanks,
Helmut

@bung87
Copy link
Collaborator

bung87 commented Nov 19, 2022

maybe it's just a unhandled case , when I commented the error reporting it compiles and runs but get IndexError, didn't looking deeply into your code. could this exmaple be minimal, I haven't writen a resursive iterator myself.

@HJarausch
Copy link
Author

I have reduced the size of the code to less than 50 lines.
The error still occurs with
Nim Compiler Version 1.9.5 [Linux: amd64]
Compiled at 2023-07-04
Copyright (c) 2006-2023 by Andreas Rumpf

git hash: 31ba104
BUG3.nim.txt

@Araq
Copy link
Member

Araq commented Jul 4, 2023

From bug3.nim.txt:

#!/usr/bin/env nimr
import std/[sets, tables, sequtils]

type
  i8 = int8
  seq8 = seq[int8]
  Cell    = seq8
  NODE    = tuple[d_in:int8,Strong:bool,link:Cell]
  PATH    = seq[NODE]

var
  R_Cells : int = -1
  max_level : int

var
  Seen:HashSet[NODE]
  path:PATH

iterator Loop_next(strong_link:bool, d_in:int8, node:Cell, head:int8, 
              Seen:var HashSet[NODE], path: var PATH, level:int ) : PATH {.closure.} = 

  if level > max_level :
    return
  let GNode= len(node) > 1   # without this line, the code compiles
  
  var
    rt, ct, st : seq8
    column_type : bool

#[ with this code commented out the compiler error does not occurs ]#
    
  st= filter(st, proc(x:int8) : bool = x notin node)
  if column_type :
    rt= @[]
    ct= filter(ct, proc(x:int8) : bool = x notin node)
  else :  # row type
    rt= filter(rt, proc(x:int8) : bool = x notin node)
    ct= @[]

#[]#
iterator Nice_Loop( ) : PATH {.closure.} =
  for cell in 0i8..80i8 :
    let head= cell

    for pt in  Loop_next(true,0.i8,@[cell], head,Seen,path,0) :
      yield pt

for P in  Nice_Loop() :
  continue

@Araq Araq reopened this Jul 4, 2023
@Araq Araq added the Iterators label Jul 4, 2023
@dxxb
Copy link

dxxb commented Oct 19, 2024

As far as I can tell this has been fixed by #24316. Thank you @yglukhov.

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

6 participants