GithubHelp home page GithubHelp logo

Comments (14)

juancarlospaco avatar juancarlospaco commented on June 16, 2024 1

!nim c

iterator it(): bool = discard
for (_) in it(): discard

from nim.

metagn avatar metagn commented on June 16, 2024 1

As I've mentioned in the issue, it doesn't matter if the returned type is a tuple or not

My bad, didn't see.

There is a separate bug simplified from that example on 2.0 independent from tuple unpacking (probably same as #21476, same error, same workaround):

proc main =
  let x = false
  iterator it(): bool =
    discard x

  for a in it():
    discard
main()

which is obtained by removing the parentheses from that example, so the problem does still seem to be with the parentheses.

from nim.

github-actions avatar github-actions commented on June 16, 2024
🐧 Linux bisect by @juancarlospaco (collaborator)
devel 👎 FAIL

Output

Error: Command failed: nim c --run  -d:nimDebug -d:nimDebugDlOpen -d:ssl -d:nimDisableCertificateValidation --forceBuild:on --colors:off --verbosity:0 --hints:off --lineTrace:off --nimcache:/home/runner/work/Nim/Nim --out:/home/runner/work/Nim/Nim/temp /home/runner/work/Nim/Nim/temp.nim
SIGSEGV: Illegal storage access. (Attempt to read from nil?)

IR

Compiled filesize 0 bytes (0 bytes)

Stats

  • Started 2024-01-07T23:04:15
  • Finished 2024-01-07T23:04:15
  • Duration

AST

nnkStmtList.newTree(
  nnkIteratorDef.newTree(
    newIdentNode("it"),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      newIdentNode("bool")
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkDiscardStmt.newTree(
        newEmptyNode()
      )
    )
  ),
  nnkForStmt.newTree(
    nnkVarTuple.newTree(
      newIdentNode("_"),
      newEmptyNode()
    ),
    nnkCall.newTree(
      newIdentNode("it")
    ),
    nnkStmtList.newTree(
      nnkDiscardStmt.newTree(
        newEmptyNode()
      )
    )
  )
)
stable 👎 FAIL

Output

Error: Command failed: nim c --run  -d:nimDebug -d:nimDebugDlOpen -d:ssl -d:nimDisableCertificateValidation --forceBuild:on --colors:off --verbosity:0 --hints:off --lineTrace:off --nimcache:/home/runner/work/Nim/Nim --out:/home/runner/work/Nim/Nim/temp /home/runner/work/Nim/Nim/temp.nim
SIGSEGV: Illegal storage access. (Attempt to read from nil?)

IR

Compiled filesize 0 bytes (0 bytes)

Stats

  • Started 2024-01-07T23:04:16
  • Finished 2024-01-07T23:04:17
  • Duration

AST

nnkStmtList.newTree(
  nnkIteratorDef.newTree(
    newIdentNode("it"),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      newIdentNode("bool")
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkDiscardStmt.newTree(
        newEmptyNode()
      )
    )
  ),
  nnkForStmt.newTree(
    nnkVarTuple.newTree(
      newIdentNode("_"),
      newEmptyNode()
    ),
    nnkCall.newTree(
      newIdentNode("it")
    ),
    nnkStmtList.newTree(
      nnkDiscardStmt.newTree(
        newEmptyNode()
      )
    )
  )
)
2.0.0 👎 FAIL

Output

Error: Command failed: nim c --run  -d:nimDebug -d:nimDebugDlOpen -d:ssl -d:nimDisableCertificateValidation --forceBuild:on --colors:off --verbosity:0 --hints:off --lineTrace:off --nimcache:/home/runner/work/Nim/Nim --out:/home/runner/work/Nim/Nim/temp /home/runner/work/Nim/Nim/temp.nim
SIGSEGV: Illegal storage access. (Attempt to read from nil?)

IR

Compiled filesize 0 bytes (0 bytes)

Stats

  • Started 2024-01-07T23:04:20
  • Finished 2024-01-07T23:04:20
  • Duration

AST

nnkStmtList.newTree(
  nnkIteratorDef.newTree(
    newIdentNode("it"),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      newIdentNode("bool")
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkDiscardStmt.newTree(
        newEmptyNode()
      )
    )
  ),
  nnkForStmt.newTree(
    nnkVarTuple.newTree(
      newIdentNode("_"),
      newEmptyNode()
    ),
    nnkCall.newTree(
      newIdentNode("it")
    ),
    nnkStmtList.newTree(
      nnkDiscardStmt.newTree(
        newEmptyNode()
      )
    )
  )
)
1.6.14 👎 FAIL

Output

