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

fix #22548;environment misses for type reference in iterator access n… #22559

Merged
merged 5 commits into from
Aug 27, 2023

Conversation

bung87
Copy link
Collaborator

@bung87 bung87 commented Aug 25, 2023

…ested in closure

fix #22548
fix #21737

@bung87

This comment was marked as duplicate.

@juancarlospaco
Copy link
Collaborator

@bung87
Comment must start with the !nim because it checks the first line only for performance for fast builds,
you can have any arbitrary text and links after the code blocks (or write the text on other comment):
https://github.com/juancarlospaco/nimrun-action/blob/ab65b08c2b52e338f1069de69f51cc4f5253dfb5/index.js#L187

@bung87 bung87 force-pushed the fix-22548 branch 2 times, most recently from edc32f8 to 38d298e Compare August 25, 2023 17:56
@bung87
Copy link
Collaborator Author

bung87 commented Aug 25, 2023

!nim c

template mytoSeq*(iter: untyped): untyped =
  var result: seq[typeof(iter)]# = @[]
  for x in iter:
    result.add(x)
  result

iterator test(dir:int):int=
  yield 1234

iterator walkGlobKinds (): int =
  let dir = 123
  let it = mytoSeq(test(dir))  

proc main()=
    let it = iterator():int=
      for path in walkGlobKinds():
          yield path
main()

refs: #21737

@github-actions
Copy link
Contributor

@bung87 (collaborator)

devel 👎 FAIL

Output

Error: Command failed: nim c --run  -d:nimDebugDlOpen -d:ssl -d:nimDisableCertificateValidation --forceBuild:on --colors:off --verbosity:0 --hints:off --warnings:off --lineTrace:off --nimcache:/home/runner/work/Nim/Nim --out:/home/runner/work/Nim/Nim/temp /home/runner/work/Nim/Nim/temp.nim
/home/runner/work/Nim/Nim/temp.nim(10, 25) Error: internal error: environment misses: dir

Stats

  • Started 2023-08-25T18:15:23
  • Finished 2023-08-25T18:15:23
  • Duration

IR

Compiled filesize 0 bytes (0 bytes)

AST

nnkStmtList.newTree(
  nnkTemplateDef.newTree(
    nnkPostfix.newTree(
      newIdentNode("*"),
      newIdentNode("mytoSeq")
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      newIdentNode("untyped"),
      nnkIdentDefs.newTree(
        newIdentNode("iter"),
        newIdentNode("untyped"),
        newEmptyNode()
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkVarSection.newTree(
        nnkIdentDefs.newTree(
          newIdentNode("result"),
          nnkBracketExpr.newTree(
            newIdentNode("seq"),
            nnkCall.newTree(
              newIdentNode("typeof"),
              newIdentNode("iter")
            )
          ),
          newEmptyNode()
        )
      ),
      nnkForStmt.newTree(
        newIdentNode("x"),
        newIdentNode("iter"),
        nnkStmtList.newTree(
          nnkCall.newTree(
            nnkDotExpr.newTree(
              newIdentNode("result"),
              newIdentNode("add")
            ),
            newIdentNode("x")
          )
        )
      ),
      newIdentNode("result")
    )
  ),
  nnkIteratorDef.newTree(
    newIdentNode("test"),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      newIdentNode("int"),
      nnkIdentDefs.newTree(
        newIdentNode("dir"),
        newIdentNode("int"),
        newEmptyNode()
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkYieldStmt.newTree(
        newLit(1234)
      )
    )
  ),
  nnkIteratorDef.newTree(
    newIdentNode("walkGlobKinds"),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      newIdentNode("int")
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkLetSection.newTree(
        nnkIdentDefs.newTree(
          newIdentNode("dir"),
          newEmptyNode(),
          newLit(123)
        )
      ),
      nnkLetSection.newTree(
        nnkIdentDefs.newTree(
          newIdentNode("it"),
          newEmptyNode(),
          nnkCall.newTree(
            newIdentNode("mytoSeq"),
            nnkCall.newTree(
              newIdentNode("test"),
              newIdentNode("dir")
            )
          )
        )
      )
    )
  ),
  nnkProcDef.newTree(
    newIdentNode("main"),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      newEmptyNode()
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkLetSection.newTree(
        nnkIdentDefs.newTree(
          newIdentNode("it"),
          newEmptyNode(),
          nnkIteratorDef.newTree(
            newEmptyNode(),
            newEmptyNode(),
            newEmptyNode(),
            nnkFormalParams.newTree(
              newIdentNode("int")
            ),
            newEmptyNode(),
            newEmptyNode(),
            nnkStmtList.newTree(
              nnkForStmt.newTree(
                newIdentNode("path"),
                nnkCall.newTree(
                  newIdentNode("walkGlobKinds")
                ),
                nnkStmtList.newTree(
                  nnkYieldStmt.newTree(
                    newIdentNode("path")
                  )
                )
              )
            )
          )
        )
      )
    )
  ),
  nnkCall.newTree(
    newIdentNode("main")
  )
)
stable 👎 FAIL

Output

Error: Command failed: nim c --run  -d:nimDebugDlOpen -d:ssl -d:nimDisableCertificateValidation --forceBuild:on --colors:off --verbosity:0 --hints:off --warnings:off --lineTrace:off --nimcache:/home/runner/work/Nim/Nim --out:/home/runner/work/Nim/Nim/temp /home/runner/work/Nim/Nim/temp.nim
/home/runner/work/Nim/Nim/temp.nim(10, 25) Error: internal error: environment misses: dir

Stats

  • Started 2023-08-25T18:15:24
  • Finished 2023-08-25T18:15:24
  • Duration

IR

Compiled filesize 0 bytes (0 bytes)

AST

nnkStmtList.newTree(
  nnkTemplateDef.newTree(
    nnkPostfix.newTree(
      newIdentNode("*"),
      newIdentNode("mytoSeq")
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      newIdentNode("untyped"),
      nnkIdentDefs.newTree(
        newIdentNode("iter"),
        newIdentNode("untyped"),
        newEmptyNode()
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkVarSection.newTree(
        nnkIdentDefs.newTree(
          newIdentNode("result"),
          nnkBracketExpr.newTree(
            newIdentNode("seq"),
            nnkCall.newTree(
              newIdentNode("typeof"),
              newIdentNode("iter")
            )
          ),
          newEmptyNode()
        )
      ),
      nnkForStmt.newTree(
        newIdentNode("x"),
        newIdentNode("iter"),
        nnkStmtList.newTree(
          nnkCall.newTree(
            nnkDotExpr.newTree(
              newIdentNode("result"),
              newIdentNode("add")
            ),
            newIdentNode("x")
          )
        )
      ),
      newIdentNode("result")
    )
  ),
  nnkIteratorDef.newTree(
    newIdentNode("test"),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      newIdentNode("int"),
      nnkIdentDefs.newTree(
        newIdentNode("dir"),
        newIdentNode("int"),
        newEmptyNode()
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkYieldStmt.newTree(
        newLit(1234)
      )
    )
  ),
  nnkIteratorDef.newTree(
    newIdentNode("walkGlobKinds"),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      newIdentNode("int")
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkLetSection.newTree(
        nnkIdentDefs.newTree(
          newIdentNode("dir"),
          newEmptyNode(),
          newLit(123)
        )
      ),
      nnkLetSection.newTree(
        nnkIdentDefs.newTree(
          newIdentNode("it"),
          newEmptyNode(),
          nnkCall.newTree(
            newIdentNode("mytoSeq"),
            nnkCall.newTree(
              newIdentNode("test"),
              newIdentNode("dir")
            )
          )
        )
      )
    )
  ),
  nnkProcDef.newTree(
    newIdentNode("main"),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      newEmptyNode()
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkLetSection.newTree(
        nnkIdentDefs.newTree(
          newIdentNode("it"),
          newEmptyNode(),
          nnkIteratorDef.newTree(
            newEmptyNode(),
            newEmptyNode(),
            newEmptyNode(),
            nnkFormalParams.newTree(
              newIdentNode("int")
            ),
            newEmptyNode(),
            newEmptyNode(),
            nnkStmtList.newTree(
              nnkForStmt.newTree(
                newIdentNode("path"),
                nnkCall.newTree(
                  newIdentNode("walkGlobKinds")
                ),
                nnkStmtList.newTree(
                  nnkYieldStmt.newTree(
                    newIdentNode("path")
                  )
                )
              )
            )
          )
        )
      )
    )
  ),
  nnkCall.newTree(
    newIdentNode("main")
  )
)
2.0.0 👎 FAIL

