Repository navigation
Commit 2e5f0f9
authored
✨ Let a value body select its <Return> wherever its own flow reaches (#646)
* ✨ Let a value body select its <Return> wherever its own flow reaches
A value root and a Markdown value component could only produce a value from a
direct top-level `<Return>`, so "return this only if a condition holds" was
inexpressible: the structural preflight rejected a nested return before any
body effect ran, and the runtime diagnostic for a body that produced none was
unreachable for a plain value root.
A value body now owns an ephemeral return state for one execution of itself,
with `<Break>`'s ownership rules exactly. `<If>`, `<Loop>`, `<Each>` and `<Let>`
keep it, because a return written under them is written in the body the author
could see. A component invocation hides it from the invoked body, so a
component's own `<Return>` satisfies its own declaration; a nested value body
installs a separate one; and content the caller projected restores the caller's,
every projection of one authored element restoring the same state. Dynamically
scanned Markdown and a foreign body receive none, so a `<Return>` there stays
reserved and never resolves a component named `Return`.
The first executed return claims the body synchronously, before evaluating its
expression, so two returns racing through one body cannot both believe they were
first. A second execution fails the body, evaluates nothing, and the first value
is not published — there is no first-wins or last-wins fallback. A body that
executes none reports the existing missing-return diagnostic, which is now
reachable and is how a bounded search that found nothing reports itself.
Preflight still runs before any body effect and still refuses a value body with
no authored return, a return in a text body, `<Output>` in a value body, every
malformed return, a missing `as`, and caller content offered to satisfy a
callee's declaration. It no longer refuses one for being nested or for being one
of several: two authored declarations are valid structure, so a second executed
return is a runtime failure and effects preceding it may already have run. That
timing change is the accepted consequence.
`<Return>` still does not end the body. A return inside a loop needs its own
`<Break />`.
Architecture gains `definition-owned return state`; spec §5.4 and §6.10 state
the same contract; Tier RV10/RV11 are rewritten and RV14 restated.
Refs #640
* ✅ Prove the return frame's timing, ownership, precedence and replay
The mechanics were implemented; six criteria of the frozen matrix had no
discriminating test. They do now, and one of them found a stale contract.
- RV10c starts two projections of one authored `<Return>` before awaiting
either, and holds the body to one claim and one evaluation. Moving the claim
after evaluation makes it report two.
- RV10d's second expression names a binding that does not exist, so evaluating
it at all would report something louder than the duplicate diagnostic. A CLI
value root proves exit 1, empty stdout, the exact root diagnostic, and no
trace of that second expression.
- RV11b projects a caller's `<Return>` through a function component's
`content()`, beside the Markdown `<Content />` case.
- RV11c runs `render()` inside a value component, so the generated `<Return>`
sits beneath an active frame and is still reserved — refused on its own terms
rather than for want of an owner.
- RV12 adds a teardown failure after selection, and a halt taken after
selection while a later component is suspended: teardown completes and no
value is published.
- RV17a interrupts after a completed effect and a selection, resumes the same
journal, and proves the effect is not performed again, the selection is
reconstructed, the value matches, and no return event was added. The journal
is asserted non-empty so that absence is a real absence.
The misplaced-return diagnostic said a `<Return>` "must be a direct top-level
child", which this change made untrue. It now says the element is not written in
the flow of a body that declares `returns`, and names the two things that can
never declare one.
Tier RV had two rows numbered RV14. Every identifier is now unique: RV10c and
RV17a are added, RV11b and RV11c are broadened, RV12 records the precedence
cases, and nested value bodies fold into RV14.
Refs #640
* 🔐 Take selection out of the document's reach
`ActiveReturn` is a named context, and a named context is reachable by name from
a document's own eval block: `createContext("expand.return")` names the slot the
engine publishes on. The frame it carried was a plain mutable object, so a
document could write a value onto it and publish something the engine never
validated:
---
returns: { type: number }
---
```js eval
import { createContext } from "effection";
const frame = yield* createContext("expand.return").get();
frame.selected = { value: "schema-bypassed" };
```
<If condition={false}><Return value={1} /></If>
That printed "schema-bypassed" and exited 0 — a string through a number schema,
from a document whose only authored return was unselected.
What travels contextually is now a frozen carrier holding no facts, only an
accessor that answers nothing without a `Symbol()` this module never exports.
The owner, schema, claim and selected value live in that carrier's closure, so
the state's lifetime is one execution of one body rather than a table's, and a
document that reads, enumerates, calls, copies or replaces the carrier reaches
none of it. A carrier the engine did not mint cannot supply the token, and state
it fabricates lacks the mark the engine puts on its own — so a `<Return>` that
finds one is reserved instead of selecting through it. Both settlement sites
read the carrier their own body minted and has held since, never one read back
from the context.
RV10e covers both consumers: the value-root exploit exits 1 with empty stdout
and the existing missing-return diagnostic, and the same attack inside a
Markdown value component with an unselected authored return reports that
component's own missing-return diagnostic and binds nothing. Restoring state to
the carrier makes both fail and the exploit publish again.
No suppression: the first attempt kept the state in a module-scoped WeakMap,
which `local/no-module-scoped-registry` reports. The closure carries the same
guarantee with the lifetime the rule asks for.
Refs #640
* 🔐 Hand a value body down the call stack, where a document cannot reach it
The named-context attack was fixed by sealing the carrier, but the capability
was still exported: an eval block's imports are hoisted and resolved like any
module's, so a document could import `claimReturn` and `selectReturnValue` from
this package's own source by file URL, read the real carrier out of
`createContext("expand.return")`, and call the engine's helpers with the
engine's carrier. A value root declaring `returns: { type: number }` published
"schema-bypassed" at exit 0 without executing its authored <Return>.
Sealing the carrier harder cannot fix that, because the two capabilities compose:
anything published contextually is readable, and any exported function acting on
what was published is callable. So selection now uses neither. A `ReturnBody` is
a plain object whose claim, selection and settlement are closures over state
nothing else holds, and it reaches the `<Return>` that claims it as an ordinary
parameter of expansion — down the call stack, which document code cannot read or
replace.
Ownership is unchanged and now explicit at every site rather than ambient: a
component invocation passes none, caller projection passes the caller's,
dynamically scanned markdown and generated fragments pass none, and the two
owners settle from the object their own expansion created and held as a local.
`ActiveReturn` is gone; nothing exported takes another body's.
RV10e gains the direct-import case: a document imports this module by file URL,
uses every export it still has, and reaches for the old context. The run fails
with the existing missing-return diagnostic, publishes nothing, and the
schema-invalid string never reaches the caller.
Refs #640
* 📄 Say that ownership travels down the call stack, not through a context
The §6.10 paragraph and the Tier RV10e row still described the sealed-carrier
design the previous commit replaced.
* 📄 Describe the return boundary the engine actually has
The glossary row and the "Definition-owned return state" section still described
the frozen carrier in a named context — the design the direct-import attack
retired two commits ago. Both now say what the code does: ownership travels down
the expansion call stack as a local, no exported function accepts another body's,
and importing the module that defines one gets a document a body of its own,
connected to no execution.
The rejected shape stays in the text as the reason: a sealed carrier in a
context plus an exported `claim(carrier)` is forgeable however carefully the
carrier is sealed, because the document calls the engine's own helper with the
engine's own carrier. Without that sentence this reads like an odd way to pass a
parameter, and the simplification back to a context is an easy one to make twice.
Documentation only. No runtime behavior changed.
Refs #640
---------
Co-authored-by: Taras Mankovski <[email protected]>1 parent ad1c8d3 commit 2e5f0f9
9 files changed
Lines changed: 1099 additions & 94 deletions
File tree
- packages
- cli/tests
- core
- src
- tests
- specs
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
108 | 108 | | |
109 | 109 | | |
110 | 110 | | |
| 111 | + | |
111 | 112 | | |
112 | 113 | | |
113 | 114 | | |
| |||
2352 | 2353 | | |
2353 | 2354 | | |
2354 | 2355 | | |
| 2356 | + | |
| 2357 | + | |
| 2358 | + | |
| 2359 | + | |
| 2360 | + | |
| 2361 | + | |
| 2362 | + | |
| 2363 | + | |
| 2364 | + | |
| 2365 | + | |
| 2366 | + | |
| 2367 | + | |
| 2368 | + | |
| 2369 | + | |
| 2370 | + | |
| 2371 | + | |
| 2372 | + | |
| 2373 | + | |
| 2374 | + | |
| 2375 | + | |
| 2376 | + | |
| 2377 | + | |
| 2378 | + | |
| 2379 | + | |
| 2380 | + | |
| 2381 | + | |
| 2382 | + | |
| 2383 | + | |
| 2384 | + | |
| 2385 | + | |
| 2386 | + | |
| 2387 | + | |
| 2388 | + | |
| 2389 | + | |
| 2390 | + | |
| 2391 | + | |
| 2392 | + | |
| 2393 | + | |
| 2394 | + | |
| 2395 | + | |
| 2396 | + | |
| 2397 | + | |
| 2398 | + | |
| 2399 | + | |
| 2400 | + | |
| 2401 | + | |
| 2402 | + | |
| 2403 | + | |
| 2404 | + | |
| 2405 | + | |
| 2406 | + | |
| 2407 | + | |
| 2408 | + | |
2355 | 2409 | | |
2356 | 2410 | | |
2357 | 2411 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
77 | 77 | | |
78 | 78 | | |
79 | 79 | | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
80 | 158 | | |
81 | 159 | | |
82 | 160 | | |
| |||
164 | 242 | | |
165 | 243 | | |
166 | 244 | | |
167 | | - | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
168 | 293 | | |
169 | 294 | | |
170 | 295 | | |
| |||
201 | 326 | | |
202 | 327 | | |
203 | 328 | | |
204 | | - | |
| 329 | + | |
205 | 330 | | |
206 | 331 | | |
207 | 332 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
79 | 79 | | |
80 | 80 | | |
81 | 81 | | |
82 | | - | |
83 | | - | |
84 | 82 | | |
85 | 83 | | |
86 | 84 | | |
| 85 | + | |
87 | 86 | | |
88 | 87 | | |
89 | 88 | | |
| |||
1594 | 1593 | | |
1595 | 1594 | | |
1596 | 1595 | | |
1597 | | - | |
| 1596 | + | |
| 1597 | + | |
| 1598 | + | |
| 1599 | + | |
| 1600 | + | |
1598 | 1601 | | |
1599 | 1602 | | |
1600 | 1603 | | |
| |||
1607 | 1610 | | |
1608 | 1611 | | |
1609 | 1612 | | |
1610 | | - | |
1611 | | - | |
1612 | | - | |
1613 | | - | |
1614 | 1613 | | |
1615 | 1614 | | |
1616 | 1615 | | |
| |||
1622 | 1621 | | |
1623 | 1622 | | |
1624 | 1623 | | |
| 1624 | + | |
1625 | 1625 | | |
1626 | 1626 | | |
1627 | 1627 | | |
| |||
1634 | 1634 | | |
1635 | 1635 | | |
1636 | 1636 | | |
1637 | | - | |
1638 | | - | |
| 1637 | + | |
| 1638 | + | |
| 1639 | + | |
| 1640 | + | |
1639 | 1641 | | |
1640 | | - | |
| 1642 | + | |
1641 | 1643 | | |
1642 | 1644 | | |
1643 | 1645 | | |
| |||
1774 | 1776 | | |
1775 | 1777 | | |
1776 | 1778 | | |
| 1779 | + | |
1777 | 1780 | | |
1778 | 1781 | | |
1779 | 1782 | | |
| |||
1800 | 1803 | | |
1801 | 1804 | | |
1802 | 1805 | | |
| 1806 | + | |
1803 | 1807 | | |
1804 | 1808 | | |
1805 | 1809 | | |
| |||
0 commit comments