Skip to content

skills: functional-core does not say whether a function over a struct counts against its method cap #2365

Done

Description

@OmarAlJarrah

Problem

morphic-designing-code/references/design-rules.md#functional-core does not say whether a function that takes a struct and reads its state counts as one of that struct's methods. That leaves the 20-method cap open to two readings, and the tree follows the one the rule's text does not.

The rule says "A method belongs on a type only when it reads or guards that type's own state, and a type nearing the method cap is split by the state its methods read". The cap's own comment says "A failure prompts asking what the type has started doing, not raising the number" (internal/archtest/methodcap_test.go). #2081 took that path for admission: it moved methods to functions of a narrower input (lowering.Ctx) or to a reader of another type.

reftable's binder instead sits at the cap with 20 methods, and carries 15 more functions that take *binder and read it:

$ git grep -h -E '^func \([a-z]+ \*binder\)' -- 'compilers/openapi/internal/reftable/*.go' ':!*_test.go' | wc -l
      20
$ git grep -h -E '^func [a-zA-Z]+\([a-z]+ \*binder[,)]' -- 'compilers/openapi/internal/reftable/*.go' ':!*_test.go' | wc -l
      15

staticSites(b *binder) and resettle(b *binder, site DocumentPointer) in dynamic.go are two of them. The archtest counter sees only receivers, so moving a method to a function over the same struct keeps the cap green while the type's surface grows. That is the growth the cap was added to stop. A builder working near the cap during #2354's work read binder as the convention, because no rule says otherwise.

Direction

A draft with two readings for the change to settle:

  1. Count a function whose first parameter is the struct, and which reads its fields, as that struct's method for the cap. State this in functional-core. A type at the cap is then split by the state its methods read, as openapi: rename the schema package's admission types and take admission off the method cap #2081 did. binder becomes a case to split, and archtest: hold every production type to the method cap, not only compilers/ #1159's counter may take such functions in.
  2. Accept functions over an unexported struct as within the rule, and state it, with the reason a function of the struct differs from a method of it.

Either way, the rule should name binder or #2081 as its example, so the next builder near the cap reads the decision rather than inferring it.

Out of scope

Splitting binder itself, which a reading of 1 would file on its own. The cap's number.

Related: #2081, #1159

Priority: P4, rule 1 (housekeeping): a skills change that alters no lowering, validation, IR or emit-contract behaviour. The two git grep counts above → 20 methods on *binder and 15 functions over it (morphic @4a7a384c9).

Activity

  1. added
    type:docs
    priority:P4
    on Nov 29, 2026
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:docs

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions