Repository navigation
Description
Problem
Several functions in compilers/openapi/internal/schema restate a lowering's dispatch to answer, ahead of the lowering, what it will build or read. Each is a second copy of a decision, and nothing but its tests holds it to the first. With #1996 (at 6630476; ownHomes, nodeTypes and restKinds do not exist on main, composesAsModel and mergeConsumes do) they are:
ownHomesandnodeTypes(refinement.go): which bounds the node a refinement builds can hold, "read off what lowers the position rather than off the node", restating the dispatch oflowerElected,lowerUntypedandlowerUndecided.composesAsModel(union.go): whether the siblings of a union lower to aModel; its comment says "It mirrors lower's dispatch".mergeConsumes(allof.go): "the complete statement of what the merge keeps", restating whatfillAllOfreads.restKinds(refinement.go): rebuilds the own-keywords part of whatadmissionWalk.readOwncomputes (declaredInstanceTypes(s) & valueKinds(c, s)withclaimedKinds(c, s)) to leave a union out.
A mirror out of step shows as a position whose admission and node disagree. With Plain: {items: {type: string}, minItems: 1} and Wrapped: {allOf: [{items: {type: string}}]} in one openapi: 3.1.0 document:
$ morphic compile --diag-limit 0 spec.yaml | jq -c '.types | to_entries[] | select(.key | test("schemas/(Plain|Wrapped)")) | {id: (.key | split("/") | last), kind: .value.kind, inferred: (.value.provenance.inferred // null), unmodeled: ((.value.unmodeled // {}) | keys)}'
{"id":"Plain","kind":"list","inferred":"kind-inference","unmodeled":[]}
{"id":"Wrapped","kind":"scalar","inferred":null,"unmodeled":["openapi:items"]}(#1996 at 6630476; main lowers both to a Scalar over the top type.) Wrapped is the top type keeping its items, where Plain, the same schema without the allOf, is a List.
Three more readers answer one question, "this pointer is an allOf entry", each its own way and none through the other: failedEntry (statement/table.go, last / and Atoi), writtenAsEntry (schema/admissions.go, ParseUint and the parent's last token) and splitRef (schema/allof_disjoint.go, pointer equality of adjacent branches). statement.Entry already knows.
And naming flattens an allOf on its own: titleWords (naming/titles.go) walks nested allOf to statement.MaxFlattenDepth over raw nodes and Namer.conjoined (naming/naming.go) asks statement.ReadBeside over raw pairs, beside statement.Table's flatten and conjoins. They differ on an entry whose $ref fails (the statement reads it whole) and on a reference merged past the merge bound.
Direction
A draft. Where a lowering reports which keys and which bounds it took, the mirrors answer from that report and are deleted; where it cannot (restKinds), export readOwn's own-keywords part as one function both call. Let a statement.Statement say whether its schema is an entry, and have the three readers ask it; have naming read the table.
Done when git grep -nE 'func (ownHomes|nodeTypes|composesAsModel|mergeConsumes|restKinds|failedEntry|writtenAsEntry)\b' -- compilers lists none and the package's tests and goldens are unchanged. Each mirror is its own change.
Out of scope
The disagreement shown above, which is a defect to file apart. Message text. What naming should name.
Priority: P4, rule 1 (a refactor that changes no lowering, validation, IR or emit-contract behaviour). Existence of each function checked with the git grep above at 6630476.
Activity
OmarAlJarrah commentedon Nov 18, 2026
One more channel that belongs with this, on the branch of #1996 (at 338aac4): the keys a position does not keep travel twice.
unreadKeys(s, read keySet, handled []string)incompilers/openapi/internal/schema/unread.gotakes what a build read as a bit set and what an election skipped or said as a list of names, for one question, which keys of the domain not to keep.unreadByReferenceandkeepUnreadAcrossthread the list, the second appending to a clipped copy, andkeepUnreadconcatenates two lists per node. Only keys of the domain matter to it, sohandledcan be folded into the set at its four feeders (dispatch.skipped,dispatch.said,compositionCensusHandled,branchesSay), and the lowering then reports one thing, the keys it accounted for.OmarAlJarrah commentedon Nov 19, 2026
Where this stands after #2132, which removes some of these and is on
mainat c06d94a (the commit subjects below are those of its branch). It closes nothing here: what follows is what is gone, what stands and what each waits on.Gone
nodeTypes, withlowerUntypedandlowerUndecided(refactor(compilers/openapi): decide once how a schema's types lower). How a schema whose dispatch picks no keyword family lowers is one value,typingOf: the lowering builds by it andnodeHomesreads it.lowersTypeArrayreads it too (refactor(compilers/openapi): ask the type decision for a type list), and so doesobjectVariant, which counted the index of a type list's object variant in the types the schema writes by hand (refactor(compilers/openapi): ask the type decision for an object variant).composesAsModel(refactor(compilers/openapi): ask the dispatch what a union's body builds). The dispatch among a schema's own keywords is one function,ownDispatch, which the lowering's own dispatch (dispatchAt) returns; a union's classification asks it andtypingOf.restKinds' copy of the own-keywords reading (refactor(compilers/openapi): read a schema's own kinds in one place):readOwnandrestKindscall oneownKinds, the remedy the Direction gives, andrestAdmitsObjects, which met a union holder's type with its value sets itself, calls it too (refactor(compilers/openapi): read a union holder's own kinds by ownKinds);toldWhereWrittenstill meets the two inside a switch arm, asownKinds' comment says.restKindsitself stays: it asks for the kinds of a schema less its union, over the flattened entries, which the walk does not compute. Nothing held the old copy to the walk: dropping the value sets from it alone failed no test of the package.Stands
ownHomes(withnodeHomes) andmergeConsumeswait on openapi: return what a build made, so two readers stop predicting it #2133. The first answers which bounds a node holds for the voices of itsallOf, the second what the merge reads of an inline entry; only the builds know either, and no build returns it. Three readers also ask before any build runs (a type list deciding whether its position keeps its principal whole, the marking of the voices the build itself reads, a visit that finds the node built), so they need a build to return what it took (openapi: return what a build made, so two readers stop predicting it #2133) and those readers to read after it.failedEntryandwrittenAsEntrywait on openapi: a $ref naming an allOf entry that writes a $dynamicRef reads the entry as every kind #2058. They are two parses of a pointer and they disagree (strconv.Atoiagainststrconv.ParseUint: a member+3of a mapping keyedallOf, which a$refmay name, is an entry to the first alone), and both take a member of such a mapping, and an entry a$refnames, for an entry of the composition in hand. Folding them onto either parse changes what such a document lowers to. Each now names the other in a comment; both go when a statement says how its schema is reached.naming's own flattening (titleWords,Namer.conjoined) stands. It disagrees with the statement on an entry whose$refnames nothing, which the statement reads whole: for a property writtenmainhints the node atpdeep_title, read through the failed entry's ownallOf, where the statement's entries hold no title and the node would be hintedp. Reading the statement fromnamingtherefore moves a name an identifier is rendered from, which is a versioned change. Not measured: a reference merged in past the merge bound, and a position the bindings hold no schema for.Corrections to the text above
splitRefnever asked whether a pointer is anallOfentry. It asked whether a conjunct is the reference of an entry writing a$refbeside other keys, by comparing the pointers of adjacent conjuncts, and missed an entry whose other keys hold anallOfof their own. It is gone: the statement marks that reference (statement.Entry.Split) and the report of conjuncts sharing no value reads the mark (fix(compilers/openapi): name an entry's $ref apart beside its own allOf), which changes one name in that report's message and nothing else.The channel in the first comment is already one set on
main:unreadKeys(s, read keySet), withunreadByReference,keepUnreadAcrossanddispatch.handledcarrying akeySet.The command under "Done when" prints nothing on any tree,
mainincluded:git grep -Etakes no\bhere (git 2.56, macOS). This one works:$ git grep -nP 'func (ownHomes|nodeTypes|composesAsModel|mergeConsumes|restKinds|failedEntry|writtenAsEntry)\b' -- compilersOn
mainit lists the seven. On the pull request's head it lists five:ownHomes,mergeConsumes,failedEntryandwrittenAsEntry, which stand as above, andrestKinds, which should leave the list.OmarAlJarrah commentedon Nov 27, 2026
One more prediction of what a lowering keeps, in the same package and not listed above:
declaresPositionScoped(compilers/openapi/internal/schema/declaration.go, morphic @cfb366317). It gates whether a position hoists an alias on a list of whatattachDeclaredAnnotations,internReferenceAlias,declarationOnandPreserveUnknownKeywordskeep, and its comment says it "must stay in step with what those actually keep".It has not stayed in step. #138, #1053 and #2009 were each a keyword dropped where the list and the keepers disagreed, and each fix (#149, #1217, #1996) added the keyword to the list. #1053's direction, one predicate both read, was not taken:
For this site the issue is done when the gate asks the keepers, or reads what they report, and that
git greplists nothing.OmarAlJarrah commentedon Nov 29, 2026
Where this stands at #2354's head,
1cf9539a7. Of the seven functions this issue's Done-when names, two went onmainwith #2132 and the pull request answers three, as it doesdeclaresPositionScopedfrom the comment of 2026-11-27.failedEntryandwrittenAsEntrystand until a later part of it lands, and this issue stays open until then.The Done-when grep, in the form that runs, lists four:
ownHomesboundsHeldAt, computed once by the frame that dispatches a position and passed to the builders (7eb4b822e, a union's homes atfa2465977); #2133 says why no build can return itnodeTypes,composesAsModelmainsince #2132mergeConsumespropertiesandrequiredwhatever the entry builds, so what it reads is known before any build runs (3e493d576)restKinds3e493d576)failedEntry,writtenAsEntryallOfentry as a fact of the composition listing it, as #2058 asks, which removes bothdeclaresPositionScopedc96c2fdec,eceb87783): the gate is the disjunction of what each keeper writing on a hoisted alias may keep, each read through the list or predicate that keeper reads (annotation.ReadKeeps,declaresBound,keepsUnknownKeywordsand the rest). It is now a cheap necessary test before a dry run: the site builds the alias on no registry, runs its keepers on it, and hoists it only where it holds something (9be615eb3), so what the keepers keep decides. Its "must stay in step" comment is gone:git grep -n 'must stay in step' -- compilerslists nothingRebuilding the gate fixed the drift #2324 files: an expanded
$dynamicRefor$recursiveRefwritten alone at a position no carrier holds hoisted an alias holding only itsBase, and now lowers to the type of the position it names, as a$refthere does. Against a binary of7d7208585, the head'stestdata/(314 specs) differs in three specs, by one such alias each. The golden spec's IR and diagnostics are byte-identical but for the version stamp, and so are those of 1,863 OpenAPI 3 specs from a corpus of public API descriptions.namingreads a schema's conjuncts from its statement (b03507d81):titleWordsreads the statement's entries rather than walking the rawallOf, andNamer.conjoinedreads whether a schema conjoins with its reference from the statement too. The name the comment of 2026-11-19 predicted moves: compiled at7d7208585, the propertypthere is hinteddeep_title, and at the head it is hintedp. That moves a name an identifier is rendered from, so it is recorded under the pull request'sIRVersionrow (0.74.0). The names pin (TestIRVersion_PinsTheNames) is unchanged, since no position it lists writes such an entry, and the golden spec's IR is byte-identical but for the version stamp.OmarAlJarrah commentedon Nov 30, 2026
Finished in #2354, which closes this on merge.
failedEntrywent at 7213104, when an entry whose$refnames nothing became two conjuncts like any other, andwrittenAsEntryat acf4512, when anallOfentry became a fact of the composition listing it. The Done-when grep now listsmergeConsumesandrestKindsalone, each kept with a comment saying why, as the comment of 2026-11-29 records. One correction to that comment: at c0ff23b the propertypthere is hinteddeep_titleagain, as onmain, since the failed entry's ownallOfis now read; no name moves.