Closed
Description
Mutually recursive functions occurring in a loop that do not explicitly calls one-another are miscompiled.
let app f x = f x
let () =
for i = 1 to 4 do
let rec f x = if x = 0 then 1 else i * app g (x - 1)
and g x = app f x
in
Format.eprintf "%d@." (g i)
done
I get the following error when trying to run the generated code:``
TypeError: Cannot read property 'length' of undefined
at caml_call1 (/tmp/a.js:2416:16)
at app (/tmp/a.js:5655:36)
at f (/tmp/a.js:5660:55)
at caml_call1 (/tmp/a.js:2416:28)
at app (/tmp/a.js:5655:36)
at g (/tmp/a.js:5663:47)
at /tmp/a.js:5665:15
Using the information from mutated_vars
in group_closures
instead of ntc
seems to fix the issue. But that might not be enough to address #1007?
let calls =
if tc_only
then calls
else Var.Set.union calls (Addr.Map.find (fst x.cont) mutated_vars)
in