Repository navigation
Description
Problem
statement.Schema holds its keywords in pointer slots (Kinds, Values, Format, Text, Array, Object, Choice, Logic, Notes), each nil where the schema writes no keyword of it. Every reader that wants one slot's value first steps past the nil pointer, and each package wrote its own function for it.
$ git grep -nE '^func [a-zA-Z]+In\([a-z]+ \*statement\.Schema\) ' -- 'compilers/*.go' ':!*_test.go' | grep -v looseIn | wc -l
17
$ git grep -nE '^func namedFormat\(' -- 'compilers/*.go'
compilers/openapi/internal/schema/scalar.go:51:func namedFormat(s *statement.Schema) string {(looseIn is a predicate over Logic, not a slot reader.) Seventeen ...In functions and namedFormat make eighteen readers of one shape, three of them declared twice (objectIn, arrayIn, discriminatorIn, in schema and in annotation), with #1996 (at 6630476; the statement package does not exist on main).
That is, in schema: kindsIn, enumIn, constIn, choiceIn, objectIn, arrayIn, allOfIn, discriminatorIn, textIn, namedFormat; in annotation: notesIn, extensionsIn, arrayIn, objectIn, logicIn, xmlIn, externalDocsIn, discriminatorIn. Each is a nil check and a field read (objectIn: if s == nil || s.Object == nil { return statement.Object{} }; return *s.Object). objectIn alone has 35 call sites (30 in schema, 5 in annotation; git grep -nw objectIn -- 'compilers/openapi/internal/schema/*.go' ':!*_test.go' | grep -vc ':func '). Three more of the same shape sit beside them under other names: defaultOf, prefixItems and (reading two slots) nullableTrue.
Three of them exist twice, so a change to one reaches only its own package's callers.
Cause
statement.Schema has four methods (Held, Property, Key, find) and no accessor for a slot, so each consumer wrote one beside its own call sites.
Direction
A draft. Declare each once, as a method of *statement.Schema that tolerates a nil receiver (s.Object(), s.Array(), s.Choice(), s.Kinds(), ...), and delete the functions. A method on a nil pointer receiver is idiomatic where the zero value is the answer, and Held and Property already do. A name that collides with the slot field (Object the field and Object() the method) needs a different spelling for one or the other; settle it in the change.
Done when the command above lists none but looseIn and go test ./compilers/... is unchanged. No document, golden or IR changes.
Out of scope
Readers that do more than step past a nil slot (itemsSchema, which also reads whether items is a list, declaredInstanceTypes). Whether the slots themselves should be values rather than pointers.
Priority: P4, rule 1 (a refactor that changes no lowering, validation, IR or emit-contract behaviour; it unblocks no higher-tier work). git grep counts above at 6630476.
Activity
OmarAlJarrah commentedon Nov 18, 2026
Part of this is on the branch of #1996 (at 8ed8087), which leaves the issue open for the rest.
Done there: the fourteen readers of a keyword inside a slot are nil-safe methods of
*statement.Schema(Types,Enum,Const,FormatName,PrefixItems,Discriminator,Default,XML,ExternalDocs, and the five that return a whole slot,ArrayKeywords,ObjectKeywords,TextKeywords,ChoiceKeywords,LogicKeywords, named so because the fields hold the bare names), the free functions are gone, three of which were declared twice, and a table test reads each on a nil schema and a nil slot.Left:
notesIn,extensionsInandallOfInstay free functions. They read a field the schema holds itself, not a keyword inside a slot, andSchemacarries 18 methods against the cap of 20, so the three would pass it.nullableTruestays too: it classifies the key's node. Closing this wants either those three read another way or a reason recorded for leaving them.OmarAlJarrah commentedon Nov 29, 2026
#2354 closes this at its merge without the change it asks, for the reason below.
At
1cf9539a7the Done-when command lists three readers:Each steps past a nil schema, not a nil slot, which a method of
statement.Schemawould read off its own receiver.statement.Schemaholds 18 methods (git grep -hE '^func \(([[:alnum:]_]+ )?\*?Schema\) ' -- 'compilers/openapi/internal/statement/*.go' ':!*_test.go' | wc -l) against the cap of 20 ininternal/archtest(maxMethodsPerType), so the three as methods break it, and tradingfindaway to make room would leave no room for the next. Each of the three now says why it is a function (3e493d576).find's in-band-1is filed apart as #2331.