Skip to content

Instantly share code, notes, and snippets.

@hugoabonizio
Last active November 10, 2017 12:06
Show Gist options
  • Save hugoabonizio/82bb6ca249f15de03a21ce8d9deeb924 to your computer and use it in GitHub Desktop.
Save hugoabonizio/82bb6ca249f15de03a21ce8d9deeb924 to your computer and use it in GitHub Desktop.
This program breaks Crystal compiler
a = {1, 0}
b = {a, a}
c = {b, b}
d = {c, c}
e = {d, d}
f = {e, e}
g = {f, f}
h = {g, g}
i = {h, h}
j = {i, i}
k = {j, j}
l = {k, k}
m = {l, l}
n = {m, m}
o = {n, n}
p = {o, o}
q = {p, p}
puts q
@veelenga
Copy link

veelenga commented Nov 9, 2017

b written twice. Is this intentional ?

b = {a, a}
b = {a, a}

@JonnyCodewalker
Copy link

JonnyCodewalker commented Nov 9, 2017

@veelenga not needed, I can't test it right now, but the principle is that the faculty ^2 we are dealing with is breaking the stack I guess. There are 2 ^ 18 = 262144 Integers. Considering an Integer to be 32bit (not sure what the implementation is) we get 8388608bit, or rather 8192Mib or 1GiB. Depending on how the stack is implemented I can easily see that blowing it up.

Note that you can't really avoid that problem, since you could just add more and more "levels", but maybe you would search for a way to optimize it and maybe make the issue clearer?

@sam0x17
Copy link

sam0x17 commented Nov 10, 2017

This is a cool bug

@hugoabonizio
Copy link
Author

hugoabonizio commented Nov 10, 2017

@veelenga this wasn't intentional, I fixed it now! Thanks!

@JonnyCodewalker thank you for the explanation 😃

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment