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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
//! The auto-parameter vocabulary in both directions (ADR-0503's
//! extraction, ADR-0718's substitution): the reserved placeholder prefix
//! and its two named predicates, the name grammar's one writer and its
//! reader, and the authored-spelling pairs the naming path substitutes
//! with. A sibling of `normalize.rs` — the one-pass normalizer produces
//! the spellings, this module owns the vocabulary around them — so the
//! normalizer's own header stays true and the placeholder grammar has
//! one home whichever direction a consumer reads it.
/// The reserved prefix of every auto-parameter name. A statement whose
/// token stream references a parameter with this prefix, or a caller whose
/// parameter map carries a key with it, is [`NormalizeOutcome::NotCacheable`]
/// — the caller can never collide with the engine's own names. Private
/// behind the two named predicates that spell the policy
/// ([`name_is_auto_parameter`] on names, [`column_carries_auto_parameter`]
/// on rendered column text): the prefix itself is not surface.
const AUTO_PARAM_PREFIX: &str = "__AUTO_";
/// Whether a caller's parameter map carries any [`AUTO_PARAM_PREFIX`]-named
/// key — the one spelling of the reserved-prefix collision policy, consulted
/// at the one boundary that decides cache participation — the facade's
/// `Connection::cache_lookup`, before the raw stage — where such a caller
/// disables the cache for the statement entirely. Generic over the value
/// type — the policy is about the names only.
/// Whether `name` is an auto-parameter name ([`AUTO_PARAM_PREFIX`]) —
/// the one spelling of the prefix test, shared by the caller-map
/// boundary above and the planner's auto-parameter plan predicate (the
/// dispatch epilogue's authored-name restore is keyed on the same
/// prefix, ADR-0663).
/// Whether a rendered result column carries the auto-parameter prefix
/// (the compiled plan spells an unaliased auto-extracted item as the
/// placeholder) — the text-level half of the epilogue's re-parse
/// trigger, beside the name-level [`name_is_auto_parameter`]: the two
/// consult one prefix, one on names the plan holds typed, one on the
/// column text the plan rendered.
/// One extracted literal's authored spelling (ADR-0718): the placeholder
/// name the compiled plan carries, and the authored source text the
/// naming path substitutes it with. Named fields, never a positional
/// pair — which side is the placeholder is a compile-time fact, not a
/// destructuring convention.
/// The extracted literals' authored spellings, one per literal, in
/// creation order — the pairs the naming path substitutes with,
/// [`Normalized::values`] zipped with [`Normalized::spellings`], carried
/// beside the values on every cache channel that already carries them.
/// The placeholder's authored text is data, never re-derived by a parse
/// at result time.
pub type AuthoredSpellings = ;
/// Zip a normalization's [`AuthoredSpellings`] — the one construction,
/// from the two parallel vectors the normalizer produced (generic over
/// the value type: the normalizer's own `NormalizedValue`, the engine's
/// `Value`, whatever channel carries the pairs).
/// Replace every auto-parameter placeholder in `text` with its authored
/// spelling (ADR-0718) — the one substitution, in the crate that owns the
/// placeholder grammar. Three rules make it safe on rendered column text,
/// which is a verbatim substring of the rewritten statement:
///
/// - **Exact-name match**: a `$__AUTO_…` occurrence substitutes only when
/// the whole parsed name is one of `spellings`' carried names. A
/// non-extracted string literal's content can look like a placeholder
/// (`startsWith(n.x, '$__AUTO_INT_0__')` — the call-argument guard kept
/// the string out of extraction); a lookalike that is not a carried
/// name stays verbatim, exactly what a re-parse of the source would
/// have kept.
/// - **Quote awareness**: the scan tracks string spans by the lexer's own
/// rules (a `'`/`"` opens, the same byte closes, a backslash escapes
/// the next byte), so a string literal that happens to contain a
/// *carried* name verbatim is never touched from inside its quotes —
/// the one case an exact-name match alone cannot refuse.
/// - **Single pass**: the output is never re-scanned, so an authored
/// spelling that itself contains placeholder-lookalike text (an
/// extracted string literal) lands once, verbatim.
///
/// Inter-token spacing inside a substituted name follows the plan the
/// column text came from (ADR-0718 decision 4): a first execution's
/// splice preserves the literal span's trailing separator verbatim, so
/// the name reproduces the source's spacing exactly (`RETURN 1 + 2`
/// answers `1 + 2`); a template hit's plan was compiled from the
/// FIRST statement's rewritten text, so the name inherits that
/// statement's spacing — the one recorded divergence.
/// Write one whole auto-parameter name — the grammar
/// [`crate::normalize::Pass::fresh_name`] assigns with (the tag derives
/// from the value it names there, the index from the one creation
/// counter), stated once here so the writer and the reader below can
/// never drift. The reader stays deliberately tolerant of unknown tags
/// (any uppercase run): a stored pair list may outlive a dialect that
/// grew a new value kind.
pub
/// Read one whole auto-parameter name from the bytes after a `$` —
/// [`AUTO_PARAM_PREFIX`], a kind tag, `_`, digits, and the closing `__`
/// (the grammar [`auto_parameter_name`] writes) — `None` when the bytes
/// do not spell one. Every consumed byte is echoed into the returned
/// name, so the caller advances by `name.len()`: the name IS the
/// consumption record.