Output

Error: Command failed: nim c --run  -d:nimDebugDlOpen -d:ssl -d:nimDisableCertificateValidation --forceBuild:on --colors:off --verbosity:0 --hints:off --warnings:off --lineTrace:off --nimcache:/home/runner/work/Nim/Nim --out:/home/runner/work/Nim/Nim/temp /home/runner/work/Nim/Nim/temp.nim
/home/runner/work/Nim/Nim/temp.nim(10, 25) Error: internal error: environment misses: dir

Stats

  • Started 2023-08-25T18:15:25
  • Finished 2023-08-25T18:15:25
  • Duration

IR

Compiled filesize 0 bytes (0 bytes)

AST

nnkStmtList.newTree(
  nnkTemplateDef.newTree(
    nnkPostfix.newTree(
      newIdentNode("*"),
      newIdentNode("mytoSeq")
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      newIdentNode("untyped"),
      nnkIdentDefs.newTree(
        newIdentNode("iter"),
        newIdentNode("untyped"),
        newEmptyNode()
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkVarSection.newTree(
        nnkIdentDefs.newTree(
          newIdentNode("result"),
          nnkBracketExpr.newTree(
            newIdentNode("seq"),
            nnkCall.newTree(
              newIdentNode("typeof"),
              newIdentNode("iter")
            )
          ),
          newEmptyNode()
        )
      ),
      nnkForStmt.newTree(
        newIdentNode("x"),
        newIdentNode("iter"),
        nnkStmtList.newTree(
          nnkCall.newTree(
            nnkDotExpr.newTree(
              newIdentNode("result"),
              newIdentNode("add")
            ),
            newIdentNode("x")
          )
        )
      ),
      newIdentNode("result")
    )
  ),
  nnkIteratorDef.newTree(
    newIdentNode("test"),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      newIdentNode("int"),
      nnkIdentDefs.newTree(
        newIdentNode("dir"),
        newIdentNode("int"),
        newEmptyNode()
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkYieldStmt.newTree(
        newLit(1234)
      )
    )
  ),
  nnkIteratorDef.newTree(
    newIdentNode("walkGlobKinds"),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      newIdentNode("int")
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkLetSection.newTree(
        nnkIdentDefs.newTree(
          newIdentNode("dir"),
          newEmptyNode(),
          newLit(123)
        )
      ),
      nnkLetSection.newTree(
        nnkIdentDefs.newTree(
          newIdentNode("it"),
          newEmptyNode(),
          nnkCall.newTree(
            newIdentNode("mytoSeq"),
            nnkCall.newTree(
              newIdentNode("test"),
              newIdentNode("dir")
            )
          )
        )
      )
    )
  ),
  nnkProcDef.newTree(
    newIdentNode("main"),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      newEmptyNode()
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkLetSection.newTree(
        nnkIdentDefs.newTree(
          newIdentNode("it"),
          newEmptyNode(),
          nnkIteratorDef.newTree(
            newEmptyNode(),
            newEmptyNode(),
            newEmptyNode(),
            nnkFormalParams.newTree(
              newIdentNode("int")
            ),
            newEmptyNode(),
            newEmptyNode(),
            nnkStmtList.newTree(
              nnkForStmt.newTree(
                newIdentNode("path"),
                nnkCall.newTree(
                  newIdentNode("walkGlobKinds")
                ),
                nnkStmtList.newTree(
                  nnkYieldStmt.newTree(
                    newIdentNode("path")
                  )
                )
              )
            )
          )
        )
      )
    )
  ),
  nnkCall.newTree(
    newIdentNode("main")
  )
)
1.6.0 👎 FAIL

Output

Error: Command failed: nim c --run  -d:nimDebugDlOpen -d:ssl -d:nimDisableCertificateValidation --forceBuild:on --colors:off --verbosity:0 --hints:off --warnings:off --lineTrace:off --nimcache:/home/runner/work/Nim/Nim --out:/home/runner/work/Nim/Nim/temp /home/runner/work/Nim/Nim/temp.nim
/home/runner/work/Nim/Nim/temp.nim(10, 25) Error: internal error: environment misses: dir

Stats

  • Started 2023-08-25T18:15:29
  • Finished 2023-08-25T18:15:29
  • Duration

IR

Compiled filesize 0 bytes (0 bytes)

AST

nnkStmtList.newTree(
  nnkTemplateDef.newTree(
    nnkPostfix.newTree(
      newIdentNode("*"),
      newIdentNode("mytoSeq")
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      newIdentNode("untyped"),
      nnkIdentDefs.newTree(
        newIdentNode("iter"),
        newIdentNode("untyped"),
        newEmptyNode()
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkVarSection.newTree(
        nnkIdentDefs.newTree(
          newIdentNode("result"),
          nnkBracketExpr.newTree(
            newIdentNode("seq"),
            nnkCall.newTree(
              newIdentNode("typeof"),
              newIdentNode("iter")
            )
          ),
          newEmptyNode()
        )
      ),
      nnkForStmt.newTree(
        newIdentNode("x"),
        newIdentNode("iter"),
        nnkStmtList.newTree(
          nnkCall.newTree(
            nnkDotExpr.newTree(
              newIdentNode("result"),
              newIdentNode("add")
            ),
            newIdentNode("x")
          )
        )
      ),
      newIdentNode("result")
    )
  ),
  nnkIteratorDef.newTree(
    newIdentNode("test"),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      newIdentNode("int"),
      nnkIdentDefs.newTree(
        newIdentNode("dir"),
        newIdentNode("int"),
        newEmptyNode()
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkYieldStmt.newTree(
        newLit(1234)
      )
    )
  ),
  nnkIteratorDef.newTree(
    newIdentNode("walkGlobKinds"),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      newIdentNode("int")
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkLetSection.newTree(
        nnkIdentDefs.newTree(
          newIdentNode("dir"),
          newEmptyNode(),
          newLit(123)
        )
      ),
      nnkLetSection.newTree(
        nnkIdentDefs.newTree(
          newIdentNode("it"),
          newEmptyNode(),
          nnkCall.newTree(
            newIdentNode("mytoSeq"),
            nnkCall.newTree(
              newIdentNode("test"),
              newIdentNode("dir")
            )
          )
        )
      )
    )
  ),
  nnkProcDef.newTree(
    newIdentNode("main"),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      newEmptyNode()
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkLetSection.newTree(
        nnkIdentDefs.newTree(
          newIdentNode("it"),
          newEmptyNode(),
          nnkIteratorDef.newTree(
            newEmptyNode(),
            newEmptyNode(),
            newEmptyNode(),
            nnkFormalParams.newTree(
              newIdentNode("int")
            ),
            newEmptyNode(),
            newEmptyNode(),
            nnkStmtList.newTree(
              nnkForStmt.newTree(
                newIdentNode("path"),
                nnkCall.newTree(
                  newIdentNode("walkGlobKinds")
                ),
                nnkStmtList.newTree(
                  nnkYieldStmt.newTree(
                    newIdentNode("path")
                  )
                )
              )
            )
          )
        )
      )
    )
  ),
  nnkCall.newTree(
    newIdentNode("main")
  )
)
1.4.0 👎 FAIL

Output

Error: Command failed: nim c --run  -d:nimDebugDlOpen -d:ssl -d:nimDisableCertificateValidation --forceBuild:on --colors:off --verbosity:0 --hints:off --warnings:off --lineTrace:off --nimcache:/home/runner/work/Nim/Nim --out:/home/runner/work/Nim/Nim/temp /home/runner/work/Nim/Nim/temp.nim
/home/runner/work/Nim/Nim/temp.nim(10, 25) Error: internal error: environment misses: dir

Stats

  • Started 2023-08-25T18:15:32
  • Finished 2023-08-25T18:15:33
  • Duration

IR

Compiled filesize 0 bytes (0 bytes)

AST

