Lambdas and closures
Platform spec node
Lambdas and closures
Spec standingStandard
No architecture decision records under adr/ for this feature yet. Standard features must
publish at least one ADR or keep a ## Decisions summary on the hub.
- Control flow Conditionals, loops, and structured control transfer. Lowering to HIR/CLIF follows the evaluation order defined here.
- Events Multicast events, subscription lifetime, and thread affinity assumptions. UI stacks build on these primitives.
- Lambdas and closures Capture lists, environment layout, and lifetime of delegates. JIT and AOT must agree on closure calling conventions.
0 revisions (git unavailable at build; counts may be empty)
No commits recorded for this path.
| Section id | Required | Found |
|---|---|---|
scope | yes | yes |
features | yes | yes |
Full tree: run pnpm verify:platform-spec-layout (writes src/generated/platform-spec-layout-report.json).
Normative specification
Section titled “Normative specification”Defines lambda expressions (=>), closures, and their typing. Function types are in Types; inference in Type inference.
Syntax
Section titled “Syntax”param => bodyor(p1, p2) => bodywherebodyis an expression or{ block }.- Parameters may be typed (
T name) or untyped (name) when contextual type is available. - Lambdas may appear anywhere an
Expressionis allowed, including asspawnoperands.
Static rules
Section titled “Static rules”- Lambda type must be inferable from expected type or parameter annotations (E1202 otherwise).
- Captured locals must be definitely assigned before capture or diagnosed per definite-assignment rules (v0.1: follow reference compiler behavior).
- Lambdas must not capture
mutbindings unless the implementation explicitly allows it; otherwise must error.
Dynamic semantics
Section titled “Dynamic semantics”- A closure must extend the lifetime of captured storage to at least the closure value’s lifetime.
- Invocation uses the standard function call ABI for the target triple.
- Closures passed to
spawnmust be compatible with fiber entry signatures (see Fibers and spawn).
Diagnostics
Section titled “Diagnostics”Type inference and call mismatch bands E1202, E1205. Registry: Diagnostic code registry.
Conformance
Section titled “Conformance”Closure codegen tests must match between debug and release for the reference backend on each supported triple.
Decisions
Section titled “Decisions”- D-LM-LAM-001 — Expression lambdas: Statement lambdas use block bodies; no separate
fnliteral syntax in v0.1. - D-LM-LAM-002 — No async lambdas:
async/awaitare not closure modifiers; usespawninstead. - D-LM-LAM-003 — Capture extends lifetime: Closures must keep captured locals alive for the closure value’s lifetime.
- D-LM-LAM-004 — GC for escaped captures: Captured reference-bearing values must be heap-traced when they escape the frame.
Platform view
Section titled “Platform view”Capture lists, environment layout, and lifetime of delegates. JIT and AOT must agree on closure calling conventions.