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
@@ -0,0 +1,90 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "../../type"
4
+
5
+ module Rigor
6
+ module Inference
7
+ module MethodDispatcher
8
+ # The dependency-source tier (ADR-10): a method an opt-in gem's source defines answers `Dynamic` from the
9
+ # `Analysis::DependencySourceInference::Index` the environment carries, below every signature and above the
10
+ # discovered-method tier. `MethodDispatcher.resolve_site` records the origin of its answer, so it is a call
11
+ # there and a member of no tier array.
12
+ #
13
+ # {#dep_source_class_name} is a second entry: the boundary-cross record `resolve_site` makes after an RBS
14
+ # answer reads the receiver's class the same way.
15
+ module DependencySource
16
+ module_function
17
+
18
+ # ADR-10 slice 2b-ii. Consults the per-run `Analysis::DependencySourceInference::Index`
19
+ # carried by the environment for `(class_name, method_name)` observations harvested from
20
+ # opt-in gems' `roots:`. On a hit, returns `Combinator.untyped` so the call site carries
21
+ # the `Dynamic[top]` provenance (per ADR-10's "Inference contract": gem-source-inferred
22
+ # shapes never publish as ground-truth `T`). Returns `nil` when the environment carries no
23
+ # index, the index has no entry, or the receiver has no nominal class to look up.
24
+ def try_dispatch(context)
25
+ receiver_type = context.receiver
26
+ method_name = context.method_name
27
+ environment = context.environment
28
+ index = environment&.dependency_source_index
29
+ return nil if index.nil? || index.empty?
30
+
31
+ class_name = dep_source_class_name(receiver_type)
32
+ return nil if class_name.nil?
33
+
34
+ # ADR-10 5a — per-receiver plugin veto. When a registered plugin declares
35
+ # `manifest(owns_receivers: [<class>])` AND the call's receiver IS that class (or a
36
+ # subclass), decline and let plugins handle the call. Plugins that own a receiver are
37
+ # the authoritative source for that type; gem-source inference must not contribute
38
+ # behind their backs.
39
+ return nil if plugin_owns_receiver?(class_name, environment)
40
+
41
+ contribution = index.contribution_for(class_name: class_name, method_name: method_name)
42
+ return dependency_source_return_type(contribution) if contribution
43
+
44
+ # ADR-10 5b — β budget semantics. On a catalog miss, if the receiver class belongs to a
45
+ # budget-exceeded gem AND the user opted into `:dependency_silence`, return
46
+ # `Dynamic[top]` rather than falling through to the user-class fallback. The user-class
47
+ # fallback would otherwise emit `call.undefined-method` for methods Rigor's catalog
48
+ # couldn't reach because the walker hit its cap.
49
+ budget_silence_result(class_name, index, environment)
50
+ end
51
+
52
+ # Maps a {DependencySourceInference::Walker::CatalogEntry} to the Type the dispatcher
53
+ # returns at the call site. When the heuristic recovered a static facet, wrap it in
54
+ # `Dynamic[T]` per ADR-10's gem-boundary contract; otherwise fall back to the
55
+ # pre-heuristic `Dynamic[top]`.
56
+ def dependency_source_return_type(contribution)
57
+ return Type::Combinator.untyped if contribution.return_type.nil?
58
+
59
+ Type::Combinator.dynamic(contribution.return_type)
60
+ end
61
+
62
+ def budget_silence_result(class_name, index, _environment)
63
+ return nil unless index.budget_overrun_strategy == :dependency_silence
64
+
65
+ owning_gem = index.gem_for(class_name)
66
+ return nil if owning_gem.nil?
67
+ return nil unless index.budget_exceeded.include?(owning_gem)
68
+
69
+ Type::Combinator.untyped
70
+ end
71
+
72
+ # ADR-52 WD1 — the per-dispatch plugins × owns_receivers × `class_ordering` walk moved into
73
+ # the compiled contribution table: the union is built once per registry (almost always
74
+ # empty → O(1) false) and per-class verdicts memoise per run.
75
+ def plugin_owns_receiver?(class_name, environment)
76
+ registry = environment&.plugin_registry
77
+ return false if registry.nil? || registry.empty?
78
+
79
+ registry.contribution_index.owns_receiver?(class_name, environment)
80
+ end
81
+
82
+ def dep_source_class_name(receiver_type)
83
+ case receiver_type
84
+ when Type::Nominal, Type::Singleton then receiver_type.class_name
85
+ end
86
+ end
87
+ end
88
+ end
89
+ end
90
+ end
@@ -0,0 +1,78 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "../../type"
4
+
5
+ module Rigor
6
+ module Inference
7
+ module MethodDispatcher
8
+ # The discovered-method tier (v0.1.3, ADR-24): a call to a method the project's own source defines, on a class
9
+ # the scope's `discovered_methods` table records, answers `Dynamic[top]` where no body is there to re-type.
10
+ # `MethodDispatcher.resolve_site` asks it below the dependency-source tier and records the origin of a
11
+ # `Dynamic` answer, so it is a call there and a member of no tier array.
12
+ #
13
+ # {#discovered_method_lookup} is a second entry: `MethodDispatcher.record_transitive_void_origin`, which
14
+ # `dispatch_site` runs after `resolve_site`, keys the same table the same way.
15
+ module DiscoveredMethod
16
+ module_function
17
+
18
+ # v0.1.3 — discovered-method dispatch tier. `scope` carries the `discovered_methods` table
19
+ # built once per program by `ScopeIndexer` (a `Hash[String, Hash[Symbol, :instance |
20
+ # :singleton]]`). When the receiver names a discovered class AND the requested method is
21
+ # recorded for that class's appropriate kind, return `Type::Combinator.untyped` — the
22
+ # dispatcher cannot infer a more precise return type from the bare `def` shape, but the
23
+ # call site stops being a fail-soft hot spot.
24
+ #
25
+ # Returns `nil` when scope / receiver class is unavailable, when the method is not in the
26
+ # discovered table, OR when `discovered_def_nodes` carries a re-typable body for the method
27
+ # (so the downstream `CallLadder::UserMethod` rung can re-type the body
28
+ # for a precise return type rather than collapsing to `Dynamic[top]` here).
29
+ #
30
+ # The tier does NOT gate on `rbs_class_known?`. RBS dispatch already had its turn upstream
31
+ # and returned `nil` (otherwise we wouldn't be here). When RBS knows the class but the
32
+ # particular method is missing from the sig — common for internal helpers and for
33
+ # auto-generated stubs that emit `class X` without enumerating every method — falling
34
+ # through to the user-class fallback would mistakenly fire `call.undefined-method`.
35
+ # Honoring the discovered table here keeps the sibling-private call resolution working
36
+ # under partial RBS coverage.
37
+ def try_dispatch(context)
38
+ receiver_type = context.receiver
39
+ method_name = context.method_name
40
+ scope = context.scope
41
+ return nil if scope.nil?
42
+
43
+ class_name, kind = discovered_method_lookup(receiver_type)
44
+ return nil if class_name.nil?
45
+ return nil unless scope.discovered_method?(class_name, method_name, kind)
46
+ # Decline when a re-typable body is recorded for the method, so the downstream
47
+ # `ExpressionTyper` inference tier can fold a precise return instead of collapsing to
48
+ # `Dynamic[top]` here — instance bodies via `user_def_for`, singleton bodies (`def
49
+ # self.x` / `module_function`) via `singleton_def_for` (module-singleton call
50
+ # resolution, ADR-57 follow-up).
51
+ return nil if kind == :instance && scope.user_def_for(class_name, method_name)
52
+ return nil if kind == :singleton && scope.singleton_def_for(class_name, method_name)
53
+
54
+ Type::Combinator.untyped
55
+ end
56
+
57
+ # Resolves the `(class_name, kind)` pair scope_indexer keys its `discovered_methods` table
58
+ # on. `Nominal[X]` looks up instance methods on X; `Singleton[X]` looks up singleton
59
+ # methods on X. Other carriers return `[nil, nil]` so the tier declines.
60
+ def discovered_method_lookup(receiver_type)
61
+ # #525 — the ADR-48 member carriers name their class too: a `Line = Struct.new(...) do ... end`
62
+ # value is a StructInstance whose block-def methods are discovered under "Line".
63
+ case receiver_type
64
+ when Type::Nominal, Type::StructInstance, Type::DataInstance
65
+ [receiver_type.class_name, :instance]
66
+ when Type::Singleton, Type::StructClass, Type::DataClass
67
+ [receiver_type.class_name, :singleton]
68
+ else NO_DISCOVERED_LOOKUP
69
+ end
70
+ end
71
+
72
+ # The shared "no discovered-method key" pair; callers destructure it (#775).
73
+ NO_DISCOVERED_LOOKUP = [nil, nil].freeze
74
+ private_constant :NO_DISCOVERED_LOOKUP
75
+ end
76
+ end
77
+ end
78
+ end
@@ -20,9 +20,9 @@ module Rigor
20
20
  #
