Problem
The parser does not accept the Rust-style if let PATTERN = EXPR { body } form. Today the kernel pattern below fails with error[EP0001]: Expected ')' after binding name:
if let Some(ref mut sensor) = THERMAL.sensors[i] {
sensor.update_temp(t)
}
if let Some(parent_id) = parent {
update_parent(parent_id)
}Background
Rust's if let is a syntactic shortcut for matching one specific pattern of an enum variant and binding its payload, with an optional else for the no-match case. Functionally equivalent to:
match EXPR {
PATTERN => body,
_ => {} // or `else_body`
}The kernel was written in a Rust-influenced style and uses this pattern heavily for Option<T> unwrapping.
Scope
$ grep -rn "if let Some" home-os/kernel/src --include='*.home' | wc -l
85
$ grep -rln "if let Some" home-os/kernel/src --include='*.home' | wc -l
8 filesAffected kernel files
- kernel/src/power/thermal_x86.home:382
- kernel/src/power/battery.home:357
- kernel/src/power/device_pm.home:266
- kernel/src/drivers/bluetooth/hci.home:466
- kernel/src/arch/arm64/rpi/devicetree.home:289
- kernel/src/power/cpufreq_x86.home (multiple sites)
- kernel/src/arch/arm64/rpi/emmc.home (multiple sites)
- 1 more
Expected behavior
Parse if let PATTERN = EXPR { body } [else { else_body }] as syntactic sugar for a match expression on EXPR with one explicit arm and a wildcard fallback:
if let Some(x) = expr { body }if let Some(ref mut x) = expr { body }(Rust'sref mutborrow modifier — acceptable if treated as binding declaration; actual mutability semantics can be future work)if let .Variant(payload) = expr { body }(using Home's existing dot-prefixed enum-variant pattern syntax)if let Some(x) = expr { body } else { fallback }
Implementation hint
In statement-context dispatch, after seeing if, peek for let. If next is let, dispatch to a new parseIfLetStatement that:
- Consumes
let - Parses a pattern using the existing
parsePatternmachinery (which already handlesSome(x),.Variant(x), etc. for match arms) - Expects
= - Parses the scrutinee expression
- Expects
{, parses body block - Optional
else { ... } - Lowers to
match EXPR { PATTERN => body, _ => else_body or {} }AST node — reuses existing match-arm machinery so codegen needs no changes.
Note: ref mut in the binding can be parsed and ignored for now (or attached as a binding modifier flag) — full borrow semantics are downstream.
Tests
Positive:
if let Some(x) = foo() { use(x) }if let Some(x) = foo() { use(x) } else { handle_none() }if let .Ok(v) = result { use(v) }- Nested:
if let Some(a) = x { if let Some(b) = y { use(a, b) } }
Regression:
if cond { ... }keeps workingif let pattern = exprdoes NOT matchif let_var: T = expr(variable named "let" — there shouldn't be one, but be careful with the disambiguation)
Acceptance
- The 5+ listed kernel files clear
home-debug astpast theif letline. - Existing test suite green.