Skip to content
Beskid Platform specification

Beskid

Jump to a Beskid service

Beskid

Jump to a Beskid service

Lambdas and closures

Platform spec node

Lambdas and closures

Spec standingStandard

Owner
Piotr Mikstacki
Submitter
Piotr Mikstacki

Defines lambda expressions (=>), closures, and their typing. Function types are in Types; inference in Type inference.

  • param => body or (p1, p2) => body where body is an expression or { block }.
  • Parameters may be typed (T name) or untyped (name) when contextual type is available.
  • Lambdas may appear anywhere an Expression is allowed, including as spawn operands.
  • 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 mut bindings unless the implementation explicitly allows it; otherwise must error.
  • 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 spawn must be compatible with fiber entry signatures (see Fibers and spawn).

Type inference and call mismatch bands E1202, E1205. Registry: Diagnostic code registry.

Closure codegen tests must match between debug and release for the reference backend on each supported triple.

  • D-LM-LAM-001 — Expression lambdas: Statement lambdas use block bodies; no separate fn literal syntax in v0.1.
  • D-LM-LAM-002 — No async lambdas: async/await are not closure modifiers; use spawn instead.
  • 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.

Capture lists, environment layout, and lifetime of delegates. JIT and AOT must agree on closure calling conventions.