ingraph-codegen 0.1.0

The emission engine behind ingraph-derive: a plain declaration model in, the ingraph framework faces out.
Documentation
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
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
//! THE LAUNCH ENTRY: the one door a deployment of a graph root goes through.
//!
//! ```ignore
//! #[ingraph::graph]
//! pub struct Media {
//!   videos: Video,
//!   scenes: Scene,
//! }
//! ```
//!
//! emits, beside the options spine, `Media::launch` — the ruled sequence walked once, in order:
//! VALIDATE, then CREATE, then WIRE, then IGNITE, and an [`App<Media>`][`App`] at the end of it.
//!
//! The running world is the FRAMEWORK's type and not an emitted one — every indexer's lifecycle is
//! the same lifecycle — so what this entry contributes is the type parameter: the root it was
//! emitted for is what the world is `App` OF, which is the seat a later round's emitted faces hang
//! off.
//!
//! # PARSE is the caller's, and that is the framework reading no file
//!
//! The sequence's first step does not appear here, because the options arrive already typed: an
//! application picks its format, merges whatever layers it has and hands over a `MediaOptions`. What
//! this entry spends is that value, and it is spent WHOLE — the sections move into their nodes'
//! constructions, so a deployment's options are consumed by the launch they describe.
//!
//! # What the emission can say, and what it must be handed
//!
//! A root declares a LIST: mount names and node types, in one order. That list is exactly what the
//! create walk's third step needs, so the node pass is emitted here in full — one
//! [`Creation::node`] call per declared mount, in declaration order, each with its own section and
//! its own bare-options probe.
//!
//! The RESOURCES are the same kind of list, and the catalog round made them one: a root's
//! `#[ingraph(resource)]` fields say which resources exist, under which mount, and from which one
//! source — so the entry drives them itself, before anything else is built, exactly as the ruled
//! sequence orders it. The only ones it does NOT drive are the `factory` resources, whose options
//! close over something the application holds; those stay `prepare`'s, which still runs before the
//! first node.
//!
//! Every other step needs a fact the root's own declaration does not carry, and the three-author
//! wall is why: what a node SUBSCRIBES to is written in that node's declaration, which this derive
//! cannot see. So the topology, the write lanes and the engines all enter as parameters, and each
//! one is the narrowest shape that carries what it must:
//!
//! | step | who states it | how it arrives |
//! |---|---|---|
//! | parse | the application | already typed, as `<Root>Options` |
//! | validate | the DECLARATIONS' topology + this deployment's enablement | a [`Plan`], whose enablement AND catalog the entry replaces with the root's own |
//! | create — declared resources | THIS EMISSION | one call per `resource` field, from the source its declaration names |
//! | create — `factory` resources, slots | the party that can NAME them | `prepare`, driven against the walk |
//! | create — nodes AND origins | THIS EMISSION | one call per declared mount |
//! | wire + ignite | the party that can name the operators' types | `wire`, handed the built nodes and the wiring walk |
//! | sources last | the ENTRY | [`Ignition::into_app`] is never the closure's to call |
//!
//! # THE ORIGIN TIER is five lines, and only the CONVERGED door writes them
//!
//! A `#[ingraph(origin)]` field names a source mounted as a HEAD whose one out-edge IS its feed. The
//! converged door writes the whole of it: `Blueprint::origin` declares it, `Creation::node` builds
//! it from its own section, `Wiring::bridge` opens its edge from the PRODUCER's end, `Wiring::enrol`
//! registers it, and `Ignition::origin_kept` puts it on an engine with that edge as its feed.
//!
//! `launch_wired` writes ONE of them — the construction — and stops there, which is the same
//! division it already keeps: the caller states the plan and holds the wiring walk, so the closure
//! that already names the operators' types is the party that spells the bridge. The origin therefore
//! comes out of that door in the bag, built and unmounted.
//!
//! The last row is the one worth reading twice. `wire` hands back an [`Ignition`], not an [`App`],
//! so a caller may register bodies, teardowns and sources on it and cannot spend the moment they
//! start: SOURCES LAST stays structural through the emitted door exactly as it is inside the
//! ignition itself.
//!
//! # THE PRE-IGNITION UNWIND is emitted here, because the values are the WALK's
//!
//! A launch that refuses before anything ignited is holding everything it has built so far, and the
//! ruling says those values SAY their goodbyes rather than merely dropping. Nothing about that is
//! the framework's to do alone: the values live in this entry's own locals, which is precisely what
//! *ownership never left the launch walk* means. So the walk is emitted in fallible PHASES, each
//! with ONE refusal arm that hands its walk and a [`Staging`] ledger to that walk's own `unwind`:
//!
//! | phase | what the ledger reaches | who says it |
//! |---|---|---|
//! | resources, `prepare`, the node pass | the bag's filled slots | [`Creation::unwind`] |
//! | the wiring pass | each wired-but-unignited party's operator, or the value the wiring never reached | [`Wiring::unwind`] |
//!
//! Two shapes make that work and neither is decoration. The node bag is declared EMPTY and filled
//! slot by slot, because a struct literal's earlier temporaries are dropped by the very `?` that
//! abandons it — there would be nothing left to say goodbye to. And every per-mount holder is
//! declared BEFORE the phase that fills it, so one arm reaches all of them rather than one arm per
//! step. Each phase's outcome is bound to a local before it is matched, because the block borrows
//! the walk the unwind then consumes.
//!
//! The IGNITION pass keeps its `?`: by then the framework owns the failure — see `Ignition::unwind`,
//! which states what it does and does not reach.
//!
//! [`Creation::node`]: ../../ingraph/struct.Creation.html#method.node
//! [`Creation::unwind`]: ../../ingraph/struct.Creation.html#method.unwind
//! [`Wiring::unwind`]: ../../ingraph/struct.Wiring.html#method.unwind
//! [`Staging`]: ../../ingraph/struct.Staging.html
//! [`Ignition`]: ../../ingraph/struct.Ignition.html
//! [`Ignition::into_app`]: ../../ingraph/struct.Ignition.html#method.into_app
//! [`Plan`]: ../../ingraph/struct.Plan.html
//! [`App`]: ../../ingraph/struct.App.html

use proc_macro2::TokenStream;
use quote::{format_ident, quote};

use crate::{
  catalog::{Catalog, ResourceField, ResourceSource, default_resources_name},
  emit::{framework, leading, parameter},
  graph::{FusedMember, OriginMount},
  options::default_options_name,
};

/// The two goodbye arms' own suite — the resource word's routing and the pre-ignition unwind.
/// Beside the entry's suite for the ROSTERS' sake, exactly as `emit`'s own topic suites sit.
#[cfg(test)]
mod goodbye_tests;
#[cfg(test)]
mod origin_tests;
#[cfg(test)]
mod tests;

/// `<Root>Nodes` — the name the create walk's product takes.
///
/// The options spine's own rule one organ over: the type is derived from the USER's root, so a
/// `Media` configured by a `MediaOptions` builds a `MediaNodes`.
#[must_use]
pub fn default_nodes_name(root: &syn::Ident) -> syn::Ident {
  format_ident!("{root}Nodes")
}

/// One ingraph root's launch entry, ready to emit.
///
/// It borrows for [`OptionsSpine`](crate::options::OptionsSpine)'s reason: what it needs is the list
/// the root model already holds, and a second copy of that list is a second thing to keep in step.
#[derive(Debug, Clone, Copy)]
pub struct LaunchEntry<'a> {
  /// Where `ingraph` lives, as the declaration named it.
  pub krate: &'a syn::Path,
  /// The root's own visibility — what the entry and the node bag take.
  pub vis: &'a syn::Visibility,
  /// The root type, whose name both emitted names derive from.
  pub root: &'a syn::Ident,
  /// The NODES, in declaration order.
  pub nodes: &'a [syn::Type],
  /// The mount NAMES beside them, in that same order — the sections' keys, and the names a refusal
  /// reports a node under.
  pub mounts: &'a [syn::Ident],
  /// The RESOURCES, in declaration order — the create walk's FIRST step.
  pub resources: &'a [ResourceField],
  /// The SLOT-BEARING members, in declaration order — LAYER TWO's list and the sole-default law's.
  ///
  /// A fused member is a retrieving declaration, so it is the tier that owns corpora: what the
  /// launch reads off each one is `Habitats::make` (the homes it makes, in the targets its own legs
  /// name), `Habitats::TARGETS` (those same targets as demands, which is what mounts them) and
  /// `Habitats::UNBOUND` (the corpora whose legs named nothing, which the deployment's catalog
  /// binds). Empty is the ordinary state of a graph that retrieves nothing, and it is what makes all
  /// three emissions disappear rather than emit a loop over no members.
  pub fused: &'a [FusedMember],
  /// The ORIGINS, in declaration order — the tier whose members are HEADS the graph does not feed.
  ///
  /// Five lines apiece and no more, which is what an origin's whole shape costs: declared onto the
  /// blueprint through `Blueprint::origin` (a head, whose effect is pure), built from its own
  /// section by the same `Creation::node` a node goes through, its ONE out-edge opened from the
  /// producer's end by `Wiring::bridge`, enrolled, and put on an engine by `Ignition::origin_kept`
  /// with that edge as its FEED.
  ///
  /// Empty is the ordinary state, and it is what makes every line of this tier disappear.
  pub origins: &'a [OriginMount],
}

impl LaunchEntry<'_> {
  /// EVERY MEMBER THE CREATE WALK BUILDS, in declaration order within each tier — the nodes, then
  /// the origins.
  ///
  /// One iterator because the BAG is one bag: the slot a built member lands in, the taker that
  /// empties it and the `Debug` row that reports it are the same three lines for either tier. What
  /// the two differ by is the DOOR each is built through — see [`built`](Self::built) — and
  /// everything AFTER the build: declaring, wiring, igniting, which are written apart.
  fn built_members(&self) -> impl Iterator<Item = (&syn::Ident, &syn::Type)> {
    self.mounts.iter().zip(self.nodes).chain(
      self
        .origins
        .iter()
        .map(|origin| (&origin.mount, &origin.ty)),
    )
  }

  /// THE CREATE WALK'S OWN LINES, one per built member: a node's through `Creation::node`, an
  /// origin's through `Creation::origin`.
  ///
  /// # Two doors, and the same walk either side of them
  ///
  /// A node states its construction through `AsyncConstructor`; an origin states it through its OWN
  /// face — `Source::build` or `AsyncSource::build` — reached under the mode its declaration named.
  /// Both lines read the same section shape, spend the same bare-options probe and stop at the same
  /// first refusal, so what differs is the door's name and the projection the probe is spelled over.
  ///
  /// The origin's line WAS the node's. `build` signed a `Context` — a running body's window the
  /// create stage has not got — so the walk could not reach it, the road detoured origin
  /// construction through `AsyncConstructor`, and every origin on it wrote a second options seat that
  /// nothing read. The window is `&Resources` on both faces now, and the second seat went with the
  /// detour.
  fn built(&self, creation: &TokenStream, section: &TokenStream) -> Vec<TokenStream> {
    let krate = self.krate;
    // The probes are reached through the SHELF like every other framework name: a `#[macro_export]`
    // macro lives at the crate root, and `drive` re-exports it so that the module path the shelf
    // mirrors exists — the four gates' own arrangement, one organ over.
    let bare = framework(krate, &["drive"], "bare_options");
    let bare_origin = framework(krate, &["drive"], "bare_origin_options");

    let nodes = self.mounts.iter().zip(self.nodes).map(|(mount, node)| {
      let key = mount.to_string();
      quote! {
        __ingraph_nodes.#mount = #creation::node::<#node>(
          &mut __ingraph_creation,
          #key,
          ::core::option::Option::map(options.#mount, #section::unshelved),
          #bare!(#node),
        ).await?;
      }
    });
    let origins = self.origins.iter().map(|origin| {
      let (mount, ty) = (&origin.mount, &origin.ty);
      let key = mount.to_string();
      quote! {
        __ingraph_nodes.#mount = #creation::origin::<#ty>(
          &mut __ingraph_creation,
          #key,
          ::core::option::Option::map(options.#mount, #section::unshelved),
          #bare_origin!(#ty),
        ).await?;
      }
    });
    nodes.chain(origins).collect()
  }

  /// The node bag and the entry that fills it.
  #[must_use]
  pub fn emit(&self) -> TokenStream {
    let bag = self.bag();
    let takers = self.takers();
    let debug = self.debug();
    let entry = self.entry();
    let converged = self.converged();
    quote! {
      #bag
      #takers
      #debug
      #entry
      #converged
    }
  }

  /// `<Root>Nodes` — one slot per declared mount, `None` for the ones this deployment does not
  /// launch.
  fn bag(&self) -> TokenStream {
    let vis = self.vis;
    let root = self.root;
    let name = default_nodes_name(root);
    let fields = self.built_members().map(|(mount, node)| {
      let doc = leading(&format!(
        "The member this deployment built at `{mount}` — `None` where it does not launch one."
      ));
      quote! {
        #[doc = #doc]
        pub(crate) #mount: ::core::option::Option<#node>,
      }
    });
    let doc = leading(&format!(
      "What one launch of [`{root}`] BUILT — one slot per declared node and one per declared \
       ORIGIN, filled for the ones this deployment runs.\n\nIt is the create walk's product and the \
       wiring stage's input: a member comes out of it once, by the mount name its section was \
       written under, and goes into the resident that will run it — or, for an origin, onto the \
       engine its own life runs on. A slot left `None` is presence-is-enablement arriving at the \
       far end — nobody named that member, so nothing was built for it, and there is nothing to \
       wire."
    ));
    quote! {
      #[doc = #doc]
      #vis struct #name {
        #(#fields)*
      }
    }
  }

  /// One `take_<mount>` per node — the door the wiring closure spends a built value through.
  ///
  /// A TAKE rather than a borrow, because a resident OWNS the operator it runs: the value has to
  /// leave the bag, and it may leave it once. `Assembly::take_cadences` is the same verb one stage
  /// on, for the same reason.
  fn takers(&self) -> TokenStream {
    let vis = self.vis;
    let name = default_nodes_name(self.root);
    let takers = self.built_members().map(|(mount, node)| {
      let take = format_ident!("take_{mount}");
      let doc = leading(&format!(
        "Take the member built at `{mount}`, leaving the slot empty — `None` where this deployment \
         does not launch it, and `None` again on a second ask."
      ));
      quote! {
        #[doc = #doc]
        #[inline]
        #vis fn #take(&mut self) -> ::core::option::Option<#node> {
          ::core::option::Option::take(&mut self.#mount)
        }
      }
    });
    quote! {
      impl #name {
        #(#takers)*
      }
    }
  }

  /// A `Debug` reporting which slots are FILLED, and never the nodes themselves.
  ///
  /// The options spine's trade, made again for the same reason: a node is the author's type, and
  /// deriving here would put a `Debug` bound on every one of them for the benefit of this line. What
  /// a start-up log wants is which nodes this deployment built, which is exactly what the presence
  /// of each slot says.
  fn debug(&self) -> TokenStream {
    let name = default_nodes_name(self.root);
    let fields = self.built_members().map(|(mount, _ty)| {
      let key = mount.to_string();
      quote!(.field(#key, &::core::option::Option::is_some(&self.#mount)))
    });
    quote! {
      impl ::core::fmt::Debug for #name {
        fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
          f.debug_struct(::core::stringify!(#name))
            #(#fields)*
            .finish()
        }
      }
    }
  }

  /// The catalog half of this root's list — see [`crate::catalog`].
  fn catalog(&self) -> Catalog<'_> {
    Catalog {
      krate: self.krate,
      vis: self.vis,
      root: self.root,
      resources: self.resources,
    }
  }

  /// THE CREATE WALK'S FIRST STEP: every resource whose source the DECLARATION names, built before
  /// anything else and in declaration order.
  ///
  /// Two sources land here and one does not. A `#[ingraph(resource)]` field is built from the
  /// deployment's own section, falling back to the options' `Default` where the document wrote none
  /// — the same probe a bare node section runs at, spelled at the one kind of site that can answer
  /// it. A `factory = "path::fn"` field is built from what that function returns, called by this
  /// walk. A bare `factory` field is neither: its options are the application's to hand over, so it
  /// belongs to `prepare`, which runs immediately after this and still before the first node.
  ///
  /// Both closures are THUNKS because the walk is lazy: a resource nothing enabled demands is never
  /// built, so its section is never read and its initializer is never called.
  ///
  /// The section values are destructured out of the options FIRST, under prefixed bindings. A move
  /// out of one field leaves the rest of the options whole for the node pass, and the prefix is what
  /// keeps a resource mounted at `options` or `plan` from shadowing the entry's own parameters.
  fn resource_pass(&self) -> TokenStream {
    if self.resources.is_empty() {
      return TokenStream::new();
    }
    let krate = self.krate;
    let creation = framework(krate, &["drive"], "Creation");
    let bare = framework(krate, &["drive"], "bare_resource_options");

    let binding = |mount: &syn::Ident| format_ident!("__ingraph_resource_{mount}");
    let catalog = self.catalog();
    let taken = catalog.has_block().then(|| {
      let block = default_resources_name(self.root);
      let fields = catalog.sections().map(|field| {
        let (mount, held) = (&field.mount, binding(&field.mount));
        quote!(#mount: #held,)
      });
      quote! {
        let #block { #(#fields)* } = options.resources;
      }
    });

    let built = self
      .resources
      .iter()
      .filter(|field| field.source.is_walked())
      .map(|field| {
        let ty = &field.ty;
        let sourced = match &field.source {
          ResourceSource::Section => {
            let held = binding(&field.mount);
            quote!(move || ::core::option::Option::or_else(#held, || #bare!(#ty)))
          }
          ResourceSource::Initializer(path) => quote!(|| ::core::option::Option::Some(#path())),
          // Filtered out above: a bare `factory` is the application's own door.
          ResourceSource::Prepare => TokenStream::new(),
        };
        // THE `teardown` WORD, cashed: the only difference the word makes anywhere is which of the
        // two doors this line names, and the one it names is what puts the built handle in the
        // context's own release list — said LAST of everything the launch built.
        let door = if field.teardown {
          quote!(declared_resource_saying_goodbye)
        } else {
          quote!(declared_resource)
        };
        quote! {
          #creation::#door::<#ty, _>(&mut __ingraph_creation, #sourced).await?;
        }
      });

    quote! {
      #taken
      #(#built)*
    }
  }

  /// **LAYER TWO** — one call per slot-bearing member, run after the resources are built and before
  /// the first node.
  ///
  /// # The completeness law, as a position in the walk
  ///
  /// Every mounted target's homes are made HERE, each on the face its own resource declared, and the
  /// whole set finishes before anything is constructed, wired or ignited. So a mixed node — a
  /// `title` in a blocking full-text mount, an `embedding` in an awaited remote one — has both sides
  /// made, and neither is skipped for the other being present: the union of the members' steps is
  /// the cover.
  ///
  /// The BARRIER is structural rather than a discipline: this sits inside the create walk's own
  /// fallible phase, so a refusal takes the same arm every other create failure takes and everything
  /// already built says its goodbyes. A launch that served first would have a request reach a corpus
  /// that does not exist yet.
  ///
  /// # Why the loop is over MEMBERS and not over RESOURCES
  ///
  /// The root holds a list of member types and a list of resource types, and the PAIRING between
  /// them is a fact of neither: which targets a declaration's legs point at is written in the
  /// DECLARATION. A `resources × members` loop here would demand that every mounted target be a
  /// home for every member, which is false of every mixed deployment there is. So the step is
  /// emitted where the pairing is known and the root drives one call per member — with one visitor
  /// per target even so, the create walk keeping the machines it builds.
  fn habitat_pass(&self) -> TokenStream {
    if self.fused.is_empty() {
      return TokenStream::new();
    }
    let krate = self.krate;
    let habitats = framework(krate, &["drive"], "Habitats");
    let steps = self.fused.iter().map(|member| {
      let ty = &member.ty;
      quote! {
        <#ty as #habitats>::make(&mut __ingraph_creation).await?;
      }
    });
    quote!(#(#steps)*)
  }

  /// **THE UNBOUND CORPORA**, stated on the plan before the validate walk — the sole-default law's
  /// own input.
  ///
  /// A leg that WROTE `resource = "…"` is bound at the word and states nothing here. This is the
  /// other case: a corpus that needs a resource of a KIND and named none, which only the
  /// deployment's own catalog can settle — exactly one kind-compatible resource declared and the leg
  /// takes it, zero or several and the launch refuses listing the candidates.
  ///
  /// It is what makes those laws reachable from an EMITTED launch. The resolution has been in the
  /// launch floor since the binding round and had no caller but a hand-wired arrangement, which by
  /// this crate's own rule made it a promise rather than a rule; this is the caller.
  fn binding_pass(&self, plan: &TokenStream) -> TokenStream {
    if self.fused.is_empty() {
      return TokenStream::new();
    }
    let krate = self.krate;
    let habitats = framework(krate, &["drive"], "Habitats");
    let rows = self.fused.iter().map(|member| {
      let ty = &member.ty;
      quote! {
        for __ingraph_corpus in <#ty as #habitats>::UNBOUND {
          __ingraph_plan = #plan::binding(
            __ingraph_plan,
            ::core::convert::Into::into(__ingraph_corpus),
          );
        }
      }
    });
    quote!(#(#rows)*)
  }

  /// **THE MOUNTS**, stated on the plan before the validate walk — every target this root's members
  /// point at, and the reason a read-only deployment gets a store at all.
  ///
  /// A resource is built for whoever holds a `Shared<R>`, and the launch can see one kind of holder:
  /// a node with such a field. The other kind is the WIRE — a search resolver the application hands
  /// the handle to after the launch, which appears in no list this entry reads. Without this pass a
  /// deployment that only READS its corpora asks for nothing, gets no store, and has layer two make
  /// no homes; the first query then opens an index nobody has created.
  ///
  /// The declaration is the party that knows, because the pairing lives there and nowhere else —
  /// `Habitats::TARGETS`, the same rows `make` spends one step apiece on. A write mount and a
  /// read-only mount state it identically: whether some node happens to land into a target is not a
  /// fact about whether that target has to exist.
  ///
  /// What stays lazy is the resource NOTHING points at: a model behind a `Shared<R>` field on a node
  /// this deployment does not launch is still never built.
  fn mount_pass(&self, plan: &TokenStream) -> TokenStream {
    if self.fused.is_empty() {
      return TokenStream::new();
    }
    let krate = self.krate;
    let habitats = framework(krate, &["drive"], "Habitats");
    let rows = self.fused.iter().map(|member| {
      let ty = &member.ty;
      quote! {
        for __ingraph_mount in <#ty as #habitats>::TARGETS {
          __ingraph_plan = #plan::mounting(__ingraph_plan, __ingraph_mount());
        }
      }
    });
    quote!(#(#rows)*)
  }

  /// `mut` where there is a MEMBER whose unbound corpora could be stated on the plan — the same rule
  /// [`mutable`](Self::mutable) keeps one stage on, and for the same reason: an emitted `mut` nobody
  /// spends is a warning in somebody else's crate.
  ///
  /// The hand-wired door has no use for it: there the plan is a PARAMETER, so what varies is whether
  /// it is rebound at all — see [`entry`](Self::entry).
  fn mutable_plan(&self) -> TokenStream {
    if self.fused.is_empty() {
      TokenStream::new()
    } else {
      quote!(mut)
    }
  }

  /// The NODE BAG, empty — one `None` per declared mount, filled in as the create walk builds.
  ///
  /// The bag is declared BEFORE the fallible steps and filled slot by slot, rather than written as
  /// one struct literal over N calls, and that is the pre-ignition unwind's whole precondition: a
  /// literal's earlier temporaries are dropped by the `?` that abandons it, so the values a refusal
  /// leaves behind would be gone before anything could say goodbye to them. Filled in place, they
  /// are still the walk's, and [`staged_from_bag`](Self::staged_from_bag) is what reaches them.
  fn empty_bag(&self) -> TokenStream {
    let bag = default_nodes_name(self.root);
    let slots = self
      .built_members()
      .map(|(mount, _ty)| quote!(#mount: ::core::option::Option::None,));
    quote!(#bag { #(#slots)* })
  }

  /// `mut` where there is a MEMBER to spend it on — a node or an origin.
  ///
  /// A root whose fields are all resources builds nothing, so its bag is never assigned into — and
  /// an emitted `mut` nobody uses is a warning in somebody else's crate, which is the one thing an
  /// expansion may not leave behind.
  fn mutable(&self) -> TokenStream {
    if self.mounts.is_empty() && self.origins.is_empty() {
      TokenStream::new()
    } else {
      quote!(mut)
    }
  }

  /// `mut` where there is a GOODBYE LEDGER to push to — the NODE tier alone.
  ///
  /// [`mutable`](Self::mutable)'s narrower twin, and the two differ for a reason worth stating
  /// rather than deriving: an origin is never STAGED. `Staging::declared` is written over
  /// `Declared`, whose `TEARDOWN` word and `goodbye` an origin has neither of — `#[ingraph::source]`
  /// emits no teardown seat, so an origin's whole wind-down is its own [`Drop`], which is the
  /// shipped posture for every value that enrols in no other. So a root with origins and no nodes
  /// has a bag that IS assigned into and a ledger that is not.
  fn mutable_staged(&self) -> TokenStream {
    if self.mounts.is_empty() {
      TokenStream::new()
    } else {
      quote!(mut)
    }
  }

  /// THE CREATE WALK'S OWN LEDGER: every node the bag still holds, in declaration order.
  ///
  /// Declaration order IS enrolment order, and the chain says its list backwards — so nothing here
  /// reverses anything.
  fn staged_from_bag(&self) -> TokenStream {
    let krate = self.krate;
    let bag = default_nodes_name(self.root);
    let staging = framework(krate, &["drive"], "Staging");
    let taken = self.mounts.iter().zip(self.nodes).map(|(mount, node)| {
      let take = format_ident!("take_{mount}");
      let key = mount.to_string();
      quote! {
        if let ::core::option::Option::Some(__ingraph_value) =
          #bag::#take(&mut __ingraph_nodes)
        {
          #staging::declared::<#node>(&mut __ingraph_staged, #key, __ingraph_value);
        }
      }
    });
    let mutable = self.mutable_staged();
    quote! {
      {
        let #mutable __ingraph_staged = #staging::new();
        #(#taken)*
        __ingraph_staged
      }
    }
  }

  /// THE WIRING WALK'S LEDGER: each mount's wired-but-unignited party, or the value the wiring
  /// never reached.
  ///
  /// One or the other and never both — a node leaves the bag exactly when its resident is made — so
  /// the two arms of the match are the two places one mount's value can be at the moment a wiring
  /// step refuses. A party that WAS wired is staged as its operator alone: the rest of the resident
  /// goes first, which is what lets the resource a goodbye reaches for be one handle closer to
  /// releasable.
  fn staged_from_bodies(&self) -> TokenStream {
    let krate = self.krate;
    let bag = default_nodes_name(self.root);
    let staging = framework(krate, &["drive"], "Staging");
    let taken = self.mounts.iter().zip(self.nodes).map(|(mount, node)| {
      let mounted = self.mounted(node);
      let body = format_ident!("__ingraph_body_{mount}");
      let take = format_ident!("take_{mount}");
      let key = mount.to_string();
      quote! {
        match ::core::option::Option::take(&mut #body) {
          ::core::option::Option::Some(__ingraph_body) => {
            // WHERE the value has got to by now is the CELL's business: inside a resident at the
            // buffered pair, in a lane mount's warm set at the streaming one.
            #mounted::stage(&mut __ingraph_staged, #key, __ingraph_body);
          }
          ::core::option::Option::None => {
            if let ::core::option::Option::Some(__ingraph_value) =
              #bag::#take(&mut __ingraph_nodes)
            {
              #staging::declared::<#node>(&mut __ingraph_staged, #key, __ingraph_value);
            }
          }
        }
      }
    });
    let mutable = self.mutable_staged();
    quote! {
      {
        let #mutable __ingraph_staged = #staging::new();
        #(#taken)*
        __ingraph_staged
      }
    }
  }

  /// `<Root>::launch` — the ruled sequence, walked once.
  fn entry(&self) -> TokenStream {
    let krate = self.krate;
    let vis = self.vis;
    let root = self.root;
    let options = default_options_name(root);
    let bag = default_nodes_name(root);

    let app = framework(krate, &["drive"], "App");
    let constructor = framework(krate, &["drive"], "AsyncConstructor");
    let creation = framework(krate, &["drive"], "Creation");
    let ignition = framework(krate, &["drive"], "Ignition");
    let launch_error = framework(krate, &["drive"], "LaunchError");
    let plan = framework(krate, &["drive"], "Plan");
    let wired = framework(krate, &["drive"], "Wired");
    let wiring = framework(krate, &["drive"], "Wiring");
    let registries = framework(krate, &["drive"], "Registries");

    let prepare = parameter("PREPARE");
    let wire = parameter("WIRE");

    // One `AsyncConstructor::Error` predicate per declared node, discharged at the call site exactly as
    // the walk's `Describe` predicates are: a root nobody launches carries no obligation, and a node
    // whose error cannot be erased is refused where the launch is written.
    let errors = self.nodes.iter().map(|node| {
      quote! {
        <#node as #constructor>::Error:
          ::core::error::Error + ::core::marker::Send + ::core::marker::Sync + 'static,
      }
    });

    // THE ORIGINS OWE THE SAME THING THROUGH THEIR OWN ROW. A hand-wired door builds every member
    // the create walk can build — an origin is constructed from its own section exactly as a node is
    // — and leaves the ARRANGEMENT to the caller, who states the plan and holds the wiring walk. So
    // the origin comes out of this door in the bag, and the closure that already names the
    // operators' types is the party that spells `Wiring::bridge` and `Ignition::origin_bridged` over
    // it. `launch`/`launch_with` are where the framework does that itself.
    //
    // What it takes to BUILD one is the row and the erasable error under it, and no more: this door
    // ignites nothing, so the `Produced`/`Ordered` mobility the converged road asks for is not owed
    // here. `Lived<Mode>` is what carries the construction, so it is named even though this door
    // never drives the life — the two verbs are one row, per the trait's own note.
    let lived = framework(krate, &["drive"], "Lived");
    let declared_origin = framework(krate, &["source"], "DeclaredOrigin");
    let died = framework(krate, &["drive"], "Died");
    let origin_errors = self.origins.iter().map(|origin| {
      let ty = &origin.ty;
      quote! {
        #ty: #declared_origin + #lived<<#ty as #declared_origin>::Mode>,
        #died<#ty>:
          ::core::error::Error + ::core::marker::Send + ::core::marker::Sync + 'static,
      }
    });

    // The same predicate for the RESOURCES, and for the same reason: the create walk erases a
    // resource's own refusal into the launch family, so a resource whose error cannot be erased is
    // refused where the launch is written rather than inside the walk.
    let resource = framework(krate, &["resource"], "AsyncResource");
    let resource_errors = self.resources.iter().map(|field| {
      let ty = &field.ty;
      quote! {
        <#ty as #resource>::Error:
          ::core::error::Error + ::core::marker::Send + ::core::marker::Sync + 'static,
      }
    });

    let resources = self.resource_pass();
    let habitat = self.habitat_pass();
    let bindings = self.binding_pass(&plan);
    let mounts = self.mount_pass(&plan);
    // THE PLAN IS REBOUND ONLY WHERE THERE IS SOMETHING TO STATE ON IT. A root that retrieves
    // nothing states no corpus, so the parameter goes straight into the walk and this door's
    // expansion is what it always was — an emitted rename nobody spends would be noise in somebody
    // else's crate, which is the same rule the `mut` above keeps.
    let (held, hold) = if self.fused.is_empty() {
      (quote!(plan), TokenStream::new())
    } else {
      (
        quote!(__ingraph_plan),
        quote!(let mut __ingraph_plan = plan;),
      )
    };

    let section = framework(krate, &["drive"], "NodeSection");
    let built = self.built(&creation, &section);
    let empty = self.empty_bag();
    let mutable = self.mutable();
    let staged = self.staged_from_bag();

    // THE ORIGIN PARAGRAPH IS CONDITIONAL, for the same reason the emitted `mut` is: a root that
    // mounts no origin should carry no sentence about one, and a doc attribute is a token like any
    // other — an unconditional paragraph would put this tier's vocabulary in every expansion.
    let origins = if self.origins.is_empty() {
      String::new()
    } else {
      "\n\nAn `#[ingraph(origin)]` field is BUILT by this door and mounted by nobody: the \
       arrangement is the caller's `plan` here, so the origin comes out in the node bag and the \
       `wire` closure — which already names the operators' types — is what opens its edge and puts \
       it on an engine. `launch` is the door that does the whole of it."
        .to_owned()
    };
    let doc = leading(&format!(
      "Launch this deployment of [`{root}`] — validate, create, wire, ignite.\n\n`options` is what \
       this deployment RUNS and `plan` is what the declarations SAY: the entry replaces the plan's \
       enablement with the options' own, so presence-is-enablement enters here and nowhere \
       else.\n\n`prepare` drives the create walk's first two steps — the resources an enabled node \
       demands, and the slots they open — because naming a resource type or a slot's declaration is \
       something only the party that has them can do. It runs BEFORE any node is built, which is \
       the ruled order: a construction reaching `ctx.shared::<R>()` finds what this put \
       there.\n\n`wire` is handed the built nodes and the wiring walk, and gives back the ignition \
       it filled. It spans the wiring and the engines because both name the operators' types, which \
       an emission cannot. What it does NOT hold is the moment the sources start: this entry spends \
       that, so SOURCES LAST stays a fact of the door rather than a rule a caller keeps.{origins}\n\n# \
       Errors\n\nEvery refusal of the sequence, under one type: the validate walk's whole \
       collected list, or the first failure of any walk after it — a resource that would not load, \
       a node that would not build, an edge that would not connect, an engine that would not start."
    ));

    let syncs = self.nodes.iter().map(|node| {
      let mounted = self.mounted(node);
      quote!(#mounted::SYNC)
    });
    let all_sync = leading(
      "Whether EVERY node this root mounts is on the blocking face — the deployment's own \
       syncness, folded from one row per mount, read through the MOUNT CELL that node's own two \
       words selected.\n\nIt is a proof and not a switch: nothing in the launch reads it, and \
       nothing can, because stable Rust cannot pick an impl by a const. What it is for is an \
       ASSERTION — `const _: () = assert!(Root::ALL_SYNC);` in a deployment that means to have no \
       awaited body in it, and a diagnostic anywhere the question is worth printing.\n\nIt reads \
       BOTH PAIRS, which is why it is spelled through the cell: `Driven::SYNC` is the buffered \
       pair's row and a `stream` declaration has not got one, so a fold spelled through that trait \
       alone did not compile for a root with a streaming node in it. `Streams::SYNC` is the same \
       fact one pair over.\n\nNo row of it can lie, and it takes two facts to say why. The const \
       is set by the blanket rows and by nothing an author can write, so a node cannot state a \
       syncness its face does not have; and the face itself is pinned against the words the \
       declaration wrote by the `Mount` bound the launch spends beside it, so a mount whose body \
       awaits and whose declaration stayed bare does not compile at all.",
    );

    quote! {
      impl #root {
        #[doc = #all_sync]
        #vis const ALL_SYNC: bool = true #(&& #syncs)*;

        #[doc = #doc]
        #vis async fn launch_wired<#prepare, #wire>(
          options: #options,
          plan: #plan,
          prepare: #prepare,
          wire: #wire,
        ) -> ::core::result::Result<#app<Self>, #launch_error>
        where
          #prepare: ::core::ops::AsyncFnOnce(
            &mut #creation<'_>,
          ) -> ::core::result::Result<(), #launch_error>,
          #wire: ::core::ops::FnOnce(
            #bag,
            #wiring<'_>,
          ) -> ::core::result::Result<#ignition, #launch_error>,
          #(#errors)*
          #(#origin_errors)*
          #(#resource_errors)*
        {
          let __ingraph_enablement = #options::enablement(&options);
          // THE ROOT-KEY REGISTRIES, built from this deployment's own `[registry]` section — and
          // read HERE rather than at the wiring walk, because the per-mount sections below are
          // MOVED out of `options` one field at a time and a borrow of a partly-moved value is not
          // a borrow.
          let __ingraph_registries = ::std::sync::Arc::new(
            #registries::new(::core::clone::Clone::clone(#options::registry(&options))),
          );
          // THE SOLE-DEFAULT LAW'S INPUT, stated before the walk that resolves it: every corpus
          // whose leg named no resource, read off the member that owns it — and beside it every
          // target those legs DID name, which is what makes this deployment mount them.
          #hold
          #bindings
          #mounts
          let __ingraph_wired = #plan::validate(
            #plan::with_resources(
              #plan::with_enablement(#held, __ingraph_enablement),
              Self::resources(),
            ),
          )?;
          let mut __ingraph_creation = #wired::create(&__ingraph_wired);
          let #mutable __ingraph_nodes = #empty;
          // THE PRE-IGNITION UNWIND, create half: one arm for the whole fallible walk, so a
          // refusal at any step reaches the values every step before it built. The outcome is
          // BOUND rather than matched in place — the block borrows the walk it refuses about, and
          // the unwind consumes it.
          let __ingraph_created = async {
            #resources
            prepare(&mut __ingraph_creation).await?;
            // LAYER TWO, before the first node: a construction reaching a corpus finds it made.
            #habitat
            #(#built)*
            ::core::result::Result::<(), #launch_error>::Ok(())
          }.await;
          if let ::core::result::Result::Err(__ingraph_error) = __ingraph_created {
            return ::core::result::Result::Err(
              #creation::unwind(__ingraph_creation, #staged, __ingraph_error),
            );
          }
          let __ingraph_ignition = wire(
            __ingraph_nodes,
            {
              // The hand-wiring closure is handed a walk that ALREADY carries this deployment's
              // registries, so a by-hand arrangement coordinates through the same tables an
              // emitted one does without having to know they exist.
              let mut __ingraph_wiring = #creation::wire(__ingraph_creation);
              #wiring::set_registries(&mut __ingraph_wiring, __ingraph_registries);
              __ingraph_wiring
            },
          )?;
          ::core::result::Result::Ok(#ignition::into_app::<Self>(__ingraph_ignition))
        }
      }
    }
  }
}

/// **THE CONVERGENCE** — the door a deployment goes through when nothing is wired by hand.
///
/// `launch_wired` above takes the topology, the create hook and the wiring closure as parameters,
/// because a root's own declaration states none of the three. The facts trait is what changed that:
/// a node STATES its effect, its lane, its edges and its options type, and the root NAMES them
/// through `<Field as Declared>::…`. So the plan is no longer handed over — it is JOINED here — and
/// the wiring closure is no longer needed, because the one thing it could do that this cannot is
/// attach a value only the author can name.
///
/// # What still needs a hand, and it is exactly one thing
///
/// `prepare`. A bare `factory` resource's options close over something the application holds — a
/// live handle, a socket, a directory it just made — and no declaration can state a value. So there
/// are two doors here and not one: [`launch`] for a deployment that needs no hand at all, and
/// `launch_with` for one whose resources take the application's own. They are the same walk;
/// the first calls the second with a closure that does nothing.
///
/// # What the wiring closure could do that this cannot
///
/// Attach a WRITE LANE, a poll context or a journal to a resident. Each of them changes the
/// resident's TYPE and each is a value the author's own code holds, so a walk that has only the
/// declarations cannot name one. A node declaring `AsyncLands` therefore comes out of this door carrying
/// no lane, exactly as it does out of `Wiring::resident` — the launch floor's own honest posture,
/// one layer up. `launch_wired` stays for the deployments that have one to attach.
impl LaunchEntry<'_> {
  /// The two converged doors, and the walk they share.
  fn converged(&self) -> TokenStream {
    let krate = self.krate;
    let vis = self.vis;
    let root = self.root;
    let options = default_options_name(root);
    let bag = default_nodes_name(root);

    let app = framework(krate, &["drive"], "App");
    let blueprint = framework(krate, &["drive"], "Blueprint");
    let creation = framework(krate, &["drive"], "Creation");
    let declared = framework(krate, &["drive"], "Declared");
    let ignition = framework(krate, &["drive"], "Ignition");
    // The equation's own name is spelled inside `predicates`; the walk below spends the rest.
    let launch_error = framework(krate, &["drive"], "LaunchError");
    let plan = framework(krate, &["drive"], "Plan");
    let wired = framework(krate, &["drive"], "Wired");
    let wiring = framework(krate, &["drive"], "Wiring");
    let registries = framework(krate, &["drive"], "Registries");
    let produced_of = framework(krate, &["drive"], "Produced");
    let prepare = parameter("PREPARE");

    let predicates = self.predicates();
    let resources = self.resource_pass();
    let habitat = self.habitat_pass();
    let bindings = self.binding_pass(&plan);
    let mounts = self.mount_pass(&plan);
    let mutable_plan = self.mutable_plan();

    // ONE LINE PER FIELD, AND IT MOUNTS EITHER KIND. The door is not named here — the CELL is, and
    // the cell is what the node's own `stream` word selected: `Blueprint::node` for a buffered
    // declaration and `Blueprint::stream` for a streaming one. This expansion cannot see the word
    // and does not have to.
    let handles = self.mounts.iter().zip(self.nodes).map(|(mount, node)| {
      let mounted = self.mounted(node);
      let handle = format_ident!("__ingraph_at_{mount}");
      let key = mount.to_string();
      quote! {
        let #handle = #mounted::declare(&mut __ingraph_blueprint, #key);
      }
    });

    // THE ORIGINS, declared through their own door and with NO cell in front of it. A node's line is
    // addressed to `Worn<Pair, Mode>` because the pair word lives on the node's own declaration and
    // this expansion cannot see it; an origin has no pair axis at all — the mode axis it does have
    // is already collapsed inside `Lived<M>`, which `Blueprint::origin` and `Ignition::origin_kept`
    // are each written once over — so there is nothing here for a cell to dispatch on and the door
    // is named directly.
    let origin_handles = self.origins.iter().map(|origin| {
      let (mount, ty) = (&origin.mount, &origin.ty);
      let handle = format_ident!("__ingraph_at_{mount}");
      let key = mount.to_string();
      quote! {
        let #handle = #blueprint::origin::<#ty>(&mut __ingraph_blueprint, #key);
      }
    });

    let section = framework(krate, &["drive"], "NodeSection");
    // THE PER-NODE STREAM SEATS, taken before the sections are moved out — the `channels` block's
    // own arrangement, one row over. `None` is what a section that wrote none states and what a
    // buffered mount always gets, so a deployment with no streaming node in it builds no seats at
    // all.
    let seats = self.mounts.iter().map(|mount| {
      let seat = format_ident!("__ingraph_seats_{mount}");
      quote! {
        let #seat = ::core::option::Option::map(
          ::core::option::Option::and_then(
            ::core::option::Option::as_ref(&options.#mount),
            #section::stream,
          ),
          ::core::clone::Clone::clone,
        );
      }
    });

    // THE SHELF, read before the sections are moved out: a `channels` block a deployment wrote is
    // what wins over the author's declared default and over the framework's shipped constant, and
    // this is the road that layer travels. A node whose section says nothing is left to the two
    // layers under it.
    let channels = framework(krate, &["drive"], "Channels");
    let tuned = self.mounts.iter().map(|mount| {
      let key = mount.to_string();
      quote!(.mounted(#key, ::core::option::Option::as_ref(&options.#mount)))
    });

    // ONE LINE PER MEMBER THE CREATE WALK BUILDS, origins among them — each through its own tier's
    // door, per `built`. Construction is where the two tiers read the same section and spend the same
    // probe, and nothing about the difference between them is reached yet.
    let built = self.built(&creation, &section);
    let empty = self.empty_bag();
    let mutable = self.mutable();
    let staged_bag = self.staged_from_bag();
    let staged_bodies = self.staged_from_bodies();

    // The per-mount holders, declared BEFORE the wiring's own fallible walk so that ONE arm can
    // reach every one of them — the same precondition the empty bag serves one stage earlier.
    let holders = self.mounts.iter().map(|mount| {
      let body = format_ident!("__ingraph_body_{mount}");
      let feed = format_ident!("__ingraph_feed_{mount}");
      let intake = format_ident!("__ingraph_intake_{mount}");
      quote! {
        let mut #body = ::core::option::Option::None;
        let mut #feed = ::core::option::Option::None;
        let mut #intake = ::core::option::Option::None;
      }
    });

    // ONE HOLDER PER ORIGIN, carrying all three things its ignition needs at once — the built value,
    // the far half of its out-edge, and its enrolment. They travel together because they are taken
    // together: the enrolment is minted on the WIRING walk (the ignition has no registry to ask) and
    // spent on the ignition one, and an enrolment made for an origin whose value or edge turned out
    // to be absent would be a party the shutdown waits on and nothing ever settles.
    let origin_holders = self.origins.iter().map(|origin| {
      let mount = &origin.mount;
      let bridge = format_ident!("__ingraph_bridge_{mount}");
      quote!(let mut #bridge = ::core::option::Option::None;)
    });

    // THE INTAKE PASS, and it is a pass of its own rather than the first two lines of the next one.
    //
    // An edge is OPENED by whichever side reaches it first, and its type is the CONSUMER's input.
    // A producer whose downstream set has several products cannot open one — which product an edge
    // carries is written in the consumer's own declaration, and this walk holds names rather than
    // types — so it seats the product that consumer's inbox already named. That is only possible if
    // every mounted node's receiving halves have been taken before any node is wired, which is what
    // this pass is: field order stops being load-bearing, and a demultiplexer declared before its
    // subscribers mounts exactly as one declared after them does.
    //
    // The bag is NOT drawn from here. A refusal in the pass below has to find every unwired node's
    // value still in it — that is what the pre-ignition unwind stages goodbyes from — so the value
    // stays where it was and only the edges are opened. The two are the same set: `Creation::node`
    // fills the bag exactly for the nodes this deployment launches, and `Mount::intake` answers
    // `None` for exactly the ones it does not.
    let intakes = self.mounts.iter().zip(self.nodes).map(|(mount, node)| {
      let mounted = self.mounted(node);
      let handle = format_ident!("__ingraph_at_{mount}");
      let intake = format_ident!("__ingraph_intake_{mount}");
      quote! {
        // THE CONTAINER ENTRY. What comes back is the RECEIVING HALVES in the shape this node's own
        // cell takes them in — ONE inbox at the two driven pairs, and the whole N-edge `Upstreams`
        // set at the autonomous one, position by declaration order. This expansion cannot see which
        // shape its node wants and does not have to: `Mount::Intake` is the cell answering on the
        // declaration's behalf.
        #intake = #mounted::intake(&mut __ingraph_wiring, #handle)?;
      }
    });

    let wire = self.mounts.iter().zip(self.nodes).map(|(mount, node)| {
      let mounted = self.mounted(node);
      let handle = format_ident!("__ingraph_at_{mount}");
      let body = format_ident!("__ingraph_body_{mount}");
      let feed = format_ident!("__ingraph_feed_{mount}");
      let intake = format_ident!("__ingraph_intake_{mount}");
      let seat = format_ident!("__ingraph_seats_{mount}");
      let take = format_ident!("take_{mount}");
      quote! {
        if let ::core::option::Option::Some(__ingraph_operator) = #bag::#take(&mut __ingraph_nodes) {
          if let ::core::option::Option::Some(__ingraph_intake) =
            ::core::option::Option::take(&mut #intake)
          {
            // A node the graph itself feeds has no door for anybody else to open — a HEAD is the
            // one that is fed from outside, and having no declared source IS what makes it one. It
            // publishes into slot zero, which is the one edge a head has.
            if <#node as #declared>::UPSTREAMS.is_empty() {
              #feed = #wiring::outbox::<#mounted::In>(
                &mut __ingraph_wiring,
                #handle,
              )?;
            }
            #body = #mounted::wire(
              &mut __ingraph_wiring,
              #handle,
              __ingraph_operator,
              __ingraph_intake,
              #seat,
            )?;
          }
        }
      }
    });

    // **THE BRIDGE**, opened on the wiring walk and from the PRODUCER's end. Which consumer an
    // origin feeds is written in that consumer's own `subscribe(…)` and joined into the plan by type
    // identity, so this expansion never names it: `Wiring::bridge` reads the origin's ONE channel
    // out-edge off the arrangement and answers the sending half under the origin's own `Produced`
    // projection.
    //
    // The value is taken out of the bag HERE rather than at the ignition, and the order inside the
    // block is the reason: an origin whose edge could not be opened — its consumer dark, or itself
    // not launched — must leave its value where the pre-ignition unwind can still find it, and must
    // not enrol a party that will never settle. So the edge is asked for FIRST and the take happens
    // only once all three parts exist.
    let bridges = self.origins.iter().map(|origin| {
      let (mount, ty) = (&origin.mount, &origin.ty);
      let handle = format_ident!("__ingraph_at_{mount}");
      let bridge = format_ident!("__ingraph_bridge_{mount}");
      let take = format_ident!("take_{mount}");
      let key = mount.to_string();
      let produced = quote!(#produced_of<#ty>);
      quote! {
        if let ::core::option::Option::Some(__ingraph_consumer) =
          #wiring::bridge::<#produced>(&mut __ingraph_wiring, #handle)?
        {
          if let ::core::option::Option::Some(__ingraph_origin) =
            #bag::#take(&mut __ingraph_nodes)
          {
            #bridge = ::core::option::Option::Some((
              __ingraph_origin,
              __ingraph_consumer,
              #wiring::enrol(&mut __ingraph_wiring, #key),
            ));
          }
        }
      }
    });

    let ignite = self.mounts.iter().zip(self.nodes).map(|(mount, node)| {
      let mounted = self.mounted(node);
      let body = format_ident!("__ingraph_body_{mount}");
      let feed = format_ident!("__ingraph_feed_{mount}");
      // BOTH WORDS ARE THE DOOR'S OWN BUSINESS: the cell reads `<#node as Declared>::Pair` and
      // `::Mode` off the declaration this expansion cannot see, so what is written here is one
      // line that starts a THREAD under a buffered body and hands a mounted LANE to the app's
      // cupboard for a streaming one — the party that drives a lane being the party that holds it.
      quote! {
        if let ::core::option::Option::Some(__ingraph_feeder) = #feed {
          #mounted::feeder(&mut __ingraph_ignition, __ingraph_feeder);
        }
        if let ::core::option::Option::Some(__ingraph_body) = #body {
          #mounted::ignite(&mut __ingraph_ignition, __ingraph_body)?;
        }
      }
    });

    // **THE ORIGINS, LAST OF ALL** — after every node this deployment runs has its engine, so a
    // producer that is STARTED ONCE and runs on its own never waits on a consumer that has not been
    // spawned yet. Nothing depends on this for correctness — the edge is bounded and a full one is
    // ordinary backpressure — and it is the same *last on, first off* the whole stage is arranged
    // around: an origin hears the wind-down at `App::shutdown`'s first step, before a source stops
    // admitting and before the framework lets go of any edge.
    //
    // `origin_kept` rather than `origin_bridged` because a `Bridged` owns a `Stopper` and a stopper
    // SAYS THE STOP AS IT GOES: an expansion has nowhere to put a returned handle, so a walk that
    // dropped one would wind down the origin it had just started. The world keeps it, and
    // `App::origin::<S>()` is where a deployment reaches it.
    let origin_ignite = self.origins.iter().map(|origin| {
      let (mount, ty) = (&origin.mount, &origin.ty);
      let bridge = format_ident!("__ingraph_bridge_{mount}");
      let key = mount.to_string();
      quote! {
        if let ::core::option::Option::Some(
          (__ingraph_origin, __ingraph_consumer, __ingraph_party)
        ) = #bridge {
          #ignition::origin_kept::<#ty>(
            &mut __ingraph_ignition,
            #key,
            __ingraph_origin,
            __ingraph_consumer,
            // THE COMMAND LINE'S DEPTH, and it governs that line ALONE: a bridged feed is bounded by
            // the EDGE, resolved from the declarations and this deployment's own document like every
            // other edge. What is left for a number is the door an application says things to the
            // origin down, and a door's depth is the framework's shipped answer — a queue of callers
            // who are all waiting, where depth buys latency rather than throughput.
            #wiring::DOOR_CAPACITY,
            __ingraph_party,
          )?;
        }
      }
    });

    // Conditional, for the reason the hand-wired door's own paragraph is: a root that mounts no
    // origin carries no sentence about one.
    let origins = if self.origins.is_empty() {
      String::new()
    } else {
      "\n\nAn `#[ingraph(origin)]` field is mounted here too, and is mounted LAST: a source is a \
       HEAD the graph does not feed, so what it gets is an engine of its own and its one out-edge \
       as its feed. See `App::origin` for the two ends this world then keeps — and note that it \
       KEEPS them, because letting go of that handle is telling the origin to wind down."
        .to_owned()
    };
    let plain_doc = leading(&format!(
      "**Launch this deployment of [`{root}`] — and wire NOTHING by hand.**\n\nThe whole ruled \
       sequence from one value: the arrangement is joined from what each declared node states about \
       itself, the deployment's own sections decide who runs, the resources an enabled node demands \
       are built before the first construction, the edges are opened and the engines \
       started.{origins}\n\nWhat \
       comes back is the running world, with an intake door onto every head — see [`App::feeder`]. \
       Use [`launch_with`](Self::launch_with) where a `factory` resource's options are the \
       application's own to hand over.\n\n# Errors\n\nEvery refusal of the sequence, under one type: \
       an upstream this root does not mount, the validate walk's whole collected list, or the first \
       failure of any walk after it."
    ));
    let hooked_doc = leading(&format!(
      "Launch this deployment of [`{root}`], giving the create walk the application's own \
       hand.\n\n[`launch`](Self::launch)'s walk exactly, with `prepare` run after the declared \
       resources are built and BEFORE the first node — which is the ruled order, and what makes a \
       construction reaching `ctx.shared::<R>()` find what this put there. It is where a bare \
       `#[ingraph(resource(factory))]` gets its options, because those close over a value the \
       application holds and no declaration can state one.\n\n# Errors\n\nSee \
       [`launch`](Self::launch)."
    ));

    quote! {
      impl #root {
        #[doc = #plain_doc]
        #vis async fn launch(
          options: #options,
        ) -> ::core::result::Result<#app<Self>, #launch_error>
        where
          #predicates
        {
          Self::launch_with(options, async |_| ::core::result::Result::Ok(())).await
        }

        #[doc = #hooked_doc]
        #vis async fn launch_with<#prepare>(
          options: #options,
          prepare: #prepare,
        ) -> ::core::result::Result<#app<Self>, #launch_error>
        where
          #prepare: ::core::ops::AsyncFnOnce(
            &mut #creation<'_>,
          ) -> ::core::result::Result<(), #launch_error>,
          #predicates
        {
          // THE ARRANGEMENT, joined: one call per mounted field, in declaration order, and the
          // edges appear by themselves — each node's declared upstreams are looked up among these
          // very fields by type identity.
          let mut __ingraph_blueprint = #blueprint::new();
          #(#handles)*
          #(#origin_handles)*
          let #mutable_plan __ingraph_plan = #blueprint::into_plan(__ingraph_blueprint)?;
          // THE SOLE-DEFAULT LAW'S INPUT, stated before the walk that resolves it: every corpus
          // whose leg named no resource, read off the member that owns it — and beside it every
          // target those legs DID name, which is what makes this deployment mount them.
          #bindings
          #mounts

          let __ingraph_enablement = #options::enablement(&options);
          // THE ROOT-KEY REGISTRIES, built from this deployment's own `[registry]` section — and
          // read HERE rather than at the wiring walk, because the per-mount sections below are
          // MOVED out of `options` one field at a time and a borrow of a partly-moved value is not
          // a borrow.
          let __ingraph_registries = ::std::sync::Arc::new(
            #registries::new(::core::clone::Clone::clone(#options::registry(&options))),
          );
          let __ingraph_channels = #channels::new() #(#tuned)*;
          #(#seats)*
          let __ingraph_wired = #plan::validate(
            #plan::with_channels(
              #plan::with_resources(
                #plan::with_enablement(__ingraph_plan, __ingraph_enablement),
                Self::resources(),
              ),
              __ingraph_channels,
            ),
          )?;
          let mut __ingraph_creation = #wired::create(&__ingraph_wired);
          // THE BAG, empty and filled in place — see `LaunchEntry::empty_bag` for why a struct
          // literal could not have been the shape.
          let #mutable __ingraph_nodes = #empty;
          // THE PRE-IGNITION UNWIND, create half. The outcome is BOUND rather than matched in
          // place: the block borrows the walk it refuses about, and the unwind consumes it.
          let __ingraph_created = async {
            #resources
            prepare(&mut __ingraph_creation).await?;
            // LAYER TWO, before the first node: a construction reaching a corpus finds it made.
            #habitat
            #(#built)*
            ::core::result::Result::<(), #launch_error>::Ok(())
          }.await;
          if let ::core::result::Result::Err(__ingraph_error) = __ingraph_created {
            return ::core::result::Result::Err(
              #creation::unwind(__ingraph_creation, #staged_bag, __ingraph_error),
            );
          }

          let mut __ingraph_wiring = #creation::wire(__ingraph_creation);
          // BEFORE ANY BODY IS WIRED: a resident takes its handle as it is built, so this reaches
          // the walk ahead of the first one.
          #wiring::set_registries(&mut __ingraph_wiring, __ingraph_registries);
          #(#holders)*
          #(#origin_holders)*
          // THE PRE-IGNITION UNWIND, wiring half: the parties this walk WIRED and never ignited,
          // beside whatever it never reached.
          let __ingraph_connected = (|| -> ::core::result::Result<(), #launch_error> {
            #(#intakes)*
            #(#wire)*
            #(#bridges)*
            ::core::result::Result::Ok(())
          })();
          if let ::core::result::Result::Err(__ingraph_error) = __ingraph_connected {
            return ::core::result::Result::Err(
              #wiring::unwind(__ingraph_wiring, #staged_bodies, __ingraph_error),
            );
          }
          let mut __ingraph_ignition = #wiring::into_assembly(__ingraph_wiring).ignite();
          #(#ignite)*
          #(#origin_ignite)*
          ::core::result::Result::Ok(#ignition::into_app::<Self>(__ingraph_ignition))
        }
      }
    }
  }

  /// The MOUNT CELL `node` declared, as the type its own two words select.
  ///
  /// `Worn<<#node as Declared>::Pair, <#node as Declared>::Mode>` — the PAIR word and the MODE
  /// word, both of which live on the node's OWN declaration and are invisible to this expansion,
  /// read back through the seats they set. It is what lets one emitted line per field mount either
  /// kind: a `stream` declaration seats `Streaming` and a bare one seats `Buffered`, and each cell
  /// knows its own two doors.
  ///
  /// Two ordinary projections, which is what the pair seat's becoming a TYPE bought. It was a const,
  /// bridged through a `Pair<STREAMS>` carrier and writable only where `#node` is concrete, because
  /// a const argument may not depend on a generic parameter on stable — see `Word` for the mode
  /// axis, which really does carry a const and keeps its bridge.
  fn cell(&self, node: &syn::Type) -> TokenStream {
    let krate = self.krate;
    let declared = framework(krate, &["drive"], "Declared");
    let worn = framework(krate, &["drive"], "Worn");
    quote!(#worn<<#node as #declared>::Pair, <#node as #declared>::Mode>)
  }

  /// [`cell`](Self::cell) as a QUALIFIED PATH — `<Worn<…> as Mount<#node>>`, what every per-node
  /// line the launch emits is addressed to.
  fn mounted(&self, node: &syn::Type) -> TokenStream {
    let krate = self.krate;
    let mount = framework(krate, &["drive"], "Mount");
    let cell = self.cell(node);
    quote!(<#cell as #mount<#node>>)
  }

  /// What each declared node owes, discharged AT THE CALL SITE.
  ///
  /// The same posture the hand-wired door's `AsyncConstructor::Error` predicate already keeps, widened to
  /// everything this walk spends: a root nobody launches carries no obligation, and a node that
  /// cannot be launched is refused where the launch is written rather than where the root is
  /// declared.
  ///
  /// The equation is the one to read twice. `AsyncConstructor<Options = <#node as Declared>::Options>`
  /// pins the type the AUTHOR's constructor takes to the path the DECLARATION named — the `options`
  /// word and the impl beside it, made to agree by the compiler. A declaration that lets them drift
  /// is `E0271`, at the launch, naming both types.
  ///
  /// # THE MOUNT IS ONE LINE, and the five it replaced are implied by it
  ///
  /// `Worn<…>: Mount<#node>` is the whole of what the mount costs. The face the declaration's words
  /// select, and the `Send` / `Clone` / `Error` obligations on the three messages it carries, are
  /// bounds on `Mount`'s own associated types — so they hold wherever the row does, and a predicate
  /// spelling them again here would be one fact written at two altitudes. What stays is the half
  /// `Mount` says nothing about: the node's CONSTRUCTION.
  fn predicates(&self) -> TokenStream {
    let krate = self.krate;
    let constructor = framework(krate, &["drive"], "AsyncConstructor");
    let declared = framework(krate, &["drive"], "Declared");
    let mount = framework(krate, &["drive"], "Mount");
    let resource = framework(krate, &["resource"], "AsyncResource");

    let nodes = self.nodes.iter().map(|node| {
      let cell = self.cell(node);
      quote! {
        #node: #declared
          + #constructor<Options = <#node as #declared>::Options>
          + ::core::marker::Send
          + 'static,
        #cell: #mount<#node>,
        <#node as #constructor>::Error:
          ::core::error::Error + ::core::marker::Send + ::core::marker::Sync + 'static,
      }
    });
    let resources = self.resources.iter().map(|field| {
      let ty = &field.ty;
      quote! {
        <#ty as #resource>::Error:
          ::core::error::Error + ::core::marker::Send + ::core::marker::Sync + 'static,
      }
    });
    let origins = self
      .origins
      .iter()
      .map(|origin| self.origin_predicate(origin));
    quote!(#(#nodes)* #(#resources)* #(#origins)*)
  }

  /// What ONE ORIGIN owes, discharged at the call site exactly as a node's obligations are.
  ///
  /// # It is the node predicate with the CELL taken out, and that is the whole difference
  ///
  /// A node's row is `Declared + AsyncConstructor<Options = <N as Declared>::Options>` plus
  /// `Worn<Pair, Mode>: Mount<N>`, and the mount row is what implies the face and the three
  /// messages' own obligations. An origin has no such row to lean on — there is no pair axis for a
  /// cell to be indexed by — so the two facts a cell would have carried are spelled here instead:
  /// [`DeclaredOrigin`], which is the record `#[ingraph::source]` emits, and `Lived<Mode>`, which is
  /// the FACE the declaration's own `async` word selected. Nothing an author can write fills a
  /// `Lived` row — `Source` and `AsyncSource` do — so a declaration whose word disagrees with its
  /// body is `E0277` here, naming the trait it does not implement.
  ///
  /// The three messages are then named through the projections the origin layer already publishes:
  /// what it PRODUCES crosses onto its engine and down its edge, what it is TOLD crosses down its
  /// command line, and what its DEATH is reported as reaches the taps as an erased error.
  ///
  /// There is NO options equation. A node's `Options = <N as Declared>::Options` pins the
  /// constructor's type to the path its declaration named, because two declarations state it and
  /// they can drift; an origin states it in ONE place — its own face's `Source::Options` — and the
  /// section this spine emits for it is written off that same projection, so the two agree by
  /// construction rather than by a predicate.
  ///
  /// # THE CONSTRUCTION SEAM IS THE FACE'S OWN, and the row that drives is the row that opens
  ///
  /// `Lived<Mode>` carries BOTH verbs: `Lived::open` is `Source::build` under the mode the
  /// declaration named, and `Lived::live` is `Source::run` under it. So the row already spelled for
  /// the drive is the whole of what a construction needs as well, and this predicate names no second
  /// construction trait — `Creation::origin` is bounded on exactly the row above.
  ///
  /// That closes a debt this comment used to record. `build` signed a `Context` — a RUNNING body's
  /// window, whose wind-down line the mount has not minted at the create stage — so nothing in the
  /// framework could call it, and this road detoured origin construction through `AsyncConstructor`,
  /// the door `Creation::node` takes. The visible cost was TWO options seats per origin, one of which
  /// nothing read. `build`'s window is `&Resources` on both faces now, the detour is retired, and
  /// `AsyncConstructor` is left where it belongs — the RESIDENT construction door.
  ///
  /// `Died<#ty>` is therefore the ONE error predicate, and it is one because the face says so: an
  /// origin refuses a construction and a death in a single currency, so the erasure a start-up
  /// refusal needs and the erasure a tap needs are one obligation written once.
  ///
  /// [`DeclaredOrigin`]: ../../ingraph/trait.DeclaredOrigin.html
  fn origin_predicate(&self, origin: &OriginMount) -> TokenStream {
    let krate = self.krate;
    let ty = &origin.ty;
    let declared_origin = framework(krate, &["source"], "DeclaredOrigin");
    let lived = framework(krate, &["drive"], "Lived");
    let produced = framework(krate, &["drive"], "Produced");
    let ordered = framework(krate, &["drive"], "Ordered");
    let died = framework(krate, &["drive"], "Died");
    quote! {
      #ty: #declared_origin
        + #lived<<#ty as #declared_origin>::Mode>
        + ::core::marker::Send
        + 'static,
      #produced<#ty>: ::core::marker::Send,
      #ordered<#ty>: ::core::marker::Send,
      #died<#ty>: ::core::error::Error + ::core::marker::Send + ::core::marker::Sync + 'static,
    }
  }
}