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
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
require "prism"
|
|
4
4
|
|
|
5
5
|
require_relative "../source/node_children"
|
|
6
|
+
require_relative "genuine_send"
|
|
6
7
|
|
|
7
8
|
module Rigor
|
|
8
9
|
module Inference
|
|
@@ -30,27 +31,41 @@ module Rigor
|
|
|
30
31
|
end
|
|
31
32
|
|
|
32
33
|
# True when the block `call_node` carries is a return barrier.
|
|
33
|
-
|
|
34
|
+
#
|
|
35
|
+
# Through `send`, the call is reflective only where the receiver's `send` is `Kernel#send`
|
|
36
|
+
# ({GenuineSend.call?}, issue #3081): `def send(_name) = yield` makes `send(:lambda) { return nil }` an
|
|
37
|
+
# ordinary block whose `return` exits the method. `scope` is the scope the call is typed in; without one,
|
|
38
|
+
# or with `typed: false` (a caller holding the enclosing body's scope, not the call's) and an explicit
|
|
39
|
+
# receiver, nothing proves the `send` genuine and the block is not a barrier, which can only widen the
|
|
40
|
+
# method's return type. `__send__` and `public_send` are other methods and keep the reflective reading.
|
|
41
|
+
def block_call?(call_node, scope: nil, typed: true)
|
|
34
42
|
name = call_node.name
|
|
35
|
-
|
|
36
|
-
sent = call_node.arguments&.arguments&.first
|
|
37
|
-
return false unless sent.is_a?(Prism::SymbolNode)
|
|
43
|
+
return barrier_name?(name, call_node) unless SEND_CALLS.include?(name)
|
|
38
44
|
|
|
39
|
-
|
|
40
|
-
|
|
45
|
+
sent = call_node.arguments&.arguments&.first
|
|
46
|
+
return false unless sent.is_a?(Prism::SymbolNode)
|
|
47
|
+
return false unless barrier_name?(sent.unescaped.to_sym, call_node)
|
|
48
|
+
|
|
49
|
+
name != :send || GenuineSend.call?(call_node.receiver, scope, typed: typed)
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
# True when a call of `name` on `call_node`'s receiver keeps its block from the enclosing method.
|
|
53
|
+
def barrier_name?(name, call_node)
|
|
41
54
|
DEFINE_CALLS.include?(name) || (name == :lambda && kernel_receiver?(call_node.receiver))
|
|
42
55
|
end
|
|
56
|
+
private_class_method :barrier_name?
|
|
43
57
|
|
|
44
58
|
# True when a `return` under `node` exits the enclosing method: one reachable without crossing a barrier node
|
|
45
59
|
# or a barrier call's block. Allocation-free and early-exiting, for a caller that asks it of every block body.
|
|
46
|
-
|
|
60
|
+
# `scope` is the enclosing body's, so a `send` barrier is judged by its `self` alone ({.block_call?}).
|
|
61
|
+
def exits_method?(node, scope = nil)
|
|
47
62
|
return false if node.nil? || node?(node)
|
|
48
63
|
return true if node.is_a?(Prism::ReturnNode)
|
|
49
64
|
|
|
50
|
-
barrier_block = node.block if node.is_a?(Prism::CallNode) && block_call?(node)
|
|
65
|
+
barrier_block = node.block if node.is_a?(Prism::CallNode) && block_call?(node, scope: scope, typed: false)
|
|
51
66
|
node.rigor_each_child do |child|
|
|
52
67
|
next if child.equal?(barrier_block)
|
|
53
|
-
return true if exits_method?(child)
|
|
68
|
+
return true if exits_method?(child, scope)
|
|
54
69
|
end
|
|
55
70
|
false
|
|
56
71
|
end
|
|
@@ -0,0 +1,311 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "prism"
|
|
4
|
+
|
|
5
|
+
require_relative "../../source/alias_names"
|
|
6
|
+
require_relative "../../source/constant_path"
|
|
7
|
+
require_relative "../../source/node_children"
|
|
8
|
+
require_relative "../declaration_walk/rules"
|
|
9
|
+
require_relative "certainty"
|
|
10
|
+
|
|
11
|
+
module Rigor
|
|
12
|
+
module Inference
|
|
13
|
+
module ScopeIndexer
|
|
14
|
+
# The alias def-node pass, moved out of `scope_indexer.rb` whole (ADR-116 WD9, #3400): the post-pass over the
|
|
15
|
+
# methods table's `def_nodes` that gives the new name of each `alias` and `alias_method` the `def` node its old
|
|
16
|
+
# name held at the alias (#2006), and settles the new name's contest (ADR-119 WD3).
|
|
17
|
+
# {.apply_alias_def_nodes} is the entry, which `ScopeIndexer.build_methods_and_def_nodes` calls once, after its
|
|
18
|
+
# own walk. The other ten functions are private: the slot's writer, the walk that fills the alias map with its
|
|
19
|
+
# five arms and the predicate one of them asks, and the two recorders. {AliasMap}, the map and the list of the
|
|
20
|
+
# aliases it met, moved with them: only this pass builds one.
|
|
21
|
+
#
|
|
22
|
+
# It asks {DeclarationWalk::Rules} for each declaration context and calls one function left in
|
|
23
|
+
# `scope_indexer.rb`, at two sites: `ScopeIndexer.follow_slot_writer`, the rule every writer of a def-node slot
|
|
24
|
+
# settles the slot's contest by. It reads `ScopeIndexer::INSTANCE_EVAL_CALLS` lexically, as {NodePropagation}
|
|
25
|
+
# reads the indexer's constants: other rows of `scope_indexer.rb` read it too.
|
|
26
|
+
#
|
|
27
|
+
# `scope_indexer.rb` requires this file, and this file does not require it back. It requires the file of what
|
|
28
|
+
# else it names. So the file loads alone, and until `scope_indexer.rb` has loaded the entry answers only for a
|
|
29
|
+
# program with no alias and no body in the block of an eval-family call, or of a class-creating call no write
|
|
30
|
+
# names: an alias is a `NoMethodError` (`follow_slot_writer`), and such a block a `NameError`
|
|
31
|
+
# (`INSTANCE_EVAL_CALLS`).
|
|
32
|
+
module AliasDefNodes
|
|
33
|
+
module_function
|
|
34
|
+
|
|
35
|
+
# Post-pass over the `def_nodes` accumulator: for every `alias` declaration inside a class body, if the original
|
|
36
|
+
# method name maps to a `Prism::DefNode`, register the new name pointing to the same node so inter-procedural
|
|
37
|
+
# return-type inference works for the aliased name.
|
|
38
|
+
#
|
|
39
|
+
# ADR-119 WD3 — the alias is the slot's writer: the new name's slot is contested when the alias is possible
|
|
40
|
+
# or the slot it copies is contested, and cleared otherwise.
|
|
41
|
+
#
|
|
42
|
+
# Issue #2006 — in source order. An alias copies what its old name held AT the alias, read from the walk's
|
|
43
|
+
# definer history ({ScopeIndexer::MethodTables#wrote_definer}) and the copies earlier aliases made: a `def` of
|
|
44
|
+
# the old name written after the alias (`alias old_x x; def x = 1`) is not what `old_x` runs, and nothing before
|
|
45
|
+
# the alias copies nothing. The new name's slot then follows its last writer: a later `def` keeps the slot the
|
|
46
|
+
# walk gave it, and a later `define_method` / `attr_*` leaves the copy contested, as
|
|
47
|
+
# {ScopeIndexer.supersede_def_nodes} leaves a replaced `def`.
|
|
48
|
+
def apply_alias_def_nodes(root, accumulator, tables)
|
|
49
|
+
alias_map = collect_class_alias_map(root, [], AliasMap.new.track(tables.certainty))
|
|
50
|
+
history = (tables.definer_history || {}).transform_values(&:dup)
|
|
51
|
+
alias_map.copy_into(history).each { |key| settle_alias_slot(accumulator, tables, key, history[key]) }
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
# Writes the new name's slot from its last writer `writes.last` ({.apply_alias_def_nodes}): an alias copy or a
|
|
55
|
+
# later `def` writes its `def` with its certainty (for the `def`, what the walk wrote already). A last writer
|
|
56
|
+
# with no `def` this file holds — a later `define_method` / `attr_*`, or an alias that copies nothing this file
|
|
57
|
+
# defines (an inherited or core method, an attr reader, a name it cannot read) — contests the slot, which keeps
|
|
58
|
+
# what it holds or else the latest copy, so no sibling file's `def` fills it.
|
|
59
|
+
def settle_alias_slot(accumulator, tables, (class_name, new_name), writes)
|
|
60
|
+
last = writes.last
|
|
61
|
+
slot = (accumulator[class_name] ||= {})
|
|
62
|
+
if last[1]
|
|
63
|
+
slot[new_name] = last[1]
|
|
64
|
+
ScopeIndexer.follow_slot_writer(tables, :contested_def_nodes, [class_name, new_name], last[2])
|
|
65
|
+
else
|
|
66
|
+
copy = writes.rfind { |write| write[1] }
|
|
67
|
+
slot[new_name] ||= copy[1] if copy
|
|
68
|
+
ScopeIndexer.follow_slot_writer(tables, :contested_def_nodes, [class_name, new_name], false)
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
# The `{class => {new name => old name}}` map {.collect_class_alias_map} fills, which also lists every alias it
|
|
73
|
+
# met as an event `[class, new name, old name, start offset, possible?]` ({Certainty}).
|
|
74
|
+
class AliasMap < Hash
|
|
75
|
+
attr_reader :events
|
|
76
|
+
|
|
77
|
+
def track(certainty)
|
|
78
|
+
@certainty = certainty || Certainty::EMPTY
|
|
79
|
+
@events = []
|
|
80
|
+
self
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
# Records that `node` wrote the `[class_name, new_name]` entry, aliasing `old_name`.
|
|
84
|
+
def wrote(class_name, new_name, old_name, node)
|
|
85
|
+
return if @certainty.nil?
|
|
86
|
+
|
|
87
|
+
@events << [class_name, new_name, old_name, node.location.start_offset,
|
|
88
|
+
Certainty.possible?(@certainty, node)]
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
# Issue #2006 — adds every alias to `history` (`{[class, name] => [[offset, def node or nil, certain,
|
|
92
|
+
# (:alias)], ...]}`, ascending), in source order. An alias whose old name held a `def` at the alias copies it,
|
|
93
|
+
# certain when that write and the alias are. Any other alias — an old name with no `def` of this file before
|
|
94
|
+
# it (inherited, core, an attr reader, a sibling file's), or one it cannot read — adds a write with no `def`,
|
|
95
|
+
# which leaves the slot contested ({AliasDefNodes.settle_alias_slot}). An alias whose new name it cannot read
|
|
96
|
+
# adds one to every name of the class written before it. Returns the `[class, name]` keys it wrote.
|
|
97
|
+
def copy_into(history)
|
|
98
|
+
@events.sort_by { |event| event[3] }.flat_map do |class_name, new_name, old_name, at, possible|
|
|
99
|
+
source = old_name && history[[class_name, old_name]]&.rfind { |write| write.first < at }
|
|
100
|
+
write = if source&.[](1) then [at, source[1], source[2] && !possible, :alias].freeze
|
|
101
|
+
else [at, nil, false, :alias].freeze
|
|
102
|
+
end
|
|
103
|
+
keys = new_name ? [[class_name, new_name]] : names_before(history, class_name, at)
|
|
104
|
+
keys.each { |key| (history[key] ||= []).push(write).sort_by!(&:first) }
|
|
105
|
+
end.uniq
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
private
|
|
109
|
+
|
|
110
|
+
def names_before(history, class_name, at)
|
|
111
|
+
history.filter_map { |key, writes| key if key.first == class_name && writes.first.first < at }
|
|
112
|
+
end
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
# Builds a map `{class_name => {new_name_sym => old_name_sym}}` by walking the tree for `AliasMethodNode` nodes
|
|
116
|
+
# inside class bodies. `leaf_owner` is the meta-new override: inside `K = Class.new { … }` the
|
|
117
|
+
# block's aliases bind on the class the write names — it overrides `qualified_prefix`, which
|
|
118
|
+
# keeps naming the enclosing lexical cref for declarations.
|
|
119
|
+
def collect_class_alias_map(node, qualified_prefix, accumulator, leaf_owner = nil,
|
|
120
|
+
singleton_cref: false, defs_singleton: false)
|
|
121
|
+
return accumulator unless node.is_a?(Prism::Node)
|
|
122
|
+
|
|
123
|
+
case node
|
|
124
|
+
when Prism::ClassNode, Prism::ModuleNode
|
|
125
|
+
return collect_alias_map_declaration(node, qualified_prefix, accumulator, leaf_owner,
|
|
126
|
+
singleton_cref)
|
|
127
|
+
when Prism::SingletonClassNode
|
|
128
|
+
return collect_alias_map_singleton(node, qualified_prefix, accumulator, leaf_owner,
|
|
129
|
+
singleton_cref)
|
|
130
|
+
when Prism::ConstantWriteNode, Prism::ConstantPathWriteNode, Prism::ConstantOrWriteNode,
|
|
131
|
+
Prism::ConstantPathOrWriteNode
|
|
132
|
+
return accumulator if collect_alias_map_meta_new?(node, qualified_prefix, accumulator,
|
|
133
|
+
leaf_owner, singleton_cref)
|
|
134
|
+
when Prism::AliasMethodNode, Prism::CallNode
|
|
135
|
+
return accumulator if record_alias_leaf?(node, qualified_prefix, accumulator,
|
|
136
|
+
leaf_owner, singleton_cref,
|
|
137
|
+
defs_singleton: defs_singleton)
|
|
138
|
+
return accumulator if collect_alias_map_block_call?(node, qualified_prefix, accumulator,
|
|
139
|
+
leaf_owner, singleton_cref)
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
node.rigor_each_child do |child|
|
|
143
|
+
collect_class_alias_map(child, qualified_prefix, accumulator, leaf_owner,
|
|
144
|
+
singleton_cref: singleton_cref,
|
|
145
|
+
defs_singleton: defs_singleton)
|
|
146
|
+
end
|
|
147
|
+
accumulator
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
# The alias-leaf arm of {.collect_class_alias_map}: inside a `class <<` body the alias binds
|
|
151
|
+
# on the singleton — the map files nothing; a re-anchored declaration below it clears the
|
|
152
|
+
# flag again, and a meta-new block's `leaf_owner` re-anchors it onto the named class.
|
|
153
|
+
# Returns true when the leaf was consumed (AliasMethodNode always; a recognised
|
|
154
|
+
# `alias_method` call), false when the node is an ordinary call to keep walking.
|
|
155
|
+
def record_alias_leaf?(node, qualified_prefix, accumulator, leaf_owner, singleton_cref,
|
|
156
|
+
defs_singleton: false)
|
|
157
|
+
rec_prefix = leaf_owner || qualified_prefix
|
|
158
|
+
if node.is_a?(Prism::AliasMethodNode)
|
|
159
|
+
# `defs_singleton` is the instance_eval split: the `alias` keyword binds on the
|
|
160
|
+
# receiver's singleton, while `alias_method` — a call on the receiver-as-module —
|
|
161
|
+
# stays instance-side and still records.
|
|
162
|
+
unless defs_singleton || (singleton_cref && leaf_owner.nil?)
|
|
163
|
+
record_alias_map_entry(node, rec_prefix, accumulator)
|
|
164
|
+
end
|
|
165
|
+
return true
|
|
166
|
+
end
|
|
167
|
+
return false unless node.is_a?(Prism::CallNode)
|
|
168
|
+
|
|
169
|
+
# `alias_method :new, :old` — the CallNode twin of the `alias` keyword (#533; liquid's i18n
|
|
170
|
+
# `t` alias was the corpus case). Unlike AliasMethodNode a call's children can carry further
|
|
171
|
+
# class bodies (`Class.new do … end`), so the walk continues below it either way.
|
|
172
|
+
names = Source::AliasNames.alias_method_call_names(node)
|
|
173
|
+
if (names || unread_alias_method?(node)) && !rec_prefix.empty? && !(singleton_cref && leaf_owner.nil?)
|
|
174
|
+
record_alias_call_entry(accumulator, rec_prefix.join("::"), names, node)
|
|
175
|
+
end
|
|
176
|
+
false
|
|
177
|
+
end
|
|
178
|
+
|
|
179
|
+
# Issue #2006 — an `alias_method` call on no receiver or `self` whose names {Source::AliasNames} cannot read
|
|
180
|
+
# (`alias_method n, :to_s`, `self.alias_method :x, :y`, a splat): it still replaces a method, which
|
|
181
|
+
# {AliasMap#copy_into} contests.
|
|
182
|
+
def unread_alias_method?(node)
|
|
183
|
+
node.name == :alias_method && (node.receiver.nil? || node.receiver.is_a?(Prism::SelfNode))
|
|
184
|
+
end
|
|
185
|
+
|
|
186
|
+
# The rebinding-block call arm of {.collect_class_alias_map}: an anonymous meta-new call
|
|
187
|
+
# (`Class.new { … }` no write names) files its block's aliases nowhere, and an eval-family
|
|
188
|
+
# call binds them on the receiver — a nameable receiver re-anchors the owner while a
|
|
189
|
+
# receiver that names nothing, or an unnameable self below `class <<`, walks ownerless.
|
|
190
|
+
def collect_alias_map_block_call?(node, qualified_prefix, accumulator, leaf_owner,
|
|
191
|
+
singleton_cref)
|
|
192
|
+
return false unless node.is_a?(Prism::CallNode) && node.block.is_a?(Prism::BlockNode)
|
|
193
|
+
|
|
194
|
+
if DeclarationWalk::Rules.meta_new_constant_rvalue?(node)
|
|
195
|
+
block_owner = []
|
|
196
|
+
elsif DeclarationWalk::Rules.receiver_eval_call?(node)
|
|
197
|
+
self_prefix = leaf_owner || qualified_prefix
|
|
198
|
+
unnameable = DeclarationWalk::Rules.unnameable_eval_self?(false, leaf_owner, qualified_prefix,
|
|
199
|
+
singleton_cref)
|
|
200
|
+
block_owner = DeclarationWalk::Rules.eval_receiver_prefix(node, self_prefix, qualified_prefix,
|
|
201
|
+
unnameable_self: unnameable) || []
|
|
202
|
+
else
|
|
203
|
+
return false
|
|
204
|
+
end
|
|
205
|
+
|
|
206
|
+
[node.receiver, *node.arguments&.arguments.to_a].compact.each do |part|
|
|
207
|
+
collect_class_alias_map(part, qualified_prefix, accumulator, leaf_owner,
|
|
208
|
+
singleton_cref: singleton_cref)
|
|
209
|
+
end
|
|
210
|
+
if (body = node.block.body)
|
|
211
|
+
collect_class_alias_map(body, qualified_prefix, accumulator, block_owner,
|
|
212
|
+
singleton_cref: singleton_cref,
|
|
213
|
+
defs_singleton: INSTANCE_EVAL_CALLS.include?(node.name))
|
|
214
|
+
end
|
|
215
|
+
true
|
|
216
|
+
end
|
|
217
|
+
|
|
218
|
+
# The meta-new arm of {.collect_class_alias_map}: the write's receiver and arguments keep
|
|
219
|
+
# the enclosing context; the block's aliases bind on the class the write names, or file
|
|
220
|
+
# nothing when the write is unnameable below an unnameable cref.
|
|
221
|
+
def collect_alias_map_meta_new?(node, qualified_prefix, accumulator, leaf_owner,
|
|
222
|
+
singleton_cref)
|
|
223
|
+
call = DeclarationWalk::Rules.meta_new_block_call(node)
|
|
224
|
+
return false unless call
|
|
225
|
+
|
|
226
|
+
child_prefix = DeclarationWalk::Rules.meta_new_child_prefix(node, qualified_prefix, leaf_owner)
|
|
227
|
+
meta_ownerless = singleton_cref && !DeclarationWalk::Rules.meta_new_path_target_nameable?(node, leaf_owner)
|
|
228
|
+
[call.receiver, *call.arguments&.arguments.to_a].compact.each do |part|
|
|
229
|
+
collect_class_alias_map(part, qualified_prefix, accumulator, leaf_owner,
|
|
230
|
+
singleton_cref: singleton_cref)
|
|
231
|
+
end
|
|
232
|
+
if (body = DeclarationWalk::Rules.meta_new_block_body(node))
|
|
233
|
+
collect_class_alias_map(body, qualified_prefix, accumulator,
|
|
234
|
+
(meta_ownerless ? nil : child_prefix) || [],
|
|
235
|
+
singleton_cref: singleton_cref)
|
|
236
|
+
end
|
|
237
|
+
true
|
|
238
|
+
end
|
|
239
|
+
|
|
240
|
+
# The class/module arm of {.collect_class_alias_map}: under an unnameable cref a
|
|
241
|
+
# bare/`self::` header opens `#<singleton>::Name` — the map files nothing for it;
|
|
242
|
+
# a rooted or explicit-base header re-anchors at a nameable prefix.
|
|
243
|
+
def collect_alias_map_declaration(node, qualified_prefix, accumulator, leaf_owner,
|
|
244
|
+
singleton_cref)
|
|
245
|
+
self_decl = DeclarationWalk::Rules.self_anchored_decl_prefix(node.constant_path, leaf_owner)
|
|
246
|
+
child_prefix = self_decl ||
|
|
247
|
+
Source::ConstantPath.declaration_prefix(qualified_prefix, node.constant_path)
|
|
248
|
+
return accumulator unless child_prefix
|
|
249
|
+
|
|
250
|
+
child_cref = DeclarationWalk::Rules.unnameable_decl?(node, self_decl, singleton_cref)
|
|
251
|
+
if node.body
|
|
252
|
+
collect_class_alias_map(node.body, child_cref ? [] : child_prefix, accumulator,
|
|
253
|
+
singleton_cref: child_cref)
|
|
254
|
+
end
|
|
255
|
+
accumulator
|
|
256
|
+
end
|
|
257
|
+
|
|
258
|
+
# The `class <<` arm of {.collect_class_alias_map}: the expression evaluates in the
|
|
259
|
+
# enclosing context (`class << (class D; self; end)` → `C::D`), while the body is a
|
|
260
|
+
# singleton context the map files nothing for directly — a nameable declaration
|
|
261
|
+
# inside still re-anchors through the flag.
|
|
262
|
+
def collect_alias_map_singleton(node, qualified_prefix, accumulator, leaf_owner,
|
|
263
|
+
singleton_cref)
|
|
264
|
+
collect_class_alias_map(node.expression, qualified_prefix, accumulator, leaf_owner,
|
|
265
|
+
singleton_cref: singleton_cref)
|
|
266
|
+
if node.body
|
|
267
|
+
# `self` below `class <<` is the singleton class — `self::`-anchored receivers
|
|
268
|
+
# decline; a named eval receiver still re-anchors to a real class.
|
|
269
|
+
collect_class_alias_map(node.body, qualified_prefix, accumulator, [],
|
|
270
|
+
singleton_cref: true)
|
|
271
|
+
end
|
|
272
|
+
accumulator
|
|
273
|
+
end
|
|
274
|
+
|
|
275
|
+
def record_alias_call_entry(accumulator, class_name, names, node)
|
|
276
|
+
if names.nil?
|
|
277
|
+
# Issue #2006 — an unread `alias_method` maps nothing, but still replaces a method ({AliasMap#copy_into}).
|
|
278
|
+
new_name = Source::AliasNames.literal_name(node.arguments&.arguments&.first)
|
|
279
|
+
accumulator.wrote(class_name, new_name, nil, node) if accumulator.is_a?(AliasMap)
|
|
280
|
+
return
|
|
281
|
+
end
|
|
282
|
+
|
|
283
|
+
(accumulator[class_name] ||= {})[names.first] = names.last
|
|
284
|
+
accumulator.wrote(class_name, names.first, names.last, node) if accumulator.is_a?(AliasMap)
|
|
285
|
+
end
|
|
286
|
+
|
|
287
|
+
def record_alias_map_entry(alias_node, qualified_prefix, accumulator)
|
|
288
|
+
return if qualified_prefix.empty?
|
|
289
|
+
|
|
290
|
+
names = Source::AliasNames.keyword_names(alias_node)
|
|
291
|
+
class_name = qualified_prefix.join("::")
|
|
292
|
+
if names.nil?
|
|
293
|
+
# Issue #2006 — an `alias` whose names are not plain symbols still replaces a method ({AliasMap#copy_into}).
|
|
294
|
+
new_name = Source::AliasNames.symbol_name(alias_node.new_name)
|
|
295
|
+
accumulator.wrote(class_name, new_name, nil, alias_node) if accumulator.is_a?(AliasMap)
|
|
296
|
+
return
|
|
297
|
+
end
|
|
298
|
+
|
|
299
|
+
new_name, old_name = names
|
|
300
|
+
(accumulator[class_name] ||= {})[new_name] = old_name
|
|
301
|
+
accumulator.wrote(class_name, new_name, old_name, alias_node) if accumulator.is_a?(AliasMap)
|
|
302
|
+
end
|
|
303
|
+
|
|
304
|
+
private_class_method :settle_alias_slot, :collect_class_alias_map, :record_alias_leaf?, :unread_alias_method?,
|
|
305
|
+
:collect_alias_map_block_call?, :collect_alias_map_meta_new?,
|
|
306
|
+
:collect_alias_map_declaration, :collect_alias_map_singleton, :record_alias_call_entry,
|
|
307
|
+
:record_alias_map_entry
|
|
308
|
+
end
|
|
309
|
+
end
|
|
310
|
+
end
|
|
311
|
+
end
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "../declaration_walk/rules"
|
|
4
|
+
|
|
5
|
+
module Rigor
|
|
6
|
+
module Inference
|
|
7
|
+
module ScopeIndexer
|
|
8
|
+
# The scope a census pre-pass types an rvalue under, moved out of `scope_indexer.rb` whole (ADR-116 WD9,
|
|
9
|
+
# #3400): {.census_body_scope}, and {.census_nesting}, the chain that scope answers `Module.nesting` with.
|
|
10
|
+
# Three censuses ask for it, each a module of its own: the class ivar index ({ClassIvarIndex}, at four sites),
|
|
11
|
+
# the class-variable census ({ClassCvarCensus}, at two) and the typed constant walk ({ConstantTables}, which
|
|
12
|
+
# asks for the chain alone too). A fourth, the published-constant ivar census ({PublishedConstantIvars}), types
|
|
13
|
+
# nothing and asks the truthiness guard about an rvalue under the same scope (issue #3437), and so does a fifth,
|
|
14
|
+
# its class-variable twin ({PublishedConstantCvars}, issue #3443). Both functions are
|
|
15
|
+
# public, because another file calls each.
|
|
16
|
+
#
|
|
17
|
+
# It asks {DeclarationWalk::Rules} for the chain a prefix stands for, calls nothing left in `scope_indexer.rb`
|
|
18
|
+
# and reads none of its constants. `scope_indexer.rb` and the five modules require this file, and it requires
|
|
19
|
+
# none of them back. It requires the file of what it names, so it loads alone and answers there as it does
|
|
20
|
+
# with the indexer loaded.
|
|
21
|
+
module CensusScope
|
|
22
|
+
module_function
|
|
23
|
+
|
|
24
|
+
# Issue #681 — the scope a census pre-pass types an rvalue under. The census walks never enter a body
|
|
25
|
+
# through `StatementEvaluator`, so nothing stamped the declaration's `Module.nesting` on the scope they
|
|
26
|
+
# build and `Reflection.lexical_nesting_chain` fell back to peeling `self_type`'s qualified name. That
|
|
27
|
+
# peel cannot tell a compact `class Admin::Census` (nesting `[Admin::Census]`, so a bare `Post` names
|
|
28
|
+
# `::Post`) from the nested spelling (nesting `[Admin::Census, Admin]`, where it names `Admin::Post`),
|
|
29
|
+
# so `@post = Post.new` and `DEFAULT = Post` were recorded under the wrong class and every later read
|
|
30
|
+
# answered it. The prefix these walks already thread IS the chain — `["Admin::Census"]` for the compact
|
|
31
|
+
# form, `["Admin", "Census"]` for the nested one — so the fact was in hand and only the stamp was
|
|
32
|
+
# missing.
|
|
33
|
+
def census_body_scope(default_scope, qualified_prefix, self_type)
|
|
34
|
+
default_scope.with_self_type(self_type)
|
|
35
|
+
.with_lexical_nesting(census_nesting(default_scope, qualified_prefix))
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
# The chain a census walk answers `Module.nesting` with: the one
|
|
39
|
+
# {DeclarationWalk::Rules.scope_entering_declaration} threaded on the scope when a header was entered, and only
|
|
40
|
+
# failing that the prefix-derived approximation below.
|
|
41
|
+
def census_nesting(scope, qualified_prefix)
|
|
42
|
+
scope&.lexical_nesting || DeclarationWalk::Rules.lexical_nesting_for_prefix(qualified_prefix)
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
|
@@ -15,7 +15,7 @@ module Rigor
|
|
|
15
15
|
# - the program's statements, and the bodies of `class`, `module` and `class << self` declarations that are
|
|
16
16
|
# themselves certain;
|
|
17
17
|
# - the block of a meta-new constant write (`K = Class.new do … end`, `Module.new`, `Struct.new`,
|
|
18
|
-
# `Data.define`, {
|
|
18
|
+
# `Data.define`, {DeclarationWalk::Rules.meta_new_block_call}) and of a bare factory call
|
|
19
19
|
# ({AnonymousMetaClass.block_form_receiver}), when the write or the call is certain: Ruby runs the block once,
|
|
20
20
|
# as the new class's body (ADR-119 WD2, "Conditional definers");
|
|
21
21
|
# - a `begin` WITHOUT a `rescue` clause: its main statements and its `ensure` clause;
|
|
@@ -168,7 +168,7 @@ module Rigor
|
|
|
168
168
|
|
|
169
169
|
# A meta-new constant write: the factory's receiver and arguments, and its block as the class body.
|
|
170
170
|
def meta_new_write?(node)
|
|
171
|
-
call =
|
|
171
|
+
call = DeclarationWalk::Rules.meta_new_block_call(node)
|
|
172
172
|
return false unless call
|
|
173
173
|
|
|
174
174
|
certain(call.receiver)
|