···876876- #12861: Fix a possible crash in the `threads` library.
877877 (Mark Shinwell, review by Gabriel Scherer and KC Sivaramakrishnan)
878878879879+- #12958: Fix tail-modulo-cons compilation of try-with, && and ||
880880+ expressions.
881881+ (Gabriel Scherer and Nicolás Ojeda Bär, report by Sylvain Boilard, review by
882882+ Gabriel Scherer)
883883+879884OCaml 5.1.1 (8 December 2023)
880885----------------------------
881886
+4-11
lambda/tmc.ml
···642642 | Ltrywith (l1, id, l2) ->
643643 (* in [try l1 with id -> l2], the term [l1] is
644644 not in tail-call position (after it returns
645645- we need to remove the exception handler),
646646- so it is not transformed here *)
647647- let l1 = traverse ctx l1 in
648648- let+ l2 = choice ctx ~tail l2 in
645645+ we need to remove the exception handler) *)
646646+ let+ l1 = choice ctx ~tail:false l1
647647+ and+ l2 = choice ctx ~tail l2 in
649648 Ltrywith (l1, id, l2)
650649 | Lstaticcatch (l1, ids, l2) ->
651650 (* In [static-catch l1 with ids -> l2],
···836835 | _ -> invalid_arg "choice_prim" in
837836 let+ l1 = choice ctx ~tail l1 in
838837 Lprim (Popaque, [l1], loc)
839839- | (Psequand | Psequor) as shortcutop ->
840840- let l1, l2 = match primargs with
841841- | [l1; l2] -> l1, l2
842842- | _ -> invalid_arg "choice_prim" in
843843- let l1 = traverse ctx l1 in
844844- let+ l2 = choice ctx ~tail l2 in
845845- Lprim (shortcutop, [l1; l2], loc)
846838847839 (* in common cases we just return *)
848840 | Pbytes_to_string | Pbytes_of_string
···902894 | Pbswap16
903895 | Pbbswap _
904896 | Pint_as_pointer
897897+ | Psequand | Psequor
905898 ->
906899 let primargs = traverse_list ctx primargs in
907900 Choice.lambda (Lprim (prim, primargs, loc))
+11
testsuite/tests/tmc/shortcut.ml
···11+(* TEST flags = "-w -71"; *)
22+33+let[@tail_mod_cons] rec f () = Some (g ())
44+and[@tail_mod_cons] g () = false && true
55+66+let () = assert (f () = Some false)
77+88+let[@tail_mod_cons] rec f () = Some (g ())
99+and[@tail_mod_cons] g () = true || false
1010+1111+let () = assert (f () = Some true)