Skip to content

Commit a6275b6

Browse files
author
Nat
committed
Bug repro, compiled iteration over uninitialized ListOf(bool)
Strange behavior observed when iterating through a list of bools which was created with .setSizeUnsafe(N), so full of garbage data. Outside of the compiler, or when using the builtin sum(), the iteration gives the expected answer, the number of True values in the garbage data. Inside a simple Entrypointed function to count Trues, we get a ludicrously large answer (bigger than N). Running the same function with some extra added statements for no purpose (could be almost anything more than "pass"), we instead get 0. The compiler seems to know to replace uninitialized data with False.
1 parent 8c2c809 commit a6275b6

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
from typed_python import ListOf, Entrypoint
2+
3+
4+
N = 50
5+
A = ListOf(bool)()
6+
A.reserve(N)
7+
A.setSizeUnsafe(N)
8+
9+
10+
@Entrypoint
11+
def countTrueInUninitializedList(A):
12+
total = 0
13+
for i in range(len(A)):
14+
if A[i]:
15+
total += 1
16+
17+
return total, sum(A)
18+
19+
20+
print(countTrueInUninitializedList(A))
21+
22+
23+
@Entrypoint
24+
def sameButWithAddedStatements(A):
25+
indices = ListOf(int)()
26+
total = 0
27+
for i in range(len(A)):
28+
if A[i]:
29+
indices.append(i)
30+
total += 1
31+
32+
return total, sum(A)
33+
34+
35+
print(sameButWithAddedStatements(A))

0 commit comments

Comments
 (0)