Skip to main content

Module check

Module check 

Source
Expand description

The contract check stage of the blocks feature, flm.blocks.check-contract: it checks every frozen tree against the tree contract and reports each violation.

The tree contract is the set of rules every tree satisfies after parsing (the parse part) and the further rules a tree satisfies after the block-structure pass (the block-structure part). Its checker, crate::lang::rewrites::blocks::check, is two plain functions over a tree. This module makes it a check stage of the pipeline: a stage of per-tree scope that runs, over every frozen tree, each part of the contract that the plan’s trees are subject to, and reports every violation as the Error diagnostic flm.blocks.contract-violated (ContractViolated). A violation is a fault in the program (the parser, a rewrite pass or an element’s aspect), not in the document.

The stage provides CONTRACT_CHECKED (flm.blocks.contract-checked), which the blocks feature adds to the collection flm.validated. Every workflow of the standard package demands that collection (the check workflow and the workflow of each standard backend), so the stage runs in every standard plan.

§What the stage requires, and which rules it checks

The stage requires the decision about block structure, never one particular outcome, so that it fits into any plan. It does not require the decision about user definitions; it is only ordered after it. It finds out which outcomes the plan chose by reading each outcome’s trees table as an optional read (a read that finds nothing when the table was not written), and checks the rules that apply to those outcomes:

  • It requires BLOCKS (flm.blocks), the decision about block structure, and reads STRUCTURED (flm.blocks.structured) optionally. Where that table was written, the trees were structured and both parts of the contract apply. Where it was not, the plan chose the trees as parsed (flm.blocks.raw, which the lowering rules of the latex-recomposed backend require) and only the parse part applies.
  • Whenever the registry declares flm.userdefs.expanded, it reads that table optionally and is ordered after flm.userdefs, the decision about user definitions whose expansion policy is per-plan. Where the table was written, no use site of a user definition (an element that carries the Expand aspect; see crate::lang::rewrites::userdefs) may remain in a structured tree, and a remaining one is a violation. Where it was not, the plan chose to keep those use sites in the tree for the lowering rules (flm.userdefs.kept), and that one rule of the block-structure part does not apply; every other rule still does. The stage never adds the expansion to a plan that does not otherwise need it.
  • Whenever the registry declares flm.userdefs.always-expanded, it requires that capability: the definitions whose expansion policy is always are expanded in every plan, so the check is meaningful only after that rewrite stage has run. The capability refines nothing, so requiring it chooses no alternative.

Constants§

CONTRACT_CHECK
The name of the contract check stage, flm.blocks.check-contract. See the module documentation.
CONTRACT_CHECKED
The capability the contract check stage provides, flm.blocks.contract-checked: every frozen tree satisfies the parts of the tree contract that apply to the plan’s trees, or its violations have been reported. A member of the collection flm.validated. The module documentation says which parts apply to which plan.