rigortype 0.4.8 → 0.4.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (349) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -1
  3. data/docs/handbook/01-getting-started.md +1 -1
  4. data/docs/handbook/04-tuples-and-shapes.md +6 -1
  5. data/docs/handbook/12-lightweight-hkt.md +1 -1
  6. data/docs/handbook/appendix-typescript.md +28 -17
  7. data/docs/manual/02-cli-reference.md +10 -0
  8. data/docs/manual/03-configuration.md +1 -1
  9. data/docs/manual/04-diagnostics.md +1 -1
  10. data/docs/manual/10-mcp-server.md +122 -10
  11. data/docs/manual/plugins/rigor-activerecord.md +7 -0
  12. data/lib/rigor/analysis/check_rules/always_raises.rb +95 -0
  13. data/lib/rigor/analysis/check_rules/always_truthy_condition_collector.rb +32 -2
  14. data/lib/rigor/analysis/check_rules/argument_type.rb +802 -0
  15. data/lib/rigor/analysis/check_rules/call_facts.rb +2 -2
  16. data/lib/rigor/analysis/check_rules/dead_assignment_collector.rb +30 -1
  17. data/lib/rigor/analysis/check_rules/declaration_sourced_guard.rb +4 -5
  18. data/lib/rigor/analysis/check_rules/duplicate_hash_key_collector.rb +34 -0
  19. data/lib/rigor/analysis/check_rules/ivar_write_collector.rb +131 -4
  20. data/lib/rigor/analysis/check_rules/nil_receiver.rb +195 -0
  21. data/lib/rigor/analysis/check_rules/override_param_narrowed.rb +111 -0
  22. data/lib/rigor/analysis/check_rules/override_return_widened.rb +88 -0
  23. data/lib/rigor/analysis/check_rules/override_support.rb +246 -0
  24. data/lib/rigor/analysis/check_rules/override_visibility.rb +135 -0
  25. data/lib/rigor/analysis/check_rules/published_constant_guard.rb +75 -31
  26. data/lib/rigor/analysis/check_rules/raise_non_exception.rb +198 -0
  27. data/lib/rigor/analysis/check_rules/receiver_predicates.rb +576 -0
  28. data/lib/rigor/analysis/check_rules/return_in_ensure_collector.rb +52 -4
  29. data/lib/rigor/analysis/check_rules/return_type.rb +225 -0
  30. data/lib/rigor/analysis/check_rules/rigor_testing.rb +119 -0
  31. data/lib/rigor/analysis/check_rules/rule_ids.rb +7 -7
  32. data/lib/rigor/analysis/check_rules/rule_walk.rb +4 -3
  33. data/lib/rigor/analysis/check_rules/self_closedness_scanner.rb +2 -0
  34. data/lib/rigor/analysis/check_rules/self_undefined_method.rb +165 -0
  35. data/lib/rigor/analysis/check_rules/shadowed_rescue_collector.rb +34 -0
  36. data/lib/rigor/analysis/check_rules/source_arity.rb +2 -2
  37. data/lib/rigor/analysis/check_rules/special_global_write.rb +256 -0
  38. data/lib/rigor/analysis/check_rules/suppression.rb +275 -0
  39. data/lib/rigor/analysis/check_rules/undefined_method.rb +882 -0
  40. data/lib/rigor/analysis/check_rules/unreachable_branch.rb +97 -0
  41. data/lib/rigor/analysis/check_rules/unreachable_clause_collector.rb +42 -0
  42. data/lib/rigor/analysis/check_rules/unresolved_toplevel.rb +140 -0
  43. data/lib/rigor/analysis/check_rules/visibility_mismatch.rb +252 -0
  44. data/lib/rigor/analysis/check_rules/void_value_use_collector.rb +27 -0
  45. data/lib/rigor/analysis/check_rules/wrong_arity.rb +303 -0
  46. data/lib/rigor/analysis/check_rules.rb +66 -4931
  47. data/lib/rigor/analysis/dependency_recorder.rb +1 -1
  48. data/lib/rigor/analysis/dependency_source_inference/builder.rb +2 -4
  49. data/lib/rigor/analysis/dependency_source_inference/gem_resolver.rb +1 -2
  50. data/lib/rigor/analysis/dependency_source_inference/walker.rb +15 -15
  51. data/lib/rigor/analysis/incremental_session.rb +4 -4
  52. data/lib/rigor/analysis/path_expansion.rb +1 -1
  53. data/lib/rigor/analysis/plugin_fact_fingerprint.rb +5 -5
  54. data/lib/rigor/analysis/reachability/graph.rb +2 -3
  55. data/lib/rigor/analysis/reachability/plugin_roots.rb +2 -2
  56. data/lib/rigor/analysis/reachability/scan.rb +2 -2
  57. data/lib/rigor/analysis/rule_catalog.rb +2 -1
  58. data/lib/rigor/analysis/run_cache_key.rb +9 -8
  59. data/lib/rigor/analysis/runner/buffer_pool_dispatcher.rb +2 -2
  60. data/lib/rigor/analysis/runner/dependency_rows.rb +206 -0
  61. data/lib/rigor/analysis/runner/diagnostic_aggregator.rb +24 -22
  62. data/lib/rigor/analysis/runner/effect_cache_entries.rb +69 -0
  63. data/lib/rigor/analysis/runner/pool_coordinator.rb +6 -8
  64. data/lib/rigor/analysis/runner/project_pre_passes.rb +3 -5
  65. data/lib/rigor/analysis/runner/scope_seed.rb +144 -0
  66. data/lib/rigor/analysis/runner.rb +49 -296
  67. data/lib/rigor/analysis/template_unit_collector.rb +1 -1
  68. data/lib/rigor/analysis/template_units.rb +10 -10
  69. data/lib/rigor/analysis/worker_session.rb +7 -7
  70. data/lib/rigor/bleeding_edge.rb +3 -2
  71. data/lib/rigor/builtins/hkt_builtins.rb +17 -17
  72. data/lib/rigor/builtins/imported_refinements.rb +8 -16
  73. data/lib/rigor/builtins/regex_refinement.rb +3 -3
  74. data/lib/rigor/builtins/static_return_refinements.rb +143 -19
  75. data/lib/rigor/cache/incremental_snapshot.rb +21 -8
  76. data/lib/rigor/cache/rbs_descriptor.rb +18 -1
  77. data/lib/rigor/cli/coverage_renderer.rb +15 -1
  78. data/lib/rigor/cli/coverage_report.rb +19 -1
  79. data/lib/rigor/cli/diagnostic_formats.rb +3 -2
  80. data/lib/rigor/cli/docs_command.rb +5 -5
  81. data/lib/rigor/cli/effects_command.rb +7 -6
  82. data/lib/rigor/cli/fused_protection_report.rb +7 -7
  83. data/lib/rigor/cli/lsp_command.rb +1 -1
  84. data/lib/rigor/cli/mcp_command.rb +5 -2
  85. data/lib/rigor/cli/options.rb +4 -0
  86. data/lib/rigor/cli/plugins_command.rb +1 -1
  87. data/lib/rigor/cli/sig_gen_command.rb +1 -1
  88. data/lib/rigor/cli/skill_command.rb +5 -4
  89. data/lib/rigor/cli/triage_renderer.rb +3 -2
  90. data/lib/rigor/cli/unused_command.rb +4 -4
  91. data/lib/rigor/cli.rb +14 -0
  92. data/lib/rigor/configuration/coercion.rb +418 -0
  93. data/lib/rigor/configuration/defaults.rb +248 -0
  94. data/lib/rigor/configuration/dependencies.rb +1 -1
  95. data/lib/rigor/configuration/loader.rb +354 -0
  96. data/lib/rigor/configuration/severity_profile.rb +4 -4
  97. data/lib/rigor/configuration.rb +51 -860
  98. data/lib/rigor/effects/attribution.rb +1 -1
  99. data/lib/rigor/effects/effect_table.rb +1 -1
  100. data/lib/rigor/effects/identity.rb +3 -3
  101. data/lib/rigor/effects/local_ownership.rb +2 -2
  102. data/lib/rigor/effects/snapshot.rb +1 -1
  103. data/lib/rigor/effects/summary.rb +5 -4
  104. data/lib/rigor/environment/member_consistency.rb +10 -0
  105. data/lib/rigor/environment/rbs_loader.rb +19 -22
  106. data/lib/rigor/environment/reflection.rb +1 -1
  107. data/lib/rigor/environment/unreadable_signature.rb +21 -0
  108. data/lib/rigor/environment.rb +8 -8
  109. data/lib/rigor/flow_contribution/merger.rb +1 -0
  110. data/lib/rigor/hashing/xxh3.rb +1 -1
  111. data/lib/rigor/inference/acceptance.rb +23 -2
  112. data/lib/rigor/inference/alias_mutation_floor/site_collector.rb +5 -0
  113. data/lib/rigor/inference/alias_mutation_floor.rb +0 -5
  114. data/lib/rigor/inference/anonymous_meta_class.rb +2 -2
  115. data/lib/rigor/inference/block_call_timing.rb +6 -0
  116. data/lib/rigor/inference/budget_trace.rb +3 -2
  117. data/lib/rigor/inference/builtins/date_catalog.rb +3 -3
  118. data/lib/rigor/inference/builtins/method_catalog.rb +3 -3
  119. data/lib/rigor/inference/builtins/time_catalog.rb +3 -3
  120. data/lib/rigor/inference/call_ladder/literal_send.rb +98 -0
  121. data/lib/rigor/inference/call_ladder/overriding_def.rb +98 -0
  122. data/lib/rigor/inference/call_ladder/project_singleton.rb +362 -0
  123. data/lib/rigor/inference/call_ladder/refined.rb +212 -0
  124. data/lib/rigor/inference/call_ladder/top_level_def.rb +222 -0
  125. data/lib/rigor/inference/call_ladder/user_method.rb +247 -0
  126. data/lib/rigor/inference/call_ladder.rb +219 -0
  127. data/lib/rigor/inference/callee_write_census.rb +2 -2
  128. data/lib/rigor/inference/captured_locals.rb +2 -2
  129. data/lib/rigor/inference/clause_widening.rb +63 -1
  130. data/lib/rigor/inference/declaration_walk/context.rb +12 -12
  131. data/lib/rigor/inference/declaration_walk/rules.rb +750 -0
  132. data/lib/rigor/inference/declaration_walk/traversal.rb +9 -8
  133. data/lib/rigor/inference/declaration_walk.rb +4 -3
  134. data/lib/rigor/inference/def_node_resolver.rb +2 -2
  135. data/lib/rigor/inference/def_return_typer.rb +14 -6
  136. data/lib/rigor/inference/deferred_mutation.rb +120 -0
  137. data/lib/rigor/inference/define_method_block_self.rb +1 -1
  138. data/lib/rigor/inference/definer_resolution.rb +4 -4
  139. data/lib/rigor/inference/error_info.rb +8 -8
  140. data/lib/rigor/inference/expression_typer/composites.rb +348 -0
  141. data/lib/rigor/inference/expression_typer/per_element_assemblers.rb +233 -0
  142. data/lib/rigor/inference/expression_typer/writes.rb +218 -0
  143. data/lib/rigor/inference/expression_typer.rb +275 -1825
  144. data/lib/rigor/inference/external_ancestor_resolution.rb +2 -2
  145. data/lib/rigor/inference/fallback.rb +1 -0
  146. data/lib/rigor/inference/for_yield_slots.rb +126 -0
  147. data/lib/rigor/inference/genuine_send.rb +92 -0
  148. data/lib/rigor/inference/global_write_census.rb +2 -2
  149. data/lib/rigor/inference/hkt_body.rb +2 -0
  150. data/lib/rigor/inference/in_effect_refinements/walk.rb +2 -2
  151. data/lib/rigor/inference/index_write_widening.rb +4 -4
  152. data/lib/rigor/inference/indexed_narrowing.rb +1 -1
  153. data/lib/rigor/inference/intervening_ivar_reset.rb +46 -9
  154. data/lib/rigor/inference/ivar_writer_census.rb +1 -1
  155. data/lib/rigor/inference/loop_store_sites.rb +239 -0
  156. data/lib/rigor/inference/macro_block_self_type.rb +4 -3
  157. data/lib/rigor/inference/method_dispatcher/block_folding.rb +3 -2
  158. data/lib/rigor/inference/method_dispatcher/call_context.rb +84 -14
  159. data/lib/rigor/inference/method_dispatcher/composite_receiver.rb +144 -0
  160. data/lib/rigor/inference/method_dispatcher/constant_folding.rb +7 -5
  161. data/lib/rigor/inference/method_dispatcher/declared_constructor.rb +1 -1
  162. data/lib/rigor/inference/method_dispatcher/dependency_source.rb +90 -0
  163. data/lib/rigor/inference/method_dispatcher/discovered_method.rb +78 -0
  164. data/lib/rigor/inference/method_dispatcher/file_folding.rb +2 -2
  165. data/lib/rigor/inference/method_dispatcher/hkt_builtin_return.rb +40 -0
  166. data/lib/rigor/inference/method_dispatcher/iterator_dispatch.rb +1 -6
  167. data/lib/rigor/inference/method_dispatcher/literal_string_folding.rb +4 -2
  168. data/lib/rigor/inference/method_dispatcher/match_data_folding.rb +1 -1
  169. data/lib/rigor/inference/method_dispatcher/meta_introspection.rb +506 -0
  170. data/lib/rigor/inference/method_dispatcher/overload_selector.rb +2 -0
  171. data/lib/rigor/inference/method_dispatcher/plugin_contribution.rb +134 -0
  172. data/lib/rigor/inference/method_dispatcher/project_patched.rb +134 -0
  173. data/lib/rigor/inference/method_dispatcher/rbs_dispatch.rb +125 -43
  174. data/lib/rigor/inference/method_dispatcher/reduce_folding.rb +3 -4
  175. data/lib/rigor/inference/method_dispatcher/regexp_folding.rb +1 -1
  176. data/lib/rigor/inference/method_dispatcher/set_folding.rb +1 -1
  177. data/lib/rigor/inference/method_dispatcher/shape_dispatch.rb +19 -6
  178. data/lib/rigor/inference/method_dispatcher/singleton_folding.rb +3 -3
  179. data/lib/rigor/inference/method_dispatcher/singleton_mixin_dispatch.rb +7 -4
  180. data/lib/rigor/inference/method_dispatcher/static_refinement.rb +106 -0
  181. data/lib/rigor/inference/method_dispatcher/synthesized_stub.rb +41 -0
  182. data/lib/rigor/inference/method_dispatcher/synthetic_method_dispatch.rb +133 -0
  183. data/lib/rigor/inference/method_dispatcher/universal_object_dispatch.rb +2 -1
  184. data/lib/rigor/inference/method_dispatcher/user_class_fallback.rb +216 -0
  185. data/lib/rigor/inference/method_dispatcher.rb +175 -1361
  186. data/lib/rigor/inference/method_parameter_binder.rb +18 -18
  187. data/lib/rigor/inference/module_function_state.rb +5 -4
  188. data/lib/rigor/inference/mutation_widening.rb +20 -7
  189. data/lib/rigor/inference/narrowing/case_literals.rb +58 -0
  190. data/lib/rigor/inference/narrowing/class_dispatch.rb +302 -0
  191. data/lib/rigor/inference/narrowing/complements.rb +322 -0
  192. data/lib/rigor/inference/narrowing/presence_predicates.rb +205 -0
  193. data/lib/rigor/inference/narrowing/regex_match.rb +499 -0
  194. data/lib/rigor/inference/narrowing.rb +86 -1269
  195. data/lib/rigor/inference/object_mixins.rb +2 -2
  196. data/lib/rigor/inference/opaque_mutation.rb +214 -0
  197. data/lib/rigor/inference/optimistic_origin.rb +52 -14
  198. data/lib/rigor/inference/parameter_inference_collector.rb +1 -1
  199. data/lib/rigor/inference/pre_eval_constants.rb +11 -9
  200. data/lib/rigor/inference/precision_scanner.rb +27 -2
  201. data/lib/rigor/inference/project_patched_methods.rb +3 -3
  202. data/lib/rigor/inference/range_constant.rb +3 -3
  203. data/lib/rigor/inference/rbs_type_translator.rb +2 -2
  204. data/lib/rigor/inference/refine_self.rb +8 -7
  205. data/lib/rigor/inference/refined_dispatch.rb +2 -2
  206. data/lib/rigor/inference/return_barrier.rb +24 -9
  207. data/lib/rigor/inference/scope_indexer/alias_def_nodes.rb +311 -0
  208. data/lib/rigor/inference/scope_indexer/census_scope.rb +47 -0
  209. data/lib/rigor/inference/scope_indexer/certainty.rb +2 -2
  210. data/lib/rigor/inference/scope_indexer/class_cvar_census.rb +282 -0
  211. data/lib/rigor/inference/scope_indexer/class_cvars_collector.rb +12 -5
  212. data/lib/rigor/inference/scope_indexer/class_declarations.rb +228 -0
  213. data/lib/rigor/inference/scope_indexer/class_ivar_index.rb +2028 -0
  214. data/lib/rigor/inference/scope_indexer/constant_ivar_value.rb +4 -3
  215. data/lib/rigor/inference/scope_indexer/constant_tables.rb +844 -0
  216. data/lib/rigor/inference/scope_indexer/cvar_hierarchy.rb +159 -0
  217. data/lib/rigor/inference/scope_indexer/declaration_artifacts.rb +219 -0
  218. data/lib/rigor/inference/scope_indexer/declaration_signature.rb +212 -0
  219. data/lib/rigor/inference/scope_indexer/def_nestings_collector.rb +2 -2
  220. data/lib/rigor/inference/scope_indexer/factory_call_resolver.rb +53 -0
  221. data/lib/rigor/inference/scope_indexer/literal_receiver_mutations.rb +266 -0
  222. data/lib/rigor/inference/scope_indexer/member_layouts_collector.rb +8 -7
  223. data/lib/rigor/inference/scope_indexer/mixin_accumulator.rb +1 -1
  224. data/lib/rigor/inference/scope_indexer/mixin_effects.rb +470 -0
  225. data/lib/rigor/inference/scope_indexer/mixin_tables.rb +388 -0
  226. data/lib/rigor/inference/scope_indexer/mutated_carrier_widening.rb +163 -0
  227. data/lib/rigor/inference/scope_indexer/mutated_element_census.rb +211 -0
  228. data/lib/rigor/inference/scope_indexer/node_propagation.rb +520 -0
  229. data/lib/rigor/inference/scope_indexer/program_globals.rb +154 -0
  230. data/lib/rigor/inference/scope_indexer/published_constant_cvars.rb +146 -0
  231. data/lib/rigor/inference/scope_indexer/published_constant_ivars.rb +181 -0
  232. data/lib/rigor/inference/scope_indexer/shared_walk_tables.rb +823 -0
  233. data/lib/rigor/inference/scope_indexer/singleton_class_sources.rb +85 -0
  234. data/lib/rigor/inference/scope_indexer/superclasses_collector.rb +5 -5
  235. data/lib/rigor/inference/scope_indexer.rb +2657 -9558
  236. data/lib/rigor/inference/self_call_ivar_writes.rb +22 -3
  237. data/lib/rigor/inference/set_mutation.rb +2 -2
  238. data/lib/rigor/inference/singleton_hook_definers.rb +185 -0
  239. data/lib/rigor/inference/statement_evaluator/def_arguments_and_assertions.rb +365 -0
  240. data/lib/rigor/inference/statement_evaluator/pattern_bindings.rb +581 -0
  241. data/lib/rigor/inference/statement_evaluator.rb +201 -1008
  242. data/lib/rigor/inference/synthetic_method_scanner.rb +0 -3
  243. data/lib/rigor/language_server/completion_provider.rb +8 -8
  244. data/lib/rigor/language_server/diagnostic_publisher.rb +6 -7
  245. data/lib/rigor/language_server/document_symbol_provider.rb +4 -6
  246. data/lib/rigor/language_server/folding_range_provider.rb +3 -3
  247. data/lib/rigor/language_server/hover_provider.rb +2 -2
  248. data/lib/rigor/language_server/loop.rb +2 -2
  249. data/lib/rigor/language_server/server.rb +3 -2
  250. data/lib/rigor/language_server/signature_help_provider.rb +7 -9
  251. data/lib/rigor/lens/document.rb +10 -1
  252. data/lib/rigor/lens/file_reader.rb +2 -1
  253. data/lib/rigor/mcp/loop.rb +48 -6
  254. data/lib/rigor/mcp/server.rb +248 -23
  255. data/lib/rigor/mcp/skill_catalog.rb +157 -0
  256. data/lib/rigor/plugin/base.rb +22 -4
  257. data/lib/rigor/plugin/effect_attribution.rb +1 -1
  258. data/lib/rigor/plugin/inflector.rb +2 -2
  259. data/lib/rigor/plugin/io_boundary.rb +1 -1
  260. data/lib/rigor/plugin/loader.rb +4 -4
  261. data/lib/rigor/plugin/macro/heredoc_template.rb +4 -3
  262. data/lib/rigor/plugin/optimistic_return.rb +20 -0
  263. data/lib/rigor/plugin/registry.rb +2 -2
  264. data/lib/rigor/plugin/template_unit.rb +4 -2
  265. data/lib/rigor/plugin/trust_policy.rb +2 -1
  266. data/lib/rigor/plugin.rb +1 -1
  267. data/lib/rigor/protection/mutator.rb +8 -9
  268. data/lib/rigor/rbs_extended/reporter.rb +2 -2
  269. data/lib/rigor/rbs_extended.rb +2 -2
  270. data/lib/rigor/reflection/constant_ancestors.rb +1 -1
  271. data/lib/rigor/reflection/project_method.rb +2 -2
  272. data/lib/rigor/reflection.rb +4 -4
  273. data/lib/rigor/scope/discovery_index.rb +15 -10
  274. data/lib/rigor/scope/resolution_chain.rb +29 -6
  275. data/lib/rigor/scope.rb +89 -32
  276. data/lib/rigor/sig_gen/generator.rb +5 -4
  277. data/lib/rigor/sig_gen/renderer.rb +3 -3
  278. data/lib/rigor/sig_gen/writer.rb +8 -6
  279. data/lib/rigor/source/parameter_envelope.rb +1 -1
  280. data/lib/rigor/triage/catalogue.rb +4 -4
  281. data/lib/rigor/type/combinator.rb +2 -2
  282. data/lib/rigor/type/data_instance.rb +2 -2
  283. data/lib/rigor/type/struct_instance.rb +3 -3
  284. data/lib/rigor/type_node/generic.rb +2 -1
  285. data/lib/rigor/type_of_memo.rb +2 -1
  286. data/lib/rigor/typing_state.rb +3 -2
  287. data/lib/rigor/version.rb +1 -1
  288. data/plugins/rigor-actioncable/lib/rigor/plugin/actioncable/analyzer.rb +2 -2
  289. data/plugins/rigor-actioncable/lib/rigor/plugin/actioncable/channel_discoverer.rb +1 -1
  290. data/plugins/rigor-actionmailer/lib/rigor/plugin/actionmailer/mailer_discoverer.rb +4 -4
  291. data/plugins/rigor-actionmailer/lib/rigor/plugin/actionmailer.rb +1 -1
  292. data/plugins/rigor-actionpack/lib/rigor/plugin/actionpack/controller_discoverer.rb +4 -3
  293. data/plugins/rigor-actionpack/lib/rigor/plugin/actionpack/effects.rb +7 -5
  294. data/plugins/rigor-actionpack/lib/rigor/plugin/actionpack/erb_compiler.rb +4 -2
  295. data/plugins/rigor-actionpack/lib/rigor/plugin/actionpack/render_locals.rb +1 -1
  296. data/plugins/rigor-actionpack/lib/rigor/plugin/actionpack/view_assigns.rb +3 -2
  297. data/plugins/rigor-actionpack/lib/rigor/plugin/actionpack.rb +7 -7
  298. data/plugins/rigor-activejob/lib/rigor/plugin/activejob/job_discoverer.rb +1 -1
  299. data/plugins/rigor-activejob/lib/rigor/plugin/activejob.rb +2 -2
  300. data/plugins/rigor-activerecord/lib/rigor/plugin/activerecord/model_discoverer.rb +9 -8
  301. data/plugins/rigor-activerecord/lib/rigor/plugin/activerecord/model_index.rb +3 -2
  302. data/plugins/rigor-activerecord/lib/rigor/plugin/activerecord/schema_parser.rb +15 -7
  303. data/plugins/rigor-activerecord/lib/rigor/plugin/activerecord/schema_table.rb +10 -3
  304. data/plugins/rigor-activerecord/lib/rigor/plugin/activerecord/structure_sql_parser.rb +12 -1
  305. data/plugins/rigor-activerecord/lib/rigor/plugin/activerecord.rb +20 -5
  306. data/plugins/rigor-activestorage/lib/rigor/plugin/activestorage/attachment_discoverer.rb +1 -1
  307. data/plugins/rigor-activestorage/lib/rigor/plugin/activestorage.rb +3 -2
  308. data/plugins/rigor-activesupport-core-ext/lib/rigor/plugin/activesupport_core_ext/effects.rb +1 -1
  309. data/plugins/rigor-activesupport-core-ext/lib/rigor/plugin/activesupport_core_ext.rb +8 -7
  310. data/plugins/rigor-dry-schema/lib/rigor/plugin/dry_schema.rb +1 -1
  311. data/plugins/rigor-dry-types/lib/rigor/plugin/dry_types/alias_scanner.rb +1 -1
  312. data/plugins/rigor-dry-types/lib/rigor/plugin/dry_types.rb +6 -7
  313. data/plugins/rigor-factorybot/lib/rigor/plugin/factorybot/factory_discoverer.rb +3 -2
  314. data/plugins/rigor-graphql/lib/rigor/plugin/graphql/type_scanner.rb +4 -3
  315. data/plugins/rigor-hanami/lib/rigor/plugin/hanami.rb +4 -2
  316. data/plugins/rigor-minitest/lib/rigor/plugin/minitest.rb +1 -1
  317. data/plugins/rigor-pundit/lib/rigor/plugin/pundit.rb +1 -1
  318. data/plugins/rigor-rails-i18n/lib/rigor/plugin/rails_i18n/analyzer.rb +5 -3
  319. data/plugins/rigor-rails-i18n/lib/rigor/plugin/rails_i18n.rb +1 -1
  320. data/plugins/rigor-rails-routes/lib/rigor/plugin/rails_routes/devise_routes.rb +4 -5
  321. data/plugins/rigor-rails-routes/lib/rigor/plugin/rails_routes/doorkeeper_routes.rb +2 -2
  322. data/plugins/rigor-rails-routes/lib/rigor/plugin/rails_routes/helper_discoverer.rb +5 -4
  323. data/plugins/rigor-rails-routes/lib/rigor/plugin/rails_routes/helper_table.rb +3 -2
  324. data/plugins/rigor-rails-routes/lib/rigor/plugin/rails_routes/routes_parser.rb +30 -31
  325. data/plugins/rigor-rails-routes/lib/rigor/plugin/rails_routes.rb +13 -15
  326. data/plugins/rigor-rbnacl/lib/rigor/plugin/rbnacl.rb +1 -1
  327. data/plugins/rigor-rspec/lib/rigor/plugin/rspec/let_scope_index.rb +4 -3
  328. data/plugins/rigor-rspec/lib/rigor/plugin/rspec/matcher_analyzer.rb +16 -13
  329. data/plugins/rigor-rspec/lib/rigor/plugin/rspec/scope_walker.rb +3 -2
  330. data/plugins/rigor-shoulda-matchers/lib/rigor/plugin/shoulda_matchers/analyzer.rb +6 -6
  331. data/plugins/rigor-sidekiq/lib/rigor/plugin/sidekiq/analyzer.rb +3 -3
  332. data/plugins/rigor-sorbet/lib/rigor/plugin/sorbet/assertion_recognizer.rb +2 -2
  333. data/plugins/rigor-sorbet/lib/rigor/plugin/sorbet/catalog.rb +3 -2
  334. data/plugins/rigor-sorbet/lib/rigor/plugin/sorbet/catalog_walker.rb +6 -5
  335. data/plugins/rigor-sorbet/lib/rigor/plugin/sorbet/sig_parser.rb +2 -2
  336. data/plugins/rigor-sorbet/lib/rigor/plugin/sorbet/sigil_detector.rb +4 -5
  337. data/plugins/rigor-sorbet/lib/rigor/plugin/sorbet/type_translator.rb +1 -1
  338. data/plugins/rigor-sorbet/lib/rigor/plugin/sorbet.rb +3 -4
  339. data/sig/rigor/analysis/check_rules/suppression.rbs +9 -0
  340. data/sig/rigor/analysis/dependency_recorder.rbs +9 -0
  341. data/sig/rigor/inference.rbs +275 -11
  342. data/sig/rigor/plugin/base.rbs +14 -5
  343. data/sig/rigor/plugin/optimistic_return.rbs +16 -0
  344. data/sig/rigor/scope.rbs +7 -1
  345. data/sig/rigor/source.rbs +4 -0
  346. data/skills/rigor-mcp-setup/SKILL.md +20 -6
  347. data/skills/rigor-plugin-review/SKILL.md +3 -3
  348. data/skills/rigor-type-oracle/references/01-oracle-commands.md +1 -1
  349. metadata +90 -3