21
21
  # Default policy (`fold_platform_specific_paths == false`): decline the fold so the RBS tier answers with
22
22
  # `Nominal[String]` / `Tuple[Nominal[String], Nominal[String]]` / `bool`. That is the platform-agnostic
23
- # envelope — every concrete answer the method could legally return on any platform fits inside it. The future
23
+ # envelope — every concrete answer the method could legally return on any platform fits inside it. The
24
24
  # `non-empty-string` refinement carrier (see
25
- # [imported-built-in-types.md](../../../../../docs/type-specification/imported-built-in-types.md)) will
25
+ # [imported-built-in-types.md](../../../../../docs/type-specification/imported-built-in-types.md)) could
26
26
  # tighten the basename/dirname/join cases further without leaking platform specifics; today we leave them at
27
27
  # the nominal envelope.
28
28
  #
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "../../type"
4
+ require_relative "../../builtins/hkt_builtins"
5
+
6
+ module Rigor
7
+ module Inference
8
+ module MethodDispatcher
9
+ # The HKT-builtin return tier (ADR-20 slice 3): the stdlib methods whose upstream RBS return is `untyped` and
10
+ # whose runtime shape Rigor models as a Lightweight HKT (`JSON.parse` as `json::value`). The table is
11
+ # `Rigor::Builtins::HktBuiltins::METHOD_RETURN_OVERRIDES`. Its place in the order is `MethodDispatcher`'s
12
+ # `BUNDLED_OVERRIDE_TIERS`.
13
+ module HktBuiltinReturn
14
+ module_function
15
+
16
+ # ADR-20 slice 3 — looks up the receiver / method pair in
17
+ # {Rigor::Builtins::HktBuiltins::METHOD_RETURN_OVERRIDES} and returns the reduced HKT type.
18
+ # Only fires when the receiver is a {Rigor::Type::Singleton} (the `JSON.parse` shape) and
19
+ # the registry-backed reduction succeeds; returns `nil` otherwise so the dispatcher falls
20
+ # through to RBS.
21
+ def try_dispatch(context)
22
+ receiver_type = context.receiver
23
+ method_name = context.method_name
24
+ arg_types = context.args
25
+ environment = context.environment
26
+ return nil if environment.nil?
27
+ return nil unless receiver_type.is_a?(Type::Singleton)
28
+
29
+ Rigor::Builtins::HktBuiltins.method_return_override(
30
+ class_name: receiver_type.class_name,
31
+ method_name: method_name,
32
+ kind: :singleton,
33
+ arg_types: arg_types,
34
+ hkt_registry: environment.hkt_registry
35
+ )
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
@@ -169,10 +169,6 @@ module Rigor
169
169
  # substitution; this tier exists so Tuple- and HashShape-shaped receivers reach the block body with
170
170
  # the precise per-position element union / `Tuple[K, V]` pair rather than the projected
171
171
  # `Array[union]` / `Hash[K, V]` widening.
172
- #
173
- # NOTE: `Plugin::NodeRuleWalk` (ADR-52 WD4) is now in place as the intended migration target for
174
- # these Enumerable projections. The four methods (group_by, partition, each_slice, each_cons) remain
175
- # here pending that migration.
176
172
  def single_element_block_params(receiver)
177
173
  element = element_type_of(receiver)
178
174
  return nil if element.nil?
@@ -182,8 +178,7 @@ module Rigor
182
178
 
183
179
  # `each_slice(n) { |slice| … }` and `each_cons(n) { |window| … }` both yield an `Array[element]`
184
180
  # once per iteration. The tier ignores the slice-size argument (a Constant<Integer> `n` could in
185
- # principle bound the slice's length, but a tighter Tuple-of-`n` carrier is reserved for the plugin
186
- # tier per the NOTE above).
181
+ # principle bound the slice's length, but a tighter Tuple-of-`n` carrier is not modelled).
187
182
  def slice_block_params(receiver)
188
183
  element = element_type_of(receiver)
189
184
  return nil if element.nil?
@@ -22,12 +22,14 @@ module Rigor
22
22
  # Result rule:
23
23
  #
24
24
  # - `+`, `<<`, `concat`: receiver and argument MUST both be
25
- # `Type::Combinator.literal_string_compatible?`. The result is `literal-string`. `<<` and `concat`
25
+ # `Type::Combinator.literal_string_compatible?`. The result is `literal-string`, or
26
+ # `non-empty-literal-string` when either side is provably non-empty. `<<` and `concat`
26
27
  # mutate the receiver at runtime; the analyzer does not track that mutation against the local's
27
28
  # binding, but the call's *return value* is the receiver itself, and the receiver stays
28
29
  # literal-bearing because every appended slice was literal-bearing too.
29
30
  # - `*`: receiver MUST be literal-bearing; argument MUST be integer-typed. The result is
30
- # `literal-string`.
31
+ # `literal-string` (`non-empty-literal-string` for a non-empty receiver and a positive count,
32
+ # `Constant[""]` for a zero count; a negative count declines).
31
33
  # - `join`: receiver MUST be `Tuple[…]` with every element literal-string-compatible; the optional
32
34
  # separator argument MUST also be literal-string-compatible. Result: `literal-string`. Empty
33
35
  # `Tuple[]` lifts too — `[].join` is the empty string at runtime, which is literal-bearing
@@ -7,7 +7,7 @@ module Rigor
7
7
  module Inference
8
8
  module MethodDispatcher
9
9
  # Issue #1381 — slice reads of the proven `$~`. On a proven-match edge the flow engine narrows `$~` to
10
- # `MatchData` and each unconditional group's `$N` to `String` (see `Narrowing#regex_match_predicate_scopes`).
10
+ # `MatchData` and each unconditional group's `$N` to `String` (see `RegexMatch.regex_match_predicate_scopes`).
11
11
  # The Integer overload of RBS `MatchData#[]` already reads `String`, but the Range and `(start, length)`
12
12
  # overloads and `values_at` read `Array[String?]`, and destructuring that binds every slot `String?`.
13
13
  # This tier answers those reads with a Tuple, one slot per group, using the rule