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

Nim check hangs in macro #9829

Closed
liwt31 opened this issue Nov 30, 2018 · 2 comments · Fixed by #11849
Closed

Nim check hangs in macro #9829

liwt31 opened this issue Nov 30, 2018 · 2 comments · Fixed by #11849

Comments

@liwt31
Copy link

liwt31 commented Nov 30, 2018

Nim check hangs in macro. Don't know what exactly caused this.

Example

Content of bug.nim:

macro foo(): untyped  = 
  let lines = ["123", "5423"]
  var idx = 0
  while idx < lines.len():
    if lines[idx].len() < 1: 
      inc(idx)
      continue
 
foo()

Current Output

$ nim check bug.nim 
Hint: used config file '/home/wtli/.choosenim/toolchains/nim-0.19.0/config/nim.cfg' [Conf]
Hint: system [Processing]
Hint: bug [Processing]
^CSIGINT: Interrupted by Ctrl-C.
Traceback (most recent call last)
proxyexe.nim(62)         proxyexe
proxyexe.nim(49)         main
osproc.nim(1136)         waitForExit
SIGINT: Interrupted by Ctrl-C.

The program hangs in Hint: bug [Processing] until a SIGINT.

Expected Output

I know there's a infinite loop, but I've seen:

Error: interpretation requires too many iterations; if you are sure this is not a bug in your code edit compiler/vmdef.MaxLoopIterations and rebuild the compiler

before in a simpler case. That's a lot nicer (and very cool!).

Possible Solution

Donno.

Additional Information

Nim Compiler Version 0.19.0 [Linux: amd64]
Compiled at 2018-09-26
Copyright (c) 2006-2018 by Andreas Rumpf

git hash: f6c5c636bb1a1f4e1301ae0ba5a8afecef439132
active boot switches: -d:release
Linux localhost.localdomain 3.10.0-862.el7.x86_64 #1 SMP Fri Apr 20 16:44:24 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux

Thank you in advance.

@nc-x
Copy link
Contributor

nc-x commented Dec 14, 2018

@Araq Why the crash label, this is not a crash.

@liwt31

Don't know what exactly caused this.

macro foo(): untyped  = 
  let lines = ["123", "5423"]
  var idx = 0
  while idx < lines.len():                   -----
    if lines[idx].len() < 1:                      | Infinite loop because inc(idx) is never called
      inc(idx)                                    | 
      continue                               -----
 
foo()

A macro is evaluated at compile time. And you created an infinite loop (which runs at compile time). So the compilation nevers completes.

Also the issue is not specific to nim check. nim c also gets stuck at infinite loop.

@Araq
Copy link
Member

Araq commented Dec 14, 2018

The VM doesn't have infinite loops, an infinite loop is a crash.

@krux02 krux02 removed their assignment Jan 10, 2019
krux02 added a commit to krux02/Nim that referenced this issue Jul 29, 2019
@krux02 krux02 mentioned this issue Jul 29, 2019
krux02 added a commit to krux02/Nim that referenced this issue Jul 30, 2019
Araq pushed a commit that referenced this issue Aug 4, 2019
narimiran pushed a commit that referenced this issue Aug 12, 2019
(cherry picked from commit b73d097)
narimiran pushed a commit that referenced this issue Aug 13, 2019
(cherry picked from commit b73d097)
narimiran pushed a commit that referenced this issue Aug 13, 2019
(cherry picked from commit b73d097)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants