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
|
@@ -14,7 +14,7 @@ module Rigor
|
|
|
14
14
|
# gathers those as-written names breadth-first over the project ancestry; this module resolves each
|
|
15
15
|
# group against the RBS environment and reports WHICH declaration answered, not merely that one did.
|
|
16
16
|
#
|
|
17
|
-
# The logic existed twice before: `
|
|
17
|
+
# The logic existed twice before: `CallLadder::TopLevelDef.rbs_ancestor_answers?` asked it as a boolean (the
|
|
18
18
|
# implicit-self binding veto of issue #633 / ADR-110), and the dispatch side of #527 needs the same
|
|
19
19
|
# walk but wants the definition and its owner so it can dispatch there. Two copies of an MRO cut-off
|
|
20
20
|
# rule is one copy too many, so the boolean is now `!resolve(...).nil?`.
|
|
@@ -91,7 +91,7 @@ module Rigor
|
|
|
91
91
|
end
|
|
92
92
|
|
|
93
93
|
# True when the RBS declaration found for the name sits on `class_name` itself rather than on an
|
|
94
|
-
# ancestor; mirrors `CheckRules
|
|
94
|
+
# ancestor; mirrors `CheckRules::OverrideSupport.defined_on?` and `SigGen::Generator#declared_on_class_itself?`.
|
|
95
95
|
def declared_on_class?(definition, class_name)
|
|
96
96
|
return false if definition.nil?
|
|
97
97
|
return false unless definition.respond_to?(:defined_in)
|
|
@@ -16,6 +16,7 @@ module Rigor
|
|
|
16
16
|
# - family: :prism for real Prism nodes, :virtual for nodes that include Rigor::AST::Node.
|
|
17
17
|
# - inner_type: the Rigor::Type returned to the caller (currently always Dynamic[Top]; later slices may
|
|
18
18
|
# carry richer fallback types).
|
|
19
|
+
# - origin: the {DynamicOrigin} cause the typer attributed to the fallback, or nil when it recorded none.
|
|
19
20
|
class Fallback < Data.define(:node_class, :location, :family, :inner_type, :origin)
|
|
20
21
|
def initialize(node_class:, location:, family:, inner_type:, origin: nil)
|
|
21
22
|
raise ArgumentError, "node_class must be a Class, got #{node_class.class}" unless node_class.is_a?(Class)
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "../type"
|
|
4
|
+
require_relative "multi_target_binder"
|
|
5
|
+
require_relative "method_dispatcher"
|
|
6
|
+
|
|
7
|
+
module Rigor
|
|
8
|
+
module Inference
|
|
9
|
+
# Issue #3265 — the slot types a multi-target or splat `for` index (`for a, *s in e`) reads from an `each`
|
|
10
|
+
# whose block receives a varying number of values: one declaring optional, rest or trailing positionals
|
|
11
|
+
# (`{ (Symbol, *Integer) -> void }`). A fixed-arity block yields a value list the `for` path types as one
|
|
12
|
+
# tuple; a varying one has no tuple, and the closed tuple of its leading positionals bound `s` to `[]`.
|
|
13
|
+
#
|
|
14
|
+
# `for` assigns what the block receives as `index = values`, where `values` is the one yielded value, or the
|
|
15
|
+
# array of all of them when the block receives more than one. So:
|
|
16
|
+
#
|
|
17
|
+
# - a front slot inside the required positionals reads that positional's type; every value list starts
|
|
18
|
+
# with them;
|
|
19
|
+
# - the rest reads `Array` of everything that can land there: the required positionals from its start on
|
|
20
|
+
# and every optional, rest and trailing one;
|
|
21
|
+
# - a back slot reads its trailing positional when every value list is long enough to keep it apart from
|
|
22
|
+
# the fronts;
|
|
23
|
+
# - every other slot reads `Dynamic[top]`, never `nil`: a slot past the required positionals holds a value
|
|
24
|
+
# or `nil` depending on how many values the block received.
|
|
25
|
+
#
|
|
26
|
+
# When the block may receive a single value (fewer than two required and trailing positionals), Ruby
|
|
27
|
+
# destructures that value itself, so the slots above hold only when no declared type has an implicit
|
|
28
|
+
# `to_ary` ({MethodDispatcher::RbsDispatch.array_conversion_free?}); otherwise {.slots} answers nil and the
|
|
29
|
+
# index binds the `Dynamic[top]` floor.
|
|
30
|
+
#
|
|
31
|
+
# `StatementEvaluator` asks {.element_type} for the value a multi-target or splat index binds from, and hands
|
|
32
|
+
# {.bind} back to it when that value is a signature; {.bind} binds each slot through the evaluator's own
|
|
33
|
+
# single-index binder, the block it is given.
|
|
34
|
+
module ForYieldSlots
|
|
35
|
+
module_function
|
|
36
|
+
|
|
37
|
+
# The value a multi-target or splat index over `coll_type`'s declared `each` binds from: the tuple of a
|
|
38
|
+
# fixed-arity block's positionals (its one positional alone), the signature of any other block, or
|
|
39
|
+
# `structural` when the block declares no positional.
|
|
40
|
+
#
|
|
41
|
+
# A block that declares a keyword receives it as a trailing positional Hash (`yield :s, k: "x"` binds
|
|
42
|
+
# `for a, b` to `b = {k: "x"}`), which no positional slot states, so the whole index binds `Dynamic[top]`.
|
|
43
|
+
def element_type(coll_type, structural, scope)
|
|
44
|
+
signature = MethodDispatcher.expected_block_signature(
|
|
45
|
+
receiver_type: coll_type, method_name: :each, arg_types: [], environment: scope.environment, scope: scope
|
|
46
|
+
)
|
|
47
|
+
return structural if signature.nil?
|
|
48
|
+
return Type::Combinator.untyped if signature.keywords
|
|
49
|
+
return signature unless signature.fixed_arity?
|
|
50
|
+
|
|
51
|
+
params = signature.required
|
|
52
|
+
return structural if params.empty?
|
|
53
|
+
|
|
54
|
+
params.size == 1 ? params.first : Type::Combinator.tuple_of(*params)
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def signature?(value) = value.is_a?(MethodDispatcher::RbsDispatch::BlockSignature)
|
|
58
|
+
|
|
59
|
+
# Binds `index_node` (a `MultiTargetNode` or a bare `SplatNode`) from `signature`, each slot through
|
|
60
|
+
# `bind_one.(target, type, scope)`. Where {.slots} cannot read the slots, the whole index binds `Dynamic[top]`.
|
|
61
|
+
def bind(index_node, signature, scope, &bind_one)
|
|
62
|
+
lefts, rest, rights =
|
|
63
|
+
if index_node.is_a?(Prism::SplatNode)
|
|
64
|
+
[[], index_node, []]
|
|
65
|
+
else
|
|
66
|
+
[index_node.lefts, index_node.rest, index_node.rights]
|
|
67
|
+
end
|
|
68
|
+
fronts, rest_type, backs = slots(signature, lefts.size, rights.size, scope)
|
|
69
|
+
return bind_one.call(index_node, Type::Combinator.untyped, scope) if fronts.nil?
|
|
70
|
+
|
|
71
|
+
scope = lefts.each_with_index.reduce(scope) { |acc, (target, i)| bind_one.call(target, fronts[i], acc) }
|
|
72
|
+
scope = bind_rest(rest, rest_type, scope, &bind_one) if rest
|
|
73
|
+
rights.each_with_index.reduce(scope) { |acc, (target, i)| bind_one.call(target, backs[i], acc) }
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
# A variable rest binds the rest type; any other splat (`*h[:a]`, `*x.r`) binds as a bare splat index of
|
|
77
|
+
# `Dynamic[top]`, which widens its receiver. An implicit rest (`for a, in`) binds nothing.
|
|
78
|
+
def bind_rest(rest, rest_type, scope, &bind_one)
|
|
79
|
+
return scope unless rest.is_a?(Prism::SplatNode)
|
|
80
|
+
|
|
81
|
+
case rest.expression
|
|
82
|
+
when Prism::LocalVariableTargetNode, Prism::InstanceVariableTargetNode,
|
|
83
|
+
Prism::ClassVariableTargetNode, Prism::GlobalVariableTargetNode
|
|
84
|
+
bind_one.call(rest.expression, rest_type, scope)
|
|
85
|
+
else
|
|
86
|
+
bind_one.call(rest, Type::Combinator.untyped, scope)
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
# The `signature` must not be fixed-arity.
|
|
91
|
+
# @return `[fronts, rest, backs]`, or nil when the slots cannot be read.
|
|
92
|
+
def slots(signature, front_count, back_count, scope)
|
|
93
|
+
required = signature.required
|
|
94
|
+
trailing = signature.trailing
|
|
95
|
+
always = required.size + trailing.size
|
|
96
|
+
return nil if always < 2 && !all_conversion_free?(signature, scope)
|
|
97
|
+
|
|
98
|
+
untyped = Type::Combinator.untyped
|
|
99
|
+
fronts = Array.new(front_count) { |i| required.fetch(i, untyped) }
|
|
100
|
+
backs =
|
|
101
|
+
if back_count <= trailing.size && front_count + back_count <= always
|
|
102
|
+
trailing.last(back_count)
|
|
103
|
+
else
|
|
104
|
+
Array.new(back_count) { untyped }
|
|
105
|
+
end
|
|
106
|
+
[fronts, rest_type(signature, front_count), backs]
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
# Every value at or past position `front_count` is one of the required positionals from there on or an
|
|
110
|
+
# optional, rest or trailing one, so the rest holds `Array` of their union wherever its back slots cut it.
|
|
111
|
+
def rest_type(signature, front_count)
|
|
112
|
+
element = Type::Combinator.union(*signature.required.drop(front_count), *signature.optional,
|
|
113
|
+
*[signature.rest].compact, *signature.trailing)
|
|
114
|
+
Type::Combinator.nominal_of("Array", type_args: [element])
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
def all_conversion_free?(signature, scope)
|
|
118
|
+
types = [*signature.required, *signature.optional, *[signature.rest].compact, *signature.trailing]
|
|
119
|
+
types.all? do |type|
|
|
120
|
+
class_name = MultiTargetBinder.conversion_class_name(type)
|
|
121
|
+
!class_name.nil? && MethodDispatcher::RbsDispatch.array_conversion_free?(class_name, scope)
|
|
122
|
+
end
|
|
123
|
+
end
|
|
124
|
+
end
|
|
125
|
+
end
|
|
126
|
+
end
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "prism"
|
|
4
|
+
|
|
5
|
+
require_relative "external_ancestor_resolution"
|
|
6
|
+
|
|
7
|
+
module Rigor
|
|
8
|
+
module Inference
|
|
9
|
+
# Whether a receiver's `send` is `Kernel#send`, the reflective call, rather than a method of the same name a
|
|
10
|
+
# class defines for itself (`Mailer#send(message, flags)`, `UDPSocket#send(msg, flags)`). ADR-132 WD3: a
|
|
11
|
+
# consumer that reads `recv.send(:m, …)` as `recv.m(…)` may do so only where the `send` is genuine, and
|
|
12
|
+
# falls back to the ordinary call otherwise (issues #3080, #3081).
|
|
13
|
+
#
|
|
14
|
+
# `__send__` and `public_send` are separate methods and are not asked about here: their consumers keep the
|
|
15
|
+
# reflective reading.
|
|
16
|
+
#
|
|
17
|
+
# A receiver is genuine when no project class or module on its chain defines `send` in source, and the RBS
|
|
18
|
+
# declaration Ruby reaches (on the class, or through the project's ancestry to an external one) is
|
|
19
|
+
# `Kernel`'s or `BasicObject`'s. A receiver the engine cannot see into — `Dynamic`, `top`, a literal or
|
|
20
|
+
# shape carrier — keeps the reflective reading it had before this check.
|
|
21
|
+
module GenuineSend
|
|
22
|
+
GENUINE_OWNERS = Set["::Kernel", "::BasicObject"].freeze
|
|
23
|
+
private_constant :GENUINE_OWNERS
|
|
24
|
+
|
|
25
|
+
module_function
|
|
26
|
+
|
|
27
|
+
# True when every member of `receiver_type` reaches the genuine `send`.
|
|
28
|
+
def type?(receiver_type, scope)
|
|
29
|
+
case receiver_type
|
|
30
|
+
when Type::Union then receiver_type.members.all? { |member| type?(member, scope) }
|
|
31
|
+
when Type::Nominal, Type::StructInstance, Type::DataInstance
|
|
32
|
+
class_side?(receiver_type.class_name, :instance, scope)
|
|
33
|
+
when Type::Singleton then class_side?(receiver_type.class_name, :singleton, scope)
|
|
34
|
+
else true
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
# True when the `send` a call with receiver `receiver_node` reaches is genuine, judged in `scope` (the scope
|
|
39
|
+
# the call is typed in). An implicit or `self` receiver reads the scope's `self`; any other receiver is typed
|
|
40
|
+
# in `scope` only when `typed:` (a caller holding another node's scope passes false, and the answer is then
|
|
41
|
+
# false: nothing proves the `send` genuine). No scope proves nothing either.
|
|
42
|
+
def call?(receiver_node, scope, typed: true)
|
|
43
|
+
return false if scope.nil?
|
|
44
|
+
|
|
45
|
+
receiver_type =
|
|
46
|
+
case receiver_node
|
|
47
|
+
when nil, Prism::SelfNode then scope.self_type || Type::Combinator.nominal_of("Object")
|
|
48
|
+
else
|
|
49
|
+
return false unless typed
|
|
50
|
+
|
|
51
|
+
scope.type_of(receiver_node)
|
|
52
|
+
end
|
|
53
|
+
!receiver_type.nil? && type?(receiver_type, scope)
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def class_side?(class_name, kind, scope)
|
|
57
|
+
return true if class_name.nil? || scope.nil?
|
|
58
|
+
return false unless project_definer(class_name, kind, scope).nil?
|
|
59
|
+
|
|
60
|
+
rbs_genuine?(class_name, kind, scope)
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
# True when the RBS declaration of `send` Ruby reaches on `class_name`'s `kind` side, on the class or through
|
|
64
|
+
# the project's ancestry to an external one, is `Kernel`'s or `BasicObject`'s, or when none is found. The
|
|
65
|
+
# typer asks this alone before letting a project `def send` body answer: a project RBS `def send:` is the
|
|
66
|
+
# contract and outranks the body, as it does for any other method.
|
|
67
|
+
def rbs_genuine?(class_name, kind, scope)
|
|
68
|
+
definition = ExternalAncestorResolution.method_definition(class_name, :send, kind, scope: scope)
|
|
69
|
+
definition ||= ExternalAncestorResolution.resolve(class_name, :send, kind, scope: scope)&.first
|
|
70
|
+
definition.nil? || genuine_definition?(definition)
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
# True when the `send` declaration is implemented in `Kernel` / `BasicObject`. `defined_in` alone is not
|
|
74
|
+
# enough: an overload a class adds (`def send: (String, Integer) -> Integer | ...`) keeps `Kernel` as the
|
|
75
|
+
# method's `defined_in` while `implemented_in` names the class. An overload a reopened `module Kernel` adds
|
|
76
|
+
# stays genuine.
|
|
77
|
+
def genuine_definition?(definition)
|
|
78
|
+
GENUINE_OWNERS.include?((definition.implemented_in || definition.defined_in).to_s)
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
# The project `def send` Ruby reaches on `class_name`'s `kind` side, or nil.
|
|
82
|
+
def project_definer(class_name, kind, scope)
|
|
83
|
+
if kind == :singleton
|
|
84
|
+
scope.singleton_def_through_ancestors(class_name, :send).first
|
|
85
|
+
else
|
|
86
|
+
scope.user_def_through_ancestors(class_name, :send).first
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
private_class_method :class_side?, :project_definer, :genuine_definition?
|
|
90
|
+
end
|
|
91
|
+
end
|
|
92
|
+
end
|
|
@@ -112,8 +112,8 @@ module Rigor
|
|
|
112
112
|
# `defines:write`, `refines:write`, `defines_any`, `refines_any`, and `main_mixin` for every top-level mixin: its
|
|
113
113
|
# reader asks about each, and one shared key is a deliberate precision trade-off (a mixin moving anywhere
|
|
114
114
|
# re-checks every write that read them). The rules that read the census record these keys
|
|
115
|
-
# (`
|
|
116
|
-
# every entry that appeared in or vanished from a file's census.
|
|
115
|
+
# (`SpecialGlobalWrite.record_global_census`), and `Analysis::Incremental.changed_global_census_keys` fires
|
|
116
|
+
# them for every entry that appeared in or vanished from a file's census.
|
|
117
117
|
def dependency_key(entry)
|
|
118
118
|
case entry
|
|
119
119
|
when DEFINES_ANY then "defines_any"
|
|
@@ -26,6 +26,8 @@ module Rigor
|
|
|
26
26
|
# - {Union} — N-ary union of arms.
|
|
27
27
|
# - {NominalApp} — parameterised nominal class (`Array[X]`, `Hash[K, V]`) whose type args are
|
|
28
28
|
# themselves body nodes.
|
|
29
|
+
# - {Conditional}, {TestSubtype}, {TestEquality}, {TestMembership} — the ADR-20 § D3 conditional form and
|
|
30
|
+
# its three tests.
|
|
29
31
|
#
|
|
30
32
|
# Every node is a frozen `Data.define` value; structural equality is by-field.
|
|
31
33
|
module HktBody
|
|
@@ -129,8 +129,8 @@ module Rigor
|
|
|
129
129
|
# `M = Module.new do … end`: the block's `self` is the module the write names, so a `refine` in it refines
|
|
130
130
|
# for `M`. The write's other parts walk as they would anyway.
|
|
131
131
|
def walked_meta_new_write?(node, prefix, body, in_def, context)
|
|
132
|
-
call =
|
|
133
|
-
return false if call.nil? || !
|
|
132
|
+
call = DeclarationWalk::Rules.meta_new_block_call(node)
|
|
133
|
+
return false if call.nil? || !DeclarationWalk::Rules.module_new_call?(call)
|
|
134
134
|
|
|
135
135
|
named = meta_new_owner(node, prefix)
|
|
136
136
|
walk(call.receiver, prefix, body, in_def, context) if call.receiver
|
|
@@ -21,10 +21,10 @@ module Rigor
|
|
|
21
21
|
# value it stores comes from the construct that owns it — a multi-assign slot (`h[:a], z = 1, 2`), a `for` index
|
|
22
22
|
# (`for h[:a] in xs`, alone, splatted or in a multi-target) or a rescue reference (`rescue => h[:e]`). Only that
|
|
23
23
|
# construct can type the value, so `StatementEvaluator#eval_multi_write`, `#bind_for_index` and
|
|
24
|
-
#
|
|
25
|
-
# {MultiTargetBinder} decomposed for it, the element or the rescued exception. {CONTENT_WRITE_NODE_CLASSES}
|
|
26
|
-
# it for the nested-block write-back, and `ScopeIndexer`'s pre-pass, which needs no stored value, names the
|
|
27
|
-
# next to {NODE_CLASSES}.
|
|
24
|
+
# `PatternBindings.bind_rescue_reference` observe the straight-line write, passing each target to {.widen} with the
|
|
25
|
+
# slot {MultiTargetBinder} decomposed for it, the element or the rescued exception. {CONTENT_WRITE_NODE_CLASSES}
|
|
26
|
+
# adds it for the nested-block write-back, and `ScopeIndexer`'s pre-pass, which needs no stored value, names the
|
|
27
|
+
# class next to {NODE_CLASSES}.
|
|
28
28
|
module IndexWriteWidening
|
|
29
29
|
NODE_CLASSES = [Prism::IndexOrWriteNode, Prism::IndexAndWriteNode, Prism::IndexOperatorWriteNode].freeze
|
|
30
30
|
|
|
@@ -40,7 +40,7 @@ module Rigor
|
|
|
40
40
|
# - An intervening mutator from {MutationWidening::SHAPE_MUTATORS} runs against the receiver
|
|
41
41
|
# (e.g. `params.delete(:f)`, `params.clear`, `params.default = 0`, `buf.delete_prefix!("x")`).
|
|
42
42
|
#
|
|
43
|
-
#
|
|
43
|
+
# The last two are implemented in `StatementEvaluator#eval_call`'s post-dispatch path through
|
|
44
44
|
# {.invalidate_after_call}.
|
|
45
45
|
module IndexedNarrowing
|
|
46
46
|
# Literal Prism nodes whose Ruby value the analyzer trusts as a stable address. Symbol /
|
|
@@ -6,6 +6,7 @@ require_relative "../type"
|
|
|
6
6
|
require_relative "reflective_ivar_write"
|
|
7
7
|
require_relative "refined_dispatch/own_method"
|
|
8
8
|
require_relative "self_call_ivar_writes"
|
|
9
|
+
require_relative "unknown_store_widening"
|
|
9
10
|
|
|
10
11
|
module Rigor
|
|
11
12
|
module Inference
|
|
@@ -170,9 +171,16 @@ module Rigor
|
|
|
170
171
|
end
|
|
171
172
|
return scope if calls.empty?
|
|
172
173
|
|
|
173
|
-
|
|
174
|
+
widen_past(calls, scope)
|
|
174
175
|
end
|
|
175
176
|
|
|
177
|
+
# {.widen} past `calls`, under `mark: true`, over the names they are proven to write and the contents they are
|
|
178
|
+
# proven to mutate ({.proven_effects}), or over every name when one of them is not proven.
|
|
179
|
+
def widen_past(calls, scope)
|
|
180
|
+
widen(scope, mark: true) { proven_effects(calls, scope) }
|
|
181
|
+
end
|
|
182
|
+
private_class_method :widen_past
|
|
183
|
+
|
|
176
184
|
# `scope` with each instance variable narrowed below its class-ivar seed widened back over the seed. The block
|
|
177
185
|
# answers the names the call may write, or nil for any; it runs at most once, and only when an instance
|
|
178
186
|
# variable is narrowed, since a proof costs a read of the callee. An instance variable whose binding carries
|
|
@@ -184,12 +192,19 @@ module Rigor
|
|
|
184
192
|
# proven) and `direct_writes` (called at most once, answering a `Set`) does not name the variable: a call
|
|
185
193
|
# proven to write it, or whose callee visibly assigns it a possibly-nil value ({DirectIvarWrites}), widens it
|
|
186
194
|
# unmarked.
|
|
195
|
+
#
|
|
196
|
+
# Issue #3340 — the block may answer a {SelfCallIvarWrites::Effects} in place of the names, whose `mutated`
|
|
197
|
+
# (`{ name => [call, ...] }`) names the instance variables a proven call mutates in place without writing
|
|
198
|
+
# them. Such a binding keeps its narrowing, the call having rebound nothing, and takes each call's unknown
|
|
199
|
+
# store ({UnknownStoreWidening.widen}), which forgets what the binding said about the object's contents:
|
|
200
|
+
# `return if @xs.empty?; reset!` leaves `@xs` an `Array[String]` when `reset!` runs `@xs.clear`.
|
|
187
201
|
def widen(scope, mark: false, direct_writes: nil)
|
|
188
202
|
seed = class_ivar_seed(scope)
|
|
189
203
|
return scope if seed.nil? || seed.empty?
|
|
190
204
|
|
|
191
205
|
computed = false
|
|
192
206
|
writes = nil
|
|
207
|
+
mutated = nil
|
|
193
208
|
direct = lazy_set(direct_writes)
|
|
194
209
|
seed.reduce(scope) do |widened, (name, seed_type)|
|
|
195
210
|
local_type = scope.ivar(name)
|
|
@@ -198,8 +213,12 @@ module Rigor
|
|
|
198
213
|
unless computed
|
|
199
214
|
writes = yield
|
|
200
215
|
computed = true
|
|
216
|
+
if writes.is_a?(SelfCallIvarWrites::Effects)
|
|
217
|
+
mutated = writes.mutated
|
|
218
|
+
writes = writes.written
|
|
219
|
+
end
|
|
201
220
|
end
|
|
202
|
-
next widened if writes && !writes.include?(name)
|
|
221
|
+
next widen_mutated(widened, name, local_type, mutated) if writes && !writes.include?(name)
|
|
203
222
|
|
|
204
223
|
joined = Type::Combinator.union(local_type, seed_type)
|
|
205
224
|
widened = widened.with_ivar(name, joined)
|
|
@@ -218,6 +237,17 @@ module Rigor
|
|
|
218
237
|
end
|
|
219
238
|
private_class_method :widen_marks?
|
|
220
239
|
|
|
240
|
+
# `scope` with the instance variable `name`, bound to `local_type`, at the unknown store of each call
|
|
241
|
+
# `mutated` names for it; `scope` itself when it names none or no store widens the binding.
|
|
242
|
+
def widen_mutated(scope, name, local_type, mutated)
|
|
243
|
+
sites = mutated&.[](name)
|
|
244
|
+
return scope if sites.nil?
|
|
245
|
+
|
|
246
|
+
widened = UnknownStoreWidening.widen(local_type, sites)
|
|
247
|
+
widened == local_type ? scope : scope.with_ivar(name, widened)
|
|
248
|
+
end
|
|
249
|
+
private_class_method :widen_mutated
|
|
250
|
+
|
|
221
251
|
# A callable answering `callable`'s `Set`, computed on the first call; an empty one when `callable` is nil.
|
|
222
252
|
def lazy_set(callable)
|
|
223
253
|
value = nil
|
|
@@ -241,7 +271,7 @@ module Rigor
|
|
|
241
271
|
calls = candidate_calls(node, run_lambdas, scope)
|
|
242
272
|
return scope if calls.empty?
|
|
243
273
|
|
|
244
|
-
|
|
274
|
+
widen_past(calls, scope)
|
|
245
275
|
end
|
|
246
276
|
|
|
247
277
|
# Whether a candidate call in `node` may write the instance variable `name`. A `when` test passes
|
|
@@ -256,13 +286,20 @@ module Rigor
|
|
|
256
286
|
end
|
|
257
287
|
|
|
258
288
|
# The union of the names each call may write ({SelfCallIvarWrites.of}), or nil when one is not proven.
|
|
259
|
-
def proven_writes(calls, scope)
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
289
|
+
def proven_writes(calls, scope) = proven_effects(calls, scope)&.written
|
|
290
|
+
|
|
291
|
+
# The {SelfCallIvarWrites::Effects} of `calls` together, or nil when one is not proven.
|
|
292
|
+
def proven_effects(calls, scope)
|
|
293
|
+
written = Set.new
|
|
294
|
+
mutated = {}
|
|
295
|
+
calls.each do |call|
|
|
296
|
+
effects = SelfCallIvarWrites.effects(call, scope)
|
|
297
|
+
return nil if effects.nil?
|
|
298
|
+
|
|
299
|
+
written.merge(effects.written)
|
|
300
|
+
effects.mutated.each { |name, sites| (mutated[name] ||= []).concat(sites) }
|
|
265
301
|
end
|
|
302
|
+
SelfCallIvarWrites::Effects.new(written: written, mutated: mutated)
|
|
266
303
|
end
|
|
267
304
|
|
|
268
305
|
# The candidate calls under `node`, in source order.
|
|
@@ -12,7 +12,7 @@ module Rigor
|
|
|
12
12
|
# replace. The standard is parity with a literal write: `@x = 1` in `initialize` already reads `1` in every sibling
|
|
13
13
|
# method whatever an unknown object's code does, so only the writers that literal writes would also have to answer
|
|
14
14
|
# for are recorded, and an unknown-receiver writer records nothing (as `ReflectiveIvarWrite` leaves
|
|
15
|
-
# `o.instance_variable_set` alone).
|
|
15
|
+
# `o.instance_variable_set` alone). Four entry kinds go into the census `Set` (a fifth, `:binds_class`, is below):
|
|
16
16
|
#
|
|
17
17
|
# - `[:ivar_set, name]` — a literal `o.instance_variable_set(:@x, v)` (or the same through a `send` that spells
|
|
18
18
|
# it) on an explicit receiver other than `self`, and an `@x` write in the literal block of an
|