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
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
//! The `analysis_query` family (issue #632 / FG-3), extracted out of
//! `queries.rs` per issue #662: pure code movement, no semantic change, no
//! signature change. See the parent module's doc comment for how these fit
//! into the overall query-shaped pipeline.
// ─── FG-3 (issue #632): decomposed analysis_query ─────────────────────
//
// `analysis_query`'s only cutoff used to be `PartialEq` over the whole
// `AnalysisResult` — index, resolutions, diagnostics (range-laden), and
// symbol_meta bundled into one struct — so it almost never backdated, and
// every file's validate/dialect_gate/annotation-content checks re-ran on
// nearly any edit, since they were three whole-project passes each looping
// every file. This section splits that into:
//
// - [`resolutions_index_query`] — index + resolutions, no diagnostics: the
// RESOLUTIONS/INDEX half.
// - [`per_file_diagnostics_query`] / [`contributor_diagnostics_query`] — the
// genuinely per-file diagnostic contributors (validate, dialect_gate,
// annotation content checks) behind a thin whole-project aggregator, so a
// body edit re-runs only the edited file's own contributor.
// - [`whole_project_diagnostics_query`] — now a thin aggregator (issue
// #750, FG-3 completion): the external-check family is decomposed into
// [`inline_docs_query`] / [`external_meta_query`] /
// [`call_site_metas_query`] and the per-file [`value_meta_query`] /
// [`call_site_diagnostics_query`]; only the M-2 modules pass and the
// strict typed-mode pass remain genuinely whole-project — reading the
// narrow [`resolutions_index_query`] projection and the
// already-FG-2/FG-2.1-narrowed `type_inference_query`, never the
// diagnostics-laden bundle.
// - [`analysis_diagnostics_query`] — the DIAGNOSTICS half: every diagnostic
// source merged, in the same order `finish_analysis` produces them, so
// `db.analysis()` stays output-identical to the monolithic, module-aware
// `brink_analyzer::analyze_with_modules` path (pinned by
// `query_equivalence.rs`) — only equal to the module-*blind*
// `analyze_with_options` for ink projects without a declared `#@module`,
// see `ProjectDb::module_map`'s doc (issue #1526).
// - [`analysis_query`] — kept as a thin assembler over the above three for
// `db.analysis()`'s existing LSP/IDE/CLI-facing `AnalysisResult` shape.
// [`diagnostics_query`] and [`lir_query`] read
// [`analysis_diagnostics_query`]/[`resolutions_index_query`] directly
// instead of through this bundle, so a diagnostics-only edit never forces
// a resolutions-only reader to recompute and vice versa.
use BTreeMap;
use Arc;
use ;
use DefinitionId;
use ;
use crateLookupSet;
use ;
/// Index + resolutions, aggregated across every file's [`resolve_query`]
/// (issue #632 / FG-3) — deliberately without diagnostics, so this struct's
/// `PartialEq` never touches a diagnostic's range. Neither
/// [`symbol_index_query`] nor any file's [`resolve_query`] reads
/// `project.analysis_options`, so an `AnalysisOptions` edit that only
/// changes diagnostics (e.g. raising `semantic_type_check` to `Error`) never
/// even triggers salsa to re-run this query's closure — not just a
/// backdate, a full skip (pinned by `fg3_dependency_edges.rs`).
///
/// `Arc`-wrapped (design doc §2 Fork 2's "Arc<plain>" ruling, applied here):
/// pointer identity is the observable a re-execution-vs-cutoff test needs —
/// see `fg3_dependency_edges.rs`.
pub
/// One file's per-file diagnostic contributors (issue #632 / FG-3 design doc
/// §1 item 4 — [`brink_analyzer::per_file_diagnostics`]): structural
/// validation, the dialect gate, and (brink dialect only) annotation-content
/// checks. Reads only this file's own `lowered_query`/`resolve_query`, plus
/// the narrow, cutoff-friendly [`resolution_index_query`] projection (for
/// annotation content checks' declared-`LIST`-name lookup — range-free, so
/// it doesn't reintroduce whole-project churn), the registered host
/// manifest (T1d-2, docs/t1d-spec.md §3 — `Handle<K>` annotation content
/// checks' declared-handle-kind lookup), and (issue #2272 review finding)
/// [`file_import_scope_query`]'s `ImportScope` for the referrer-scoped
/// `E061` struct-name lookup. The manifest is project-wide, host-set config,
/// not derived from any file's edits — reading it here is the same coarse,
/// range-free dependency shape as `dialect`, already read two lines below,
/// so it doesn't reintroduce the whole-project churn FG-3 eliminated.
/// `file_import_scope_query` is a *new* dependency edge onto
/// [`module_map_query`] this query didn't carry before #2272 —
/// `module_map_query` is itself built from every file's `raw_lowered_query`,
/// so a declared-module-affecting edit anywhere in the project can in
/// principle reach this query — but the edge is cutoff-safe: `ImportScope`
/// carries no `TextRange` (its own doc), so `file_import_scope_query`'s
/// `PartialEq` backdates on any edit that leaves every file's declared
/// module name and this file's own `IMPORT` list unchanged, which is the
/// overwhelming majority of edits (in particular every body-only edit, in
/// this file or any other). Reading `module_map_query` directly here
/// instead (as an earlier draft did) would NOT have this property — see
/// `file_import_scope_query`'s own doc for why. Otherwise still: never
/// another file's HIR: a body edit in file Y leaves file X's memo fully
/// validated (same `Arc`/pointer), not re-executed.
/// `Arc`-wrapped for the same pointer-identity reason as [`ResolvedProject`].
///
/// Also the B0.9 native strict-only enforcement point
/// ([`brink_analyzer::native_strict_only_error`], issue #1342): this is the
/// narrowest seam that has both a file's own [`super::Language`]
/// classification (`super::file_language`) and `AnalysisOptions` access —
/// `super::lower_native_file` has neither (issue #1179's finding), so the
/// check cannot live there. Reading `opts.types` here doesn't widen this
/// query's dependency edge: `opts` (the whole `AnalysisOptions`) is already
/// read for `dialect`/`host_manifest` above.
///
/// Same seam decouples the T1b dialect gate from native files (issue #1348):
/// `dialect` is an ink-only axis (docs/t1b-surface-spec.md §1), orthogonal to
/// this file's [`super::Language`] classification, so
/// `brink_analyzer::per_file_diagnostics`'s `is_native` flag — computed here,
/// once, and reused for both calls below — skips the gate for a native file
/// exactly the way `native_strict_only_error` above is native-conditional.
///
/// `lru = 4096`: per-file runaway-guard ceiling (issue #647).
///
/// Gated on [`is_source_file`] (issue #2329 review finding): this is a
/// direct per-file entry point (`ProjectDb::per_file_diagnostics`), reachable
/// without going through [`contributor_diagnostics_query`]'s own gate, so a
/// non-source document must be excluded here too or its bogus ink-lowered
/// HIR still reaches `brink_analyzer::per_file_diagnostics`.
pub
/// Aggregated per-file diagnostic contributors across the whole project
/// (issue #632 / FG-3 — "a thin aggregator" per the design doc). The loop
/// itself is cheap: each iteration is a salsa memo lookup, not a HIR walk —
/// [`per_file_diagnostics_query`]'s actual `validate`/`dialect_gate`/
/// annotation-content work only re-runs for the file(s) whose own
/// dependencies changed.
pub
/// The project-wide inline `///` doc merge (issue #750 / FG-3 completion —
/// [`brink_analyzer::project_inline_docs`]), keyed by `(kind, declared
/// name)`. Reads every file's manifest, but the output is range-free
/// ([`DocBlock`] carries parsed doc content only), so any edit that leaves
/// every `///` block intact backdates this memo — the `Eq`-cutoff seam
/// between per-file manifest churn and the doc-consuming enrichment passes
/// ([`external_meta_query`], [`value_meta_query`]).
pub
/// The index-driven half of the external-check family (issue #750 / FG-3
/// completion — [`brink_analyzer::external_meta_diagnostics`]): host-
/// manifest enrichment + checks for externals (`E039`/`E040`) plus
/// knot/stitch doc enrichment. Reads the *full ranged* [`symbol_index_query`]
/// (diagnostic spans need real ranges) and [`inline_docs_query`] — never any
/// file's HIR, which is the decomposition's point: the pre-#750 shape ran
/// this inside a query that also walked every file's HIR, so any body edit
/// re-ran the whole family. Cheap to re-execute (proportional to
/// externals/callables, no HIR walk); its range-free `symbol_meta` half
/// backdates dependents via [`call_site_metas_query`].
pub
pub
/// Name-keyed external metas for the call-site checks (issue #750 / FG-3
/// completion — [`brink_analyzer::call_site_metas`]): the range-free
/// projection of [`external_meta_query`]'s enrichment map, filtered to
/// `SymbolKind::External`. This is the cutoff seam guarding every file's
/// [`call_site_diagnostics_query`] memo (the `resolution_index` playbook):
/// a body edit shifts declaration ranges → the full index changes →
/// [`external_meta_query`] re-executes — but as long as no external's
/// *content* (docs/manifest/params) changed, this projection comes out
/// `Eq`, and every other file's call-site memo stays fully validated
/// without re-executing. `Arc`-wrapped for the same pointer-identity
/// reason as [`per_file_diagnostics_query`].
pub
/// One file's VAR/CONST/LIST initializer/doc enrichment (issue #750 / FG-3
/// completion — [`brink_analyzer::file_value_meta`]): purely presentational
/// `symbol_meta` entries, no diagnostics. Reads only this file's own
/// `lowered_query`, the range-zeroed [`inference_index_query`] projection
/// (the pass reads `by_name` + `kind`, never a symbol's range — see the
/// analyzer seam's doc), and [`inline_docs_query`] — so a body edit in file
/// Y leaves file X's memo fully validated (same `Arc`), not re-executed.
///
/// `lru = 4096`: per-file runaway-guard ceiling (issue #647).
pub
/// One file's external call-site literal checks (`E041`/`E042`) — issue
/// #750 / FG-3 completion, [`brink_analyzer::file_call_site_diagnostics`].
/// Reads only this file's own `lowered_query` plus the range-free
/// [`call_site_metas_query`] projection, so a body edit in file Y leaves
/// file X's memo fully validated (same `Arc`), not re-executed — the last
/// per-file HIR walk `finish_analysis` still ran project-wide. Empty when
/// the `external_check` severity is `Off` (the same gate the monolithic
/// path applies before walking any file).
///
/// `lru = 4096`: per-file runaway-guard ceiling (issue #647).
pub
/// One file's `#@effects(…)` exceedance diagnostics (T2-2,
/// docs/effects-spec.md §10, issue #861). Brink-only, same TM-2
/// content-check precedent [`per_file_diagnostics_query`]'s doc cites: under
/// `strict-ink` the directive is already rejected whole by `dialect_gate`'s
/// `E051`, so checking its declared names here would be noise.
///
/// Reads only the def ids [`brink_analyzer::effects_assertion_defs`] finds
/// in *this file's* HIR (a structural scan — no inference triggered by the
/// scan itself) and, for exactly those defs, the salsa-memoized per-def
/// [`effects_query`]. A file with no `#@effects` directive at all never
/// calls `effects_query`, so an unannotated project stays effect-inference-
/// free — T2-1's advisory/lazy posture, preserved.
///
/// The assertion's `reads`/`writes`/`calls` clause names are resolved
/// through this file's own [`brink_analyzer::ImportScope`] (issue #881, the
/// T2 follow-up to M-2d/#790), built from [`module_map_query`] + this file's
/// own `IMPORT`s exactly like [`resolve_query`] builds it — so the checker
/// can never attribute a clause to a different declared module's same-name
/// cell than the one this file's own resolution binds.
///
/// `lru = 4096`: per-file runaway-guard ceiling (issue #647).
pub
/// One file's FS-2 `await`-condition purity diagnostics (E105,
/// docs/flow-suspension-spec.md §3/§5, issue #928). Brink-only + lazy, the
/// same posture as [`effects_assertion_diagnostics_query`]: a file with no
/// `await` never fetches a single per-def effect row, so an await-free project
/// stays effect-inference-free.
///
/// Unlike the assertion query (which knows its target defs up front), the
/// callees a condition names are discovered by resolving the condition's
/// calls ([`brink_analyzer::await_condition_callees`]); each is judged by its
/// salsa-memoized per-def [`effects_query`] row — the incremental analogue of
/// the monolithic path's whole-project `effects_project` table.
///
/// `lru = 4096`: per-file runaway-guard ceiling (issue #647).
pub
/// The module name the project's `[project] conventions` pointer names, or
/// `None` when there is nothing to resolve.
///
/// The ONE place the `conventions` pointer is turned into a module name, so
/// the two consumers that need it — [`conventions_confinement_diagnostics_query`]
/// (which asks "is *this* file that module?") and
/// [`conventions_projection_query`] (which asks "*which* file is that
/// module?") — cannot drift apart on the answer. Both must agree exactly:
/// a projection built from a file that confinement does not consider the
/// conventions module would report handlers the compiler is simultaneously
/// diagnosing as misplaced.
///
/// `None` covers the two cases both consumers treat identically and
/// silently (see `brink_analyzer::conventions_module_diagnostics`'s own
/// module doc): an unset `conventions` key, and a **bare preset name**
/// (`conventions = "screenplay"`), which names a `std::conventions::*` module
/// rather than a project file — `brink_analyzer::BUILTIN_ELEMENT_PRESETS`'s
/// own doc records that nothing resolves a preset name to its mounted
/// source yet (it needs #1582's pub marker and #2167's closure-scoped
/// confinement, neither built). `Some` does NOT mean a file with that
/// module name exists; each caller checks that against
/// [`module_map_query`] itself, because they warn differently about it.
/// One file's conventions-module confinement diagnostics (`E169`, issue
/// #1844 — the MODULE half of the 2026-07-31 §9.1 ruling's item (4); #1838/
/// #1847 cover the *placement* half, `E112`). A pattern-claiming
/// `@[convention(claims = "…", order = N)]` handler is legal only in the project's
/// configured conventions module (`brink.toml`'s `[project] conventions`,
/// renamed from `elements` by issue #2180); this is the db-direct seam that
/// has both a file's real module identity ([`module_map_query`]'s native
/// branch, `crate::modules::native_module_path`) and the resolved
/// `AnalysisOptions` the pointer travels on. `brink_analyzer::
/// analyze_with_modules` (the off-db road: `IdeSnapshot::analyze`,
/// `brink-lsp`'s `analysis_loop`) is now a second such seam — issue #2335
/// added `brink_analyzer::conventions_confinement_diagnostics`, which
/// mirrors this query file-for-file via its own caller-computed module
/// identity, since a caller with no `ProjectDb` cannot ask
/// [`module_map_query`] directly.
///
/// Lazy in the same shape as [`await_purity_diagnostics_query`]/
/// [`comparator_contract_diagnostics_query`]: a file with no declared claim
/// handler never even reads [`module_map_query`]. One case stays
/// intentionally silent (not merely lazy) — see `brink_analyzer::
/// conventions_module_diagnostics`'s own module doc for why: a bare preset
/// name (`conventions = "screenplay"`, which names a `std::conventions::*`
/// module rather than a project file — no path in the tree to compare
/// against without a preset registry this slice doesn't build). A
/// path-shaped pointer that resolves to no file that actually exists in
/// `project.files(db)` (a typo, a moved/deleted target, an `.ink`-suffixed
/// path, or a pointer whose minted module doesn't line up with the file
/// keys — e.g. a `brink.toml` discovered at a nested key) used to be a
/// second such silent case, `tracing::warn!`-only; as of issue #2320 it
/// reports a real `E169` per declared handler instead — checked HERE,
/// against [`module_map_query`]'s real module set, before any file is
/// compared against it, and worded to blame the *pointer* rather than the
/// handlers' placement (see the arm's own comment below for why
/// per-handler, and why the wording differs from the confinement
/// message).
///
/// An **entirely unset `conventions` key is NO LONGER one of those silent
/// cases** (issue #2289, part 2 of the 2026-08-05 ruling): a declared claim
/// handler names no module to belong to, which is a misconfiguration, not
/// an opt-out — see [`brink_analyzer::conventions_unconfigured_diagnostics`]'s
/// own doc.
///
/// **A file mounted under a reserved peer root is exempt entirely**
/// (`std::…`, `brink_ir::symbols::is_reserved_root_module`, issue #2251) —
/// found while implementing the unset-key case above: `brink-environment`
/// unconditionally mounts `std::conventions::screenplay` into every
/// compiled project's file set (issue #2080) regardless of whether that
/// project's own `brink.toml` ever names it, so with no exemption every
/// project with *no* `conventions` key configured would suddenly fail to
/// compile at all — the mounted preset's own `heading`/`transition`/`cue`/
/// `parenthetical` handlers would all misfire the new unconfigured-`E169`
/// above (verified against a real `brink compile` run on a bare
/// `[project]` toml before this exemption was added). The SAME exemption
/// also fixes a latent, pre-#2289 instance of this bug: a project that
/// *did* configure `conventions` to one of its own files already flagged
/// the mounted preset's handlers as "outside the configured module",
/// which was never reachable before because the unset-key short-circuit
/// silently protected the far more common no-`conventions`-at-all case
/// from ever exercising this code path at all.
///
/// `lru = 4096`: per-file runaway-guard ceiling (issue #647), matching
/// every other per-file diagnostic query in this module.
pub
/// The project's cross-file claiming injection seam (issue #2289,
/// correcting the file-local claiming defect the 2026-08-05 ruling names:
/// *"it's never file local. you configure conventions for a project,
/// that's why they're conventions and not 'local patterns'."*): the
/// configured conventions module's OWN declared `@[convention]` handlers,
/// plus which file that module is, so [`super::lowered_query`] knows both
/// what to inject into every other file and which file to skip (itself).
///
/// `None` in every case [`conventions_projection_query`] already treats as
/// "nothing to inject" — no `conventions` key, a bare preset pointer, or a
/// path-shaped pointer that resolves to no real project file (the same
/// "warn, never silently drop" channel that query and
/// [`conventions_confinement_diagnostics_query`] both use). This query
/// deliberately re-derives its own small "which file is the expected
/// module" resolution rather than sharing either sibling's — see
/// [`expected_conventions_module`]'s own doc for why the pointer-to-name
/// step itself IS shared, and this module's existing precedent of each
/// consumer owning its own file-lookup walk (`conventions_confinement_
/// diagnostics_query`'s `any`, `conventions_projection_query`'s
/// `min_by_key`) — this query's own `min_by_key` matches the latter's
/// deterministic tie-break.
///
/// Reads [`raw_lowered_query`] for the conventions module's own file, never
/// the project-aware [`lowered_query`]: `HirFile::claim_handlers` is always
/// the file's own LOCAL declarations regardless of what (if anything) that
/// file itself was lowered with injected (`Elements::handler_decls` in
/// `brink-ir` never reads an injected handler — see that method's own
/// doc), so the two queries agree here by construction. Reading the
/// project-aware query instead would close a cycle: `lowered_query` calls
/// this query to decide what to inject, so this query calling back into
/// `lowered_query` for the very file it is about to hand off would recurse
/// on itself the moment that file needed lowering.
///
/// `Arc`-wrapped: every native file in the project reads this once per
/// project revision ([`super::lowered_query`]'s dependency), and `Option<
/// (FileId, Vec<ClaimHandlerDecl>)>`'s derived `PartialEq` backdates it
/// across an edit that leaves the conventions module's declared handler
/// set unchanged (e.g. a body-only edit inside one of its handlers) — the
/// same early-cutoff shape [`import_closure_query`]/[`conventions_projection_query`]
/// already rely on.
pub
/// The transitive `IMPORT` closure of `entry`: `entry` itself plus every
/// module reachable by following native `IMPORT` statements outward,
/// breadth over the module-name → file reverse index [`module_map_query`]
/// already builds. Issue #2111 finding 3: built in a **reusable** shape,
/// generic over any entry file rather than conventions-specific, so #2167's
/// `E169` confinement relaxation (legalizing a claim handler that delegates
/// to an imported preset) can call this exact query instead of re-deriving
/// its own closure walk.
///
/// Ink files have no `IMPORT` (only `INCLUDE`, which
/// [`super::compilation_closure_files`]/`IncludeGraph` already cover) — an
/// ink `entry` simply has no imports to walk and the closure is `[entry]`.
///
/// Sorted ascending by path (not discovery/traversal order) before
/// returning: two callers that both need "first file wins on a name
/// collision" (this module's own [`conventions_projection_query`], and any
/// future #2167 use) get the same deterministic tie-break without each
/// having to re-sort, and the order can never depend on `project.files`'
/// incoming order or on which import statement happened to be visited
/// first.
///
/// The same path-sorted, first-wins rule governs name resolution *while
/// walking imports*, too: when two files in the project declare the same
/// module name, the import-target lookup resolves to the lowest-path file,
/// deterministically — never whichever one `project.files` happened to
/// iterate over last. Both the closure's final **order** and its
/// **membership** (which file a duplicate name resolves to) are therefore
/// independent of `project.files`' incoming order.
///
/// A named-but-unresolvable import (a typo, a module that doesn't exist)
/// is simply not followed — this query only ever widens by real, resolved
/// files, never by a dangling name a diagnostic elsewhere already reports.
pub
/// The project's conventions projection (issue #2111, NS-T seam 1/6):
/// every `@[convention]` handler declared in the project's one configured
/// conventions module, ascending by `order` — the editor-facing artifact
/// the design-backport comment on #2111 (`docs/decision-log.md`
/// 2026-08-03) calls "THE SOLE EDITOR INTERCHANGE": claims pattern, order,
/// mode (attach/wrap), resulting disposition, and the `attach = StructName`
/// schema, now RESOLVED to its fields and their types (issue #2111
/// continuation, finding 1). Schema, never values — see
/// [`ConventionsProjection`]'s own doc for that boundary, for why no
/// comptime-fault/last-good case exists here (the mechanism that would have
/// needed one, `fn conventions()` registration, is dissolved), and for the
/// one part of #2111 this query still does not deliver (wire emission into
/// `.inkb`/`StoryData` — see that type's doc).
///
/// # Resolution (shared with [`conventions_confinement_diagnostics_query`])
///
/// Both queries route the `[project] conventions` pointer through the same
/// [`expected_conventions_module`] helper, so "which module is the
/// conventions module" has exactly one answer:
///
/// - No `conventions` configured at all → empty projection. There is no
/// conventions module to project.
/// - A **bare preset name** (`conventions = "screenplay"`, not path-shaped) →
/// ALSO empty, for now. `brink_analyzer::BUILTIN_ELEMENT_PRESETS`'s own
/// doc states plainly that nothing resolves a preset name to its mounted
/// source yet: "`std::conventions::screenplay` has no real
/// `use`-importable module path… that needs #1582's pub marker and
/// #2167's closure-scoped confinement, neither built yet." Minting a
/// bespoke resolution here (bypassing that stated dependency) would be
/// exactly the kind of undetermined-default invention the parent ruling's
/// own "do not invent it" caution warns against — the issue's own
/// "pre-frozen preset" note describes a *destination*, not something
/// this slice can honestly claim to deliver ahead of #1582/#2167.
/// - A path-shaped pointer that resolves to a real project file → that
/// file's own [`ClaimHandlerDecl`]s, projected, with each `attach` name
/// resolved against every struct visible from that file's [`import_closure_query`]
/// (finding 3).
/// - A path-shaped pointer that resolves to no real file → empty, with the
/// same `tracing::warn!` this query's confinement sibling emits (never a
/// silent drop).
///
/// # Invalidation
///
/// Reads: `project.analysis_options(db)` (for the `conventions` pointer and
/// the native root), [`module_map_query`] (to find which file carries the
/// expected module name, and to resolve `IMPORT` targets), the resolved
/// conventions module's own [`import_closure_query`] (finding 3 — widened
/// from the pre-continuation "conventions module alone" footprint), and
/// every file in that closure's own [`lowered_query`] output (for their
/// `structs`, to resolve `attach` names). `module_map_query` and
/// `import_closure_query` are whole-project-shaped, so an edit elsewhere
/// can *reach* this query — but only through a changed module map or a
/// changed closure, both of which salsa backdates when their value is
/// unchanged, so an ordinary edit to a file **outside** the closure never
/// re-executes this query's closure (proven by
/// `tests/issue_2111_conventions_projection.rs`'s `Arc::ptr_eq` cases,
/// including the new one for an edit to an *imported* struct file). See
/// [`ConventionsProjection`]'s own doc for why this is now the ruled "the
/// conventions module and its import closure" invalidation contract exactly,
/// not the narrower "conventions module alone" reading the pre-continuation
/// slice used (load-bearing on the un-resolved-schema shape that slice
/// carried, and no longer true now that `attach` is resolved).
pub
/// One file's NS-A4 comparator-contract diagnostics (E119,
/// docs/stdlib-spec.md §4b, issue #1110 — extended to the fn-value verb
/// trio `map`/`filter`/`fold` by issue #1679, §4): `sort_by`/`sorted_by`/
/// `map`/`filter`/`fold` calls whose callback's row — named either by an
/// inline `#fn(target)` literal (ink/brink) or, since issue #1887, a
/// native bare-name reference — provably exceeds pure·silent. Brink-only
/// + lazy, the exact
/// [`await_purity_diagnostics_query`] shape: a file with no such site never
/// fetches a single per-def effect row, so a callback-free project stays
/// effect-inference-free.
///
/// `lru = 4096`: per-file runaway-guard ceiling (issue #647).
pub
/// Whole-project diagnostics + `symbol_meta` (issue #632 / FG-3 design doc
/// §1), now a thin aggregator (issue #750 / FG-3 completion) over the
/// decomposed external-check family — [`external_meta_query`] + per-file
/// [`value_meta_query`] / [`call_site_diagnostics_query`] — plus the two
/// genuinely whole-project passes left: the M-2 module import/visibility
/// checks ([`brink_analyzer::module_diagnostics`], which need every file's
/// HIR plus the project-wide resolutions) and, under `types = strict`, the
/// strict typed-mode checks ([`brink_analyzer::strict_diagnostics`], which
/// need a whole-project [`InferenceResult`] — the FG-4-era candidate for a
/// per-SCC-reading split, out of #750's scope). The aggregation loops are
/// salsa memo lookups, not HIR walks: a body edit in file Y re-runs only
/// Y's own value-meta/call-site contributors (plus the modules pass, which
/// post-dates #750's decomposition — M-1/M-2 landed while this slice was in
/// flight and is per-file-splittable follow-up work if it ever shows up
/// hot).
///
/// [`InferenceResult`]: brink_analyzer::InferenceResult
pub
/// Run `per_file` over every SOURCE file in file order, skipping non-source
/// documents (issue #2329: brink.toml/.md/.json never contribute analysis).
/// The shared shape of every per-file pass in
/// [`whole_project_diagnostics_query`] — the gate lives here once, not
/// copy-pasted per loop (and clippy's `too_many_lines` on the aggregator is
/// what finally forced the extraction).
pub
/// B3a UFCS resolution (issue #1482/#1506): the project's verdict table,
/// translated to `brink-ir`'s own lowering-facing mirror type
/// (`brink_ir::lir::UfcsLookup`), plus the diagnostics the analyzer's `ufcs`
/// pass produced alongside it.
pub
/// Compute [`UfcsResolution`], translating the analyzer's verdict table to
/// `brink-ir`'s own lowering-facing mirror type at this one seam — see that
/// type's doc for why `brink-ir` can't name `brink_analyzer::UfcsVerdict`
/// directly (it sits below `brink-analyzer` in the crate graph).
///
/// Memoized once per project and read by four call sites —
/// [`whole_project_diagnostics_query`] (the diagnostics half), (issue #1506)
/// `lir_knot_chunk_query`'s per-knot LIR lowering plus `lir_lowering_query`'s
/// own root-content step, and (issue #1507) `ProjectDb::ufcs_verdict`, which
/// `brink-ide`'s hover/go-to-def wiring reads through — so all four see the
/// same table rather than each re-running whole-project inference.
///
/// Lazy on the same argument [`whole_project_diagnostics_query`]'s old
/// inline check used: a project with no dotted-callee call anywhere never
/// triggers inference here (every ink project is in that set by
/// construction — ink's own lowering cannot produce a multi-segment callee
/// path; see `brink-analyzer`'s `ufcs` module doc), and builds (and stays
/// pointer-stable at) the empty table.
pub
/// B1 `or`-coalescing typing (issue #1492/#1471): the project's recorded
/// per-step chain shapes, translated to `brink-ir`'s own lowering-facing
/// mirror type (`brink_ir::lir::CoalesceLookup`).
///
/// Only the **table** half of `brink_analyzer::coalesce_types` is kept: its
/// `E066` diagnostics are strict-mode-only and already reach
/// [`whole_project_diagnostics_query`] through `strict::check`'s own wiring
/// (see `brink_analyzer::coalesce_types`' doc — surfacing them from here
/// too would emit strict-only diagnostics under `types = gradual`, and
/// duplicate them under strict).
///
/// Deliberately **not** gated on the `types` policy: the recorded shapes are
/// a typing *record*, not a strict-mode check. Native's un-overridden
/// default is gradual (`brink-analyzer::strict::native_strict_only_error`'s
/// own doc), and a gradual chain whose operands *are* statically pinned
/// still deserves the right code shape; only genuinely unpinned steps come
/// back as `CoalesceShape::RuntimeCheck`.
///
/// Memoized once per project and read by the two LIR-lowering call sites
/// (`lir_knot_chunk_query`, `lir_lowering_query`'s root-content step), so
/// both see the same table. Lazy the same way [`ufcs_resolution_query`] is:
/// a project with no `or`-coalescing anywhere (every ink-dialect project,
/// by construction — `InfixOp::Coalesce` is native-lowering-only) never
/// triggers whole-project inference here and stays pointer-stable at the
/// empty table.
pub
/// All analysis diagnostics, assembled in the exact order
/// [`brink_analyzer::finish_analysis`] would produce them (issue #632 /
/// FG-3): symbol-index diagnostics, every file's own `resolve_query`
/// diagnostics, the per-file contributors
/// ([`contributor_diagnostics_query`]), then the whole-project contributors
/// ([`whole_project_diagnostics_query`]). [`diagnostics_query`] filters this
/// by file; [`lir_query`] reads it directly for its error gate — neither
/// goes through the bundled [`analysis_query`] anymore.
pub
/// Full cross-file analysis (issue #632 / FG-3: now a thin assembler over
/// [`resolutions_index_query`] + [`analysis_diagnostics_query`] +
/// [`whole_project_diagnostics_query`] rather than calling
/// [`brink_analyzer::finish_analysis`] directly) — `db.analysis()`'s public
/// shape, kept for LSP/IDE/CLI consumers that want the whole bundled
/// result. Output-identical to the pre-FG-3 query and to the monolithic,
/// module-aware `analyze_with_modules` path (pinned by
/// `query_equivalence.rs`) — only equal to the module-*blind*
/// `analyze_with_options` for ink projects without a declared `#@module`,
/// see `ProjectDb::module_map`'s doc (issue #1526); the decomposition
/// changes *dependency edges*, not values. Narrower consumers
/// ([`diagnostics_query`], [`lir_query`]) read the three sub-queries
/// directly instead of through this bundle.
pub
/// Per-file diagnostics (spec §4 layer 3): this file's lowering + syntax
/// diagnostics plus its share of the cross-file analysis diagnostics. Raw —
/// suppression filtering stays a consumer concern (see
/// [`partition_diagnostics`]). Reads [`analysis_diagnostics_query`] directly
/// (issue #632 / FG-3) rather than through the bundled [`analysis_query`],
/// so a resolutions-only change (no diagnostic anywhere differs) leaves this
/// memo's dependency fully validated.
///
/// `lru = 4096`: per-file runaway-guard ceiling (issue #647).
///
/// Gated on [`is_source_file`] (issue #2329 review finding): this is a
/// direct per-file entry point (`ProjectDb::diagnostics`), reachable without
/// going through [`analysis_diagnostics_query`]'s own gate on this same
/// file's contribution, so a non-source document must be excluded here too
/// or its bogus ink-lowered `lowered_query` diagnostics still surface.
pub
/// Whether the project has at least one Error-severity diagnostic after
/// suppression filtering and [`brink_analyzer::effective_severity`]
/// partitioning (issue #791 / FG-4a — PR #753's seam finding #3: "`lir_query`
/// still reads `analysis_diagnostics_query` wholesale for its error gate;
/// FG-4's per-container chunks will want a 'has any error' boolean
/// projection so chunk memos don't ride the full diagnostic vector's Eq").
///
/// Computes the exact same `errors.is_empty()` verdict [`super::lir_query`]'s
/// gate used to compute inline, from the exact same inputs
/// ([`analysis_diagnostics_query`] plus every file's lowering diagnostics,
/// suppressions, and the entry file's `disable_all` flag) via the same
/// shared [`partition_diagnostics`] — so this is a pure re-expression of the
/// gate as its own query, not a new rule. `bool`'s `PartialEq` is the
/// cheapest possible cutoff: a diagnostics edit that changes *content* (a
/// message, an added warning) without flipping whether any error exists
/// backdates this memo, so any dependent that reads only this boolean (not
/// the full `Vec<Diagnostic>`) stays fully validated across that edit — see
/// `fg4a_dependency_edges.rs`.
///
/// [`partition_diagnostics`]: super::partition_diagnostics
pub
/// The same [`partition_diagnostics`] "does at least one Error-severity
/// diagnostic exist" verdict as [`has_errors_query`], but scoped to the
/// project's **codegen closure** ([`super::compilation_closure_files`]) rather
/// than every file loaded into the project db — the same reachability
/// machinery `struct_shape_data_query`/`lir_prelude_decls_query`/
/// `lir_lowering_query` in `queries/mod.rs` already use. For an ink project
/// that closure is `entry`'s transitive `INCLUDE` closure (issue #815's
/// established narrowing); for a **native** project it is every discovered
/// `.brink` module (issue #1296), so a broken **unreferenced** sibling module
/// still fails this gate — the whole native module tree is the compilation
/// unit (Rust parity).
///
/// [`has_errors_query`] itself is untouched and stays whole-project: it feeds
/// `db.has_errors()`/`db.lir_product()`, IDE-surface reads FG-4a's
/// dependency-edge tests pin on purpose (issue #791) — a broken file
/// genuinely unrelated to any particular entry must still show up as a
/// project-wide error signal there. This narrower query is the *additional*
/// gate the #1032 collapse ruling adds for `compileProject`'s artifact path
/// ([`super::lir_in_closure_query`] / `db.story_data()`): once the editor's
/// session db and analysis db became the same db, a WIP scratch file or a
/// second, `INCLUDE`-unrelated story sharing that db could flip
/// `compileProject(entry)` from `ok:true` to `ok:false` even though codegen
/// only ever lowered `entry`'s own closure (#815) — a false-negative gate,
/// not corrupt output. Scoping the gate to match what codegen actually reads
/// closes that gap: an unrelated file's error still surfaces through
/// `diagnostics_query`/`db.diagnostics(file)` (both still whole-project,
/// unchanged), it just no longer blocks a different entry's build.
pub