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
@@ -60,7 +60,7 @@ module Rigor
60
60
  private
61
61
 
62
62
  # A malformed key cannot arrive from `Configuration` (tier 2 rejects it), but this class is also
63
- # constructed straight from a Hash in specs and by a future plugin channel (#387), so an
63
+ # constructed straight from a Hash in specs (plugin rows go through {PluginFacts}, #387), so an
64
64
  # unparseable key is dropped rather than raised on: attribution is an enrichment, and a bad row
65
65
  # must not take a run down.
66
66
  def build_rows(table)
@@ -10,7 +10,7 @@ module Rigor
10
10
  #
11
11
  # An EffectTable is **not a diagnostic and never enters `rigor check`'s stream**. It hangs off the
12
12
  # runner for the report of this slice and the snapshot of #381 to read, exactly as
13
- # [ADR-102](../adr/102-unused-code-reachability-report.md) draws the report-versus-diagnostic line.
13
+ # [ADR-102](../../../docs/adr/102-unused-code-reachability-report.md) draws the report-versus-diagnostic line.
14
14
  class EffectTable
15
15
  # One method's row.
16
16
  #
@@ -15,7 +15,7 @@ module Rigor
15
15
  # A run has one identity for its diagnostics and one for its effect summaries. The diagnostics identity
16
16
  # is today's and is deliberately untouched by this file: collection is observational, so a diagnostics
17
17
  # entry computed with effects on is valid for a run with effects off and vice versa. The effects
18
- # identity is that identity **plus** the three things that change what a summary means without changing
18
+ # identity is that identity **plus** the four things that change what a summary means without changing
19
19
  # a single analyzed byte:
20
20
  #
21
21
  # - the **vocabulary version** ({Registry#vocabulary_version}) — a rename or a removal re-reads every
@@ -31,7 +31,7 @@ module Rigor
31
31
  #
32
32
  # This module is the ONE place that answers it. {.digest} is the string form (what the ADR-46 snapshot
33
33
  # payload carries beside `return_summaries`) and {.descriptor} is the {Cache::Descriptor} form (what the
34
- # ADR-45 whole-run effects slot is keyed by): the same three inputs, spelled for the two stores.
34
+ # ADR-45 whole-run effects slot is keyed by): the same four inputs, spelled for the two stores.
35
35
  #
36
36
  # Nothing here is consulted when collection is off — no entry is written, no key is perturbed, and the
37
37
  # `effects:` block stays out of `Configuration#to_h` so enabling the feature invalidates no existing
@@ -78,7 +78,7 @@ module Rigor
78
78
  # The effects identity as a cache KEY descriptor: the run's own diagnostics key descriptor plus one
79
79
  # `configs:` entry carrying {.digest}. Composing (rather than rebuilding) is what makes the effects
80
80
  # slot inherit every diagnostics-invalidating input — engine version, engine source, RBS libraries,
81
- # the analyzed-path set — for free, so "the effects identity is the diagnostics identity plus three
81
+ # the analyzed-path set — for free, so "the effects identity is the diagnostics identity plus four
82
82
  # things" is a property of the code rather than a claim about it.
83
83
  #
84
84
  # @param base — the run's diagnostics key descriptor
@@ -17,14 +17,14 @@ module Rigor
17
17
  # The analysis is deliberately **flow-insensitive and whole-body**: a local that escapes anywhere
18
18
  # disqualifies, even if the escape happens after the mutation. That is strictly more conservative than
19
19
  # the "escaped before the mutating call" reading, which is the direction false positives are budgeted
20
- # in ([ADR-5](../adr/5-robustness-principle.md)) — an unproven local mutation becomes an
20
+ # in ([ADR-5](../../../docs/adr/5-robustness-principle.md)) — an unproven local mutation becomes an
21
21
  # `unknown-ownership` taint, never a proven `mutate` label.
22
22
  #
23
23
  # This is the tracer slice's approximation, not the eventual answer. `ClosureEscapeAnalyzer` answers a
24
24
  # different question (fact retention, not "does the code contain") and is deliberately left alone.
25
25
  module LocalOwnership
26
26
  # Assignment right-hand sides that witness a fresh allocation. `.dup` / `.clone` follow
27
- # [ADR-76](../adr/76-effect-modeling-freeze-dup-shape-preservation.md)'s reading of `dup` as the
27
+ # [ADR-76](../../../docs/adr/76-effect-modeling-freeze-dup-shape-preservation.md)'s reading of `dup` as the
28
28
  # allocation witness; `.new` is {constructor?}'s, because only a class object's `new` is `Class#new`.
29
29
  COPYING_SELECTORS = %i[dup clone].to_set.freeze
30
30
 
@@ -18,7 +18,7 @@ module Rigor
18
18
  # It is `db/schema.rb` for effects: a generated artefact a project commits, whose diff in a pull
19
19
  # request *is* the review signal, whose freshness CI checks, and where intent is expressed by
20
20
  # committing the regenerated file rather than by annotating code. It emits no diagnostic and never
21
- # enters `rigor check`'s stream ([ADR-102](../adr/102-unused-code-reachability-report.md)).
21
+ # enters `rigor check`'s stream ([ADR-102](../../../docs/adr/102-unused-code-reachability-report.md)).
22
22
  #
23
23
  # Two tables, chosen so a diff is **attributable**:
24
24
  #
@@ -10,13 +10,14 @@ module Rigor
10
10
  # (ADR-103 WD1 / WD12; the lanes and the exhaustiveness bit are normative in
11
11
  # `docs/type-specification/effect-labels.md`).
12
12
  #
13
- # Three carriers and one projection:
13
+ # The fields, and one projection:
14
14
  #
15
15
  # - {#bundles} — `{Origin => LabelSet}`, the labels kept **per origin** so the judgment can discharge
16
16
  # policy per origin (tolerating what an origin was *for* frees its transport, WD14; {Discharge}).
17
- # - {#declared_bundles} — the same shape for the `≤` lane, and {#declared} its flat projection. Its one
18
- # producer today is the project's `effects.attribution:` table (#385), whose origins carry
19
- # {Origin::ATTRIBUTION}; a *nominal supertype's* envelope joins it with #386. The lane is kept apart
17
+ # - {#declared_bundles} — the same shape for the `≤` lane, and {#declared} its flat projection. Its producers
18
+ # are the project's `effects.attribution:` table (#385), whose origins carry {Origin::ATTRIBUTION},
19
+ # a callee's imported envelope (#386, {Origin::ENVELOPE}) and a plugin's `effect_attributions:`
20
+ # (#387, {Origin::PLUGIN}). The lane is kept apart
20
21
  # from {#bundles} because nothing declared is ever proven: diagnostics read {#proven} only, so an
21
22
  # attributed label can never manufacture an `effect.envelope-exceeded`.
22
23
  # - {#exhaustive} — false when some call this method makes could not be resolved.
@@ -89,6 +89,16 @@ module Rigor
89
89
  # so an rbs or Ruby bump that introduces one fails CI instead of reporting an error on correct code.
90
90
  UNRELIABLE_ANCESTRY = %w[Tempfile Delegator Random Random::Base Gem::MissingSpecError].to_set.freeze
91
91
 
92
+ # The other direction of the same disagreements: for each class above, the named ancestors RBS declares
93
+ # that Ruby's own hierarchy lacks. A subtype check that reads the analyzer process's loaded classes
94
+ # (`Inference::Acceptance`) must not refute `Tempfile <= IO` from Ruby's `Tempfile < Delegator`
95
+ # (#3321), but `Tempfile <= Integer` is refuted by both hierarchies and stays refuted. A class absent
96
+ # here has no such ancestor (rbs 4.2 gives `Random` only an unnamed module). The ancestry guard spec
97
+ # derives this table afresh and fails when it drifts.
98
+ RBS_ONLY_ANCESTORS = {
99
+ "Tempfile" => %w[File IO Enumerable File::Constants Object Kernel PP::ObjectMixin].to_set.freeze
100
+ }.freeze
101
+
92
102
  # @param loader — the project's {RbsLoader}, whose built environment answers the hierarchy.
93
103
  def initialize(loader)
94
104
  @loader = loader
@@ -14,6 +14,7 @@ require_relative "deferred_signature_plan"
14
14
  require_relative "vendored_signature_plan"
15
15
  require_relative "ruby_library_roots"
16
16
  require_relative "core_root"
17
+ require_relative "unreadable_signature"
17
18
  require_relative "../rooted_glob"
18
19
  require_relative "../typing_state"
19
20
 
@@ -884,7 +885,7 @@ module Rigor
884
885
  buffer = ::RBS::Buffer.new(name: file, content: content)
885
886
  _buffer, directives, decls = ::RBS::Parser.parse_signature(buffer)
886
887
  [buffer, directives, decls]
887
- rescue ::RBS::ParsingError, Errno::ENOENT, Errno::EISDIR, Errno::EACCES
888
+ rescue ::RBS::ParsingError, *UnreadableSignature::ERRORS
888
889
  nil
889
890
  end
890
891
 
@@ -905,7 +906,7 @@ module Rigor
905
906
  nil
906
907
  rescue ::RBS::ParsingError => e
907
908
  [file, e.message.to_s.lines.first.to_s.strip]
908
- rescue Errno::ENOENT, Errno::EISDIR, Errno::EACCES
909
+ rescue *UnreadableSignature::ERRORS
909
910
  nil
910
911
  end
911
912
  end
@@ -955,7 +956,8 @@ module Rigor
955
956
 
956
957
  content = File.read(file, encoding: "UTF-8")
957
958
  peers.any? { |buffer| buffer.content == content }
958
- rescue Errno::ENOENT, Errno::EISDIR, Errno::EACCES
959
+ # Defensive: the caller has already skipped an unreadable file through `parse_signature_file`.
960
+ rescue *UnreadableSignature::ERRORS
959
961
  false
960
962
  end
961
963
 
@@ -1467,7 +1469,7 @@ module Rigor
1467
1469
  def read_signature_text(file)
1468
1470
  content = File.read(file, encoding: "UTF-8")
1469
1471
  invalid_encoding?(content) ? nil : content
1470
- rescue Errno::ENOENT, Errno::EISDIR, Errno::EACCES
1472
+ rescue *UnreadableSignature::ERRORS
1471
1473
  nil
1472
1474
  end
1473
1475
 
@@ -1716,7 +1718,7 @@ module Rigor
1716
1718
  # @return whether `path` sits under the bundled gem-overlay root — the prefix half of
1717
1719
  # "this run loaded a `data/gem_overlay/` directory". Callers needing ONE gem's overlay ask
1718
1720
  # {.gem_overlay_sig_paths} for that gem's directory instead: `signature_standdowns` uses this
1719
- # to recognise overlay rows across every gem, while `CheckRules#gem_overlay_loaded?` keys on
1721
+ # to recognise overlay rows across every gem, while `ReceiverPredicates.gem_overlay_loaded?` keys on
1720
1722
  # the activesupport overlay alone (#3041 — a project can load the addressable overlay without
1721
1723
  # the activesupport one, and only the latter may open `ActiveSupport::Duration` /
1722
1724
  # `ActiveSupport::Concern`). `GEM_OVERLAY_SIGS_ROOT` is defined inside this `class << self`
@@ -1734,7 +1736,7 @@ module Rigor
1734
1736
  #
1735
1737
  # - `Environment.gem_overlay_paths` asks per gem, so the overlay stands down instead of loading
1736
1738
  # alongside the twin and collapsing every class they share;
1737
- # - `CheckRules#gem_overlay_loaded?` asks across all of them, because the twin's `sig/` carries no
1739
+ # - `ReceiverPredicates.gem_overlay_loaded?` asks across all of them, because the twin's `sig/` carries no
1738
1740
  # plugin manifest, so `open_receivers:` cannot protect the partial `ActiveSupport::Duration`
1739
1741
  # declaration it nonetheless loads.
1740
1742
  #
@@ -1878,13 +1880,8 @@ module Rigor
1878
1880
  @cache_store = cache_store
1879
1881
  @virtual_rbs = virtual_rbs.map { |name, content| [name.to_s.dup.freeze, content.to_s.dup.freeze].freeze }.freeze
1880
1882
  # Per-loader memoization bucket. Held as a single mutable Hash so the loader instance itself can be
1881
- # `.freeze`d (per ADR-15 reflection-facade contract) without losing the lazy-memo behaviour. Slot
1882
- # names currently consulted: `:env`, `:env_loaded`, `:env_build_warned`, `:definition_build_warned`,
1883
- # `:definition_build_details`, `:definition_build_reported`, `:definition_build_failures`,
1884
- # `:definition_build_deferred_count`, `:definition_build_deferred_first`,
1885
- # `:definition_build_summary_warned`, `:member_consistency`, `:member_consistency_proven`, `:internal_demand`,
1886
- # `:internal_demand_status`, `:builder`, `:reflection`,
1887
- # `:instance_definitions_table`, `:singleton_definitions_table`.
1883
+ # `.freeze`d (per ADR-15 reflection-facade contract) without losing the lazy-memo behaviour. Slots are
1884
+ # created on first use by the `@state[:name]` readers below, so there is no fixed list.
1888
1885
  # Constructed via `Hash.new` (NOT a `{ ... }` literal) so Rigor's `HashShape` narrowing doesn't
1889
1886
  # infer a fixed key set from the initial state and fold post-initial slot reads (e.g.
1890
1887
  # `@state[:env_loaded]`) to a constant `nil`.
@@ -2070,13 +2067,6 @@ module Rigor
2070
2067
  @state[:ruby_library_roots] ||= RubyLibraryRoots.shared
2071
2068
  end
2072
2069
 
2073
- # Issue #2174 — the subset of `signature_paths:` the user configured (every entry is also in
2074
- # `@signature_paths`), and the features the project's source requires: read only by
2075
- # {#ruby_library_reopen?}.
2076
- # Issue #610 — the subset of `signature_paths:` a bundled PLUGIN contributed. Loaded last and allowed to stand
2077
- # down against a colliding generic arity ({.add_deferred_signatures}). Issue #2978 — and the subset that stands
2078
- # down member by member to the rest. Every entry of either is also in `@signature_paths`, so the env cache
2079
- # descriptor already digests these files.
2080
2070
  # Issue #3030 — every `.rbs` file this loader reads from its `signature_paths:`, the `_`-prefixed directories of
2081
2071
  # its `rbs collection` gem directories left out ({.project_sig_files}).
2082
2072
  def signature_files
@@ -2084,11 +2074,18 @@ module Rigor
2084
2074
  end
2085
2075
  private :signature_files
2086
2076
 
2077
+ # Issue #610 — the subset of `signature_paths:` a bundled PLUGIN contributed. Loaded last and allowed to stand
2078
+ # down against a colliding generic arity ({.add_deferred_signatures}). Issue #2978 — and the subset that stands
2079
+ # down member by member to the rest. Every entry of either is also in `@signature_paths`, so the env cache
2080
+ # descriptor already digests these files.
2087
2081
  def assign_partition(deferred_signature_paths, subordinate_signature_paths)
2088
2082
  @deferred_signature_paths = deferred_signature_paths.map { |p| Pathname(p) }.freeze
2089
2083
  @subordinate_signature_paths = subordinate_signature_paths.map { |p| Pathname(p) }.freeze
2090
2084
  end
2091
2085
 
2086
+ # Issue #2174 — the subset of `signature_paths:` the user configured (every entry is also in
2087
+ # `@signature_paths`), and the features the project's source requires: read only by
2088
+ # {#ruby_library_reopen?}.
2092
2089
  def assign_reopen_inputs(project_signature_paths, required_features)
2093
2090
  @project_signature_paths = project_signature_paths.map { |p| Pathname(p) }.freeze
2094
2091
  @required_features = required_features.map { |feature| feature.to_s.dup.freeze }.freeze
@@ -2547,7 +2544,7 @@ module Rigor
2547
2544
  end
2548
2545
 
2549
2546
  # Returns true when the named RBS declaration is a Module (`RBS::AST::Declarations::Module`) rather
2550
- # than a Class. The `user_class_fallback_receiver` tier consults this to route
2547
+ # than a Class. The user-class fallback tier (`UserClassFallback`) consults this to route
2551
2548
  # `Nominal[M].some_kernel_method` (where M is a module mixin like `PP::ObjectMixin`) through the
2552
2549
  # `Nominal[Object]` fallback, because every concrete includer of M sees Kernel / Object instance
2553
2550
  # methods as part of its own ancestor chain.
@@ -3243,7 +3240,7 @@ module Rigor
3243
3240
  # The Reflection consumes the loader's already-warmed cache producers (or, when no `cache_store` is
3244
3241
  # set, eagerly walks the env). Once constructed, the Reflection carries the derived tables
3245
3242
  # independently and never re-consults the loader — making it safe to share across Ractors while the
3246
- # loader stays per- process / per-Ractor for write-path operations.
3243
+ # loader stays per-process / per-Ractor for write-path operations.
3247
3244
  def reflection
3248
3245
  @state[:reflection] ||= begin
3249
3246
  require_relative "reflection"
@@ -4,7 +4,7 @@ module Rigor
4
4
  class Environment
5
5
  # Frozen read-only RBS query facade.
6
6
  # [ADR-15](../../../docs/adr/15-ractor-concurrency.md) Phase 2b extracts the read-only surface of
7
- # {RbsLoader} into this carrier so future Ractor-isolated workers can share one Reflection across the
7
+ # {RbsLoader} into this carrier so Ractor-isolated workers can share one Reflection across the
8
8
  # pool while keeping the per-Ractor mutable accelerator state (per-process memo Hashes) where it belongs.
9
9
  #
10
10
  # Backing tables (all frozen at construction):
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Rigor
4
+ class Environment
5
+ # Issue #3469 — the read errors that make a signature file "unreadable": a file the RBS loader skips so the
6
+ # rest of the environment still loads, and whose cache row folds in {Cache::RbsDescriptor::UNREADABLE_DIGEST}
7
+ # instead of a content digest. One list, so the loader and the cache key agree on which files they skip.
8
+ #
9
+ # - `ENOENT` — a dangling symlink, or a file removed between the glob and the read
10
+ # - `EISDIR` — a directory named `*.rbs`
11
+ # - `EACCES` — a file the user cannot read (`chmod 000`)
12
+ # - `ELOOP` — a symlink loop (`x.rbs -> loop.rbs -> x.rbs`)
13
+ # - `ENOTDIR` — a symlink through a file (`w.rbs -> foo.rbs/inner`)
14
+ # - `ENAMETOOLONG` — a symlink whose target is longer than the system's name limit
15
+ #
16
+ # Named subclasses rather than `SystemCallError`, so an unexpected I/O failure still surfaces.
17
+ module UnreadableSignature
18
+ ERRORS = [Errno::ENOENT, Errno::EISDIR, Errno::EACCES, Errno::ELOOP, Errno::ENOTDIR, Errno::ENAMETOOLONG].freeze
19
+ end
20
+ end
21
+ end
@@ -122,6 +122,13 @@ module Rigor
122
122
  freeze
123
123
  end
124
124
 
125
+ # Issue #2883 — builds the RBS environment now, if it is not built yet, so typing never builds it. A no-op for an
126
+ # environment with no loader. Answers the environment.
127
+ def prepare_for_typing!
128
+ rbs_loader&.prepare_for_typing!
129
+ self
130
+ end
131
+
125
132
  # ADR-20 slices 2e + 6 — lazy HKT registry getter. Merge order on first call: builtins (base) ← plugin
126
133
  # manifest aggregation ← RBS env scan. Last-write-wins on URI collisions so user-authored `.rbs` overlays
127
134
  # beat plugin entries, which beat the bundled JSON_VALUE. Memoised; single-threaded use only (under the
@@ -132,13 +139,6 @@ module Rigor
132
139
  # stage that failed and the other stage still runs, so this getter never raises into its callers —
133
140
  # neither into a file's `analyze_body` rescue nor out of the run-owned demands, which have no rescue
134
141
  # above them at all.
135
- # Issue #2883 — builds the RBS environment now, if it is not built yet, so typing never builds it. A no-op for an
136
- # environment with no loader. Answers the environment.
137
- def prepare_for_typing!
138
- rbs_loader&.prepare_for_typing!
139
- self
140
- end
141
-
142
142
  def hkt_registry
143
143
  @hkt_registry_holder.fetch do
144
144
  pre_scan = pre_scan_hkt_registry
@@ -879,7 +879,7 @@ module Rigor
879
879
  end
880
880
 
881
881
  # Returns true when the RBS environment carries the named declaration as a Module (not a Class). Used by
882
- # the `user_class_fallback_receiver` tier to detect a module-mixin receiver (e.g. `PP::ObjectMixin`) so
882
+ # the user-class fallback tier (`UserClassFallback`) to detect a module-mixin receiver (e.g. `PP::ObjectMixin`) so
883
883
  # the dispatcher can route unresolved method calls through the `Nominal[Object]` fallback — every
884
884
  # concrete includer of M honours Kernel / Object instance methods through its own ancestor chain.
885
885
  def rbs_module?(name)
@@ -33,6 +33,7 @@ module Rigor
33
33
  # - `:mutation` / `:invalidation` / `:role` — Union; dedupe by equality.
34
34
  # - `:exception` — Single-valued. Two non-`nil` non-equal exceptional effects record an
35
35
  # `:exceptional_disagreement` conflict.
36
+ # - `:effects` — Union (label-set join) across every tier; never a conflict.
36
37
  #
37
38
  # ## Cross-tier contradictions
38
39
  #
@@ -3,7 +3,7 @@
3
3
  module Rigor
4
4
  module Hashing
5
5
  # Pure-Ruby XXH3-64 (seed 0, default secret) — the content hash for the `rigor lens` anchors of
6
- # ADR-113 WD6, landed ahead of `rigor lens` itself (#1083). A port of the upstream xxHash scalar
6
+ # ADR-113 WD6 (#1083). A port of the upstream xxHash scalar
7
7
  # path (`xxhash.h`'s `XXH3_64bits` with `XXH3_kSecret`), pinned by the upstream sanity-check
8
8
  # vectors and cross-checked against lisplens's `xxhash-rust` output; see
9
9
  # `spec/rigor/hashing/xxh3_spec.rb`.
@@ -4,6 +4,7 @@ require_relative "../type"
4
4
  require_relative "range_constant"
5
5
  require_relative "content_join"
6
6
  require_relative "../typing_state"
7
+ require_relative "../environment/member_consistency"
7
8
 
8
9
  module Rigor
9
10
  module Inference
@@ -427,7 +428,8 @@ module Rigor
427
428
  # `Class` (when `T` is a class) and always an instance of `Module`. Without this rule a method whose
428
429
  # parameter is typed `Class | Module` would reject every `is_a?(SomeClass)` call and similar
429
430
  # introspection patterns. The rule conservatively answers `:yes` for `Module` (every singleton is at
430
- # least a Module) and for `Class` / `Object` / `BasicObject` (the class object inherits from those).
431
+ # least a Module) and for `Class` / `Object` / `Kernel` / `BasicObject` (the class object inherits from
432
+ # or includes those).
431
433
  # Other Nominals fall through to the default `:no`.
432
434
  CLASS_OBJECT_NOMINALS = %w[Module Class Object Kernel BasicObject].freeze
433
435
  private_constant :CLASS_OBJECT_NOMINALS
@@ -1275,10 +1277,29 @@ module Rigor
1275
1277
  # stdlib, and application classes. When either name fails to resolve we surface "maybe": the caller
1276
1278
  # (overload selector) treats yes/maybe identically, so the conservative answer keeps overload
1277
1279
  # coverage intact. RbsHierarchy exists but this path does not yet consult it; migration to an
1278
- # RBS-driven lookup is deferred.
1280
+ # RBS-driven lookup is deferred. A `:no` against an ancestor only RBS declares (`RBS_ONLY_ANCESTORS`) is
1281
+ # withheld as `:maybe` (#3321).
1279
1282
  def class_subtype_result(target_name:, actual_name:, mode:, kind:)
1280
1283
  return Type::AcceptsResult.yes(mode: mode, reasons: "exact name match") if target_name == actual_name
1281
1284
 
1285
+ result = host_class_subtype_result(target_name: target_name, actual_name: actual_name, mode: mode, kind: kind)
1286
+ return result unless result.no? && rbs_only_ancestor?(actual_name, target_name)
1287
+
1288
+ # #3321 — the analyzer process's own hierarchy cannot refute an ancestor RBS declares and Ruby's hierarchy
1289
+ # lacks: `rigor check` requires `tempfile`, whose `Tempfile < Delegator`, while the RBS declares
1290
+ # `class Tempfile < File`. A `:no` here would report a `Tempfile` passed where `IO` is declared.
1291
+ Type::AcceptsResult.maybe(
1292
+ mode: mode,
1293
+ reasons: "RBS declares #{target_name} an ancestor of #{actual_name}; the host hierarchy does not (#{kind})"
1294
+ )
1295
+ end
1296
+
1297
+ def rbs_only_ancestor?(actual_name, target_name)
1298
+ ancestors = Environment::MemberConsistency::RbsProof::RBS_ONLY_ANCESTORS[actual_name.to_s.delete_prefix("::")]
1299
+ !ancestors.nil? && ancestors.include?(target_name.to_s.delete_prefix("::"))
1300
+ end
1301
+
1302
+ def host_class_subtype_result(target_name:, actual_name:, mode:, kind:)
1282
1303
  target_class = resolve_class(target_name)
1283
1304
  actual_class = resolve_class(actual_name)
1284
1305
  # When only `actual` resolves, we can still rule out `actual <:= target` by inspecting `actual`'s
@@ -205,6 +205,11 @@ module Rigor
205
205
 
206
206
  def local?(read) = read.is_a?(Prism::LocalVariableReadNode) || read.is_a?(Prism::ItLocalVariableReadNode)
207
207
 
208
+ # A site's key is the start of the outermost loop or block that holds it (it may run again after any later
209
+ # point inside that loop), else where it has handed its locals on: its end (the receiver of a call has handed
210
+ # its locals on before the call's message runs, while the call's own arguments are handed on by the call
211
+ # itself), or its block's start. A local's key is its least site's; a capture by a closure that may run later
212
+ # is {ALWAYS}.
208
213
  def key = @site ? @outer || AliasMutationFloor.handed_by(@site) : ALWAYS
209
214
 
210
215
  def note(table, name)
@@ -279,11 +279,6 @@ module Rigor
279
279
  memo: {}.compare_by_identity, named_memo: {}.compare_by_identity)
280
280
  end
281
281
 
282
- # A site's key ({SiteCollector}) is the start of the outermost loop or block that holds it (it may run again after
283
- # any later point inside that loop), else where it has handed its locals on: its end (the receiver of a call has
284
- # handed its locals on before the call's message runs, while the call's own arguments are handed on by the call
285
- # itself), or its block's start. A local's key is its least site's; a capture by a closure that may run later is
286
- # {ALWAYS}.
287
282
  # Where a site has handed its locals on: a call's block may receive them as soon as it starts.
288
283
  def handed_by(node)
289
284
  block = node.block if node.is_a?(Prism::CallNode)
@@ -17,7 +17,7 @@ module Rigor
17
17
  # return) there was no name, so the body fell through to the enclosing — usually top-level — scope. Two
18
18
  # false positives followed on correct code: `attr_reader` became a `call.unresolved-toplevel` warning
19
19
  # (`Scope#toplevel?` is `self_type.nil?`), and the class itself typed as the bare `Singleton[Object]`
20
- # `MethodDispatcher#class_new_lift` hands back, taking `Object`'s zero-arity `new` with it.
20
+ # `MethodDispatcher::MetaIntrospection.class_new_lift` hands back, taking `Object`'s zero-arity `new` with it.
21
21
  #
22
22
  # This module supplies the missing name: a per-call-site synthetic one, spelled so that no Ruby constant
23
23
  # path can collide with it in the discovery tables, and stable across the index pass and the dispatch
@@ -34,7 +34,7 @@ module Rigor
34
34
  # The receiver constant name (`:Class`, `:Module`, `:Struct`, `:Data`) of a class-creating meta call that
35
35
  # carries a literal block, or nil for anything else. The receiver MUST be the bare constant (or its
36
36
  # `::`-rooted spelling) — a call through a variable or another call's return has no statically known
37
- # identity, exactly as `ScopeIndexer#meta_constant_receiver?` requires.
37
+ # identity, exactly as `DeclarationWalk::Rules.meta_constant_receiver?` requires.
38
38
  #
39
39
  # Argument shapes are deliberately NOT inspected: `Class.new(Base) { ... }` and
40
40
  # `Data.define(*members) { ... }` evaluate their block as a class body whatever the arguments are, and a
@@ -78,6 +78,12 @@ module Rigor
78
78
  call_node.name == :loop && kernel_spelled_receiver?(call_node.receiver)
79
79
  end
80
80
 
81
+ # Issue #3340 — `:loop` for a call {.kernel_loop?} accepts, else nil: the class
82
+ # `StatementEvaluator#repeating_block_entry` gives a call its escape analysis leaves `:unknown` although it
83
+ # runs its block until the block breaks or raises. Its body enters with the captures it mutates in place
84
+ # widened, as a catalogued iterator's does, and a capture it rebinds keeps its call-site binding.
85
+ def loop_class(call_node) = kernel_loop?(call_node) ? :loop : nil
86
+
81
87
  # Issue #1107 — whether a `loop` call can complete normally although its declared return is `bot`.
82
88
  #
83
89
  # `Kernel#loop` is `() { () -> void } -> bot` in core RBS, yet it rescues a `StopIteration` its block
@@ -20,8 +20,8 @@ module Rigor
20
20
  #
21
21
  # - {RECURSION_GUARD} — `ExpressionTyper#infer_user_method_return` detected a `(receiver, method)` cycle
22
22
  # and returned `Dynamic[top]` (the de-facto recursion-depth budget, effective depth 1).
23
- # - {ANCESTOR_WALK_LIMIT} — `resolve_user_def_through_ancestors` hit the 100-node BFS cap and gave up
24
- # resolving the self-call.
23
+ # - {ANCESTOR_WALK_LIMIT} — a `Scope` ancestor walk hit its 100-node cap ({Scope::ANCESTOR_WALK_LIMIT}) and
24
+ # gave up rather than read an answer off a cut chain.
25
25
  # - {HKT_FUEL_EXHAUSTED} — `HktReducer` ran out of its reduction fuel budget and unwound to `app.bound`.
26
26
  # - {RECURSION_UNROLL_FUEL} — the constant-arg recursion unroll (ADR-55 slice 1) exhausted its per-entry
27
27
  # fuel and fell back to the plain `(receiver, method)` guard (in-cycle call → `Dynamic[top]`).
@@ -29,6 +29,7 @@ module Rigor
29
29
  # cap without converging and collapsed the summary to `untyped` (today's behaviour).
30
30
  # - {BLOCK_WRITEBACK_CAP} — the block / loop write-back fixpoint ({BodyFixpoint.converge}) collapsed a
31
31
  # local that had not converged to `Dynamic[top]`.
32
+ # - {CALLEE_CHAIN_CAP} — {CalleeMutationChain} walked past its node cap from one parameter and took it as mutated.
32
33
  #
33
34
  # Enabled only when `RIGOR_BUDGET_TRACE` is set (to any non-empty value) in the environment, or via
34
35
  # {enable!} in tests. When disabled, {hit} is a single boolean check and returns immediately, so normal
@@ -20,9 +20,9 @@ module Rigor
20
20
  # `iso8601` etc. The Ruby-side prelude (`lib/date.rb`) only contributes `Date#infinite?` and the
21
21
  # nested `Date::Infinity` class; the bulk of the surface is in C.
22
22
  #
23
- # Date / DateTime receivers are not lifted to a `Constant` carrier today (there is no Date literal
24
- # node — the closest is `Date.today` / `Date.parse(...)`, which produce `Nominal[Date]`). The
25
- # catalog wiring therefore mostly governs:
23
+ # There is no Date literal node, so a Date / DateTime receiver is a `Constant` carrier only when
24
+ # deterministic constructor folding built it (`Date.new`); `Date.today` / `Date.parse(...)` produce
25
+ # `Nominal[Date]`. The catalog wiring therefore mostly governs:
26
26
  #
27
27
  # 1. The Integer-typed reader surface (`#year`, `#month`, `#day`, `#wday`, `#hour`, `#min`, `#sec`) —
28
28
  # RBS-declared `Integer` is preserved through dispatch.
@@ -14,7 +14,7 @@ module Rigor
14
14
  # `safe_for_folding?(class_name, selector, kind:)` returns true when:
15
15
  # 1. The catalog has an entry for `(class_name, selector, kind)`,
16
16
  # 2. The entry's `purity` is one of `leaf` / `trivial` / `leaf_when_numeric`,
17
- # 3. The selector is NOT in the per-class mutation blocklist.
17
+ # 3. The selector is NOT in `NON_REPRODUCIBLE_SELECTORS` or the per-class mutation blocklist.
18
18
  #
19
19
  # Missing catalog files (e.g. in a bare gem install where data was opted out) degrade to `false` so
20
20
  # the dispatcher falls back to its hand-rolled allow lists.
@@ -105,8 +105,8 @@ module Rigor
105
105
  end
106
106
 
107
107
  def blocked?(class_name, selector)
108
- # Bang-suffixed selectors are mutating by Ruby convention (`upcase!`, `concat`, etc. are listed
109
- # explicitly below; this catches the rest). We bias toward false negatives: losing a fold
108
+ # Bang-suffixed selectors are mutating by Ruby convention (non-bang mutators such as `concat`
109
+ # are listed in each topic's blocklist; this catches the rest). We bias toward false negatives: losing a fold
110
110
  # opportunity is acceptable; folding a mutator is not.
111
111
  selector_str = selector.to_s
112
112
  return true if selector_str.end_with?("!")
@@ -11,9 +11,9 @@ module Rigor
11
11
  # surface, and the Ruby-side prelude `references/ruby/timev.rb` contributes the class-side
12
12
  # constructors (`Time.now`, `Time.at`, `Time.new`) through Primitive cexpr stubs.
13
13
  #
14
- # Time receivers are not lifted to a `Constant` carrier today (there is no `Time` literal node — the
15
- # closest is `Time.now` / `Time.new(...)`, which produce `Nominal[Time]`). The catalog wiring
16
- # therefore mostly governs:
14
+ # There is no `Time` literal node, so a Time receiver is a `Constant` carrier only when deterministic
15
+ # constructor folding built it (`Time.utc`); `Time.now` / `Time.new(...)` produce `Nominal[Time]`. The
16
+ # catalog wiring therefore mostly governs:
17
17
  #
18
18
  # 1. The size-projection-equivalent reader surface (`#year`, `#month`, `#hour`, `#sec`, `#wday`, …)
19
19
  # — RBS-declared `Integer` is preserved through dispatch.
@@ -0,0 +1,98 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "prism"
4
+
5
+ require_relative "../genuine_send"
6
+ require_relative "../method_dispatcher"
7
+ require_relative "project_singleton"
8
+ require_relative "user_method"
9
+
10
+ module Rigor
11
+ module Inference
12
+ module CallLadder
13
+ # The `literal_send` rung of the call ladder (ADR-116 WD12): `recv.send(:name, …)` with a literal name, typed as
14
+ # `recv.name(…)` would be. `ExpressionTyper` asks it in a call's ladder, behind the refined rung. Its own
15
+ # sequence is the `send_target` entry of `CallLadder::ENTRIES`: the target is a site of its own (the inner name
16
+ # and arguments, no block), asked of the dispatcher and then of the user-method and project-singleton rungs, and
17
+ # a receiver with a `send` of its own is answered ahead of them from that `send`'s body. {ExpressionTyper} is not
18
+ # required here: it requires this file, and `Scope` is loaded before either.
19
+ #
20
+ # {.try_call} is the rung, asked with the call's site and the walking typer, and the module's one entry. Every
21
+ # other function is private to the module.
22
+ #
23
+ # The module holds no state. It reads the scope as `typer.scope` and calls back one method of the typer,
24
+ # `type_of`, for the target's arguments. That is the typer's own entry, public for every caller, and
25
+ # `CallLadder::PORT` lists it as a public callback (`CallLadder::PUBLIC_CALLBACKS`), not a re-entry point. The
26
+ # module hands the typer on only to the two rungs it asks, and to `CallLadder::UserMethod.infer` for an own
27
+ # `send`.
28
+ module LiteralSend
29
+ module_function
30
+
31
+ # Issue #533 — `x.send(:selector, args)` with a LITERAL symbol is statically `x.selector(args)`:
32
+ # the private-boundary idiom (protobuf's `send(:get_file_descriptor)` at 84 sites) resolves through
33
+ # the same dispatch + project-inference tiers as the direct call would. `send` legitimately crosses
34
+ # visibility, so no public-only gate applies (`public_send` is treated identically — typing the
35
+ # success path of a call that would raise on a private method is ADR-5 optimism). Declines: a
36
+ # non-literal selector, a splat / forwarded tail (positional correspondence unknown), or a block at
37
+ # the call site (block forwarding is out of this slice). The sequence is `send_target` in {CallLadder::RUNGS}.
38
+ #
39
+ # Issue #3080 — `send` reads as its target only where the receiver's `send` is `Kernel#send`
40
+ # ({GenuineSend.type?}). A class with its own `send` (`def send(message, flags)`, `UDPSocket#send`, a project
41
+ # RBS `def send:`) is called like any other method. `__send__` and `public_send` are other methods and keep
42
+ # the reading.
43
+ LITERAL_SEND_SELECTORS = %i[send __send__ public_send].freeze
44
+ private_constant :LITERAL_SEND_SELECTORS
45
+
46
+ # The rung, asked with the call's site: its call node and receiver are the `send`'s.
47
+ def try_call(site, typer)
48
+ node = site.call_node
49
+ receiver = site.receiver
50
+ args = literal_send_arguments(node)
51
+ return nil if args.nil?
52
+ if node.name == :send && !GenuineSend.type?(receiver, typer.scope)
53
+ return own_send_type(node, receiver, args, typer)
54
+ end
55
+
56
+ rest = args[1..]
57
+ inner_name = args.first.unescaped.to_sym
58
+ inner_args = rest.map { |a| typer.type_of(a) }
59
+ target = MethodDispatcher::CallContext.build(
60
+ receiver: receiver, method_name: inner_name, args: inner_args,
61
+ block_type: nil, environment: typer.scope.environment, call_node: node, scope: typer.scope
62
+ )
63
+ MethodDispatcher.dispatch_site(target) || CallLadder::UserMethod.try_call(target, typer) ||
64
+ CallLadder::ProjectSingleton.try_call(target, typer)
65
+ end
66
+
67
+ # The arguments of a literal-selector `send` / `__send__` / `public_send` call with no block and no splat or
68
+ # forwarded tail, or nil.
69
+ def literal_send_arguments(node)
70
+ return nil unless LITERAL_SEND_SELECTORS.include?(node.name)
71
+ return nil unless node.block.nil?
72
+
73
+ args = node.arguments&.arguments
74
+ return nil unless args && args.first.is_a?(Prism::SymbolNode)
75
+ return nil if args.any? { |a| a.is_a?(Prism::SplatNode) || a.is_a?(Prism::ForwardingArgumentsNode) }
76
+
77
+ args
78
+ end
79
+
80
+ # Issue #3080 — the receiver's own `send`. A project `def send` comes before `Kernel#send` in every chain that
81
+ # reaches it, so where the only declaration Ruby reaches is `Kernel#send` (or there is none) the body answers
82
+ # the call, ahead of the `Kernel#send` declaration the ordinary dispatch would read off `Object`. Where an RBS
83
+ # `def send:` reaches the receiver from the class itself or from an ancestor (an overload included), that
84
+ # declaration is the contract (its `void`, its return type), so nil hands the call to the ordinary dispatch,
85
+ # as for any other declared method. Nil too
86
+ # where no body can be read: a union or class-object receiver.
87
+ def own_send_type(node, receiver, args, typer)
88
+ return nil unless CallLadder::UserMethod.user_inference_receiver?(receiver)
89
+ return nil unless GenuineSend.rbs_genuine?(receiver.class_name, :instance, typer.scope)
90
+
91
+ CallLadder::UserMethod.infer(receiver, node, args.map { |a| typer.type_of(a) }, node.name, nil, typer)
92
+ end
93
+
94
+ private_class_method :literal_send_arguments, :own_send_type
95
+ end
96
+ end
97
+ end
98
+ end