Non tail-rec code is not properly rejected but fails the compilation
Non tail-rec recursion fails the compiler, instead of properly reporting the rejection.
Optimize.tailrec2loop
can reject the input when it finds a non tail-rec recursion, not keeping it LetRec
.
$ ./test.sh ml_non_tailrec_toplevel.ml
Entering directory '/Users/jun/.share/scaml'
Entering directory '/Users/jun/.share/scaml'
----- ml_non_tailrec_toplevel.ml
dune exec ../driver/main.exe -- --scaml-noscamlib --scaml-dump-iml --scaml-time -I ../_build/install/default/lib/scaml/scamlib -o /Users/jun/.share/scaml/tests/_build/ml_non_tailrec_toplevel.ml/ml_non_tailrec_toplevel.tz /Users/jun/.share/scaml/tests/_build/ml_non_tailrec_toplevel.ml/ml_non_tailrec_toplevel.ml : THIS COMPILATION MUST FAIL
Entering directory '/Users/jun/.share/scaml'
Entering directory '/Users/jun/.share/scaml'
Translated in 0.000197 secs
...
Unsupported (fun param_storage_192 ->
let rec (g_195 : int -> int) =
fun i_201 ->
if i_201 = 0
then (dealloc i_201; dealloc g_195; 0)
else
(let (k_202 : int) = (g_195; dealloc g_195) (i_201 - 1) in
(k_202; dealloc k_202) + (i_201; dealloc i_201)) in
let (i_220 : int) =
(g_195; dealloc g_195)
(snd (param_storage_192; dealloc param_storage_192)) in
assert (i_220 = 55); ([], ((i_220; dealloc i_220))));
dealloc g_195
Fatal error: exception "Assert_failure src/compile.ml:763:8"
Raised at SCamlc__Compile.Make.structure in file "src/compile.ml", line 763, characters 8-20
Called from Stdlib__list.rev_map.rmap_f in file "list.ml", line 103, characters 22-25
Called from Spotlib__Xlist.map in file "lib/xlist.ml", line 151, characters 21-32
Called from SCamlc__Tools.with_time in file "src/tools.ml", line 117, characters 12-16
Called from SCamlc__SCamlComp.link_contract.(fun) in file "src/SCamlComp.ml", line 353, characters 22-73
Called from SCamlc__Conf.with_opt in file "src/conf.ml", line 185, characters 12-16
Called from SCamlc__SCamlComp.link.(fun) in file "src/SCamlComp.ml", line 417, characters 16-62
Called from Stdlib__list.iter in file "list.ml", line 110, characters 12-15
Called from SCamlc__Conf.with_opt in file "src/conf.ml", line 185, characters 12-16
Called from Dune__exe__Main.main.(fun) in file "driver/main.ml", line 278, characters 8-50
Called from SCamlc__Conf.with_opt in file "src/conf.ml", line 185, characters 12-16
Called from Dune__exe__Main.main in file "driver/main.ml", line 224, characters 4-1023
Re-raised at Location.report_exception.loop in file "parsing/location.ml", line 926, characters 14-25
Called from Dune__exe__Main.main in file "driver/main.ml", line 285, characters 4-35
Called from Dune__exe__Main in file "driver/main.ml", line 289, characters 2-9
Ok: Compilation failed as expected