nnkStmtList.newTree(
  nnkTemplateDef.newTree(
    nnkPostfix.newTree(
      newIdentNode("*"),
      newIdentNode("mytoSeq")
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      newIdentNode("untyped"),
      nnkIdentDefs.newTree(
        newIdentNode("iter"),
        newIdentNode("untyped"),
        newEmptyNode()
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkVarSection.newTree(
        nnkIdentDefs.newTree(
          newIdentNode("result"),
          nnkBracketExpr.newTree(
            newIdentNode("seq"),
            nnkCall.newTree(
              newIdentNode("typeof"),
              newIdentNode("iter")
            )
          ),
          newEmptyNode()
        )
      ),
      nnkForStmt.newTree(
        newIdentNode("x"),
        newIdentNode("iter"),
        nnkStmtList.newTree(
          nnkCall.newTree(
            nnkDotExpr.newTree(
              newIdentNode("result"),
              newIdentNode("add")
            ),
            newIdentNode("x")
          )
        )
      ),
      newIdentNode("result")
    )
  ),
  nnkIteratorDef.newTree(
    newIdentNode("test"),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      newIdentNode("int"),
      nnkIdentDefs.newTree(
        newIdentNode("dir"),
        newIdentNode("int"),
        newEmptyNode()
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkYieldStmt.newTree(
        newLit(1234)
      )
    )
  ),
  nnkIteratorDef.newTree(
    newIdentNode("walkGlobKinds"),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      newIdentNode("int")
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkLetSection.newTree(
        nnkIdentDefs.newTree(
          newIdentNode("dir"),
          newEmptyNode(),
          newLit(123)
        )
      ),
      nnkLetSection.newTree(
        nnkIdentDefs.newTree(
          newIdentNode("it"),
          newEmptyNode(),
          nnkCall.newTree(
            newIdentNode("mytoSeq"),
            nnkCall.newTree(
              newIdentNode("test"),
              newIdentNode("dir")
            )
          )
        )
      )
    )
  ),
  nnkProcDef.newTree(
    newIdentNode("main"),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      newEmptyNode()
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkLetSection.newTree(
        nnkIdentDefs.newTree(
          newIdentNode("it"),
          newEmptyNode(),
          nnkIteratorDef.newTree(
            newEmptyNode(),
            newEmptyNode(),
            newEmptyNode(),
            nnkFormalParams.newTree(
              newIdentNode("int")
            ),
            newEmptyNode(),
            newEmptyNode(),
            nnkStmtList.newTree(
              nnkForStmt.newTree(
                newIdentNode("path"),
                nnkCall.newTree(
                  newIdentNode("walkGlobKinds")
                ),
                nnkStmtList.newTree(
                  nnkYieldStmt.newTree(
                    newIdentNode("path")
                  )
                )
              )
            )
          )
        )
      )
    )
  ),
  nnkCall.newTree(
    newIdentNode("main")
  )
)
1.2.0 👎 FAIL

Output

Error: Command failed: nim c --run  -d:nimDebugDlOpen -d:ssl -d:nimDisableCertificateValidation --forceBuild:on --colors:off --verbosity:0 --hints:off --warnings:off --lineTrace:off --nimcache:/home/runner/work/Nim/Nim --out:/home/runner/work/Nim/Nim/temp /home/runner/work/Nim/Nim/temp.nim
/home/runner/work/Nim/Nim/temp.nim(10, 25) Error: internal error: environment misses: dir

Stats

  • Started 2023-08-25T18:15:48
  • Finished 2023-08-25T18:15:48
  • Duration

IR

Compiled filesize 0 bytes (0 bytes)

AST

nnkStmtList.newTree(
  nnkTemplateDef.newTree(
    nnkPostfix.newTree(
      newIdentNode("*"),
      newIdentNode("mytoSeq")
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      newIdentNode("untyped"),
      nnkIdentDefs.newTree(
        newIdentNode("iter"),
        newIdentNode("untyped"),
        newEmptyNode()
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkVarSection.newTree(
        nnkIdentDefs.newTree(
          newIdentNode("result"),
          nnkBracketExpr.newTree(
            newIdentNode("seq"),
            nnkCall.newTree(
              newIdentNode("typeof"),
              newIdentNode("iter")
            )
          ),
          newEmptyNode()
        )
      ),
      nnkForStmt.newTree(
        newIdentNode("x"),
        newIdentNode("iter"),
        nnkStmtList.newTree(
          nnkCall.newTree(
            nnkDotExpr.newTree(
              newIdentNode("result"),
              newIdentNode("add")
            ),
            newIdentNode("x")
          )
        )
      ),
      newIdentNode("result")
    )
  ),
  nnkIteratorDef.newTree(
    newIdentNode("test"),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      newIdentNode("int"),
      nnkIdentDefs.newTree(
        newIdentNode("dir"),
        newIdentNode("int"),
        newEmptyNode()
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkYieldStmt.newTree(
        newLit(1234)
      )
    )
  ),
  nnkIteratorDef.newTree(
    newIdentNode("walkGlobKinds"),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      newIdentNode("int")
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkLetSection.newTree(
        nnkIdentDefs.newTree(
          newIdentNode("dir"),
          newEmptyNode(),
          newLit(123)
        )
      ),
      nnkLetSection.newTree(
        nnkIdentDefs.newTree(
          newIdentNode("it"),
          newEmptyNode(),
          nnkCall.newTree(
            newIdentNode("mytoSeq"),
            nnkCall.newTree(
              newIdentNode("test"),
              newIdentNode("dir")
            )
          )
        )
      )
    )
  ),
  nnkProcDef.newTree(
    newIdentNode("main"),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      newEmptyNode()
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkLetSection.newTree(
        nnkIdentDefs.newTree(
          newIdentNode("it"),
          newEmptyNode(),
          nnkIteratorDef.newTree(
            newEmptyNode(),
            newEmptyNode(),
            newEmptyNode(),
            nnkFormalParams.newTree(
              newIdentNode("int")
            ),
            newEmptyNode(),
            newEmptyNode(),
            nnkStmtList.newTree(
              nnkForStmt.newTree(
                newIdentNode("path"),
                nnkCall.newTree(
                  newIdentNode("walkGlobKinds")
                ),
                nnkStmtList.newTree(
                  nnkYieldStmt.newTree(
                    newIdentNode("path")
                  )
                )
              )
            )
          )
        )
      )
    )
  ),
  nnkCall.newTree(
    newIdentNode("main")
  )
)
1.0.0 👎 FAIL

Output

Error: Command failed: nim c --run  -d:nimDebugDlOpen -d:ssl -d:nimDisableCertificateValidation --forceBuild:on --colors:off --verbosity:0 --hints:off --warnings:off --lineTrace:off --nimcache:/home/runner/work/Nim/Nim --out:/home/runner/work/Nim/Nim/temp /home/runner/work/Nim/Nim/temp.nim
/home/runner/work/Nim/Nim/temp.nim(10, 25) Error: internal error: environment misses: dir

Stats

  • Started 2023-08-25T18:16:02
  • Finished 2023-08-25T18:16:02
  • Duration

IR

Compiled filesize 0 bytes (0 bytes)

AST

nnkStmtList.newTree(
  nnkTemplateDef.newTree(
    nnkPostfix.newTree(
      newIdentNode("*"),
      newIdentNode("mytoSeq")
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      newIdentNode("untyped"),
      nnkIdentDefs.newTree(
        newIdentNode("iter"),
        newIdentNode("untyped"),
        newEmptyNode()
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkVarSection.newTree(
        nnkIdentDefs.newTree(
          newIdentNode("result"),
          nnkBracketExpr.newTree(
            newIdentNode("seq"),
            nnkCall.newTree(
              newIdentNode("typeof"),
              newIdentNode("iter")
            )
          ),
          newEmptyNode()
        )
      ),
      nnkForStmt.newTree(
        newIdentNode("x"),
        newIdentNode("iter"),
        nnkStmtList.newTree(
          nnkCall.newTree(
            nnkDotExpr.newTree(
              newIdentNode("result"),
              newIdentNode("add")
            ),
            newIdentNode("x")
          )
        )
      ),
      newIdentNode("result")
    )
  ),
  nnkIteratorDef.newTree(
    newIdentNode("test"),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      newIdentNode("int"),
      nnkIdentDefs.newTree(
        newIdentNode("dir"),
        newIdentNode("int"),
        newEmptyNode()
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkYieldStmt.newTree(
        newLit(1234)
      )
    )
  ),
  nnkIteratorDef.newTree(
    newIdentNode("walkGlobKinds"),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      newIdentNode("int")
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkLetSection.newTree(
        nnkIdentDefs.newTree(
          newIdentNode("dir"),
          newEmptyNode(),
          newLit(123)
        )
      ),
      nnkLetSection.newTree(
        nnkIdentDefs.newTree(
          newIdentNode("it"),
          newEmptyNode(),
          nnkCall.newTree(
            newIdentNode("mytoSeq"),
            nnkCall.newTree(
              newIdentNode("test"),
              newIdentNode("dir")
            )
          )
        )
      )
    )
  ),
  nnkProcDef.newTree(
    newIdentNode("main"),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      newEmptyNode()
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkLetSection.newTree(
        nnkIdentDefs.newTree(
          newIdentNode("it"),
          newEmptyNode(),
          nnkIteratorDef.newTree(
            newEmptyNode(),
            newEmptyNode(),
            newEmptyNode(),
            nnkFormalParams.newTree(
              newIdentNode("int")
            ),
            newEmptyNode(),
            newEmptyNode(),
            nnkStmtList.newTree(
              nnkForStmt.newTree(
                newIdentNode("path"),
                nnkCall.newTree(
                  newIdentNode("walkGlobKinds")
                ),
                nnkStmtList.newTree(
                  nnkYieldStmt.newTree(
                    newIdentNode("path")
                  )
                )
              )
            )
          )
        )
      )
    )
  ),
  nnkCall.newTree(
    newIdentNode("main")
  )
)
0.20.2 👎 FAIL

Output

Error: Command failed: nim c --run  -d:nimDebugDlOpen -d:ssl -d:nimDisableCertificateValidation --forceBuild:on --colors:off --verbosity:0 --hints:off --warnings:off --lineTrace:off --nimcache:/home/runner/work/Nim/Nim --out:/home/runner/work/Nim/Nim/temp /home/runner/work/Nim/Nim/temp.nim
/home/runner/work/Nim/Nim/temp.nim(10, 25) Error: internal error: environment misses: dir

Stats

  • Started 2023-08-25T18:16:12
  • Finished 2023-08-25T18:16:13
  • Duration

IR

Compiled filesize 0 bytes (0 bytes)

AST

nnkStmtList.newTree(
  nnkTemplateDef.newTree(
    nnkPostfix.newTree(
      newIdentNode("*"),
      newIdentNode("mytoSeq")
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      newIdentNode("untyped"),
      nnkIdentDefs.newTree(
        newIdentNode("iter"),
        newIdentNode("untyped"),
        newEmptyNode()
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkVarSection.newTree(
        nnkIdentDefs.newTree(
          newIdentNode("result"),
          nnkBracketExpr.newTree(
            newIdentNode("seq"),
            nnkCall.newTree(
              newIdentNode("typeof"),
              newIdentNode("iter")
            )
          ),
          newEmptyNode()
        )
      ),
      nnkForStmt.newTree(
        newIdentNode("x"),
        newIdentNode("iter"),
        nnkStmtList.newTree(
          nnkCall.newTree(
            nnkDotExpr.newTree(
              newIdentNode("result"),
              newIdentNode("add")
            ),
            newIdentNode("x")
          )
        )
      ),
      newIdentNode("result")
    )
  ),
  nnkIteratorDef.newTree(
    newIdentNode("test"),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      newIdentNode("int"),
      nnkIdentDefs.newTree(
        newIdentNode("dir"),
        newIdentNode("int"),
        newEmptyNode()
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkYieldStmt.newTree(
        newLit(1234)
      )
    )
  ),
  nnkIteratorDef.newTree(
    newIdentNode("walkGlobKinds"),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      newIdentNode("int")
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkLetSection.newTree(
        nnkIdentDefs.newTree(
          newIdentNode("dir"),
          newEmptyNode(),
          newLit(123)
        )
      ),
      nnkLetSection.newTree(
        nnkIdentDefs.newTree(
          newIdentNode("it"),
          newEmptyNode(),
          nnkCall.newTree(
            newIdentNode("mytoSeq"),
            nnkCall.newTree(
              newIdentNode("test"),
              newIdentNode("dir")
            )
          )
        )
      )
    )
  ),
  nnkProcDef.newTree(
    newIdentNode("main"),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      newEmptyNode()
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkLetSection.newTree(
        nnkIdentDefs.newTree(
          newIdentNode("it"),
          newEmptyNode(),
          nnkIteratorDef.newTree(
            newEmptyNode(),
            newEmptyNode(),
            newEmptyNode(),
            nnkFormalParams.newTree(
              newIdentNode("int")
            ),
            newEmptyNode(),
            newEmptyNode(),
            nnkStmtList.newTree(
              nnkForStmt.newTree(
                newIdentNode("path"),
                nnkCall.newTree(
                  newIdentNode("walkGlobKinds")
                ),
                nnkStmtList.newTree(
                  nnkYieldStmt.newTree(
                    newIdentNode("path")
                  )
                )
              )
            )
          )
        )
      )
    )
  ),
  nnkCall.newTree(
    newIdentNode("main")
  )
)
Stats
  • GCC 11.4.0
  • LibC 2.35
  • Valgrind 3.18.1
  • NodeJS 17.1
  • Linux 5.15.0
  • Created 2023-08-25T18:14:32Z
  • Comments 3
  • Commands nim c --run -d:nimDebugDlOpen -d:ssl -d:nimDisableCertificateValidation --forceBuild:on --colors:off --verbosity:0 --hints:off --warnings:off --lineTrace:off --nimcache:/home/runner/work/Nim/Nim --out:/home/runner/work/Nim/Nim/temp /home/runner/work/Nim/Nim/temp.nim

🤖 Bug found in 53 minutes bisecting 8 commits at 0 commits per second.

compiler/lambdalifting.nim Outdated Show resolved Hide resolved
@bung87 bung87 requested a review from Araq August 27, 2023 03:59
@@ -417,6 +418,9 @@ Consider:

"""

proc isTypeOf(ident: PIdent; cache: IdentCache): bool =
ident == getIdent(cache, "typeof") or ident == getIdent(cache, "type")

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does the frontend not transform these into nkType nodes? It should and would make this far easier.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was expecting these are just nkTypeOfExpr

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, even better. :-)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's the node processing path goes to here?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

semMagicAfterOverloadResolution should turn the magic mType and mTypeOf to nkTypeOfExpr

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tried , didn't found chance transform the node , now only detect via magic, seems sufficient

@Araq Araq merged commit 0b78b7f into nim-lang:devel Aug 27, 2023
16 checks passed
@github-actions
Copy link
Contributor

Thanks for your hard work on this PR!
The lines below are statistics of the Nim compiler built from 0b78b7f

Hint: mm: orc; opt: speed; options: -d:release
169349 lines; 11.250s; 610.578MiB peakmem

@yglukhov
Copy link
Member

yglukhov commented Sep 1, 2023

@bung87 this pr has broken my hacky unofficial yasync experiments, because after this pr the fields in the env objects are in different order from their declaration in the iter, and that's the behavior I relied on. Is this new behavior intentional? Can it be circumvented somehow?

@bung87
Copy link
Collaborator Author

bung87 commented Sep 1, 2023

make detectCapturedVars also processing on the symbol

of nkIdentDefs:
    detectCapturedVars(n[0], owner, c)
    detectCapturedVars(n[^1], owner, c)

@yglukhov
Copy link
Member

yglukhov commented Sep 1, 2023

@bung87 sorry I didn't understand. Does it mean you'll be looking into this? :)

@bung87
Copy link
Collaborator Author

bung87 commented Sep 1, 2023

I've tested locally, compiler/lambdalifting.nim line start from 526, change to the solution above. but I will not make PR

@bung87 bung87 deleted the fix-22548 branch September 1, 2023 13:02
@yglukhov
Copy link
Member

yglukhov commented Sep 1, 2023

Indeed, it seems to work, thanks. I'll make a PR now.

yglukhov added a commit to yglukhov/Nim that referenced this pull request Sep 1, 2023
narimiran pushed a commit that referenced this pull request Sep 11, 2023
#22559)

* fix #22548;environment misses for type reference in iterator access nested in closure

* fix #21737

* Update lambdalifting.nim

* remove containsCallKinds

* simplify

(cherry picked from commit 0b78b7f)
narimiran pushed a commit that referenced this pull request Apr 17, 2024
#22559)

* fix #22548;environment misses for type reference in iterator access nested in closure

* fix #21737

* Update lambdalifting.nim

* remove containsCallKinds

* simplify

(cherry picked from commit 0b78b7f)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants