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,106 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "../../type"
|
|
4
|
+
require_relative "../../builtins/static_return_refinements"
|
|
5
|
+
require_relative "call_context"
|
|
6
|
+
require_relative "shape_dispatch"
|
|
7
|
+
|
|
8
|
+
module Rigor
|
|
9
|
+
module Inference
|
|
10
|
+
module MethodDispatcher
|
|
11
|
+
# The static-refinement tier: the stdlib methods whose upstream RBS is broader than the documented behaviour
|
|
12
|
+
# (`Kernel#__dir__` declared `() -> String?`, a zero-start slice declared nilable) answer the tightened type
|
|
13
|
+
# from `Rigor::Builtins::StaticReturnRefinements::OVERRIDES`, with the vendored `ruby/rbs` left as it is. Its
|
|
14
|
+
# place in the order is `MethodDispatcher`'s `BUNDLED_OVERRIDE_TIERS`.
|
|
15
|
+
module StaticRefinement
|
|
16
|
+
module_function
|
|
17
|
+
|
|
18
|
+
# Consults the Rigor-bundled static refinement table for a (owner-class, method-name,
|
|
19
|
+
# kind) entry. Kernel methods are mixed into every non-BasicObject class, so an
|
|
20
|
+
# implicit-self `__dir__` call (receiver_type = Nominal[ClassName]) is matched by looking
|
|
21
|
+
# up Kernel as the owner. Explicit `Kernel.__dir__` (receiver_type = Singleton[Kernel]) and
|
|
22
|
+
# instance-side calls (receiver_type = Nominal[Klass]) share the `:both` row.
|
|
23
|
+
#
|
|
24
|
+
# The receiver-side ancestor check is intentionally cheap: any non-BasicObject Nominal /
|
|
25
|
+
# Singleton matches every Kernel-owned override. BasicObject explicitly excludes Kernel and
|
|
26
|
+
# is therefore rejected. The narrow risk of a user-defined `def __dir__` shadowing Kernel's
|
|
27
|
+
# method would also alter the runtime answer; users with that configuration opt out via a
|
|
28
|
+
# `signature_paths` overlay declaring their own return type.
|
|
29
|
+
#
|
|
30
|
+
# A union receiver is answered member by member, and only when every member is: each member
|
|
31
|
+
# answers as it would alone (`(Array[String] | String)[0..]` drops the nil of both), and one
|
|
32
|
+
# member no entry refines leaves the whole call to RBS.
|
|
33
|
+
def try_dispatch(context)
|
|
34
|
+
receiver_type = context.receiver
|
|
35
|
+
method_name = context.method_name
|
|
36
|
+
arg_types = context.args
|
|
37
|
+
candidates = Rigor::Builtins::StaticReturnRefinements.owners_for(method_name)
|
|
38
|
+
return nil if candidates.empty?
|
|
39
|
+
if receiver_type.is_a?(Type::Union)
|
|
40
|
+
return try_static_refinement_members(receiver_type, method_name, arg_types, context, candidates)
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
owner = static_refinement_owner_for(receiver_type, candidates)
|
|
44
|
+
return nil unless owner
|
|
45
|
+
|
|
46
|
+
kind = receiver_type.is_a?(Type::Singleton) ? :singleton : :instance
|
|
47
|
+
Rigor::Builtins::StaticReturnRefinements.lookup(
|
|
48
|
+
owner_class_name: owner,
|
|
49
|
+
method_name: method_name,
|
|
50
|
+
kind: kind,
|
|
51
|
+
arg_types: arg_types,
|
|
52
|
+
context: context
|
|
53
|
+
)
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def try_static_refinement_members(receiver_type, method_name, arg_types, context, candidates)
|
|
57
|
+
members = receiver_type.members
|
|
58
|
+
return nil unless members.all? { |member| static_refinement_owner_for(member, candidates) }
|
|
59
|
+
|
|
60
|
+
results = members.map do |member|
|
|
61
|
+
static_member_answer(member, method_name, arg_types, context)
|
|
62
|
+
end
|
|
63
|
+
return nil if results.any?(&:nil?)
|
|
64
|
+
|
|
65
|
+
Type::Combinator.union(*results)
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
# A `Tuple` member the table answers is offered to {ShapeDispatch} first, as it is when it is the lone receiver
|
|
69
|
+
# (the precise tiers run ahead of this one) and as `RbsDispatch`'s union path offers it (#3320): `[][0...-1]` is
|
|
70
|
+
# the exact `[]` there, not the `Array[untyped]` projection.
|
|
71
|
+
def static_member_answer(member, method_name, arg_types, context)
|
|
72
|
+
answer = try_dispatch(context.with(receiver: member))
|
|
73
|
+
return answer unless answer && member.is_a?(Type::Tuple)
|
|
74
|
+
|
|
75
|
+
ShapeDispatch.try_dispatch(
|
|
76
|
+
CallContext.build(
|
|
77
|
+
receiver: member, method_name: method_name, args: arg_types, block_type: context.block_type
|
|
78
|
+
)
|
|
79
|
+
) || answer
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
# Picks the most specific override owner the receiver honours. For Kernel-owned overrides
|
|
83
|
+
# the receiver simply needs to be a real-class Nominal / Singleton (i.e. not BasicObject
|
|
84
|
+
# and not a Dynamic / Constant / shape carrier — those carriers go through their own
|
|
85
|
+
# narrower tiers).
|
|
86
|
+
def static_refinement_owner_for(receiver_type, candidates)
|
|
87
|
+
receiver_class = static_refinement_class_for(receiver_type)
|
|
88
|
+
return nil unless receiver_class
|
|
89
|
+
|
|
90
|
+
return "Kernel" if candidates.include?("Kernel") && receiver_class != "BasicObject"
|
|
91
|
+
|
|
92
|
+
candidates.find { |owner| owner == receiver_class }
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
def static_refinement_class_for(receiver_type)
|
|
96
|
+
case receiver_type
|
|
97
|
+
when Type::Singleton, Type::Nominal
|
|
98
|
+
receiver_type.class_name
|
|
99
|
+
when Type::Tuple
|
|
100
|
+
"Array"
|
|
101
|
+
end
|
|
102
|
+
end
|
|
103
|
+
end
|
|
104
|
+
end
|
|
105
|
+
end
|
|
106
|
+
end
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "../../type"
|
|
4
|
+
|
|
5
|
+
module Rigor
|
|
6
|
+
module Inference
|
|
7
|
+
module MethodDispatcher
|
|
8
|
+
# The synthesized-stub tier (ADR-5 robustness): a call on a type Rigor invented so that a project signature
|
|
9
|
+
# would build answers `Dynamic[Top]` instead of falling through to `call.undefined-method`. Its place in the
|
|
10
|
+
# order is `MethodDispatcher`'s `STUB_AND_UNIVERSAL_TIERS`.
|
|
11
|
+
module SynthesizedStub
|
|
12
|
+
module_function
|
|
13
|
+
|
|
14
|
+
# ADR-5 robustness — returns `Dynamic[Top]` when the receiver is an instance or singleton
|
|
15
|
+
# of a type Rigor synthesized (a missing-namespace module or a referenced-type stub). The
|
|
16
|
+
# stub has no methods, so the call would otherwise reach the user-class fallback and
|
|
17
|
+
# surface `call.undefined-method`; the honest answer for a type Rigor invented is "unknown
|
|
18
|
+
# shape", i.e. `Dynamic[Top]`. Returns nil (declines) for any real type.
|
|
19
|
+
def try_dispatch(context)
|
|
20
|
+
receiver_type = context.receiver
|
|
21
|
+
environment = context.environment
|
|
22
|
+
return nil if environment.nil?
|
|
23
|
+
|
|
24
|
+
loader = environment.rbs_loader
|
|
25
|
+
return nil if loader.nil? || !loader.respond_to?(:synthesized_type_names)
|
|
26
|
+
|
|
27
|
+
names = loader.synthesized_type_names
|
|
28
|
+
return nil if names.empty?
|
|
29
|
+
|
|
30
|
+
class_name =
|
|
31
|
+
case receiver_type
|
|
32
|
+
when Type::Nominal, Type::Singleton then receiver_type.class_name.to_s.sub(/\A::/, "")
|
|
33
|
+
end
|
|
34
|
+
return nil unless class_name && names.include?(class_name)
|
|
35
|
+
|
|
36
|
+
Type::Combinator.untyped
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "../../type"
|
|
4
|
+
require_relative "call_context"
|
|
5
|
+
require_relative "rbs_dispatch"
|
|
6
|
+
|
|
7
|
+
module Rigor
|
|
8
|
+
module Inference
|
|
9
|
+
module MethodDispatcher
|
|
10
|
+
# The synthetic-method tier (ADR-16 Tier B / Tier C): a method a plugin's macro table synthesised for the
|
|
11
|
+
# receiver's class answers from the `SyntheticMethodIndex` the environment carries. Its place in the order
|
|
12
|
+
# is `MethodDispatcher`'s `SYNTHETIC_TIERS`, below `RbsDispatch` and above the project-patched tier.
|
|
13
|
+
#
|
|
14
|
+
# Named for the dispatch and not `SyntheticMethod`: that is {Rigor::Inference::SyntheticMethod}, the record the
|
|
15
|
+
# index holds, and a module of the same name here would shadow it for every tier.
|
|
16
|
+
#
|
|
17
|
+
# Two entries beside {#try_dispatch}: {#synthetic_method_member?}, which `MethodDispatcher.plugin_member_answers?`
|
|
18
|
+
# asks, and {#synthetic_method_class_name}, which {ProjectPatched} keys its registry lookup on.
|
|
19
|
+
module SyntheticMethodDispatch
|
|
20
|
+
module_function
|
|
21
|
+
|
|
22
|
+
# ADR-16 synthetic-method tier. Slice 2b shipped the floor — a match short-circuits at the
|
|
23
|
+
# right precedence (above dep-source / discovered / user-class-fallback; below RBS) and
|
|
24
|
+
# returns `Dynamic[T]`. Slice 6 (precision promotion):
|
|
25
|
+
# - Tier B path (slice 6a, `provenance[:origin_module]` recorded by the slice-3b scanner):
|
|
26
|
+
# redispatch on `Nominal[origin_module]` via `RbsDispatch` so the module's authored RBS
|
|
27
|
+
# return type wins. Devise's `valid_password?` returns `bool`, not `Dynamic[T]`.
|
|
28
|
+
# - Tier C path (slice 6b, plain `return_type:` string from the manifest's emit table):
|
|
29
|
+
# look up `environment.nominal_for_name(return_type)` so `attribute :avatar,
|
|
30
|
+
# Types::String` emits a synthetic reader returning
|
|
31
|
+
# `Nominal[ActiveStorage::Attached::One]` (when the class is in RBS). Unparameterised
|
|
32
|
+
# class names only — parameterised forms (`Array[String]`, `Hash[K, V]`) and
|
|
33
|
+
# plugin-supplied utility-type names (`Pick<T, K>`) require routing through the full
|
|
34
|
+
# ADR-13 `Plugin::TypeNodeResolver` chain, which slice 6 does not yet wire in (the
|
|
35
|
+
# resolver chain is consulted only for `%a{rigor:v1:…}` payloads as of ADR-13 slice 3).
|
|
36
|
+
def try_dispatch(context)
|
|
37
|
+
receiver_type = context.receiver
|
|
38
|
+
method_name = context.method_name
|
|
39
|
+
arg_types = context.args
|
|
40
|
+
block_type = context.block_type
|
|
41
|
+
environment = context.environment
|
|
42
|
+
index = environment&.synthetic_method_index
|
|
43
|
+
return nil if index.nil? || index.empty?
|
|
44
|
+
|
|
45
|
+
class_name = synthetic_method_class_name(receiver_type)
|
|
46
|
+
return nil if class_name.nil?
|
|
47
|
+
|
|
48
|
+
matches = case receiver_type
|
|
49
|
+
when Type::Singleton then index.lookup_singleton(class_name, method_name)
|
|
50
|
+
else index.lookup_instance(class_name, method_name)
|
|
51
|
+
end
|
|
52
|
+
return nil if matches.empty?
|
|
53
|
+
|
|
54
|
+
promoted = promote_synthetic_match(matches, method_name, arg_types, block_type, environment)
|
|
55
|
+
promoted || Type::Combinator.untyped
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
# The synthetic-method half of {MethodDispatcher.plugin_member_answers?} — the same `(class_name,
|
|
59
|
+
# method_name, kind)` probe {#try_dispatch} makes, without the return-type promotion the veto has no use for.
|
|
60
|
+
def synthetic_method_member?(receiver_type, method_name, environment)
|
|
61
|
+
index = environment&.synthetic_method_index
|
|
62
|
+
return false if index.nil? || index.empty?
|
|
63
|
+
|
|
64
|
+
class_name = synthetic_method_class_name(receiver_type)
|
|
65
|
+
return false if class_name.nil?
|
|
66
|
+
|
|
67
|
+
matches = if receiver_type.is_a?(Type::Singleton)
|
|
68
|
+
index.lookup_singleton(class_name, method_name)
|
|
69
|
+
else
|
|
70
|
+
index.lookup_instance(class_name, method_name)
|
|
71
|
+
end
|
|
72
|
+
!matches.empty?
|
|
73
|
+
rescue StandardError
|
|
74
|
+
false
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
# First non-nil promotion wins. Tier B (origin_module) and Tier C (return_type nominal
|
|
78
|
+
# lookup) are tried in the same registration-order pass per WD11 first-wins — the slice-3b
|
|
79
|
+
# scanner sets `origin_module` for Tier B entries and leaves it absent for Tier C, so the
|
|
80
|
+
# two paths self-route per match.
|
|
81
|
+
def promote_synthetic_match(matches, method_name, arg_types, block_type, environment)
|
|
82
|
+
return nil if environment.nil?
|
|
83
|
+
|
|
84
|
+
matches.each do |synthetic|
|
|
85
|
+
promoted =
|
|
86
|
+
promote_via_origin_module(synthetic, method_name, arg_types, block_type, environment) ||
|
|
87
|
+
promote_via_return_type(synthetic, environment)
|
|
88
|
+
return promoted if promoted
|
|
89
|
+
end
|
|
90
|
+
nil
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
# Slice 6a-TierB. For Tier B emissions (origin_module recorded in provenance), redispatch
|
|
94
|
+
# the call on the included module's `Nominal[...]` type via `RbsDispatch`. Returns nil when
|
|
95
|
+
# the SyntheticMethod is not a Tier B entry or when the origin_module is not in the RBS
|
|
96
|
+
# env.
|
|
97
|
+
def promote_via_origin_module(synthetic, method_name, arg_types, block_type, environment)
|
|
98
|
+
module_name = synthetic.provenance[:origin_module]
|
|
99
|
+
return nil unless module_name
|
|
100
|
+
|
|
101
|
+
module_type = Type::Combinator.nominal_of(module_name)
|
|
102
|
+
RbsDispatch.try_dispatch(
|
|
103
|
+
CallContext.build(
|
|
104
|
+
receiver: module_type, method_name: method_name, args: arg_types,
|
|
105
|
+
environment: environment, block_type: block_type
|
|
106
|
+
)
|
|
107
|
+
)
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
# Slice 6b-TierC. For Tier C emissions, look up the manifest-declared `return_type:` string
|
|
111
|
+
# via `environment.nominal_for_name`. Skips the placeholder `"untyped"` (Tier B's
|
|
112
|
+
# record-but-do-not-resolve marker from the slice-3b scanner) and the `"void"` keyword
|
|
113
|
+
# (RBS-style absent return). Falls back to nil when the class is not in the env — caller
|
|
114
|
+
# then returns Dynamic[T].
|
|
115
|
+
TIER_C_PLACEHOLDER_RETURNS = %w[untyped void].freeze
|
|
116
|
+
private_constant :TIER_C_PLACEHOLDER_RETURNS
|
|
117
|
+
|
|
118
|
+
def promote_via_return_type(synthetic, environment)
|
|
119
|
+
return_type = synthetic.return_type
|
|
120
|
+
return nil if return_type.nil? || TIER_C_PLACEHOLDER_RETURNS.include?(return_type)
|
|
121
|
+
|
|
122
|
+
environment.nominal_for_name(return_type)
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
def synthetic_method_class_name(receiver_type)
|
|
126
|
+
case receiver_type
|
|
127
|
+
when Type::Nominal, Type::Singleton then receiver_type.class_name
|
|
128
|
+
end
|
|
129
|
+
end
|
|
130
|
+
end
|
|
131
|
+
end
|
|
132
|
+
end
|
|
133
|
+
end
|
|
@@ -18,7 +18,8 @@ module Rigor
|
|
|
18
18
|
#
|
|
19
19
|
# **Where it sits.** After every real tier has declined, so a receiver Rigor can name always resolves
|
|
20
20
|
# through RBS first — `"".frozen?` is answered by `String`'s signature, not by this table. It only ever
|
|
21
|
-
# replaces a `Dynamic[Top]` that the engine was about to produce anyway.
|
|
21
|
+
# replaces a `Dynamic[Top]` that the engine was about to produce anyway. Its place in the order is
|
|
22
|
+
# `MethodDispatcher`'s `STUB_AND_UNIVERSAL_TIERS`, behind the synthesized-stub tier.
|
|
22
23
|
#
|
|
23
24
|
# **What is deliberately NOT here**, each measured rather than argued (same note):
|
|
24
25
|
#
|
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "../../analysis/dependency_recorder"
|
|
4
|
+
require_relative "../../memo_audit"
|
|
5
|
+
require_relative "../../reflection"
|
|
6
|
+
require_relative "../../type"
|
|
7
|
+
require_relative "../../typing_state"
|
|
8
|
+
require_relative "../block_call_timing"
|
|
9
|
+
require_relative "../external_ancestor_resolution"
|
|
10
|
+
require_relative "project_patched"
|
|
11
|
+
require_relative "rbs_dispatch"
|
|
12
|
+
# Last, as `method_dispatcher.rb` required it ahead of the two memos below (#2399): what it loads declares its slots
|
|
13
|
+
# first, so the memos keep their place in `Rigor::TypingState.slots`.
|
|
14
|
+
require_relative "../../run_scoped_slots"
|
|
15
|
+
|
|
16
|
+
module Rigor
|
|
17
|
+
module Inference
|
|
18
|
+
module MethodDispatcher
|
|
19
|
+
# The user-class ancestor fallback (Slice 7 phase 10): a receiver Rigor knows by name but not by RBS is retried
|
|
20
|
+
# against `Object` (an instance, or an instance of an RBS-known module) or `Class` (a class object), so `puts`,
|
|
21
|
+
# `raise` and `attr_reader` resolve on a class the project wrote without a signature.
|
|
22
|
+
# `MethodDispatcher.resolve_site` asks it behind every other tier that reads the receiver's class and records
|
|
23
|
+
# the origin of a `Dynamic` answer, so it is a call there and a member of no tier array.
|
|
24
|
+
#
|
|
25
|
+
# It declines where Ruby would not reach `Object` first: a name a core or stdlib ancestor of the class declares
|
|
26
|
+
# (#2196), and a class object whose singleton chain holds a project definer of the name (#2284). On an explicit
|
|
27
|
+
# receiver it answers no private method; `ProjectPatched.explicit_non_self_receiver?` reads the call node for it.
|
|
28
|
+
#
|
|
29
|
+
# The two memos it keeps are `Rigor::TypingState` slots, declared when this file loads. `method_dispatcher.rb`
|
|
30
|
+
# requires it behind every file that declares a slot of its own, which is where the two declarations stood in
|
|
31
|
+
# that file's body, so they keep their place in `Rigor::TypingState.slots`.
|
|
32
|
+
module UserClassFallback
|
|
33
|
+
module_function
|
|
34
|
+
|
|
35
|
+
def try_dispatch(context)
|
|
36
|
+
receiver_type = context.receiver
|
|
37
|
+
environment = context.environment
|
|
38
|
+
call_node = context.call_node
|
|
39
|
+
return nil if environment.nil?
|
|
40
|
+
|
|
41
|
+
fallback_receiver = user_class_fallback_receiver(receiver_type, environment)
|
|
42
|
+
return nil if fallback_receiver.nil?
|
|
43
|
+
return nil if declared_by_external_ancestor?(receiver_type, environment, context)
|
|
44
|
+
return nil if project_singleton_definer?(receiver_type, context)
|
|
45
|
+
|
|
46
|
+
# Preserve the ORIGINAL receiver type as the `self` substitution so `Kernel#dup: () ->
|
|
47
|
+
# self` and other `self`-returning methods route through Object's RBS while still
|
|
48
|
+
# returning the caller's type rather than `Object`. Without this, `base = self.dup`
|
|
49
|
+
# inside a `Bundler::URI::Generic` instance method types `base` as `Object` because
|
|
50
|
+
# `Bundler::URI::Generic` is not in RBS and the fallback's `self` resolves to Object.
|
|
51
|
+
#
|
|
52
|
+
# `public_only:` — when the call has an EXPLICIT, non-`self` receiver
|
|
53
|
+
# (`Favourite.select(...)`), suppress the private `Object`/`Kernel`/`Class` methods the
|
|
54
|
+
# fallback would otherwise resolve. Ruby raises `NoMethodError` for a private method
|
|
55
|
+
# called with an explicit receiver, so resolving `Favourite.select` to the private
|
|
56
|
+
# `Kernel#select` (`-> Array[String]`) is a confidently-wrong type. Implicit-self /
|
|
57
|
+
# `self.`-receiver calls (`puts`, `raise`, `require`) keep resolving — those are the
|
|
58
|
+
# fallback's intended targets.
|
|
59
|
+
RbsDispatch.try_dispatch(
|
|
60
|
+
context.with(
|
|
61
|
+
receiver: fallback_receiver,
|
|
62
|
+
self_type_override: receiver_type,
|
|
63
|
+
public_only: ProjectPatched.explicit_non_self_receiver?(call_node),
|
|
64
|
+
call_node: nil, scope: nil
|
|
65
|
+
)
|
|
66
|
+
)
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
# Issue #2196 — a project class whose ancestry reaches a core or stdlib class before `Object` (`class FL <
|
|
70
|
+
# Array`) answers a name that class declares from that class, not from `Object` / `Kernel`: Ruby dispatches
|
|
71
|
+
# `select { … }` on an `FL` to `Array#select`, never to the private `Kernel#select` (`-> Array[String]`). The
|
|
72
|
+
# ancestor tiers decline such a name where they cannot type it (`RbsDispatch#returns_the_walked_ancestry?`),
|
|
73
|
+
# and the `Object` fallback then fabricated `Kernel#select`'s answer, so `fields.detect { |f| f.errors }` read
|
|
74
|
+
# `f` as `String`. The fallback declines the name instead, which leaves the call `Dynamic[top]`.
|
|
75
|
+
# {ExternalAncestorResolution.resolve} answers nil for a name only `Object`, `Kernel` or `BasicObject` declares,
|
|
76
|
+
# so `puts` and `raise` keep resolving.
|
|
77
|
+
def declared_by_external_ancestor?(receiver_type, environment, context)
|
|
78
|
+
return false unless receiver_type.is_a?(Type::Nominal)
|
|
79
|
+
|
|
80
|
+
scope = context.scope
|
|
81
|
+
return false if scope.nil?
|
|
82
|
+
|
|
83
|
+
class_name = receiver_type.class_name
|
|
84
|
+
method_name = context.method_name
|
|
85
|
+
if MemoAudit.enabled? && MemoAudit.suspended?
|
|
86
|
+
return external_ancestor_declares?(class_name, method_name, scope,
|
|
87
|
+
environment)
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
memo = external_ancestor_memo(scope, environment)
|
|
91
|
+
key = [class_name, method_name]
|
|
92
|
+
if memo.key?(key)
|
|
93
|
+
return MemoAudit.check("user class fallback external ancestor", memo[key], class_name, method_name) do
|
|
94
|
+
external_ancestor_declares?(class_name, method_name, scope, environment)
|
|
95
|
+
end
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
memo[key] = MemoAudit.key_audit("user class fallback external ancestor") do
|
|
99
|
+
external_ancestor_declares?(class_name, method_name, scope, environment)
|
|
100
|
+
end
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
def external_ancestor_declares?(class_name, method_name, scope, environment)
|
|
104
|
+
!ExternalAncestorResolution.resolve(class_name, method_name, :instance,
|
|
105
|
+
scope: scope, environment: environment, record_dependencies: false).nil?
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
# Issue #2284 — a class object whose singleton chain holds a project definer of the name (its own `def
|
|
109
|
+
# self.name`, one a project superclass wrote, an `extend`ed module's `def name`) answers from that definer,
|
|
110
|
+
# not from `Module#name` / `Class#…` on the `Singleton[Object]` fallback: Ruby's singleton ancestry puts
|
|
111
|
+
# every project entry ahead of `Class`. The fallback declines so the typer's singleton-body inference
|
|
112
|
+
# answers the definer's return, or `Dynamic` where the slot is contested and the def may not be the one
|
|
113
|
+
# that runs.
|
|
114
|
+
#
|
|
115
|
+
# The chain walk files the class edge of every entry it passes, so it runs only for a name some project file
|
|
116
|
+
# defines at all ({BlockCallTiming.project_defines_anywhere?}, which files the `defines:<name>` edge either way,
|
|
117
|
+
# #1459). Without it every class-body `private` / `attr_reader` call on a project class would depend on its
|
|
118
|
+
# whole ancestry. The by-name answer is memoised per discovery index; the edge is filed on every call.
|
|
119
|
+
def project_singleton_definer?(receiver_type, context)
|
|
120
|
+
return false unless receiver_type.is_a?(Type::Singleton)
|
|
121
|
+
|
|
122
|
+
scope = context.scope
|
|
123
|
+
return false if scope.nil?
|
|
124
|
+
return false unless project_defines_name?(scope, context.method_name)
|
|
125
|
+
|
|
126
|
+
!scope.singleton_def_through_ancestors(receiver_type.class_name, context.method_name).last.nil?
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
def project_defines_name?(scope, method_name)
|
|
130
|
+
if MemoAudit.enabled? && MemoAudit.suspended?
|
|
131
|
+
return BlockCallTiming.project_defines_anywhere?(method_name,
|
|
132
|
+
scope)
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
memo = defines_name_memo(scope)
|
|
136
|
+
if memo.key?(method_name)
|
|
137
|
+
Analysis::DependencyRecorder.read_missing(:defines, method_name) if Analysis::DependencyRecorder.active?
|
|
138
|
+
return MemoAudit.check("user class fallback defines name", memo[method_name], method_name) do
|
|
139
|
+
BlockCallTiming.project_defines_anywhere?(method_name, scope)
|
|
140
|
+
end
|
|
141
|
+
end
|
|
142
|
+
|
|
143
|
+
memo[method_name] = MemoAudit.key_audit("user class fallback defines name") do
|
|
144
|
+
BlockCallTiming.project_defines_anywhere?(method_name, scope)
|
|
145
|
+
end
|
|
146
|
+
end
|
|
147
|
+
|
|
148
|
+
# ADR-129 WD1 — a run-scoped Memo: one slot keyed on the identity of the discovery index and the environment,
|
|
149
|
+
# the only inputs the name table's answers read.
|
|
150
|
+
DEFINES_NAME_MEMO = TypingState.memo(
|
|
151
|
+
:user_class_fallback_defines_name,
|
|
152
|
+
run_scoped: true, audit: "user class fallback defines name",
|
|
153
|
+
reason: "one [discovery, environment, names] slot keyed on the identities of the discovery " \
|
|
154
|
+
"index and the environment; each name's answer reads only them"
|
|
155
|
+
)
|
|
156
|
+
private_constant :DEFINES_NAME_MEMO
|
|
157
|
+
|
|
158
|
+
# One slot per discovery index and environment, as {#external_ancestor_memo} keeps its own: the answer reads
|
|
159
|
+
# only the frozen discovery tables and the environment's `pre_eval:` patches.
|
|
160
|
+
def defines_name_memo(scope)
|
|
161
|
+
discovery = scope.discovery
|
|
162
|
+
environment = scope.environment
|
|
163
|
+
state = TypingState.current
|
|
164
|
+
slot = state[DEFINES_NAME_MEMO]
|
|
165
|
+
unless slot && slot[0].equal?(discovery) && slot[1].equal?(environment)
|
|
166
|
+
slot = [discovery, environment, {}]
|
|
167
|
+
state[DEFINES_NAME_MEMO] = slot
|
|
168
|
+
end
|
|
169
|
+
slot[2]
|
|
170
|
+
end
|
|
171
|
+
|
|
172
|
+
# ADR-129 WD1 — a run-scoped Memo, keyed as {DEFINES_NAME_MEMO} is.
|
|
173
|
+
EXTERNAL_ANCESTOR_MEMO = TypingState.memo(
|
|
174
|
+
:user_class_fallback_external_ancestor,
|
|
175
|
+
run_scoped: true, audit: "user class fallback external ancestor",
|
|
176
|
+
reason: "one [discovery, environment, answers] slot keyed on the identities of the " \
|
|
177
|
+
"discovery index and the RBS environment, the only inputs the walk reads"
|
|
178
|
+
)
|
|
179
|
+
private_constant :EXTERNAL_ANCESTOR_MEMO
|
|
180
|
+
|
|
181
|
+
# One slot per discovery index and environment, as `RbsDispatch#ancestor_memo_slot` keeps its own: the answer
|
|
182
|
+
# reads only the frozen discovery tables and the RBS environment, and its walk is withheld from dependency
|
|
183
|
+
# recording, so it may be served again for the same pair.
|
|
184
|
+
def external_ancestor_memo(scope, environment)
|
|
185
|
+
discovery = scope.discovery
|
|
186
|
+
state = TypingState.current
|
|
187
|
+
slot = state[EXTERNAL_ANCESTOR_MEMO]
|
|
188
|
+
unless slot && slot[0].equal?(discovery) && slot[1].equal?(environment)
|
|
189
|
+
slot = [discovery, environment, {}]
|
|
190
|
+
state[EXTERNAL_ANCESTOR_MEMO] = slot
|
|
191
|
+
end
|
|
192
|
+
slot[2]
|
|
193
|
+
end
|
|
194
|
+
|
|
195
|
+
def user_class_fallback_receiver(receiver_type, environment)
|
|
196
|
+
case receiver_type
|
|
197
|
+
when Type::Nominal
|
|
198
|
+
# Modules: even when RBS knows the module, an instance method on a mixin-only module
|
|
199
|
+
# (e.g. `PP::ObjectMixin`) observes Kernel / Object methods through every concrete
|
|
200
|
+
# includer's ancestor chain. Route through the `Nominal[Object]` fallback so
|
|
201
|
+
# `self.inspect` / `self.respond_to?` / `self.class` resolve cleanly when the module
|
|
202
|
+
# itself does not declare them.
|
|
203
|
+
known = Rigor::Reflection.rbs_class_known?(receiver_type.class_name, environment: environment)
|
|
204
|
+
return environment.nominal_for_name("Object") if !known || environment.rbs_module?(receiver_type.class_name)
|
|
205
|
+
|
|
206
|
+
nil
|
|
207
|
+
when Type::Singleton
|
|
208
|
+
return nil if Rigor::Reflection.rbs_class_known?(receiver_type.class_name, environment: environment)
|
|
209
|
+
|
|
210
|
+
environment.singleton_for_name("Class")
|
|
211
|
+
end
|
|
212
|
+
end
|
|
213
|
+
end
|
|
214
|
+
end
|
|
215
|
+
end
|
|
216
|
+
end
|