1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
//! The contract check stage of the [`blocks`](super) 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](crate::guide::concepts_overview#frozen-trees-and-computed-data), 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`](crate::stdlib::VALIDATED). Every workflow of the standard
//! package demands that collection (the [`check`
//! workflow](crate::stdlib::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`](crate::lang::rewrites::userdefs::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.
//!
//! [`ContractViolated`]: crate::lang::rewrites::blocks::ContractViolated
use cratePlanCx;
use crateStageCx;
use crate;
use crateStageOut;
use crate;
use crate;
use ;
/// The name of the contract check stage, `flm.blocks.check-contract`. See the
/// module documentation.
pub const CONTRACT_CHECK: &str = "flm.blocks.check-contract";
/// 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`](crate::stdlib::VALIDATED). The module documentation says
/// which parts apply to which plan.
pub const CONTRACT_CHECKED: &str = "flm.blocks.contract-checked";
/// The contract check stage, `flm.blocks.check-contract`. See the module
/// documentation.
pub ;