Skip to content

compilers: a compiler's output duties are checked by convention, not by the contract #967

Closed

Description

@OmarAlJarrah

Problem

A throwaway second compiler, registered through engine.NewWith at c387e25c, returned documents that engine.Run and irverify both accept although the design forbids them:

  • Services empty, although ir-design §2 says a document has at least one;
  • Sources empty, or with an empty Format and Hash;
  • Name cleared.

A cleared IRVersion or IDSpaces is caught.

Other duties hold only by convention:

  • Calling compile.Types.Violations() after interning is one; only compilers/openapi/openapi.go does it.
  • A recognition whose Format is zero is skipped silently (compilers/compilers.go).
  • When a new compiler package has no rules entry, the layering test's message says "not allowed for compilers", not that an entry is missing.

The shipped compiler meets every duty, so none of this shows today. The next compiler (#469, #470) will meet it one silent gap at a time.

Direction

A proposal:

  • State each duty in compilers.Compiler's doc.
  • Check the cheap ones where the engine or registry already holds the data: a document has a source table and at least one service, and each SourceInfo has a format.
  • Let irverify own the rest, and give the archtest message the fix.

Done when the throwaway compiler's violations above each produce a named error or violation.

Out of scope

The harness's single-compiler wiring (#968).

Related: #469, #470, #800, #968

Priority: P3, rule 3 (off the golden spec: another format's compiler). Return a document with no services and an empty source table from a compiler registered through engine.NewWith → no error, no diagnostic, no violation (morphic @c387e25c).

Metadata

Metadata

Assignees

No one assigned

    Labels

    priority:P3Later emitters, M4 and up, 3.2-only, streaming, webhooks, rare constructstype:featureNew capability or enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions