You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat(linear-arrows): enforce -[q]-> quantity annotations on lambda params
Three coordinated fixes:
**typecheck.ml — lambda synth:**
Replace the hardcoded QOmega in ExprLambda synthesis with the actual
p_quantity from each parameter declaration. A lambda `|@linear x: T| e`
now synthesises type `T -[1]-> U` instead of `T -[ω]-> U`, so the
arrow type faithfully records the linearity contract.
**typecheck.ml — lambda check mode:**
When checking a lambda against an expected `TArrow (_, q, _, _)`, verify
that any explicit param quantity annotation matches the expected arrow
quantity. Unannotated params silently inherit the expected quantity
(correct for context-driven inference).
**quantity.ml — lambda body param checking:**
Add an `errors` accumulator to `env` (since `infer_usage_expr` is unit).
In `ExprLambda`, declare annotated params via `env_declare` so `env_use`
tracks their usage counts. After walking the body, check each annotated
param with `check_quantity` and push violations to `env.errors`. Drain
accumulated errors at the end of `check_function_quantities` (step 4).
Also fixes: save/restore `env.quantities` entries that lambda params
shadow, so nested scopes cannot leak stale quantity entries.
**codegen.ml / wasm.ml / wasm_encode.ml:**
Add `custom_sections` field to `wasm_module` and emit it in the encoder
(Wasm section ID 0). Wire `ownership_kind` annotations collected during
codegen into the `affinescript.ownership` custom section for typed-wasm
Level 7/10 verification. Fix `codegen.ml` record literal to include the
new field.
**Tests:**
- `test/e2e/fixtures/linear_arrow.affine` — valid single-use @linear lambda
- `test/e2e/fixtures/linear_arrow_violation.affine` — double-use @linear lambda
- `E2E Linear Arrows` suite: 2 cases (valid accepted, violation rejected)
- 75 tests total, all passing.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
0 commit comments