Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 20 additions & 7 deletions compiler/src/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

use crate::ast::*;
use crate::content::{misnested, misnested_inside, Shape, P_CLOSERS, P_SCOPE};
use crate::infer::{inferred_action, run_findings, scalar_type, trigger_text, Code, RunOpts};
use crate::infer::{action_waits, inferred_action, run_findings, scalar_type, trigger_text, Code, RunOpts};
use crate::model::{ModelBuilder, ModelSymbol};
use crate::modules::ModuleSet;
use crate::parse::{js_trim, JsDecl, Part, Shape as FShape};
Expand Down Expand Up @@ -245,6 +245,8 @@ struct Sym<'a> {
reader: bool,
/// an action declared here: how many arguments a call passes (AC-1f)
arity: Option<usize>,
/// an action declared here: whether its change can outlast the call (an `await`, `refresh`, `affects`; AC-1h)
waits: Option<bool>,
/// RG-4b: the props of `component C()`, which declares none — C's name: reading them is UNBOUND
no_props: Option<String>,
}
Expand Down Expand Up @@ -283,6 +285,7 @@ impl<'a> Sym<'a> {
foreign: None,
reader: false,
arity: None,
waits: None,
no_props: None,
}
}
Expand Down Expand Up @@ -1216,9 +1219,10 @@ impl<'a> Checker<'a> {
match d {
Decl::Server { params, .. } => sym.params = Some(params.iter().map(|n| SigParam { name: n.clone(), r#ref: false, ty: None }).collect()),
Decl::Source { question, .. } => sym.question = *question,
Decl::Action { params, .. } => {
Decl::Action { params, body, .. } => {
sym.io = true; // R-io-2: an action is io
sym.arity = Some(params.len()); // AC-1f: its parameters
sym.waits = Some(action_waits(body)); // AC-1h
}
Decl::Fn { params, decls: fdecls, .. } => {
sym.params = Some(params.iter().map(|p| SigParam { name: p.name.clone(), r#ref: p.r#ref, ty: p.ty.clone() }).collect());
Expand Down Expand Up @@ -1848,7 +1852,7 @@ impl<'a> Checker<'a> {
self.comp("action", env, Some(name.clone()), None, |c| c.stmts(body, inner, Ctx { in_action: true, ..Ctx::imperative() }));
self.actions.push(ActionRec { name: name.clone(), body, env: inner, line: *line as i64 });
let ptypes: Vec<Option<String>> = ptypes.iter().map(|t| t.as_ref().map(|t| if self.scalar_aliases.contains(t.trim()) { "string".to_string() } else { t.clone() })).collect();
self.run_checks_with(body, true, params, false, ptypes, Some(inner));
self.run_checks_with(body, true, params, false, ptypes, Some(inner), None);
}
Decl::Server { name, params, body, line, .. } => {
let region = self.reg(env);
Expand Down Expand Up @@ -2359,7 +2363,7 @@ impl<'a> Checker<'a> {
self.actions.push(ActionRec { name: format!("inferred here (AC-1b: {})", trigger_text(w)), body: ss, env: inner, line: self.line });
}
if !ctx.server {
self.run_checks(ss, why.is_some(), params, why.is_some());
self.run_checks_with(ss, why.is_some(), params, why.is_some(), vec![], None, Some(inner));
}
return;
}
Expand Down Expand Up @@ -2399,13 +2403,15 @@ impl<'a> Checker<'a> {
// ---- imperative scope (SC-2) ----
/// AC-1c, AC-1d, AC-1e over one imperative run (`crate::infer`).
fn run_checks(&mut self, stmts: &[Stmt], action: bool, bound: &[String], inferred: bool) {
self.run_checks_with(stmts, action, bound, inferred, vec![], None);
self.run_checks_with(stmts, action, bound, inferred, vec![], None, None);
}
/// `answers_in`: a declared action's scope, where AC-1g asks which names are sources with a question.
fn run_checks_with(&mut self, stmts: &[Stmt], action: bool, bound: &[String], inferred: bool, ptypes: Vec<Option<String>>, answers_in: Option<EId>) {
/// `actions_in`: an arrow's scope, where AC-1h asks which names are actions whose change can outlast the call.
fn run_checks_with(&mut self, stmts: &[Stmt], action: bool, bound: &[String], inferred: bool, ptypes: Vec<Option<String>>, answers_in: Option<EId>, actions_in: Option<EId>) {
let answered = |n: &str| answers_in.and_then(|env| self.lookup(env, n)).map_or(false, |t| self.syms[t].kind == SymKind::Source && self.syms[t].question);
let stateful = |n: &str| answers_in.and_then(|env| self.lookup(env, n)).map_or(false, |t| self.syms[t].kind == SymKind::Source || self.syms[t].kind == SymKind::Eq);
let found = run_findings(stmts, action, bound, inferred, &RunOpts { ptypes, answered: if answers_in.is_some() { Some(&answered) } else { None }, stateful: if answers_in.is_some() { Some(&stateful) } else { None } });
let is_action = |n: &str| actions_in.and_then(|env| self.lookup(env, n)).map_or(false, |t| self.syms[t].kind == SymKind::Action && self.syms[t].waits != Some(false));
let found = run_findings(stmts, action, bound, inferred, &RunOpts { ptypes, answered: if answers_in.is_some() { Some(&answered) } else { None }, stateful: if answers_in.is_some() { Some(&stateful) } else { None }, is_action: if actions_in.is_some() { Some(&is_action) } else { None } });
for f in found {
let n = &f.name;
match f.code {
Expand All @@ -2415,6 +2421,13 @@ impl<'a> Checker<'a> {
}
Code::HeldWrite => self.err("HELD_WRITE", "AC-1c", format!("{n} := … comes before an `await` in a body that is an action because it writes and awaits (AC-1b), so it is held until the body ends (AC-1): for state that shows while the work runs, `guess {n} := …` (a source with a question, ST-5c); for a reset that lands now, `onFlush(() => {{ {n} := … }})` (EF-8); to hold it on purpose, declare the action (`action name() {{ … }}`); or write it after the `await`")),
Code::StaleOwnRead => self.err("STALE_OWN_READ", "AC-1d", format!("{n} is read after this change wrote it: the read sees the committed value, not the write (W-4) — keep the value you wrote in a local (`let v = …; {n} := v`) and read that, or write functionally (`{n} := v => …`, W-6)")),
Code::StaleNextRead => {
let held = match &f.via {
Some(v) => format!("this run calls {v}, so its writes join that action's change"),
None => "an action holds its writes".into(),
};
self.err("STALE_NEXT_READ", "AC-1h", format!("{n} := … is computed from {n}, and it is held: {held} until the change settles (AC-1). Until then the next run reads the committed {n}, not this write, and computes the same value again (a counter mints one id twice). For the next run to build on the held value while the screen waits, read it with `latest {n}` (R-9), or write functionally (`{n} := v => …`, W-6) when this run doesn't need the value; for the write to show now, give it its own instant, `onFlush(() => {{ {n} := … }})` (EF-8)"))
}
Code::StaleWriteBack => self.err("STALE_WRITE_BACK", "AC-1e", format!("{n} := … after an `await` is computed from {n} as it was read before that `await`: whatever changed {n} in between (another action, a reload) is overwritten — write functionally (`{n} := v => …`, W-6), which applies to {n} as it stands at the write, or guess it (`guess`, AC-3) and let the answer replace the guess")),
}
}
Expand Down
66 changes: 64 additions & 2 deletions compiler/src/infer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ pub enum Code {
StaleOwnRead,
StaleWriteBack,
StaleCapture,
StaleNextRead,
}
pub struct Finding {
pub code: Code,
Expand Down Expand Up @@ -169,6 +170,21 @@ pub struct RunOpts<'o> {
pub answered: Option<&'o dyn Fn(&str) -> bool>,
/// names of sources and equations in scope
pub stateful: Option<&'o dyn Fn(&str) -> bool>,
/// AC-1h: names of actions in scope whose change can outlast the call
pub is_action: Option<&'o dyn Fn(&str) -> bool>,
}

/// AC-1h: whether an action's change can outlast its call — its body (not a closure's) awaits, re-asks, or declares `affects`.
pub fn action_waits(ss: &[Stmt]) -> bool {
ss.iter().any(|s| {
stmt_await(s)
|| matches!(s.k, StmtKind::Refresh(_) | StmtKind::Affects(_))
|| match &s.k {
StmtKind::Sif { t, f, .. } => action_waits(t) || action_waits(f),
StmtKind::Try { body, handler, fin, .. } => action_waits(body) || handler.as_deref().is_some_and(action_waits) || fin.as_deref().is_some_and(action_waits),
_ => false,
}
})
}

/// keys from the source; "*" a computed key
Expand Down Expand Up @@ -232,8 +248,27 @@ struct Walker<'o> {
inferred: bool,
answered: Option<&'o dyn Fn(&str) -> bool>,
stateful: Option<&'o dyn Fn(&str) -> bool>,
is_action: Option<&'o dyn Fn(&str) -> bool>,
/// AC-1h: plain writes computed from their own source in this change, and the action a plain run's stretch calls
next: Vec<String>,
joins: Option<String>,
local_actions: HashSet<String>,
/// AC-1h: sources this change read plainly (a functional write beside one still leaves that read stale)
seen: HashSet<String>,
}
impl<'o> Walker<'o> {
/// AC-1h: a declared action's body before an `await`, or a plain run's stretch that calls an action by name, is held;
/// an inferred action's are HELD_WRITE already.
fn flush_next(&mut self, held: bool) {
let next = std::mem::take(&mut self.next);
let via = self.joins.take();
self.seen.clear();
if held && !self.inferred {
for n in next {
self.report_via(Code::StaleNextRead, n, via.clone());
}
}
}
fn report(&mut self, code: Code, name: String) {
self.report_via(code, name, None);
}
Expand Down Expand Up @@ -266,8 +301,9 @@ impl<'o> Walker<'o> {
};
if let Some(k) = root {
if st.written.get(&k).is_some_and(|ws| ws.iter().any(|w| overlaps(w, &path))) {
self.report(Code::StaleOwnRead, k);
self.report(Code::StaleOwnRead, k.clone());
}
self.seen.insert(k);
return;
}
if !std::ptr::eq(x, e) {
Expand All @@ -278,6 +314,13 @@ impl<'o> Walker<'o> {
ExprKind::Fn { .. } | ExprKind::ServerFn { .. } | ExprKind::Draft { .. } | ExprKind::Pending(_) | ExprKind::Latest(_) | ExprKind::Lit(_) | ExprKind::Pre { .. } | ExprKind::Peek(_) | ExprKind::StyleMap { .. } => {}
ExprKind::Call { f, args } => {
let c = called_closure(x, local);
if !self.action && c.is_none() && self.joins.is_none() {
if let ExprKind::Id(n) = &f.k {
if (!sh.contains(n) && self.is_action.is_some_and(|a| a(n))) || self.local_actions.contains(n) {
self.joins = Some(n.clone());
}
}
}
for a in args {
self.read(a, st, sh, local, depth);
}
Expand Down Expand Up @@ -447,13 +490,24 @@ impl<'o> Walker<'o> {
for h in std::mem::take(&mut st.held) {
self.report(Code::HeldWrite, h);
}
self.flush_next(true);
} else {
st.written.clear();
let held = self.joins.is_some();
self.flush_next(held);
}
}
if let StmtKind::Let { name, .. } = &s.k {
sh.insert(name.clone());
st.taint.insert(name.clone(), d);
match &e.k {
ExprKind::Fn { stmts: Some(ss), .. } if inferred_action(ss).is_some() => {
self.local_actions.insert(name.clone());
}
_ => {
self.local_actions.remove(name);
}
}
match closure_of(s) {
Some(c) => {
local.insert(name.clone(), c);
Expand Down Expand Up @@ -482,7 +536,11 @@ impl<'o> Walker<'o> {
if d.iter().any(|(dk, dp, ep)| *dk == k && *ep < st.epoch && overlaps(dp, &path)) {
self.report(Code::StaleWriteBack, k.clone());
back = true;
} else if d.iter().any(|(dk, dp, ep)| *dk == k && (self.action || *ep == st.epoch) && overlaps(dp, &path)) {
self.next.push(k.clone());
}
} else if matches!(s.k, StmtKind::Write { .. }) && self.seen.contains(&k) {
self.next.push(k.clone()); // AC-1h: a functional write beside a plain read of its source
}
// AC-1g: the answer takes the server's answer, plain arguments and its own value at the write (the closure's
// argument): a row parameter, a local read from any source (before the `await` or after it), or a source
Expand Down Expand Up @@ -551,7 +609,7 @@ impl<'o> Walker<'o> {
/// its awaits (AC-1); a plain run's change ends at each `await`. `inferred`: an action by AC-1b, the only kind HELD_WRITE
/// applies to. `bound`: the run's parameters. Each finding once per name, in source order.
pub fn run_findings(stmts: &[Stmt], action: bool, bound: &[String], inferred: bool, opts: &RunOpts) -> Vec<Finding> {
let mut w = Walker { out: vec![], said: HashSet::new(), action, inferred, answered: opts.answered, stateful: opts.stateful };
let mut w = Walker { out: vec![], said: HashSet::new(), action, inferred, answered: opts.answered, stateful: opts.stateful, is_action: opts.is_action, next: vec![], joins: None, local_actions: HashSet::new(), seen: HashSet::new() };
let sh: IndexSet<String> = bound.iter().cloned().collect();
let mut taint: IndexMap<String, Vec<Dep>> = IndexMap::new();
for (i, p) in bound.iter().enumerate() {
Expand All @@ -562,5 +620,9 @@ pub fn run_findings(stmts: &[Stmt], action: bool, bound: &[String], inferred: bo
}
}
w.walk(stmts, State { written: IndexMap::new(), held: IndexSet::new(), dead: false, taint, epoch: 0 }, &sh, &IndexMap::new(), &[]);
let held = !action && w.joins.is_some(); // a declared action's writes after its last `await` land as it ends
w.flush_next(held);
let held_writes: HashSet<String> = w.out.iter().filter(|f| f.code == Code::HeldWrite).map(|f| f.name.clone()).collect();
w.out.retain(|f| f.code != Code::StaleNextRead || !held_writes.contains(&f.name));
w.out
}
8 changes: 6 additions & 2 deletions eval/harness/fuzz-board.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ async function session(browser, url, seed, steps, log, others = false) {
const moment = () => { const m = JSON.stringify(COLS.map(col => srv.cols[col].map(c => `${c.id}:${c.title}`).sort())); if (moments[moments.length - 1] !== m) moments.push(m); };
moment();
const ui = { page: "board", selected: null, visit: 0 };
const failedCols = new Set(); // B5: columns whose last answer was a failure, until one lands (a retry re-asks, the error still stands)
const writeVisit = new Map(); // write key -> the visit (board or archive) it was made on
const settledCount = new Map();
let lateVisit = false; // B1
Expand Down Expand Up @@ -202,8 +203,10 @@ async function session(browser, url, seed, steps, log, others = false) {
const x = col && b[col].rows.find(y => y.id === target);
if (x) {
// B5 (Ryan, 2026-11-19): the detail finds its card in every column, so while one of them has failed it may show
// its errored fallback (that it can't show the card now) instead; it must still never name a wrong column or title
const failed = (await Promise.all(COLS.map(cl => exists(`retry-${cl}`)))).some(Boolean);
// its errored fallback (that it can't show the card now) instead; it must still never name a wrong column or title.
// Derived from an error is errored (Ryan, 2026-11-24): that holds until the failed column answers again, also while
// its retry is out
const failed = failedCols.size > 0 || (await Promise.all(COLS.map(cl => exists(`retry-${cl}`)))).some(Boolean);
const wrongCol = COLS.some(cl => cl !== col && detail.includes(`in ${NAME[cl]}`));
if (failed ? wrongCol : !detail.includes(`in ${NAME[col]}`)) note("detail column", `#${x.id} shows in ${NAME[col]}, the detail says "${detail.slice(0, 80)}"`);
if (!detail.includes(`#${x.id} ${x.title}`) && (!failed || detail.includes(`#${x.id} `))) note("two views", `card "${x.text}", detail "${detail.slice(0, 80)}"`);
Expand Down Expand Up @@ -250,6 +253,7 @@ async function session(browser, url, seed, steps, log, others = false) {
if (!a.fail && name === "toggleItem") heldTwice.push(key); // B4
writeVisit.delete(key);
trail.push(`${a.fail ? "fail" : "land"} ${key}`);
{ const fc = key.match(/^fetchCards:(\w+)$/)?.[1]; if (fc) { if (a.fail) failedCols.add(fc); else failedCols.delete(fc); } }
await page.evaluate(([k, a]) => a.fail ? globalThis.__flights.fail(k, "declined") : globalThis.__flights.land(k, a.value), [key, a]);
await settle();
}
Expand Down
29 changes: 29 additions & 0 deletions eval/results/rerun-2026-11-23/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# .rx rerun on Solid main 30e7805eb (2026-11-23)

24 new .rx apps: board and desk9, 6 Opus + 6 Haiku each, same scaffold as round 15 (`--brief plain --inline-docs`),
current guide, Solid main 30e7805eb (#5095, #5104, #5146 fixed). Graded with `harness/grade.sh` (`FUZZ_ROUND=--r15`).
Defects = failed hidden + overlap tests + fuzz seeds with a hole, minus tests whose hold probe passes and the
after-left family (`python3 score.py`).

| | round 15 | rerun |
|---|---|---|
| desk9 Opus | 0.00 | 0.33 (2,0,0,0,0,0) |
| desk9 Haiku | 1.50 | 3.50 |
| board Opus | 6.33 | 3.67 (0,14,1,0,0,7) |
| board Haiku | 24.67 | 19.00 |

Round 15 column rescored with the same probes (it was 0, 1.5, 6.33, 25.17).

Probe changes (judgement calls, for Ryan to check):
- `round15/trace/holds9.mjs` re-ask also answers the selected issue's detail; `round15/trace/holds.mjs` `reloads()`
answers columns not named as they first loaded. Apps that re-ask every list after a write held there and settle right.
- `trace/holds-board-reopen.mjs`: "the new-card input starts empty when the board opens again" checked after To do's
re-ask lands. All six Opus apps keep the add input under To do's loading (ruled acceptable 2026-11-12).

Traced:
- board opus-2 (13 seeds): the detail sits in one loading region that reads all three columns, so it says "loading"
until every column has arrived (agent).
- board opus-6 (7 seeds): page NotReadyError = solidjs/solid#5174 (a handler reading a ternary prop while its source
re-asks; `repro/handler-reads-ternary-prop-during-reask.spec.tsx`). Minimal trail: land doing; land todo; left #3;
land move; right #2.
- Haiku's 12 agents each posted one stray chat message (a tool they were told not to use); not part of the task.
Loading
Loading