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.
In this repository43 other files it gives its agents.
- AGENTS.mdAGENTS.md
- counterexample-first-provingSkill
- hol-metamath-adapterSkill
- isabelle-isar-adapterSkill
- itp-cross-portingSkill
- lean-ai-formalizationSkill
- lean-asymptotic-algorithmsSkill
- lean-bisectSkill
- lean-blueprintSkill
- lean-buildSkill
- lean-computational-reflectionSkill
- lean-core-onlySkill
- lean-corpus-auditSkill
- lean-dependency-managementSkill
- lean-doc-syncSkill
- lean-egraph-cpsat-superoptSkill
- lean-gatewaySkill
- lean-kernel-optimizationSkill
- lean-knowledge-formalizationSkill
- lean-math-analysisSkill
- lean-math-discreteSkill
- lean-math-dynamicalSkill
- lean-math-foundationsSkill
- lean-math-optimizationSkill
- lean-math-stochasticSkill
- lean-mweSkill
- lean-pedagogical-expositionSkill
- lean-proof-refactorSkill
- lean-proof-repairSkill
- lean-proof-reviewSkill
- lean-proofSkill
- lean-researchSkill
- lean-retro-methodologySkill
- lean-review-councilSkill
- lean-security-formalizationSkill
- lean-setupSkill
- lean-specificationSkill
- lean-tautology-triageSkill
- lean-unboxed-limbs-swarSkill
- lean-upstream-prSkill
- lean-verification-gateSkill
- research-councilSkill
- rocq-proof-adapterSkill
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
- Very specific: line 55
Keep branching step lambdas <= 30 AST nodes (KERNEL-LAW-28).
≈ “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.
Files
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), flatteningProd/WPairstate into<= 6unboxed scalar parameters (KERNEL-LAW-09,KERNEL-LAW-10,KERNEL-LAW-24), preservingm_whnfDAG 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
- Unpack at Wrapper -- Strip records/typeclasses and bounds once at the entry wrapper; keep
@Nat.recworkers monomorphic with<= 6unboxed scalar arguments. - Factor Join Points &
SpecConstr-- Extract converging merge branches (<= 30AST nodes if branching,KERNEL-LAW-28) as closed helpers preservingm_whnfDAG sharing (KERNEL-LAW-01C). - Defunctionalize CPS -- Replace higher-order closures with closed continuation constructors or direct tail
accumulators (
Nat.succvsNat.add 1,ADR-INV-0025). - Verify Full-Consumer Cost -- Prove
wrapper n = spec nand check end-to-endreal - twinlitinstructions:uto catch the Single-Consumer Isolation Paradox.
Recovery & STOP
- Revert any CPS or Join-Point split regressing end-to-end
real - twinlitinstructions. - Keep branching step lambdas
<= 30AST 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..31kernel cost model../lean-computational-reflection/SKILL.md-- Section 1/2/3 duality & reflection
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
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.