Error: Command failed: nim c --run  -d:nimDebug -d:nimDebugDlOpen -d:ssl -d:nimDisableCertificateValidation --forceBuild:on --colors:off --verbosity:0 --hints:off --lineTrace:off --nimcache:/home/runner/work/Nim/Nim --out:/home/runner/work/Nim/Nim/temp /home/runner/work/Nim/Nim/temp.nim
SIGSEGV: Illegal storage access. (Attempt to read from nil?)

IR

Compiled filesize 0 bytes (0 bytes)

Stats

  • Started 2024-01-07T23:04:23
  • Finished 2024-01-07T23:04:23
  • Duration

AST

nnkStmtList.newTree(
  nnkIteratorDef.newTree(
    newIdentNode("it"),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      newIdentNode("bool")
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkDiscardStmt.newTree(
        newEmptyNode()
      )
    )
  ),
  nnkForStmt.newTree(
    nnkVarTuple.newTree(
      newIdentNode("_"),
      newEmptyNode()
    ),
    nnkCall.newTree(
      newIdentNode("it")
    ),
    nnkStmtList.newTree(
      nnkDiscardStmt.newTree(
        newEmptyNode()
      )
    )
  )
)
1.4.8 👎 FAIL

Output

Error: Command failed: nim c --run  -d:nimDebug -d:nimDebugDlOpen -d:ssl -d:nimDisableCertificateValidation --forceBuild:on --colors:off --verbosity:0 --hints:off --lineTrace:off --nimcache:/home/runner/work/Nim/Nim --out:/home/runner/work/Nim/Nim/temp /home/runner/work/Nim/Nim/temp.nim
SIGSEGV: Illegal storage access. (Attempt to read from nil?)

IR

Compiled filesize 0 bytes (0 bytes)

Stats

  • Started 2024-01-07T23:04:25
  • Finished 2024-01-07T23:04:25
  • Duration

AST

nnkStmtList.newTree(
  nnkIteratorDef.newTree(
    newIdentNode("it"),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      newIdentNode("bool")
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkDiscardStmt.newTree(
        newEmptyNode()
      )
    )
  ),
  nnkForStmt.newTree(
    nnkVarTuple.newTree(
      newIdentNode("_"),
      newEmptyNode()
    ),
    nnkCall.newTree(
      newIdentNode("it")
    ),
    nnkStmtList.newTree(
      nnkDiscardStmt.newTree(
        newEmptyNode()
      )
    )
  )
)
1.2.18 👎 FAIL

Output

Error: Command failed: nim c --run  -d:nimDebug -d:nimDebugDlOpen -d:ssl -d:nimDisableCertificateValidation --forceBuild:on --colors:off --verbosity:0 --hints:off --lineTrace:off --nimcache:/home/runner/work/Nim/Nim --out:/home/runner/work/Nim/Nim/temp /home/runner/work/Nim/Nim/temp.nim
SIGSEGV: Illegal storage access. (Attempt to read from nil?)

IR

Compiled filesize 0 bytes (0 bytes)

Stats

  • Started 2024-01-07T23:04:27
  • Finished 2024-01-07T23:04:27
  • Duration

AST

nnkStmtList.newTree(
  nnkIteratorDef.newTree(
    newIdentNode("it"),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      newIdentNode("bool")
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkDiscardStmt.newTree(
        newEmptyNode()
      )
    )
  ),
  nnkForStmt.newTree(
    nnkVarTuple.newTree(
      newIdentNode("_"),
      newEmptyNode()
    ),
    nnkCall.newTree(
      newIdentNode("it")
    ),
    nnkStmtList.newTree(
      nnkDiscardStmt.newTree(
        newEmptyNode()
      )
    )
  )
)
1.0.10 👎 FAIL

Output

Error: Command failed: nim c --run  -d:nimDebug -d:nimDebugDlOpen -d:ssl -d:nimDisableCertificateValidation --forceBuild:on --colors:off --verbosity:0 --hints:off --lineTrace:off --nimcache:/home/runner/work/Nim/Nim --out:/home/runner/work/Nim/Nim/temp /home/runner/work/Nim/Nim/temp.nim
SIGSEGV: Illegal storage access. (Attempt to read from nil?)

IR

Compiled filesize 0 bytes (0 bytes)

Stats

  • Started 2024-01-07T23:04:30
  • Finished 2024-01-07T23:04:30
  • Duration

AST

nnkStmtList.newTree(
  nnkIteratorDef.newTree(
    newIdentNode("it"),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      newIdentNode("bool")
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkDiscardStmt.newTree(
        newEmptyNode()
      )
    )
  ),
  nnkForStmt.newTree(
    nnkVarTuple.newTree(
      newIdentNode("_"),
      newEmptyNode()
    ),
    nnkCall.newTree(
      newIdentNode("it")
    ),
    nnkStmtList.newTree(
      nnkDiscardStmt.newTree(
        newEmptyNode()
      )
    )
  )
)
Stats
  • GCC 11.4.0
  • Clang 14.0.0
  • NodeJS 19.0
  • Created 2024-01-07T23:03:48Z
  • Comments 1
  • Commands nim c --run -d:nimDebug -d:nimDebugDlOpen -d:ssl -d:nimDisableCertificateValidation --forceBuild:on --colors:off --verbosity:0 --hints: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 18 minutes bisecting 7 commits at 0 commits per second

from nim.

metagn avatar metagn commented on June 16, 2024

Putting parentheses makes it unpack tuples in for loops (old but broken and undocumented behavior, there are other issues open because of this: #19805, #15924). Since bool is not a tuple type, the compiler crashes (I surmise). So we need to check that the type is a tuple. (As written below, this is not the cause, but the issue does still seem to be with the parentheses) The for loop tuple unpacking code probably needs cleaning up, it wasn't touched during the recent tuple unpacking refactors

from nim.

ZoomRmc avatar ZoomRmc commented on June 16, 2024

Putting parentheses makes it unpack tuples in for loops (old but broken and undocumented behavior, there are other issues open because of this: #19805, #15924). Since bool is not a tuple type, the compiler crashes (I surmise). So we need to check that the type is a tuple. The for loop tuple unpacking code probably needs cleaning up, it wasn't touched during the recent tuple unpacking refactors

As I've mentioned in the issue, it doesn't matter if the returned type is a tuple or not, it still crashes. I just minimized the code as much as I possibly could.

proc main() =
  let x = false
  iterator it(): (bool, bool) =
    if x: discard
    discard

  for (_, _) in it():
    discard

main()

On the second thought, to crash with the actual tuple we need to access a captured local variable. So it's might be a separate bug :)

from nim.

ringabout avatar ringabout commented on June 16, 2024

I think the first example is invalid code, just as

let (a) = false

gives

Error: tuple expected for tuple unpacking, but got 'int'

from nim.

metagn avatar metagn commented on June 16, 2024

There is still a bug like #21476 for parentheses but doesn't work with the workaround for #21476. Maybe it is still the same issue though.

proc main() =
  let x = false
  iterator it(): (bool, bool) {.closure.} = # normally {.closure.} here makes #21476 work
    discard x

  for (_, _) in it():
    discard

main()

Output is segfault.

from nim.

ringabout avatar ringabout commented on June 16, 2024

Putting parentheses makes it unpack tuples in for loops (old but broken and undocumented behavior, there are other issues open because of this:

It's quite weird that the tuple unpacking works for nested arrays in the for loop. I didn't know this feature/bug before. It is quite inconsistent with var tuples unpacking.

from nim.

metagn avatar metagn commented on June 16, 2024

I think the purpose is to prevent an implicit pairs iterator while allowing items but we need to make sure this is the only difference and document it

from nim.

ringabout avatar ringabout commented on June 16, 2024

I checked #19805. It seems to me that it happened to compile because there is no restriction on the tuple types for tuple unpacking. Though I will wait for #23185 to see whether it breaks something.

errWrongNumberOfVariables is cute though since it doesn't work for array types (iterAfterVarLent.len is always 2), it's reasonable to suppose there would have been a check for tuple types.

if n[0].len-1 != iterAfterVarLent.len:
  return localErrorNode(c, n, n[0].info, errWrongNumberOfVariables)

I think it's most likely unintentional. The cases in the #19805 failed twice to get itself compiled.

from nim.

ringabout avatar ringabout commented on June 16, 2024

I think the example two is the same case as #15924 because there is no var tuple unpacking for closures

from nim.

ringabout avatar ringabout commented on June 16, 2024

There is still a bug like #21476 for parentheses but doesn't work with the workaround for #21476. Maybe it is still the same issue though.

proc main() =
  let x = false
  iterator it(): (bool, bool) {.closure.} = # normally {.closure.} here makes #21476 work
    discard x

  for (_, _) in it():
    discard

main()

Output is segfault.

fixed by #23205

from nim.

ZoomRmc avatar ZoomRmc commented on June 16, 2024

fixed by #23205

proc main() =
  let x = false
  iterator it(): (bool, bool) =
    if x: discard
    discard
  for (_, _) in it(): discard

main()

> Error: internal error: proc has no result symbol

from nim.

metagn avatar metagn commented on June 16, 2024

That should be the same issue as #21476, as long as it doesn't matter if we use (_, _) or just _. Still worth mentioning in #21476 if it is the same issue though since the original example in #21476 is a bit misleading.

from nim.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.