agentleFS
r-irber-irbe/proof-skills/skills/lean-worker-wrapper-cps/SKILL.md

lean-worker-wrapper-cps

Skill3 starsChanged 13 days agoApache-2.0View on GitHub

USE FOR: GHC Core style Lean 4 WHNF tuning -- Worker/Wrapper unboxing, Join Points (`m_whnf`), `SpecConstr` specialization, and defunctionalized first-order CPS continuations. DO NOT USE FOR: statement-level Mixin/Mathlib generalization (`@lean-proof-refactor`) or raw SIMD/SWAR bit packing (`@lean-unboxed-limbs-swar`). TRIGGERS: worker-wrapper, join point, SpecConstr, defunctionalized CPS, Danvy, unboxed accumulator, WPair, instantiate_rev, KERNEL-LAW-09, KERNEL-LAW-10.

The file

We split this skill into the rules it gives an agent

1 rule. About 0 are common, 0 are distinctive, and 1 is very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈0

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 1

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Keep branching step lambdas <= 30 AST nodes (KERNEL-LAW-28).

    line 55

≈ “Common” is an estimate: at least 1 in 5 of the 408,460 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Worker/Wrapper, Join Points, SpecConstr & Defunctionalized CPS in Lean 4

Eliminate tuple/record boxing, instantiate_rev substitution bloat, and higher-order closure allocation in hot @Nat.rec loops using Worker/Wrapper splitting, non-escaping Join Points, SpecConstr, and closed defunctionalized CPS.

Routing

  • USE FOR: stripping structure/typeclass wrappers at entry (wrapper -> worker), flattening Prod/WPair state into <= 6 unboxed scalar parameters (KERNEL-LAW-09, KERNEL-LAW-10, KERNEL-LAW-24), preserving m_whnf DAG sharing across merge branches via local Join Points, and replacing closure parameters with algebraic continuation tags.
  • DO NOT USE FOR: general lemma extraction (@lean-proof-refactor) or pure asymptotic algorithm replacement (@lean-asymptotic-algorithms).

Workflow

  1. Unpack at Wrapper -- Strip records/typeclasses and bounds once at the entry wrapper; keep @Nat.rec workers monomorphic with <= 6 unboxed scalar arguments.
  2. Factor Join Points & SpecConstr -- Extract converging merge branches (<= 30 AST nodes if branching, KERNEL-LAW-28) as closed helpers preserving m_whnf DAG sharing (KERNEL-LAW-01C).
  3. Defunctionalize CPS -- Replace higher-order closures with closed continuation constructors or direct tail accumulators (Nat.succ vs Nat.add 1, ADR-INV-0025).
  4. Verify Full-Consumer Cost -- Prove wrapper n = spec n and check end-to-end real - twinlit instructions:u to catch the Single-Consumer Isolation Paradox.

Recovery & STOP

  • Revert any CPS or Join-Point split regressing end-to-end real - twinlit instructions.
  • Keep branching step lambdas <= 30 AST nodes (KERNEL-LAW-28).

Handoffs

  • Predecessors: lean-proof, lean-proof-refactor.
  • Successors: lean-kernel-optimization, lean-proof-review, lean-verification-gate.

Detailed reference

  • Card: ../../references/cards/lean-worker-wrapper-cps-tables.md
  • Handbook: ../../references/handbooks/lean-worker-wrapper-cps-handbook.md
  • Template: ../../templates/core/Template_WorkerWrapper_JoinPoints.md

See also

  • ../lean-kernel-optimization/SKILL.md -- KERNEL-LAW-01..31 kernel cost model
  • ../lean-computational-reflection/SKILL.md -- Section 1/2/3 duality & reflection

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.