Why does `enable-javascript-harmony` prevent StackOverflows in Web Workers?

1.3k Views Asked by At

I have some code compiled from Ocaml to Javascript using js_of_ocaml. Now, when moving that code to work in a Web Worker thread, I started to get StackOverflows.

However, when I run the code on the main thread, or if I enable chrome://flags/#enable-javascript-harmony in the worker version the code runs fine!

Any idea of what could be going on? What is the enable-harmony flag doing exactly?

I presume that it could be enabling tail-call optimization, but it seems weird to me that it is not enabled already. Also, tail call alone doesn't explain why the code doesn't overflow if ran in the main thread.

See the links below for an example of the actual code. In the first link, the code runs in the main thread, in the second, the main part of the code is delegated to a worker:

When we reach the first induction on the optimize_0plus_sound lemma, a stack overflow will happen in the worker version; the version with Coq running in the main thread has no problem at all. Weird.

Thanks!

1

There are 1 best solutions below

3
Andreas Rossberg On

It's indeed tail call elimination. That is an ES6 feature, and still somewhat experimental in V8, so it's only enabled by the flag at the moment.

My guess is that you are only seeing the effect on workers because you didn't restart Chrome after changing the flag?