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,247 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "prism"
|
|
4
|
+
|
|
5
|
+
require_relative "../../analysis/dependency_recorder"
|
|
6
|
+
require_relative "../../memo_audit"
|
|
7
|
+
require_relative "../../reflection"
|
|
8
|
+
require_relative "../../type"
|
|
9
|
+
require_relative "../definer_resolution"
|
|
10
|
+
require_relative "../method_dispatcher"
|
|
11
|
+
|
|
12
|
+
module Rigor
|
|
13
|
+
module Inference
|
|
14
|
+
module CallLadder
|
|
15
|
+
# The `user_method` rung of the call ladder (ADR-116 WD12, the first rung with a module of its own): a call on
|
|
16
|
+
# an instance of a project class, answered by re-typing the body of the `def` Ruby calls, with the call's
|
|
17
|
+
# argument types bound. `ExpressionTyper` asks it behind the dispatcher, in each entry `CallLadder::RUNGS` gives
|
|
18
|
+
# it. {ExpressionTyper} is not required here: it requires this file, and `Scope` is loaded before either.
|
|
19
|
+
#
|
|
20
|
+
# Three entries, and every other function is private to the module:
|
|
21
|
+
#
|
|
22
|
+
# - {.try_call} is the rung, asked with the site and the walking typer.
|
|
23
|
+
# - {.infer} is the same question with its arguments as positionals, for a caller that asks this rung alone
|
|
24
|
+
# with arguments that are not a site's: the own-`def` rung, and a receiver's own `send`.
|
|
25
|
+
# - {.user_inference_receiver?} is the rung's gate, a predicate on the receiver type alone. The own-`def`
|
|
26
|
+
# rung's gate, the own-`send` reading and the recursion scan ask it, so it lives here once.
|
|
27
|
+
#
|
|
28
|
+
# The module holds no state. It reads the scope as `typer.scope` (never the site's, which `sig/` leaves
|
|
29
|
+
# untyped) and calls back four methods of the typer: `class_graph_buckets`, `positional_correspondence`,
|
|
30
|
+
# `infer_user_method_return` and `degrade_if_overridable`. `CallLadder::PORT` lists those five names, and
|
|
31
|
+
# `spec/rigor/inference/call_ladder/port_spec.rb` fails a call on the typer that is not one of them. A function
|
|
32
|
+
# that only reads the scope takes it as a parameter and never sees the typer.
|
|
33
|
+
module UserMethod
|
|
34
|
+
module_function
|
|
35
|
+
|
|
36
|
+
# The rung: {.infer} for the call `site` describes. The method name is the site's, not the call node's: the
|
|
37
|
+
# read of `c[k] += v` is a site whose node is the write and whose name is `[]`.
|
|
38
|
+
def try_call(site, typer)
|
|
39
|
+
infer(site.receiver, site.call_node, site.args, site.method_name, site.block_type, typer)
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
# v0.0.2 #5 — re-types the body of a user-defined instance method with the call site's argument types
|
|
43
|
+
# bound to the method's parameters. Used as a last-resort tier after `MethodDispatcher.dispatch` has
|
|
44
|
+
# exhausted its catalogue (RBS, shape, constant folding, user-class fallback). Returns nil when:
|
|
45
|
+
#
|
|
46
|
+
# - the receiver is not `Nominal[T]` for some T;
|
|
47
|
+
# - no def_node is recorded for that class/method (the receiver is foreign or has only an RBS sig);
|
|
48
|
+
# - the def has no body, or has a parameter shape we cannot bind from the call's positional args.
|
|
49
|
+
def infer(receiver, call_node, arg_types, method_name, block_type, typer)
|
|
50
|
+
return nil unless user_inference_receiver?(receiver)
|
|
51
|
+
|
|
52
|
+
def_node, owner, raising = resolve_typing_def_with_owner(receiver.class_name, method_name, typer)
|
|
53
|
+
return every_definer_raises_type(raising, receiver, call_node, arg_types, block_type, typer) if def_node.nil?
|
|
54
|
+
|
|
55
|
+
arg_types, positionals_unknown = typer.positional_correspondence(call_node, arg_types)
|
|
56
|
+
result = typer.infer_user_method_return(def_node, receiver, arg_types,
|
|
57
|
+
self_fold_safe: fold_safe_call_receiver?(call_node, typer.scope),
|
|
58
|
+
yield_type: block_type, positionals_unknown: positionals_unknown)
|
|
59
|
+
return result if result.nil?
|
|
60
|
+
|
|
61
|
+
typer.degrade_if_overridable(result, owner, method_name, :instance)
|
|
62
|
+
rescue StandardError
|
|
63
|
+
nil
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
# #525 — instance-side user-method inference accepts the named ADR-48 member carriers alongside
|
|
67
|
+
# plain nominals: a `Line = Struct.new(...) do ... end` value is a StructInstance whose block defs
|
|
68
|
+
# live under "Line", and the carrier itself is the right `self` for the body (member reads inside
|
|
69
|
+
# the def project through it).
|
|
70
|
+
def user_inference_receiver?(receiver)
|
|
71
|
+
case receiver
|
|
72
|
+
when Type::Nominal then true
|
|
73
|
+
when Type::StructInstance, Type::DataInstance then !receiver.class_name.nil?
|
|
74
|
+
else false
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
# Issue #525 — whether the RECEIVER EXPRESSION of this call is one whose struct member map is still
|
|
79
|
+
# current. Three arms:
|
|
80
|
+
#
|
|
81
|
+
# - a call that MATERIALISES the struct (`Point.new(…)`, `Point[…]`, `Struct.new(:x).new(…)`, a
|
|
82
|
+
# `.with(…)` copy) — the object was created by this very expression, so nothing has run against it;
|
|
83
|
+
# - a local the fold-safe scan proved is never mutated / aliased / escaped;
|
|
84
|
+
# - `nil` / `self`, inheriting the CURRENT body's own grant, which is what lets a chain of
|
|
85
|
+
# implicit-self readers propagate: `Line.new(…).outer` grants `outer`'s body `:self`, and an
|
|
86
|
+
# `inner` call inside it carries the grant into `inner`'s body.
|
|
87
|
+
#
|
|
88
|
+
# The first arm shares `StructFolding`'s materialisation test with the direct member-read gate. Neither
|
|
89
|
+
# accepts a bare chained call: "chained" is not "fresh" once a method can hand back its own receiver,
|
|
90
|
+
# and a self-returning fluent builder is ordinary Ruby:
|
|
91
|
+
#
|
|
92
|
+
# Line = Struct.new(:text) do
|
|
93
|
+
# def with_text(v) = (self.text = v; self)
|
|
94
|
+
# def shout = text.upcase
|
|
95
|
+
# end
|
|
96
|
+
# Line.new("a").with_text("z").shout # runtime "Z"
|
|
97
|
+
#
|
|
98
|
+
# Accepting the `with_text(…)` receiver as fresh would grant `shout` a member map two statements
|
|
99
|
+
# stale and fold `"A"`. Only the shapes the folding layer itself materialises qualify here.
|
|
100
|
+
#
|
|
101
|
+
# This is only a property of the receiver expression; whether the grant is actually issued also needs
|
|
102
|
+
# a `StructInstance` carrier and a body that survives the self-use scan, both decided in
|
|
103
|
+
# {ExpressionTyper#build_user_method_body_scope}.
|
|
104
|
+
def fold_safe_call_receiver?(call_node, scope)
|
|
105
|
+
return false if call_node.nil?
|
|
106
|
+
|
|
107
|
+
case call_node.receiver
|
|
108
|
+
when Prism::CallNode then materialization_call?(call_node.receiver, scope)
|
|
109
|
+
when Prism::LocalVariableReadNode then scope.struct_fold_safe?(call_node.receiver.name)
|
|
110
|
+
when nil, Prism::SelfNode then scope.struct_fold_safe?(:self)
|
|
111
|
+
else false
|
|
112
|
+
end
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
# Issue #595 — the materialisation test lives ONCE, in
|
|
116
|
+
# [`struct_materialization.rb`](../method_dispatcher/struct_materialization.rb), because the direct
|
|
117
|
+
# member-read gate ({MethodDispatcher::StructFolding}`#fresh_receiver?`) needs the identical answer;
|
|
118
|
+
# see {MethodDispatcher::StructMaterialization.materialization_call?}. A `.with` call is never one
|
|
119
|
+
# (`Struct` has no `#with`, #1335), so the test needs no lookup from either consumer.
|
|
120
|
+
def materialization_call?(node, scope)
|
|
121
|
+
MethodDispatcher::StructMaterialization.materialization_call?(node, scope)
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
# ADR-119 C2-b1 — the TYPING read of {ExpressionTyper#resolve_user_def_with_owner}: the same
|
|
125
|
+
# `[def_node, owner]` pair, but answered through {DefinerResolution} so a chain that does not stand for the
|
|
126
|
+
# name (a conditional definer, a conditional include, a fork, an external ancestor that may answer first) is
|
|
127
|
+
# `[nil, nil]` and the call types `Dynamic` instead of from a definer Ruby may not reach. ABSENT is the same
|
|
128
|
+
# `[nil, nil]`: at a typing site "no definer" and "cannot say" both fall through to the rungs below this one.
|
|
129
|
+
# Existence reads ({ExpressionTyper#resolve_user_def_through_ancestors}, the self-purity scan) stay on
|
|
130
|
+
# {ExpressionTyper#resolve_user_def_with_owner}'s memo: an existence read turning false there could ADD a
|
|
131
|
+
# `call.undefined-method` firing.
|
|
132
|
+
#
|
|
133
|
+
# UNKNOWN carries a third element, the `bot` exception's definers ({.every_project_definer}): the def nodes
|
|
134
|
+
# of every project entry on the chain that defines the name, or nil where the exception cannot apply.
|
|
135
|
+
#
|
|
136
|
+
# The memo is the typer's class-graph slot ({ExpressionTyper#class_graph_buckets}), under its `:typing_def`
|
|
137
|
+
# bucket.
|
|
138
|
+
def resolve_typing_def_with_owner(class_name, method_name, typer)
|
|
139
|
+
cache = typer.class_graph_buckets[:typing_def]
|
|
140
|
+
table = (cache[class_name.to_s] ||= {})
|
|
141
|
+
key = method_name.to_sym
|
|
142
|
+
if table.key?(key)
|
|
143
|
+
return MemoAudit.check("class graph typing def", table[key], class_name, key) do
|
|
144
|
+
compute_typing_def_with_owner(class_name, method_name, typer.scope)
|
|
145
|
+
end
|
|
146
|
+
end
|
|
147
|
+
|
|
148
|
+
table[key] = MemoAudit.key_audit("class graph typing def") do
|
|
149
|
+
compute_typing_def_with_owner(class_name, method_name, typer.scope)
|
|
150
|
+
end
|
|
151
|
+
end
|
|
152
|
+
|
|
153
|
+
def compute_typing_def_with_owner(class_name, method_name, scope)
|
|
154
|
+
case DefinerResolution.resolve(scope, class_name, method_name, :instance, question: :definer)
|
|
155
|
+
in DefinerResolution::Known(answer: [node, owner])
|
|
156
|
+
[node, owner]
|
|
157
|
+
in DefinerResolution::UNKNOWN
|
|
158
|
+
[nil, nil, every_project_definer(class_name, method_name, scope)]
|
|
159
|
+
in DefinerResolution::ABSENT
|
|
160
|
+
[nil, nil]
|
|
161
|
+
end
|
|
162
|
+
end
|
|
163
|
+
|
|
164
|
+
# ADR-119 C2-b1 errata (the `bot` exception) — an UNKNOWN chain does not say WHICH definer Ruby calls, but
|
|
165
|
+
# when every project definer of the name on the chain types `bot` (each raises or exits), the call cannot
|
|
166
|
+
# return whichever of them runs, so it types `bot` and a guard such as `fail_with 'no' unless count` still
|
|
167
|
+
# narrows. `defs` is {.every_project_definer}'s list; each is inferred with this call's receiver and
|
|
168
|
+
# arguments, stopping at the first that returns (the answer is then `Dynamic` whatever the rest say).
|
|
169
|
+
# Accepted cost: an RBS-unknown external ahead of them that really defines the name and returns is a
|
|
170
|
+
# narrowing false negative; `bot` reports nothing about a value, and that exposure is master's.
|
|
171
|
+
def every_definer_raises_type(defs, receiver, call_node, arg_types, block_type, typer)
|
|
172
|
+
return nil if defs.nil?
|
|
173
|
+
|
|
174
|
+
self_fold_safe = fold_safe_call_receiver?(call_node, typer.scope)
|
|
175
|
+
arg_types, positionals_unknown = typer.positional_correspondence(call_node, arg_types)
|
|
176
|
+
defs.each do |def_node|
|
|
177
|
+
result = typer.infer_user_method_return(def_node, receiver, arg_types,
|
|
178
|
+
self_fold_safe: self_fold_safe, yield_type: block_type,
|
|
179
|
+
positionals_unknown: positionals_unknown)
|
|
180
|
+
return nil unless result.is_a?(Type::Bot)
|
|
181
|
+
end
|
|
182
|
+
Type::Combinator.bot
|
|
183
|
+
end
|
|
184
|
+
|
|
185
|
+
# The def node of every project entry on `class_name`'s instance chain that defines `method_name`, in any
|
|
186
|
+
# position (the order is what UNKNOWN does not know), or nil where the `bot` exception cannot apply: a cut
|
|
187
|
+
# chain, no project definer, an entry whose only record of the name has no body (an `attr_*` or a
|
|
188
|
+
# `define_method` with no `def`), a definer resting on a `possible` or contested fact (another body may be the
|
|
189
|
+
# one Ruby holds), or an external RBS knows that declares the name. An external RBS does not know is passed
|
|
190
|
+
# over. Only what the tables hold is read: a `define_method` beside an entry's own `def` of the name, and a
|
|
191
|
+
# receiver-form `X.include(M)` outside `X`'s body, are not seen (as on the Known path).
|
|
192
|
+
#
|
|
193
|
+
# ADR-46: the answer depends on every entry, so each files its class edge and its negative class edge (a new
|
|
194
|
+
# file reopening it may add a definer or a mixin), and each project entry's {Scope#user_def_for} files the
|
|
195
|
+
# method edge, positive for a definer and `read_missing(:method, "Owner#name")` for one that lacks the
|
|
196
|
+
# `def`. `DefinerResolution`'s decline filed none of this past the external that stopped it.
|
|
197
|
+
def every_project_definer(class_name, method_name, scope)
|
|
198
|
+
chain = Scope::ResolutionChain.for(scope, class_name.to_s, :instance, :methods)
|
|
199
|
+
chain.record(scope)
|
|
200
|
+
return nil if chain.truncated?
|
|
201
|
+
|
|
202
|
+
defs = []
|
|
203
|
+
declined = false
|
|
204
|
+
chain.entries.uniq.each do |entry|
|
|
205
|
+
if entry.external?
|
|
206
|
+
note_missing_class(entry.raw.to_s.split("::").last)
|
|
207
|
+
declined = true if external_declares?(entry.candidates, method_name, scope)
|
|
208
|
+
next
|
|
209
|
+
end
|
|
210
|
+
note_missing_class(entry.last_segment)
|
|
211
|
+
node = scope.user_def_for(entry.name, method_name)
|
|
212
|
+
defs << node if node
|
|
213
|
+
declined = true if definer_without_single_body?(entry.name, method_name, node, scope)
|
|
214
|
+
end
|
|
215
|
+
declined || defs.empty? ? nil : defs.freeze
|
|
216
|
+
end
|
|
217
|
+
|
|
218
|
+
def note_missing_class(segment)
|
|
219
|
+
Analysis::DependencyRecorder.read_missing(:class, segment) if Analysis::DependencyRecorder.active?
|
|
220
|
+
end
|
|
221
|
+
|
|
222
|
+
def definer_without_single_body?(owner, method_name, node, scope)
|
|
223
|
+
discovery = scope.discovery
|
|
224
|
+
key = [owner, method_name.to_sym]
|
|
225
|
+
(node.nil? && scope.discovered_method?(owner, method_name, :instance)) ||
|
|
226
|
+
discovery.possible_method?(owner, method_name, :instance) ||
|
|
227
|
+
discovery.contested?(:discovered_def_nodes, key)
|
|
228
|
+
end
|
|
229
|
+
|
|
230
|
+
# True where RBS knows one of the names the external's spelling can denote and declares the instance method
|
|
231
|
+
# in it; a lookup that fails counts as declaring (the exception then does not apply).
|
|
232
|
+
def external_declares?(candidates, method_name, scope)
|
|
233
|
+
known = candidates.find { |candidate| Rigor::Reflection.rbs_class_known?(candidate, scope: scope) }
|
|
234
|
+
return false if known.nil?
|
|
235
|
+
|
|
236
|
+
!Rigor::Reflection.instance_method_definition(known, method_name, scope: scope).nil?
|
|
237
|
+
rescue StandardError
|
|
238
|
+
true
|
|
239
|
+
end
|
|
240
|
+
|
|
241
|
+
private_class_method :fold_safe_call_receiver?, :materialization_call?, :resolve_typing_def_with_owner,
|
|
242
|
+
:compute_typing_def_with_owner, :every_definer_raises_type, :every_project_definer,
|
|
243
|
+
:note_missing_class, :definer_without_single_body?, :external_declares?
|
|
244
|
+
end
|
|
245
|
+
end
|
|
246
|
+
end
|
|
247
|
+
end
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Rigor
|
|
4
|
+
module Inference
|
|
5
|
+
# ADR-116 WD12 — the order a call is typed in, declared once.
|
|
6
|
+
#
|
|
7
|
+
# `ExpressionTyper` types a call by asking a *ladder* of *rungs* in order, and the first that answers wins.
|
|
8
|
+
# `MethodDispatcher` is one rung; what it asks inside itself are *tiers*, and their order is its own
|
|
9
|
+
# (`MethodDispatcher.resolve_site`). The typer writes the ladder in full for a call, and a shorter sequence is
|
|
10
|
+
# written for two other *entries*: the read a compound index write performs (`c[k] += v`), in the typer, and the
|
|
11
|
+
# target of a literal `send`, in that rung's module. Sequences copied by hand drift apart (#3358), so the order
|
|
12
|
+
# and each entry's subset are declared here, and `spec/rigor/inference/call_ladder_spec.rb` reads the code with
|
|
13
|
+
# Prism and fails unless every method that can answer from two or more rungs asks them as these tables say.
|
|
14
|
+
#
|
|
15
|
+
# The engine does not load this file. The ladder stays straight-line code, no method is generated from the
|
|
16
|
+
# tables and no rung is wrapped to fit them: ADR-116 rejects a table walked at run time, which would put a
|
|
17
|
+
# megamorphic call on the path every call takes. The tables are for the spec, and for whoever places a rung.
|
|
18
|
+
#
|
|
19
|
+
# To add a rung, add its row to {RUNGS} at its position, naming the entries that ask it, and its call at that
|
|
20
|
+
# position in each of those entries' methods. To move a rung's body out of the typer, change its row's `home`
|
|
21
|
+
# and `asked_as`: the spec takes the spelling of every ask from the row.
|
|
22
|
+
#
|
|
23
|
+
# A rung whose body has moved is a module under `call_ladder/` whose entry is `try_call(site, typer)`. What it
|
|
24
|
+
# may call on that typer is {PORT}, and what it exposes beside `try_call` is {SECOND_ENTRIES}:
|
|
25
|
+
# `spec/rigor/inference/call_ladder/port_spec.rb` holds each rung module to both, and
|
|
26
|
+
# `spec/rigor/inference/call_ladder/reentry_spec.rb` holds every other file away from {REENTRY} and the typer
|
|
27
|
+
# and the rungs away from {DISPATCHER_INTERIOR}. {PUBLIC_CALLBACKS} are in the port and under neither rule of
|
|
28
|
+
# the reentry spec.
|
|
29
|
+
module CallLadder
|
|
30
|
+
# One way the typer asks the ladder. `home` is the constant, as written from `Rigor::Inference`, whose file
|
|
31
|
+
# holds the entry's sequence, and `written_in` the methods there: the first starts the sequence, and each
|
|
32
|
+
# later one continues it from where an earlier one calls it. `ahead` names what may answer in those
|
|
33
|
+
# methods before the first rung is asked: methods of `home`, called with no receiver. Those are not rungs,
|
|
34
|
+
# and nothing else there may answer.
|
|
35
|
+
Entry = Data.define(:name, :home, :written_in, :ahead)
|
|
36
|
+
|
|
37
|
+
# One rung. `asked_by` is the entries that ask it. `home` and `asked_as` spell the ask: a method of `home`,
|
|
38
|
+
# called with no receiver in `home`'s own file and on the constant anywhere else. `in_typer_because` says
|
|
39
|
+
# why the body is still a method of `ExpressionTyper` — the slice of ADR-116 WD12 that moves it, or why it
|
|
40
|
+
# stays — and is nil for a rung whose body has a module of its own.
|
|
41
|
+
Rung = Data.define(:name, :asked_by, :home, :asked_as, :in_typer_because)
|
|
42
|
+
|
|
43
|
+
# A sequence that departs from its entry's rows, and why. With no `written_in` it holds for the entry's
|
|
44
|
+
# own methods and for every branch of them. With one it is a branch: a method the entry's first method
|
|
45
|
+
# returns through, held to what the entry asks ahead of that return and then to the entry's rungs less
|
|
46
|
+
# `omits`, each rung named in `gates` asked through its gate.
|
|
47
|
+
#
|
|
48
|
+
# A row is one of two kinds. Drift is a rung the entry should ask and does not: a defect, recorded against
|
|
49
|
+
# `issue`, whose fix asks the rung and deletes the row. Design has no issue and stays; ADR-116 names the one
|
|
50
|
+
# there is, and another needs an amendment to it. Newly found drift needs only its row and its issue.
|
|
51
|
+
ExceptionRow = Data.define(:name, :entry, :written_in, :omits, :gates, :issue, :because)
|
|
52
|
+
|
|
53
|
+
# A rung asked through its gate: the branch tests `ask`, a second entry at the rung's home, and answers
|
|
54
|
+
# `answer` where it holds, in place of asking the rung.
|
|
55
|
+
Gate = Data.define(:rung, :ask, :answer)
|
|
56
|
+
|
|
57
|
+
TYPER = "ExpressionTyper"
|
|
58
|
+
private_constant :TYPER
|
|
59
|
+
|
|
60
|
+
ENTRIES = Ractor.make_shareable(
|
|
61
|
+
[
|
|
62
|
+
# A call. Indexed and method-chain narrowing answers ahead of the ladder, before the operands are typed.
|
|
63
|
+
Entry.new(name: :call, home: TYPER, written_in: %i[call_result_type_for dispatch_miss_result],
|
|
64
|
+
ahead: %i[indexed_narrowing_for]),
|
|
65
|
+
# The `c[k]` read of `c[k] += v`. It answers nil when the ladder is exhausted, and its caller widens.
|
|
66
|
+
Entry.new(name: :index_read, home: TYPER, written_in: %i[implicit_index_read_type], ahead: []),
|
|
67
|
+
# The target of `recv.send(:name, …)`: the sequence inside the `literal_send` rung, written in its module. A
|
|
68
|
+
# receiver with a `send` of its own is answered ahead of it (`own_send_type`, which asks user-method
|
|
69
|
+
# inference alone).
|
|
70
|
+
Entry.new(name: :send_target, home: "CallLadder::LiteralSend", written_in: %i[try_call],
|
|
71
|
+
ahead: %i[own_send_type])
|
|
72
|
+
]
|
|
73
|
+
)
|
|
74
|
+
|
|
75
|
+
# The rungs, in the order they are asked. `asked_by` is what each entry should ask: where the code leaves a
|
|
76
|
+
# rung out by mistake, the row still names the entry and {EXCEPTIONS} holds the gap against its issue.
|
|
77
|
+
# `send_target` does not ask `refined` by design: a literal `send` of a name refined in effect is answered
|
|
78
|
+
# by the `refined` rung of the call, which sits above `literal_send`.
|
|
79
|
+
RUNGS = Ractor.make_shareable(
|
|
80
|
+
[
|
|
81
|
+
Rung.new(name: :refined, asked_by: %i[call index_read], home: "CallLadder::Refined", asked_as: %i[try_call],
|
|
82
|
+
in_typer_because: nil),
|
|
83
|
+
Rung.new(name: :literal_send, asked_by: %i[call], home: "CallLadder::LiteralSend", asked_as: %i[try_call],
|
|
84
|
+
in_typer_because: nil),
|
|
85
|
+
Rung.new(name: :top_level_def, asked_by: %i[call send_target], home: "CallLadder::TopLevelDef",
|
|
86
|
+
asked_as: %i[try_call], in_typer_because: nil),
|
|
87
|
+
Rung.new(name: :receiver_block_folds, asked_by: %i[call], home: TYPER,
|
|
88
|
+
asked_as: %i[try_receiver_block_folds],
|
|
89
|
+
in_typer_because: "stays: its methods call back eight of block typing's, the cluster #3359 " \
|
|
90
|
+
"decides."),
|
|
91
|
+
Rung.new(name: :overriding_def, asked_by: %i[call index_read send_target], home: "CallLadder::OverridingDef",
|
|
92
|
+
asked_as: %i[try_call], in_typer_because: nil),
|
|
93
|
+
# Two spellings until every entry builds its site once: `dispatch` takes the call's fields as keywords,
|
|
94
|
+
# `dispatch_site` the site.
|
|
95
|
+
Rung.new(name: :dispatcher, asked_by: %i[call index_read send_target], home: "MethodDispatcher",
|
|
96
|
+
asked_as: %i[dispatch dispatch_site], in_typer_because: nil),
|
|
97
|
+
Rung.new(name: :user_method, asked_by: %i[call index_read send_target], home: "CallLadder::UserMethod",
|
|
98
|
+
asked_as: %i[try_call], in_typer_because: nil),
|
|
99
|
+
Rung.new(name: :project_singleton, asked_by: %i[call index_read send_target],
|
|
100
|
+
home: "CallLadder::ProjectSingleton", asked_as: %i[try_call], in_typer_because: nil),
|
|
101
|
+
Rung.new(name: :dynamic_receiver, asked_by: %i[call], home: TYPER,
|
|
102
|
+
asked_as: %i[inherit_receiver_origin],
|
|
103
|
+
in_typer_because: "stays: S3 was dropped. With `non_nil_retry` it is 28 code lines, and the move " \
|
|
104
|
+
"would make `call_dispatch_type_for` public to hide them."),
|
|
105
|
+
Rung.new(name: :non_nil_retry, asked_by: %i[call index_read], home: TYPER,
|
|
106
|
+
asked_as: %i[try_non_nil_receiver_retry],
|
|
107
|
+
in_typer_because: "stays: S3 was dropped, as for `dynamic_receiver`"),
|
|
108
|
+
Rung.new(name: :unresolved, asked_by: %i[call], home: TYPER,
|
|
109
|
+
asked_as: %i[unresolved_call_result],
|
|
110
|
+
in_typer_because: "stays: S9 was dropped. The move would make `fallback_for` public to hide 71 " \
|
|
111
|
+
"code lines.")
|
|
112
|
+
]
|
|
113
|
+
)
|
|
114
|
+
|
|
115
|
+
EXCEPTIONS = Ractor.make_shareable(
|
|
116
|
+
[
|
|
117
|
+
ExceptionRow.new(
|
|
118
|
+
name: :index_read_without_refined, entry: :index_read, written_in: nil, omits: %i[refined], gates: [],
|
|
119
|
+
issue: 3358,
|
|
120
|
+
because: "`h[:a] += v` ignores a refinement of `[]` that `h[:a]` honours. The splat branch is held to " \
|
|
121
|
+
"what the entry asks ahead of it, so the fix asks the rung once, above the return into it."
|
|
122
|
+
),
|
|
123
|
+
ExceptionRow.new(
|
|
124
|
+
name: :index_read_without_non_nil_retry, entry: :index_read, written_in: nil, omits: %i[non_nil_retry],
|
|
125
|
+
gates: [], issue: 3370,
|
|
126
|
+
because: "`h[:a] += 1` on a receiver that may be nil reads `Dynamic[top]` where `h[:a]` reads the member."
|
|
127
|
+
),
|
|
128
|
+
ExceptionRow.new(
|
|
129
|
+
name: :splat_index_read, entry: :index_read, written_in: :splat_index_read_type,
|
|
130
|
+
omits: %i[user_method project_singleton],
|
|
131
|
+
gates: [Gate.new(rung: :overriding_def, ask: :overriding_own_def?, answer: :dynamic_top)], issue: nil,
|
|
132
|
+
because: "a splat index (`c[*keys] += v`) leaves no positional argument types to bind to a body, so " \
|
|
133
|
+
"the rungs that type a body are not asked: the own-`def` rung is asked through its gate " \
|
|
134
|
+
"(`CallLadder::OverridingDef.overriding_own_def?`) and answers `Dynamic[top]`, and only the " \
|
|
135
|
+
"dispatcher follows."
|
|
136
|
+
),
|
|
137
|
+
ExceptionRow.new(
|
|
138
|
+
name: :send_target_without_top_level_def, entry: :send_target, written_in: nil, omits: %i[top_level_def],
|
|
139
|
+
gates: [], issue: 3369,
|
|
140
|
+
because: "`send(:name, …)` on implicit `self` reads the RBS method of that name where `name(…)` reads " \
|
|
141
|
+
"the project's top-level `def`."
|
|
142
|
+
),
|
|
143
|
+
ExceptionRow.new(
|
|
144
|
+
name: :send_target_without_overriding_def, entry: :send_target, written_in: nil,
|
|
145
|
+
omits: %i[overriding_def], gates: [], issue: 3368,
|
|
146
|
+
because: "`x.send(:name)` reads a declaration a project ancestor wrote where `x.name` reads the " \
|
|
147
|
+
"receiver's own `def`."
|
|
148
|
+
)
|
|
149
|
+
]
|
|
150
|
+
)
|
|
151
|
+
|
|
152
|
+
# The typer's re-entry points: methods of `ExpressionTyper` that are public only so that a rung module can call
|
|
153
|
+
# them on the typer it is given, each `@api private`. They run the typer's own code, which reads its cursor
|
|
154
|
+
# (the node `type_of` is typing) and the frames `TypingState` pushes and pops around a body, so they mean
|
|
155
|
+
# something only inside the `type_of` walk that asked the rung. Nothing outside `call_ladder/` calls one on a
|
|
156
|
+
# typer it holds. A slice adds a name here when its rung first needs it, and makes the method public then.
|
|
157
|
+
REENTRY = Ractor.make_shareable(
|
|
158
|
+
%i[
|
|
159
|
+
class_graph_buckets
|
|
160
|
+
positional_correspondence
|
|
161
|
+
infer_user_method_return
|
|
162
|
+
degrade_if_overridable
|
|
163
|
+
resolve_user_def_through_ancestors
|
|
164
|
+
call_result_type_for
|
|
165
|
+
]
|
|
166
|
+
)
|
|
167
|
+
|
|
168
|
+
# The typer's public callbacks: methods of `ExpressionTyper` a rung module may call on its typer that were public
|
|
169
|
+
# before any rung needed them, so that neither the `@api private` mark nor the re-entry rule applies. `type_of`
|
|
170
|
+
# is the typer's own entry, which the statement evaluator, the rules and the plugins call on typers of their own;
|
|
171
|
+
# a rung calls it to type a node of its call. A public callback counts toward the cut-off of four as a re-entry
|
|
172
|
+
# point does, so that a rung typing nodes through it is not cheaper to move than one calling back the typer's
|
|
173
|
+
# private code.
|
|
174
|
+
PUBLIC_CALLBACKS = Ractor.make_shareable(%i[type_of])
|
|
175
|
+
|
|
176
|
+
# The port: every method of the typer a rung module may call on the `typer` it is given, `send` and the
|
|
177
|
+
# other reflective calls being none of them. `scope` reads the frame's scope; a rung reads it there and never
|
|
178
|
+
# from its site, whose `scope` `sig/` leaves untyped. The rest are {PUBLIC_CALLBACKS} and {REENTRY}, and a rung
|
|
179
|
+
# calls back at most four of them. A rung that needs a fifth does not move (ADR-116, the #3318 cut-off): the
|
|
180
|
+
# list is not widened to fit one.
|
|
181
|
+
PORT = Ractor.make_shareable([:scope, *PUBLIC_CALLBACKS, *REENTRY])
|
|
182
|
+
|
|
183
|
+
# A function a rung module exposes beside its rung's `asked_as`, for a caller that asks part of the rung with
|
|
184
|
+
# arguments that are not a site's. `home` is the module, as a rung's `home` is. `given_typer` says whether the
|
|
185
|
+
# entry takes the typer, and so may use {PORT}; one that does not is a function of its arguments alone, and
|
|
186
|
+
# names neither a typer nor a scope. ADR-116's amendment names each entry: a new one is a row here and its
|
|
187
|
+
# name there.
|
|
188
|
+
SecondEntry = Data.define(:home, :name, :given_typer, :because)
|
|
189
|
+
|
|
190
|
+
SECOND_ENTRIES = Ractor.make_shareable(
|
|
191
|
+
[
|
|
192
|
+
SecondEntry.new(
|
|
193
|
+
home: "CallLadder::UserMethod", name: :infer, given_typer: true,
|
|
194
|
+
because: "the own-`def` rung and a receiver's own `send` ask this rung alone, with a method name and " \
|
|
195
|
+
"argument types that are not their site's, so it takes them as positionals."
|
|
196
|
+
),
|
|
197
|
+
SecondEntry.new(
|
|
198
|
+
home: "CallLadder::UserMethod", name: :user_inference_receiver?, given_typer: false,
|
|
199
|
+
because: "the rung's gate, a predicate on the receiver type. The own-`def` rung's gate, the own-`send` " \
|
|
200
|
+
"reading and the recursion scan ask it too, so it moved with the rung: left in the typer it " \
|
|
201
|
+
"was the rung's fifth callback."
|
|
202
|
+
),
|
|
203
|
+
SecondEntry.new(
|
|
204
|
+
home: "CallLadder::OverridingDef", name: :overriding_own_def?, given_typer: true,
|
|
205
|
+
because: "the rung's gate, which the read under a splat index asks in place of the rung (the design row " \
|
|
206
|
+
"`splat_index_read` of EXCEPTIONS), so it moved with the rung. It reads the scope and the RBS " \
|
|
207
|
+
"definition, so it is given the typer."
|
|
208
|
+
)
|
|
209
|
+
]
|
|
210
|
+
)
|
|
211
|
+
|
|
212
|
+
# The dispatcher's interior: entries of `MethodDispatcher` that only the dispatcher and the tiers that dispatch
|
|
213
|
+
# again call (`MethodDispatcher::ProjectPatched`, `MethodDispatcher::CompositeReceiver`). They skip the records
|
|
214
|
+
# `dispatch_site` makes after an answer, so the typer and the rung modules ask the dispatcher by its row's
|
|
215
|
+
# `asked_as` and never by one of these.
|
|
216
|
+
DISPATCHER_INTERIOR = Ractor.make_shareable(%i[resolve resolve_site])
|
|
217
|
+
end
|
|
218
|
+
end
|
|
219
|
+
end
|
|
@@ -43,7 +43,7 @@ module Rigor
|
|
|
43
43
|
# parameter to a new object (`h = h.dup`): a node that starts after it no longer reaches the caller's argument,
|
|
44
44
|
# read as `StatementEvaluator#after_rebind?` reads it.
|
|
45
45
|
#
|
|
46
|
-
# {
|
|
46
|
+
# {.handed_aliases} answers the parameters a read may be (not a part of), so a hand-off of an alias (`poke(other)`)
|
|
47
47
|
# is followed as the parameter's own hand-off.
|
|
48
48
|
module CalleeWriteCensus
|
|
49
49
|
# `written` is the parameter names written; `alias_table` maps a key (`[local, level]`, `[ivar, :ivar]` or
|
|
@@ -620,7 +620,7 @@ module Rigor
|
|
|
620
620
|
|
|
621
621
|
private
|
|
622
622
|
|
|
623
|
-
# The names {
|
|
623
|
+
# The names {.handed_aliases} can answer for: every key's name.
|
|
624
624
|
def alias_names(table)
|
|
625
625
|
names = Set.new
|
|
626
626
|
table.each_key { |key| names << key.first }
|
|
@@ -18,7 +18,7 @@ module Rigor
|
|
|
18
18
|
# The outer locals a block body can REBIND — the one name set that ADR-56's captured-local write-back
|
|
19
19
|
# (`StatementEvaluator#write_back_block_captures`), the escaping-block narrowing drop
|
|
20
20
|
# (`StatementEvaluator#drop_captured_narrowing`) and issue #587's per-element fold
|
|
21
|
-
# (`ExpressionTyper#per_element_captured_bindings`) all key on. It lives in one place so the
|
|
21
|
+
# (`ExpressionTyper#per_element_captured_bindings`) all key on. It lives in one place so the three
|
|
22
22
|
# cannot disagree about what "captured" means.
|
|
23
23
|
#
|
|
24
24
|
# A write counts across every local-write form — plain `=` (`LocalVariableWriteNode`), the operator /
|
|
@@ -512,7 +512,7 @@ module Rigor
|
|
|
512
512
|
# The index arm spells {INDEX_STORE_NODES} out rather than splatting it: `when *ARRAY` copies the array
|
|
513
513
|
# on every evaluation, and this runs once per node of every scanned block body, which cost `rigor check`
|
|
514
514
|
# about 126K allocations over the v0.3.9 `lib` ([#1502](https://github.com/rigortype/rigor/issues/1502),
|
|
515
|
-
# the shape `
|
|
515
|
+
# the shape `DeclarationWalk::Rules::META_CONSTANT_WRITE_NODES` records). Keep the arm and the list in step.
|
|
516
516
|
def mutated_receiver(node)
|
|
517
517
|
case node
|
|
518
518
|
when Prism::CallNode then node.receiver if MutationWidening::SHAPE_MUTATORS.include?(node.name)
|
|
@@ -4,7 +4,10 @@ require "prism"
|
|
|
4
4
|
|
|
5
5
|
require_relative "../source/node_children"
|
|
6
6
|
require_relative "../type"
|
|
7
|
+
require_relative "alias_mutation_floor"
|
|
7
8
|
require_relative "captured_locals"
|
|
9
|
+
require_relative "opaque_mutation"
|
|
10
|
+
require_relative "unknown_store_widening"
|
|
8
11
|
|
|
9
12
|
module Rigor
|
|
10
13
|
module Inference
|
|
@@ -64,6 +67,65 @@ module Rigor
|
|
|
64
67
|
widened.equal?(scope) ? nil : widened
|
|
65
68
|
end
|
|
66
69
|
|
|
70
|
+
# Issue #3340 — `scope`, the entry of `node`'s rescue chain, past what the `begin` body may have done to the
|
|
71
|
+
# objects its locals hold: a clause runs after the body raised from any point, and an in-place mutation rebinds
|
|
72
|
+
# nothing, so {.widen} does not see it. Each local the body mutates in place
|
|
73
|
+
# (`CapturedLocals.loop_content_mutations`) reads what it can hold after any prefix of the body ran
|
|
74
|
+
# ({.past_any_prefix}), and each local the body hands to unread code, or mutates through a literal `send`, a
|
|
75
|
+
# `Method` object or a symbol block, takes one unknown store ({OpaqueMutation.floor_reached}). `scope` itself
|
|
76
|
+
# for a `begin` with no rescue clause. A body that can mutate nothing `scope` binds
|
|
77
|
+
# ({CapturedLocals.may_touch_capture?}, an allocation-free scan) skips the first half, and a scope that binds
|
|
78
|
+
# no literal shape the second.
|
|
79
|
+
def content_entry(scope, node)
|
|
80
|
+
body = node.statements
|
|
81
|
+
return scope unless node.rescue_clause && body
|
|
82
|
+
|
|
83
|
+
if CapturedLocals.may_touch_capture?(body, scope)
|
|
84
|
+
scope = CapturedLocals.loop_content_mutations(body, scope).reduce(scope) do |acc, (name, sites)|
|
|
85
|
+
type = acc.local(name)
|
|
86
|
+
type.nil? ? acc : acc.with_mutated_local(name, past_any_prefix(type, sites, body, name))
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
return scope unless AliasMutationFloor.local_besides?(scope, nil) { |t| AliasMutationFloor.literal_shape?(t) }
|
|
90
|
+
|
|
91
|
+
OpaqueMutation.floor_reached(body, scope)
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
# A closed hash shape the body does nothing to but remove from keeps its shape with every key optional
|
|
95
|
+
# ({AliasMutationFloor.removed_keys_shape}): nothing was stored, and a read of a key the body may have deleted
|
|
96
|
+
# still answers its `nil`, so `h.delete(k); raise` then `h[k].x` in the clause reports. That holds only where
|
|
97
|
+
# the removers are everything the body does with the local ({.only_removed?}). Any other binding takes the
|
|
98
|
+
# unknown store of every site, with the gradual arm where its contents stay value-pinned, as a loop body's
|
|
99
|
+
# later pass enters (`StatementEvaluator#unknown_store_binding`).
|
|
100
|
+
def past_any_prefix(type, sites, body, name)
|
|
101
|
+
if type.is_a?(Type::HashShape) && only_removed?(body, name, sites)
|
|
102
|
+
shape = AliasMutationFloor.removed_keys_shape(type, sites.first.name)
|
|
103
|
+
return shape if shape
|
|
104
|
+
end
|
|
105
|
+
widened = UnknownStoreWidening.widen(type, sites)
|
|
106
|
+
UnknownStoreWidening.value_pinned_collection?(widened) ? UnknownStoreWidening.gradual_content(widened) : widened
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
# True when every read of the local `name` under `body` is the receiver of one of `sites`, each a blockless
|
|
110
|
+
# remover or reorderer called on the local itself. Any other mention may reach the object another way: a
|
|
111
|
+
# `send`, a `yield`, an alias, an element read, a remover's own block (whose parameters are the values), an
|
|
112
|
+
# argument. Then the body may have stored, and the shape's value pins do not stand.
|
|
113
|
+
def only_removed?(body, name, sites)
|
|
114
|
+
sites.all? { |site| own_remover?(site, name) } && mentions_of(body, name) == sites.size
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
def own_remover?(site, name)
|
|
118
|
+
site.is_a?(Prism::CallNode) && UnknownStoreWidening::VALUE_PRESERVING.include?(site.name) &&
|
|
119
|
+
site.block.nil? && site.receiver.is_a?(Prism::LocalVariableReadNode) && site.receiver.name == name
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
# How many times `node` reads or writes the local `name`, at any depth.
|
|
123
|
+
def mentions_of(node, name)
|
|
124
|
+
count = MENTION_NODES.include?(node.class) && node.name == name ? 1 : 0
|
|
125
|
+
node.rigor_each_child { |child| count += mentions_of(child, name) }
|
|
126
|
+
count
|
|
127
|
+
end
|
|
128
|
+
|
|
67
129
|
# `counts` with each write under `node` counted.
|
|
68
130
|
def count_writes(node, counts)
|
|
69
131
|
return counts if SCOPE_BODY_NODES.any? { |klass| node.is_a?(klass) }
|
|
@@ -84,7 +146,7 @@ module Rigor
|
|
|
84
146
|
node.rigor_each_child { |child| found = mentions(child, among, found) }
|
|
85
147
|
found
|
|
86
148
|
end
|
|
87
|
-
private_class_method :count_writes, :mentions
|
|
149
|
+
private_class_method :count_writes, :mentions, :past_any_prefix, :only_removed?, :own_remover?, :mentions_of
|
|
88
150
|
end
|
|
89
151
|
end
|
|
90
152
|
end
|