Skip to content

ir: assert IRVersion once, against a pin of the encoded shape, instead of in every golden #964

Closed

Description

@OmarAlJarrah

Problem

The IR version is asserted in 115 places and checked against the shape it versions in none.

A missed bump is costly. A build at version N reads only N, so the stamp is all that tells a reader the shape moved.

Direction

A proposal, in two parts that land together:

  1. Pin the shape. A test derives a canonical description of every type reachable from ir.Document: JSON member names, Go types, omitempty and omitzero, and the sealed sums' kind tags. It reads the package through internal/decls, hashes the description, and compares against a table keyed by IRVersion.
    • A shape change with no bump fails, naming the version to add.
    • A bump with no shape change fails.
    • Two PRs taking one number with different shapes fail on whichever reaches main second.
  2. Stop stamping each golden. The golden helper compares documents with the irVersion member masked, or writes goldens without it. A bump then touches the constant, the table and the version history, not every golden.

Done when planted mutations redden the pin with IRVersion left as is (a member added or removed, a JSON tag renamed, omitzero changed to omitempty, a TypeKind added), and a version bump regenerates no golden.

Out of scope

What a bump promises consumers (#432).

Related: #432

Priority: P4, rule 1 (a test change with no behaviour change). git log --format=%H -G 'IRVersion = "' -- ir/document.go | wc -l → 14 (the first version and 13 bumps); the last six each rewrote 103 to 115 goldens, 93 to 110 of them only on the irVersion line (morphic @c387e25c).

Metadata

Metadata

Assignees

No one assigned

    Labels

    priority:P4Refactors, tests, CI, hostile-input hardening, cosmetic diagnostics, other formatstype:testTests only

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions