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
@@ -28,7 +28,7 @@ module Rigor
28
28
  module ObjectMixins
29
29
  OWNER = "Object"
30
30
  # The owner key `ScopeIndexer` files a top-level `include` under, beside `Object`'s own key, so that
31
- # no ancestry walk that types a call reaches it (see `ScopeIndexer#toplevel_include_owner`).
31
+ # no ancestry walk that types a call reaches it (see `ScopeIndexer::MixinTables.toplevel_include_owner`).
32
32
  TOPLEVEL_INCLUDE_KEY = "<toplevel-include>"
33
33
 
34
34
  module_function
@@ -174,7 +174,7 @@ module Rigor
174
174
  end
175
175
  private_class_method :source_defines?
176
176
 
177
- # The same "is this mixin's surface enumerable" reading `Analysis::CheckRules#known_mixin?` gives a
177
+ # The same "is this mixin's surface enumerable" reading `UndefinedMethod.known_mixin?` gives a
178
178
  # class's own includes (#746): a project class or module, or an RBS declaration Rigor did not
179
179
  # synthesize to keep a broken signature buildable.
180
180
  def declared?(scope, name)
@@ -0,0 +1,214 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "prism"
4
+
5
+ require_relative "alias_mutation_floor"
6
+ require_relative "deep_erasure"
7
+ require_relative "mutation_rejoin"
8
+ require_relative "mutation_widening"
9
+ require_relative "receiver_alias"
10
+ require_relative "set_mutation"
11
+
12
+ module Rigor
13
+ module Inference
14
+ # Issue #3340 — a variable handed to code the engine cannot read, in a form that may mutate the object it holds
15
+ # without the call site spelling `xs.<mutator>`:
16
+ #
17
+ # - the receiver of a `send` / `public_send` / `__send__` whose name is computed (`xs.send(name)`), or is a
18
+ # literal mutator the call gives a block ({AliasMutationFloor.literal_send_target} reads only the blockless
19
+ # form);
20
+ # - the receiver of a `Method` object the statement calls at once under a computed name (`xs.method(name).call`).
21
+ # A literal name is the call it makes instead ({.method_object_target}), as a literal `send` is;
22
+ # - the receiver of `instance_eval` / `instance_exec`, whose block runs with that object as `self`: a literal
23
+ # block that calls a mutator on `self` (`xs.instance_eval { clear }`), a block passed as a value, or a string;
24
+ # - a local among the arguments of a `yield` ({.yielded}), which the method's block receives as a call's
25
+ # arguments are received by an opaque proc.
26
+ #
27
+ # Each such variable takes one unknown store, and only when its binding holds a literal shape or an empty-witness
28
+ # refinement ({AliasMutationFloor.callee_floor}): a `Tuple`, a `HashShape`, a literal String or Set,
29
+ # `non-empty-array[T]`. A nominal (`Array[String]`) is a claim no store is read to falsify, and is left alone, so
30
+ # the floor forgets only what the mutation can make false. The locals that may hold the same object floor with
31
+ # it ({AliasMutationFloor.floor_after_written_local}).
32
+ #
33
+ # Not covered: a `Method` object kept in a variable and called later (`m = xs.method(:clear); m.call`), and a
34
+ # block passed as a value over a literal Array of locals (`[xs].each(&blk)`).
35
+ module OpaqueMutation
36
+ SEND_NAMES = %i[send public_send __send__].to_set.freeze
37
+ SELF_EVAL_NAMES = %i[instance_eval instance_exec].to_set.freeze
38
+ METHOD_OBJECT_NAMES = %i[method public_method].to_set.freeze
39
+ # The names that run a `Method` object: `m.call`, `m.()` (which parses as `call`), `m[]` and `m === x`.
40
+ METHOD_CALL_NAMES = %i[call [] ===].to_set.freeze
41
+ # Every call name {.floor} reads, so any other call returns at one lookup.
42
+ NAMES = (SEND_NAMES | SELF_EVAL_NAMES | METHOD_CALL_NAMES).freeze
43
+ # The names a mutation of `self` is read by inside an `instance_eval` block: the straight-line widening's, a
44
+ # Set-only adder's, and a `send`, which may name any of them.
45
+ SELF_MUTATORS = (MutationWidening::SHAPE_MUTATORS | SetMutation::MUTATORS | SEND_NAMES).freeze
46
+ NAME_LITERALS = [Prism::SymbolNode, Prism::StringNode].freeze
47
+ NO_READS = [].freeze
48
+ private_constant :SEND_NAMES, :SELF_EVAL_NAMES, :METHOD_OBJECT_NAMES, :METHOD_CALL_NAMES, :NAMES,
49
+ :SELF_MUTATORS, :NAME_LITERALS, :NO_READS
50
+
51
+ module_function
52
+
53
+ # `recv.method(:name).call(args)` (or `.()`, `[]`, `===`; `public_method` too) as the call it makes,
54
+ # `recv.name(args)`, or nil: for a `Method` object any other way, a computed name, or a call with a block.
55
+ def method_object_target(call_node)
56
+ taker = method_object(call_node)
57
+ return nil if taker.nil? || !call_node.block.nil?
58
+
59
+ name = literal_name(taker.arguments.arguments.first)
60
+ name && call_node.copy(receiver: taker.receiver, name: name)
61
+ end
62
+
63
+ # `scope` after `call_node`, with each variable its opaque receiver names floored ({.floor_reads}).
64
+ def floor(call_node, scope)
65
+ return scope unless NAMES.include?(call_node.name)
66
+
67
+ receiver = opaque_receiver(call_node)
68
+ return scope if receiver.nil?
69
+
70
+ floor_reads(ReceiverAlias.mutated_reads(receiver), scope, call_node)
71
+ end
72
+
73
+ # `scope` after `node` when it is a `yield`, with each local it passes, positionally or as a keyword's value,
74
+ # floored; `scope` itself for any other node.
75
+ def yielded(node, scope)
76
+ arguments = node.arguments&.arguments if node.is_a?(Prism::YieldNode)
77
+ return scope if arguments.nil?
78
+
79
+ floor_reads(local_arguments(arguments), scope, nil)
80
+ end
81
+
82
+ # `scope` with every local `body` hands to code the engine cannot read, or mutates through a form the
83
+ # straight-line widening reads only at the call ({.reached_reads}), floored: what the local can hold once any
84
+ # prefix of `body` has run, for the rescue clause that follows it (`ClauseWidening.content_entry`).
85
+ def floor_reached(body, scope)
86
+ floor_reads(reached_reads(body, []), scope, nil)
87
+ end
88
+
89
+ # The variable reads under `node`, outside a nested `def`, that a `yield` passes, an opaque receiver names
90
+ # ({.opaque_receiver}), a literal `send` or a literal-named `Method` object mutates, or a symbol block mutates
91
+ # as an element of a literal Array.
92
+ def reached_reads(node, reads)
93
+ return reads if node.nil? || node.is_a?(Prism::DefNode)
94
+
95
+ if node.is_a?(Prism::YieldNode)
96
+ reads.concat(local_arguments(node.arguments&.arguments || NO_READS))
97
+ elsif node.is_a?(Prism::CallNode)
98
+ call_reads(node, reads)
99
+ end
100
+ node.rigor_each_child { |child| reached_reads(child, reads) }
101
+ reads
102
+ end
103
+
104
+ def call_reads(call_node, reads)
105
+ made = AliasMutationFloor.literal_send_target(call_node) || method_object_target(call_node)
106
+ receiver = made && SELF_MUTATORS.include?(made.name) ? made.receiver : opaque_receiver(call_node)
107
+ reads.concat(ReceiverAlias.mutated_reads(receiver)) if receiver
108
+ return unless call_node.receiver.is_a?(Prism::ArrayNode) && DeepErasure.symbol_proc_mutation?(call_node.block)
109
+
110
+ call_node.receiver.elements.each { |element| reads.concat(ReceiverAlias.mutated_reads(element)) }
111
+ end
112
+
113
+ # The receiver `call_node` hands to code that may mutate it, or nil.
114
+ def opaque_receiver(call_node)
115
+ receiver = call_node.receiver
116
+ return nil if receiver.nil? || receiver.is_a?(Prism::SelfNode)
117
+
118
+ name = call_node.name
119
+ if SEND_NAMES.include?(name) then receiver if opaque_send?(call_node)
120
+ elsif SELF_EVAL_NAMES.include?(name) then receiver if self_mutating_eval?(call_node)
121
+ else
122
+ taker = method_object(call_node)
123
+ taker.receiver if taker && literal_name(taker.arguments.arguments.first).nil?
124
+ end
125
+ end
126
+
127
+ # A `send` with a computed name, or with a literal mutator's name and a block.
128
+ def opaque_send?(call_node)
129
+ target = call_node.arguments&.arguments&.first
130
+ return false if target.nil?
131
+
132
+ name = literal_name(target)
133
+ name.nil? ? !target.is_a?(Prism::BlockArgumentNode) : !call_node.block.nil? && SELF_MUTATORS.include?(name)
134
+ end
135
+
136
+ # An `instance_eval` / `instance_exec` whose code may mutate its receiver: a literal block calling a mutator
137
+ # on `self`, or code the call does not show (a block passed as a value, a string).
138
+ def self_mutating_eval?(call_node)
139
+ block = call_node.block
140
+ return true unless block.is_a?(Prism::BlockNode)
141
+
142
+ self_mutation?(block.body)
143
+ end
144
+
145
+ # Whether `node` calls a {SELF_MUTATORS} name on `self`, implicitly or as `self.`, outside a nested `def`. A
146
+ # nested block is read too: it runs on the same `self`.
147
+ def self_mutation?(node)
148
+ return false if node.nil? || node.is_a?(Prism::DefNode)
149
+
150
+ if node.is_a?(Prism::CallNode) && SELF_MUTATORS.include?(node.name)
151
+ receiver = node.receiver
152
+ return true if receiver.nil? || receiver.is_a?(Prism::SelfNode)
153
+ end
154
+ node.rigor_each_child { |child| return true if self_mutation?(child) }
155
+ false
156
+ end
157
+
158
+ # The `recv.method(name)` call `call_node` runs at once (`recv.method(name).call`), or nil.
159
+ def method_object(call_node)
160
+ return nil unless METHOD_CALL_NAMES.include?(call_node.name)
161
+
162
+ taker = call_node.receiver
163
+ return nil unless taker.is_a?(Prism::CallNode) && METHOD_OBJECT_NAMES.include?(taker.name)
164
+ return nil if taker.receiver.nil? || taker.receiver.is_a?(Prism::SelfNode)
165
+
166
+ taker.arguments&.arguments&.size == 1 && taker.block.nil? ? taker : nil
167
+ end
168
+
169
+ # The method a literal Symbol or String names, or nil for any other node.
170
+ def literal_name(node)
171
+ return nil unless NAME_LITERALS.include?(node.class) && node.unescaped.valid_encoding?
172
+
173
+ node.unescaped.to_sym
174
+ end
175
+
176
+ # The local reads among `arguments`: a positional argument or a keyword's value.
177
+ def local_arguments(arguments)
178
+ reads = nil
179
+ arguments.each do |argument|
180
+ if argument.is_a?(Prism::KeywordHashNode)
181
+ argument.elements.each do |pair|
182
+ next unless pair.is_a?(Prism::AssocNode)
183
+
184
+ value = pair.value.is_a?(Prism::ImplicitNode) ? pair.value.value : pair.value
185
+ (reads ||= []) << value if value.is_a?(Prism::LocalVariableReadNode)
186
+ end
187
+ elsif argument.is_a?(Prism::LocalVariableReadNode)
188
+ (reads ||= []) << argument
189
+ end
190
+ end
191
+ reads || NO_READS
192
+ end
193
+
194
+ # `scope` with each variable of `reads` at one unknown store, where its binding holds a literal shape. With a
195
+ # `call_node`, every local that may hold a local read's object floors too.
196
+ def floor_reads(reads, scope, call_node)
197
+ reads.reduce(scope) do |acc, read|
198
+ getter, builder = MutationWidening::ALIAS_ACCESSORS[read.class]
199
+ next acc if getter.nil?
200
+
201
+ if call_node && read.is_a?(Prism::LocalVariableReadNode)
202
+ acc = AliasMutationFloor.floor_after_written_local(acc, read, call_node)
203
+ end
204
+ name = ReceiverAlias.read_name(read)
205
+ current = acc.public_send(getter, name)
206
+ floored = current && AliasMutationFloor.callee_floor(current)
207
+ next acc if floored.nil? || floored == current
208
+
209
+ MutationRejoin.rebind(acc, builder, name, floored, pre_state: current, kind: getter)
210
+ end
211
+ end
212
+ end
213
+ end
214
+ end
@@ -6,8 +6,9 @@ require_relative "../type"
6
6
 
7
7
  module Rigor
8
8
  module Inference
9
- # Marks a value whose *nil-freeness* rests on Rigor's deliberate choice to ignore core RBS's
10
- # `%a{implicitly-returns-nil}` annotation rather than on the value's class. See
9
+ # Marks a value whose *nil-freeness* rests on a deliberate choice rather than on the value's class: Rigor's
10
+ # choice to ignore core RBS's `%a{implicitly-returns-nil}` annotation ({IMPLICITLY_RETURNS_NIL}), or a plugin's
11
+ # to omit a `nil` its answer can hold ({PLUGIN_NIL_FREE}, #3322). See
11
12
  # docs/internal-spec/inference-engine.md § "That deferred-to answer is nil-free for a lookup that can
12
13
  # miss": `Hash#[]` reads as `V` and `Array#first` as `E` because pessimising them to `V?` costs 25
13
14
  # measured false positives on Rigor's own `lib`. The consequence the spec draws is that such a value is
@@ -33,10 +34,16 @@ module Rigor
33
34
  # The core-RBS annotation `RbsDispatch` reads the return type past.
34
35
  ANNOTATION = "implicitly-returns-nil"
35
36
 
36
- # The single cause carried today. Kept as a symbol (rather than a bare `true`) so a later slice can
37
- # distinguish further optimistic families without changing the table's shape.
37
+ # The cause an `%a{implicitly-returns-nil}` read carries. Kept as a symbol (rather than a bare `true`) so the
38
+ # optimistic families stay distinguishable without changing the table's shape ({PLUGIN_NIL_FREE} is the
39
+ # second).
38
40
  IMPLICITLY_RETURNS_NIL = :implicitly_returns_nil
39
41
 
42
+ # Issue #3322 — a plugin's `dynamic_return` answered through `Plugin::Base#optimistic_nil_free`: the type
43
+ # omits a `nil` the value can hold, on the plugin's judgment that contributing it costs more false
44
+ # positives than it finds (rigor-activerecord's nullable column readers).
45
+ PLUGIN_NIL_FREE = :plugin_nil_free
46
+
40
47
  # The argument-free unary predicates whose folded result is a statement about the receiver's
41
48
  # *nil-freeness* and nothing else, which is what makes the derivation sound rather than a general taint:
42
49
  # `nil?` answers the exact question the optimism is a bet on, and `!` (which Prism spells as a `CallNode`
@@ -51,6 +58,14 @@ module Rigor
51
58
  # other value folds from the carrier's value and stays out, for the reason the value predicates do.
52
59
  NIL_COMPARISONS = %i[== != eql? equal? ===].freeze
53
60
 
61
+ # Issue #3322 — ActiveSupport's presence predicates. Both are value predicates on a hit (`"".present?` is
62
+ # false), but where `NilClass` declares them ({.nil_class_declares?}) a miss answers a fixed boolean —
63
+ # `nil.present?` is false and `nil.blank?` true, as for `false` — so a fold over an optimistic carrier is a
64
+ # bet exactly as `nil?`'s is: `record.completed_at.present?` folds to `true` only because the reader omitted
65
+ # the `nil` the column can hold. The value is the predicate's answer for a falsey carrier
66
+ # ({.miss_answer_of_call}).
67
+ PRESENCE_PREDICATES = { present?: false, blank?: true }.freeze
68
+
54
69
  # {.miss_answer}'s answer for an expression whose value on a miss cannot be told.
55
70
  UNKNOWN_MISS = Object.new.freeze
56
71
 
@@ -82,7 +97,13 @@ module Rigor
82
97
 
83
98
  # The entry a control-flow join keeps for a name both arms mark: the answer survives only when the arms
84
99
  # agree on it, since otherwise a miss can take either arm's.
85
- def join_bound_marks(mine, theirs) = mine == theirs ? mine : bound_cause(mine)
100
+ def join_bound_marks(mine, other) = mine == other ? mine : stronger_cause(bound_cause(mine), bound_cause(other))
101
+
102
+ # #3322 — the cause kept where two marks combine (a join, either operand of `&&` / `||`, a write's right-hand
103
+ # side and old binding). A lookup's cause outranks a plugin's: both stop the certainty consumers, but only the
104
+ # lookup's makes `rigor sig-gen` keep the `nil` a miss returns (`DefReturnTyper#lookup_mark?`), so letting the
105
+ # plugin's shadow it would drop that `nil` by arm order alone.
106
+ def stronger_cause(left, right) = left && right && left == PLUGIN_NIL_FREE ? right : left || right
86
107
 
87
108
  # `rebound` — `scope` with the local `name` rebound to its type across a loop's iterations
88
109
  # (`CapturedLocals.bind`) — re-marked with the mark `scope` holds for `name` or `optimistic`, the one an
@@ -90,13 +111,13 @@ module Rigor
90
111
  # that one comes without its answer, so the pair's cannot be told.
91
112
  def carry_local_mark(scope, rebound, name, optimistic)
92
113
  miss = optimistic ? UNKNOWN_MISS : scope.optimistic_local_miss(name)
93
- rebound.with_optimistic_local(name, scope.optimistic_local(name) || optimistic, miss: miss)
114
+ rebound.with_optimistic_local(name, stronger_cause(scope.optimistic_local(name), optimistic), miss: miss)
94
115
  end
95
116
 
96
117
  # {.carry_local_mark} for an instance variable.
97
118
  def carry_ivar_mark(scope, rebound, name, optimistic)
98
119
  miss = optimistic ? UNKNOWN_MISS : scope.optimistic_ivar_miss(name)
99
- rebound.with_optimistic_ivar(name, scope.optimistic_ivar(name) || optimistic, miss: miss)
120
+ rebound.with_optimistic_ivar(name, stronger_cause(scope.optimistic_ivar(name), optimistic), miss: miss)
100
121
  end
101
122
 
102
123
  # The effective optimistic-nil-free cause of an expression under `scope`, or nil when its nil-freeness is
@@ -129,7 +150,7 @@ module Rigor
129
150
  Prism::InstanceVariableAndWriteNode, Prism::ClassVariableAndWriteNode,
130
151
  Prism::GlobalVariableAndWriteNode
131
152
  resolve_write_form(node, scope)
132
- when Prism::AndNode, Prism::OrNode then resolve(node.left, scope) || resolve(node.right, scope)
153
+ when Prism::AndNode, Prism::OrNode then stronger_cause(resolve(node.left, scope), resolve(node.right, scope))
133
154
  when Prism::CallNode
134
155
  resolve_attribute_write(node, scope) || resolve_through_safe_navigation(node, scope) ||
135
156
  resolve_through_predicate(node, scope)
@@ -159,7 +180,7 @@ module Rigor
159
180
  # the mark recorded on the read itself, which lives in the side table every scope shares; the binding lookup
160
181
  # stays as the fallback for the post-write scope `branch_certainty` passes.
161
182
  def resolve_write(node, scope)
162
- resolve(node.value, scope) || optimistic_write_binding(node, scope)
183
+ stronger_cause(resolve(node.value, scope), optimistic_write_binding(node, scope))
163
184
  end
164
185
 
165
186
  # Only locals and ivars carry a binding mark; a global or class-variable write, and a
@@ -192,7 +213,7 @@ module Rigor
192
213
  # to, joined by the old binding's own mark for the case where the miss — not the rvalue — is
193
214
  # what makes the condition live (`v = h[k]; if (v &&= "lit")`).
194
215
  def resolve_and_write(node, scope)
195
- resolve(node.value, scope) || and_write_binding_mark(node, scope)
216
+ stronger_cause(resolve(node.value, scope), and_write_binding_mark(node, scope))
196
217
  end
197
218
 
198
219
  # The `[type, mark]` pair an `||=` reads its old value through: the scope binding and the
@@ -258,7 +279,7 @@ module Rigor
258
279
  # `recv.nil?` / `!recv` / `recv == nil` — the fold is a statement about `recv`, so it is exactly as
259
280
  # optimistic as `recv` is.
260
281
  def resolve_through_predicate(node, scope)
261
- operand = nil_question_operand(node)
282
+ operand = nil_question_operand(node, scope)
262
283
  operand && resolve(operand, scope)
263
284
  end
264
285
 
@@ -266,11 +287,12 @@ module Rigor
266
287
  # or any argument means `nil?` / `!` is not the unary predicate it looks like (`x.!(y)` is a user-defined
267
288
  # operator). A comparison needs exactly one positional argument and exactly one `nil` literal side, and
268
289
  # answers the other side (`nil == nil` states nothing about a carrier).
269
- def nil_question_operand(node)
290
+ def nil_question_operand(node, scope)
270
291
  return nil unless node.block.nil?
271
292
 
272
293
  arguments = node.arguments&.arguments || []
273
- if NIL_COLLAPSING_PREDICATES.include?(node.name)
294
+ if NIL_COLLAPSING_PREDICATES.include?(node.name) ||
295
+ (PRESENCE_PREDICATES.key?(node.name) && nil_class_declares?(node.name, scope))
274
296
  node.receiver if arguments.empty?
275
297
  elsif NIL_COMPARISONS.include?(node.name) && arguments.size == 1
276
298
  nil_comparison_operand(node.receiver, arguments.first)
@@ -310,17 +332,33 @@ module Rigor
310
332
  def miss_answer_of_call(node, scope)
311
333
  return nil if node.safe_navigation? && resolve(node.receiver, scope)
312
334
 
313
- operand = nil_question_operand(node)
335
+ operand = nil_question_operand(node, scope)
314
336
  inner = operand ? miss_answer(operand, scope) : UNKNOWN_MISS
315
337
  return UNKNOWN_MISS if inner.equal?(UNKNOWN_MISS)
316
338
 
317
339
  case node.name
318
340
  when :! then !inner
319
341
  when :!= then !inner.nil?
342
+ when :present?, :blank? then presence_answer(node.name, inner)
320
343
  else inner.nil?
321
344
  end
322
345
  end
323
346
 
347
+ # #3322 — a presence predicate restates a miss only where `nil` answers it (ActiveSupport's `NilClass#present?`,
348
+ # which rigor-activesupport-core-ext and gem_rbs_collection declare). Without that declaration a miss raises
349
+ # `NoMethodError` instead — the element-read rule above — so the fold over a hit stands as proof.
350
+ def nil_class_declares?(name, scope)
351
+ definition = Rigor::Reflection.instance_definition("NilClass", scope: scope)
352
+ !definition.nil? && !definition.methods[name].nil?
353
+ end
354
+
355
+ # What `present?` / `blank?` answers for a carrier whose value is `inner`: the falsey answer for `nil` /
356
+ # `false`, its negation for `true` (the only other miss answers a derivation produces).
357
+ def presence_answer(name, inner)
358
+ falsey = PRESENCE_PREDICATES.fetch(name)
359
+ inner ? !falsey : falsey
360
+ end
361
+
324
362
  # `(x.nil?)` — a single-statement parenthesised body is its own value, and authors do parenthesise a
325
363
  # composed guard. A multi-statement body's value is its last statement, but the earlier statements can
326
364
  # rebind, so only the single-statement form is derived.
@@ -43,7 +43,7 @@ module Rigor
43
43
  end
44
44
 
45
45
  # The dispatch class for a receiver type, for the subset the collector resolves to a user
46
- # `def` (mirrors `CheckRules#concrete_class_name` for the carriers a user-method receiver
46
+ # `def` (mirrors `CheckRules::ReceiverPredicates.concrete_class_name` for the carriers a user-method receiver
47
47
  # is typed as). `class_name_of` is the Nominal/Singleton-only variant for an implicit-self
48
48
  # `self_type`.
49
49
  def concrete_class_name(type)
@@ -14,13 +14,13 @@ module Rigor
14
14
  # ADR-17 slice 2 gave `pre_eval:` a project-wide **method** registry ({ProjectPatchedMethods}). A
15
15
  # constant declared in the same file stayed invisible across the file boundary: `Scope#in_source_constants`
16
16
  # was per-file and kept out of `Runner#project_scope_seed_tables`, so only class-shaped
17
- # constants (a `class` / `module` declaration, or one of the four meta-new forms `ScopeIndexer`'s
18
- # `record_class_new_constant_decl` promotes) ever crossed. `TIMEOUT = 30` in a listed file read as
17
+ # constants (a `class` / `module` declaration, or one of the four meta-new forms
18
+ # `ScopeIndexer::ClassDeclarations` promotes) ever crossed. `TIMEOUT = 30` in a listed file read as
19
19
  # `Dynamic[top]` everywhere else.
20
20
  #
21
21
  # This collector closes that half. It walks the `pre_eval:` files with the SAME constant pre-pass the
22
- # per-file path uses ({ScopeIndexer.build_in_source_constants}) and publishes the result — widened — into
23
- # the project seed. Files not listed under `pre_eval:` are untouched, so the feature is opt-in by
22
+ # per-file path uses ({ScopeIndexer::ConstantTables.build_in_source_constants}) and publishes the result — widened —
23
+ # into the project seed. Files not listed under `pre_eval:` are untouched, so the feature is opt-in by
24
24
  # construction and its cost stays proportional to the listed file count (ADR-17 WD1's cost-bounded
25
25
  # argument, which is also why slice 5's full-project two-pass stayed rejectable).
26
26
  #
@@ -71,9 +71,9 @@ module Rigor
71
71
  #
72
72
  # ## The multi-file write rule — widen on conflict, all the way to `Dynamic[top]`
73
73
  #
74
- # Within one file, `ScopeIndexer#record_constant_write` unions repeated writes; that union is widened as a
75
- # whole (`X = 1; X = "a"` in one file publishes `Integer | String`). ACROSS files the same union would be
76
- # a type neither author can see, so the rule is **widen on conflict**: when two listed files publish the
74
+ # Within one file, `ScopeIndexer::ConstantTables.record_constant_write` unions repeated writes; that union is
75
+ # widened as a whole (`X = 1; X = "a"` in one file publishes `Integer | String`). ACROSS files the same union would
76
+ # be a type neither author can see, so the rule is **widen on conflict**: when two listed files publish the
77
77
  # same qualified name with different widened types, the name is dropped from the table entirely and reads
78
78
  # as `Dynamic[top]` — the widest type there is, and the one the name already had. Agreeing writes (`X = 1`
79
79
  # here, `X = 2` there — both `Integer`) are not a conflict at all, which is the point of widening first:
@@ -138,7 +138,9 @@ module Rigor
138
138
  return EMPTY unless parse_result.errors.empty?
139
139
 
140
140
  root = parse_result.value
141
- ScopeIndexer.build_in_source_constants(root, declaration_seeded_scope(root, scope_builder.call(path)))
141
+ ScopeIndexer::ConstantTables.build_in_source_constants(
142
+ root, declaration_seeded_scope(root, scope_builder.call(path))
143
+ )
142
144
  rescue StandardError
143
145
  EMPTY
144
146
  end
@@ -148,7 +150,7 @@ module Rigor
148
150
  # classes onto the project-seeded scope so a `CONST = SomeClassDefinedRightHere.new` rvalue types the
149
151
  # same way it does during real analysis.
150
152
  def declaration_seeded_scope(root, scope)
151
- declared_types, discovered_classes = ScopeIndexer.build_declaration_artifacts(root)
153
+ declared_types, discovered_classes = ScopeIndexer::DeclarationArtifacts.build_declaration_artifacts(root)
152
154
  scope.with_discovery(
153
155
  scope.discovery.with(
154
156
  declared_types: declared_types,
@@ -26,6 +26,11 @@ module Rigor
26
26
  # The summary exposes `precision_ratio` (constant+nominal+shaped+refined+bot over total) and
27
27
  # `opaque_ratio` (dynamic_top+top over total).
28
28
  #
29
+ # It also tallies *call sites*: every `Prism::CallNode` (a counted expression, so the tally is a subset of
30
+ # `total`), and of those the *Dynamic call sites*, whose result classifies as `:dynamic_top` or
31
+ # `:dynamic_specific` — a whole `Dynamic`, or a union whose worst member is one. A `Top` result is not a Dynamic
32
+ # call site, and neither is a union holding both `Dynamic` and `Top` (its worst tier is `:top`).
33
+ #
29
34
  # For Union types the *worst* member tier is used, since the union is only as precise as its
30
35
  # least-precise constituent. Intersection uses the *best* member (the most specific side wins).
31
36
  # Difference follows its base type.
@@ -87,8 +92,21 @@ module Rigor
87
92
  PRECISE_TIERS = %i[constant nominal shaped refined bot].to_set.freeze
88
93
  private_constant :PRECISE_TIERS
89
94
 
95
+ DYNAMIC_TIERS = %i[dynamic_top dynamic_specific].to_set.freeze
96
+ private_constant :DYNAMIC_TIERS
97
+
90
98
  # Per-file result. Immutable value object.
91
- class FileResult < Data.define(:total, :tier_counts)
99
+ class FileResult < Data.define(:total, :tier_counts, :call_sites, :dynamic_call_sites)
100
+ def initialize(total:, tier_counts:, call_sites: 0, dynamic_call_sites: 0)
101
+ super
102
+ end
103
+
104
+ def dynamic_call_ratio
105
+ return 0.0 if call_sites.zero?
106
+
107
+ dynamic_call_sites.fdiv(call_sites)
108
+ end
109
+
92
110
  def precise_count
93
111
  PRECISE_TIERS.sum { |t| tier_counts.fetch(t, 0) }
94
112
  end
@@ -132,6 +150,8 @@ module Rigor
132
150
  scope_index = ScopeIndexer.index(root, default_scope: @scope)
133
151
  tier_counts = TIERS.to_h { |t| [t, 0] }
134
152
  total = 0
153
+ call_sites = 0
154
+ dynamic_call_sites = 0
135
155
 
136
156
  Source::NodeWalker.each(root) do |node|
137
157
  next if NON_EXPRESSION_NODE_TYPES.include?(node.class.name)
@@ -140,9 +160,14 @@ module Rigor
140
160
  tier = classify(type)
141
161
  tier_counts[tier] += 1
142
162
  total += 1
163
+ next unless node.is_a?(Prism::CallNode)
164
+
165
+ call_sites += 1
166
+ dynamic_call_sites += 1 if DYNAMIC_TIERS.include?(tier)
143
167
  end
144
168
 
145
- FileResult.new(total: total, tier_counts: tier_counts)
169
+ FileResult.new(total: total, tier_counts: tier_counts, call_sites: call_sites,
170
+ dynamic_call_sites: dynamic_call_sites)
146
171
  end
147
172
 
148
173
  private
@@ -8,9 +8,9 @@ module Rigor
8
8
  # pre-pass (slice 2) from the user's `.rigor.yml` `pre_eval:` list.
9
9
  #
10
10
  # Each entry records one `def`, `alias` or `alias_method` declaration the pre-pass observed inside a class /
11
- # module body. The dispatcher's `try_project_patched_method` tier consults this registry between the plugin
12
- # tier and the dependency-source tier so project-side `lib/core_ext/string_extensions.rb` patches are visible
13
- # to cross-file dispatch.
11
+ # module body. The dispatcher's project-patched tier (`MethodDispatcher::ProjectPatched`) consults this registry
12
+ # between the plugin tier and the dependency-source tier so project-side `lib/core_ext/string_extensions.rb`
13
+ # patches are visible to cross-file dispatch.
14
14
  #
15
15
  # The dispatcher answers `Dynamic[T]` (with a heuristic static facet) when `Entry#return_type` is
16
16
  # non-nil, or `Dynamic[Top]` when the heuristic declined (`nil`). See {Entry} for the per-field
@@ -8,7 +8,7 @@ module Rigor
8
8
  #
9
9
  # A `Constant` normally carries a value and no generic instantiation, which is why acceptance
10
10
  # ignores a nominal's `type_args` against one. A Range value is the exception: the engine only
11
- # builds `Constant<Range>` when both endpoints are static (`ExpressionTyper#type_of_range`), so
11
+ # builds `Constant<Range>` when both endpoints are static (`ExpressionTyper::Composites.type_of_range`), so
12
12
  # the element the range would yield IS known, and a `Range[T]` parameter can be judged against it.
13
13
  #
14
14
  # Two consumers share the reading so they cannot drift: `Acceptance` refutes a `Range[T]`
@@ -22,7 +22,7 @@ module Rigor
22
22
  # nil — meaning "no opinion, keep the answer you already had" — covers a carrier that is not a
23
23
  # `Constant<Range>`, a range with no endpoint at all (`nil..nil` constrains nothing), and a
24
24
  # range whose endpoints are not literals. The literal set is the one
25
- # `ExpressionTyper#static_range_endpoint` pins; a value outside it reached the carrier by some
25
+ # `ExpressionTyper::Composites.static_range_endpoint` pins; a value outside it reached the carrier by some
26
26
  # other route and the caller has no lifting for it.
27
27
  def literal_endpoints(type)
28
28
  return nil unless type.is_a?(Type::Constant)
@@ -39,7 +39,7 @@ module Rigor
39
39
 
40
40
  # The endpoints lifted to their own classes and unioned — the element type the range would
41
41
  # yield. Lifting rather than pinning the values mirrors
42
- # `ExpressionTyper#nominal_range_for_endpoints`: `1..9` yields Integers, not the two values 1
42
+ # `ExpressionTyper::Composites.nominal_range_for_endpoints`: `1..9` yields Integers, not the two values 1
43
43
  # and 9, so binding a `Range[A]` parameter's `A` to `Integer` states what the runtime can
44
44
  # honour. Nil when {#literal_endpoints} has nothing to read.
45
45
  def element_type(type)
@@ -67,8 +67,8 @@ module Rigor
67
67
  # carrying only a hint that the value should not be used. Mapping it to `untyped` made Rigor looser
68
68
  # than the toolchain it reads — `Dynamic[top]` is consistent with everything at a gradual boundary,
69
69
  # where `top` demands proof — so a caller could silently depend on a return whose author declared
70
- # "don't rely on this". See ADR-92 WD2; `special-types.md` § `void` (a distinct carrier + a value-use
71
- # diagnostic) remains unimplemented and marked.
70
+ # "don't rely on this". See ADR-92 WD2. The value-use diagnostic is a side table, not a carrier
71
+ # (ADR-100, {VoidOrigin}); the distinct `void` carrier of `special-types.md` § `void` remains unimplemented.
72
72
  RBS::Types::Bases::Void => :translate_top,
73
73
  RBS::Types::Optional => :translate_optional,
74
74
  RBS::Types::Union => :translate_union,
@@ -158,7 +158,7 @@ module Rigor
158
158
  return unknown if node.is_a?(Prism::LambdaNode)
159
159
  return refinement_body(parent) if node.name == :refine
160
160
  return eval_body(parent, node, eval_names) if RefineCensus::SELF_EVAL_CALLS.include?(node.name)
161
- return meta_new_body(node) if ScopeIndexer.meta_new_constant_rvalue?(node)
161
+ return meta_new_body(node) if DeclarationWalk::Rules.meta_new_constant_rvalue?(node)
162
162
  return unknown if parent.here == MAIN
163
163
  return method_body(parent, node.name == :define_singleton_method) if method_block?(node)
164
164
  return parent if keeps_self?(node, &)
@@ -184,7 +184,7 @@ module Rigor
184
184
  def module_here?(here) = named_module?(here) || here.is_a?(Array) || here == ANONYMOUS || here == REFINEMENT
185
185
 
186
186
  def meta_new_body(node)
187
- ScopeIndexer.module_new_call?(node) ? module_body(ANONYMOUS) : class_body(false)
187
+ DeclarationWalk::Rules.module_new_call?(node) ? module_body(ANONYMOUS) : class_body(false)
188
188
  end
189
189
 
190
190
  # A core iteration method on a receiver whose value is a literal in this file: a literal, or a constant, local
@@ -284,10 +284,10 @@ module Rigor
284
284
  context(here, instance, here, deferred: parent.deferred, remote: remote)
285
285
  end
286
286
 
287
- # The modules a `*_eval` / `*_exec` call `node` written in `context` at the lexical `prefix` may run its block
288
- # on, when its receiver is a constant: every name the constant's spelling can denote, innermost first, as another
289
- # file may declare any of them (`M.module_eval { … }` in `module L` runs on `L::M` where some file declares it);
290
- # a `self::`-anchored one as the method walk resolves it (`ScopeIndexer.eval_receiver_prefix`). Else nil.
287
+ # The modules a `*_eval` / `*_exec` call `node` written in `context` at the lexical `prefix` may run its block on,
288
+ # when its receiver is a constant: every name the constant's spelling can denote, innermost first, as another file
289
+ # may declare any of them (`M.module_eval { … }` in `module L` runs on `L::M` where some file declares it); a
290
+ # `self::`-anchored one as the method walk resolves it (`DeclarationWalk::Rules.eval_receiver_prefix`). Else nil.
291
291
  def eval_receiver_names(node, prefix, context)
292
292
  return nil unless RefineCensus::SELF_EVAL_CALLS.include?(node.name) && !RefineCensus.self_call?(node)
293
293
 
@@ -298,7 +298,8 @@ module Rigor
298
298
 
299
299
  here = context.here
300
300
  self_prefix = here.is_a?(String) && here != wildcard ? here.split("::") : []
301
- resolved = ScopeIndexer.eval_receiver_prefix(node, self_prefix, prefix, unnameable_self: self_prefix.empty?)
301
+ resolved = DeclarationWalk::Rules.eval_receiver_prefix(node, self_prefix, prefix,
302
+ unnameable_self: self_prefix.empty?)
302
303
  [resolved.join("::")] unless resolved.nil? || resolved.empty?
303
304
  end
304
305
 
@@ -3,8 +3,8 @@
3
3
  module Rigor
4
4
  module Inference
5
5
  # ADR-121 WD2 (issue #1664) — which in-effect refinement, if any, answers a call on an instance of a class. The
6
- # typed refined arm (`ExpressionTyper#try_refined_dispatch`) asks it before every other answer, because those
7
- # answer from the method a refinement replaces.
6
+ # typed refined arm (`CallLadder::Refined.try_call`, the first rung of the call ladder) asks it before every other
7
+ # answer, because those answer from the method a refinement replaces.
8
8
  #
9
9
  # Precedence follows `doc/syntax/refinements.rdoc` § Method Lookup: walk the receiver's classes from the most
10
10
  # derived. At each class, the latest in-effect module refining the name for that class wins; otherwise its