52. Static closure & operation-value lowering (2026-11-21)
- Three-tier static closure lowering in
cpl-codegen(devirt.rs,emit.rs,expr.rs,stmt.rs), withstd::functiononly for genuinely dynamic values.- Direct elision (
StaticDirect): when a struct fn-field or fn parameter holds a single statically known zero-capture closure and never escapes to a dynamicstd::functionhome or assignment, calls emit directly ascpl_fnN(...)and thestd::functionfield/parameter is replaced with a 1-byteboolplaceholder (falseat construction/call sites). Eliminatesstd::functioncompletely fromMonoid,Action,SegTree,LazySegTree,DualSegTree,SparseTable,DisjointSparseTable. - Template functor parameters (
StaticTemplate): any non-recursive, non-entry/judge/hook function with a non-mut, non-reassignedTy::Fnparameter that is not directly elided lowers to a C++17 function template (template <class F0, ...>,F0&& p), passing lambdas (including capturing/mutable ones) by type with zerostd::functionand full inlining. - Local
autobindings (StaticLocalAuto): any non-hoisted, non-reassigned local closure binding (let f = ...or nestedfn via(...) = ...) emitsauto f = [...](...) { ... };instead ofstd::function<...>. - Dynamic fallback (
DynamicStdFunction): genuinely dynamic fn values (struct fields holding multiple or capturing closures, recursive/entry/judge fn parameters, mutable/reassigned fn slots) retainstd::function.#include <functional>is emitted only whenstd::functionappears in the output. - Visibility (
cpl explain <file.cp>):cpl explain <file.cp>(and--json) runscpl_codegen::explain_closuresand reports every fn-typed site's lowering mode (static: direct,static: template,static: auto, ordynamic: std::functionwith reason), fulfilling the "nothing secret under the hood" rule. - Return-tuple move: returning a struct/tuple literal moves owned non-scalar local fields (
std::move(table)) when unreferenced by sibling fields, preventing O(n log n) vector copies on range-structure constructors (DisjointSparseTable35.4 ms / 1.98x → 18.9 ms / 1.09x vs matched C++17). Reverse: revertelidable,template_params,local_auto, andexplain_closuresincrates/cpl-codegen/src/devirt.rs, theemit.rs/expr.rs/stmt.rshooks, andexplain_fileincrates/cpl-cli/src/lib.rs.
- Direct elision (