Skip to content

Commit 0adcdad

Browse files
authored
Merge pull request #26 from ryansolid/claude/project-thread-u432or
Writes only through the owner's name (O-4); withdraw source contexts (RG-7c)
2 parents 5b9f3e2 + 3ef156a commit 0adcdad

21 files changed

Lines changed: 138 additions & 151 deletions

File tree

‎compiler/src/check.rs‎

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,8 @@ struct Sym<'a> {
211211
line: i64,
212212
question: bool,
213213
io: bool,
214+
/// a fn's parameter: never a write target (O-4)
215+
param: bool,
214216
instantiating: bool,
215217
params: Option<Vec<SigParam>>,
216218
captures: Vec<SId>,
@@ -244,6 +246,7 @@ impl<'a> Sym<'a> {
244246
line,
245247
question: false,
246248
io: false,
249+
param: false,
247250
instantiating: false,
248251
params: None,
249252
captures: vec![],
@@ -1105,8 +1108,8 @@ impl<'a> Checker<'a> {
11051108
self.err("DUPLICATE_DECLARATION", "E-7", format!("{} is declared twice in one block", name));
11061109
}
11071110
let contract = if ty.as_ref().is_some_and(|t| ROW_WORDS.is_match(t)) || *exported { Some(contract_of(ty.as_deref())) } else { None };
1108-
if *source && dflt.is_some() {
1109-
self.err("INVALID_CONTEXT_DEFAULT", "RG-7c", format!("context {}: source … has no default — a provided source is its provider's; a default would be one source every user writes (declare that source instead)", name));
1111+
if *source {
1112+
self.err("SOURCE_CONTEXT", "O-4", format!("context {}: source … is withdrawn (RG-7c, 2026-10-31): what is provided is read beneath it — provide the writes you allow, as actions (`context {}: {{ current: T; set: (v: T) => void }}`)", name, name));
11101113
}
11111114
let suffix = if self.regions[region].parent.is_some() {
11121115
let n = self.seq;
@@ -1694,12 +1697,6 @@ impl<'a> Checker<'a> {
16941697
let region = self.reg(env);
16951698
self.regions[region].provides.insert(info.key.clone());
16961699
self.provisions.push(Provision { key: info.key.clone(), e, env });
1697-
if info.source {
1698-
let t = if let ExprKind::Id(n) = &e.k { self.lookup(env, n) } else { None };
1699-
if t.is_none_or(|t| self.syms[t].kind != SymKind::Source || self.syms[t].imported.is_some()) {
1700-
self.err("PROVIDE_NOT_A_SOURCE", "RG-7c", format!("context {} carries a source: provide one of this module's sources by name (`provide {} = x`)", name, name));
1701-
}
1702-
}
17031700
if let Some(contract) = info.contract {
17041701
let line = self.line;
17051702
self.later.push(Later::Provide { name: name.clone(), e, env, line, contract });
@@ -1753,9 +1750,13 @@ impl<'a> Checker<'a> {
17531750
let inner = self.env(Some(env), r);
17541751
for p in params {
17551752
if p.r#ref {
1756-
self.bind(inner, &p.name, Sym::new(SymKind::Eq, &p.name, r, *line as i64));
1753+
let mut s = Sym::new(SymKind::Eq, &p.name, r, *line as i64);
1754+
s.param = true;
1755+
self.bind(inner, &p.name, s);
17571756
} else {
1758-
let s = self.new_sym(Sym::new(SymKind::Value, &p.name, r, *line as i64));
1757+
let mut s = Sym::new(SymKind::Value, &p.name, r, *line as i64);
1758+
s.param = true;
1759+
let s = self.new_sym(s);
17591760
self.envs[inner].vars.insert(p.name.clone(), s);
17601761
}
17611762
}
@@ -2323,11 +2324,7 @@ impl<'a> Checker<'a> {
23232324
let info = self.syms[c].ctx.clone().unwrap();
23242325
self.uses.push(UseRec { region, name: info.key.clone(), line: self.line, display: target.name.clone() });
23252326
if !info.source {
2326-
self.err(
2327-
"WRITE_TO_NON_SOURCE",
2328-
"RG-7c",
2329-
format!("context {} is not declared `source`: what is provided is read-only (`context {}: source T` to write through it)", target.name, target.name),
2330-
);
2327+
self.err("WRITE_TO_NON_SOURCE", "O-4", format!("context {} is read beneath its provision: call an action it provides that writes it (O-4)", target.name));
23312328
}
23322329
}
23332330
} else {
@@ -2341,7 +2338,8 @@ impl<'a> Checker<'a> {
23412338
SymKind::Props => "props".to_string(),
23422339
k => format!("a {}", k.as_str()),
23432340
};
2344-
self.err("WRITE_TO_NON_SOURCE", "W-1", format!("{} is {}: only sources are written (W-1)", target.name, what));
2341+
let hint = if k == SymKind::Props || k == SymKind::Value || self.syms[t].param { " — a source is written only in the region that declares it: have its owner pass an action that writes it (O-4)" } else { "" };
2342+
self.err("WRITE_TO_NON_SOURCE", "W-1", format!("{} is {}: only sources are written (W-1){}", target.name, what, hint));
23452343
} else if let Some(imp) = self.syms[t].imported.clone() {
23462344
self.err(
23472345
"WRITE_TO_NON_SOURCE",

‎eval/reference/settings/rx/form.rx‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ export component SettingsForm(props: { initial: Settings }) {
1717
// The failure as a value next to the field: "" when the draft is valid.
1818
nameError: string = (valid && "") catch (e: NameRequired | NameTooLong) => e.message
1919

20-
provide theme = draftTheme
20+
action pickTheme(t) { draftTheme := t } // O-4: the form owns the draft; a picker beneath may only pick
21+
provide theme = { current: draftTheme, pick: pickTheme }
2122
provide density = draftDensity
2223

2324
<div>

‎eval/reference/settings/rx/theme.rx‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
export type Theme = "light" | "dark"
55
export type Density = "comfortable" | "compact"
66

7-
// The theme being edited. It carries a source (RG-7c), so a picker anywhere
8-
// beneath the provider can change it without knowing who owns it.
9-
export context theme: source Theme
7+
// The theme being edited, and the one write its owner allows (O-4): a picker
8+
// anywhere beneath the provider can change it without knowing who owns it.
9+
export context theme: { current: Theme; pick: (t: Theme) => void }
1010

1111
// Layout density. Only some subtrees provide it; everywhere else it is the
1212
// default (RG-7b).

‎eval/reference/settings/rx/ui.rx‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,23 @@ export component Panel(props: { title: string; children: View }) {
1111
</section>
1212
}
1313

14-
// Changes the theme by writing through the context (RG-7c): it does not know,
15-
// or import, who owns the theme.
14+
// Changes the theme through the function the context provides (O-4): it does
15+
// not know, or import, who owns the theme.
1616
export component ThemePicker(props: {}) {
17-
current = use theme
17+
current = (use theme).current
1818
<div>
1919
<span>Theme: {current}</span>{" "}
20-
<button data-testid="theme-light" onClick={() => { use theme := "light" }}>light</button>{" "}
21-
<button data-testid="theme-dark" onClick={() => { use theme := "dark" }}>dark</button>
20+
<button data-testid="theme-light" onClick={() => { (use theme).pick("light") }}>light</button>{" "}
21+
<button data-testid="theme-dark" onClick={() => { (use theme).pick("dark") }}>dark</button>
2222
</div>
2323
}
2424

2525
// The appearance controls: the picker, whatever extra controls the caller
2626
// passes, and a preview of both contexts.
2727
export component Appearance(props: { children: View }) {
28-
<div class={use theme}>
28+
<div class={(use theme).current}>
2929
<ThemePicker />{" "}
3030
{props.children}{" "}
31-
<p data-testid="preview">Preview: {use theme} / {use density}</p>
31+
<p data-testid="preview">Preview: {(use theme).current} / {use density}</p>
3232
</div>
3333
}

‎examples/ai/feed.rx‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// feed.rx — a chat feed: rooms fetched once, the selected room's messages as a
22
// stream, a compose box whose send is an optimistic action, a typing indicator,
3-
// and a room list that reads / writes the selected room through context.
3+
// and a room list that reads the selected room through context and picks one
4+
// through the function the context provides.
45
// Written from the spec alone (02–08) as a cold test of the language.
56

67
import pure { fetchRooms, streamMessages, sendMessage } from "./api"
@@ -12,8 +13,9 @@ type Message = { id: number; from: string; text: string }
1213

1314
// --- app state (module level: lives for the module's lifetime, 07 §1) ---
1415
source selected: number := 1 // E-4: a plain source
15-
context room: source number // RG-7: a declared context that carries a source (RG-7c)
16-
provide room = selected // the provision *is* the source — `use room := …` writes it
16+
action pick(id) { selected := id } // O-4: the module owns `selected`; this is the one write it allows
17+
context room: { current: number; pick: (id: number) => void } // RG-7: a declared context
18+
provide room = { current: selected, pick: pick } // readers beneath read `current` and call `pick`
1719

1820
rooms: Room[] = await fetchRooms() // R-1: fetched once; pending until it lands (no inputs → never re-asked)
1921
source messages: Message[] = await* streamMessages(selected) -> [] // ST-5 + ST-6b: a stream, first paint `[]` (R-7)
@@ -49,8 +51,8 @@ component RoomList(props: { rooms: Room[] }) {
4951
}
5052

5153
component RoomItem(props: { room: Room }) {
52-
active = (use room) == props.room.id // RG-7b: `use` is an equation over the provision
53-
<li onClick={() => { use room := props.room.id }}>{props.room.name} {active ? "*" : "-"}{" "}</li>
54+
active = (use room).current == props.room.id // RG-7b: `use` is an equation over the provision
55+
<li onClick={() => { (use room).pick(props.room.id) }}>{props.room.name} {active ? "*" : "-"}{" "}</li>
5456
}
5557

5658
component Compose(props: {}) {

‎examples/ai2/settings/NOTES.md‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,3 +120,6 @@ Modules: `theme.rx` (contexts only) ← `settings.rx` (server truth + actions),
120120
| 9 density | high | plain local write, RG-7b |
121121
| 10 save again | medium | H-11 on `saveError` (a constant question); branch closing under a guess (assumption 5) |
122122
| 11 resolve save | medium-high | H-11: an equal truth confirms silently; the plain `saveError := ""` truth |
123+
124+
(2026-10-31: RG-7c is withdrawn. The program now provides `{ current, pick }`, with `pick` an action
125+
the form declares (O-4); the notes above describe the run as it was.)

‎examples/ai2/settings/form.rx‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ export component SettingsForm(props: { initial: Settings }) {
1717
// The failure as a value next to the field: "" when the draft is valid.
1818
nameError: string = (valid && "") catch (e: NameRequired | NameTooLong) => e.message
1919

20-
provide theme = draftTheme
20+
action pickTheme(t) { draftTheme := t } // O-4: the form owns the draft; a picker beneath may only pick
21+
provide theme = { current: draftTheme, pick: pickTheme }
2122
provide density = draftDensity
2223

2324
<div>

‎examples/ai2/settings/theme.rx‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
export type Theme = "light" | "dark"
55
export type Density = "comfortable" | "compact"
66

7-
// The theme being edited. It carries a source (RG-7c), so a picker anywhere
8-
// beneath the provider can change it without knowing who owns it.
9-
export context theme: source Theme
7+
// The theme being edited, and the one write its owner allows (O-4): a picker
8+
// anywhere beneath the provider can change it without knowing who owns it.
9+
export context theme: { current: Theme; pick: (t: Theme) => void }
1010

1111
// Layout density. Only some subtrees provide it; everywhere else it is the
1212
// default (RG-7b).

‎examples/ai2/settings/ui.rx‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,23 @@ export component Panel(props: { title: string; children: View }) {
1111
</section>
1212
}
1313

14-
// Changes the theme by writing through the context (RG-7c): it does not know,
15-
// or import, who owns the theme.
14+
// Changes the theme through the function the context provides (O-4): it does
15+
// not know, or import, who owns the theme.
1616
export component ThemePicker(props: {}) {
17-
current = use theme
17+
current = (use theme).current
1818
<div>
1919
<span>Theme: {current}</span>{" "}
20-
<button onClick={() => { use theme := "light" }}>light</button>{" "}
21-
<button onClick={() => { use theme := "dark" }}>dark</button>
20+
<button onClick={() => { (use theme).pick("light") }}>light</button>{" "}
21+
<button onClick={() => { (use theme).pick("dark") }}>dark</button>
2222
</div>
2323
}
2424

2525
// The appearance controls: the picker, whatever extra controls the caller
2626
// passes, and a preview of both contexts.
2727
export component Appearance(props: { children: View }) {
28-
<div class={use theme}>
28+
<div class={(use theme).current}>
2929
<ThemePicker />{" "}
3030
{props.children}{" "}
31-
<p>Preview: {use theme} / {use density}</p>
31+
<p>Preview: {(use theme).current} / {use density}</p>
3232
</div>
3333
}

‎guide/language.md‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ export default component App() { … } // the entry module's default compo
1414
```
1515

1616
A file's top level is imports, exports and declarations. A `source` at the top level is app state; inside a
17-
component it is that instance's state. Exported sources are read-only to importers: export actions that write them.
17+
component it is that instance's state. Only the block that declares a source writes it: importers, props, function
18+
parameters and contexts are read-only, at every path into a store. To let other code write it, hand it an action that
19+
does (`export action select(id) { selected := id }`, or an action passed as a prop or provided in a context).
1820

1921
## Declarations
2022

@@ -48,7 +50,7 @@ values. Arrays and strings have their usual methods: `xs.filter(f)`, `xs.map(f)`
4850
| `peek(x)` | `x` read once, without depending on it |
4951
| `e catch (err) => alt` | `alt` when `e` fails |
5052
| `c ? a : throw NotFound(id)` | a failure as a value of an arm |
51-
| `use name` / `provide name = e` | context: the nearest provision above |
53+
| `use name` / `provide name = e` | context: the nearest provision above, read-only (provide actions to let readers write) |
5254

5355
## Markup
5456

0 commit comments

Comments
 (0)