Skip to content

Commit 7e5bc81

Browse files
ryansolidclaude
andauthored
eval: desk9 .rx reference grades 0; fix keyed refresh; tighten R-8; two guide patterns (#58)
* eval: hand-written desk9 .rx reference grades 0; fix refresh of keyed equations The round 7 chain4 app graded 3 defects on desk9 (fuzz seeds 8, 11, 12). The new reference keeps issue data in an app-level module and lays every write in flight over each answer through guessed sources, and grades 77/77, 38/38, 0/20. refresh of a keyed equation re-asked nothing in the compiled runtime and the oracle; S-keyed-refresh pins the fix. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0117BoWLtkg281f1NkGEDjCt * R-8: an errored region or disabled covers a failure only when it reads the value Ruled 2026-11-13: pending? x takes no failure, so a region whose content reads x only under pending? never shows its fallback, and the click throws (desk9 fuzz seed 11). rxc refuses it as UNGUARDED_SNAPSHOT; the five references with the old labels.rx are fixed (labels and chain4 tasks still pass all their tests). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0117BoWLtkg281f1NkGEDjCt * guide: lay every write over the answer; keep server data with the app Two patterns from the desk9 reference, with a generic example: writes in flight as guess lists laid over the answer by one equation every view reads, and server data plus its actions in a module so a write outlives its page. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0117BoWLtkg281f1NkGEDjCt * guide: narrow the module pattern to writes that outlive their page Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0117BoWLtkg281f1NkGEDjCt * guide: frame the module pattern as data belongs with its lifetime Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0117BoWLtkg281f1NkGEDjCt * guide: state is not tied to components, so place it by lifetime Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0117BoWLtkg281f1NkGEDjCt --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent ea67d8c commit 7e5bc81

25 files changed

Lines changed: 804 additions & 50 deletions

File tree

‎compiler/src/check.rs‎

Lines changed: 47 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3117,11 +3117,11 @@ impl<'a> Checker<'a> {
31173117
continue;
31183118
}
31193119
seen.insert(s);
3120-
if attrs.iter().any(|a| a.name == "disabled" && self.depends(&a.e, env, s, &mut HashSet::new())) {
3121-
continue;
3122-
}
3123-
let need_hold = absent && !self.region_reads(region, s, |r| r.provides.contains(HOLD));
3124-
let need_catch = failing && !self.region_reads(region, s, |r| r.catches.is_some());
3120+
// a `disabled` that reads `s` covers the handler; for a failure it must read the value, since
3121+
// `pending? s` of a failed `s` is false and leaves the element enabled
3122+
let disabled_by = |probes: bool| attrs.iter().any(|a| a.name == "disabled" && self.depends_in(&a.e, env, s, &mut HashSet::new(), probes));
3123+
let need_hold = absent && !disabled_by(true) && !self.region_reads(region, s, |r| r.provides.contains(HOLD));
3124+
let need_catch = failing && !disabled_by(false) && !self.region_reads_in(region, s, |r| r.catches.is_some(), false);
31253125
if !need_hold && !need_catch {
31263126
continue;
31273127
}
@@ -3479,18 +3479,24 @@ impl<'a> Checker<'a> {
34793479
}
34803480
/// R-8: `e` reads `s`, directly or through the equations it reads.
34813481
fn depends(&self, e: &Expr, env: EId, s: SId, busy: &mut HashSet<SId>) -> bool {
3482+
self.depends_in(e, env, s, busy, true)
3483+
}
3484+
/// `probes: false`: only reads of `s`'s value count, not of its verdict (`pending? s`), which takes no failure
3485+
/// (R-8, ruled 2026-11-13).
3486+
fn depends_in(&self, e: &Expr, env: EId, s: SId, busy: &mut HashSet<SId>, probes: bool) -> bool {
34823487
let mut stack = vec![Node::E(e)];
34833488
while let Some(n) = stack.pop() {
34843489
if let Node::E(x) = n {
34853490
match &x.k {
34863491
ExprKind::Fn { .. } | ExprKind::ServerFn { .. } => continue,
3492+
ExprKind::Pending(_) if !probes => continue,
34873493
ExprKind::Id(name) => {
34883494
if let Some(t) = self.lookup(env, name) {
34893495
if t == s {
34903496
return true;
34913497
}
34923498
if let Some((te, tenv)) = self.syms[t].expr {
3493-
if busy.insert(t) && self.depends(te, tenv, s, busy) {
3499+
if busy.insert(t) && self.depends_in(te, tenv, s, busy, probes) {
34943500
return true;
34953501
}
34963502
}
@@ -3506,11 +3512,16 @@ impl<'a> Checker<'a> {
35063512
}
35073513
/// R-8: some region around `r` that is `kind` has a reader of `s` in it.
35083514
fn region_reads(&self, r: RId, s: SId, kind: impl Fn(&Region) -> bool) -> bool {
3515+
self.region_reads_in(r, s, kind, true)
3516+
}
3517+
/// `probes`: whether a read under `pending?` counts. For the failure half it does not: the region catches only
3518+
/// what its content reads (ruled 2026-11-13, found by the desk9 reference's fuzz seed 11).
3519+
fn region_reads_in(&self, r: RId, s: SId, kind: impl Fn(&Region) -> bool, probes: bool) -> bool {
35093520
let mut cur = Some(r);
35103521
while let Some(c) = cur {
35113522
if kind(&self.regions[c]) {
35123523
for rd in &self.readers {
3513-
if self.inside(rd.region, c) && self.depends(rd.e, rd.env, s, &mut HashSet::new()) {
3524+
if self.inside(rd.region, c) && self.depends_in(rd.e, rd.env, s, &mut HashSet::new(), probes) {
35143525
return true;
35153526
}
35163527
}
@@ -4342,6 +4353,35 @@ mod tests {
43424353
check_modules(&set, spa).diags.iter().map(|d| (d.line, d.code.clone())).collect()
43434354
}
43444355

4356+
/// 04 R-8 (ruled 2026-11-13): an `errored` region covers a handler's read of a failing value only when its content
4357+
/// reads the value; `pending? x` takes no failure (the desk9 reference's fuzz seed 11).
4358+
#[test]
4359+
fn errored_region_covers_only_a_value_read() {
4360+
let src = r#"export default component App() {
4361+
source id := 1
4362+
labels = await fetch("labels:" + id)
4363+
errored fallback(e) { <p>failed</p> } {
4364+
loading fallback { <p>loading</p> } {
4365+
<button disabled={pending? labels} onClick={() => { log(labels.length) }}>probe</button>
4366+
}
4367+
}
4368+
errored fallback(e) { <p>failed</p> } {
4369+
loading fallback { <p>loading</p> } {
4370+
<p>{labels.length}</p>
4371+
<button disabled={pending? labels} onClick={() => { log(labels.length) }}>read</button>
4372+
}
4373+
}
4374+
loading fallback { <p>loading</p> } {
4375+
<button disabled={labels.length > 9} onClick={() => { log(labels.length) }}>disabled</button>
4376+
}
4377+
}
4378+
"#;
4379+
let got: Vec<i64> = codes(src, false).iter().filter(|(_, c)| c == "UNGUARDED_SNAPSHOT").map(|(l, _)| *l).collect();
4380+
// `probe`: its region reads only `pending? labels`, so a failure leaves it live; `read` sits beside a value
4381+
// read; `disabled` reads the value, so a failure disables it
4382+
assert_eq!(got, vec![6], "{:?}", codes(src, false));
4383+
}
4384+
43454385
/// 06 AC-3a: a guess a click can make while its value loads a new question, unless the element is covered.
43464386
#[test]
43474387
fn guess_while_loading() {

‎eval/reference/chain1/rx/labels.rx‎

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,16 @@ export component Labels(props: { id: number }) {
5555
<input data-testid="label-input" value={labelInput} onInput={e => { labelInput := e.target.value }} />
5656
{loading on(props.id) fallback { <button data-testid="add-label" disabled>add label</button> } {
5757
{errored fallback(e) { <button data-testid="add-label" disabled>add label</button> } {
58-
<button data-testid="add-label" disabled={pending? shown} onClick={() => {
59-
if (labelInput != "" && !shown.includes(labelInput)) {
60-
let label = labelInput
61-
onFlush(() => { labelInput := "" })
62-
add(props.id, label)
63-
}
64-
}}>add label</button>
58+
// the button reads what it guards: `shown` failing puts this region on its fallback, never under a live click
59+
{for have in [shown] {
60+
<button data-testid="add-label" disabled={pending? shown} onClick={() => {
61+
if (labelInput != "" && !have.includes(labelInput)) {
62+
let label = labelInput
63+
onFlush(() => { labelInput := "" })
64+
add(props.id, label)
65+
}
66+
}}>add label</button>
67+
}}
6568
}}
6669
}}
6770
{if labelError != "" {

‎eval/reference/chain2/rx/labels.rx‎

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,16 @@ export component Labels(props: { id: number }) {
5555
<input data-testid="label-input" value={labelInput} onInput={e => { labelInput := e.target.value }} />
5656
{loading on(props.id) fallback { <button data-testid="add-label" disabled>add label</button> } {
5757
{errored fallback(e) { <button data-testid="add-label" disabled>add label</button> } {
58-
<button data-testid="add-label" disabled={pending? shown} onClick={() => {
59-
if (labelInput != "" && !shown.includes(labelInput)) {
60-
let label = labelInput
61-
onFlush(() => { labelInput := "" })
62-
add(props.id, label)
63-
}
64-
}}>add label</button>
58+
// the button reads what it guards: `shown` failing puts this region on its fallback, never under a live click
59+
{for have in [shown] {
60+
<button data-testid="add-label" disabled={pending? shown} onClick={() => {
61+
if (labelInput != "" && !have.includes(labelInput)) {
62+
let label = labelInput
63+
onFlush(() => { labelInput := "" })
64+
add(props.id, label)
65+
}
66+
}}>add label</button>
67+
}}
6568
}}
6669
}}
6770
{if labelError != "" {

‎eval/reference/chain3/rx/labels.rx‎

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,16 @@ export component Labels(props: { id: number }) {
5555
<input data-testid="label-input" value={labelInput} onInput={e => { labelInput := e.target.value }} />
5656
{loading on(props.id) fallback { <button data-testid="add-label" disabled>add label</button> } {
5757
{errored fallback(e) { <button data-testid="add-label" disabled>add label</button> } {
58-
<button data-testid="add-label" disabled={pending? shown} onClick={() => {
59-
if (labelInput != "" && !shown.includes(labelInput)) {
60-
let label = labelInput
61-
onFlush(() => { labelInput := "" })
62-
add(props.id, label)
63-
}
64-
}}>add label</button>
58+
// the button reads what it guards: `shown` failing puts this region on its fallback, never under a live click
59+
{for have in [shown] {
60+
<button data-testid="add-label" disabled={pending? shown} onClick={() => {
61+
if (labelInput != "" && !have.includes(labelInput)) {
62+
let label = labelInput
63+
onFlush(() => { labelInput := "" })
64+
add(props.id, label)
65+
}
66+
}}>add label</button>
67+
}}
6568
}}
6669
}}
6770
{if labelError != "" {

‎eval/reference/chain4/rx/labels.rx‎

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,16 @@ export component Labels(props: { id: number }) {
5555
<input data-testid="label-input" value={labelInput} onInput={e => { labelInput := e.target.value }} />
5656
{loading on(props.id) fallback { <button data-testid="add-label" disabled>add label</button> } {
5757
{errored fallback(e) { <button data-testid="add-label" disabled>add label</button> } {
58-
<button data-testid="add-label" disabled={pending? shown} onClick={() => {
59-
if (labelInput != "" && !shown.includes(labelInput)) {
60-
let label = labelInput
61-
onFlush(() => { labelInput := "" })
62-
add(props.id, label)
63-
}
64-
}}>add label</button>
58+
// the button reads what it guards: `shown` failing puts this region on its fallback, never under a live click
59+
{for have in [shown] {
60+
<button data-testid="add-label" disabled={pending? shown} onClick={() => {
61+
if (labelInput != "" && !have.includes(labelInput)) {
62+
let label = labelInput
63+
onFlush(() => { labelInput := "" })
64+
add(props.id, label)
65+
}
66+
}}>add label</button>
67+
}}
6568
}}
6669
}}
6770
{if labelError != "" {
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
// The selected issue's comments, and posting one. Posts in flight live in their own source, so changing the
2+
// selection never waits for them, and each shows only under its own issue.
3+
4+
import pure { fetchComments } from "./api"
5+
import { addComment } from "./api"
6+
7+
export component Comments(props: { id: number; user: string }) {
8+
source comments = await fetchComments(props.id)
9+
source sending: { id: number; author: string; text: string }[] = []
10+
shownSending = sending.filter(s => s.id == props.id)
11+
source postError: string | null := null
12+
source commentInput: string := ""
13+
14+
// a post error belongs to the issue it was made on: selecting another clears it
15+
effect (props.id) { postError := null }
16+
17+
action postComment(id: number, author: string, text: string) {
18+
onFlush(() => { postError := null })
19+
try {
20+
guess sending := [...sending, { id: id, author: author, text: text }]
21+
await addComment(id, author, text)
22+
refresh comments
23+
} catch (e) {
24+
postError := e.message
25+
}
26+
}
27+
28+
<div>
29+
<div data-testid="comments">
30+
{loading on(props.id) fallback { <p>loading comments</p> } {
31+
{errored fallback(e) { <p>comments error: {e.message}</p> } {
32+
<ul>
33+
{for c in comments {
34+
<li data-testid="comment">{c.author}: {c.text}</li>
35+
}}
36+
{for s in shownSending {
37+
<li data-testid="comment">{s.author}: {s.text} (sending…)</li>
38+
}}
39+
</ul>
40+
}}
41+
}}
42+
</div>
43+
<input data-testid="comment-input" value={commentInput} onInput={e => { commentInput := e.target.value }} />
44+
<button data-testid="post" onClick={() => {
45+
if (commentInput != "") {
46+
let text = commentInput
47+
onFlush(() => { commentInput := "" })
48+
postComment(props.id, props.user, text)
49+
}
50+
}}>post</button>
51+
{if postError != null {
52+
<p>post error: {postError}</p>
53+
}}
54+
</div>
55+
}

‎eval/reference/desk9/rx/desk.rx‎

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
// The issues the desk shows, and every write on them. This is app state, not the issues page's: a write the user
2+
// made outlives the page it was made on, so its refresh reaches the list and detail on screen when it lands, even
3+
// after the page was left and opened again.
4+
//
5+
// Three layers (guide/async.md): `issues` and `detail` are the server's answers; `renames`, `assigns` and `closing`
6+
// hold the writes still out, as guesses; `rows` and `heading` lay those writes over whatever the answers are. A row
7+
// that arrives from a reload while a write on it is out shows the write too, and the list row and the detail heading
8+
// read one rename, so they cannot disagree.
9+
10+
import pure { fetchIssues, fetchIssue } from "./api"
11+
import { assign, renameIssue, closeIssue } from "./api"
12+
13+
export error NotFound(id: number) => `issue #${id} not found`
14+
15+
fn found(it, id: number) => it == null ? throw NotFound(id) : it
16+
17+
type Rename = { id: number; title: string }
18+
type Assign = { id: number; who: string }
19+
20+
fn titleOf(rs: Rename[], id: number, title: string): string => rs.reduce((t, r) => r.id == id ? r.title : t, title)
21+
fn assigneeOf(xs: Assign[], id: number, who: string | null): string | null => xs.reduce((w, x) => x.id == id ? x.who : w, who)
22+
23+
// opening the issues page starts it as the app starts: a new visit asks for the list again
24+
export source visit: number := 0
25+
export source filter: string := "open"
26+
export source selected: number | null := null
27+
28+
issues key id = visit >= 0 ? await fetchIssues(filter) : []
29+
export detail = selected == null ? null : found(await fetchIssue(selected), selected)
30+
31+
// the writes still out: each is a guess its action makes. An accepted write ends with the list's re-ask, and its
32+
// guess stays until that answer lands (D-34); a declined one reverts with its message, in one frame (AC-7)
33+
source renames: Rename[] = []
34+
source assigns: Assign[] = []
35+
source closing: number[] = []
36+
37+
shown = issues.filter(r => !(filter == "open" && closing.includes(r.id)))
38+
export rows key id = shown.map(r => ({ id: r.id, title: titleOf(renames, r.id, r.title), assignee: assigneeOf(assigns, r.id, r.assignee) }))
39+
export heading = detail == null ? "" : titleOf(renames, detail.id, detail.title)
40+
41+
export source assignError: string := ""
42+
export source renameError: string := ""
43+
export source closeError: string := ""
44+
// the newest row action's failure; row actions and the detail's leave each other's errors alone
45+
export source rowError: string := ""
46+
47+
export action openPage() {
48+
visit := visit + 1
49+
filter := "open"
50+
selected := null
51+
onFlush(() => {
52+
assignError := ""
53+
renameError := ""
54+
closeError := ""
55+
rowError := ""
56+
})
57+
}
58+
59+
export action showFilter(f: string) {
60+
filter := f
61+
}
62+
63+
export action select(id: number) {
64+
selected := id
65+
onFlush(() => {
66+
assignError := ""
67+
renameError := ""
68+
closeError := ""
69+
})
70+
}
71+
72+
export action assignTo(id: number, who: string, fromRow: boolean) {
73+
if (fromRow) {
74+
onFlush(() => { rowError := "" })
75+
} else {
76+
onFlush(() => { assignError := "" })
77+
}
78+
try {
79+
guess assigns := xs => [...xs, { id: id, who: who }]
80+
await assign(id, who)
81+
refresh issues
82+
} catch (e) {
83+
if (fromRow) {
84+
rowError := e.message
85+
} else {
86+
assignError := e.message
87+
}
88+
}
89+
}
90+
91+
export action renameTo(id: number, title: string) {
92+
onFlush(() => { renameError := "" })
93+
try {
94+
guess renames := rs => [...rs, { id: id, title: title }]
95+
await renameIssue(id, title)
96+
refresh issues
97+
refresh detail
98+
} catch (e) {
99+
renameError := e.message
100+
}
101+
}
102+
103+
export action closeOne(id: number, fromRow: boolean) {
104+
if (fromRow) {
105+
onFlush(() => { rowError := "" })
106+
} else {
107+
onFlush(() => { closeError := "" })
108+
}
109+
try {
110+
guess closing := cs => [...cs, id]
111+
await closeIssue(id)
112+
refresh issues
113+
} catch (e) {
114+
if (fromRow) {
115+
rowError := e.message
116+
} else {
117+
closeError := e.message
118+
}
119+
}
120+
}

0 commit comments

Comments
 (0)