i assume your `type B` is actually 
`array[64,array[64,array[64,array[64,int32]]]]` as 64*64*6*64 actually compiles 
and runs just fine (on linux anyway, with 8MB stack)

FIrst some bad answers:

to increase the stack you can try `{.passL: "-z stack-size=67109864".}` where 
the number is sizeof(B)+1000

i found that initializing a 64x64x64x64 array at compile time required 
`--maxLoopIterationsVM:20000000` or so

or if you want to override the compiler's side-effect analysis and use a ptr or 
ref you could 
    
    
    let defaultBRef = block:
      var r = new B
      r[] = defaultB
      r
    #or let defaultBPtr = defaultB.unsafeAddr
    func hi(i:int32):int32 =
      {.cast(noSideEffect).}:
        defaultBRef[i][i][i div 10][i] * i
    
    
    Run

putting your object on the heap isn't a bad idea, but why not pass it into `hi` 
as a parameter. it is still created at compile time but doesn't need to be 
copied into heap to be used, and it won't break the stack as it will certainly 
be passed as a hidden pointer: 
    
    
    import random#just making sure it's not optimized away
    type B = array[64,array[64,array[64,array[64,int32]]]]
    const defaultB:B = block:
      var r:B
        for i in 0'i32..63:
          for j in 0'i32..63:
            for k in 0'i32..63:
              for l in 0'i32..63:
               r[i][j][k][l] = i + j + k + l
      r
    func hiAux(b:B,i:int32):int32 =
      b[i][i][i][i] * i
    func hi(i:int32):int32 = defaultB.hiAux(i)
    echo hi(rand(63).int32)
    
    
    Run

Reply via email to