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
docs(examples,README,SPEC): adopt if (var x = expr) for remaining presence checks
Migrates the `var x = expr; if (x != null) { ... uses x ... }` shape to
the IfLet form wherever the bound name is used inside the truthy branch.
Examples (9 sites):
- `safety_demo.ks`: scalar map count update.
- `ringbuf_demo.ks`: two `network_events.reserve()` /
`security_events.reserve()` patterns.
- `map_operations_demo.ks`: `shared_stats[batch_key]` in-place mutation
(drops the redundant write-back) and `event_stream.reserve()`.
- `type_checking.ks`: `connection_stats[header.src_ip]` scalar update.
- `types_demo.ks`: four sites — `packet_filter[info]`, two scalar
`connection_count` / `protocol_stats` updates, and the
`extract_packet_info` pointer-returning helper.
README:
- The `lookup_or_create` snippet, which still showed the old shape, now
uses IfLet directly.
SPEC (8 sites):
- §3.1.2 (TC programs): `connection_tracker` helper.
- §4.6.7 (Map Integration with Pointers): `map_pointer_operations` —
the canonical example for "map lookup returns pointer" now uses IfLet.
- §5.2 (Global Maps): two `flow_stats` lookups now collapse from a
presence check + redundant lookup to a single IfLet.
- §9.2 (Top-Level Userspace Coordination): `process_events` ringbuf
read.
- §10.2 (Transparent Dynptr Integration): two `reserve()`-and-write
examples — drops the explicit `: *u8` annotation since IfLet's
grammar doesn't support a binding type annotation; the type is
inferred from `reserve()`'s return type and noted in a comment.
- §10.4 (Memory Lifetime): `cache_map[key]` lifetime-safety example.
- §10.6 (Cross-Context Memory Safety): two `shared_map[0]` examples.
Sites left intentionally untouched in both `examples/` and SPEC:
- `m[k] != null` with the body using only `m[k] op= rhs` (rate_limiter,
maps_demo:87, map_operations_demo:60) — IfLet adds an unused binding.
- All `== null` shapes (object_allocation, ringbuf_demo program-load
checks, test_error_handling) — IfLet branches on presence, not
absence.
- `tcp_info != null && tcp_info.flags & TCP_SYN` (SPEC §3.1.2 ddos
example) — compound condition; IfLet doesn't desugar to `&&`.
- `var buffer = kzalloc(...); if (buffer != null) { mark_secure } return buffer`
(SPEC §3.6.5) — `return buffer` is outside the if; IfLet would put
the binding out of scope at the return.
- `return cache_entry != null && cache_entry.is_valid` (SPEC
cache-checksum example) — return-as-expression, not an if.
Pre-existing safety_demo stack-overflow (608 bytes > 512) is unrelated
and predates this PR; verified by stashing the migrations and
re-compiling — same 608-byte error.
84 alcotest suites still green.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
0 commit comments