Skip to content

Add missing cases/fix wrong cases in tail recursiveness check

E. Rivas requested to merge er433/fix/check_recursive_call into dev

Motivation and Context

From the MR introducing compilation of non-tail recursive functions, Alistair mentioned a case where the check for tail recursive functions fails.

Description

This MR updates the function checking, in particular:

  • Adds missing cases (mutability, refs.).
  • It changes E_recursive case to keep checking current name.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Performance improvement (non-breaking change that improves performance)
  • None (change with no changelog)

Changelog

Example file

$ cat error_no_tail_recursive_function2.mligo
let rec foo (xs : int list) : int =
  let rec loop (xs : int list) : int =
    loop (foo xs :: xs)
  in
  loop xs

Before fix

$ ligo compile expression cameligo foo --init-file error_no_tail_recursive_function2.mligo
An internal error ocurred. Please, contact the developers.
Corner case: foo not found in env.

After fix

$ ligo compile expression cameligo foo --init-file error_no_tail_recursive_function2.mligo
File "error_no_tail_recursive_function2.mligo", line 3, characters 10-13:
  2 |   let rec loop (xs : int list) : int =
  3 |     loop (foo xs :: xs)
  4 |   in

Recursive call not in tail position.
The value of a recursive call must be immediately returned by the defined function.

Checklist:

  • Changes follow the existing coding style (use dune @fmt to check).
  • Tests for the changes have been added (for bug fixes / feature).
  • Documentation has been updated.
  • Changelog description has been added (if appropriate).
  • Start titles under ## Changelog section with #### (if appropriate).
  • There is no image or uploaded file in changelog
  • Examples in changed behaviour have been added to the changelog (for breaking change / feature).
Edited by E. Rivas

Merge request reports

Loading