nimly icon indicating copy to clipboard operation
nimly copied to clipboard

nimly Uses Too Many Loops In Compile-time

Open loloicci opened this issue 5 years ago • 14 comments

loloicci avatar Mar 21 '19 15:03 loloicci

You can avoid this error to use the new compiler option maxLoopIterationsVM:N (maybe later than Nim v1.0.6) (See also https://nim-lang.org/docs/nimc.html).

Before v1.0.6, you can use niml with compiler build with vmdef patched as follows

diff --git a/compiler/vmdef.nim b/compiler/vmdef.nim
index 7a2bc1607..91706ae5d 100644
--- a/compiler/vmdef.nim
+++ b/compiler/vmdef.nim
@@ -17,7 +17,7 @@ const
   byteExcess* = 128 # we use excess-K for immediates
   wordExcess* = 32768
 
-  MaxLoopIterations* = 3_000_000 # max iterations of all loops
+  MaxLoopIterations* = high(int) #3_000_000 # max iterations of all loops

loloicci avatar Mar 21 '19 17:03 loloicci

improve some #25

loloicci avatar Apr 11 '19 16:04 loloicci

It maybe solved when nim becomes version 1.0.0.

loloicci avatar Oct 24 '19 05:10 loloicci

Hi, I'm encountering this issue using nim 1.0.6.

samdmarshall avatar Mar 19 '20 16:03 samdmarshall

@samdmarshall thanks for your reporting. Could you share the code with the bug if you can?

loloicci avatar Mar 20 '20 14:03 loloicci

oh, sorry, yeah - of course. i'll try to isolate into a stand-alone sample. do you want me posting here in this issue or as a new one?

samdmarshall avatar Mar 20 '20 14:03 samdmarshall

Thanks! Either is fine. Link to #11 if you post as a new issue.

loloicci avatar Mar 20 '20 14:03 loloicci

https://github.com/bung87/rust2nim I face this when compile entry file.

it's the first time I try to use a parser generator, I may doing something wrong, but this stop me get ing further information.

bung87 avatar Jun 02 '20 22:06 bung87

lexgen.nim line:378

if toSeq(sTran.keys) == toSeq(tran.keys): I modify to this , reduce the iterations, it seems under the compare calls the argument changes dynamically. there's proc defaultAndOther called by lexgen.nim(567, 33) convertToLexData throw too many iterations error .

bung87 avatar Jun 03 '20 10:06 bung87

@bung87 Thank you for your analysis!

if toSeq(sTran.keys) == toSeq(tran.keys): I modify to this , reduce the iterations, it seems under the compare calls the argument changes dynamically.

If you will create a new PR, I will merge this change after checking this has no unexpected effects.

You can avoid this error to use the new compiler option maxLoopIterationsVM:N (maybe later than Nim v1.0.6) (See also https://nim-lang.org/docs/nimc.html).

loloicci avatar Jun 04 '20 11:06 loloicci

I will create a PR later, merge if you think that's correct since I has no much knowledge in this domain. write a wrong grammar also will cause this?

I checked after modified test will not pass.

bung87 avatar Jun 04 '20 11:06 bung87

Sorry, @bung87. Your suggestion does not work expectedly.

toSeq(sTran.keys) == toSeq(tran.keys)

This returns always true and causes error in nimble test. (nim c -r tests/test_lexgen.nim provides more information)

I did some refactoring in lexgen.nim in the #40. Check this if you are interested in what this part does.

loloicci avatar Jun 04 '20 12:06 loloicci

@bung87

write a wrong grammar also will cause this?

No (as far as I know). This error is caused when the calculation needed to generate the lexer is too much. Without bug in the implementation, this generation does not cause infinite loops.

loloicci avatar Jun 04 '20 12:06 loloicci

Thanks for your explaintion! then I feel fine with maxLoopIterationsVM, from what I understand the lexer parser generate during compile time, that probably exceed the limit even code is fine, that sounds reasonable.

I just aware you removed the bug label, guess I can just try :P

bung87 avatar Jun 04 '20 13:06 bung87