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
//! RECIPE FUSION — the packages a search recipe mints over the members it LISTS, the evidence its
//! door answers with, and the door itself.
//!
//! ```ignore
//! #[ingraph::search(shared(text(type = "String")), dedup(hash), limit = 20)]
//! pub struct TravelSearch {
//!   #[ingraph(weight = 1.0, depth = 50, tower(zh(type = "crate::ZhQuery", shared)))]
//!   subs: Subs,
//!   #[ingraph(weight = 2.0, depth = 100,
//!     tower(text(type = "crate::ClipText", shared)),
//!     tower(image(type = "crate::ClipImage", shared)))]
//!   shots: Shots,
//! }
//! ```
//!
//! mints, at module scope:
//!
//! ```text
//! TravelSearchSubsTowerOptions   { zh }                          one member's bound towers
//! TravelSearchShotsTowerOptions  { text, image }
//! TravelSearchFuseOptions        { fusion, subs: Route<…>, shots: Route<…>, subs_towers, shots_towers }
//! TravelSearchFuseQuestion       { question, subs: …, shots: … }
//! TravelSearchFusedEvidence<V₁,…>  one variant per member, holding THAT MEMBER's own evidence
//! TravelSearchFusedError<E₁,…>     one variant per member, holding THAT MEMBER's own refusal
//! TravelSearch::fuse(…)            the door
//! ```
//!
//! # THIS IS #290's MACHINERY, MOVED — the ONE HOME migration, and nothing else
//!
//! Every type above was minted by a GRAPH ROOT until this round, off the root's `fuse(…)` word, from
//! `crate::graph::fuse`. What moved is the HOME and the SOURCE: the same [`Packages`] emitter, the
//! same [`Route`]/[`Fusable`]/`AsyncFusedRead` road, the same reciprocal-rank fold, the same
//! nested-evidence enums — now minted off a [`SearchModel`] rather than off a `GraphModel`.
//!
//! Three things did NOT come with it, each because the migration took away its reason to exist:
//!
//! 1. **The WORD-COUNT DOOR LAW.** A root counted how many members wore which word to decide how
//!    many doors to emit; a recipe LISTS its members, so there is exactly one door and its arity is
//!    the declaration's own field list. Nothing here counts.
//! 2. **The TRIMS** — `fuse(vector)` / `fuse(fulltext)` — and with them the typed doors and the
//!    `VectorFusable`/`FulltextFusable` demands those doors carried. A recipe that wants two
//!    members fused writes two members; a recipe that wants a different set writes a second recipe,
//!    which is the *several recipes over one set of members* the grammar already admits. There was
//!    nothing left for a modality claim to trim, and on 2026-08-19 the two markers themselves were
//!    struck from `ingraph` — so the demand this list records as unwritten is now unwritable.
//! 3. **The ROOT's own `fuse` EMISSION.** The graph root keeps the word as a TIER word — it is what
//!    puts a retrieving declaration on the slot-bearing list the launch builds and the type walk
//!    visits — and emits no door, no package and no evidence enum. See [`crate::graph`].
//!
//! What did NOT change is the MEMBER's side: a member is asked through `AsyncFusedRead::keys` with
//! its own package and its own question, both reached by projection, and its `fused_keys` stays what
//! its own declaration minted. The question layer is the grain above this one and owes the member
//! nothing.
//!
//! # THE ROOT the members are joined at is a PARAMETER
//!
//! A recipe answers in a key it never names: every member's `AsyncFusedRead::Root` is bound to one
//! parameter, so two members answering two key types is `E0271` at the caller's own call rather than
//! a runtime mismatch.
//!
//! What the recipe DOES say about that parameter is how the fold tells two of them apart — the
//! `dedup(hash)` / `dedup(eq)` word, which picks the framework join (`HashJoin` / `EqJoin`) and the
//! `where` row stated about the root parameter (`Hash + Eq` / `PartialEq`, `Clone` on both).
//!
//! [`Route`]: https://docs.rs/ingraph
//! [`Fusable`]: https://docs.rs/ingraph

use heck::ToUpperCamelCase as _;
use quote::{format_ident, quote};

use super::{MemberModel, SearchModel};
use crate::{
  emit::{framework, leading},
  fuse::{Packages, Row},
};

#[cfg(test)]
mod dedup_tests;
#[cfg(test)]
mod tests;

impl SearchModel {
  /// The RECIPE FUSION emission, whole: the tower packages, the two request packages, the evidence
  /// and refusal enums, and the door.
  ///
  /// UNCONDITIONAL, which is the word-count law's absence stated as code: a recipe with one member
  /// is a recipe that fuses one ranking, and a one-term fold is the fold. What made the root's
  /// emission conditional was that a root's members arrived by a word rather than by a list, so
  /// *fewer than two* was a state it could be in; a recipe with no member is refused at the front
  /// end.
  #[must_use]
  pub fn fuse(&self) -> proc_macro2::TokenStream {
    let towers = self.tower_packages();
    let packages = self.packages_emission();
    let evidence = self.evidence();
    let door = self.door();
    quote! {
      #towers
      #packages
      #evidence
      #door
    }
  }

  /// The PACKAGE EMITTER this recipe mints through — the same one an index tier and a graph root
  /// use, which is what makes this a migration rather than a second implementation.
  fn packages(&self) -> Packages<'_> {
    Packages {
      krate: &self.krate,
      vis: &self.vis,
      owner: &self.name,
      // UNDRESSED BY CHOICE, and the choice is a reserved seam rather than a structural block. A
      // recipe DOES name a backend (`SearchModel::graphql`) and `IndexGraphql::of` builds the block
      // this seat wants out of one word, so dressing the tree is a line here rather than a road.
      // What holds it back is what a dressed tree would then be obliged to publish, which the
      // 2026-08-27 census read off the rows:
      //
      // * the `<member>_towers` rows hold `<Tower as DeclaredTower>::StepOptions`, whose own rows are
      //   `<Step as Serve>::Options` — so a dressed tree walks straight into the `()` seat: a step
      //   configured with nothing has no wire face, and this pass cannot know which steps those are;
      // * the per-member rows hold `Route<<M as Fusable>::Options>`, and `Route`'s own input face
      //   demands the member's package cross — which is a third party's declaration to keep.
      //
      // Both land as `E0277` at the RECIPE's declaration, about types it never wrote. So the packages
      // stay Rust-only until a round rules WHICH rows a request may name.
      graphql: None,
      base: &self.name,
      // No block is no override: every minted name reaches a schema as its Rust name.
      members: Vec::new(),
    }
  }

  /// ONE PACKAGE PER MEMBER THAT BINDS A TOWER — the knobs a caller names for the towers this
  /// recipe bound to that member.
  ///
  /// # THE TOWER LIVES AT THE SEARCH GRAIN, and this is where that is spelled
  ///
  /// A binding used to be written inside the member's own declaration (`arm(…)` / `chain(…)`), and
  /// that form is retired: a tower turns a QUESTION into what a member can be asked with, and which
  /// question a deployment asks is the recipe's business rather than the index's. So the tower's
  /// seat is here, on the recipe's own options tree, beside the [`Route`] rows for the same members.
  ///
  /// The type is `<Tower as DeclaredTower>::StepOptions` — a PROJECTION and never a name mangled out
  /// of the path's last segment. The recipe's expansion has never seen the tower's fields, and this
  /// is the seam that fact is crossed by: a hand-written tower stating `type StepOptions = ();` seats
  /// here exactly as a generated one does.
  ///
  /// It is the DEPLOYMENT's clock and not the request's, which is why the rename matters at this
  /// seat: `<Tower>SearchOptions` — the word-keyed package a REQUEST names — is published as the
  /// recipe's own `options` ARGUMENT and never as a row of this tree.
  ///
  /// A member that binds no tower mints nothing, which is the presence law every other package
  /// emitter here already keeps.
  ///
  /// [`Route`]: https://docs.rs/ingraph
  fn tower_packages(&self) -> proc_macro2::TokenStream {
    let bound = self.members.iter().filter(|member| !member.arms.is_empty());
    let minted = bound.map(|member| self.tower_package(member));
    quote!(#(#minted)*)
  }

  /// ONE member's tower package — the rows its arms declared, each spelled as the projection.
  fn tower_package(&self, member: &MemberModel) -> proc_macro2::TokenStream {
    let declared = framework(&self.krate, &["retrieve"], "DeclaredTower");
    let rows: Vec<Row> = member
      .arms
      .iter()
      .map(|arm| {
        let tower = &arm.tower;
        Row::new(
          &arm.name,
          quote!(<#tower as #declared>::StepOptions),
          &format!("`{}` tower", arm.name),
        )
      })
      .collect();
    self.packages().package(
      &tower_options_name(&self.name, &member.field),
      &format!(
        "The knobs the towers bound to [`{recipe}`]'s `{member}` member run under — one row per \
         arm, each holding that TOWER's own options object by projection.",
        recipe = self.name,
        member = member.field,
      ),
      &rows,
    )
  }

  /// The two PACKAGES the door is configured and asked with — one `Route` seat per member, one
  /// tower seat per member that binds one, and one question seat per member, all reached BY
  /// PROJECTION off `Fusable`.
  ///
  /// A recipe names no member's package type. `<M as Fusable>::Options` is what the seat holds, so a
  /// third-party member joins with no edit here.
  fn packages_emission(&self) -> proc_macro2::TokenStream {
    let krate = &self.krate;
    let route = framework(krate, &["retrieve"], "Route");
    let flavour = framework(krate, &["retrieve"], "FusionOptions");
    let fusable = framework(krate, &["retrieve"], "Fusable");
    let packages = self.packages();
    let mut rows = vec![Row::new(
      &format_ident!("fusion"),
      quote!(#flavour),
      "fusion flavour",
    )];
    rows.extend(self.members.iter().map(|member| {
      let ty = &member.ty;
      Row::new(
        &member.field,
        quote!(#route<<#ty as #fusable>::Options>),
        &format!("`{}` member", member.field),
      )
    }));
    rows.extend(
      self
        .members
        .iter()
        .filter(|member| !member.arms.is_empty())
        .map(|member| {
          let package = tower_options_name(&self.name, &member.field);
          Row::new(
            &tower_row(&member.field),
            quote!(#package),
            &format!("towers bound to `{}`", member.field),
          )
        }),
    );
    let options = packages.package(
      &self.options_name(),
      &format!(
        "The knobs a FUSED retrieve under [`{recipe}`] runs under — one route per member, each \
         wearing the edge facts a request states about it (its weight in the fold, whether it is \
         walked, and HOW DEEP to ask it) and holding that member's OWN package by projection, plus \
         one seat per member for the towers this recipe bound to it.",
        recipe = self.name,
      ),
      &rows,
    );
    let mut asked = vec![Row::new(
      &format_ident!("question"),
      quote!(::std::string::String),
      "question",
    )];
    asked.extend(self.members.iter().map(|member| {
      let ty = &member.ty;
      Row::new(
        &member.field,
        quote!(<#ty as #fusable>::Question),
        &format!("`{}` member", member.field),
      )
    }));
    let question = packages.question(
      &self.question_name(),
      &format!(
        "The question a FUSED retrieve under [`{recipe}`] is asked with — the recipe's own, and one \
         package per member for the members that ask something else. A member whose seat is EMPTY \
         is not walked, which is the participation rule at recipe grain.",
        recipe = self.name,
      ),
      &asked,
    );
    quote! {
      #options
      #question
    }
  }

  /// The EVIDENCE and REFUSAL enums the door answers with — one variant per member, each holding
  /// that member's OWN type as a parameter.
  ///
  /// # NESTED provenance, and the recipe opens none of it
  ///
  /// A member's evidence is whatever its own grain minted. The recipe wraps it in a variant naming
  /// the MEMBER and asks nothing of the type, which is what *aggregating by projection* means: the
  /// client reads *which members agreed, and what each of them saw*, all the way down.
  fn evidence(&self) -> proc_macro2::TokenStream {
    let vis = &self.vis;
    let evidence = self.evidence_name();
    let refusal = self.refusal_name();
    let seen: Vec<syn::Ident> = self
      .members
      .iter()
      .map(|member| evidence_param(&member.field))
      .collect();
    let errors: Vec<syn::Ident> = self
      .members
      .iter()
      .map(|member| error_param(&member.field))
      .collect();
    let variants = self.members.iter().zip(&seen).map(|(member, param)| {
      let variant = variant(&member.field);
      let doc = leading(&format!(
        "`{member}` ranked this root, and what `{member}` itself saw — that member's own \
         provenance, whole.",
        member = member.field,
      ));
      quote! {
        #[doc = #doc]
        #variant(#param)
      }
    });
    let refusals = self.members.iter().zip(&errors).map(|(member, param)| {
      let variant = variant(&member.field);
      let doc = leading(&format!(
        "`{member}` refused, in that member's own vocabulary.",
        member = member.field,
      ));
      quote! {
        #[doc = #doc]
        #variant(#param)
      }
    });
    let arms = self.members.iter().map(|member| {
      let variant = variant(&member.field);
      let field = member.field.to_string();
      quote! {
        Self::#variant(__ingraph_refusal) => {
          ::core::write!(__ingraph_formatter, "{}: {__ingraph_refusal}", #field)
        }
      }
    });
    let sources = self.members.iter().map(|member| {
      let variant = variant(&member.field);
      quote!(Self::#variant(__ingraph_refusal) => ::core::option::Option::Some(__ingraph_refusal))
    });
    let displays = errors
      .iter()
      .map(|param| quote!(#param: ::core::fmt::Display));
    let bounds = errors
      .iter()
      .map(|param| quote!(#param: ::core::error::Error + 'static));
    let doc = leading(&format!(
      "WHICH of [`{recipe}`]'s members agreed about a fused root, and what each of them saw — one \
       variant per member, each carrying that member's OWN evidence untouched.",
      recipe = self.name,
    ));
    let refusal_doc = leading(&format!(
      "WHICH of [`{recipe}`]'s members refused, in that member's own vocabulary.",
      recipe = self.name,
    ));
    quote! {
      #[doc = #doc]
      #[derive(::core::fmt::Debug, ::core::clone::Clone, ::core::cmp::PartialEq)]
      #vis enum #evidence<#(#seen,)*> {
        #(#variants,)*
      }

      #[doc = #refusal_doc]
      #[derive(::core::fmt::Debug, ::core::clone::Clone, ::core::cmp::PartialEq)]
      #vis enum #refusal<#(#errors,)*> {
        #(#refusals,)*
      }

      #[automatically_derived]
      impl<#(#displays,)*> ::core::fmt::Display for #refusal<#(#errors,)*> {
        fn fmt(
          &self,
          __ingraph_formatter: &mut ::core::fmt::Formatter<'_>,
        ) -> ::core::fmt::Result {
          match self {
            #(#arms,)*
          }
        }
      }

      #[automatically_derived]
      impl<#(#bounds,)*> ::core::error::Error for #refusal<#(#errors,)*> {
        fn source(&self) -> ::core::option::Option<&(dyn ::core::error::Error + 'static)> {
          match self {
            #(#sources,)*
          }
        }
      }
    }
  }

  /// THE DOOR — every member asked through the one road, their ordinals folded, and the answer in a
  /// key this recipe never names.
  ///
  /// # The four facts a fold needs, and the recipe answers three of them by DECLARATION
  ///
  /// WHICH members to ask (a member whose question seat is empty is structurally absent, and one the
  /// caller disabled is not walked), how much each one's opinion counts, HOW DEEP to ask each of
  /// them, and what arithmetic joins them.
  ///
  /// The root read the middle two off the REQUEST alone and fell back to the framework's own
  /// numbers. A recipe declared them, so the fallbacks are the DECLARATION's: a member the request
  /// did not configure takes the `weight` the recipe wrote for it, and a member the request did not
  /// ask a depth of is capped at the `depth` the recipe wrote. A recipe that wrote neither is the
  /// root's own behaviour exactly — `Route::DEFAULT_WEIGHT` and the caller's whole budget — which is
  /// what makes the migration behaviour-preserving where nothing new was written.
  ///
  /// # `limit` STAYS REQUIRED, and the recipe's own `limit` is not what answers it
  ///
  /// The declared `limit` rides [`DeclaredSearch::LIMIT`] instead, for the ruling's own reason: the
  /// framework's answer to *how many* is a CODEGEN constant that becomes an SDL literal, and *no
  /// door, seam or fold ever reads it*. A door taking an optional budget would need a runtime
  /// framework default to terminate its chain, which is exactly what that ruling refuses to mint. So
  /// the caller of the Rust door states its budget, and the declared number is the WIRE's default —
  /// the tier it was ruled to be in.
  ///
  /// # It narrows a member's intake through the EDGE, which is the only place a request may
  ///
  /// A recipe holds a member's package by PROJECTION and cannot read a row out of it. What it DOES
  /// hold about a member is the edge, and `Route::depth` is the fact on it — resolved by
  /// `route_depth` against the recipe's own declared depth and handed down as that member's own
  /// `limit`. What happens to the number below is the member's business, which is the FRACTAL.
  ///
  /// # The JOIN is the RECIPE's word
  ///
  /// The framework join the fold runs and the `where` row the door states about its root parameter
  /// are both read off `dedup` — `HashJoin` with `Hash + Eq` or `EqJoin` with `PartialEq`.
  ///
  /// [`DeclaredSearch::LIMIT`]: https://docs.rs/ingraph
  fn door(&self) -> proc_macro2::TokenStream {
    let SearchModel {
      krate, vis, dedup, ..
    } = self;
    let read = framework(krate, &["retrieve"], "AsyncFusedRead");
    let route = framework(krate, &["retrieve"], "Route");
    let flavour = framework(krate, &["retrieve"], "FusionOptions");
    let fusion = framework(krate, &["retrieve"], "Fusion");
    let fused = framework(krate, &["retrieve"], "Fused");
    let rooted = framework(krate, &["retrieve"], "Rooted");
    let weighted = framework(krate, &["retrieve"], "fuse_weighted");
    let join = framework(krate, &["retrieve"], dedup.join());
    let admits = dedup.admits();
    let recipe = &self.name;
    let key = format_ident!("__INGRAPH_ROOT__");
    let options = self.options_name();
    let question = self.question_name();
    let evidence = self.evidence_name();
    let refusal = self.refusal_name();

    let engines: Vec<syn::Ident> = self
      .members
      .iter()
      .map(|member| engine_param(&member.field))
      .collect();
    let seen: Vec<proc_macro2::TokenStream> = self
      .members
      .iter()
      .zip(&engines)
      .map(|(member, engine)| {
        let ty = &member.ty;
        quote!(<#ty as #read<#engine>>::Evidence)
      })
      .collect();
    let errors: Vec<proc_macro2::TokenStream> = self
      .members
      .iter()
      .zip(&engines)
      .map(|(member, engine)| {
        let ty = &member.ty;
        quote!(<#ty as #read<#engine>>::Error)
      })
      .collect();
    let params = self.members.iter().zip(&engines).map(|(member, engine)| {
      let field = &member.field;
      let ty = &member.ty;
      quote!(#field: <#ty as #read<#engine>>::Ctx<'__ingraph_ctx>,)
    });
    let obligations = self.members.iter().zip(&engines).map(|(member, engine)| {
      let ty = &member.ty;
      quote! {
        #engine: '__ingraph_ctx,
        #ty: #read<#engine, Root = #key>,
      }
    });
    let asks = self.members.iter().zip(&engines).map(|(member, engine)| {
      let field = &member.field;
      let ty = &member.ty;
      let variant = variant(field);
      let edge = self.member_edge(member);
      quote! {
        {
          #edge
          // A MEMBER WITH NO QUESTION IS STRUCTURALLY ABSENT, which is `participates`' law at recipe
          // grain: a request that asked two of three members does not silently ask the third.
          if let (true, ::core::option::Option::Some(__ingraph_asked)) =
            (__ingraph_enabled, #question::#field(question))
          {
            let __ingraph_ranked = <#ty as #read<#engine>>::keys(
              #field,
              ::core::option::Option::and_then(__ingraph_route, #route::options),
              __ingraph_asked,
              __ingraph_depth,
            )
            .await
            .map_err(#refusal::#variant)?;
            __ingraph_members.push((
              __ingraph_weight,
              ::core::iter::Iterator::collect::<::std::vec::Vec<_>>(
                ::core::iter::Iterator::map(
                  ::std::vec::Vec::into_iter(__ingraph_ranked),
                  |__ingraph_hit| {
                    let (__ingraph_root, __ingraph_rank, __ingraph_seen) =
                      __ingraph_hit.into_components();
                    #rooted::new(
                      __ingraph_root,
                      __ingraph_rank,
                      #evidence::#variant(__ingraph_seen),
                    )
                  },
                ),
              ),
            ));
          }
        }
      }
    });
    let doc = leading(&format!(
      "FUSED — every member [`{recipe}`] lists asked at once, their rankings joined by reciprocal \
       rank fusion. Answers in the key every one of them agrees about.",
    ));
    let projection = leading(
      "This recipe names NOTHING of a member's: the context, the package, the question, the \
       evidence and the refusal are all projections, so a third-party member joins by implementing \
       `AsyncFusedRead` and this door absorbs it with no edit here.",
    );
    let currency = leading(
      "No score of any member enters the fusion — only the ORDINAL each of them gave the hit — which \
       is what lets members whose currencies were never compared be fused at all. Each member's own \
       evidence rides out NESTED instead, whole and unopened.",
    );
    let key_note = leading(
      "The ROOT is a parameter and never a type this emission names: every member's own key is \
       bound to it, so two members answering two key types have no root to be fused at and say so \
       as `E0271` at this call.",
    );
    let mechanism = leading(&format!(
      "Roots are placed through `{join}`, which is what this recipe's `dedup({word})` chose — the \
       `where` row below is that mechanism's price. The law it answers is that a key that cannot \
       hash is retrievable, so a member that reached for `dedup(eq)` for that reason must not \
       become unfusable in a recipe that lists it.",
      join = dedup.join(),
      word = dedup.as_str(),
    ));
    quote! {
      #[automatically_derived]
      impl #recipe {
        #[doc = #doc]
        #[doc = ""]
        #[doc = #projection]
        #[doc = ""]
        #[doc = #key_note]
        #[doc = ""]
        #[doc = #currency]
        #[doc = ""]
        #[doc = #mechanism]
        #[allow(clippy::too_many_arguments)]
        #vis async fn fuse<'__ingraph_ctx, #key, #(#engines),*>(
          #(#params)*
          options: ::core::option::Option<&#options>,
          question: &#question,
          limit: ::core::num::NonZeroUsize,
        ) -> ::core::result::Result<
          ::std::vec::Vec<#fused<#key, #evidence<#(#seen,)*>>>,
          #refusal<#(#errors,)*>,
        >
        where
          #key: #admits,
          #(#obligations)*
        {
          let __ingraph_fusion = ::core::option::Option::map_or(
            ::core::option::Option::and_then(options, #options::fusion),
            <#fusion as ::core::default::Default>::default(),
            #flavour::fusion,
          );
          let mut __ingraph_members = ::std::vec::Vec::new();
          #(#asks)*
          ::core::result::Result::Ok(
            #weighted::<_, _, #join<#key>>(__ingraph_members, __ingraph_fusion)
          )
        }
      }
    }
  }

  /// **ONE MEMBER'S EDGE, RESOLVED** — the four numbers a fold needs about a member, in the tier
  /// order the spec locks, as the statements that bind them.
  ///
  /// Binds `__ingraph_route`, `__ingraph_enabled`, `__ingraph_weight` and `__ingraph_depth`, and
  /// reads `options` and `limit` from the scope it is spliced into.
  ///
  /// # It is a HELPER because there are two callers and ONE law
  ///
  /// The Rust door asks each member through its own `Ctx`; the WIRE road asks it through the citizen
  /// seam, out of the schema's own data. What each of them ASKS differs; what the recipe DECLARED
  /// about the edge does not — the weight, the depth chain and the participation rule are the same
  /// four lines whoever spends them. Written twice they could come to disagree, and the thing that
  /// would disagree is the number a client sees.
  pub(super) fn member_edge(&self, member: &MemberModel) -> proc_macro2::TokenStream {
    let krate = &self.krate;
    let route = framework(krate, &["retrieve"], "Route");
    let depth = framework(krate, &["retrieve"], "route_depth");
    let fusable = framework(krate, &["retrieve"], "Fusable");
    let options = self.options_name();
    let field = &member.field;
    let ty = &member.ty;
    // THE DECLARED COEFFICIENT — the recipe's own `weight`, or the request layer's multiplicative
    // identity where the recipe wrote none. `Route::weight` is not an `Option`, so a route the
    // request supplied answers whole and a member with no route falls to the declaration.
    let declared_weight = member.weight.map_or_else(
      || quote!(#route::<<#ty as #fusable>::Options>::DEFAULT_WEIGHT),
      |weight| quote!(#weight),
    );
    let declared_depth = member.depth.map_or_else(
      || quote!(::core::option::Option::None),
      |depth| {
        let depth = depth.get();
        quote!(::core::num::NonZeroU32::new(#depth))
      },
    );
    quote! {
      let __ingraph_route = ::core::option::Option::and_then(options, #options::#field);
      let __ingraph_enabled = ::core::option::Option::map_or(
        __ingraph_route,
        #route::<<#ty as #fusable>::Options>::DEFAULT_ENABLED,
        #route::enabled,
      );
      let __ingraph_weight = ::core::option::Option::map_or(
        __ingraph_route,
        #declared_weight,
        #route::weight,
      );
      // THE DEPTH THIS RECIPE ASKS THIS MEMBER AT — the request's own ask, capped by the depth the
      // DECLARATION wrote, cut at the caller's budget. The middle tier is what a graph root
      // structurally could not fill: a root held no per-member number, and a recipe does.
      let __ingraph_declared: ::core::option::Option<::core::num::NonZeroU32> = #declared_depth;
      let __ingraph_depth = #depth(
        ::core::option::Option::and_then(__ingraph_route, #route::depth),
        ::core::option::Option::as_ref(&__ingraph_declared),
        limit,
      );
    }
  }

  /// The name of the package the door is configured with.
  pub(super) fn options_name(&self) -> syn::Ident {
    format_ident!("{}FuseOptions", self.name)
  }

  /// The name of the package the door is asked with.
  pub(super) fn question_name(&self) -> syn::Ident {
    format_ident!("{}FuseQuestion", self.name)
  }

  /// The name of the enum the door's answers carry their provenance in.
  pub(super) fn evidence_name(&self) -> syn::Ident {
    format_ident!("{}FusedEvidence", self.name)
  }

  /// The name of the enum the door refuses with.
  pub(super) fn refusal_name(&self) -> syn::Ident {
    format_ident!("{}FusedError", self.name)
  }
}

/// The name of ONE MEMBER's tower package.
fn tower_options_name(recipe: &syn::Ident, member: &syn::Ident) -> syn::Ident {
  format_ident!(
    "{recipe}{}TowerOptions",
    member.to_string().to_upper_camel_case()
  )
}

/// The row ONE MEMBER's tower package takes in the recipe's own options package.
///
/// A COMPOUND name, and the one this emission mints: a member already owns the row holding its
/// `Route`, and its towers are a second fact about the same member. Two rows under one name is
/// refused where every package is built, so a member whose neighbour is literally called
/// `<member>_towers` is told so rather than silently merged.
fn tower_row(member: &syn::Ident) -> syn::Ident {
  format_ident!("{member}_towers")
}

/// ONE member's variant name in a recipe's evidence and refusal enums.
fn variant(field: &syn::Ident) -> syn::Ident {
  format_ident!("{}", field.to_string().to_upper_camel_case())
}

/// The ENGINE parameter one member is asked through — the standing emitted-ident law at recipe
/// grain.
fn engine_param(field: &syn::Ident) -> syn::Ident {
  crate::fuse::engine_param(field)
}

/// The EVIDENCE parameter one member's own provenance rides.
fn evidence_param(field: &syn::Ident) -> syn::Ident {
  use heck::ToShoutySnakeCase as _;

  format_ident!(
    "__INGRAPH_EVIDENCE_{}__",
    field.to_string().to_shouty_snake_case()
  )
}

/// The ERROR parameter one member's own refusal rides.
fn error_param(field: &syn::Ident) -> syn::Ident {
  crate::fuse::error_param(field)
}