Skip to content

Production: a looped fallible function cannot tail-call another fallible function (LLB6005) #279

Closed

Description

@afflom

Problem

A looped (tail-recursive) fallible function whose tail position calls a different fallible function has no Rust rendering. lexlean check and lexlean build pass. lexlean production build fails with LLB6005 and lexlean verify with LLI9001. Reproduced at release/v0.4 9796067, Lean 4.32.1.

error[LLB6005]: root `Repro.Main.run`: package `repro_tailcall` for rust-std: arithmetic: the fallible call of f2 does not propagate its overflow
error[LLI9001]: phase verify: Repro.Main.run has no rendering in rust-std: arithmetic: the fallible call of f2 does not propagate its overflow

Minimal module (language 1.2):

\begin{lexlean}{Main}
\useglossary{lexlean.std.nat@1.2.0}
\title{Natural number addition}
\begin{semanticmodule}
definition{name: bump, parameters: [n : Nat], result: Nat, body: (n + 1), executable: true}

definition{
  name: countdown,
  parameters: [n : Nat, acc : Nat],
  result: Nat,
  body: (match n | Nat.zero => (bump acc) | Nat.succ below => (countdown below acc)),
  executable: true,
  recursive_argument: n
}

definition{
  name: run,
  parameters: [n : Nat],
  result: Nat,
  body: (countdown n 0),
  executable: true,
  production: {effects: [overflow], targets: [rust-std]}
}
\end{semanticmodule}
\end{lexlean}

Binding the call in a let, | Nat.zero => (let r : Nat := (bump acc); r), exports.

Cause

Read from crates/lexlean/src/calculus/rust/ at 9796067:

  1. lower.rs::succeed lowers a fallible tail call to propagate: false.
  2. tail.rs::looped/retarget wraps every non-self tail value as the loop's Err(...) exit.
  3. validate.rs::Checker::call (near line 233) accepts propagate: false on a fallible call only when tail && self.fallible.
  4. The Expr::Loop arm checks its body with self.block(body, false), so inside the loop the call is not in tail position and is rejected.

With the let, succeed wraps the binding as Succeed(Move r) instead.

Accepted when

  • The module above exports.
  • Its package agrees with the let variant on every input.
  • The validator still rejects a non-propagating fallible call that is genuinely not in tail position.
  • A register row, a scenario and a fixture cover the case.

Found while building UOR-Foundation/mcp#18 (UOR-Foundation/mcp#20).


Generated by Claude Code

Activity

  1. humuhumu33 commented on Oct 22, 2026

    @humuhumu33
    Contributor

    Claiming this one. Plan: reproduce on release/v0.5, locate the rule in calculus/rust (lower.rs succeed → tail.rs looped/retarget → validate.rs Checker::call), register a row + scenario + failing fixture first (R3), then the rendering, with plants recorded in VERIFICATION.md. Targeting release/v0.5; say if you want it on another line.

  2. added 2 commits that reference this issue on Oct 23, 2026
  3. humuhumu33 commented on Oct 25, 2026

    @humuhumu33
    Contributor

    Landed in #300 (a1c40ab on release/v0.5): fallible tail call (LLB6005), RB-21, register 449.

  4. self-assigned this
    on Oct 25, 2026
  5. afflom commented on Oct 25, 2026

    @afflom
    MemberAuthor

    Maintainer note for the 0.5.0 line, no new issue (moratorium, #15): a fallible closure application (Expr::Apply) at a loop's end is still refused today, because apply_types_expr enters Expr::Loop with tail = false (validate.rs:722) and refuses the application at validate.rs:683-688 as a dropped failure (LLB6005). Fail-closed, same class as this issue; fix is a few lines in apply_types_expr plus the bootstrap twin and one BS-05 vector, after the tag.


    Generated by Claude Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions