Skip to content

Commit c6f391c

Browse files
authored
format: guide when to use gather vs flat context composition (#259)
Document when a `gather` context is the right tool and when a flat context object is preferred. The context schema is open: a single object composes any number of disjoint discriminator keys (`code`, `variables`, `invoke`, `return`, and so on) as siblings, and that flat form is preferred. Reserve `gather` for what a flat object cannot express — two or more facts that collide on the same key, such as multiple `frame`s (each with its own `code` range) or multiple `variables` blocks. A `gather` over disjoint keys is equivalent to the flat object and collapses to it.
1 parent 5603954 commit c6f391c

1 file changed

Lines changed: 28 additions & 0 deletions

File tree

‎packages/web/spec/program/context/gather.mdx‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,34 @@ import SchemaViewer from "@site/src/components/SchemaViewer";
66

77
# Gather multiple contexts
88

9+
A `gather` context asserts that every one of its child contexts
10+
holds at the marked instruction. It is the tool for composing
11+
multiple context facts that cannot coexist as sibling keys on a
12+
single object.
13+
914
<SchemaViewer
1015
schema={{ id: "schema:ethdebug/format/program/context/gather" }}
1116
/>
17+
18+
## When to use `gather`
19+
20+
The context schema is open: a single context object may carry
21+
any number of discriminator keys together — `code`, `variables`,
22+
`invoke`, `return`, and so on all compose as siblings on the same
23+
object. Prefer the flat form when it works.
24+
25+
Reach for `gather` only when two or more facts would collide on
26+
the same key. The canonical cases are:
27+
28+
- **Multiple [`frame`](/spec/program/context/frame)s** — an instruction
29+
that maps
30+
simultaneously to an IR step and a source step needs one
31+
entry per frame, each with its own `code` range.
32+
- **Multiple `variables` blocks** — when separate pipeline
33+
passes each contribute variable information (e.g., one
34+
names the variable, the other supplies its pointer), each
35+
set lives in its own context.
36+
37+
If every child context uses a different discriminator key, a
38+
`gather` can be collapsed into a single flat object with the
39+
same meaning — and that flat form is the preferred style.

0 commit comments

Comments
 (0)