@@ -56,6 +56,9 @@ require_relative "template_units"
56
56
  require_relative "runner/effect_envelope_pass"
57
57
  require_relative "runner/effect_annotation_residual_pass"
58
58
  require_relative "runner/buffer_pool_dispatcher"
59
+ require_relative "runner/dependency_rows"
60
+ require_relative "runner/effect_cache_entries"
61
+ require_relative "runner/scope_seed"
59
62
 
60
63
  module Rigor
61
64
  module Analysis
@@ -506,7 +509,7 @@ module Rigor
506
509
  # (sequential + fork-worker) through `project_scope_seed_tables`. Empty unless the project lists
507
510
  # `pre_eval:` files that declare publishable constants, so a project without one is byte-identical.
508
511
  @project_pre_eval_constants = {}.freeze
509
- # Issue #663 — the listed set {#publishable_pre_eval_constants} asks "is this writer one of ours?"
512
+ # Issue #663 — the listed set {ScopeSeed.publishable_pre_eval_constants} asks "is this writer one of ours?"
510
513
  # against; a function of the configuration alone, so it outlives every discovery rebuild.
511
514
  @pre_eval_path_set = nil
512
515
  # ADR-84 WD2 — per-run identity token for the user-method return memo's bucket (see
@@ -761,8 +764,8 @@ module Rigor
761
764
 
762
765
  # Issue #644 — per-file PUBLICATION CENSUS: `{path => {qualified constant name => descriptor}}`, the
763
766
  # value-constant twin of {#class_declarations}. The descriptor (`[literal]` or
764
- # `ScopeIndexer::CONSTANT_UNPUBLISHABLE`) is load-bearing and a bare name set is not: a name's published
765
- # answer is a function of the WHOLE project's write set for it, so what a recheck has to detect is a
767
+ # `ScopeIndexer::ConstantTables::CONSTANT_UNPUBLISHABLE`) is load-bearing and a bare name set is not: a name's
768
+ # published answer is a function of the WHOLE project's write set for it, so what a recheck has to detect is a
766
769
  # change in the census — a value edit, a write becoming unpublishable, a second declarer appearing or
767
770
  # going away — not merely a name appearing.
768
771
  # {Incremental.changed_constant_publications} diffs it; the reader's `constant:` edge is recorded on
@@ -820,7 +823,7 @@ module Rigor
820
823
  # - the whole result is nil for a pool run, whose workers typed the calls in memos this process never sees.
821
824
  #
822
825
  # @return the summaries keyed by `[path, "Class#method"]` (or `"Class.method"`), each holding `keys:`,
823
- # `returns:` and `effects:`, or nil; nil for a pool run.
826
+ # `returns:`, `effects:` and `guard_constants:`, or nil; nil for a pool run.
824
827
  def return_summaries
825
828
  return nil if pool_mode?
826
829
 
@@ -1166,35 +1169,12 @@ module Rigor
1166
1169
  nil
1167
1170
  end
1168
1171
 
1169
- # The read half of the serving entry (#482). A miss, a stale dependency, a corrupt entry and a
1170
- # stored value of the wrong shape are one answer — nil, "collect it again" — because none of them
1171
- # can be told apart from the outside and all of them have the same remedy. An entry from before the
1172
- # split simply does not exist under this producer id, so an older cache re-collects once.
1173
1172
  def peek_effect_summary(descriptor)
1174
- cached = @cache_store.peek_validated(
1175
- producer_id: RunCacheKey::RUN_EFFECTS_TABLE_PRODUCER_ID, key_descriptor: descriptor
1176
- )
1177
- return nil unless cached.is_a?(Array) && cached.length == 3
1178
- return nil unless cached[0].is_a?(Effects::EffectTable) && cached[1].is_a?(Hash) &&
1179
- cached[2].is_a?(Hash)
1180
-
1181
- cached
1182
- rescue StandardError
1183
- nil
1173
+ EffectCacheEntries.peek_effect_summary(@cache_store, descriptor)
1184
1174
  end
1185
1175
 
1186
- # The read half of the collections entry — only ever asked by {#forced_file_effects}, on the paths
1187
- # that need per-file form. The stored shape is `[collections]`; an entry from before the split is
1188
- # `[collections, table]` and its first member is the same Hash, so it still reads.
1189
1176
  def peek_effect_collections(descriptor)
1190
- cached = @cache_store.peek_validated(
1191
- producer_id: RunCacheKey::RUN_EFFECTS_PRODUCER_ID, key_descriptor: descriptor
1192
- )
1193
- return nil unless cached.is_a?(Array) && cached.first.is_a?(Hash)
1194
-
1195
- cached.first
1196
- rescue StandardError
1197
- nil
1177
+ EffectCacheEntries.peek_effect_collections(@cache_store, descriptor)
1198
1178
  end
1199
1179
 
1200
1180
  # The write half, run only after a miss, so nothing here recomputes anything. Two entries under one
@@ -1220,22 +1200,11 @@ module Rigor
1220
1200
  end
1221
1201
 
1222
1202
  def write_effect_entry(producer_id, descriptor, payload, dependencies)
1223
- @cache_store.fetch_or_validate(
1224
- producer_id: producer_id, key_descriptor: descriptor,
1225
- generation_cap: RunCacheKey::EFFECTS_GENERATION_CAP
1226
- ) { [payload, dependencies] }
1203
+ EffectCacheEntries.write_effect_entry(@cache_store, producer_id, descriptor, payload, dependencies)
1227
1204
  end
1228
1205
 
1229
- # An empty table over non-empty summaries is {#close_effect_graph}'s fail-soft answer, not a
1230
- # result — persisting it would freeze one run's propagation failure into every warm hit until the
1231
- # next invalidation. Storing nil instead makes the warm hit re-run the fixpoint, which is exactly
1232
- # the retry the fail-soft posture wants.
1233
1206
  def storable_effect_table(collections)
1234
- table = @effect_table
1235
- return nil if table.nil?
1236
- return nil if table.empty? && collections.any? { |_, collection| !collection.summaries.empty? }
1237
-
1238
- table
1207
+ EffectCacheEntries.storable_effect_table(@effect_table, collections)
1239
1208
  end
1240
1209
  private :serve_effect_collections, :served_from_effect_entries?,
1241
1210
  :effects_key_descriptor, :peek_effect_summary,
@@ -1501,8 +1470,8 @@ module Rigor
1501
1470
 
1502
1471
  # Issue #352 / ADR-17 — the `pre_eval:` CONSTANT publication pre-pass, the twin of the slice-2 patched-
1503
1472
  # METHOD registry the eager pre-passes already build. Walks each listed file's constant writes with the
1504
- # per-file pre-pass ({Inference::ScopeIndexer.build_in_source_constants}) under a project-seeded scope,
1505
- # widens each result to its erased class, and populates `@project_pre_eval_constants` — which
1473
+ # per-file pre-pass ({Inference::ScopeIndexer::ConstantTables.build_in_source_constants}) under a project-seeded
1474
+ # scope, widens each result to its erased class, and populates `@project_pre_eval_constants` — which
1506
1475
  # `project_scope_seed_tables` then seeds onto every per-file scope, so `TIMEOUT = 30` in a listed file
1507
1476
  # reads as `Integer` instead of `Dynamic[top]` in its consumers. The widening + multi-file conflict rules
1508
1477
  # live in {Inference::PreEvalConstants}.
@@ -1598,48 +1567,17 @@ module Rigor
1598
1567
  Cache::Descriptor.new(files: entries, globs: globs.uniq)
1599
1568
  end
1600
1569
 
1601
- # #1962 / #1555 — a kind row per path the run's answer depends on the presence and kind of, not only its
1602
- # bytes. An analysis root: its path errors (`no such file or directory`, `not a Ruby file`) answer to whether
1603
- # it exists and whether it is a directory or a file, while what a directory root holds is the analysed-file
1604
- # set the key carries. A `pre_eval:` entry: `pre-eval.file-not-found` answers to whether it is a file (one
1605
- # that is has its `:stat` row from {#pre_eval_file_entries}). A project signature root, configured or the
1606
- # auto-detected `sig`: the loader reads a directory and a file differently, and #979's listing rows cover a
1607
- # file appearing under a root that existed, not the root appearing. A kind row rather than an existence row,
1608
- # because a directory replaced by a file of the same name leaves an existence row fresh. The `--incremental`
1609
- # slot records kind rows for the same paths ({#incremental_slot_rows}, {#baseline_dependency_rows}, #1977).
1610
1570
  def root_presence_entries(expansion)
1611
- (expansion.fetch(:roots) + @configuration.pre_eval + signature_root_candidates)
1612
- .uniq.map { |path| Cache::Descriptor::FileEntry.kind(path: path) }
1571
+ DependencyRows.root_presence_entries(expansion.fetch(:roots), @configuration.pre_eval,
1572
+ signature_root_candidates)
1613
1573
  end
1614
1574
 
1615
- # Every file a plugin read or probed through its `IoBoundary` (#577 / #613), and every directory it listed
1616
- # (#954), as the boundaries stand when asked.
1617
1575
  def plugin_boundary_rows
1618
- files = []
1619
- globs = []
1620
- @plugin_registry.plugins.each do |plugin|
1621
- # Read the boundary WITHOUT triggering its lazy `@io_boundary ||=` initializer: plugin instances
1622
- # are frozen after the run, and a plugin that never built a boundary read no files through it,
1623
- # so it contributes no dependencies.
1624
- boundary = plugin.instance_variable_get(:@io_boundary)
1625
- next unless boundary
1626
-
1627
- # #629 — a boundary carries GlobEntry listing rows too (`IoBoundary#list_directory`), and they
1628
- # are the only edge back to a file the run decided was ABSENT from a directory it consulted.
1629
- boundary_descriptor = boundary.cache_descriptor
1630
- files.concat(boundary_descriptor.files)
1631
- globs.concat(boundary_descriptor.globs)
1632
- end
1633
- Cache::Descriptor.new(files: files, globs: globs)
1576
+ DependencyRows.plugin_boundary_rows(@plugin_registry.plugins)
1634
1577
  end
1635
1578
 
1636
- # One glob row per producer `watch:` pattern (ADR-60 WD3), recomputed against the tree as it stands.
1637
1579
  def producer_watch_glob_entries
1638
- @plugin_registry.plugins.flat_map do |plugin|
1639
- plugin.class.producers.each_value.flat_map do |prod|
1640
- prod[:watch] ? plugin.send(:watch_glob_entries, prod[:watch]) : []
1641
- end
1642
- end
1580
+ DependencyRows.producer_watch_glob_entries(@plugin_registry.plugins)
1643
1581
  end
1644
1582
 
1645
1583
  # ADR-45 WD2 (#1507) — the rows `rigor check --incremental`'s run-result slot records beside the analysed
@@ -1693,15 +1631,10 @@ module Rigor
1693
1631
  )
1694
1632
  end
1695
1633
 
1696
- # Whether every boundary row that appeared or changed during the per-file loop is one some file's analysis
1697
- # was credited with. A row outside every file's attribution would ride this run's `run` rows only, and the
1698
- # next narrowed run — which does not repeat the read — would drop it.
1699
1634
  def analysis_reads_attributed?
1700
1635
  post = @post_analysis_plugin_rows || plugin_boundary_rows
1701
1636
  pre = @pre_analysis_plugin_rows || post
1702
- credited = @analysis_reads.each_value.flat_map(&:itself).to_set
1703
- (post.files - pre.files).all? { |row| credited.include?(row) } &&
1704
- (post.globs - pre.globs).all? { |row| credited.include?(row) }
1637
+ DependencyRows.analysis_reads_attributed?(post, pre, @analysis_reads)
1705
1638
  end
1706
1639
 
1707
1640
  # ADR-45 WD2 (#1507) — the rows a FULL run records for the inputs an incremental recheck does not re-derive,
@@ -1729,11 +1662,6 @@ module Rigor
1729
1662
  # change time it cannot read, and passes over a `pinned` one.
1730
1663
  BaselineRows = Data.define(:owned, :pinned)
1731
1664
 
1732
- # A loader's two readers {Cache::RbsDescriptor} takes signature roots from. `core_root` (issue #2517) is the
1733
- # selected core, which the slot key names by path only, so its files are `owned` rows like the project's own.
1734
- SignatureRoots = Struct.new(:signature_paths, :core_root)
1735
- private_constant :SignatureRoots
1736
-
1737
1665
  # @param files — the run's analysed-path set.
1738
1666
  def baseline_dependency_rows(files:)
1739
1667
  return nil if pool_mode? || !@collect_stats || @analyzed_files.empty?
@@ -1753,21 +1681,8 @@ module Rigor
1753
1681
  )
1754
1682
  end
1755
1683
 
1756
- # The signature tree's rows, the project's own and the rest.
1757
1684
  def signature_rows
1758
- roots = SignatureRoots.new(@snapshots.signature_paths, @configuration.core_root)
1759
- own = (signature_root_candidates + [@configuration.core_root].compact)
1760
- .map { |root| File.join(File.absolute_path(root.to_s), "") }
1761
- own_files, other_files = Cache::RbsDescriptor.file_entries(roots, comparator: :stat)
1762
- .partition { |row| within?(row.path, own) }
1763
- own_globs, other_globs = Cache::RbsDescriptor.glob_entries(roots).partition { |row| within?(row.root, own) }
1764
- [Cache::Descriptor.new(files: own_files, globs: own_globs.uniq),
1765
- Cache::Descriptor.new(files: other_files, globs: other_globs.uniq)]
1766
- end
1767
-
1768
- def within?(path, roots)
1769
- directory = File.join(File.absolute_path(path.to_s), "")
1770
- roots.any? { |root| directory.start_with?(root) }
1685
+ DependencyRows.signature_rows(@snapshots.signature_paths, @configuration.core_root, signature_root_candidates)
1771
1686
  end
1772
1687
 
1773
1688
  # The project's own signature roots, whether or not they exist:
@@ -1778,90 +1693,34 @@ module Rigor
1778
1693
  Environment.project_signature_root_candidates(@configuration.signature_paths)
1779
1694
  end
1780
1695
 
1781
- # One names-mode listing row per directory the discovery widening globbed, so a file appearing there is seen
1782
- # as well as an edit to one that existed. Issue #1583 — keyed on the widening decision, not on what it
1783
- # added: a run over `lib/b.rb` alone in `lib` widens to nothing, and a `lib/a.rb` created afterwards must
1784
- # still move the answer of the run-result cache and the `--incremental` slot.
1785
1696
  def discovery_glob_entries
1786
- return [] unless @discovery_widened
1787
-
1788
- @configuration.paths.select { |root| File.directory?(root) }.map do |root|
1789
- Cache::Descriptor::GlobEntry.compute(root: root, pattern: PathExpansion::RUBY_GLOB, mode: :names)
1790
- end
1697
+ DependencyRows.discovery_glob_entries(@discovery_widened, @configuration.paths)
1791
1698
  end
1792
1699
 
1793
- # Issue #2987 — one names-mode listing row per bundle `sig/` layout ({Environment::BundleSigDiscovery.discover}'s
1794
- # two globs). The signature rows list only the directories the loader read, so a gem that GAINS a `sig/`
1795
- # (or loses it) while its version and lock entry stand still sits in none of them, and the run-result
1796
- # slot kept serving the environment built without (or with) it.
1797
1700
  def bundle_sig_glob_entries
1798
- root = Environment::BundleSigDiscovery.resolve_bundle_path(
1799
- bundle_path: @configuration.bundler_bundle_path, project_root: Dir.pwd,
1800
- auto_detect: @configuration.bundler_auto_detect
1801
- )
1802
- return [] if root.nil?
1803
-
1804
- Environment::BundleSigDiscovery::SIG_GLOBS.map do |pattern|
1805
- Cache::Descriptor::GlobEntry.compute(root: root.to_s, pattern: pattern, mode: :names)
1806
- end
1701
+ DependencyRows.bundle_sig_glob_entries(@configuration.bundler_bundle_path, @configuration.bundler_auto_detect)
1807
1702
  end
1808
1703
 
1809
1704
  def unanalysed_pre_eval_entries(files)
1810
- analysed = files.to_set { |path| File.absolute_path(path) }
1811
- outside = @configuration.pre_eval.reject { |path| analysed.include?(File.absolute_path(path)) }
1812
- outside.map do |path|
1813
- if File.file?(path)
1814
- Cache::Descriptor::FileEntry.stat(path: path, digest: Cache::FileDigest.hexdigest(path))
1815
- else
1816
- kind_entries([path]).first
1817
- end
1818
- end
1705
+ DependencyRows.unanalysed_pre_eval_entries(files, @configuration.pre_eval, @buffer)
1819
1706
  end
1820
1707
 
1821
- # #1977 — one `:kind` row per path, the row {#root_presence_entries} records in the plain slot.
1822
1708
  def kind_entries(paths)
1823
- paths.uniq.map do |path|
1824
- Cache::Descriptor::FileEntry.kind(path: @buffer ? @buffer.resolve(path) : path)
1825
- end
1709
+ DependencyRows.kind_entries(paths, @buffer)
1826
1710
  end
1827
1711
  private :plugin_boundary_rows, :producer_watch_glob_entries, :kind_entries, :root_presence_entries,
1828
1712
  :analysis_reads_attributed?, :signature_root_candidates, :discovery_glob_entries,
1829
1713
  :bundle_sig_glob_entries,
1830
- :unanalysed_pre_eval_entries, :signature_rows, :within?
1714
+ :unanalysed_pre_eval_entries, :signature_rows
1831
1715
 
1832
- # Issue #684 — the project files this run DISCOVERED but did not analyse. A widened run's diagnostics
1833
- # are a function of them (that is the entire point: the method whose absence would have been reported
1834
- # is defined in one of them), so the run-result cache must invalidate when one changes. Empty on every
1835
- # run whose discovery expansion is its analysis expansion, which is every whole-project run.
1836
1716
  def discovery_file_entries(expansion)
1837
- return [] if @project_discovery_expansion.nil?
1838
-
1839
- analyzed = expansion.fetch(:files).to_set
1840
- analyzed_file_entries(
1841
- { files: @project_discovery_expansion.fetch(:files).reject { |path| analyzed.include?(path) } }
1842
- )
1717
+ DependencyRows.discovery_file_entries(expansion, @project_discovery_expansion, @buffer)
1843
1718
  end
1844
1719
 
1845
1720
  def analyzed_file_entries(expansion)
1846
- expansion.fetch(:files).map do |path|
1847
- physical = @buffer ? @buffer.resolve(path) : path
1848
- # ADR-87 WD1 — validation-only dependency descriptor, so the stat-then-digest `:stat` comparator
1849
- # applies (the env-cache KEY files stay `:digest`).
1850
- Cache::Descriptor::FileEntry.stat(path: physical, digest: Cache::FileDigest.hexdigest(physical))
1851
- end
1721
+ DependencyRows.analyzed_file_entries(expansion, @buffer)
1852
1722
  end
1853
1723
 
1854
- # Issue #352 — a `pre_eval:` file is a real input to the run's diagnostics: its `def`s populate the
1855
- # ADR-17 patched-method registry and (since #352) its constants populate the project seed. ADR-17 WD5
1856
- # permits listing a file under `pre_eval:` and NOT under `paths:`, and such a file never appears in the
1857
- # expansion — so without this entry, editing one would leave the run-result cache serving diagnostics
1858
- # computed against the previous version. The common case (a `lib/core_ext/` file that is also under
1859
- # `paths:`) contributes a duplicate entry, which the descriptor's per-path validation absorbs.
1860
- # #392 — the TEMPLATE files behind the run's units. The key slot carries the compiled Ruby's digest
1861
- # (`template_units_digest`), which is what decides whether a cached answer describes this source; these
1862
- # entries are the validation half, so a template edited between two runs re-globs and re-digests here
1863
- # exactly as an analysed `.rb` file does. Both are needed: a transform that compiles two different
1864
- # templates to the same Ruby must still not resurrect the wrong PATH in a diagnostic.
1865
1724
  # #392 — one `:names` row per claimed `template_globs:` pattern, whether or not it matched. The file
1866
1725
  # rows below cover edits to templates that EXIST; only a glob row notices one appearing or vanishing,
1867
1726
  # which is what let a project's first template stay invisible to every warm run.
@@ -1869,25 +1728,12 @@ module Rigor
1869
1728
  template_units.glob_entries
1870
1729
  end
1871
1730
 
1872
- # Every template the run READ, successes and failures alike: a `plugin_loader` row produced by a
1873
- # template that would not compile must not outlive the edit that fixes it, and a buffer-bound path is
1874
- # digested at the bytes the run actually read.
1875
1731
  def template_unit_file_entries
1876
- template_units.source_paths.filter_map do |path|
1877
- physical = template_units.physical_path(path, @buffer)
1878
- next unless File.file?(physical)
1879
-
1880
- Cache::Descriptor::FileEntry.stat(path: physical, digest: Cache::FileDigest.hexdigest(physical))
1881
- end
1732
+ DependencyRows.template_unit_file_entries(template_units, @buffer)
1882
1733
  end
1883
1734
 
1884
1735
  def pre_eval_file_entries
1885
- @configuration.pre_eval.filter_map do |path|
1886
- physical = @buffer ? @buffer.resolve(path) : path
1887
- next unless File.file?(physical)
1888
-
1889
- Cache::Descriptor::FileEntry.stat(path: physical, digest: Cache::FileDigest.hexdigest(physical))
1890
- end
1736
+ DependencyRows.pre_eval_file_entries(@configuration.pre_eval, @buffer)
1891
1737
  end
1892
1738
 
1893
1739
  # Runs every project-wide pre-pass (`load_plugins` +
@@ -2222,14 +2068,6 @@ module Rigor
2222
2068
  @served_effect_collections.merge(effect_collections_by_path).sort_by { |path, _| path.to_s }.map(&:last)
2223
2069
  end
2224
2070
 
2225
- # Editor mode § "Scope choice — option A". Under `buffer:` non-nil the per-file analysis emits
2226
- # diagnostics ONLY for the buffer's logical path; the rest of `paths:` is consumed by the
2227
- # project-wide pre-passes (synthetic methods, project-patched methods, plugin facts) but contributes
2228
- # no per-file diagnostics. Option B (#146) narrows to the closure instead; see {#target_files}.
2229
- #
2230
- # The buffer's logical path is added to the file list even if it's not under `paths:` — per design §
2231
- # "Failure envelope": "--instead-of=Y with Y not under any paths: directory → treated as a valid
2232
- # logical identity for the buffer".
2233
2071
  # #392 — the run's template units. Built once per run, on the parent, AFTER the plugin pre-pass has
2234
2072
  # loaded the registry; a run whose plugins declare no `template_globs:` never globs and never calls a
2235
2073
  # plugin.
@@ -2249,6 +2087,14 @@ module Rigor
2249
2087
  end
2250
2088
  end
2251
2089
 
2090
+ # Editor mode § "Scope choice — option A". Under `buffer:` non-nil the per-file analysis emits
2091
+ # diagnostics ONLY for the buffer's logical path; the rest of `paths:` is consumed by the
2092
+ # project-wide pre-passes (synthetic methods, project-patched methods, plugin facts) but contributes
2093
+ # no per-file diagnostics. Option B (#146) narrows to the closure instead; see {#target_files}.
2094
+ #
2095
+ # The buffer's logical path is added to the file list even if it's not under `paths:` — per design §
2096
+ # "Failure envelope": "--instead-of=Y with Y not under any paths: directory → treated as a valid
2097
+ # logical identity for the buffer".
2252
2098
  def target_files(expansion)
2253
2099
  files = expansion.fetch(:files)
2254
2100
  # ADR-46 slice 2 — restrict the analyzed set to the affected closure while the pre-pass (run
@@ -2322,9 +2168,9 @@ module Rigor
2322
2168
 
2323
2169
  # Wires the three responsibility collaborators. Called at the end of construction (after every state
2324
2170
  # ivar is seeded). The per-run varying state (the plugin registry, dependency-source / scanner
2325
- # indexes, prepare-diagnostic snapshot, and the four end-of-pass snapshots) is reached through reader
2326
- # procs so each collaborator observes the live ivar value at call time without a back-reference
2327
- # cycle. The reporter accumulators and the {RunSnapshots} sink are shared mutable instances.
2171
+ # indexes, prepare-diagnostic snapshot) is reached through reader procs so each collaborator observes
2172
+ # the live ivar value at call time without a back-reference cycle. The reporter accumulators and the
2173
+ # {RunSnapshots} sink are shared mutable instances.
2328
2174
  def build_collaborators # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
2329
2175
  @pre_passes = ProjectPrePasses.new(
2330
2176
  configuration: @configuration, cache_store: @cache_store, buffer: @buffer,
@@ -2656,36 +2502,15 @@ module Rigor
2656
2502
  merged
2657
2503
  end
2658
2504
 
2659
- # The three mixin tables: the ADR-24 instance-side `include` map, its issue #1123 `prepend` twin
2660
- # (which carries the instance-ancestor order the include table's set-shaped value cannot), and the
2661
- # #898 singleton-side `extend` table. Grouped here because they are read as one picture of a class's
2662
- # ancestry, and split out of {#project_scope_seed_tables} to keep it under the complexity budget.
2663
2505
  def seed_mixin_tables(tables)
2664
- tables[:discovered_includes] = @project_discovered_includes unless @project_discovered_includes.empty?
2665
- tables[:discovered_prepends] = @project_discovered_prepends unless @project_discovered_prepends.empty?
2666
- tables[:discovered_extends] = @project_discovered_extends unless @project_discovered_extends.empty?
2667
- tables[:unpositioned_mixins] = @project_unpositioned_mixins unless @project_unpositioned_mixins.empty?
2506
+ ScopeSeed.seed_mixin_tables(tables, @project_discovered_includes, @project_discovered_prepends,
2507
+ @project_discovered_extends, @project_unpositioned_mixins)
2668
2508
  end
2669
2509
 
2670
- # ADR-46 slice 1 / issue #644 — the two SOURCE-ATTRIBUTION tables, read by the recording accessors
2671
- # (`Scope#record_class_dependency` for the class-declaration map, `Scope#record_constant_dependency`
2672
- # for the constant-write map). The class-declaration map rides every run: an ancestor-order reader also
2673
- # asks whether a class is declared in more than one file. The constant-write map rides only a recording
2674
- # run. Extracted to keep {#project_scope_seed_tables} under the complexity budget.
2675
- #
2676
- # Issue #617 — the census's binding writes, grouped by last segment, ride every run instead: a constant
2677
- # compound write whose plain read resolves nothing reads its binding off them, a TYPE rather than an edge.
2678
- # Issue #1290's shadowing writes ride beside them for the lexical ladder, for the same reason.
2679
2510
  def seed_dependency_attribution_tables(tables)
2680
- writers = constant_writer_index
2681
- tables[:constant_writers] = writers unless writers.empty?
2682
- shadowers = constant_shadower_index
2683
- tables[:constant_shadowers] = shadowers unless shadowers.empty?
2684
- tables[:discovered_class_sources] = @project_discovered_class_sources unless
2685
- @project_discovered_class_sources.empty?
2686
- return unless @record_dependencies
2687
-
2688
- tables[:constant_sources] = @project_constant_sources unless @project_constant_sources.empty?
2511
+ ScopeSeed.seed_dependency_attribution_tables(tables, constant_writer_index, constant_shadower_index,
2512
+ @project_discovered_class_sources, @record_dependencies,
2513
+ @project_constant_sources)
2689
2514
  end
2690
2515
 
2691
2516
  # Issue #260 — the mutable starting point {#project_scope_seed_tables} fills in: a copy of the opt-in
@@ -2732,71 +2557,9 @@ module Rigor
2732
2557
  @published_constant_name_set ||= Inference::ProjectSeedTables.published_constant_names(@project_constant_values)
2733
2558
  end
2734
2559
 
2735
- # Issue #644 — the seeded `in_source_constants` table, joining the two cross-file constant producers.
2736
- # The whole-project literal table wins over a `pre_eval:` publication of the same name: both describe
2737
- # the same assignment, the literal table pins the value the write actually carries while ADR-17's
2738
- # widener erases it to the class, and listing a file under `pre_eval:` must never LOSE precision. The
2739
- # per-file table still wins over both (`ScopeIndexer.index`'s merge) — same-file stays the most
2740
- # specific authority.
2741
- #
2742
- # ADR-124 — a `prebuilt:` runner computes no literal table of its own; a `discovery_seed:` (the editor
2743
- # publish, ADR-124) brings the project's, which then plays the same part.
2744
2560
  def merged_seed_constants
2745
- pre_eval = publishable_pre_eval_constants
2746
- literal = literal_seed_constants
2747
- return literal if pre_eval.empty?
2748
- return pre_eval if literal.empty?
2749
-
2750
- pre_eval.merge(literal).freeze
2751
- end
2752
-
2753
- # The project's literal constant table: this run's, or the one a `discovery_seed:` carries (ADR-124).
2754
- def literal_seed_constants
2755
- return @project_constant_values unless @project_constant_values.empty? && @discovery_seed
2756
-
2757
- @discovery_seed.fetch(:in_source_constants, @project_constant_values)
2758
- end
2759
-
2760
- # The per-name writer paths the #663 retraction reads: this run's census, or the one a `discovery_seed:` carries
2761
- # (ADR-124).
2762
- def constant_writer_sources
2763
- return @project_constant_sources unless @project_constant_sources.empty? && @discovery_seed
2764
-
2765
- @discovery_seed.fetch(:constant_sources, @project_constant_sources)
2766
- end
2767
-
2768
- # Issue #663 — the `pre_eval:` publication with every name an UNLISTED file also assigns retracted.
2769
- # Without this a listed `X = :a` answered `Symbol` at every reader while a sibling `X = "str"` decided
2770
- # the runtime value half the time: a confident wrong type, not lost precision, and the one asymmetry
2771
- # #644's precedence work left standing. The retraction costs the opt-in nothing where it earns its
2772
- # keep — a name only listed files write is untouched, and where the literal table also publishes it
2773
- # already won (above).
2774
- #
2775
- # Conflict is read off #644's write attribution, which censuses every assigning form, so a name the
2776
- # listed file's own typed walk widened is retracted by an unlisted `X += 1` or `A, X = 1, 2` as
2777
- # readily as by a plain reassignment. Among LISTED files the rule is unchanged: `PreEvalConstants`
2778
- # widens first and drops only on disagreement, so two listed files writing `1` and `2` still publish
2779
- # `Integer` rather than being retracted for being two.
2780
- def publishable_pre_eval_constants
2781
- return @project_pre_eval_constants if @project_pre_eval_constants.empty?
2782
-
2783
- listed = pre_eval_path_set
2784
- kept = @project_pre_eval_constants.reject { |name, _| unlisted_constant_writer?(name, listed) }
2785
- kept.size == @project_pre_eval_constants.size ? @project_pre_eval_constants : kept.freeze
2786
- end
2787
-
2788
- # True when some file outside `listed` assigns `name`. The wildcard key is consulted alongside the
2789
- # name's own attribution ([#668](https://github.com/rigortype/rigor/issues/668)): a `k::X = 7` names
2790
- # no target, and a listed file kept out of `paths:` (ADR-17 WD5 permits it) contributes no censused
2791
- # name of its own for the wildcard's paths to have been folded into.
2792
- def unlisted_constant_writer?(name, listed)
2793
- segment = name.split("::").last
2794
- sources = constant_writer_sources
2795
- writers = sources[name]
2796
- wildcard = sources["#{Inference::ScopeIndexer::DYNAMIC_TARGET_PREFIX}#{segment}"]
2797
- [writers, wildcard].any? do |paths|
2798
- paths&.any? { |path| !listed.include?(File.absolute_path(path)) }
2799
- end
2561
+ ScopeSeed.merged_seed_constants(@project_pre_eval_constants, @project_constant_values, @discovery_seed,
2562
+ @project_constant_sources, pre_eval_path_set)
2800
2563
  end
2801
2564
 
2802
2565
  # The listed `pre_eval:` files, expanded so a census path and a configured one compare as the same
@@ -2805,23 +2568,13 @@ module Rigor
2805
2568
  @pre_eval_path_set ||= @configuration.pre_eval.to_set { |path| File.absolute_path(path) }
2806
2569
  end
2807
2570
 
2808
- # ADR-46 — seed the instance + singleton `"path:line"` def-source tables (each only when non-empty).
2809
- # Extracted to keep {#project_scope_seed_tables} under the complexity budget. The singleton table (slice 4
2810
- # extension) rides the same seed so a pooled `WorkerSession` records singleton symbol edges identically.
2811
2571
  def seed_def_source_tables(tables)
2812
- tables[:discovered_def_sources] = @project_discovered_def_sources unless @project_discovered_def_sources.empty?
2813
- return if @project_discovered_singleton_def_sources.empty?
2814
-
2815
- tables[:discovered_singleton_def_sources] = @project_discovered_singleton_def_sources
2572
+ ScopeSeed.seed_def_source_tables(tables, @project_discovered_def_sources,
2573
+ @project_discovered_singleton_def_sources)
2816
2574
  end
2817
2575
 
2818
- # ADR-48 — seed the Data + Struct member-layout tables (each only when non-empty). Extracted to keep
2819
- # {#project_scope_seed_tables} under the complexity budget.
2820
2576
  def seed_member_layout_tables(tables)
2821
- tables[:data_member_layouts] = @project_data_member_layouts unless @project_data_member_layouts.empty?
2822
- return if @project_struct_member_layouts.empty?
2823
-
2824
- tables[:struct_member_layouts] = @project_struct_member_layouts
2577
+ ScopeSeed.seed_member_layout_tables(tables, @project_data_member_layouts, @project_struct_member_layouts)
2825
2578
  end
2826
2579
 
2827
2580
  # ADR-46 slice 1 — when dependency recording is enabled, wrap the per-file analysis so the cross-file
@@ -26,7 +26,7 @@ module Rigor
26
26
  # Two plugins claiming one path is a conflict with no principled winner, so registration order decides
27
27
  # and the later claim is dropped; the loser is not a diagnostic (the project chose both plugins).
28
28
  # @param previous — a warm index from an earlier run of the same project (#1038). Every unit in it
29
- # whose template is unchanged on disk is carried over instead of recompiled; see the class note.
29
+ # whose template is unchanged on disk is carried over instead of recompiled; see {TemplateUnits}' class note.
30
30
  def self.collect(registry:, root: Dir.pwd, buffer: nil, previous: nil)
31
31
  claims = claims_for(registry)
32
32
  claimed = claims.flat_map(&:last).uniq
@@ -212,16 +212,6 @@ module Rigor
212
212
  @entries.transform_values(&:source)
213
213
  end
214
214
 
215
- # The index's cache identity: every unit's digest (source bytes + transform id + synthesis version)
216
- # keyed by path, plus every FAILURE keyed by path, hashed once. nil only when the run's plugins
217
- # claimed no globs at all, so a project with no template-unit plugin perturbs no cache key.
218
- #
219
- # The failures are in it because a run that produced only failures still produced an ANSWER — one
220
- # `plugin_loader` row per file — and without them that run's key equalled the no-templates key. A
221
- # later run whose template now compiles, or whose template is gone, reconstructed the same key, and
222
- # the ADR-87 boot-slim probe (which loads no plugin, so its slot is always absent) served the stale
223
- # rows. The slot now exists whenever any plugin claimed a glob, which is exactly the condition under
224
- # which the probe's key is knowingly unreconstructable.
225
215
  def build_declined_unit_keys
226
216
  declined = @stats.keys - @entries.keys
227
217
  return NO_DECLINED_KEYS if declined.empty?
@@ -258,6 +248,16 @@ module Rigor
258
248
  end
259
249
  private :strip_handler
260
250
 
251
+ # The index's cache identity: every unit's digest (source bytes + transform id + synthesis version)
252
+ # keyed by path, plus every FAILURE keyed by path, hashed once. nil only when the run's plugins
253
+ # claimed no globs at all, so a project with no template-unit plugin perturbs no cache key.
254
+ #
255
+ # The failures are in it because a run that produced only failures still produced an ANSWER — one
256
+ # `plugin_loader` row per file — and without them that run's key equalled the no-templates key. A
257
+ # later run whose template now compiles, or whose template is gone, reconstructed the same key, and
258
+ # the ADR-87 boot-slim probe (which loads no plugin, so its slot is always absent) served the stale
259
+ # rows. The slot now exists whenever any plugin claimed a glob, which is exactly the condition under
260
+ # which the probe's key is knowingly unreconstructable.
261
261
  def digest
262
262
  return nil if @claimed_globs.empty?
263
263
 
@@ -214,9 +214,6 @@ module Rigor
214
214
  private :analyze_with_effects
215
215
  private :analyze_attributed
216
216
 
217
- # ADR-103 WD6 / #386 — the worker-side mirror of `Runner#effect_envelope_index`. Derived from the
218
- # same configuration and the session's own environment, so a worker's `≤` lane is the one the
219
- # parent would have computed for the same file.
220
217
  # ADR-103 WD10 / #387 — the worker-side mirror of `Runner#effect_plugin_facts`. The superclass table
221
218
  # arrives with the coordinator's scope seed, so a worker resolves an `ActiveRecord::Base` row through
222
219
  # the same project ancestry the parent would have walked.
@@ -229,6 +226,9 @@ module Rigor
229
226
  end
230
227
  private :effect_plugin_facts
231
228
 
229
+ # ADR-103 WD6 / #386 — the worker-side mirror of `Runner#effect_envelope_index`. Derived from the
230
+ # same configuration and the session's own environment, so a worker's `≤` lane is the one the
231
+ # parent would have computed for the same file.
232
232
  def effect_envelope_index
233
233
  @effect_envelope_index ||= Effects::EnvelopeIndex.build(
234
234
  configuration: @configuration, environment: @environment, plugin_facts: effect_plugin_facts
@@ -294,9 +294,9 @@ module Rigor
294
294
  end
295
295
  private :built_in_collectors
296
296
 
297
- # Read-once snapshot of the per-worker reporters so the caller (or the eventual Phase 4b pool
298
- # aggregator) can merge into a single coordinator-side reporter. Both reporters dedupe at write time,
299
- # so a post-hoc concat + de-dup at the entry-key level is sound.
297
+ # Read-once snapshot of the per-worker reporters so the caller (the pool coordinator) can merge into a
298
+ # single coordinator-side reporter. The reporters dedupe at write time, so a post-hoc
299
+ # concat + de-dup at the entry-key level is sound.
300
300
  #
301
301
  # Issue #696 — `definition_build_failures` rides this channel rather than a coordinator-side snapshot,
302
302
  # and it has to. Under the pool the PARENT never analyses a file, so its loader never demands a
@@ -368,7 +368,7 @@ module Rigor
368
368
  # instances registered, each tagged with the plugin id the coordinator de-duplicates by — including the
369
369
  # positioned batches of {Plugin::Base#emit_once} (#1060), which ride the same records. Marshal-clean
370
370
  # (frozen Hashes of Strings and Symbols, and frozen `Diagnostic` copies for a batch) so the fork pool
371
- # ships them back like the three drains above;
371
+ # ships them back like the drains above;
372
372
  # a registration made on the PARENT during `#prepare` is already visible to the coordinator through
373
373
  # the pre-fork session, and one a worker makes while analysing its slice arrives through the payload.
374
374
  # Entries are not cleared — a drain is a read, and the parent session is drained again on the degrade
@@ -25,8 +25,9 @@ module Rigor
25
25
  # identically on the miss path and the warm-hit path, so a warm HIT re-resolves under the
26
26
  # current selector. A behaviour feature that altered analysis results themselves would poison
27
27
  # warm caches across selector changes, because the selector is not part of the cache key. The
28
- # two queued consumers (#253, #254) change what a separate command measures, not what `check`
29
- # analyses, so neither is affected.
28
+ # two mutation-measurement consumers (#253, #254) change what a separate command measures, not
29
+ # what `check` analyses, so neither is affected; `effects-on-by-default` spells out its own
30
+ # argument at its entry.
30
31
  #
31
32
  # Each feature carries a **stable feature id** — part of the ADR-50 WD1 contract
32
33
  # vocabulary: the config, the `show` command, and the eventual CHANGELOG migration note all