I raised this issue regarding 0.17.2 but it still persists in 0.18.0. I want to generate some system constants at compile time.
I need to generate some constant arrays of numbers for a (selectable) prime generator (PG). When the array size gets past some (?) value the compiler quits with this message: generating parameters for P13 stack trace: (most recent call last) twinprimes_ssozp13par5d.nim(81) lib/system.nim(3806) genPGparameters lib/system.nim(3806, 14) Error: interpretation requires too many iterations This SERIOUSLY impedes my development process in Nim, which doesn't exist in C++. I provide code for the case that will compile, then the version that the compiler squawks at. The array `residues` for P13 (prime generator for prime of 13) contains 5760 values. The array `restwins` contains 2970 values. When I attempt to compile array `inverses`, containing another 5760 values, the compiler squawks. I ended up using Ruby to generate the `inverses` array values, then displayed to terminal, copied, pasted into an editor, line formatted, copied, then pasted the formatted array values into my Nim source code so I could compile and run the program. I need to do the next higher prime generator P17, whose array `residues|resinvrs` each contain 92,160 values, but the compiler ends when trying to create just the `residues` array. So somewhere between (5760 + 2970) = 8730 - 92,160 iterations, the compiler stops working. Besides this being an arbitrary decision to have the compiler act like this, it's undocumented, and there is apparently no (known) mechanism to extend this arbitrary limit to a user. Is there some compiler flag to eliminate|extend it? To say the least `This makes me Very Unhappy!! :-(`. My development has stalled because of this. And it is totally not feasible for me to generate two 92,160 element arrays in Ruby (which it has no problem doing) and go through the print|format|copy|paste dance of two 1000+ lines of numbers, again. And that's just for P17. P19 has 1,658,880 values for each array, `It would make me very, very Happy :-)` to eliminate this barrier to my continued project development. # This code will compile import math # for sqrt function import strutils, typetraits # for number input import times, os # for timing code execution import osproc # for getting threads count import threadpool # for parallel processing {.experimental.} # required to use 'parallel' (0.17.x) proc genPGparameters(prime: int): (int, int, int, seq[int], seq[int]) = echo("generating parameters for P", prime) let primes = [2, 3, 5, 7, 11, 13, 17, 19, 23] var modpg = 1 for prm in primes: (modpg *= prm; if prm == prime: break) var pc = 1 var residues: seq[int] = @[] while pc < modpg: (pc += 2; if gcd(modpg, pc) == 1: residues.add(pc)) let rescnt = residues.len var restwins: seq[int] = @[] var j = 0 while j < rescnt-1: if residues[j]+2 == residues[j+1]: restwins.add residues[j]; restwins.add residues[j+1]; j.inc j.inc let rescntp = restwins.len result = (modpg, rescnt, rescntp, residues, restwins) # Generate at compile time the parameters for P13 const parameters = genPGparameters(13) # This won't compile with the addition of creating the 'inverses' array import math # for sqrt function import strutils, typetraits # for number input import times, os # for timing code execution import osproc # for getting threads count import threadpool # for parallel processing {.experimental.} # required to use 'parallel' (0.17.x) proc genPGparameters(prime: int): (int, int, int, seq[int], seq[int], seq[int]) = echo("generating parameters for P", prime) let primes = [2, 3, 5, 7, 11, 13, 17, 19, 23] var modpg = 1 for prm in primes: (modpg *= prm; if prm == prime: break) var pc = 1 var residues: seq[int] = @[] while pc < modpg: (pc += 2; if gcd(modpg, pc) == 1: residues.add(pc)) let rescnt = residues.len var restwins: seq[int] = @[] var j = 0 while j < rescnt-1: if residues[j]+2 == residues[j+1]: restwins.add residues[j]; restwins.add residues[j+1]; j.inc j.inc let rescntp = restwins.len var inverses: seq[int] = @[] j = 0 while j < rescnt: let res = residues[j] for inv in residues: if res*inv mod modpg == 1: (inverses.add(inv); break) j.inc result = (modpg, rescnt, rescntp, residues, restwins, inverses) # Generate at compile time the parameters for P13 const parameters = genPGparameters(13)