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
//! The one shared body-descent skeleton (ADR-0740): the FINAL-stage
//! cursor, the any-arm fold over a stage's `UNION` arms, and the
//! concluding-clause hand-off into which each layer injects its own
//! verdict — the naming layer's ([`Query::projects_columns`]) here in
//! the IR, the executor's (the planner's full clause table with
//! any-branch breadth and the batched-call ruling) in relate-executor.
//! The model this walk runs over stays in this module's parent
//! ([`Query`](super::Query), [`Clause`](super::Clause),
//! [`final_stage`](Query::final_stage)); this module owns the
//! classification fold, its injected-verdict seam, and the structural
//! invariants it surfaces. The skeleton's tests live beside it
//! (`body_descent_tests`); the AST fixtures both that suite and the
//! executor verdict's suite build their subjects from live in
//! `body_descent_fixtures`, gated behind this crate's `test-hooks`.
use ;
/// A layer's concluding-clause verdict for the shared body-descent
/// skeleton ([`Query::final_stage_projects_rows`] /
/// [`stage_projects_rows`], ADR-0740): whether the clause concluding an
/// arm projects a statement result of its own. `descend` — the
/// skeleton's own body descent handed back — answers the clause's
/// nested bodies (a `WHEN` branch body, a nested `CALL { … }` body)
/// under the same verdict, so a layer folds them by its own breadth
/// without re-spelling the query structure the skeleton owns. The
/// descent's own type stays inline (`&dyn Fn(&Query) -> bool`): a named
/// alias for it would be a bare `dyn` defaulting to `'static`, which
/// the closures the skeleton hands back cannot satisfy.
pub type ConcludingVerdict = dyn Fn ;
/// The clause concluding a part — its last clause, with the part
/// invariant stated once, here: a part invariantly carries at least one
/// clause (validation refuses an empty part as `empty query part`
/// before any fold runs), so reaching an empty part is a broken
/// invariant to surface, never a verdict to fabricate. The skeleton's
/// arm fold and the executor's NEXT-seeding fold read this one
/// spelling.
/// The concluding clauses of a stage's parts — the skeleton's all-form
/// half, for the consumers that judge every arm instead of any arm
/// ([`stage_projects_rows`] is the any-form fold). The stage invariant
/// is surfaced once, here: a stage invariantly carries at least one
/// part, so an empty parts iterator is a broken invariant to surface,
/// never a fold that answers vacuously. The executor's NEXT-seeding
/// fold reads this one enumeration instead of re-spelling the walk and
/// its invariants.
/// The stage-level entry of the one shared body-descent skeleton
/// (ADR-0740): whether any of one stage's `UNION` arms projects a
/// statement result of its own under a layer's [`ConcludingVerdict`].
/// [`Query::final_stage_projects_rows`] is the body-level form — the
/// same fold over a whole body's FINAL stage; this entry serves the one
/// caller that judges the stage it is about to run rather than a body
/// (the executor's stage driver, which holds the stage's own parts).
///
/// The skeleton owns the structure walk and surfaces its invariants: a
/// `Query` invariantly carries at least one part, a part at least one
/// clause (validation refuses an empty part as `empty query part`
/// before any fold runs) — both stated once, in
/// [`stage_concluding_clauses`], the one enumeration this any-form fold
/// and the executor's all-form fold read. A layer owns only its
/// clause-level verdict; the two current verdicts — the naming layer's
/// `RETURN`-only base with a first-branch stand-in, the executor's
/// planner-table base with any-branch breadth and the batched-call
/// ruling — agree on every valid body, and a new nested-body arm in one
/// needs its twin in the other.
/// The naming layer's [`ConcludingVerdict`]: a `RETURN` concludes a
/// projecting body; a `WHEN` clause's first branch stands in for the
/// whole clause (the grammar pushes one before its loop can break, and
/// validation holds every branch and arm to the same export shape, so
/// the stand-in and the executor's any-branch fold answer alike); a
/// nested `CALL { … }` is its body's answer. Everything else leaves the
/// body unit — no export columns, no statement result: the update
/// clauses, the read pipeline's interior and procedure-read clauses
/// (`MATCH`/`WITH`/`UNWIND`/`CALL` — a bare procedure call, unlike the
/// row-producing `CALL { … }`), the DDL/admin family, `LOAD CSV`,
/// `FINISH`, and the routing `USE`. [`Query::projects_columns`] is this
/// verdict's one spelling over the shared body-descent skeleton
/// (ADR-0740).
pub