Skip to content

Recursion lint, part 2 of 2: Indirect Recursion #15020

Closed
@felix91gr

Description

@felix91gr

What it does

This is a restriction lint, mostly intended to be used in Safety Critical contexts.
It checks for indirect recursive calls.

It's a follow-up to #428, the Direct part of which has been implemented in #15006

I plan to be implementing it during this month.

Advantage

Context: the form asked about recommendations over the linted code

There are no universal good recommendations over the original code. Some recursive algorithms can be converted to constant-memory loops, but a lot of them actually require a stack to work. The reason why recursion is tightly controlled in Safety Critical systems is them running out of memory. This is why we cannot just recommend a loop with a stack: it would still potentially run out.

There is no "right" answer to how to change the original code:

  • Sometimes it must be changed to a loop,
  • Sometimes it must be memory-bound in some way, and then vetted to be correct,
  • And sometimes an entirely different solution is needed.

That's why this lint should issue no recommendations.

Drawbacks

I can think of two drawbacks of running this lint.

  • Possible performance issues related to the amount of unique call cycles. If this is found to be a problem, I'll add a setting to limit the cycle size to check. I don't expect it to be necessary if I do early-exiting properly, but it is a Plan B.
  • The UX problem of how to give good error messages of this lint to the user is not obvious. If done poorly, this lint could be very obtuse to read or feel clumsy to use. I want to iterate on this until the lint issues good error messages in all scenarios.

Example

fn i_call_myself_indirectly() {
  i_call_my_caller();
}

fn i_call_my_caller() {
  i_call_myself_indirectly();
}

Metadata

Metadata

Assignees

Labels

A-lintArea: New lints

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions