File: tsimple_array_checks.nim

package info (click to toggle)
nim 2.2.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 1,911,644 kB
  • sloc: sh: 24,603; ansic: 1,761; python: 1,492; makefile: 1,013; sql: 298; asm: 141; xml: 13
file content (75 lines) | stat: -rw-r--r-- 1,257 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
discard """
sortoutput: true
output: '''
0
1
2
3
4
5
6
7
8
9
Hello 1
Hello 2
Hello 3
Hello 4
Hello 5
Hello 6
'''
"""

# bug #2287

import threadPool

# If `nums` is an array instead of seq,
# NONE of the iteration ways below work (including high / len-1)
let nums = @[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

proc log(n:int) =
  echo n

proc main =
  parallel:
    for n in nums: # Error: cannot prove: i <= len(nums) + -1
      spawn log(n)
    #for i in 0 ..< nums.len: # Error: cannot prove: i <= len(nums) + -1
    #for i in 0 .. nums.len-1: # WORKS!
    #for i in 0 ..< nums.len: # WORKS!
    #  spawn log(nums[i])

# Array needs explicit size to work, probably related to issue #2287
#const a: array[0..5, int] = [1,2,3,4,5,6]

#const a = [1,2,3,4,5,6] # Doesn't work
const a = @[1,2,3,4,5,6] # Doesn't work
proc f(n: int) = echo "Hello ", n

proc maino =
  parallel:
    # while loop doesn't work:
    var i = 0
    while i < a.high:
      #for i in countup(0, a.high-1, 2):
      spawn f(a[i])
      spawn f(a[i+1])
      i += 2

maino() # Doesn't work outside a proc

when true:
  main()

block two:
  proc f(a: openArray[int]) =
    discard

  proc main() =
    var a: array[0..9, int] = [0,1,2,3,4,5,6,7,8,9]
    parallel:
      spawn f(a[0..2])


  main()