Repository navigation
Description
Problem
Two functions of compilers/openapi/internal/schema answer, ahead of a build, what the build will do, by restating its decisions:
ownHomes(withnodeHomes,boundhomes.go): which bounds the node a position builds can hold, restated from the dispatch of the lowering, because no build returns the bounds it took of the entries it folds.mergeConsumes(allof.go): which keywords of an inlineallOfentry the merge reads and which it keeps, restated from whatfillAllOfreads, because the merge returns nothing of what it read.
Each is a second copy of a decision, held to the first by tests alone. They cannot simply ask the build, for two reasons that are one: a build hands a callback down and learns what it did through captured state, so it returns no account of what it made; and three readers ask BEFORE the build runs (stand.heldWhole for a type list, markKeptWhole for the entries the build reads, and schemaBody on a visit that builds nothing), so there is nothing yet to ask.
$ git grep -nP 'func (\([^)]*\) )?(ownHomes|mergeConsumes)\b' -- compilers | cut -c1-90
compilers/openapi/internal/schema/allof.go:551:func mergeConsumes(bs *statement.Schema, key str
compilers/openapi/internal/schema/boundhomes.go:61:func ownHomes(c lowering.Ctx, s *statement.S(morphic @512f3ee46.) #2083 lists both among the predictions it asks to replace; the others it lists do not need this.
Direction
A draft. A lowering returns what it made beside its ID: the node in hand, the keys it read, and the bounds it took of the entries it folded; the merge returns what it read of each inline entry. The three early readers then read after the build, from that value, and ownHomes and mergeConsumes are deleted. The same change removes the callbacks the finishing step is handed, which is the shape #2086 measures the allocation cost of and #2084 asks a question about; the three are best designed as one change, since each alone would restructure the finishing step.
The order of finishing matters to one test today (TestInternNode_FinishesTheNodeItBuildsOnceBeforeStoringIt), which pins that a node is finished before the registry stores it; a design that finishes after the store has to show nothing reads a node in between.
Out of scope
- The other predictions openapi: replace the schema package's predictions of what a lowering builds with what it reports #2083 lists.
- Any change to what a schema lowers to: the IR and the diagnostics stay byte-equal.
Priority: P4, rule 1 (a refactor that changes no lowering, validation, IR or emit-contract behaviour). It unblocks the rest of #2083.
Activity
OmarAlJarrah commentedon Nov 29, 2026
#2354 settles this at
7eb4b822eandfa2465977, and closes it at its merge on the reasoning below rather than by the change the Direction drafts.A build now returns what it made,
builtPosition, up the lowering's frames in place of the finisher closures (c852e0988), which is the shape #2086 and #2084 ask for.TestInternNode_FinishesTheNodeItBuildsOnceBeforeStoringItis nowTestInternNode_FinishesTheNodeBeforeAnyOtherLoweringReadsIt. What the new name claims is held byTestRegistryReads_HeldToTheBaselineininternal/archtest: the schema package's one registry read isLookup, which returns an ID, so no lowering reads a node between its store and its finishing steps.The homes are decided once.
ownHomesisboundsHeldAt(schema/boundhomes.go), computed by the frame that dispatches a position:lowerDispatched, which hands them tolowerTyping;lowerSchemaBody, for a union built at its own position; andlowerPrincipal, for an inline principal. The builders that took the homes themselves now receive them:hoistScalar,lowerArray,collectionBoundsMetWithFoldedEntriesand, for a composed variant,composedBody.ConstraintsOfread only their value bounds and now takes those kinds alone, andlowerModel, which reads no voice, takes the kinds of its own bounds.carriesNumberAsTextis gone:hoistScalarreadshomes.numberTextfrom the one decision.A union's homes are decided once too.
nodeHomesgives a schema declaringoneOforanyOfthe value bounds alone only where the union is the node, with no structural keyword beside it (hasUnionSiblings, the testlowerSchemaBodypicks the union node by), andlowerTypingno longer overrides that answer. The override and the keeping of anallOfentry's unread keywords disagreed on this component in a 3.1 document:At
7d7208585the list holdsmaxItems: 9in itsConstraintsand also keeps it underopenapi:maxItemsasdegraded_lowering, with anopenapi/degraded-constructfinding. Atfa2465977it holds the bound inConstraintsalone, as the same array writingmaxItemsbeside itstypedoes, and keeps only theoneOf(validation_only).The build cannot return the homes instead, as the Direction asks, because two readers need them where no build has run or none will. A type list asks whether its position keeps its inline principal whole before any variant builds (
heldWhole), and a property's or a parameter's carrier reads its bounds after its use (UseOf, thenCarrierConstraintsOf) on a visit that builds no node.homesAtanswers both, and is the one caller ofboundsHeldAtoutside the three frames.mergeConsumesstays as well, with a comment saying why (3e493d576): the merge reads every inline entry'spropertiesandrequiredwhatever the entry builds, so what it reads is known before any build runs.IR and diagnostics are byte-identical at
7eb4b822eand atfa2465977, each against a binary of its parent, ontestdata/(314 specs), the golden spec (cloudflare/api-schemas@904c5434) and 1,863 OpenAPI 3 specs from a corpus of public API descriptions. At1cf9539a7,git grep -n 'ownHomes\|carriesNumberAsText' -- compilerslists nothing.