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.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/docs/handbook/01-getting-started.md +1 -1
- data/docs/handbook/04-tuples-and-shapes.md +6 -1
- data/docs/handbook/12-lightweight-hkt.md +1 -1
- data/docs/handbook/appendix-typescript.md +28 -17
- data/docs/manual/02-cli-reference.md +10 -0
- data/docs/manual/03-configuration.md +1 -1
- data/docs/manual/04-diagnostics.md +1 -1
- data/docs/manual/10-mcp-server.md +122 -10
- data/docs/manual/plugins/rigor-activerecord.md +7 -0
- data/lib/rigor/analysis/check_rules/always_raises.rb +95 -0
- data/lib/rigor/analysis/check_rules/always_truthy_condition_collector.rb +32 -2
- data/lib/rigor/analysis/check_rules/argument_type.rb +802 -0
- data/lib/rigor/analysis/check_rules/call_facts.rb +2 -2
- data/lib/rigor/analysis/check_rules/dead_assignment_collector.rb +30 -1
- data/lib/rigor/analysis/check_rules/declaration_sourced_guard.rb +4 -5
- data/lib/rigor/analysis/check_rules/duplicate_hash_key_collector.rb +34 -0
- data/lib/rigor/analysis/check_rules/ivar_write_collector.rb +131 -4
- data/lib/rigor/analysis/check_rules/nil_receiver.rb +195 -0
- data/lib/rigor/analysis/check_rules/override_param_narrowed.rb +111 -0
- data/lib/rigor/analysis/check_rules/override_return_widened.rb +88 -0
- data/lib/rigor/analysis/check_rules/override_support.rb +246 -0
- data/lib/rigor/analysis/check_rules/override_visibility.rb +135 -0
- data/lib/rigor/analysis/check_rules/published_constant_guard.rb +75 -31
- data/lib/rigor/analysis/check_rules/raise_non_exception.rb +198 -0
- data/lib/rigor/analysis/check_rules/receiver_predicates.rb +576 -0
- data/lib/rigor/analysis/check_rules/return_in_ensure_collector.rb +52 -4
- data/lib/rigor/analysis/check_rules/return_type.rb +225 -0
- data/lib/rigor/analysis/check_rules/rigor_testing.rb +119 -0
- data/lib/rigor/analysis/check_rules/rule_ids.rb +7 -7
- data/lib/rigor/analysis/check_rules/rule_walk.rb +4 -3
- data/lib/rigor/analysis/check_rules/self_closedness_scanner.rb +2 -0
- data/lib/rigor/analysis/check_rules/self_undefined_method.rb +165 -0
- data/lib/rigor/analysis/check_rules/shadowed_rescue_collector.rb +34 -0
- data/lib/rigor/analysis/check_rules/source_arity.rb +2 -2
- data/lib/rigor/analysis/check_rules/special_global_write.rb +256 -0
- data/lib/rigor/analysis/check_rules/suppression.rb +275 -0
- data/lib/rigor/analysis/check_rules/undefined_method.rb +882 -0
- data/lib/rigor/analysis/check_rules/unreachable_branch.rb +97 -0
- data/lib/rigor/analysis/check_rules/unreachable_clause_collector.rb +42 -0
- data/lib/rigor/analysis/check_rules/unresolved_toplevel.rb +140 -0
- data/lib/rigor/analysis/check_rules/visibility_mismatch.rb +252 -0
- data/lib/rigor/analysis/check_rules/void_value_use_collector.rb +27 -0
- data/lib/rigor/analysis/check_rules/wrong_arity.rb +303 -0
- data/lib/rigor/analysis/check_rules.rb +66 -4931
- data/lib/rigor/analysis/dependency_recorder.rb +1 -1
- data/lib/rigor/analysis/dependency_source_inference/builder.rb +2 -4
- data/lib/rigor/analysis/dependency_source_inference/gem_resolver.rb +1 -2
- data/lib/rigor/analysis/dependency_source_inference/walker.rb +15 -15
- data/lib/rigor/analysis/incremental_session.rb +4 -4
- data/lib/rigor/analysis/path_expansion.rb +1 -1
- data/lib/rigor/analysis/plugin_fact_fingerprint.rb +5 -5
- data/lib/rigor/analysis/reachability/graph.rb +2 -3
- data/lib/rigor/analysis/reachability/plugin_roots.rb +2 -2
- data/lib/rigor/analysis/reachability/scan.rb +2 -2
- data/lib/rigor/analysis/rule_catalog.rb +2 -1
- data/lib/rigor/analysis/run_cache_key.rb +9 -8
- data/lib/rigor/analysis/runner/buffer_pool_dispatcher.rb +2 -2
- data/lib/rigor/analysis/runner/dependency_rows.rb +206 -0
- data/lib/rigor/analysis/runner/diagnostic_aggregator.rb +24 -22
- data/lib/rigor/analysis/runner/effect_cache_entries.rb +69 -0
- data/lib/rigor/analysis/runner/pool_coordinator.rb +6 -8
- data/lib/rigor/analysis/runner/project_pre_passes.rb +3 -5
- data/lib/rigor/analysis/runner/scope_seed.rb +144 -0
- data/lib/rigor/analysis/runner.rb +49 -296
- data/lib/rigor/analysis/template_unit_collector.rb +1 -1
- data/lib/rigor/analysis/template_units.rb +10 -10
- data/lib/rigor/analysis/worker_session.rb +7 -7
- data/lib/rigor/bleeding_edge.rb +3 -2
- data/lib/rigor/builtins/hkt_builtins.rb +17 -17
- data/lib/rigor/builtins/imported_refinements.rb +8 -16
- data/lib/rigor/builtins/regex_refinement.rb +3 -3
- data/lib/rigor/builtins/static_return_refinements.rb +143 -19
- data/lib/rigor/cache/incremental_snapshot.rb +21 -8
- data/lib/rigor/cache/rbs_descriptor.rb +18 -1
- data/lib/rigor/cli/coverage_renderer.rb +15 -1
- data/lib/rigor/cli/coverage_report.rb +19 -1
- data/lib/rigor/cli/diagnostic_formats.rb +3 -2
- data/lib/rigor/cli/docs_command.rb +5 -5
- data/lib/rigor/cli/effects_command.rb +7 -6
- data/lib/rigor/cli/fused_protection_report.rb +7 -7
- data/lib/rigor/cli/lsp_command.rb +1 -1
- data/lib/rigor/cli/mcp_command.rb +5 -2
- data/lib/rigor/cli/options.rb +4 -0
- data/lib/rigor/cli/plugins_command.rb +1 -1
- data/lib/rigor/cli/sig_gen_command.rb +1 -1
- data/lib/rigor/cli/skill_command.rb +5 -4
- data/lib/rigor/cli/triage_renderer.rb +3 -2
- data/lib/rigor/cli/unused_command.rb +4 -4
- data/lib/rigor/cli.rb +14 -0
- data/lib/rigor/configuration/coercion.rb +418 -0
- data/lib/rigor/configuration/defaults.rb +248 -0
- data/lib/rigor/configuration/dependencies.rb +1 -1
- data/lib/rigor/configuration/loader.rb +354 -0
- data/lib/rigor/configuration/severity_profile.rb +4 -4
- data/lib/rigor/configuration.rb +51 -860
- data/lib/rigor/effects/attribution.rb +1 -1
- data/lib/rigor/effects/effect_table.rb +1 -1
- data/lib/rigor/effects/identity.rb +3 -3
- data/lib/rigor/effects/local_ownership.rb +2 -2
- data/lib/rigor/effects/snapshot.rb +1 -1
- data/lib/rigor/effects/summary.rb +5 -4
- data/lib/rigor/environment/member_consistency.rb +10 -0
- data/lib/rigor/environment/rbs_loader.rb +19 -22
- data/lib/rigor/environment/reflection.rb +1 -1
- data/lib/rigor/environment/unreadable_signature.rb +21 -0
- data/lib/rigor/environment.rb +8 -8
- data/lib/rigor/flow_contribution/merger.rb +1 -0
- data/lib/rigor/hashing/xxh3.rb +1 -1
- data/lib/rigor/inference/acceptance.rb +23 -2
- data/lib/rigor/inference/alias_mutation_floor/site_collector.rb +5 -0
- data/lib/rigor/inference/alias_mutation_floor.rb +0 -5
- data/lib/rigor/inference/anonymous_meta_class.rb +2 -2
- data/lib/rigor/inference/block_call_timing.rb +6 -0
- data/lib/rigor/inference/budget_trace.rb +3 -2
- data/lib/rigor/inference/builtins/date_catalog.rb +3 -3
- data/lib/rigor/inference/builtins/method_catalog.rb +3 -3
- data/lib/rigor/inference/builtins/time_catalog.rb +3 -3
- data/lib/rigor/inference/call_ladder/literal_send.rb +98 -0
- data/lib/rigor/inference/call_ladder/overriding_def.rb +98 -0
- data/lib/rigor/inference/call_ladder/project_singleton.rb +362 -0
- data/lib/rigor/inference/call_ladder/refined.rb +212 -0
- data/lib/rigor/inference/call_ladder/top_level_def.rb +222 -0
- data/lib/rigor/inference/call_ladder/user_method.rb +247 -0
- data/lib/rigor/inference/call_ladder.rb +219 -0
- data/lib/rigor/inference/callee_write_census.rb +2 -2
- data/lib/rigor/inference/captured_locals.rb +2 -2
- data/lib/rigor/inference/clause_widening.rb +63 -1
- data/lib/rigor/inference/declaration_walk/context.rb +12 -12
- data/lib/rigor/inference/declaration_walk/rules.rb +750 -0
- data/lib/rigor/inference/declaration_walk/traversal.rb +9 -8
- data/lib/rigor/inference/declaration_walk.rb +4 -3
- data/lib/rigor/inference/def_node_resolver.rb +2 -2
- data/lib/rigor/inference/def_return_typer.rb +14 -6
- data/lib/rigor/inference/deferred_mutation.rb +120 -0
- data/lib/rigor/inference/define_method_block_self.rb +1 -1
- data/lib/rigor/inference/definer_resolution.rb +4 -4
- data/lib/rigor/inference/error_info.rb +8 -8
- data/lib/rigor/inference/expression_typer/composites.rb +348 -0
- data/lib/rigor/inference/expression_typer/per_element_assemblers.rb +233 -0
- data/lib/rigor/inference/expression_typer/writes.rb +218 -0
- data/lib/rigor/inference/expression_typer.rb +275 -1825
- data/lib/rigor/inference/external_ancestor_resolution.rb +2 -2
- data/lib/rigor/inference/fallback.rb +1 -0
- data/lib/rigor/inference/for_yield_slots.rb +126 -0
- data/lib/rigor/inference/genuine_send.rb +92 -0
- data/lib/rigor/inference/global_write_census.rb +2 -2
- data/lib/rigor/inference/hkt_body.rb +2 -0
- data/lib/rigor/inference/in_effect_refinements/walk.rb +2 -2
- data/lib/rigor/inference/index_write_widening.rb +4 -4
- data/lib/rigor/inference/indexed_narrowing.rb +1 -1
- data/lib/rigor/inference/intervening_ivar_reset.rb +46 -9
- data/lib/rigor/inference/ivar_writer_census.rb +1 -1
- data/lib/rigor/inference/loop_store_sites.rb +239 -0
- data/lib/rigor/inference/macro_block_self_type.rb +4 -3
- data/lib/rigor/inference/method_dispatcher/block_folding.rb +3 -2
- data/lib/rigor/inference/method_dispatcher/call_context.rb +84 -14
- data/lib/rigor/inference/method_dispatcher/composite_receiver.rb +144 -0
- data/lib/rigor/inference/method_dispatcher/constant_folding.rb +7 -5
- data/lib/rigor/inference/method_dispatcher/declared_constructor.rb +1 -1
- data/lib/rigor/inference/method_dispatcher/dependency_source.rb +90 -0
- data/lib/rigor/inference/method_dispatcher/discovered_method.rb +78 -0
- data/lib/rigor/inference/method_dispatcher/file_folding.rb +2 -2
- data/lib/rigor/inference/method_dispatcher/hkt_builtin_return.rb +40 -0
- data/lib/rigor/inference/method_dispatcher/iterator_dispatch.rb +1 -6
- data/lib/rigor/inference/method_dispatcher/literal_string_folding.rb +4 -2
- data/lib/rigor/inference/method_dispatcher/match_data_folding.rb +1 -1
- data/lib/rigor/inference/method_dispatcher/meta_introspection.rb +506 -0
- data/lib/rigor/inference/method_dispatcher/overload_selector.rb +2 -0
- data/lib/rigor/inference/method_dispatcher/plugin_contribution.rb +134 -0
- data/lib/rigor/inference/method_dispatcher/project_patched.rb +134 -0
- data/lib/rigor/inference/method_dispatcher/rbs_dispatch.rb +125 -43
- data/lib/rigor/inference/method_dispatcher/reduce_folding.rb +3 -4
- data/lib/rigor/inference/method_dispatcher/regexp_folding.rb +1 -1
- data/lib/rigor/inference/method_dispatcher/set_folding.rb +1 -1
- data/lib/rigor/inference/method_dispatcher/shape_dispatch.rb +19 -6
- data/lib/rigor/inference/method_dispatcher/singleton_folding.rb +3 -3
- data/lib/rigor/inference/method_dispatcher/singleton_mixin_dispatch.rb +7 -4
- data/lib/rigor/inference/method_dispatcher/static_refinement.rb +106 -0
- data/lib/rigor/inference/method_dispatcher/synthesized_stub.rb +41 -0
- data/lib/rigor/inference/method_dispatcher/synthetic_method_dispatch.rb +133 -0
- data/lib/rigor/inference/method_dispatcher/universal_object_dispatch.rb +2 -1
- data/lib/rigor/inference/method_dispatcher/user_class_fallback.rb +216 -0
- data/lib/rigor/inference/method_dispatcher.rb +175 -1361
- data/lib/rigor/inference/method_parameter_binder.rb +18 -18
- data/lib/rigor/inference/module_function_state.rb +5 -4
- data/lib/rigor/inference/mutation_widening.rb +20 -7
- data/lib/rigor/inference/narrowing/case_literals.rb +58 -0
- data/lib/rigor/inference/narrowing/class_dispatch.rb +302 -0
- data/lib/rigor/inference/narrowing/complements.rb +322 -0
- data/lib/rigor/inference/narrowing/presence_predicates.rb +205 -0
- data/lib/rigor/inference/narrowing/regex_match.rb +499 -0
- data/lib/rigor/inference/narrowing.rb +86 -1269
- data/lib/rigor/inference/object_mixins.rb +2 -2
- data/lib/rigor/inference/opaque_mutation.rb +214 -0
- data/lib/rigor/inference/optimistic_origin.rb +52 -14
- data/lib/rigor/inference/parameter_inference_collector.rb +1 -1
- data/lib/rigor/inference/pre_eval_constants.rb +11 -9
- data/lib/rigor/inference/precision_scanner.rb +27 -2
- data/lib/rigor/inference/project_patched_methods.rb +3 -3
- data/lib/rigor/inference/range_constant.rb +3 -3
- data/lib/rigor/inference/rbs_type_translator.rb +2 -2
- data/lib/rigor/inference/refine_self.rb +8 -7
- data/lib/rigor/inference/refined_dispatch.rb +2 -2
- data/lib/rigor/inference/return_barrier.rb +24 -9
- data/lib/rigor/inference/scope_indexer/alias_def_nodes.rb +311 -0
- data/lib/rigor/inference/scope_indexer/census_scope.rb +47 -0
- data/lib/rigor/inference/scope_indexer/certainty.rb +2 -2
- data/lib/rigor/inference/scope_indexer/class_cvar_census.rb +282 -0
- data/lib/rigor/inference/scope_indexer/class_cvars_collector.rb +12 -5
- data/lib/rigor/inference/scope_indexer/class_declarations.rb +228 -0
- data/lib/rigor/inference/scope_indexer/class_ivar_index.rb +2028 -0
- data/lib/rigor/inference/scope_indexer/constant_ivar_value.rb +4 -3
- data/lib/rigor/inference/scope_indexer/constant_tables.rb +844 -0
- data/lib/rigor/inference/scope_indexer/cvar_hierarchy.rb +159 -0
- data/lib/rigor/inference/scope_indexer/declaration_artifacts.rb +219 -0
- data/lib/rigor/inference/scope_indexer/declaration_signature.rb +212 -0
- data/lib/rigor/inference/scope_indexer/def_nestings_collector.rb +2 -2
- data/lib/rigor/inference/scope_indexer/factory_call_resolver.rb +53 -0
- data/lib/rigor/inference/scope_indexer/literal_receiver_mutations.rb +266 -0
- data/lib/rigor/inference/scope_indexer/member_layouts_collector.rb +8 -7
- data/lib/rigor/inference/scope_indexer/mixin_accumulator.rb +1 -1
- data/lib/rigor/inference/scope_indexer/mixin_effects.rb +470 -0
- data/lib/rigor/inference/scope_indexer/mixin_tables.rb +388 -0
- data/lib/rigor/inference/scope_indexer/mutated_carrier_widening.rb +163 -0
- data/lib/rigor/inference/scope_indexer/mutated_element_census.rb +211 -0
- data/lib/rigor/inference/scope_indexer/node_propagation.rb +520 -0
- data/lib/rigor/inference/scope_indexer/program_globals.rb +154 -0
- data/lib/rigor/inference/scope_indexer/published_constant_cvars.rb +146 -0
- data/lib/rigor/inference/scope_indexer/published_constant_ivars.rb +181 -0
- data/lib/rigor/inference/scope_indexer/shared_walk_tables.rb +823 -0
- data/lib/rigor/inference/scope_indexer/singleton_class_sources.rb +85 -0
- data/lib/rigor/inference/scope_indexer/superclasses_collector.rb +5 -5
- data/lib/rigor/inference/scope_indexer.rb +2657 -9558
- data/lib/rigor/inference/self_call_ivar_writes.rb +22 -3
- data/lib/rigor/inference/set_mutation.rb +2 -2
- data/lib/rigor/inference/singleton_hook_definers.rb +185 -0
- data/lib/rigor/inference/statement_evaluator/def_arguments_and_assertions.rb +365 -0
- data/lib/rigor/inference/statement_evaluator/pattern_bindings.rb +581 -0
- data/lib/rigor/inference/statement_evaluator.rb +201 -1008
- data/lib/rigor/inference/synthetic_method_scanner.rb +0 -3
- data/lib/rigor/language_server/completion_provider.rb +8 -8
- data/lib/rigor/language_server/diagnostic_publisher.rb +6 -7
- data/lib/rigor/language_server/document_symbol_provider.rb +4 -6
- data/lib/rigor/language_server/folding_range_provider.rb +3 -3
- data/lib/rigor/language_server/hover_provider.rb +2 -2
- data/lib/rigor/language_server/loop.rb +2 -2
- data/lib/rigor/language_server/server.rb +3 -2
- data/lib/rigor/language_server/signature_help_provider.rb +7 -9
- data/lib/rigor/lens/document.rb +10 -1
- data/lib/rigor/lens/file_reader.rb +2 -1
- data/lib/rigor/mcp/loop.rb +48 -6
- data/lib/rigor/mcp/server.rb +248 -23
- data/lib/rigor/mcp/skill_catalog.rb +157 -0
- data/lib/rigor/plugin/base.rb +22 -4
- data/lib/rigor/plugin/effect_attribution.rb +1 -1
- data/lib/rigor/plugin/inflector.rb +2 -2
- data/lib/rigor/plugin/io_boundary.rb +1 -1
- data/lib/rigor/plugin/loader.rb +4 -4
- data/lib/rigor/plugin/macro/heredoc_template.rb +4 -3
- data/lib/rigor/plugin/optimistic_return.rb +20 -0
- data/lib/rigor/plugin/registry.rb +2 -2
- data/lib/rigor/plugin/template_unit.rb +4 -2
- data/lib/rigor/plugin/trust_policy.rb +2 -1
- data/lib/rigor/plugin.rb +1 -1
- data/lib/rigor/protection/mutator.rb +8 -9
- data/lib/rigor/rbs_extended/reporter.rb +2 -2
- data/lib/rigor/rbs_extended.rb +2 -2
- data/lib/rigor/reflection/constant_ancestors.rb +1 -1
- data/lib/rigor/reflection/project_method.rb +2 -2
- data/lib/rigor/reflection.rb +4 -4
- data/lib/rigor/scope/discovery_index.rb +15 -10
- data/lib/rigor/scope/resolution_chain.rb +29 -6
- data/lib/rigor/scope.rb +89 -32
- data/lib/rigor/sig_gen/generator.rb +5 -4
- data/lib/rigor/sig_gen/renderer.rb +3 -3
- data/lib/rigor/sig_gen/writer.rb +8 -6
- data/lib/rigor/source/parameter_envelope.rb +1 -1
- data/lib/rigor/triage/catalogue.rb +4 -4
- data/lib/rigor/type/combinator.rb +2 -2
- data/lib/rigor/type/data_instance.rb +2 -2
- data/lib/rigor/type/struct_instance.rb +3 -3
- data/lib/rigor/type_node/generic.rb +2 -1
- data/lib/rigor/type_of_memo.rb +2 -1
- data/lib/rigor/typing_state.rb +3 -2
- data/lib/rigor/version.rb +1 -1
- data/plugins/rigor-actioncable/lib/rigor/plugin/actioncable/analyzer.rb +2 -2
- data/plugins/rigor-actioncable/lib/rigor/plugin/actioncable/channel_discoverer.rb +1 -1
- data/plugins/rigor-actionmailer/lib/rigor/plugin/actionmailer/mailer_discoverer.rb +4 -4
- data/plugins/rigor-actionmailer/lib/rigor/plugin/actionmailer.rb +1 -1
- data/plugins/rigor-actionpack/lib/rigor/plugin/actionpack/controller_discoverer.rb +4 -3
- data/plugins/rigor-actionpack/lib/rigor/plugin/actionpack/effects.rb +7 -5
- data/plugins/rigor-actionpack/lib/rigor/plugin/actionpack/erb_compiler.rb +4 -2
- data/plugins/rigor-actionpack/lib/rigor/plugin/actionpack/render_locals.rb +1 -1
- data/plugins/rigor-actionpack/lib/rigor/plugin/actionpack/view_assigns.rb +3 -2
- data/plugins/rigor-actionpack/lib/rigor/plugin/actionpack.rb +7 -7
- data/plugins/rigor-activejob/lib/rigor/plugin/activejob/job_discoverer.rb +1 -1
- data/plugins/rigor-activejob/lib/rigor/plugin/activejob.rb +2 -2
- data/plugins/rigor-activerecord/lib/rigor/plugin/activerecord/model_discoverer.rb +9 -8
- data/plugins/rigor-activerecord/lib/rigor/plugin/activerecord/model_index.rb +3 -2
- data/plugins/rigor-activerecord/lib/rigor/plugin/activerecord/schema_parser.rb +15 -7
- data/plugins/rigor-activerecord/lib/rigor/plugin/activerecord/schema_table.rb +10 -3
- data/plugins/rigor-activerecord/lib/rigor/plugin/activerecord/structure_sql_parser.rb +12 -1
- data/plugins/rigor-activerecord/lib/rigor/plugin/activerecord.rb +20 -5
- data/plugins/rigor-activestorage/lib/rigor/plugin/activestorage/attachment_discoverer.rb +1 -1
- data/plugins/rigor-activestorage/lib/rigor/plugin/activestorage.rb +3 -2
- data/plugins/rigor-activesupport-core-ext/lib/rigor/plugin/activesupport_core_ext/effects.rb +1 -1
- data/plugins/rigor-activesupport-core-ext/lib/rigor/plugin/activesupport_core_ext.rb +8 -7
- data/plugins/rigor-dry-schema/lib/rigor/plugin/dry_schema.rb +1 -1
- data/plugins/rigor-dry-types/lib/rigor/plugin/dry_types/alias_scanner.rb +1 -1
- data/plugins/rigor-dry-types/lib/rigor/plugin/dry_types.rb +6 -7
- data/plugins/rigor-factorybot/lib/rigor/plugin/factorybot/factory_discoverer.rb +3 -2
- data/plugins/rigor-graphql/lib/rigor/plugin/graphql/type_scanner.rb +4 -3
- data/plugins/rigor-hanami/lib/rigor/plugin/hanami.rb +4 -2
- data/plugins/rigor-minitest/lib/rigor/plugin/minitest.rb +1 -1
- data/plugins/rigor-pundit/lib/rigor/plugin/pundit.rb +1 -1
- data/plugins/rigor-rails-i18n/lib/rigor/plugin/rails_i18n/analyzer.rb +5 -3
- data/plugins/rigor-rails-i18n/lib/rigor/plugin/rails_i18n.rb +1 -1
- data/plugins/rigor-rails-routes/lib/rigor/plugin/rails_routes/devise_routes.rb +4 -5
- data/plugins/rigor-rails-routes/lib/rigor/plugin/rails_routes/doorkeeper_routes.rb +2 -2
- data/plugins/rigor-rails-routes/lib/rigor/plugin/rails_routes/helper_discoverer.rb +5 -4
- data/plugins/rigor-rails-routes/lib/rigor/plugin/rails_routes/helper_table.rb +3 -2
- data/plugins/rigor-rails-routes/lib/rigor/plugin/rails_routes/routes_parser.rb +30 -31
- data/plugins/rigor-rails-routes/lib/rigor/plugin/rails_routes.rb +13 -15
- data/plugins/rigor-rbnacl/lib/rigor/plugin/rbnacl.rb +1 -1
- data/plugins/rigor-rspec/lib/rigor/plugin/rspec/let_scope_index.rb +4 -3
- data/plugins/rigor-rspec/lib/rigor/plugin/rspec/matcher_analyzer.rb +16 -13
- data/plugins/rigor-rspec/lib/rigor/plugin/rspec/scope_walker.rb +3 -2
- data/plugins/rigor-shoulda-matchers/lib/rigor/plugin/shoulda_matchers/analyzer.rb +6 -6
- data/plugins/rigor-sidekiq/lib/rigor/plugin/sidekiq/analyzer.rb +3 -3
- data/plugins/rigor-sorbet/lib/rigor/plugin/sorbet/assertion_recognizer.rb +2 -2
- data/plugins/rigor-sorbet/lib/rigor/plugin/sorbet/catalog.rb +3 -2
- data/plugins/rigor-sorbet/lib/rigor/plugin/sorbet/catalog_walker.rb +6 -5
- data/plugins/rigor-sorbet/lib/rigor/plugin/sorbet/sig_parser.rb +2 -2
- data/plugins/rigor-sorbet/lib/rigor/plugin/sorbet/sigil_detector.rb +4 -5
- data/plugins/rigor-sorbet/lib/rigor/plugin/sorbet/type_translator.rb +1 -1
- data/plugins/rigor-sorbet/lib/rigor/plugin/sorbet.rb +3 -4
- data/sig/rigor/analysis/check_rules/suppression.rbs +9 -0
- data/sig/rigor/analysis/dependency_recorder.rbs +9 -0
- data/sig/rigor/inference.rbs +275 -11
- data/sig/rigor/plugin/base.rbs +14 -5
- data/sig/rigor/plugin/optimistic_return.rbs +16 -0
- data/sig/rigor/scope.rbs +7 -1
- data/sig/rigor/source.rbs +4 -0
- data/skills/rigor-mcp-setup/SKILL.md +20 -6
- data/skills/rigor-plugin-review/SKILL.md +3 -3
- data/skills/rigor-type-oracle/references/01-oracle-commands.md +1 -1
- metadata +90 -3
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "../type"
|
|
4
|
+
require_relative "../source/node_walker"
|
|
5
|
+
require_relative "captured_locals"
|
|
6
|
+
require_relative "jump_targets"
|
|
7
|
+
require_relative "narrowing"
|
|
8
|
+
|
|
9
|
+
module Rigor
|
|
10
|
+
module Inference
|
|
11
|
+
# Issue #3337, ADR-56 WD2.14 — the scope a `while` / `until` loop's content join types each store's arguments
|
|
12
|
+
# in. The join's own scope, `post_loop`, reads a local the loop rebinds at its continuation binding: the join of
|
|
13
|
+
# the pre-loop binding and the body's EXIT binding. A local first assigned in the body carries the `nil` its
|
|
14
|
+
# zero-iteration seed gives it, though the store never ran on that path (`s = f; out << s` read
|
|
15
|
+
# `Array[String?]` and drew `call.possible-nil-receiver` on correct code), and a local rebound after the store
|
|
16
|
+
# carries a value the store never held (`out << s; s = nil` read `Array[nil]`).
|
|
17
|
+
#
|
|
18
|
+
# `StatementEvaluator#evaluate` leaves the scope it enters each store site with in a {Pass}'s table while the
|
|
19
|
+
# loop's rebind fixpoint runs, and {.argument_scopes} overlays each rebound local's binding there on
|
|
20
|
+
# `post_loop`. No body pass is added.
|
|
21
|
+
#
|
|
22
|
+
# The binding at the store REPLACES the continuation binding only where every execution of the store is known
|
|
23
|
+
# to follow an assignment of the local in the same iteration ({Sites#assigned}). Everywhere else it is JOINED
|
|
24
|
+
# with the continuation binding, so the answer holds every class the continuation binding holds.
|
|
25
|
+
module LoopStoreSites
|
|
26
|
+
# A body's stores. `stores` is `{ name => [site, ...] }` for every content mutation whose receiver is a local,
|
|
27
|
+
# which the join reads. `assigned` is identity-keyed `{ site => [name, ...] }` for the sites the overlay
|
|
28
|
+
# may type: the locals each one is reached with freshly assigned ({LoopStoreSites.assigned_before}). A site
|
|
29
|
+
# that is not a key keeps the join's own scope ({LoopStoreSites.overlaid?}).
|
|
30
|
+
Sites = Struct.new(:stores, :assigned)
|
|
31
|
+
|
|
32
|
+
NONE = Sites.new({}.freeze, {}.compare_by_identity.freeze).freeze
|
|
33
|
+
EMPTY = {}.freeze
|
|
34
|
+
NO_NAMES = [].freeze
|
|
35
|
+
private_constant :EMPTY, :NO_NAMES
|
|
36
|
+
|
|
37
|
+
# What the rebind fixpoint's passes leave: `scopes`, the identity-keyed table of each overlaid store site's
|
|
38
|
+
# scope, and `entry`, a copy of the assumption the last pass ran from.
|
|
39
|
+
#
|
|
40
|
+
# A loop nested in another loop's body shares the outer table: every site the inner loop overlays is one the
|
|
41
|
+
# outer loop overlays too, and the outer join reads what the inner loop leaves there ({.argument_scopes}).
|
|
42
|
+
class Pass
|
|
43
|
+
attr_reader :scopes, :entry
|
|
44
|
+
|
|
45
|
+
# `shared` is an enclosing loop's table, or nil.
|
|
46
|
+
def initialize(sites, shared)
|
|
47
|
+
@sites = sites.assigned
|
|
48
|
+
@scopes = shared || {}.compare_by_identity
|
|
49
|
+
@entry = nil
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
# Starts a fixpoint pass from `bindings`: a site the pass does not reach has no scope afterwards.
|
|
53
|
+
def start(bindings)
|
|
54
|
+
@entry = bindings.dup
|
|
55
|
+
@sites.each_key { |site| @scopes[site] = nil }
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
# The constructs {JumpTargets.boundary?} names that a store may still sit under: a nested loop of the seam's
|
|
60
|
+
# own kind, whose rebind fixpoint settles the locals it rebinds. Every other one keeps a store on the join's
|
|
61
|
+
# own scope. A block or lambda body runs at another time than the statement walk reaches it, or more often
|
|
62
|
+
# (`saved = proc { out << s }` stores what `s` holds when it is called). A `for` body has no rebind fixpoint.
|
|
63
|
+
# A method, class or module body has locals of its own, and a same-named one there is not the loop's (`s =
|
|
64
|
+
# "a"; class Foo; s = 5; o = []; o << s; end`).
|
|
65
|
+
SETTLING_LOOPS = [Prism::WhileNode, Prism::UntilNode].freeze
|
|
66
|
+
# A rescue or `ensure` clause runs from any point of the body it guards, and the check path records such a
|
|
67
|
+
# clause under a widened entry the display path does not use (issue #1231): a store typed there would answer
|
|
68
|
+
# differently per path.
|
|
69
|
+
CLAUSE_NODES = [Prism::RescueNode, Prism::EnsureNode, Prism::RescueModifierNode].freeze
|
|
70
|
+
private_constant :SETTLING_LOOPS, :CLAUSE_NODES
|
|
71
|
+
|
|
72
|
+
module_function
|
|
73
|
+
|
|
74
|
+
# The {Sites} of a loop body: the block answers `[name, site]` for a node that is a store and a nil name for
|
|
75
|
+
# any other.
|
|
76
|
+
def scan(statements)
|
|
77
|
+
return NONE if statements.nil?
|
|
78
|
+
|
|
79
|
+
stores = nil
|
|
80
|
+
assigned = nil
|
|
81
|
+
Source::NodeWalker.each_with_ancestors(statements) do |descendant, ancestors|
|
|
82
|
+
name, site = yield(descendant)
|
|
83
|
+
next if name.nil?
|
|
84
|
+
|
|
85
|
+
((stores ||= {})[name] ||= []) << site
|
|
86
|
+
(assigned ||= {}.compare_by_identity)[site] = assigned_before(site, ancestors) if overlaid?(ancestors)
|
|
87
|
+
end
|
|
88
|
+
stores.nil? ? NONE : Sites.new(stores, assigned || NONE.assigned)
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
# True when a store under `ancestors` (the loop body first) runs when the statement walk reaches it, once per
|
|
92
|
+
# iteration of the loops it is nested in, and from the scope that walk holds on every path.
|
|
93
|
+
def overlaid?(ancestors)
|
|
94
|
+
ancestors.none? do |ancestor|
|
|
95
|
+
CLAUSE_NODES.include?(ancestor.class) ||
|
|
96
|
+
(JumpTargets.boundary?(ancestor) && !SETTLING_LOOPS.include?(ancestor.class))
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
# True when a store under `ancestors` is in a `begin` with a rescue or `ensure` clause. Its body runs again
|
|
101
|
+
# on `retry`, after its own later statements, so no assignment is one the store is known to follow.
|
|
102
|
+
def guarded?(ancestors)
|
|
103
|
+
ancestors.any? do |ancestor|
|
|
104
|
+
ancestor.is_a?(Prism::BeginNode) && !(ancestor.rescue_clause.nil? && ancestor.ensure_clause.nil?)
|
|
105
|
+
end
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
# The locals every execution of `site` follows an assignment of, in the same iteration: those a plain
|
|
109
|
+
# `name = value` statement assigns earlier in a statement list on the way down to the site. Such a statement
|
|
110
|
+
# always runs before the later statements of its list, and nothing on the way is a body that runs later or again
|
|
111
|
+
# ({.overlaid?}), so the local holds at the store what this iteration gave it, never what an earlier
|
|
112
|
+
# iteration left. A conditional write, a multiple assignment and a write nested in an expression do not count.
|
|
113
|
+
def assigned_before(site, ancestors)
|
|
114
|
+
return NO_NAMES if guarded?(ancestors)
|
|
115
|
+
|
|
116
|
+
names = nil
|
|
117
|
+
ancestors.each_with_index do |ancestor, depth|
|
|
118
|
+
next unless ancestor.is_a?(Prism::StatementsNode)
|
|
119
|
+
|
|
120
|
+
on_path = ancestors[depth + 1] || site
|
|
121
|
+
ancestor.body.each do |statement|
|
|
122
|
+
break if statement.equal?(on_path)
|
|
123
|
+
|
|
124
|
+
(names ||= []) << statement.name if statement.is_a?(Prism::LocalVariableWriteNode)
|
|
125
|
+
end
|
|
126
|
+
end
|
|
127
|
+
names || NO_NAMES
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
# `{ site => scope }`: for each overlaid store the fixpoint's last pass reached, `post_loop` with every local
|
|
131
|
+
# the loop rebinds (`converged`'s names) at {.binding}. A store that pass did not reach as a statement — dead
|
|
132
|
+
# under its assumption, or nested in an expression the statement walk hands to the expression typer — has no
|
|
133
|
+
# entry, and the join keeps `post_loop` for it. `pass` is nil for a body with no store.
|
|
134
|
+
#
|
|
135
|
+
# Each scope is also left in the pass's table, so an enclosing loop's join reads this loop's locals as settled
|
|
136
|
+
# here, not at the raw pass binding.
|
|
137
|
+
def argument_scopes(sites, pass, post_loop, converged)
|
|
138
|
+
return EMPTY if pass.nil?
|
|
139
|
+
|
|
140
|
+
capped = pass.entry != converged
|
|
141
|
+
table = pass.scopes
|
|
142
|
+
closures = closure_written(post_loop) if sites.assigned.each_value.any? { |names| !names.empty? }
|
|
143
|
+
sites.assigned.each_with_object({}.compare_by_identity) do |(site, assigned), scopes|
|
|
144
|
+
reached = table[site]
|
|
145
|
+
next if reached.nil?
|
|
146
|
+
|
|
147
|
+
follows = closures.nil? ? NO_NAMES : assigned - closures
|
|
148
|
+
argument_scope = argument_scope(reached, post_loop, converged, sites.stores, capped, follows)
|
|
149
|
+
table[site] = argument_scope
|
|
150
|
+
scopes[site] = argument_scope unless argument_scope.equal?(post_loop)
|
|
151
|
+
end
|
|
152
|
+
end
|
|
153
|
+
|
|
154
|
+
# `post_loop` with each of `converged`'s names at its {.binding} for a store reached with the scope `reached`.
|
|
155
|
+
# `follows` holds the locals the store is known to follow an assignment of.
|
|
156
|
+
def argument_scope(reached, post_loop, converged, stores, capped, follows)
|
|
157
|
+
converged.each_key.reduce(post_loop) do |acc, name|
|
|
158
|
+
type = binding(name, reached, post_loop, capped: capped, assigned: follows.include?(name),
|
|
159
|
+
mutated: stores.key?(name))
|
|
160
|
+
type.nil? ? acc : acc.with_local(name, type)
|
|
161
|
+
end
|
|
162
|
+
end
|
|
163
|
+
|
|
164
|
+
# The locals a block or lambda writes anywhere in the frame `scope` runs in — a method body with its
|
|
165
|
+
# parameters, or a class, module or file body: every local write whose `depth` is positive, which is one that
|
|
166
|
+
# reaches a variable of an enclosing scope. Such a closure may run between an assignment and a store that
|
|
167
|
+
# follows it (`pr = proc { s = nil }; s = "a"; pr.call; out << s` stores `nil`), and the walk does not model
|
|
168
|
+
# the write at the call, so no assignment of such a local is one a store is known to follow. Where the closure
|
|
169
|
+
# sits does not matter: one made after the loop is counted too, which only costs precision. Nil when the scope
|
|
170
|
+
# carries no frame, where the frame's other closures cannot be seen, and when the frame holds a call that can
|
|
171
|
+
# write any local by name ({.reflective_write?}).
|
|
172
|
+
def closure_written(scope)
|
|
173
|
+
frame = scope.match_frame
|
|
174
|
+
return nil if frame.nil?
|
|
175
|
+
|
|
176
|
+
names = nil
|
|
177
|
+
[frame.body, frame.parameters].each do |root|
|
|
178
|
+
Source::NodeWalker.each(root) do |node|
|
|
179
|
+
return nil if reflective_write?(node)
|
|
180
|
+
next unless CapturedLocals::LOCAL_WRITE_NODES.include?(node.class) && node.depth.positive?
|
|
181
|
+
|
|
182
|
+
(names ||= []) << node.name
|
|
183
|
+
end
|
|
184
|
+
end
|
|
185
|
+
names || NO_NAMES
|
|
186
|
+
end
|
|
187
|
+
|
|
188
|
+
# Calls that reach a frame's locals by name, whatever the receiver: `binding` and `local_variable_set`, and
|
|
189
|
+
# `eval`; the `*_eval` forms count when given an argument, which may be source text.
|
|
190
|
+
BINDING_CALLS = %i[binding eval local_variable_set].freeze
|
|
191
|
+
STRING_EVAL_CALLS = %i[instance_eval class_eval module_eval].freeze
|
|
192
|
+
private_constant :BINDING_CALLS, :STRING_EVAL_CALLS
|
|
193
|
+
|
|
194
|
+
# True for a call through which a local may be rebound without a write node: `s = "a";
|
|
195
|
+
# binding.local_variable_set(:s, nil); out << s` stores `nil`.
|
|
196
|
+
def reflective_write?(node)
|
|
197
|
+
return false unless node.is_a?(Prism::CallNode)
|
|
198
|
+
|
|
199
|
+
BINDING_CALLS.include?(node.name) || (STRING_EVAL_CALLS.include?(node.name) && !node.arguments.nil?)
|
|
200
|
+
end
|
|
201
|
+
|
|
202
|
+
# The type a store's arguments read the rebound local `name` at, given `reached`, the scope the fixpoint's
|
|
203
|
+
# last pass reached the store with; nil to keep the continuation binding `post_loop` holds.
|
|
204
|
+
#
|
|
205
|
+
# - The continuation binding stays when the pass did not bind the name as a local at the store (an instance
|
|
206
|
+
# variable the fixpoint tracks never is one), and when the fixpoint floored it to `Dynamic[top]`: a precise
|
|
207
|
+
# arm in its place would read as knowledge the analysis lacks (`v = "a" if i > 1; out << v`, where `v`
|
|
208
|
+
# first moves on the capped pass).
|
|
209
|
+
# - A capped fixpoint's last pass ran from an assumption the cap then widened, so the binding it reached the
|
|
210
|
+
# store with is widened the same way (`n = i; out << n` is `Integer`, not the `0 | 1 | 2` of the pass).
|
|
211
|
+
# - A local the store does not follow an assignment of (`assigned` false; so is one a closure writes,
|
|
212
|
+
# {.closure_written}) may hold what an earlier iteration left, whatever the pass narrowed it to: `c = "x" if
|
|
213
|
+
# a; out << c if c; c = 5 if b` stores `5`. The continuation binding joins in whole.
|
|
214
|
+
# - A local the body also mutates in place is stored as an object the body may go on mutating (`rows << row;
|
|
215
|
+
# row << 2`), so the non-nil part of its continuation binding joins in.
|
|
216
|
+
def binding(name, reached, post_loop, capped:, assigned:, mutated:)
|
|
217
|
+
at_store = reached.local(name)
|
|
218
|
+
settled = post_loop.local(name)
|
|
219
|
+
return nil if at_store.nil? || settled.nil? || Type::Combinator.untyped?(settled)
|
|
220
|
+
|
|
221
|
+
at_store = Type::Combinator.widen_value_pinned(at_store) if capped
|
|
222
|
+
joined = join(at_store, settled, assigned, mutated)
|
|
223
|
+
joined == settled ? nil : joined
|
|
224
|
+
end
|
|
225
|
+
|
|
226
|
+
# `at_store` with the part of the continuation binding `settled` a store may also hold ({.binding}'s last two
|
|
227
|
+
# cases).
|
|
228
|
+
def join(at_store, settled, assigned, mutated)
|
|
229
|
+
if !assigned
|
|
230
|
+
Type::Combinator.union(at_store, settled)
|
|
231
|
+
elsif mutated
|
|
232
|
+
Type::Combinator.union(at_store, Narrowing.narrow_non_nil(settled))
|
|
233
|
+
else
|
|
234
|
+
at_store
|
|
235
|
+
end
|
|
236
|
+
end
|
|
237
|
+
end
|
|
238
|
+
end
|
|
239
|
+
end
|
|
@@ -136,9 +136,10 @@ module Rigor
|
|
|
136
136
|
end
|
|
137
137
|
|
|
138
138
|
# The match contract stays narrow: `Singleton[X]` receivers (class-level DSL calls) for every
|
|
139
|
-
# entry, plus `Nominal[Y]` receivers only for entries whose declared `self_type`
|
|
140
|
-
# instance — the `requires do ... requires do ... end`
|
|
141
|
-
# body, where `self` is already the ParamsScope instance the call
|
|
139
|
+
# entry, plus `Nominal[Y]` receivers only for entries whose declared `self_type` names an
|
|
140
|
+
# instance class, or that are `:lexical` ({#entry_matches?}) — the `requires do ... requires do ... end`
|
|
141
|
+
# nesting shape inside a Grape `params` body, where `self` is already the ParamsScope instance the call
|
|
142
|
+
# evaluates on.
|
|
142
143
|
def singleton_receiver_class_name(receiver_type)
|
|
143
144
|
return nil unless receiver_type.is_a?(Type::Singleton)
|
|
144
145
|
|
|
@@ -14,7 +14,8 @@ module Rigor
|
|
|
14
14
|
# typing for the same methods continues to be answered by `IteratorDispatch` (this module concerns the
|
|
15
15
|
# *return* of the call, not the block-param binding).
|
|
16
16
|
#
|
|
17
|
-
# The methods covered fall in two families
|
|
17
|
+
# The methods covered fall in two main families (`find` / `index` and block-taking `count` also fold, on a
|
|
18
|
+
# constant block; see their constants below):
|
|
18
19
|
#
|
|
19
20
|
# - **Filter-shaped** (`select` / `filter` / `reject` / `take_while` / `drop_while`): the block's
|
|
20
21
|
# truthiness selects the all-or-nothing endpoints — either every element kept or every element
|
|
@@ -183,7 +184,7 @@ module Rigor
|
|
|
183
184
|
end
|
|
184
185
|
|
|
185
186
|
# Predicate folds. The decision table mirrors Ruby's actual semantics on `Enumerable#all?` / `#any?` /
|
|
186
|
-
# `#none?` — see the
|
|
187
|
+
# `#none?` — see the module comment. A pattern argument declines: Ruby then tests
|
|
187
188
|
# `pattern === element` and ignores the block, so `[1, 2].all?(String) { true }` is `false`.
|
|
188
189
|
def fold_predicate(receiver, method_name, truthiness, args)
|
|
189
190
|
return nil unless args.empty?
|
|
@@ -4,9 +4,9 @@ module Rigor
|
|
|
4
4
|
module Inference
|
|
5
5
|
module MethodDispatcher
|
|
6
6
|
# Immutable value object carrying everything a dispatch tier needs to fold a single call site. Built
|
|
7
|
-
# once per `MethodDispatcher.dispatch`
|
|
8
|
-
# `(receiver:, method_name:, args:, …)` keyword quartet
|
|
9
|
-
# needing a Metrics/ParameterLists rubocop exemption).
|
|
7
|
+
# once per `MethodDispatcher.dispatch` or `resolve`, or by the caller of `dispatch_site`, and threaded —
|
|
8
|
+
# unchanged — through every tier, replacing the `(receiver:, method_name:, args:, …)` keyword quartet
|
|
9
|
+
# that each tier used to redeclare (several needing a Metrics/ParameterLists rubocop exemption).
|
|
10
10
|
#
|
|
11
11
|
# Every tier satisfies one interface — `try_dispatch(CallContext) -> Rigor::Type?` (the `_DispatchTier`
|
|
12
12
|
# RBS interface). Pure tiers (the singleton folders, ConstantFolding, ShapeDispatch, …) read only
|
|
@@ -14,9 +14,15 @@ module Rigor
|
|
|
14
14
|
# consult the wider context.
|
|
15
15
|
#
|
|
16
16
|
# Derived call sites (the user-class fallback's `public_only` RBS retry, the Tier-B origin-module
|
|
17
|
-
# redispatch) use
|
|
17
|
+
# redispatch) use `#with` to copy the base context with the few fields that differ rather than
|
|
18
18
|
# rebuilding the quartet by hand.
|
|
19
19
|
#
|
|
20
|
+
# A plain class that freezes itself, not a `Data` (ADR-116 WD12): `Data.new` turns positional arguments
|
|
21
|
+
# into a keyword Hash before it calls `initialize`, so a `build` allocated three objects where this
|
|
22
|
+
# class allocates one, once per dispatch. What a `Data` gave and callers use is kept — the readers,
|
|
23
|
+
# `with`, value equality and frozen instances; `to_h`, `members` and `deconstruct_keys` had no caller
|
|
24
|
+
# and are gone.
|
|
25
|
+
#
|
|
20
26
|
# Fields:
|
|
21
27
|
# - `receiver` — the receiver `Rigor::Type` (nil short-circuits)
|
|
22
28
|
# - `method_name` — the called selector (Symbol)
|
|
@@ -27,28 +33,92 @@ module Rigor
|
|
|
27
33
|
# - `scope` — the enclosing `Scope` (discovered methods, …)
|
|
28
34
|
# - `self_type_override` — receiver to attribute private dispatch to
|
|
29
35
|
# - `public_only` — suppress private-method resolution (explicit, non-self receiver)
|
|
30
|
-
CallContext
|
|
31
|
-
:receiver, :method_name, :args,
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
36
|
+
class CallContext
|
|
37
|
+
attr_reader :receiver, :method_name, :args,
|
|
38
|
+
:block_type, :environment, :call_node, :scope,
|
|
39
|
+
:self_type_override, :public_only
|
|
40
|
+
|
|
41
|
+
# The field names, for `with` to check its keywords against.
|
|
42
|
+
FIELDS = %i[
|
|
43
|
+
receiver method_name args block_type environment call_node scope self_type_override public_only
|
|
44
|
+
].freeze
|
|
45
|
+
private_constant :FIELDS
|
|
46
|
+
|
|
35
47
|
# Keyword factory with nil/false defaults for the optional context fields, so a caller that only has
|
|
36
48
|
# the call quartet (the common precise-tier path) need not spell out the rest.
|
|
37
49
|
#
|
|
38
|
-
# This is the single place the call-context field list
|
|
39
|
-
# object is to absorb the wide keyword list the tiers used to each redeclare.
|
|
50
|
+
# This is the single place a caller enumerates the call-context field list — the whole point of the
|
|
51
|
+
# value object is to absorb the wide keyword list the tiers used to each redeclare.
|
|
40
52
|
def self.build(receiver:, method_name:, args:, # rubocop:disable Metrics/ParameterLists
|
|
41
53
|
block_type: nil, environment: nil, call_node: nil,
|
|
42
54
|
scope: nil, self_type_override: nil, public_only: false)
|
|
43
|
-
#
|
|
44
|
-
#
|
|
45
|
-
# `Data.define` field list above.
|
|
55
|
+
# This runs once per dispatch and was a top allocation site, so the fields go to `new` positionally:
|
|
56
|
+
# nothing but the context itself is allocated. Order MUST track `initialize`.
|
|
46
57
|
new(
|
|
47
58
|
receiver, method_name, args,
|
|
48
59
|
block_type, environment, call_node, scope,
|
|
49
60
|
self_type_override, public_only
|
|
50
61
|
)
|
|
51
62
|
end
|
|
63
|
+
|
|
64
|
+
# Positional, in the order of the field list above.
|
|
65
|
+
def initialize(receiver, method_name, args, # rubocop:disable Metrics/ParameterLists
|
|
66
|
+
block_type, environment, call_node, scope,
|
|
67
|
+
self_type_override, public_only)
|
|
68
|
+
@receiver = receiver
|
|
69
|
+
@method_name = method_name
|
|
70
|
+
@args = args
|
|
71
|
+
@block_type = block_type
|
|
72
|
+
@environment = environment
|
|
73
|
+
@call_node = call_node
|
|
74
|
+
@scope = scope
|
|
75
|
+
@self_type_override = self_type_override
|
|
76
|
+
@public_only = public_only
|
|
77
|
+
freeze
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
# `dup` skips `initialize`, so the copy is frozen here, as a `Data`'s copy is.
|
|
81
|
+
def initialize_copy(source)
|
|
82
|
+
super
|
|
83
|
+
freeze
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
# A fresh context with the named fields replaced. It takes any keyword and raises `ArgumentError` for
|
|
87
|
+
# one that names no field, as `Data#with` did.
|
|
88
|
+
def with(**changes)
|
|
89
|
+
changes.each_key do |name|
|
|
90
|
+
raise ArgumentError, "unknown keyword: #{name.inspect}" unless FIELDS.include?(name)
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
self.class.new(
|
|
94
|
+
changes.fetch(:receiver, @receiver), changes.fetch(:method_name, @method_name),
|
|
95
|
+
changes.fetch(:args, @args), changes.fetch(:block_type, @block_type),
|
|
96
|
+
changes.fetch(:environment, @environment), changes.fetch(:call_node, @call_node),
|
|
97
|
+
changes.fetch(:scope, @scope), changes.fetch(:self_type_override, @self_type_override),
|
|
98
|
+
changes.fetch(:public_only, @public_only)
|
|
99
|
+
)
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
# Two contexts of the same class are equal when every field is.
|
|
103
|
+
def ==(other)
|
|
104
|
+
other.instance_of?(self.class) && fields == other.fields
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
def eql?(other)
|
|
108
|
+
other.instance_of?(self.class) && fields.eql?(other.fields)
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
# Seeded with the class, as `eql?` compares it.
|
|
112
|
+
def hash
|
|
113
|
+
[self.class, fields].hash
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
protected
|
|
117
|
+
|
|
118
|
+
def fields
|
|
119
|
+
[@receiver, @method_name, @args, @block_type, @environment, @call_node, @scope, @self_type_override,
|
|
120
|
+
@public_only]
|
|
121
|
+
end
|
|
52
122
|
end
|
|
53
123
|
end
|
|
54
124
|
end
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "../../type"
|
|
4
|
+
|
|
5
|
+
module Rigor
|
|
6
|
+
module Inference
|
|
7
|
+
module MethodDispatcher
|
|
8
|
+
# The composite-receiver tier (issue #1101): a `Union` or a nil-removing `Difference` receiver is dispatched
|
|
9
|
+
# once per projected member through the whole of `MethodDispatcher.resolve`, and the answers are unioned. It is
|
|
10
|
+
# the last tier `resolve_site` asks, through `COMPOSITE_TIERS`, and nothing in `resolve_site` follows its
|
|
11
|
+
# answer.
|
|
12
|
+
#
|
|
13
|
+
# The re-entry into `MethodDispatcher.resolve` is the module's one call back into the dispatcher. It passes a
|
|
14
|
+
# `plugin_typed_sink:`, so a plugin tier that answers a member buffers its plugin-typed record there, and this
|
|
15
|
+
# tier commits the buffer to the scope itself, only when every member answered.
|
|
16
|
+
module CompositeReceiver
|
|
17
|
+
module_function
|
|
18
|
+
|
|
19
|
+
# Issue #1101 — the composite-receiver projection tier, the LAST thing `resolve_site` tries.
|
|
20
|
+
#
|
|
21
|
+
# Every tier above needs a receiver it can *name*: `receiver_descriptor`, the discovered-method
|
|
22
|
+
# lookup, the dependency-source and synthesized-stub tiers and the user-class fallback all switch
|
|
23
|
+
# on `Nominal` / `Singleton` / a member carrier. A `Union` or a `Difference` is none of those, so a
|
|
24
|
+
# composite receiver whose members would each resolve perfectly well still fell through the whole
|
|
25
|
+
# chain and landed `Dynamic[top]`.
|
|
26
|
+
#
|
|
27
|
+
# `RbsDispatch` already distributes over a `Union` (and erases a `Difference` to its base, #533),
|
|
28
|
+
# but it does so INSIDE one tier, so a member that needs a LOWER tier — a user class with no RBS,
|
|
29
|
+
# a discovered `def`, an opt-in gem — makes the whole union decline. That was the corpus shape before
|
|
30
|
+
# #2430: rigor-actionpack typed `params[:k]` as the bare `ActionController::Parameters | nil` union, the
|
|
31
|
+
# `Parameters` arm resolved only through the user-class fallback, and so `params[:k].present?` / `#==`
|
|
32
|
+
# / `#blank?` / `#to_s` read opaque on every Rails app. Measured by toggling this file alone: the
|
|
33
|
+
# named-pair census drained 137 sites on redmine and 56 on mastodon, and `rigor check` reported the
|
|
34
|
+
# same diagnostics on both arms across eight survey targets. The plugin now answers a `Dynamic`
|
|
35
|
+
# carrier, which this projection does not reach, so those off-chain calls read `Dynamic[top]` until
|
|
36
|
+
# the carrier is projected here too (#2448).
|
|
37
|
+
#
|
|
38
|
+
# **Why the bottom and not next to `RbsDispatch`.** Sitting here, the tier can only ever replace a
|
|
39
|
+
# `Dynamic[top]` the typer was about to produce — the same ADR-5 argument {UniversalObjectDispatch}
|
|
40
|
+
# makes. Hoisting the projection above `RbsDispatch` would change answers that resolve today, which
|
|
41
|
+
# is a different change with a different measurement.
|
|
42
|
+
#
|
|
43
|
+
# **The projection rule** (`receiver_projection` below; the normative statement lives in
|
|
44
|
+
# [`inference-engine.md`](docs/internal-spec/inference-engine.md) § "Composite receivers"):
|
|
45
|
+
#
|
|
46
|
+
# - `Union[A, B, …]` projects to its members. Each is dispatched through this same chain and the
|
|
47
|
+
# results are unioned; if ANY member declines, the whole tier declines. Never a partial answer —
|
|
48
|
+
# a union whose members disagree about whether the method exists is exactly the case where an
|
|
49
|
+
# answer would be a guess.
|
|
50
|
+
# - `Difference[base, nil]` projects to `base` with its nil-valued members removed. Removing `nil`
|
|
51
|
+
# from a receiver cannot change method resolution at all: `NilClass` is nobody's ancestor, so
|
|
52
|
+
# every remaining inhabitant looks a method up exactly as a plain `base` inhabitant does, and the
|
|
53
|
+
# carrier is value-set-equal to the projection. This is `T.must(x)` (rigor-sorbet's
|
|
54
|
+
# `strip_nil`), which builds `Difference[inferred(x), Constant[nil]]` — over a `T?` local that
|
|
55
|
+
# base IS a union, which is why the two arms compose rather than being separate features.
|
|
56
|
+
# - Any other `Difference` DECLINES. `A − B` for a real `B` is a claim about which inhabitants
|
|
57
|
+
# survive, and the projection has nowhere to put it: dispatching on `A` re-admits exactly the
|
|
58
|
+
# overrides `B` contributed, and over a union base (`(String | Integer) − Integer` is Strings
|
|
59
|
+
# only) it re-admits a member the difference eliminated and unions in its answer — a WIDER type
|
|
60
|
+
# than today's decline, on a shape no corpus target produces. Subtracting a class from a union
|
|
61
|
+
# needs an algebra the `Difference` carrier does not have (it removes a value set, not a member),
|
|
62
|
+
# so the honest answer is to keep declining until something demands it. `RbsDispatch`'s #533
|
|
63
|
+
# erasure is untouched and still answers these for an RBS-known base.
|
|
64
|
+
#
|
|
65
|
+
# `self` binds to the PROJECTED receiver, not to the composite: the projection is the exact set of
|
|
66
|
+
# inhabitants that can reach the method, so a `-> self` method (`dup`, `itself`, `tap`) answers per
|
|
67
|
+
# member and the union reassembles them — `(String | Symbol)#itself` is `String | Symbol`. Nothing is
|
|
68
|
+
# lost on the `Difference` arm because the projection is value-set-equal to the carrier there. This
|
|
69
|
+
# falls out of re-entering `resolve` rather than needing a `self_type_override`.
|
|
70
|
+
def try_dispatch(context)
|
|
71
|
+
members = receiver_projection(context.receiver)
|
|
72
|
+
return nil if members.nil? || members.size > COMPOSITE_PROJECTION_MEMBERS
|
|
73
|
+
|
|
74
|
+
plugin_typed = []
|
|
75
|
+
# Each member goes through `resolve`, which builds its context from the site's seven call fields, and not
|
|
76
|
+
# through `resolve_site(context.with(receiver: member))`: `with` allocates a keyword Hash beside the
|
|
77
|
+
# context, one more object for every member, and it would carry a `self_type_override` over where `self`
|
|
78
|
+
# binds to the projected member (above).
|
|
79
|
+
results = members.map do |member|
|
|
80
|
+
MethodDispatcher.resolve(
|
|
81
|
+
receiver_type: member, method_name: context.method_name, arg_types: context.args,
|
|
82
|
+
block_type: context.block_type, environment: context.environment,
|
|
83
|
+
call_node: context.call_node, scope: context.scope, plugin_typed_sink: plugin_typed
|
|
84
|
+
)
|
|
85
|
+
end
|
|
86
|
+
return nil if results.any?(&:nil?)
|
|
87
|
+
|
|
88
|
+
plugin_typed.uniq.each { |node| context.scope&.record_plugin_typed_call(node) }
|
|
89
|
+
Type::Combinator.union(*results)
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
# An upper bound on the fan-out, because this tier re-runs the FULL dispatch chain per member.
|
|
93
|
+
# Real unions are two or three members wide; a receiver wider than this is a join the engine has
|
|
94
|
+
# already lost precision on, and paying N chain walks to union N answers is not worth it.
|
|
95
|
+
COMPOSITE_PROJECTION_MEMBERS = 8
|
|
96
|
+
private_constant :COMPOSITE_PROJECTION_MEMBERS
|
|
97
|
+
|
|
98
|
+
# The receivers each member of a composite carrier is dispatched as, or nil when the carrier is not
|
|
99
|
+
# projectable. Every member returned MUST itself be non-composite: that is what bounds the re-entry
|
|
100
|
+
# into `resolve` at one level, by construction rather than by a counter — the nested call reaches
|
|
101
|
+
# this tier with a receiver it declines immediately. A normalized `Union` never holds a `Union`, so
|
|
102
|
+
# the shapes the guard turns away are a `Difference` over a `Difference` (`T.must(T.must(x))`) and a
|
|
103
|
+
# `Union` holding one (`c ? T.must(y) : Bar.new`, which normalizes to `(A - nil) | Bar`). Both
|
|
104
|
+
# decline exactly as they did before this tier existed; neither appears in the survey corpus.
|
|
105
|
+
def receiver_projection(receiver)
|
|
106
|
+
members =
|
|
107
|
+
case receiver
|
|
108
|
+
when Type::Union then receiver.members
|
|
109
|
+
when Type::Difference then difference_projection(receiver)
|
|
110
|
+
end
|
|
111
|
+
return nil if members.nil? || members.empty?
|
|
112
|
+
return nil if members.any? { |member| member.is_a?(Type::Union) || member.is_a?(Type::Difference) }
|
|
113
|
+
|
|
114
|
+
members
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
# `Difference[base, nil]` projects to `base` minus its nil-valued members; every other difference
|
|
118
|
+
# declines. The nil filter runs over a scalar base as well as a union one, so the rule stays total:
|
|
119
|
+
# `Combinator.difference` does not normalize `NilClass - nil` (or `nil - nil`) to `Bot`, and this
|
|
120
|
+
# tier must not project `[NilClass]` and answer a NilClass method for a carrier with no inhabitant.
|
|
121
|
+
# Nothing observable turns on it today — `RbsDispatch`'s #533 erasure sits above this tier and
|
|
122
|
+
# already answers a nil-only base from the base's own descriptor — which is why the guard is here
|
|
123
|
+
# rather than in `Combinator`, where it would be a normalization change with its own blast radius.
|
|
124
|
+
def difference_projection(difference)
|
|
125
|
+
return nil unless nil_valued_type?(difference.removed)
|
|
126
|
+
|
|
127
|
+
base = difference.base
|
|
128
|
+
members = base.is_a?(Type::Union) ? base.members : [base]
|
|
129
|
+
retained = members.reject { |member| nil_valued_type?(member) }
|
|
130
|
+
return nil if retained.empty?
|
|
131
|
+
|
|
132
|
+
retained
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
# `nil` as either carrier spells it: the value-pinned `Constant[nil]` the engine normally produces,
|
|
136
|
+
# and the `Nominal[NilClass]` a widened or RBS-sourced position carries.
|
|
137
|
+
def nil_valued_type?(type)
|
|
138
|
+
(type.is_a?(Type::Constant) && type.value.nil?) ||
|
|
139
|
+
(type.is_a?(Type::Nominal) && type.class_name == "NilClass")
|
|
140
|
+
end
|
|
141
|
+
end
|
|
142
|
+
end
|
|
143
|
+
end
|
|
144
|
+
end
|
|
@@ -1705,10 +1705,11 @@ module Rigor
|
|
|
1705
1705
|
catalog_allows?(receiver_value, method_name)
|
|
1706
1706
|
end
|
|
1707
1707
|
|
|
1708
|
-
# Consults the offline
|
|
1709
|
-
# hand-rolled unary/binary allow lists. The catalog's `leaf` /
|
|
1710
|
-
# entries promise the underlying CRuby implementation does not call back
|
|
1711
|
-
# methods, so executing them on a literal
|
|
1708
|
+
# Consults the offline per-class catalogs (`CATALOG_BY_CLASS`, e.g. data/builtins/ruby_core/numeric.yml
|
|
1709
|
+
# for Integer / Float) as a superset of the hand-rolled unary/binary allow lists. The catalog's `leaf` /
|
|
1710
|
+
# `trivial` / `leaf_when_numeric` entries promise the underlying CRuby implementation does not call back
|
|
1711
|
+
# into user-redefinable Ruby methods, so executing them on a literal receiver is safe regardless of
|
|
1712
|
+
# monkey-patching.
|
|
1712
1713
|
#
|
|
1713
1714
|
# Resolution order:
|
|
1714
1715
|
#
|
|
@@ -1817,7 +1818,8 @@ module Rigor
|
|
|
1817
1818
|
receiver_value.is_a?(String) && receiver_value.bytesize >= STRING_FOLD_BYTE_LIMIT
|
|
1818
1819
|
end
|
|
1819
1820
|
|
|
1820
|
-
#
|
|
1821
|
+
# The listed classes fold (scalars, String, Symbol, Regexp, Pathname, Set, Date, Time); everything else
|
|
1822
|
+
# (Array, Hash, Proc, Range, ...) is held back
|
|
1821
1823
|
# because `Type::Constant` does not model those carriers and surfacing one would mis-type downstream
|
|
1822
1824
|
# calls. `Range`, `Array`, and friends have their own shape carriers; this method picks the
|
|
1823
1825
|
# conservative envelope of "values that already round-trip through `Type::Combinator.constant_of`".
|
|
@@ -11,7 +11,7 @@ module Rigor
|
|
|
11
11
|
module MethodDispatcher
|
|
12
12
|
# Issue #2884 — `X.new` through a `def self.new` that a project, gem or collection signature declares on `X` or
|
|
13
13
|
# on an ancestor of `X`. RBS models a constructor that answers another class this way (`email_address` declares
|
|
14
|
-
# `def self.new: (...) -> Address` on `EmailAddress`), and `
|
|
14
|
+
# `def self.new: (...) -> Address` on `EmailAddress`), and `MetaIntrospection.meta_new` answered `Nominal[X]` for
|
|
15
15
|
# every `Singleton[X].new` before any RBS tier ran. `meta_new` asks this module only after its curated lifts
|
|
16
16
|
# (`Array`, `Set`, `Hash`, `Struct`, `Class.new`, …) have declined, and keeps its `Nominal[X]` answer whenever
|
|
17
17
|
# this one is nil.
|