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
@@ -215,8 +215,8 @@ module Rigor
215
215
  # provenance (slice 5) can iterate over loaded plugin instances in deterministic order.
216
216
  #
217
217
  # The registry is read-only after construction; ordering is the order in which {Rigor::Plugin::Loader}
218
- # resolved configuration entries, which is project-config order with plugin-id alphabetical as the
219
- # tie-breaker.
218
+ # resolved configuration entries: project-config order, reordered only by the `manifest(consumes:)`
219
+ # topological sort.
220
220
  #
221
221
  # ADR-15 Phase 3 — alongside the instantiated `plugins`, the registry carries `blueprints`: a frozen,
222
222
  # Ractor-shareable list of {Blueprint} that records how to re-instantiate the same plugin set in a worker
@@ -93,7 +93,8 @@ module Rigor
93
93
  end
94
94
 
95
95
  # The unit's cache identity — **source bytes + transform id + synthesis version**, the triple
96
- # `docs/internal-spec/cache.md` § computed-value keys asks a synthesised input to carry. The
96
+ # `docs/internal-spec/cache.md` § computed-value keys asks a synthesised input to carry, plus the
97
+ # suppressed-rule prefixes because they change what the unit reports. The
97
98
  # template's own bytes are deliberately NOT in it: the engine analyses `ruby_source`, and two
98
99
  # templates that compile to the same Ruby have the same answer.
99
100
  #
@@ -112,7 +113,8 @@ module Rigor
112
113
 
113
114
  # The template line a `ruby_source` line reports at. Falls back to the nearest mapped line before it
114
115
  # — a synthesised prologue or a buffer-append the compiler emitted between two template lines still
115
- # points into the template rather than past its end — and to line 1 when the map says nothing at all.
116
+ # points into the template rather than past its end — and to line 1 when no mapped line precedes it. An
117
+ # empty map is the identity.
116
118
  def template_line(ruby_line)
117
119
  return ruby_line if @line_map.empty?
118
120
  return @line_map[ruby_line] if @line_map.key?(ruby_line)
@@ -17,7 +17,8 @@ module Rigor
17
17
  # ## Fields
18
18
  #
19
19
  # - `trusted_gems`: gem names the user has authorised. Derived from the `plugins:` section of `.rigor.yml`
20
- # plus any gems they reach transitively. Used today for documentation and future trust diagnostics.
20
+ # (the gem-name half of each entry; transitive dependencies are not added). Used today for
21
+ # documentation and future trust diagnostics.
21
22
  # - `allowed_read_roots`: absolute paths plugin code may read from through the {IoBoundary}. The default
22
23
  # set covers the project root, the project's `signature_paths`, and each trusted
23
24
  # gem's `Gem::Specification#full_gem_path`. The user extends this with `.rigor.yml`'s
data/lib/rigor/plugin.rb CHANGED
@@ -37,7 +37,7 @@ module Rigor
37
37
  "Rigor::Plugin.register expects a subclass of Rigor::Plugin::Base, got #{plugin_class.inspect}"
38
38
  end
39
39
 
40
- manifest = plugin_class.manifest # rigor:disable undefined-method
40
+ manifest = plugin_class.manifest
41
41
  @mutex.synchronize do
42
42
  existing = @registered[manifest.id]
43
43
  if existing && existing != plugin_class
@@ -28,14 +28,6 @@ module Rigor
28
28
  end
29
29
  end
30
30
 
31
- # Generates type-visible mutations of a Ruby source string by walking the Prism AST and recording byte-range
32
- # splices (no unparser needed — Prism hands us exact offsets, and the analyzer re-parses the spliced source).
33
- #
34
- # A mutation is "type-visible" when it should trip a diagnostic rule *if* Rigor holds a type at the site: a
35
- # call-argument literal dropped to `nil` or type-swapped (→ `call.argument-type-mismatch`), or a call site
36
- # renamed to a missing method (→ `call.undefined-method`). Only call sites and bodies are mutated, never
37
- # `def` signatures, so a reused project scan stays valid.
38
-
39
31
  # Signature-arity guard for `arity_extra` (ADR-62): verifies through `ScopeIndexer` and
40
32
  # `Reflection` that a call site targets a known, fixed/bounded positional signature and that
41
33
  # adding 1 argument exceeds `max_arity`. Drops variadic or untyped calls to eliminate noise.
@@ -133,12 +125,19 @@ module Rigor
133
125
  end
134
126
  end
135
127
 
128
+ # Generates type-visible mutations of a Ruby source string by walking the Prism AST and recording byte-range
129
+ # splices (no unparser needed — Prism hands us exact offsets, and the analyzer re-parses the spliced source).
130
+ #
131
+ # A mutation is "type-visible" when it should trip a diagnostic rule *if* Rigor holds a type at the site: a
132
+ # call-argument literal dropped to `nil` or type-swapped (→ `call.argument-type-mismatch`), or a call site
133
+ # renamed to a missing method (→ `call.undefined-method`). Only call sites and bodies are mutated, never
134
+ # `def` signatures, so a reused project scan stays valid.
136
135
  class Mutator
137
136
  IDENT = /\A[a-z_][A-Za-z0-9_]*\z/
138
137
  QUOTES = ['"', "'"].freeze
139
138
  # Mutating an argument to a universal-equality method is always an equivalent mutant: Ruby's `==` / `<=>`
140
139
  # family returns false / nil on a type mismatch rather than raising, so the engine exempts them
141
- # (`CheckRules::UNIVERSAL_EQUALITY_METHODS`; keep the two in step). Skip them to keep survivors meaningful.
140
+ # (`ArgumentType::UNIVERSAL_EQUALITY_METHODS`; keep the two in step). Skip them to keep survivors meaningful.
142
141
  UNIVERSAL_EQUALITY = %w[== != eql? equal? <=>].freeze
143
142
 
144
143
  # Every operator the mutator knows. Each maps to the diagnostic rule family it is *engineered* to trip when
@@ -6,7 +6,7 @@ module Rigor
6
6
  # cannot surface at the point of failure (the parsers are fail-soft, returning `nil` so call sites fall back
7
7
  # to the RBS-declared type).
8
8
  #
9
- # Owns three event streams:
9
+ # Owns four event streams:
10
10
  #
11
11
  # - `#unresolved_payloads` — `rigor:v1:*` directive payloads the resolver could not turn into a
12
12
  # {Rigor::Type}. Surface as `dynamic.rbs-extended.unresolved` `:info` diagnostics, except an
@@ -33,7 +33,7 @@ module Rigor
33
33
  class Reporter
34
34
  # Every entry carries its position as `(path, line, column)` primitives, flattened from the parser's
35
35
  # `RBS::Location` by {.position_of} at record time. Issues #785 (hkt) and #805 (the two older streams).
36
- # Two reasons, and either alone decides it. All three streams are drained out of every fork-pool worker
36
+ # Two reasons, and either alone decides it. All four streams are drained out of every fork-pool worker
37
37
  # ({Rigor::Analysis::WorkerSession#drain_reporters}), and an `RBS::Location` is a C-extension object with
38
38
  # no `_dump`, so a `Marshal.dump` of the drain payload raises `TypeError` — which kills the worker at
39
39
  # drain time and degrades the run to in-process re-analysis. And an `RBS::Location` compares equal only
@@ -876,8 +876,8 @@ module Rigor
876
876
  end
877
877
 
878
878
  # ADR-13 slice 3b — guards every reporter call so the in-RbsExtended-module call sites can record events
879
- # uniformly without nil-checking each time. When the reporter is nil (the v0.1.0 → v0.1.3 default for call
880
- # sites that do not yet thread `environment:`), the call is a no-op and the parser stays fail-soft.
879
+ # uniformly without nil-checking each time. When the reporter is nil (a call site that does not
880
+ # thread `environment:`), the call is a no-op and the parser stays fail-soft.
881
881
  #
882
882
  # Issue #805 — the location is flattened to `(path, line, column)` here, at record time, because the
883
883
  # entry is drained out of every fork-pool worker and an `RBS::Location` neither survives `Marshal.dump`
@@ -252,7 +252,7 @@ module Rigor
252
252
  # reopens an RBS module without restating its `include`s makes it a project entry whose chain lists only
253
253
  # the edges the project writes, so its ancestry is read less what that chain lists. The ancestry comes from
254
254
  # the declarations (`RbsLoader#declared_ancestry`), so a definition that fails to build still yields what
255
- # it declares. Where it cannot be read whole, {.ancestry_unknown?} keeps the later RBS-only mixins out
255
+ # it declares. Where it cannot be read whole, {.ancestry_unknown_before?} keeps the later RBS-only mixins out
256
256
  # instead of stopping here.
257
257
  def mixin_ancestry_stop?(owner, scope, external)
258
258
  loader = rbs_loader_for(scope, nil)
@@ -132,8 +132,8 @@ module Rigor
132
132
  # splatted `Struct.new(*FIELDS)`, `attr_accessor(*NAMES)`, a `define_method` under a computed name) answers
133
133
  # `maybe`: it defines methods under names no table holds. Issue #2994 — so does an instance side whose chain mixes
134
134
  # in a module no table names (`include(*MODS)`, `ResolutionChain#unnamed_mixin?`); the #618 top-level-`def` veto
135
- # (`ExpressionTyper#instance_self_answers?`) reads the same mark, so a plugin that stands down here does not hand
136
- # the call to a top-level `def`.
135
+ # (`CallLadder::TopLevelDef.instance_self_answers?`) reads the same mark, so a plugin that stands down here does
136
+ # not hand the call to a top-level `def`.
137
137
  def project_discovered_defined(class_name, method_name, kind, scope)
138
138
  unless scope.discovered_method_through_ancestors?(class_name, method_name, kind)
139
139
  return open_side?(class_name, kind, scope) ? Trinary.maybe : Trinary.no
@@ -256,10 +256,10 @@ module Rigor
256
256
  private_class_method :ancestor_constant_type
257
257
 
258
258
  # Issue #716 — whether the scope carries a RECORDED empty `Module.nesting`, which is the declaration
259
- # walk's positive statement that the body is written at the top level (`Inference::ScopeIndexer#
260
- # walk_def_nestings`). Distinct from `nil`, which still means "no declaration walk built this scope" and
261
- # keeps the peel ({.lexical_nesting_chain}); the two are only distinguishable because the table is
262
- # populated by that walk alone.
259
+ # walk's positive statement that the body is written at the top level
260
+ # (`Inference::ScopeIndexer::SharedWalkTables.walk_def_nestings`). Distinct from `nil`, which still means "no
261
+ # declaration walk built this scope" and keeps the peel ({.lexical_nesting_chain}); the two are only
262
+ # distinguishable because the table is populated by that walk alone.
263
263
  def recorded_toplevel_nesting?(scope) = scope.lexical_nesting.is_a?(Array) && scope.lexical_nesting.empty?
264
264
  private_class_method :recorded_toplevel_nesting?
265
265
 
@@ -43,6 +43,7 @@ module Rigor
43
43
  :local_constant_names,
44
44
  :published_constant_alias_names,
45
45
  :published_constant_ivars,
46
+ :published_constant_cvars,
46
47
  :data_member_layouts,
47
48
  :struct_member_layouts,
48
49
  :param_inferred_types,
@@ -75,9 +76,9 @@ module Rigor
75
76
 
76
77
  # ADR-119 WD1 — each member that may one day admit `possible` or `contested` facts, and the sibling that
77
78
  # holds them. Every copy path reads this one declaration, so a member never travels without its sibling:
78
- # {#with} raises on a half pair and {.compact_pairs} drops a pair only when BOTH halves are empty. No
79
- # producer fills a sibling yet (the lane-1 carriage), so every sibling is empty and each member keeps its
80
- # meaning, the union of its certain and possible facts.
79
+ # {#with} raises on a half pair and {.compact_pairs} drops a pair only when BOTH halves are empty. A sibling
80
+ # holds only what a conditional definer contributes (ADR-119 WD3), and each member keeps its meaning, the union
81
+ # of its certain and possible facts.
81
82
  #
82
83
  # - `possible_*` has its member's shape and is a subset of it (a `discovered_methods` pair is a
83
84
  # `{class => {name => kind}}` table).
@@ -105,7 +106,7 @@ module Rigor
105
106
  private_constant :PARTNERS
106
107
 
107
108
  # [#1507](https://github.com/rigortype/rigor/issues/1507) — the kind of fact each member holds, which decides
108
- # what a reader may conclude from an entry and which gate covers the member (ADR-119 WD4, proposed). Each
109
+ # what a reader may conclude from an entry and which gate covers the member (ADR-119 WD4). Each
109
110
  # reason describes the table as the code builds it today. `spec/rigor/declaration_facts/member_classes_spec.rb`
110
111
  # fails on a member that is unclassified or classified twice, and checks each class's shape on an index built
111
112
  # from a fixture project; it pins the few misfilings those checks accept.
@@ -135,7 +136,8 @@ module Rigor
135
136
  published_constant_names: "the last segments of the constants the project publishes",
136
137
  local_constant_names: "the last segments of the constants the analysed file assigns",
137
138
  published_constant_alias_names: "the file's constants copied straight from a published one",
138
- published_constant_ivars: "the ivars each class seeds from a published constant"
139
+ published_constant_ivars: "the ivars each class seeds from a published constant",
140
+ published_constant_cvars: "the class variables each class seeds from a published constant"
139
141
  }.freeze,
140
142
  single_valued: {
141
143
  discovered_def_nodes: "the def node each instance method resolves to",
@@ -208,10 +210,10 @@ module Rigor
208
210
  entries.first.is_a?(Array)
209
211
  end
210
212
 
211
- # Issue #992 — the two class-wide keys a `discovered_parameter_envelopes` bucket can carry beside its
213
+ # Issue #992 — the class-wide keys a `discovered_parameter_envelopes` bucket can carry beside its
212
214
  # `[kind, method_name]` entries. Their PRESENCE is the fact; the value is always
213
215
  # `Source::ParameterEnvelope::OPAQUE`, so a bucket folds under the one join every other entry does.
214
- # Symbols, because every per-method key is an Array and neither can collide with the other.
216
+ # Symbols, because every per-method key is an Array and none can collide with another.
215
217
  #
216
218
  # The class marks below and {ENVELOPE_PROJECT_WIDE} are presence facts read only to decline a read; they are
217
219
  # never a contested path. Contested envelope paths are always `[class, [kind, name]]`.
@@ -355,8 +357,8 @@ module Rigor
355
357
  !bucket.nil? && bucket.any? { |key, _| declaring_key?(key) }
356
358
  end
357
359
 
358
- # Issue #2901 — a per-method entry declares a member; the two macro entries ({ENVELOPE_BODY_CALL_KIND},
359
- # {ENVELOPE_COMPUTED_DEFINER_KIND}) do not.
360
+ # Issue #2901 — a per-method entry declares a member; the macro entries (`MACRO_KINDS`, among them
361
+ # {ENVELOPE_BODY_CALL_KIND} and {ENVELOPE_COMPUTED_DEFINER_KIND}) do not.
360
362
  def self.declaring_key?(key)
361
363
  return DECLARING_MARKS.include?(key) if key.is_a?(Symbol)
362
364
 
@@ -374,7 +376,7 @@ module Rigor
374
376
  # `Struct.new(*FIELDS)`, `attr_accessor(*NAMES)`, a `define_method` under a computed name, so the side defines
375
377
  # methods no table names. A project class with no `def` of its own is an external entry (#2094), so its candidate
376
378
  # names are asked too. Read by `Reflection.project_method_defined` and by the implicit-self top-level-`def` veto
377
- # (`ExpressionTyper#instance_self_answers?`), beside `call.undefined-method`'s own reader.
379
+ # (`CallLadder::TopLevelDef.instance_self_answers?`), beside `call.undefined-method`'s own reader.
378
380
  def self.open_names_on_chain?(scope, class_name, kind)
379
381
  marks = OPEN_NAMES_MARKS.fetch(kind)
380
382
  chain = ResolutionChain.for(scope, class_name.to_s, kind, :methods)
@@ -573,6 +575,9 @@ module Rigor
573
575
  # published something, so a project with no cross-file value constants pays no walk.
574
576
  published_constant_alias_names: EMPTY_NAME_SET,
575
577
  published_constant_ivars: EMPTY_TABLE,
578
+ # Issue #3443 — the class-variable twin of `published_constant_ivars`: `{class name => Set[cvar name]}` for
579
+ # a cvar whose class-cvar seed may be such a copy (`@@mode = AppConfig::MODE` in `def self.setup`).
580
+ published_constant_cvars: EMPTY_TABLE,
576
581
  data_member_layouts: EMPTY_TABLE,
577
582
  struct_member_layouts: EMPTY_TABLE,
578
583
  # ADR-67 WD3 — the call-site parameter-inference table, keyed by `[class_name, method_name, kind]` (the
@@ -49,7 +49,7 @@ module Rigor
49
49
  # answer anything new. That leaves #1570's redundant `include` with the answer master gave, since the two
50
50
  # worlds disagree there; ADR-119's arity decision point is where it gets fixed.
51
51
  #
52
- # Two things the tables do not record, so the chain cannot reproduce them:
52
+ # What the tables do not record, so the chain cannot reproduce it:
53
53
  #
54
54
  # - The interleaving of a body's `include` and `prepend` statements, and whether a class both includes and
55
55
  # prepends one module (`include M; prepend M` is `[M, C, M]` in Ruby; the tables record it as a plain
@@ -63,8 +63,10 @@ module Rigor
63
63
  # CRuby also propagates a later prepend into the includers of a prepended module and leaves a trailing
64
64
  # duplicate (`module M0; prepend M3; end; class Base; prepend M0; end; module M0; prepend M4; end` is
65
65
  # `[M4, M3, M0, M4, Base]`); the first-occurrence order is the chain's, and the duplicate is not modelled.
66
- # - `class << self; prepend P`, which the extends table records (and the extends fold copies) as an
67
- # `extend`: the chain places `P` after the singleton, where Ruby places it before.
66
+ #
67
+ # A singleton-side `prepend P` is filed in the extends table beside the `extend`s (and the extends fold copies it)
68
+ # and told apart by its `ENVELOPE_SINGLETON_PREPEND_KIND` envelope entry (#2998): the chain places it ahead of the
69
+ # class object, as Ruby does.
68
70
  #
69
71
  # An ancestor the project does not declare (`Enumerable`, `< ActiveRecord::Base`) is an EXTERNAL entry at
70
72
  # its Ruby position, carrying the name as written and the names that spelling can denote; its own RBS
@@ -252,6 +254,27 @@ module Rigor
252
254
  @memo[:hook_open_nodes] ||= @marks.filter_map { |mark| mark.node if mark.kind == :include_hook }.freeze
253
255
  end
254
256
 
257
+ # Issue #3373 — whether a class on this chain nearer than `owner` includes or prepends a module with a `def
258
+ # self.included` hook, which may define a singleton method on the includer ahead of `owner`'s `def`. A lone
259
+ # `prepend M` runs `prepended` only, but the de-duplicated mixin table cannot tell it from `include M; prepend
260
+ # M`, so a prepended module counts too. A withholding read: it over-approximates. The block is asked of each
261
+ # mixin the chain resolves, with its `included` hook's `def` node or nil, and answers whether the module may
262
+ # define a singleton method on its includer (a hook `def` no table holds, #3450, is the block's to read).
263
+ def included_hook_before?(owner, scope)
264
+ resolver = ResolutionChain.resolver_for(scope, @flavor)
265
+ @level_classes.each do |klass|
266
+ next if klass.nil?
267
+ return false if klass == owner
268
+
269
+ hooked = (scope.discovery.discovered_includes[klass] || EMPTY_NAMES).any? do |raw|
270
+ mixin = resolver.resolve_declared(klass, raw)
271
+ mixin && yield(mixin, scope.singleton_def_for(mixin, :included))
272
+ end
273
+ return true if hooked
274
+ end
275
+ false
276
+ end
277
+
255
278
  # The ONE decision every first-definer reader makes: does `answer`, read off this chain, stand, or does
256
279
  # the reader answer what the walk this chain replaced answered ({MasterOrder})? Returns `:chain` or
257
280
  # `:master`.
@@ -1298,9 +1321,6 @@ module Rigor
1298
1321
  lin
1299
1322
  end
1300
1323
 
1301
- # A memoised linearisation rebuilt for the audit by a Builder over a fresh bucket. A memoised one met no
1302
- # cycle and stayed inside the depth budget, so its depth does not change it; a retro world that fit
1303
- # {LIMIT} once fits it again.
1304
1324
  # A memoised chain's forks are the asker's too.
1305
1325
  def absorb_cached(cached)
1306
1326
  @frames.last&.absorb(cached[3], cached[4], cached[5])
@@ -1314,6 +1334,9 @@ module Rigor
1314
1334
  SINGLETON_LIN_TABLES = %i[lin_singleton lin_singleton_retro].freeze
1315
1335
  private_constant :SINGLETON_LIN_TABLES
1316
1336
 
1337
+ # A memoised linearisation rebuilt for the audit by a Builder over a fresh bucket. A memoised one met no
1338
+ # cycle and stayed inside the depth budget, so its depth does not change it; a retro world that fit
1339
+ # {LIMIT} once fits it again.
1317
1340
  def fresh_lin(table, name)
1318
1341
  side = SINGLETON_LIN_TABLES.include?(table) ? :singleton : :instance
1319
1342
  builder = Builder.new(@scope, @flavor, ResolutionChain.send(:flavor_bucket, @discovery, @flavor),
data/lib/rigor/scope.rb CHANGED
@@ -132,6 +132,13 @@ module Rigor
132
132
  @discovery.published_constant_ivars[class_name] || EMPTY_PUBLISHED_CONSTANT_IVARS
133
133
  end
134
134
 
135
+ # Issue #3443 — the class-variable twin of {#published_constant_ivars_for}: the cvar names of `class_name`
136
+ # whose class-cvar seed may come from a foreign published constant. `StatementEvaluator#seed_class_cvars`
137
+ # stamps the flow mark for these at method-body entry; a method-local write then drops it through `with_cvar`.
138
+ def published_constant_cvars_for(class_name)
139
+ @discovery.published_constant_cvars[class_name] || EMPTY_PUBLISHED_CONSTANT_IVARS
140
+ end
141
+
135
142
  # Issue #644 — true when the constant reference `name` (as written: `MODE` or `AppConfig::MODE`) is
136
143
  # published by the cross-file value-constant table and is NOT assigned by the file being analysed: a
137
144
  # value this file's author cannot see the declaration of. {Analysis::CheckRules::PublishedConstantGuard}
@@ -145,14 +152,23 @@ module Rigor
145
152
  # exemption, so over-answering there would UN-withhold: matching it on the last segment too would let an
146
153
  # unrelated `Local::MODE` in this file make a read of `AppConfig::MODE` fire.
147
154
  #
148
- # The exemption therefore matches a **suffix relation on qualified names**, not the spelling and not the
149
- # last segment: a local assignment exempts a reference when it IS that reference or ENDS with `::` plus
150
- # it. That is what a lexically relative spelling resolves to — inside `module AppConfig`, the reference
151
- # `Nested::X` is the file's own `AppConfig::Nested::X` — and it subsumes the bare case (`OWNED` matched
152
- # by `Owner::OWNED`) without matching the unrelated `Local::MODE` above. It is deliberately a relation
153
- # over already-qualified names rather than a second lexical ladder: the engine's ladder
155
+ # Issue #3437 — the exemption therefore matches the names the reference can RESOLVE to where it is written,
156
+ # not the spelling, not the last segment and not a suffix. A reference spelled `R` names `<entry>::R` for
157
+ # an entry of {#constant_lookup_namespaces} (this scope's `Module.nesting`, then the enclosing class's
158
+ # project ancestors), or the top-level `R`, and a local assignment exempts it only when it IS one of those
159
+ # names. Inside `module AppConfig`, `Nested::X` is the file's own `AppConfig::Nested::X` and `OWNED` inside
160
+ # `module Owner` is `Owner::OWNED`, so both stay exempt; a top-level `MODE` in a file that assigns
161
+ # `M::MODE` is not, because no rung of its lookup reaches `M`. A reference written with a leading `::`
162
+ # (`rooted:`) names the top level alone, as it does for the typing ladder.
163
+ #
164
+ # Every such name ends with `::` plus the spelling, so the relation is a subset of the suffix relation this
165
+ # replaced (it stays below as the pre-filter): the change can only withhold. It joins already-qualified
166
+ # names and resolves nothing, and is deliberately not a second lexical ladder: the engine's ladder
154
167
  # (`Reflection.resolve_constant_type`) answers with a TYPE and not with the candidate that won, and
155
168
  # reimplementing the walk here is the very thing that made the receiver resolution wrong once already.
169
+ # Not asking which candidate WINS leaves one over-answer: a file that assigns the top-level `MODE` and reads
170
+ # `MODE` inside `module M`, where another file assigns `M::MODE`, is exempt although the read is the other
171
+ # file's constant.
156
172
  #
157
173
  # Issue #667 — a third answer sits beside those two. `MODE2 = AppConfig::MODE` is assigned by this file,
158
174
  # so the exemption above releases it, yet its value is still one the author never saw: the alias only
@@ -164,14 +180,14 @@ module Rigor
164
180
  # the ADR-46 `constant:<segment>` name edge itself, whatever it answers. The guard asks it about spellings no
165
181
  # typing step reads (a `defined?(B::X)` probe, a callee body the one hop scans), and an edge left to the read
166
182
  # would let an `--incremental` run keep a verdict the moved publication no longer earns.
167
- def published_constant?(name)
183
+ def published_constant?(name, rooted: false)
168
184
  Analysis::DependencyRecorder.read_last_segment(:constant, name) if Analysis::DependencyRecorder.active?
169
185
  names = @discovery.published_constant_names
170
186
  return true if published_constant_alias?(name)
171
187
  return false if names.empty?
172
188
  return false unless names.include?(name.split("::").last)
173
189
 
174
- !locally_declared_constant?(name)
190
+ !locally_declared_constant?(name, rooted)
175
191
  end
176
192
 
177
193
  def published_constant_alias?(name)
@@ -180,15 +196,42 @@ module Rigor
180
196
  end
181
197
  private :published_constant_alias?
182
198
 
183
- def locally_declared_constant?(reference_name)
199
+ # The top-level name is every unrooted lookup's last rung and a rooted reference's only one. The suffix
200
+ # scan is the relation issue #3437 narrowed, kept as the pre-filter: no namespace can qualify the reference
201
+ # into a local name unless some local name ends with it, so a file that assigns no such name never asks for
202
+ # the chain or the ancestors.
203
+ def locally_declared_constant?(reference_name, rooted)
184
204
  local = @discovery.local_constant_names
185
205
  return false if local.empty?
186
206
  return true if local.include?(reference_name)
207
+ return false if rooted
187
208
 
188
209
  suffix = "::#{reference_name}"
189
- local.any? { |name| name.end_with?(suffix) }
210
+ return false unless local.any? { |name| name.end_with?(suffix) }
211
+
212
+ constant_lookup_namespaces.any? { |entry| local.include?("#{entry}#{suffix}") }
213
+ end
214
+
215
+ # Issue #3437 — the namespaces whose OWN constants an unrooted reference written in this scope can name
216
+ # before the top level, read from what the typing ladder reads: its step 1's `Module.nesting`
217
+ # (`Reflection.lexical_nesting_chain`, the single owner of that chain), then the project entries of the
218
+ # enclosing class's `:constants` resolution chain, which its step 2 walks. The list names candidates and
219
+ # resolves none, so the order the ladder settles between two ancestors does not matter here.
220
+ #
221
+ # A body whose chain was recorded EMPTY is written at the top level and gets no entry: Ruby's cref there is
222
+ # `Object`, and the caller-derived rungs issue #716 keeps below the top level are a deliberate unsoundness
223
+ # of the typing ladder that an exemption must not inherit. An ancestor only RBS declares is left out: the
224
+ # question is about names this file assigns, and the ladder does not expand such an entry either.
225
+ def constant_lookup_namespaces
226
+ nesting = Reflection.lexical_nesting_chain(self)
227
+ owner = self_type.class_name if self_type.is_a?(Type::Nominal) || self_type.is_a?(Type::Singleton)
228
+ return nesting if nesting.empty? || owner.nil? || owner.empty?
229
+
230
+ ancestors = ResolutionChain.for(self, owner, :instance, :constants)
231
+ ancestors.record(self)
232
+ nesting + ancestors.entries.filter_map(&:name)
190
233
  end
191
- private :locally_declared_constant?
234
+ private :locally_declared_constant?, :constant_lookup_namespaces
192
235
 
193
236
  def data_member_layouts = @discovery.data_member_layouts
194
237
  def struct_member_layouts = @discovery.struct_member_layouts
@@ -259,8 +302,9 @@ module Rigor
259
302
  # ADR-58 set would be the third establishing transition its *Non-transitivity* passage reserves as a
260
303
  # decision, on a Set that already carries two opposite join policies.
261
304
  EMPTY_PUBLISHED_CONSTANT_SOURCED = Set.new.freeze
262
- # Issue #667 — the empty answer of {#published_constant_ivars_for}, so a class with no such ivar (every
263
- # class in a project that publishes nothing) allocates none.
305
+ # Issue #667 — the empty answer of {#published_constant_ivars_for} (and, #3443, of
306
+ # {#published_constant_cvars_for}), so a class with no such variable (every class in a project that publishes
307
+ # nothing) allocates none.
264
308
  EMPTY_PUBLISHED_CONSTANT_IVARS = Set.new.freeze
265
309
  # The index `||=` sites of a repeating block body whose slot an earlier run of the body may have filled,
266
310
  # keyed by node identity and laid at the body's entry by a block-return pass or by `StatementEvaluator`'s
@@ -456,8 +500,9 @@ module Rigor
456
500
  end
457
501
 
458
502
  # Issue #286 — the {Inference::OptimisticOrigin} cause attached to a call node whose result is nil-free
459
- # only because `RbsDispatch` reads past `%a{implicitly-returns-nil}`, or `nil` when the value's
460
- # nil-freeness is a property of its class. Mirrors {#dynamic_origins} / {#void_origins}: advisory
503
+ # only because `RbsDispatch` reads past `%a{implicitly-returns-nil}` or a plugin answered through
504
+ # `Plugin::Base#optimistic_nil_free` (#3322), or `nil` when the value's nil-freeness is a property of its
505
+ # class. Mirrors {#dynamic_origins} / {#void_origins}: advisory
461
506
  # metadata, ignored by `==` / `hash`, and never varying a flow decision on its own.
462
507
  def record_optimistic_origin(node, cause)
463
508
  TypingState.current.log_bound_write(OPTIMISTIC_ORIGINS, @optimistic_origins, node, cause)
@@ -578,9 +623,9 @@ module Rigor
578
623
  bind_local(name, type, keep_marks: false)
579
624
  end
580
625
 
581
- # The one body behind {#with_local} and {#with_mutated_local}, which differ only in whether the two marks a
582
- # write drops survive. Passing the kept sets through unchanged, rather than dropping and re-adding them, keeps
583
- # a mutation's rebind to the one `rebuild` a write costs.
626
+ # The one body behind {#with_local} and {#with_mutated_local}, which differ only in whether the marks a
627
+ # write drops (construction facts, declaration-sourced, optimistic) survive. Passing the kept sets through
628
+ # unchanged, rather than dropping and re-adding them, keeps a mutation's rebind to the one `rebuild` a write costs.
584
629
  def bind_local(name, type, keep_marks:)
585
630
  # `rigor trace` — the moment a local enters the scope.
586
631
  Inference::FlowTracer.bind(name, type) if Inference::FlowTracer.active?
@@ -921,7 +966,8 @@ module Rigor
921
966
  # (`r << x`), a content floor after a closure or callee mutated it, an element or member write through it. The
922
967
  # binding still names the same object, so this is not a flow-live write, and the marks `with_local` drops stay:
923
968
  # ADR-58's declaration-sourced mark and issue #286's optimistic nil-freeness mark, with the miss answer issue
924
- # #1302 records in it. A source-level write keeps going through `with_local`, which drops both.
969
+ # #1302 records in it, and the #2555 construction facts. A source-level write keeps going through `with_local`,
970
+ # which drops all of them.
925
971
  #
926
972
  # Two other per-local tables are deliberately still dropped. An ADR-82 `local_origins` cause explains the
927
973
  # `Dynamic` the ASSIGNMENT bound, and a floor's `Dynamic[top]` has a different cause. Issue #667's
@@ -1041,8 +1087,19 @@ module Rigor
1041
1087
  @declaration_sourced.include?([:gradual_narrowing, name.to_sym])
1042
1088
  end
1043
1089
 
1090
+ # Issue #3443 — a write is flow-live for the published-constant mark, as {#with_ivar}'s is: the new value need
1091
+ # not be a copy of anything, and `with_published_constant_mark` re-stamps afterward when it is.
1044
1092
  def with_cvar(name, type)
1045
- rebuild(cvars: @cvars.merge(name.to_sym => type).freeze)
1093
+ rebuild(cvars: @cvars.merge(name.to_sym => type).freeze,
1094
+ published_constant_sourced: drop_published_constant_sourced_for(:cvar, name))
1095
+ end
1096
+
1097
+ # Issue #3443 — {#with_cvar}, then, when `copy` holds, the #667 published-constant mark on the cvar: the write
1098
+ # (`StatementEvaluator#eval_cvar_write`) or the method-entry seed (`#seed_class_cvars`) of a copy of a constant
1099
+ # another file publishes.
1100
+ def with_cvar_copy(name, type, copy)
1101
+ bound = with_cvar(name, type)
1102
+ copy ? bound.with_published_constant_mark(:cvar, name) : bound
1046
1103
  end
1047
1104
 
1048
1105
  # Issue #1362 — a write or narrowing of a global is flow-live, so it drops the ADR-58 `:global` mark
@@ -1255,7 +1312,7 @@ module Rigor
1255
1312
  end
1256
1313
 
1257
1314
  # Regex match-data globals (`$~`, `$&`, `$1..$N`, the pre/post-match and last-paren back-references). Narrowed
1258
- # on a successful-`=~` / `case`-`when` match edge (see `Narrowing#regex_match_predicate_scopes`). They live in
1315
+ # on a successful-`=~` / `case`-`when` match edge (see `RegexMatch.regex_match_predicate_scopes`). They live in
1259
1316
  # the method frame's special-variable slot, which the method's blocks and closures share (issue #1358), so a
1260
1317
  # later call that may run a match in this frame — a match-capable call, a block that may match, a call once
1261
1318
  # the frame has made a closure that may — rebinds every one of them, and `eval_call` forgets the narrowed
@@ -1479,7 +1536,7 @@ module Rigor
1479
1536
  # True at the top of a file AND inside a top-level `def` body (since toplevel defs leave `self_type` nil per
1480
1537
  # the existing scope-construction contract — the same nil-`self_type` signal ADR-24's self-call return
1481
1538
  # adoption historically keyed on before ADR-57 opened the gate unconditionally). Used by
1482
- # `CheckRules#unresolved_toplevel_diagnostic` to gate the `call.unresolved-toplevel` rule so it fires only
1539
+ # `CheckRules::UnresolvedToplevel.diagnostic` to gate the `call.unresolved-toplevel` rule so it fires only
1483
1540
  # outside class / module bodies, where Rails-DSL metaprogramming leniency (ADR-24 WD3 → WD4) does not apply.
1484
1541
  def toplevel?
1485
1542
  @self_type.nil?
@@ -1894,15 +1951,15 @@ module Rigor
1894
1951
  # Companion to {#user_def_for}: returns the `"path:line"` where the project defines `class_name#method_name`
1895
1952
  # (instance-side), or nil. Populated only by the cross-file project pre-pass
1896
1953
  # ({Inference::ScopeIndexer.discovered_def_index_for_paths}) — a `Prism::Location` hides its source file, so
1897
- # the site is recorded at scan time. `CheckRules#undefined_method_diagnostic` consults this to name the
1954
+ # the site is recorded at scan time. `CheckRules::UndefinedMethod.diagnostic` consults this to name the
1898
1955
  # defining file when a project monkey-patch on a core/stdlib/gem class is called cross-file, so the diagnostic
1899
1956
  # can point at `pre_eval:` (ADR-17) instead of reading as a bare unresolved call.
1900
1957
  def user_def_site_for(class_name, method_name)
1901
1958
  table = @discovery.discovered_def_sources[class_name.to_s]
1902
1959
  site = table && table[method_name.to_sym]
1903
- # ADR-88 WD3 — record the SAME instance-side cross-file method edge {#user_def_for} records at :378, so a
1960
+ # ADR-88 WD3 — record the SAME instance-side cross-file method edge {#user_def_for} records, so a
1904
1961
  # move / body-edit of `class_name#method_name`'s definition re-checks the consumer that named the
1905
- # defining file. `CheckRules#undefined_method_diagnostic` reads this to set `project_definition_site`
1962
+ # defining file. `CheckRules::UndefinedMethod.diagnostic` reads this to set `project_definition_site`
1906
1963
  # (`"path:line"`) on a `call.undefined-method` for a project monkey-patch; without the edge, a line-shift
1907
1964
  # in the defining file left the cached diagnostic pointing at a stale line (the ADR-46 symbol-granularity
1908
1965
  # closure never re-checked the caller). Recording keys on the source-entry PRESENCE (truthy `site`),
@@ -2024,7 +2081,7 @@ module Rigor
2024
2081
  # ADR-24 slice 2 — per-class table mapping a fully qualified user-class name to its superclass name AS WRITTEN
2025
2082
  # at the `class Foo < Bar` declaration (`"Bar"`, possibly a qualified `"A::B"`). Populated by `ScopeIndexer` —
2026
2083
  # per-file plus the cross-file project pre-pass — and consumed by
2027
- # `ExpressionTyper#try_user_method_inference` to walk the superclass chain when an implicit-self call does not
2084
+ # `Inference::CallLadder::UserMethod` to walk the superclass chain when an implicit-self call does not
2028
2085
  # resolve against the enclosing class's own defs. The as-written name is resolved to a qualified class at walk
2029
2086
  # time against the call's lexical nesting.
2030
2087
  def superclass_of(class_name)
@@ -2250,7 +2307,7 @@ module Rigor
2250
2307
  # `define_method`, `attr_*` and the whole singleton side, none of which contributes a `Prism::DefNode` —
2251
2308
  # and the suppression probe shared by the `call.*` check rules needs the broader one.
2252
2309
  #
2253
- # Why it must walk at all: `Analysis::CheckRules#source_declared_method?` asked `discovered_method?`,
2310
+ # Why it must walk at all: `ReceiverPredicates.source_declared_method?` asked `discovered_method?`,
2254
2311
  # which is keyed on the receiver's OWN name, while the typer resolves the same call through this
2255
2312
  # ancestry. A project class whose `sig/` declares it without its project superclass therefore drew
2256
2313
  # `call.undefined-method` on a method `dump_type` resolved on the same line of the same run — writing
@@ -2348,7 +2405,7 @@ module Rigor
2348
2405
  # Issue #722 residue 1 / #637 — a ROOTED ancestor name is anchored at the top level and has no
2349
2406
  # candidate list: `class Rooted < ::Base` names `::Base` wherever it is written, exactly as
2350
2407
  # `Source::ConstantPath.declaration_prefix` already re-anchors a rooted HEADER. The marker is the
2351
- # leading `::` `Inference::ScopeIndexer.recorded_ancestor_name` preserves.
2408
+ # leading `::` `Inference::ScopeIndexer::SharedWalkTables.recorded_ancestor_name` preserves.
2352
2409
  raw = raw_ancestor.to_s
2353
2410
  return [raw.delete_prefix("::")] if raw.start_with?("::")
2354
2411
 
@@ -2426,7 +2483,7 @@ module Rigor
2426
2483
  #
2427
2484
  # The unkeyed entry is the union, and answers a name no site recorded under its own key: an `include`
2428
2485
  # attributed to this class from OUTSIDE its declaration (`Recv.class_eval { include M }`, which
2429
- # `Inference::ScopeIndexer#walk_class_includes` names but the header walk cannot see), or a dynamic
2486
+ # `Inference::ScopeIndexer::MixinTables.walk_class_includes` names but the header walk cannot see), or a dynamic
2430
2487
  # mixin argument. It is the pre-#728 answer, so those are unchanged rather than degraded.
2431
2488
  def recorded_header_nesting(bucket, raw)
2432
2489
  bucket[raw] || bucket[DiscoveryIndex::UNKEYED_HEADER_NESTING] || EMPTY_HEADER_NESTING
@@ -2489,7 +2546,7 @@ module Rigor
2489
2546
  # file that wrote the constant: editing the literal, or deleting the file, re-checks the reader. Recorded
2490
2547
  # WITHOUT a symbol (a file-granularity / ancestry edge) because a constant's published value is a
2491
2548
  # declaration-level fact of the whole file, which is also the granularity
2492
- # `ScopeIndexer#append_constant_signature` moves the declaration signature at.
2549
+ # `ScopeIndexer::DeclarationSignature#append_constant_signature` moves the declaration signature at.
2493
2550
  #
2494
2551
  # `constant_sources` is seeded when dependency recording is on and in the editor publish's discovery seed
2495
2552
  # (ADR-124), where the recorder is inactive; elsewhere the table is empty and this is one Hash miss. The caller
@@ -2640,7 +2697,7 @@ module Rigor
2640
2697
 
2641
2698
  # Joins this scope with another at a control-flow merge point. The joined scope is bound to every local that
2642
2699
  # BOTH branches bind, with the type widened to the union of both sides. Names bound in only one branch are
2643
- # dropped from the joined scope; the eventual statement-level evaluator (Slice 3 phase 2) is responsible for
2700
+ # dropped from the joined scope; `Inference::StatementEvaluator` is responsible for
2644
2701
  # nil-injecting half-bound names where the language semantics demand it. The two scopes MUST share the same
2645
2702
  # Environment.
2646
2703
  def join(other)
@@ -3092,7 +3149,6 @@ module Rigor
3092
3149
  root[0] == kind && root[1] == name
3093
3150
  end
3094
3151
 
3095
- # ADR-58 WD1 — set/clear the declaration-sourced provenance mark.
3096
3152
  # Issue #667 — the #667 carrier's add/drop pair. Deliberately not reusing
3097
3153
  # {#add_declaration_sourced} / {#drop_declaration_sourced_for}: the two sets are joined by opposite
3098
3154
  # policies, so sharing the storage would make every future edit to either one a decision about both.
@@ -3130,6 +3186,7 @@ module Rigor
3130
3186
  mine.merge(theirs).freeze
3131
3187
  end
3132
3188
 
3189
+ # ADR-58 WD1 — set/clear the declaration-sourced provenance mark.
3133
3190
  def add_declaration_sourced(kind, name)
3134
3191
  ref = [kind.to_sym, name.to_sym]
3135
3192
  return @declaration_sourced if @declaration_sourced.include?(ref)
@@ -43,8 +43,9 @@ module Rigor
43
43
  # any), and emits one {MethodCandidate} per def.
44
44
  #
45
45
  # The scope, as it stands after the slices that widened the MVP:
46
- # - Instance and singleton methods inside a nameable `class` / `module` body are considered. Top-level /
47
- # DSL-block defs have no nameable receiver and are not candidates.
46
+ # - Instance and singleton methods inside a nameable `class` / `module` body are considered. A top-level `def`
47
+ # has no class to declare under and is only reported (`sig.skipped.top-level-def`, #1676); a DSL-block `def`
48
+ # has no nameable receiver and is not a candidate.
48
49
  # - Parameter types are `untyped` per ADR-14 § "Robustness principle compliance" clause 2 unless
49
50
  # `--params=observed` supplies call-site observations; the parameter LIST always mirrors the def's runtime
50
51
  # shape (required / optional / rest / trailing / keyword / keyword-rest / forwarding / block). Issue #778
@@ -2652,8 +2653,8 @@ module Rigor
2652
2653
 
2653
2654
  # Returns a closure that looks up `:@<attr_name>` in the class-ivar accumulator carried by the first scope
2654
2655
  # the indexer associated with this file. The accumulator is populated by
2655
- # `ScopeIndexer#build_class_ivar_index` before any statement evaluation runs, so the lookup works even
2656
- # when attr_* declarations come before the corresponding ivar writes lexically.
2656
+ # `ScopeIndexer::ClassIvarIndex.build_class_ivar_index` before any statement evaluation runs, so the lookup
2657
+ # works even when attr_* declarations come before the corresponding ivar writes lexically.
2657
2658
  #
2658
2659
  # When `obs_ivar_map` is non-empty (i.e. `--params=observed` was used), it acts as a fallback: if the ivar
2659
2660
  # pre-pass resolved the type to `nil` or `Dynamic[top]` — typically because `@ivar = param` inside