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
//! THE CREATE WALK: what a validated deployment BECOMES, and the one order it can be built in.
//!
//! [`Plan::validate`](super::Plan::validate) answered everything a deployment can be wrong about
//! without touching the world. This is the half that touches it, and it is the opposite kind of walk
//! for a reason that is not a preference: its steps BUILD things, so the second one runs in a world
//! the first one made, and a failure leaves the rest describing a deployment that no longer exists.
//! It stops at the first — [`LaunchError::Construction`] — where the validate walk collects.
//!
//! What it leaves behind is [`unwind`](Creation::unwind)'s: a walk that refuses partway holds
//! everything the steps before it built, so the values that enrolled a goodbye SAY it — in reverse,
//! resources last, through the shutdown's own chain — and everything else is dropped as the error
//! propagates, which is the shipped teardown and the right one for nearly everything. Nothing is a
//! second mechanism: the pre-ignition road differs from the post-ignition one only in where the
//! value was when the chain reached for it.
//!
//! # The order, and what actually depends on what
//!
//! 1. **RESOURCES, demand-scanned.** A resource is built iff this deployment MOUNTS it — a
//! declaration's leg points at it — or at least one ENABLED node demands it; and it is built
//! ONCE. They come first because a node's construction may reach for one:
//! `ctx.shared::<Egemma>()` inside a boot body can only find what an earlier pass put there.
//! 2. **SLOTS.** A store is a resource, so its slots open once the store is in hand, and this is
//! where the pairing between a declaration and an engine is asserted — the ONE production
//! [`SlotHandle::mint`](crate::SlotHandle::mint) site.
//! 3. **NODES**, each from its own section, through [`AsyncConstructor::with_options`] — and the
//! ORIGINS beside them, each from its own section, through its own face's
//! [`Source::build`](crate::Source::build). Two doors and one stage: the tiers are constructed
//! alike and differ only in which trait states the construction, per [`origin`](Creation::origin).
//!
//! Wiring and ignition are the rounds after this one. A create walk hands back constructed values
//! and the [`Resources`] it filled; what edges they get is [`wire`](Creation::wire)'s sentence and
//! when they start is the ignition's.
//!
//! # The resource step has TWO doors, and the CATALOG says which one a resource goes through
//!
//! A resource's declaration names exactly one source for its options, and that is the whole of the
//! single-source law: [`declared_resource`](Creation::declared_resource) serves the two sources a
//! root states on its own — the deployment's `[resources.<mount>]` section and the initialization
//! function a declaration names — and [`resource`](Creation::resource) serves the one the
//! APPLICATION spends by hand, the `prepare` closure. Each reads
//! [`ResourceCatalog::source`](crate::ResourceCatalog::source) before it builds anything and refuses where the
//! declaration named the other, so a second door does not silently win a race it was never meant to
//! be in.
//!
//! Both are lazy in the same way and for the same reason: the options arrive as a THUNK, so a
//! resource nobody demands costs neither a spelled section nor a call to an initializer.
//!
//! # The slot step opens the kind that has a name to open it under
//!
//! A full-text slot's name is [`FulltextTable::SLOT`] and an artifact family's is
//! [`BlobTable::SLOT`], each written on its own declaration — which is what lets the mint read the
//! name and the brand off ONE place. The blob kind's authority arrived with the blob-engine round,
//! so [`async_blob_slot`](Creation::async_blob_slot) and its blocking twin sit beside
//! [`async_fulltext_slot`](Creation::async_fulltext_slot) here.
//!
//! The VECTOR kind still has no such trait, and it is named rather than sketched: its store takes a
//! slot name as a plain argument, so a door for it would have the caller state the pairing, which is
//! exactly the lie the one-mint-site law exists to keep out of production. The width question
//! [`AsyncVectorStore::vector`](crate::AsyncVectorStore::vector) parks in its own note is the second half — a
//! slot electing several embeddings may hold columns of several widths, and whether that is one slot
//! per column or one slot per width is a design act, not a default this walk should pick. A blob
//! store's per-slot factory takes no such second argument, which is why the blob door could be built
//! the day its authority landed and the vector one still cannot.
//!
//! # The walk is DRIVEN, not looped
//!
//! Constructing a node means naming its TYPE, and a graph carries names rather than types — so this
//! layer cannot hold the loop. It holds the STEPS, and the declaration's emission spends them, one
//! call per declared mount, in the order above. That is the division [`Wired`] itself is written
//! for: the checked facts live here, and the party that knows the types spends them.
//!
//! # PRESENCE IS ENABLEMENT, and the section is the only authority for it
//!
//! [`node`](Creation::node) reads whether a node runs off the SECTION it is handed — an absent one
//! is a node that is not built, and that is the whole of the question. It does not read the frozen
//! [`Enablement`](super::Enablement) beside it, and that is what keeps the two from disagreeing:
//! the same sections produced that enablement through the spine's own `enablement()`, so there is
//! one source and no second one to drift from it.
use ;
use Utf8Bytes;
use crate::;
use ;
/// The CREATE walk over a checked deployment: resources, then slots, then nodes.
///
/// Begun with [`Wired::create`], which is the only door — a walk that builds is reachable only from
/// a plan that passed, so nothing constructs anything for a deployment whose refusals have not been
/// read.
///
/// It owns the [`Resources`] it fills and hands it on at the end — to the wiring walk through
/// [`wire`](Self::wire), or to a caller that wires by hand through
/// [`into_context`](Self::into_context). Dropping it instead is the failed launch's own teardown:
/// every resource it built goes with it.
///
/// # Examples
///
/// ```
/// use ingraph::{Context, AsyncConstructor, Resources, NodeSection};
/// # use ingraph::{
/// # DriverKind, Effect, Enablement, GraphBuilder, NodeWiring, Operator, Plan,
/// # };
///
/// struct Decode {
/// threads: usize,
/// }
///
/// struct DecodeOptions {
/// threads: usize,
/// }
///
/// impl Default for DecodeOptions {
/// fn default() -> Self {
/// Self { threads: 4 }
/// }
/// }
///
/// impl AsyncConstructor for Decode {
/// type Options = DecodeOptions;
/// type Error = std::io::Error;
///
/// async fn with_options(_ctx: &Resources, options: DecodeOptions) -> Result<Self, Self::Error> {
/// Ok(Self {
/// threads: options.threads,
/// })
/// }
/// }
///
/// # struct Decoding;
/// # impl Operator for Decoding {
/// # type Error = core::convert::Infallible;
/// # type In = u8;
/// # type Out = u8;
/// # fn accept(&mut self, ctx: &Context, _: ingraph::Delivery<u8>, _: &mut ingraph::Emitter<u8>)
/// # -> Result<(), Self::Error> { Ok(()) }
/// # }
/// # impl ingraph::Declared for Decoding {
/// # const EFFECT: Effect = Effect::Pure;
/// # type Channels = ingraph::Unchanneled;
/// # type Mode = ingraph::Block;
/// # type Options = ();
/// # type Pair = ingraph::Buffered;
/// # type Wires<O> = ingraph::Downstream<O>;
/// # type Attribution<O> = ();
/// # }
/// # let mut builder = GraphBuilder::new();
/// # let mount = builder.source::<Decoding>("decode", DriverKind::Thread);
/// # let plan = Plan::new(builder.validate().expect("one node validates"))
/// # .with_enablement(Enablement::new().launching("decode"))
/// # .wiring(mount.id(), NodeWiring::new(Effect::Lands).landing());
/// // A deployment that passed its checks — one node, named by its section.
/// let wired = plan.validate().expect("the deployment checks out");
///
/// # tokio::runtime::Builder::new_current_thread().build().unwrap().block_on(async {
/// let mut walk = wired.create();
///
/// // A section that states its tuning goes through `with_options`.
/// let decode = walk
/// .node::<Decode>(
/// "decode",
/// Some(NodeSection::new(DecodeOptions { threads: 8 })),
/// ingraph::bare_options!(Decode),
/// )
/// .await
/// .expect("it builds")
/// .expect("the deployment names it");
/// assert_eq!(decode.threads, 8);
///
/// // A node this deployment never named is a node the walk does not build.
/// let absent = walk
/// .node::<Decode>("decode", None, ingraph::bare_options!(Decode))
/// .await
/// .expect("nothing to refuse");
/// assert!(absent.is_none());
/// # });
/// ```
/// THE SINGLE-SOURCE LAW, refused: a resource was built through a door its declaration did not
/// name.
///
/// There is no precedence chain to lose to, and that is the whole reason this is loud. A `prepare`
/// closure beside a document section, or a section beside a named initializer, would be two answers
/// to one question — and the one that won would depend on the order the walk happened to run in,
/// which is exactly the class of surprise a start-up refusal exists to keep out of production. So
/// the door that is not the declared one refuses, and the sentence names the one that IS, because
/// what a reader needs is where the options belong rather than which call to delete.
/// A demanded resource whose declared source produced no options, and whose options cannot be built
/// out of nothing.
///
/// [`MandatoryOptionsError`]'s sentence one tier over, and it is the same rule: a section nobody
/// wrote runs at the options' own [`Default`], and a type without one has said its knobs are
/// mandatory. It names the OPTIONS TYPE for that reason — that is where a reader finds which knobs
/// they now have to write — and the MOUNT, because that is the section they write them in.
/// Written rather than derived, because the ADVICE differs by source and a reader gets one sentence:
/// a document resource is told to write its section, and an initializer is told its function
/// answered with nothing.
/// A resource built through the create walk that the ROOT CATALOG does not carry.
///
/// Unreachable from an emitted launch — the emission drives one call per catalogued field — and
/// reachable from a hand-written one, which is why it is a refusal rather than an assumption. It
/// names the TYPE, because the fix is a declaration: the resource is missing from the root's fields,
/// or from the [`ResourceCatalog`](crate::ResourceCatalog) a hand-wired arrangement states in their place.
/// A launched node or ORIGIN whose section is BARE and whose options cannot be built out of nothing.
///
/// The create-time half of the mandatory-knob rule: a present section with no `options` key runs a
/// member at its options' [`Default`], and a type without one has said that its knobs are not
/// optional. It names the OPTIONS TYPE, because that is where a reader finds which knobs they now
/// have to write — and naming the options rather than the member is also what lets ONE refusal serve
/// both tiers, whose options seats are projected through different traits.
/// THE BARE-SECTION PROBE: does `O` have a [`Default`] for a section with no `options` to run at?
///
/// # Why this is a probe and not a bound
///
/// The walk's `T` is a type PARAMETER, and a bound written on
/// [`Creation::node`](Creation::node) would be a bound on every node a deployment declares — which
/// would make an options type without a `Default` undeclarable, and the mandatory-knob rule says
/// the opposite: such a type is legal, and what it costs is that its sections must carry `options`.
/// So the question has to be asked where the answer exists, and on stable Rust that is a site with a
/// CONCRETE type: an inherent method whose impl block demands `Default` is preferred by method
/// resolution, and where the bound does not hold the candidate is discarded and the autoref one
/// below it answers instead.
///
/// [`bare_options!`](crate::bare_options) is the spelling, and callers should use it: it names the
/// node, projects its options and brings the fallback's trait into scope for exactly one expression.
///
/// # The honest tooth
///
/// The probe answers what the COMPILER can prove at the site it is written. Spelled inside a generic
/// function over an unbounded `O`, `O: Default` cannot be proven there and the answer is `None` —
/// so a wrapper that forwards without the bound turns every bare section into a mandatory-knob
/// refusal. The refusal names the node and the fix, so the failure is loud at start-up rather than
/// silent; the fix for the wrapper is to spell the probe at the site that knows the type, which is
/// the emitted arm and the hand-written launch alike.
>);
/// The arm taken where `O: Default` HOLDS — an inherent method, which method resolution reaches
/// before it autorefs into [`NoDefaultOptions`].
/// The arm taken where `O: Default` does NOT hold — one autoref away from
/// [`BareOptions::resolve`], which is what makes it the fallback rather than an ambiguity.
///
/// Nothing implements this by hand and nothing should: it exists to be the second candidate in one
/// method lookup, and its blanket impl over `&BareOptions<O>` is the whole of it.
/// The options a resource mounted with NO document section runs at — `Some` at the options'
/// [`Default`], `None` where the type has none.
///
/// [`bare_options!`](crate::bare_options)'s sibling one tier over, and the probe under it is the
/// same one for the same reason: the answer exists only where the type is CONCRETE, so a macro is
/// what puts the question at a call site that has one. What differs is the projection — a resource's
/// options are `<R as AsyncResource>::Options` — and what does not is everything else, including the
/// honest tooth [`BareOptions`] records.
///
/// It is what the emitted create walk hands
/// [`declared_resource`](crate::Creation::declared_resource) for a `#[ingraph(resource)]` field: the
/// section where the deployment wrote one, and this where it did not.
///
/// # Examples
///
/// ```
/// # use ingraph::Resources;
/// use ingraph::AsyncResource;
///
/// struct Egemma;
/// struct EgemmaOptions {
/// weights: String,
/// }
///
/// impl AsyncResource for Egemma {
/// type Options = EgemmaOptions;
/// type Error = core::convert::Infallible;
///
/// async fn build(_ctx: &Resources, _options: EgemmaOptions) -> Result<Self, Self::Error> {
/// Ok(Self)
/// }
/// }
///
/// // No `Default`, so a resource nobody wrote a section for has nothing to load from.
/// assert!(ingraph::bare_resource_options!(Egemma).is_none());
///
/// struct Clock;
///
/// impl AsyncResource for Clock {
/// type Options = ();
/// type Error = core::convert::Infallible;
///
/// async fn build(_ctx: &Resources, (): ()) -> Result<Self, Self::Error> {
/// Ok(Self)
/// }
/// }
///
/// // A zero-knob resource needs no section at all.
/// assert_eq!(ingraph::bare_resource_options!(Clock), Some(()));
/// ```
/// The options a BARE section of `$node` runs at — `Some` at the options' [`Default`], `None` where
/// the type has none.
///
/// The third argument of [`Creation::node`](crate::Creation::node), and the reason it is a macro is
/// [`BareOptions`]'s whole note: the probe answers only where the type is concrete, and a macro is
/// what puts it at the call site that has one. It brings the fallback's trait into scope for one
/// block and leaves no name behind.
///
/// # Examples
///
/// ```
/// use ingraph::{AsyncConstructor, Resources};
///
/// struct Decode;
/// struct DecodeOptions {
/// threads: usize,
/// }
///
/// impl AsyncConstructor for Decode {
/// type Options = DecodeOptions;
/// type Error = core::convert::Infallible;
///
/// async fn with_options(_ctx: &Resources, _options: DecodeOptions) -> Result<Self, Self::Error> {
/// Ok(Self)
/// }
/// }
///
/// // No `Default`, so a bare section has nothing to fill its knobs from.
/// assert!(ingraph::bare_options!(Decode).is_none());
///
/// struct Watchdog;
///
/// impl AsyncConstructor for Watchdog {
/// type Options = ();
/// type Error = core::convert::Infallible;
///
/// async fn with_options(_ctx: &Resources, (): ()) -> Result<Self, Self::Error> {
/// Ok(Self)
/// }
/// }
///
/// // A zero-knob node's `()` is `Default`, which is what lets `[watchdog]` alone launch it.
/// assert_eq!(ingraph::bare_options!(Watchdog), Some(()));
/// ```
/// The options a BARE section of the ORIGIN `$origin` runs at — `Some` at the options' [`Default`],
/// `None` where the type has none.
///
/// [`bare_options!`](crate::bare_options)'s sibling one tier over, and the probe under it is the
/// same one for the same reason. What differs is the PROJECTION: an origin's options are its own
/// face's, reached through the mode row as [`Tuned<S>`](crate::Tuned) — one seat, and the same one
/// [`Creation::origin`](crate::Creation::origin) fills from the deployment's section.
///
/// # Examples
///
/// ```
/// use ingraph::{Context, Control, Feed, Fin, Resources, Source};
///
/// /// The declaration is what states the MODE the projection reads, so the probe is spelled over a
/// /// real origin rather than over a bare `Source` impl.
/// #[ingraph::source]
/// struct Counting {
/// remaining: u64,
/// }
///
/// struct CountingOptions {
/// remaining: u64,
/// }
///
/// impl Default for CountingOptions {
/// fn default() -> Self {
/// Self { remaining: 3 }
/// }
/// }
///
/// impl Source for Counting {
/// type Options = CountingOptions;
/// type Yield = u64;
/// type Mutation = ();
/// type Error = core::convert::Infallible;
///
/// fn build(_ctx: &Resources, options: CountingOptions) -> Result<Self, Self::Error> {
/// Ok(Self {
/// remaining: options.remaining,
/// })
/// }
///
/// fn run(
/// self,
/// _ctx: Context,
/// _feed: Feed<u64>,
/// _control: Control<core::convert::Infallible>,
/// ) -> Result<Fin, Self::Error> {
/// Ok(Fin::Spent)
/// }
/// }
///
/// // A bare `[counting]` section runs the origin at its own options' default.
/// assert_eq!(
/// ingraph::bare_origin_options!(Counting).map(|options| options.remaining),
/// Some(3)
/// );
/// ```