motoko icon indicating copy to clipboard operation
motoko copied to clipboard

Fails to compile with large hard coded array.

Open skilesare opened this issue 2 years ago • 5 comments

I was trying to create a test file to give me some random bytes and I could not do 16k bytes. Some truncation of the size of the array allowed it to compile: https://gist.github.com/skilesare/9959db128f3cc208f92f2e2415f3c8c2

skilesare avatar Oct 18 '23 21:10 skilesare

Hmm, I can't get this to crash the compiler, even when doubling the length of the array. Did it happen on the playground perhaps?

crusso avatar Oct 29 '23 21:10 crusso

The playground does indeed seem to choke (become unresponsive) on this similar example: https://m7sm4-2iaaa-aaaab-qabra-cai.raw.ic0.app/?tag=2552206398

@chenyan-dfinity could this be a problem with moc-js?

crusso avatar Oct 29 '23 21:10 crusso

Possible. If you open the developer tools, you will see that even type checking gets Stack_overflow.

chenyan-dfinity avatar Oct 29 '23 21:10 chenyan-dfinity

I looked at the type checking code and it uses List.map and other h.o. functions that may not be tail recursive on js. The ocaml implementation of List.map (and some other functions) is annotated as @tail_mod(ulo)_cons but I don't know if the js backend honors that annotation.

https://github.com/ocaml/ocaml/blob/14d9ab10567d1a6d1d70c24b04656d9e44b3aacb/stdlib/list.ml#L80

crusso avatar Oct 30 '23 17:10 crusso

#4263 shows it compiles fine with non-js compilers.

crusso avatar Oct 30 '23 19:10 crusso