-
Notifications
You must be signed in to change notification settings - Fork 66
Stack overflow during grading occurs sooner in the browser than in batch mode #242
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Indeed tail call is limited in js_of_ocaml; see the docs. We use a workaround for Coq https://github.com/ejgallego/jscoq/blob/v8.10/etc/patches/trampoline.patch |
Thanks Emilio. Interesting workaround, which I don't fully understand: doesn't the fact that Besides, I suppose that this workaound is applicable to code that is already written in monadic style, but this does not really solve the problem with "normal" code. |
Indeed, what the workaround does is to help JSOO realize about the tail-rec; for teaching this is a problem indeed. |
Does anyone have a suggestion to fix this problem? It's now exposed on the public site. |
Hi @fpottier, that's an annoying problem indeed. FWIW, I recently identified another
Other ideas/suggestions are welcome as well... |
Hi everyone, I recently stumbled upon some stack overflows too on the platform, which surprised me a lot since the solutions were not recursive at all! First, the size of the stack depends on the browser. For example, the current version of Firefox has a stack size of about 26k, while Chrome only has 13k. This looks plenty for non-recursive exercises, but let's see some benchmarks. Example : a trivial test of the identity function, with the Firefox gives a stack overflow with less than 50 of those tests, resp. 30 for Chrome. At first, this suggests that one call of the test function is compiled into something of the order of 500 (~ 26k / 50) actual javascript function calls. Let's see what happens with functions with bigger arguments. The same example over int triplets instead of Firefox gives a stack overflow with less than 18 of those tests, resp. 8 for Chrome, which shows that this issue can appear with quite small exercises. This is about three times smaller than for the first example. This suggests that the number of javascript function calls is not to blame, but rather the size that arguments use on the stack. For me, this raises two questions:
|
The title says it all: I have written a grader which works in batch mode (when executed via
learn-ocaml grade
) but fails in the browser (Firefox) with aStack_overflow
exception. This happens when grading the solution of my exercisenondet_monad_cont
, which currently is sitting in a pull request inlearn-ocaml-corpus
. The second half of Question 4 (laziness) is where the grader fails.Is it possible that the compilation to JavaScript does not do tail call optimization?
Is it possible to somehow ensure that the stack limit is the same under both environments (batch mode and in-browser mode)?
Is it possible for each exercise to indicate what stack size it needs?
The text was updated successfully, but these errors were encountered: