Skip to content

openapi: return what a build made, so two readers stop predicting it #2133

In progress

Description

@OmarAlJarrah

Problem

Two functions of compilers/openapi/internal/schema answer, ahead of a build, what the build will do, by restating its decisions:

  • ownHomes (with nodeHomes, 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 inline allOf entry the merge reads and which it keeps, restated from what fillAllOf reads, 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

Related: #2083, #2086, #2084

Priority: P4, rule 1 (a refactor that changes no lowering, validation, IR or emit-contract behaviour). It unblocks the rest of #2083.

Activity

  1. added
    type:chore
    priority:P4
    on Nov 19, 2026
  2. OmarAlJarrah commented on Nov 29, 2026

    @OmarAlJarrah
    MemberAuthor

    #2354 settles this at 7eb4b822e and fa2465977, 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_FinishesTheNodeItBuildsOnceBeforeStoringIt is now TestInternNode_FinishesTheNodeBeforeAnyOtherLoweringReadsIt. What the new name claims is held by TestRegistryReads_HeldToTheBaseline in internal/archtest: the schema package's one registry read is Lookup, which returns an ID, so no lowering reads a node between its store and its finishing steps.

    The homes are decided once. ownHomes is boundsHeldAt (schema/boundhomes.go), computed by the frame that dispatches a position: lowerDispatched, which hands them to lowerTyping; lowerSchemaBody, for a union built at its own position; and lowerPrincipal, for an inline principal. The builders that took the homes themselves now receive them: hoistScalar, lowerArray, collectionBoundsMetWithFoldedEntries and, for a composed variant, composedBody. ConstraintsOf read only their value bounds and now takes those kinds alone, and lowerModel, which reads no voice, takes the kinds of its own bounds. carriesNumberAsText is gone: hoistScalar reads homes.numberText from the one decision.

    A union's homes are decided once too. nodeHomes gives a schema declaring oneOf or anyOf the value bounds alone only where the union is the node, with no structural keyword beside it (hasUnionSiblings, the test lowerSchemaBody picks the union node by), and lowerTyping no longer overrides that answer. The override and the keeping of an allOf entry's unread keywords disagreed on this component in a 3.1 document:

    L:
      type: array
      uniqueItems: true
      items: {type: string}
      oneOf: [{minItems: 1}, {maxItems: 3}]
      allOf: [{maxItems: 9}]

    At 7d7208585 the list holds maxItems: 9 in its Constraints and also keeps it under openapi:maxItems as degraded_lowering, with an openapi/degraded-construct finding. At fa2465977 it holds the bound in Constraints alone, as the same array writing maxItems beside its type does, and keeps only the oneOf (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, then CarrierConstraintsOf) on a visit that builds no node. homesAt answers both, and is the one caller of boundsHeldAt outside the three frames. mergeConsumes stays as well, with a comment saying why (3e493d576): the merge reads every inline entry's properties and required whatever the entry builds, so what it reads is known before any build runs.

    IR and diagnostics are byte-identical at 7eb4b822e and at fa2465977, each against a binary of its parent, on testdata/ (314 specs), the golden spec (cloudflare/api-schemas @904c5434) and 1,863 OpenAPI 3 specs from a corpus of public API descriptions. At 1cf9539a7, git grep -n 'ownHomes\|carriesNumberAsText' -- compilers lists nothing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    priority:P4type:chore

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions