Skip to content

Commit 08255de

Browse files
ryansolidclaude
andauthored
Destructuring (RG-4b): live in declarations, snapshots in let (#49)
* Rename the `optimistic` statement to `guess` `guess x := e` replaces `optimistic x := e` (07 decision 18, ruled 2026-11-11). Semantics and lowering are unchanged (createOptimistic / createOptimisticStore); only the surface word moves. - Parsers (ref/src/parse.ts, compiler/src/parse.rs): `guess` is the keyword; `optimistic` stays reserved and is a parse error coded OPTIMISTIC whose hint names `guess` (guide/diagnostics.md, S-parse-hints). - Codes: OPTIMISTIC_OUTSIDE_HOLD -> GUESS_OUTSIDE_HOLD, OPTIMISTIC_NO_QUESTION -> GUESS_NO_QUESTION, OPTIMISTIC_REVERTED -> GUESS_REVERTED; HELD_WRITE / STALE_WRITE_BACK / AC-1b messages say `guess`. - Spec, guide, scenarios, examples, eval reference apps and the editor grammar use `guess`. eval/results and preregistrations are left as historical records. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0117BoWP7LmQhib6M9zGnmBH * Don't reserve `optimistic`: it names Solid's primitive, not a keyword Drops the OPTIMISTIC parse hint, its guide section, spec row and S-parse-hints variant; 07 decision 18 says why. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0117BoWP7LmQhib6M9zGnmBH * Clear errors with onFlush, not a guess An error clear is a reset that lands now (EF-8), not a guess at the server's answer: `guess saveError := ""` worked only because the source was given a constant question to revert to. The guide's action example, the examples and the eval reference apps now write `onFlush(() => { saveError := "" })`, and those error sources are declared with `:=`. S-ai2-settings gains the flush instant. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0117BoWP7LmQhib6M9zGnmBH * Allow a guess over an equation (Solid's createOptimistic(fn)) `x = e` then `guess x := v` in an action is legal (06 ST-5c, 07 decision 19): a guess is not a write of the truth, and Solid's derived createOptimistic(fn) has a setter that only guesses. A plain `x := v` on an equation stays WRITE_TO_NON_SOURCE; `props.x` and parameters stay refused (O-4). New code GUESS_ON_DEFERRED: a deferred equation lags its truth (V-16). Lowering: a guessed equation is createOptimistic(fn), or createOptimisticStore(fn, seed) when keyed or guessed by path, on the client, the server (matching owner trees for hydration) and in the oracle. Both checkers and both emitters agree (crate parity, lowered alike). Scenario S-guess-equation covers an equation of a source and a child's equation of a prop. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0117BoWP7LmQhib6M9zGnmBH * Destructuring (RG-4b, 07 §5): `{ a, b } = e`, `[x, , y = d] = e`, component signatures, `let { … } = e` A destructured equation is one equation per name, each a projection of the right side that keeps updating; a destructuring `let` is one snapshot local per name, as in JS. Defaults apply on undefined. Rest is not yet supported. `[n, setN] = createSignal(0)` keeps its JS_API hint. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0117BoWP7LmQhib6M9zGnmBH * Document destructuring: 07 grammar + decision 20, guide/language.md Bare `x = e` is always an equation, `let x = e` always a snapshot, and only `:=` and `guess` mutate; destructuring keeps each side's meaning. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0117BoWP7LmQhib6M9zGnmBH * Destructuring: rest patterns, `{ a, ...rest }` and `[x, ...rest]` An object rest is Solid's `omit` of the named keys, a live view (an internal `omit` expression in every runner and the crate); an array rest is `.slice(n)`. In a `let`, an object rest is a copy (`{ ...omit(…) }`). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0117BoWP7LmQhib6M9zGnmBH --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 0140638 commit 08255de

21 files changed

Lines changed: 513 additions & 44 deletions

File tree

‎compiler/src/ast.rs‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ pub enum ExprKind {
9090
/// RG-7b
9191
Use(String),
9292
Spread(Box<Expr>),
93+
/// RG-4b: an object rest, `{ a, ...rest } = e` (the parser's own; Solid's `omit`)
94+
Omit { e: Box<Expr>, keys: Vec<String> },
9395
/// R-f-3
9496
Throw(Box<Expr>),
9597
/// R-f-4: `e catch (x: A | B) => alt`; classes absent: every failure
@@ -422,6 +424,7 @@ impl Expr {
422424
ExprKind::Draft { .. } => "draft",
423425
ExprKind::Use(_) => "use",
424426
ExprKind::Spread(_) => "spread",
427+
ExprKind::Omit { .. } => "omit",
425428
ExprKind::Throw(_) => "throw",
426429
ExprKind::Catch { .. } => "catch",
427430
ExprKind::StyleMap { .. } => "stylemap",
@@ -439,6 +442,7 @@ impl Expr {
439442
ExprKind::Un { op, e } => obj(vec![("k", k), ("op", s(op)), ("e", b(e))]),
440443
ExprKind::Pre { name, init } => obj(vec![("k", k), ("name", s(name)), ("init", ob(init))]),
441444
ExprKind::Peek(e) | ExprKind::Latest(e) | ExprKind::Pending(e) | ExprKind::Spread(e) | ExprKind::Throw(e) => obj(vec![("k", k), ("e", b(e))]),
445+
ExprKind::Omit { e, keys } => obj(vec![("k", k), ("e", b(e)), ("keys", Some(strs(keys)))]),
442446
ExprKind::Await { e, init, stream } => obj(vec![("k", k), ("e", b(e)), ("init", ob(init)), ("stream", Some(Value::Bool(*stream)))]),
443447
ExprKind::If { c, t, f } => obj(vec![("k", k), ("c", b(c)), ("t", b(t)), ("f", b(f))]),
444448
ExprKind::Tpl(parts) => obj(vec![

‎compiler/src/check.rs‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ pub(crate) fn children<'a>(n: Node<'a>, paths: bool) -> Vec<Node<'a>> {
353353
Node::E(e) => match &e.k {
354354
ExprKind::Lit(_) | ExprKind::Id(_) | ExprKind::Use(_) | ExprKind::StyleMap { .. } => {}
355355
ExprKind::Bin { l, r, .. } => out.extend([Node::E(l), Node::E(r)]),
356-
ExprKind::Un { e, .. } | ExprKind::Peek(e) | ExprKind::Latest(e) | ExprKind::Pending(e) | ExprKind::Spread(e) | ExprKind::Throw(e) => out.push(Node::E(e)),
356+
ExprKind::Un { e, .. } | ExprKind::Peek(e) | ExprKind::Latest(e) | ExprKind::Pending(e) | ExprKind::Spread(e) | ExprKind::Omit { e, .. } | ExprKind::Throw(e) => out.push(Node::E(e)),
357357
ExprKind::Pre { init, .. } => out.extend(init.iter().map(|x| Node::E(x))),
358358
ExprKind::Await { e, init, .. } => {
359359
out.push(Node::E(e));
@@ -438,7 +438,7 @@ fn free_names(e: &Expr, bound: &HashSet<String>, out: &mut IndexSet<String>) {
438438
go(i, out);
439439
}
440440
}
441-
ExprKind::Latest(x) | ExprKind::Pending(x) | ExprKind::Un { e: x, .. } | ExprKind::Spread(x) => go(x, out),
441+
ExprKind::Latest(x) | ExprKind::Pending(x) | ExprKind::Un { e: x, .. } | ExprKind::Spread(x) | ExprKind::Omit { e: x, .. } => go(x, out),
442442
ExprKind::Bin { l, r, .. } => {
443443
go(l, out);
444444
go(r, out);
@@ -2051,7 +2051,7 @@ impl<'a> Checker<'a> {
20512051
self.expr(x, env, ctx, None);
20522052
self.model.probe = save;
20532053
}
2054-
ExprKind::Un { e: x, .. } | ExprKind::Spread(x) => self.expr(x, env, ctx, None),
2054+
ExprKind::Un { e: x, .. } | ExprKind::Spread(x) | ExprKind::Omit { e: x, .. } => self.expr(x, env, ctx, None),
20552055
ExprKind::Await { e: inner, init, .. } => {
20562056
if ctx.imperative && !self.stmt_awaits.contains(&(e as *const Expr)) {
20572057
let sh = show(e);

‎compiler/src/emit.rs‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1178,6 +1178,8 @@ impl<'p> Gen<'p> {
11781178
rtc("preOr", vec![call(id(p), vec![]), thunk(i)])
11791179
}
11801180
ExprKind::Peek(x) => rtc("untrack", vec![thunk(self.expr(x, env, &sub)?)]),
1181+
// RG-4b: Solid's live view
1182+
ExprKind::Omit { e: x, keys } => rtc("omit", std::iter::once(self.expr(x, env, &sub)).chain(keys.iter().map(|k| Ok(str(k.clone())))).collect::<Result<Vec<_>, _>>()?),
11811183
ExprKind::Await { e: x, stream, .. } => {
11821184
if let Some(v) = self.hoisted.get(&(e as *const Expr)) {
11831185
return Ok(call(id(v.clone()), vec![]));

‎compiler/src/infer.rs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ impl Walker {
271271
self.read(l, st, sh, local, depth);
272272
self.read(r, st, sh, local, depth);
273273
}
274-
ExprKind::Un { e, .. } | ExprKind::Spread(e) | ExprKind::Throw(e) => self.read(e, st, sh, local, depth),
274+
ExprKind::Un { e, .. } | ExprKind::Spread(e) | ExprKind::Omit { e, .. } | ExprKind::Throw(e) => self.read(e, st, sh, local, depth),
275275
ExprKind::Await { e, init, .. } => {
276276
self.read(e, st, sh, local, depth);
277277
if let Some(i) = init {
@@ -362,7 +362,7 @@ impl Walker {
362362
self.deps(l, st, sh, out);
363363
self.deps(r, st, sh, out);
364364
}
365-
ExprKind::Un { e, .. } | ExprKind::Spread(e) | ExprKind::Throw(e) => self.deps(e, st, sh, out),
365+
ExprKind::Un { e, .. } | ExprKind::Spread(e) | ExprKind::Omit { e, .. } | ExprKind::Throw(e) => self.deps(e, st, sh, out),
366366
ExprKind::If { c, t, f } => {
367367
self.deps(c, st, sh, out);
368368
self.deps(t, st, sh, out);

0 commit comments

Comments
 (0)