Module Sarek_ppx_lib.Sarek_tailrec

module Analysis = Sarek_tailrec_analysis

Re-export analysis functions for use by other modules

val count_recursive_calls : string -> Sarek_typed_ast.texpr -> int

Re-export commonly used analysis functions

val is_tail_recursive : string -> Sarek_typed_ast.texpr -> bool

Kernel-Level Pass

val max_inline_limit : int

Maximum inline depth for bounded recursion. Beyond this, we refuse to compile as it would generate too much code.

val extract_pragma : Sarek_typed_ast.texpr -> string list option * Sarek_typed_ast.texpr

Extract pragma options and inner body from a function body. Returns (Some opts, inner_body) if body is TEPragma, (None, body) otherwise.

Transform all recursive module functions in a kernel:

  • Tail-recursive functions are transformed to loops
  • Non-tail recursion with pragma "sarek.inline N" is inlined N times
  • Validates pragma usage: unroll for tail, sarek.inline for non-tail

This pass is run after type checking and before lowering to Kirc.