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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
//! The lowered-trees table, into which a backend's lowering stage writes its
//! result, and the address of a node inside a lowered tree.
//!
//! A **table** is typed data that one stage writes beside the frozen trees and
//! other stages read; its identity is its registered dotted name, and that
//! name is also a capability ([`Table`]; see [frozen trees and computed
//! data](crate::guide::concepts_overview#frozen-trees-and-computed-data)).
//!
//! Every backend uses the table type of this module, [`LoweredTrees`],
//! with an instance of its own named `flm.lowered.<backend>`
//! ([`lowered_table_name`], [`lowered_table`]). For each document tree, the
//! table holds the lowered tree ([`LoweredTree`]), the identifiers of the
//! definitions its rules required (style and script definitions on HTML,
//! package requests and definition pieces on LaTeX), and how many rounds
//! lowering ran. [`LoweredAddr`] is the address of one node inside a lowered
//! tree; the text backend's position marks use it.
use ;
use fmt;
use Arc;
use ;
use SerialValue;
use crate;
use crate;
use crate;
use crateFlm;
/// The address of a node of a *lowered* tree: the document tree it was
/// lowered from, and the node's position in that tree's lowered form (its
/// index in storage order).
///
/// It is not a [`NodeAddr`](crate::model::addr::NodeAddr), which identifies a
/// node of a *frozen* tree, for two reasons. A lowered node may have no
/// frozen counterpart: a rule may synthesize nodes that represent no single
/// frozen node, and a lowered tree stores no map back to the frozen one. And
/// the node identifiers techy assigns carry a per-tree tag that differs from
/// run to run, whereas a position is the same in two runs over the same
/// document. An address is looked up in the lowered-trees table with
/// [`resolve`](LoweredAddr::resolve). The text backend's position marks
/// ([`TextMark::addr`](crate::stdlib::backends::text::TextMark::addr)) are
/// addresses of this kind.
///
/// # Examples
///
/// ```
/// use flm_core::model::addr::TreeId;
/// use flm_core::stdlib::backends::lowering::LoweredAddr;
///
/// let addr = LoweredAddr::at(TreeId::tree(0), 5);
/// assert_eq!(addr.to_string(), "tree#0/5");
/// ```
/// The lowered form of one document tree: the tree an emitter walks, the
/// requirements its rules recorded, and how many rounds lowering took.
/// The lowered trees of one backend, keyed by the document tree each was
/// lowered from — the table `flm.lowered.<backend>`.
///
/// The backend's lowering stage ([`LoweringStage`](super::LoweringStage))
/// writes it, and the backend's emit stage reads it. A tree whose lowering
/// failed has no entry here; the failure is reported as an Error diagnostic
/// instead ([`super::error`]). The table's projection lists `{tree, rounds,
/// requires}` per entry, not the lowered trees themselves: a consumer that
/// needs them projects them itself ([`crate::dump::project`]).
/// The name of `backend`'s lowered-trees table, `flm.lowered.<backend>` — both
/// the table's name and the capability that writing it provides.
///
/// # Examples
///
/// ```
/// use flm_core::stdlib::backends::lowering::lowered_table_name;
///
/// assert_eq!(lowered_table_name(&"text".into()).as_str(), "flm.lowered.text");
/// ```
/// The typed handle through which a stage reads or writes `backend`'s
/// lowered trees.
///
/// The feature that registers the backend must have declared the table under
/// the name [`lowered_table_name`] returns; a handle alone does not create
/// it.