rigortype 0.4.8 → 0.4.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/docs/handbook/01-getting-started.md +1 -1
- data/docs/handbook/04-tuples-and-shapes.md +6 -1
- data/docs/handbook/12-lightweight-hkt.md +1 -1
- data/docs/handbook/appendix-typescript.md +28 -17
- data/docs/manual/02-cli-reference.md +10 -0
- data/docs/manual/03-configuration.md +1 -1
- data/docs/manual/04-diagnostics.md +1 -1
- data/docs/manual/10-mcp-server.md +122 -10
- data/docs/manual/plugins/rigor-activerecord.md +7 -0
- data/lib/rigor/analysis/check_rules/always_raises.rb +95 -0
- data/lib/rigor/analysis/check_rules/always_truthy_condition_collector.rb +32 -2
- data/lib/rigor/analysis/check_rules/argument_type.rb +802 -0
- data/lib/rigor/analysis/check_rules/call_facts.rb +2 -2
- data/lib/rigor/analysis/check_rules/dead_assignment_collector.rb +30 -1
- data/lib/rigor/analysis/check_rules/declaration_sourced_guard.rb +4 -5
- data/lib/rigor/analysis/check_rules/duplicate_hash_key_collector.rb +34 -0
- data/lib/rigor/analysis/check_rules/ivar_write_collector.rb +131 -4
- data/lib/rigor/analysis/check_rules/nil_receiver.rb +195 -0
- data/lib/rigor/analysis/check_rules/override_param_narrowed.rb +111 -0
- data/lib/rigor/analysis/check_rules/override_return_widened.rb +88 -0
- data/lib/rigor/analysis/check_rules/override_support.rb +246 -0
- data/lib/rigor/analysis/check_rules/override_visibility.rb +135 -0
- data/lib/rigor/analysis/check_rules/published_constant_guard.rb +75 -31
- data/lib/rigor/analysis/check_rules/raise_non_exception.rb +198 -0
- data/lib/rigor/analysis/check_rules/receiver_predicates.rb +576 -0
- data/lib/rigor/analysis/check_rules/return_in_ensure_collector.rb +52 -4
- data/lib/rigor/analysis/check_rules/return_type.rb +225 -0
- data/lib/rigor/analysis/check_rules/rigor_testing.rb +119 -0
- data/lib/rigor/analysis/check_rules/rule_ids.rb +7 -7
- data/lib/rigor/analysis/check_rules/rule_walk.rb +4 -3
- data/lib/rigor/analysis/check_rules/self_closedness_scanner.rb +2 -0
- data/lib/rigor/analysis/check_rules/self_undefined_method.rb +165 -0
- data/lib/rigor/analysis/check_rules/shadowed_rescue_collector.rb +34 -0
- data/lib/rigor/analysis/check_rules/source_arity.rb +2 -2
- data/lib/rigor/analysis/check_rules/special_global_write.rb +256 -0
- data/lib/rigor/analysis/check_rules/suppression.rb +275 -0
- data/lib/rigor/analysis/check_rules/undefined_method.rb +882 -0
- data/lib/rigor/analysis/check_rules/unreachable_branch.rb +97 -0
- data/lib/rigor/analysis/check_rules/unreachable_clause_collector.rb +42 -0
- data/lib/rigor/analysis/check_rules/unresolved_toplevel.rb +140 -0
- data/lib/rigor/analysis/check_rules/visibility_mismatch.rb +252 -0
- data/lib/rigor/analysis/check_rules/void_value_use_collector.rb +27 -0
- data/lib/rigor/analysis/check_rules/wrong_arity.rb +303 -0
- data/lib/rigor/analysis/check_rules.rb +66 -4931
- data/lib/rigor/analysis/dependency_recorder.rb +1 -1
- data/lib/rigor/analysis/dependency_source_inference/builder.rb +2 -4
- data/lib/rigor/analysis/dependency_source_inference/gem_resolver.rb +1 -2
- data/lib/rigor/analysis/dependency_source_inference/walker.rb +15 -15
- data/lib/rigor/analysis/incremental_session.rb +4 -4
- data/lib/rigor/analysis/path_expansion.rb +1 -1
- data/lib/rigor/analysis/plugin_fact_fingerprint.rb +5 -5
- data/lib/rigor/analysis/reachability/graph.rb +2 -3
- data/lib/rigor/analysis/reachability/plugin_roots.rb +2 -2
- data/lib/rigor/analysis/reachability/scan.rb +2 -2
- data/lib/rigor/analysis/rule_catalog.rb +2 -1
- data/lib/rigor/analysis/run_cache_key.rb +9 -8
- data/lib/rigor/analysis/runner/buffer_pool_dispatcher.rb +2 -2
- data/lib/rigor/analysis/runner/dependency_rows.rb +206 -0
- data/lib/rigor/analysis/runner/diagnostic_aggregator.rb +24 -22
- data/lib/rigor/analysis/runner/effect_cache_entries.rb +69 -0
- data/lib/rigor/analysis/runner/pool_coordinator.rb +6 -8
- data/lib/rigor/analysis/runner/project_pre_passes.rb +3 -5
- data/lib/rigor/analysis/runner/scope_seed.rb +144 -0
- data/lib/rigor/analysis/runner.rb +49 -296
- data/lib/rigor/analysis/template_unit_collector.rb +1 -1
- data/lib/rigor/analysis/template_units.rb +10 -10
- data/lib/rigor/analysis/worker_session.rb +7 -7
- data/lib/rigor/bleeding_edge.rb +3 -2
- data/lib/rigor/builtins/hkt_builtins.rb +17 -17
- data/lib/rigor/builtins/imported_refinements.rb +8 -16
- data/lib/rigor/builtins/regex_refinement.rb +3 -3
- data/lib/rigor/builtins/static_return_refinements.rb +143 -19
- data/lib/rigor/cache/incremental_snapshot.rb +21 -8
- data/lib/rigor/cache/rbs_descriptor.rb +18 -1
- data/lib/rigor/cli/coverage_renderer.rb +15 -1
- data/lib/rigor/cli/coverage_report.rb +19 -1
- data/lib/rigor/cli/diagnostic_formats.rb +3 -2
- data/lib/rigor/cli/docs_command.rb +5 -5
- data/lib/rigor/cli/effects_command.rb +7 -6
- data/lib/rigor/cli/fused_protection_report.rb +7 -7
- data/lib/rigor/cli/lsp_command.rb +1 -1
- data/lib/rigor/cli/mcp_command.rb +5 -2
- data/lib/rigor/cli/options.rb +4 -0
- data/lib/rigor/cli/plugins_command.rb +1 -1
- data/lib/rigor/cli/sig_gen_command.rb +1 -1
- data/lib/rigor/cli/skill_command.rb +5 -4
- data/lib/rigor/cli/triage_renderer.rb +3 -2
- data/lib/rigor/cli/unused_command.rb +4 -4
- data/lib/rigor/cli.rb +14 -0
- data/lib/rigor/configuration/coercion.rb +418 -0
- data/lib/rigor/configuration/defaults.rb +248 -0
- data/lib/rigor/configuration/dependencies.rb +1 -1
- data/lib/rigor/configuration/loader.rb +354 -0
- data/lib/rigor/configuration/severity_profile.rb +4 -4
- data/lib/rigor/configuration.rb +51 -860
- data/lib/rigor/effects/attribution.rb +1 -1
- data/lib/rigor/effects/effect_table.rb +1 -1
- data/lib/rigor/effects/identity.rb +3 -3
- data/lib/rigor/effects/local_ownership.rb +2 -2
- data/lib/rigor/effects/snapshot.rb +1 -1
- data/lib/rigor/effects/summary.rb +5 -4
- data/lib/rigor/environment/member_consistency.rb +10 -0
- data/lib/rigor/environment/rbs_loader.rb +19 -22
- data/lib/rigor/environment/reflection.rb +1 -1
- data/lib/rigor/environment/unreadable_signature.rb +21 -0
- data/lib/rigor/environment.rb +8 -8
- data/lib/rigor/flow_contribution/merger.rb +1 -0
- data/lib/rigor/hashing/xxh3.rb +1 -1
- data/lib/rigor/inference/acceptance.rb +23 -2
- data/lib/rigor/inference/alias_mutation_floor/site_collector.rb +5 -0
- data/lib/rigor/inference/alias_mutation_floor.rb +0 -5
- data/lib/rigor/inference/anonymous_meta_class.rb +2 -2
- data/lib/rigor/inference/block_call_timing.rb +6 -0
- data/lib/rigor/inference/budget_trace.rb +3 -2
- data/lib/rigor/inference/builtins/date_catalog.rb +3 -3
- data/lib/rigor/inference/builtins/method_catalog.rb +3 -3
- data/lib/rigor/inference/builtins/time_catalog.rb +3 -3
- data/lib/rigor/inference/call_ladder/literal_send.rb +98 -0
- data/lib/rigor/inference/call_ladder/overriding_def.rb +98 -0
- data/lib/rigor/inference/call_ladder/project_singleton.rb +362 -0
- data/lib/rigor/inference/call_ladder/refined.rb +212 -0
- data/lib/rigor/inference/call_ladder/top_level_def.rb +222 -0
- data/lib/rigor/inference/call_ladder/user_method.rb +247 -0
- data/lib/rigor/inference/call_ladder.rb +219 -0
- data/lib/rigor/inference/callee_write_census.rb +2 -2
- data/lib/rigor/inference/captured_locals.rb +2 -2
- data/lib/rigor/inference/clause_widening.rb +63 -1
- data/lib/rigor/inference/declaration_walk/context.rb +12 -12
- data/lib/rigor/inference/declaration_walk/rules.rb +750 -0
- data/lib/rigor/inference/declaration_walk/traversal.rb +9 -8
- data/lib/rigor/inference/declaration_walk.rb +4 -3
- data/lib/rigor/inference/def_node_resolver.rb +2 -2
- data/lib/rigor/inference/def_return_typer.rb +14 -6
- data/lib/rigor/inference/deferred_mutation.rb +120 -0
- data/lib/rigor/inference/define_method_block_self.rb +1 -1
- data/lib/rigor/inference/definer_resolution.rb +4 -4
- data/lib/rigor/inference/error_info.rb +8 -8
- data/lib/rigor/inference/expression_typer/composites.rb +348 -0
- data/lib/rigor/inference/expression_typer/per_element_assemblers.rb +233 -0
- data/lib/rigor/inference/expression_typer/writes.rb +218 -0
- data/lib/rigor/inference/expression_typer.rb +275 -1825
- data/lib/rigor/inference/external_ancestor_resolution.rb +2 -2
- data/lib/rigor/inference/fallback.rb +1 -0
- data/lib/rigor/inference/for_yield_slots.rb +126 -0
- data/lib/rigor/inference/genuine_send.rb +92 -0
- data/lib/rigor/inference/global_write_census.rb +2 -2
- data/lib/rigor/inference/hkt_body.rb +2 -0
- data/lib/rigor/inference/in_effect_refinements/walk.rb +2 -2
- data/lib/rigor/inference/index_write_widening.rb +4 -4
- data/lib/rigor/inference/indexed_narrowing.rb +1 -1
- data/lib/rigor/inference/intervening_ivar_reset.rb +46 -9
- data/lib/rigor/inference/ivar_writer_census.rb +1 -1
- data/lib/rigor/inference/loop_store_sites.rb +239 -0
- data/lib/rigor/inference/macro_block_self_type.rb +4 -3
- data/lib/rigor/inference/method_dispatcher/block_folding.rb +3 -2
- data/lib/rigor/inference/method_dispatcher/call_context.rb +84 -14
- data/lib/rigor/inference/method_dispatcher/composite_receiver.rb +144 -0
- data/lib/rigor/inference/method_dispatcher/constant_folding.rb +7 -5
- data/lib/rigor/inference/method_dispatcher/declared_constructor.rb +1 -1
- data/lib/rigor/inference/method_dispatcher/dependency_source.rb +90 -0
- data/lib/rigor/inference/method_dispatcher/discovered_method.rb +78 -0
- data/lib/rigor/inference/method_dispatcher/file_folding.rb +2 -2
- data/lib/rigor/inference/method_dispatcher/hkt_builtin_return.rb +40 -0
- data/lib/rigor/inference/method_dispatcher/iterator_dispatch.rb +1 -6
- data/lib/rigor/inference/method_dispatcher/literal_string_folding.rb +4 -2
- data/lib/rigor/inference/method_dispatcher/match_data_folding.rb +1 -1
- data/lib/rigor/inference/method_dispatcher/meta_introspection.rb +506 -0
- data/lib/rigor/inference/method_dispatcher/overload_selector.rb +2 -0
- data/lib/rigor/inference/method_dispatcher/plugin_contribution.rb +134 -0
- data/lib/rigor/inference/method_dispatcher/project_patched.rb +134 -0
- data/lib/rigor/inference/method_dispatcher/rbs_dispatch.rb +125 -43
- data/lib/rigor/inference/method_dispatcher/reduce_folding.rb +3 -4
- data/lib/rigor/inference/method_dispatcher/regexp_folding.rb +1 -1
- data/lib/rigor/inference/method_dispatcher/set_folding.rb +1 -1
- data/lib/rigor/inference/method_dispatcher/shape_dispatch.rb +19 -6
- data/lib/rigor/inference/method_dispatcher/singleton_folding.rb +3 -3
- data/lib/rigor/inference/method_dispatcher/singleton_mixin_dispatch.rb +7 -4
- data/lib/rigor/inference/method_dispatcher/static_refinement.rb +106 -0
- data/lib/rigor/inference/method_dispatcher/synthesized_stub.rb +41 -0
- data/lib/rigor/inference/method_dispatcher/synthetic_method_dispatch.rb +133 -0
- data/lib/rigor/inference/method_dispatcher/universal_object_dispatch.rb +2 -1
- data/lib/rigor/inference/method_dispatcher/user_class_fallback.rb +216 -0
- data/lib/rigor/inference/method_dispatcher.rb +175 -1361
- data/lib/rigor/inference/method_parameter_binder.rb +18 -18
- data/lib/rigor/inference/module_function_state.rb +5 -4
- data/lib/rigor/inference/mutation_widening.rb +20 -7
- data/lib/rigor/inference/narrowing/case_literals.rb +58 -0
- data/lib/rigor/inference/narrowing/class_dispatch.rb +302 -0
- data/lib/rigor/inference/narrowing/complements.rb +322 -0
- data/lib/rigor/inference/narrowing/presence_predicates.rb +205 -0
- data/lib/rigor/inference/narrowing/regex_match.rb +499 -0
- data/lib/rigor/inference/narrowing.rb +86 -1269
- data/lib/rigor/inference/object_mixins.rb +2 -2
- data/lib/rigor/inference/opaque_mutation.rb +214 -0
- data/lib/rigor/inference/optimistic_origin.rb +52 -14
- data/lib/rigor/inference/parameter_inference_collector.rb +1 -1
- data/lib/rigor/inference/pre_eval_constants.rb +11 -9
- data/lib/rigor/inference/precision_scanner.rb +27 -2
- data/lib/rigor/inference/project_patched_methods.rb +3 -3
- data/lib/rigor/inference/range_constant.rb +3 -3
- data/lib/rigor/inference/rbs_type_translator.rb +2 -2
- data/lib/rigor/inference/refine_self.rb +8 -7
- data/lib/rigor/inference/refined_dispatch.rb +2 -2
- data/lib/rigor/inference/return_barrier.rb +24 -9
- data/lib/rigor/inference/scope_indexer/alias_def_nodes.rb +311 -0
- data/lib/rigor/inference/scope_indexer/census_scope.rb +47 -0
- data/lib/rigor/inference/scope_indexer/certainty.rb +2 -2
- data/lib/rigor/inference/scope_indexer/class_cvar_census.rb +282 -0
- data/lib/rigor/inference/scope_indexer/class_cvars_collector.rb +12 -5
- data/lib/rigor/inference/scope_indexer/class_declarations.rb +228 -0
- data/lib/rigor/inference/scope_indexer/class_ivar_index.rb +2028 -0
- data/lib/rigor/inference/scope_indexer/constant_ivar_value.rb +4 -3
- data/lib/rigor/inference/scope_indexer/constant_tables.rb +844 -0
- data/lib/rigor/inference/scope_indexer/cvar_hierarchy.rb +159 -0
- data/lib/rigor/inference/scope_indexer/declaration_artifacts.rb +219 -0
- data/lib/rigor/inference/scope_indexer/declaration_signature.rb +212 -0
- data/lib/rigor/inference/scope_indexer/def_nestings_collector.rb +2 -2
- data/lib/rigor/inference/scope_indexer/factory_call_resolver.rb +53 -0
- data/lib/rigor/inference/scope_indexer/literal_receiver_mutations.rb +266 -0
- data/lib/rigor/inference/scope_indexer/member_layouts_collector.rb +8 -7
- data/lib/rigor/inference/scope_indexer/mixin_accumulator.rb +1 -1
- data/lib/rigor/inference/scope_indexer/mixin_effects.rb +470 -0
- data/lib/rigor/inference/scope_indexer/mixin_tables.rb +388 -0
- data/lib/rigor/inference/scope_indexer/mutated_carrier_widening.rb +163 -0
- data/lib/rigor/inference/scope_indexer/mutated_element_census.rb +211 -0
- data/lib/rigor/inference/scope_indexer/node_propagation.rb +520 -0
- data/lib/rigor/inference/scope_indexer/program_globals.rb +154 -0
- data/lib/rigor/inference/scope_indexer/published_constant_cvars.rb +146 -0
- data/lib/rigor/inference/scope_indexer/published_constant_ivars.rb +181 -0
- data/lib/rigor/inference/scope_indexer/shared_walk_tables.rb +823 -0
- data/lib/rigor/inference/scope_indexer/singleton_class_sources.rb +85 -0
- data/lib/rigor/inference/scope_indexer/superclasses_collector.rb +5 -5
- data/lib/rigor/inference/scope_indexer.rb +2657 -9558
- data/lib/rigor/inference/self_call_ivar_writes.rb +22 -3
- data/lib/rigor/inference/set_mutation.rb +2 -2
- data/lib/rigor/inference/singleton_hook_definers.rb +185 -0
- data/lib/rigor/inference/statement_evaluator/def_arguments_and_assertions.rb +365 -0
- data/lib/rigor/inference/statement_evaluator/pattern_bindings.rb +581 -0
- data/lib/rigor/inference/statement_evaluator.rb +201 -1008
- data/lib/rigor/inference/synthetic_method_scanner.rb +0 -3
- data/lib/rigor/language_server/completion_provider.rb +8 -8
- data/lib/rigor/language_server/diagnostic_publisher.rb +6 -7
- data/lib/rigor/language_server/document_symbol_provider.rb +4 -6
- data/lib/rigor/language_server/folding_range_provider.rb +3 -3
- data/lib/rigor/language_server/hover_provider.rb +2 -2
- data/lib/rigor/language_server/loop.rb +2 -2
- data/lib/rigor/language_server/server.rb +3 -2
- data/lib/rigor/language_server/signature_help_provider.rb +7 -9
- data/lib/rigor/lens/document.rb +10 -1
- data/lib/rigor/lens/file_reader.rb +2 -1
- data/lib/rigor/mcp/loop.rb +48 -6
- data/lib/rigor/mcp/server.rb +248 -23
- data/lib/rigor/mcp/skill_catalog.rb +157 -0
- data/lib/rigor/plugin/base.rb +22 -4
- data/lib/rigor/plugin/effect_attribution.rb +1 -1
- data/lib/rigor/plugin/inflector.rb +2 -2
- data/lib/rigor/plugin/io_boundary.rb +1 -1
- data/lib/rigor/plugin/loader.rb +4 -4
- data/lib/rigor/plugin/macro/heredoc_template.rb +4 -3
- data/lib/rigor/plugin/optimistic_return.rb +20 -0
- data/lib/rigor/plugin/registry.rb +2 -2
- data/lib/rigor/plugin/template_unit.rb +4 -2
- data/lib/rigor/plugin/trust_policy.rb +2 -1
- data/lib/rigor/plugin.rb +1 -1
- data/lib/rigor/protection/mutator.rb +8 -9
- data/lib/rigor/rbs_extended/reporter.rb +2 -2
- data/lib/rigor/rbs_extended.rb +2 -2
- data/lib/rigor/reflection/constant_ancestors.rb +1 -1
- data/lib/rigor/reflection/project_method.rb +2 -2
- data/lib/rigor/reflection.rb +4 -4
- data/lib/rigor/scope/discovery_index.rb +15 -10
- data/lib/rigor/scope/resolution_chain.rb +29 -6
- data/lib/rigor/scope.rb +89 -32
- data/lib/rigor/sig_gen/generator.rb +5 -4
- data/lib/rigor/sig_gen/renderer.rb +3 -3
- data/lib/rigor/sig_gen/writer.rb +8 -6
- data/lib/rigor/source/parameter_envelope.rb +1 -1
- data/lib/rigor/triage/catalogue.rb +4 -4
- data/lib/rigor/type/combinator.rb +2 -2
- data/lib/rigor/type/data_instance.rb +2 -2
- data/lib/rigor/type/struct_instance.rb +3 -3
- data/lib/rigor/type_node/generic.rb +2 -1
- data/lib/rigor/type_of_memo.rb +2 -1
- data/lib/rigor/typing_state.rb +3 -2
- data/lib/rigor/version.rb +1 -1
- data/plugins/rigor-actioncable/lib/rigor/plugin/actioncable/analyzer.rb +2 -2
- data/plugins/rigor-actioncable/lib/rigor/plugin/actioncable/channel_discoverer.rb +1 -1
- data/plugins/rigor-actionmailer/lib/rigor/plugin/actionmailer/mailer_discoverer.rb +4 -4
- data/plugins/rigor-actionmailer/lib/rigor/plugin/actionmailer.rb +1 -1
- data/plugins/rigor-actionpack/lib/rigor/plugin/actionpack/controller_discoverer.rb +4 -3
- data/plugins/rigor-actionpack/lib/rigor/plugin/actionpack/effects.rb +7 -5
- data/plugins/rigor-actionpack/lib/rigor/plugin/actionpack/erb_compiler.rb +4 -2
- data/plugins/rigor-actionpack/lib/rigor/plugin/actionpack/render_locals.rb +1 -1
- data/plugins/rigor-actionpack/lib/rigor/plugin/actionpack/view_assigns.rb +3 -2
- data/plugins/rigor-actionpack/lib/rigor/plugin/actionpack.rb +7 -7
- data/plugins/rigor-activejob/lib/rigor/plugin/activejob/job_discoverer.rb +1 -1
- data/plugins/rigor-activejob/lib/rigor/plugin/activejob.rb +2 -2
- data/plugins/rigor-activerecord/lib/rigor/plugin/activerecord/model_discoverer.rb +9 -8
- data/plugins/rigor-activerecord/lib/rigor/plugin/activerecord/model_index.rb +3 -2
- data/plugins/rigor-activerecord/lib/rigor/plugin/activerecord/schema_parser.rb +15 -7
- data/plugins/rigor-activerecord/lib/rigor/plugin/activerecord/schema_table.rb +10 -3
- data/plugins/rigor-activerecord/lib/rigor/plugin/activerecord/structure_sql_parser.rb +12 -1
- data/plugins/rigor-activerecord/lib/rigor/plugin/activerecord.rb +20 -5
- data/plugins/rigor-activestorage/lib/rigor/plugin/activestorage/attachment_discoverer.rb +1 -1
- data/plugins/rigor-activestorage/lib/rigor/plugin/activestorage.rb +3 -2
- data/plugins/rigor-activesupport-core-ext/lib/rigor/plugin/activesupport_core_ext/effects.rb +1 -1
- data/plugins/rigor-activesupport-core-ext/lib/rigor/plugin/activesupport_core_ext.rb +8 -7
- data/plugins/rigor-dry-schema/lib/rigor/plugin/dry_schema.rb +1 -1
- data/plugins/rigor-dry-types/lib/rigor/plugin/dry_types/alias_scanner.rb +1 -1
- data/plugins/rigor-dry-types/lib/rigor/plugin/dry_types.rb +6 -7
- data/plugins/rigor-factorybot/lib/rigor/plugin/factorybot/factory_discoverer.rb +3 -2
- data/plugins/rigor-graphql/lib/rigor/plugin/graphql/type_scanner.rb +4 -3
- data/plugins/rigor-hanami/lib/rigor/plugin/hanami.rb +4 -2
- data/plugins/rigor-minitest/lib/rigor/plugin/minitest.rb +1 -1
- data/plugins/rigor-pundit/lib/rigor/plugin/pundit.rb +1 -1
- data/plugins/rigor-rails-i18n/lib/rigor/plugin/rails_i18n/analyzer.rb +5 -3
- data/plugins/rigor-rails-i18n/lib/rigor/plugin/rails_i18n.rb +1 -1
- data/plugins/rigor-rails-routes/lib/rigor/plugin/rails_routes/devise_routes.rb +4 -5
- data/plugins/rigor-rails-routes/lib/rigor/plugin/rails_routes/doorkeeper_routes.rb +2 -2
- data/plugins/rigor-rails-routes/lib/rigor/plugin/rails_routes/helper_discoverer.rb +5 -4
- data/plugins/rigor-rails-routes/lib/rigor/plugin/rails_routes/helper_table.rb +3 -2
- data/plugins/rigor-rails-routes/lib/rigor/plugin/rails_routes/routes_parser.rb +30 -31
- data/plugins/rigor-rails-routes/lib/rigor/plugin/rails_routes.rb +13 -15
- data/plugins/rigor-rbnacl/lib/rigor/plugin/rbnacl.rb +1 -1
- data/plugins/rigor-rspec/lib/rigor/plugin/rspec/let_scope_index.rb +4 -3
- data/plugins/rigor-rspec/lib/rigor/plugin/rspec/matcher_analyzer.rb +16 -13
- data/plugins/rigor-rspec/lib/rigor/plugin/rspec/scope_walker.rb +3 -2
- data/plugins/rigor-shoulda-matchers/lib/rigor/plugin/shoulda_matchers/analyzer.rb +6 -6
- data/plugins/rigor-sidekiq/lib/rigor/plugin/sidekiq/analyzer.rb +3 -3
- data/plugins/rigor-sorbet/lib/rigor/plugin/sorbet/assertion_recognizer.rb +2 -2
- data/plugins/rigor-sorbet/lib/rigor/plugin/sorbet/catalog.rb +3 -2
- data/plugins/rigor-sorbet/lib/rigor/plugin/sorbet/catalog_walker.rb +6 -5
- data/plugins/rigor-sorbet/lib/rigor/plugin/sorbet/sig_parser.rb +2 -2
- data/plugins/rigor-sorbet/lib/rigor/plugin/sorbet/sigil_detector.rb +4 -5
- data/plugins/rigor-sorbet/lib/rigor/plugin/sorbet/type_translator.rb +1 -1
- data/plugins/rigor-sorbet/lib/rigor/plugin/sorbet.rb +3 -4
- data/sig/rigor/analysis/check_rules/suppression.rbs +9 -0
- data/sig/rigor/analysis/dependency_recorder.rbs +9 -0
- data/sig/rigor/inference.rbs +275 -11
- data/sig/rigor/plugin/base.rbs +14 -5
- data/sig/rigor/plugin/optimistic_return.rbs +16 -0
- data/sig/rigor/scope.rbs +7 -1
- data/sig/rigor/source.rbs +4 -0
- data/skills/rigor-mcp-setup/SKILL.md +20 -6
- data/skills/rigor-plugin-review/SKILL.md +3 -3
- data/skills/rigor-type-oracle/references/01-oracle-commands.md +1 -1
- metadata +90 -3
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "prism"
|
|
4
|
+
|
|
5
|
+
require_relative "../../scope"
|
|
6
|
+
require_relative "../../source/node_children"
|
|
7
|
+
require_relative "../../type"
|
|
8
|
+
require_relative "../error_info"
|
|
9
|
+
require_relative "../global_write_census"
|
|
10
|
+
require_relative "../in_effect_refinements"
|
|
11
|
+
require_relative "../last_line"
|
|
12
|
+
require_relative "../last_status"
|
|
13
|
+
require_relative "empty_seed"
|
|
14
|
+
|
|
15
|
+
module Rigor
|
|
16
|
+
module Inference
|
|
17
|
+
module ScopeIndexer
|
|
18
|
+
# The program-global pre-pass of {ScopeIndexer#index}, moved out of `scope_indexer.rb` whole (ADR-116 WD9,
|
|
19
|
+
# L4). {.seed_program_globals} collects the file's global writes and the censuses the same walk fills, joins
|
|
20
|
+
# Ruby's own declarations into the seeds, and binds each global into the scope it is handed; every other
|
|
21
|
+
# function here is a step of that. It calls nothing of the indexer but {EmptySeed}, a sibling file:
|
|
22
|
+
# `scope_indexer.rb` requires this file, and this file does not require it back.
|
|
23
|
+
module ProgramGlobals
|
|
24
|
+
module_function
|
|
25
|
+
|
|
26
|
+
# The program-global pre-pass's tables on the seeded scope's discovery index, and each global materialised into
|
|
27
|
+
# the scope's own `globals` map (see the call site) — a declared one's seed ({#join_declared_globals}) under the
|
|
28
|
+
# ADR-58 `:global` mark — with the `gets` / `readline` names the file patches in and whether it may set `$?` to
|
|
29
|
+
# nil or define a singleton `===`.
|
|
30
|
+
def seed_program_globals(root, seeded_scope)
|
|
31
|
+
program_globals, census = build_program_global_index(root, seeded_scope)
|
|
32
|
+
census[:discovered_global_write_census] =
|
|
33
|
+
union_write_census(seeded_scope.discovered_global_write_census, census.delete(:write_census).census)
|
|
34
|
+
seeds = join_declared_globals(program_globals, seeded_scope.environment)
|
|
35
|
+
seeded_scope = seeded_scope.with_discovery(
|
|
36
|
+
seeded_scope.discovery.with(program_globals: program_globals, program_global_seeds: seeds, **census)
|
|
37
|
+
)
|
|
38
|
+
program_globals.each do |name, written|
|
|
39
|
+
seed = seeds[name]
|
|
40
|
+
seeded_scope =
|
|
41
|
+
seed ? seeded_scope.seed_declaration_sourced_global(name, seed) : seeded_scope.with_global(name, written)
|
|
42
|
+
end
|
|
43
|
+
seeded_scope
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
# Slice 7 phase 6 — program-global pre-pass. Globals are process-wide so the accumulator is a flat `Hash[Symbol,
|
|
47
|
+
# Type::t]` populated from every `Prism::GlobalVariableWriteNode` in the program (top-level AND inside method
|
|
48
|
+
# bodies). The same accumulator is seeded into every method body and the top-level scope.
|
|
49
|
+
#
|
|
50
|
+
# Issue #1359 — except the frame-local specials ({FRAME_LOCAL_GLOBALS}): Ruby keeps `$_` and `$~` in the slot
|
|
51
|
+
# of the method, class, module or file body that writes them, so a write binds only that body and its blocks,
|
|
52
|
+
# which the flow binding already carries, and every other body starts from its own slot.
|
|
53
|
+
FRAME_LOCAL_GLOBALS = %i[$_ $~].freeze
|
|
54
|
+
# Issue #1360 — nor `$!`, `$@` and `$?`, which hold no program-wide value either: the first two are the rescue
|
|
55
|
+
# clause's that is running, and `$?` the thread's. Ruby refuses a write to `$!` or `$?` (`NameError`), and a
|
|
56
|
+
# write to `$@` sets the backtrace of the exception being rescued.
|
|
57
|
+
UNSEEDED_GLOBALS = (FRAME_LOCAL_GLOBALS + %i[$! $@ $?]).freeze
|
|
58
|
+
private_constant :FRAME_LOCAL_GLOBALS, :UNSEEDED_GLOBALS
|
|
59
|
+
|
|
60
|
+
#
|
|
61
|
+
# The same walk collects the `gets` / `readline` names the file patches in through the `define_method` family
|
|
62
|
+
# ({LastLine.patched_readers}), which it reaches in every node too, and whether the file holds a call that may
|
|
63
|
+
# set `$?` to nil ({LastStatus.clears?}) or a `define_method` naming `===` ({ErrorInfo.defines_case_equality?}).
|
|
64
|
+
# Issue #1415 — the census also carries the file's evidence about the `self` of its implicit-self readers
|
|
65
|
+
# ({LastLine::SelfEvidence}), which walks the file only when a reader condition first asks. Issue #1367 — and
|
|
66
|
+
# the file's {GlobalWriteCensus}, which the `global.*` write rules read.
|
|
67
|
+
# @return the `program_globals` table and the census, keyed by the discovery index members it fills
|
|
68
|
+
def build_program_global_index(root, default_scope)
|
|
69
|
+
accumulator = {}
|
|
70
|
+
in_effect = InEffectRefinements.new(root)
|
|
71
|
+
census = { patched_line_readers: Set.new, clears_last_status: false, defines_case_equality: false,
|
|
72
|
+
write_census: GlobalWriteCensus::Collector.new(in_effect) }
|
|
73
|
+
gather_global_writes(root, default_scope, accumulator, census)
|
|
74
|
+
census[:patched_line_readers] = census[:patched_line_readers].freeze
|
|
75
|
+
census[:implicit_self_evidence] = LastLine::SelfEvidence.new(root)
|
|
76
|
+
census[:in_effect_refinements] = in_effect
|
|
77
|
+
[accumulator.freeze, census]
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
# Issue #1362 (ADR-117 WD1) — the seed of each global in `program_globals` Ruby's own signatures declare
|
|
81
|
+
# (`$VERBOSE: bool?`, `$stdout: IO`). Such a global holds what the interpreter set, from the command line or at
|
|
82
|
+
# boot, until a write, and any loaded file may write it, so its seed is the declared type joined with the file's
|
|
83
|
+
# writes, which can only widen it: `$VERBOSE = true` seeds `bool`, and `$stdout = StringIO.new` seeds
|
|
84
|
+
# `IO | StringIO`. A global only a project or a gem declares, or none does, has no entry here and is seeded with
|
|
85
|
+
# the union of the file's writes, as before, and so is a separator ({UNJOINED_SEPARATORS}).
|
|
86
|
+
#
|
|
87
|
+
# Issue #1437 — the declared `nil` is not joined (`$VERBOSE` joins `bool`, not `bool?`): a value that mixes the
|
|
88
|
+
# global with something else (`c ? $VERBOSE : true`) would carry it past the ADR-58 mark into a report the
|
|
89
|
+
# file's writes did not earn. A `nil` the file writes is joined as any write is.
|
|
90
|
+
def join_declared_globals(program_globals, environment)
|
|
91
|
+
program_globals.each_with_object({}) do |(name, written), seeds|
|
|
92
|
+
next if UNJOINED_SEPARATORS.include?(name)
|
|
93
|
+
|
|
94
|
+
declared = non_nil_declared(environment.global_for_name(name, builtin: true))
|
|
95
|
+
seeds[name] = Type::Combinator.union(declared, written) if declared
|
|
96
|
+
end.freeze
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
# `declared` without its `nil` member, or nil when it has no other.
|
|
100
|
+
def non_nil_declared(declared)
|
|
101
|
+
return declared unless declared.is_a?(Type::Union) || nil_type?(declared)
|
|
102
|
+
|
|
103
|
+
members = declared.is_a?(Type::Union) ? declared.members.reject { |member| nil_type?(member) } : []
|
|
104
|
+
members.empty? ? nil : Type::Combinator.union(*members)
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
def nil_type?(type)
|
|
108
|
+
(type.is_a?(Type::Constant) && type.value.nil?) ||
|
|
109
|
+
(type.is_a?(Type::Nominal) && type.class_name == "NilClass")
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
# Issue #1437 — the separators whose declared type is nil-bearing (`String?`, `Regexp | String | nil`) stay out
|
|
113
|
+
# of the join for now. The declared `nil` would reach `call.possible-nil-receiver` through a value that mixes
|
|
114
|
+
# the global with something else (`sep = c ? $/ : ";"`, `sep = given || $/`), which the ADR-58 mark does not
|
|
115
|
+
# follow.
|
|
116
|
+
UNJOINED_SEPARATORS = %i[$/ $, $; $\\ $-0 $-F $-i].freeze
|
|
117
|
+
private_constant :UNJOINED_SEPARATORS
|
|
118
|
+
|
|
119
|
+
# `top_level` is false inside a `class` / `module` body, for the census's top-level mixins.
|
|
120
|
+
def gather_global_writes(node, scope, accumulator, census, top_level: true)
|
|
121
|
+
return unless node.is_a?(Prism::Node)
|
|
122
|
+
|
|
123
|
+
if node.is_a?(Prism::GlobalVariableWriteNode) && !UNSEEDED_GLOBALS.include?(node.name)
|
|
124
|
+
record_global_write(node, scope, accumulator)
|
|
125
|
+
end
|
|
126
|
+
readers = LastLine.patched_readers(node)
|
|
127
|
+
census[:patched_line_readers].merge(readers) if readers
|
|
128
|
+
census[:clears_last_status] ||= LastStatus.clears?(node)
|
|
129
|
+
census[:defines_case_equality] ||= ErrorInfo.defines_case_equality?(node)
|
|
130
|
+
census[:write_census].visit(node, top_level: top_level)
|
|
131
|
+
inner = top_level && !(node.is_a?(Prism::ClassNode) || node.is_a?(Prism::ModuleNode))
|
|
132
|
+
node.rigor_each_child { |c| gather_global_writes(c, scope, accumulator, census, top_level: inner) }
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
# The project's census with the analysed file's own, answering `seed` itself when the file adds nothing to it.
|
|
136
|
+
def union_write_census(seed, file_census)
|
|
137
|
+
return seed if file_census.empty? || file_census.subset?(seed)
|
|
138
|
+
|
|
139
|
+
(seed | file_census).freeze
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
def record_global_write(node, scope, accumulator)
|
|
143
|
+
rvalue_type = EmptySeed.erase(node.value, scope.type_of(node.value))
|
|
144
|
+
existing = accumulator[node.name]
|
|
145
|
+
accumulator[node.name] =
|
|
146
|
+
existing ? Type::Combinator.union(existing, rvalue_type) : rvalue_type
|
|
147
|
+
end
|
|
148
|
+
|
|
149
|
+
private_class_method :build_program_global_index, :join_declared_globals, :non_nil_declared, :nil_type?,
|
|
150
|
+
:gather_global_writes, :union_write_census, :record_global_write
|
|
151
|
+
end
|
|
152
|
+
end
|
|
153
|
+
end
|
|
154
|
+
end
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "prism"
|
|
4
|
+
|
|
5
|
+
require_relative "../../analysis/check_rules/published_constant_guard"
|
|
6
|
+
require_relative "../../source/node_children"
|
|
7
|
+
require_relative "../../type"
|
|
8
|
+
require_relative "../declaration_walk/rules"
|
|
9
|
+
require_relative "../declaration_walk/traversal"
|
|
10
|
+
require_relative "census_scope"
|
|
11
|
+
require_relative "cvar_hierarchy"
|
|
12
|
+
|
|
13
|
+
module Rigor
|
|
14
|
+
module Inference
|
|
15
|
+
module ScopeIndexer
|
|
16
|
+
# Issue #3443 — the class-variable twin of {PublishedConstantIvars}: `{class name => Set[cvar name]}` for a
|
|
17
|
+
# cvar whose class-cvar seed may be a copy of a foreign published constant (`@@mode = AppConfig::MODE` in
|
|
18
|
+
# `def self.setup`, read as `@@mode == :production` in a sibling). {.seed_published_constant_cvars} is the
|
|
19
|
+
# entry `ScopeIndexer.index` calls once the file's constant tables are seeded; {Collector} is the walk it runs.
|
|
20
|
+
#
|
|
21
|
+
# The census keys each write exactly as the class-cvar census ({ClassCvarsCollector}) does, by the lexical
|
|
22
|
+
# cref of a `def` or a class body, and joins it along the same in-file superclass tree ({CvarHierarchy}), so a
|
|
23
|
+
# mark follows the class-cvar seed it rides on: a subclass whose entry the tree join unioned with a
|
|
24
|
+
# superclass's `@@mode = MODE` is marked too. It over-approximates in the withholding direction: every write
|
|
25
|
+
# form counts (`@@x ||= MODE`, `@@x += …`, a class-body write, `class_variable_set`), and an open tree marks
|
|
26
|
+
# each of its members. The mark can only withhold a finding, so neither can manufacture one.
|
|
27
|
+
module PublishedConstantCvars
|
|
28
|
+
module_function
|
|
29
|
+
|
|
30
|
+
# Runs only when the project published something and the file's class-cvar census seeds at least one
|
|
31
|
+
# `Type::Constant`: a seed that is not a constant never folds a predicate, so there is nothing to withhold.
|
|
32
|
+
def seed_published_constant_cvars(seeded_scope, root)
|
|
33
|
+
return seeded_scope if seeded_scope.published_constant_names.empty?
|
|
34
|
+
|
|
35
|
+
cvars = seeded_scope.discovery.class_cvars
|
|
36
|
+
return seeded_scope unless cvars.any? { |_, entries| entries.any? { |_, type| type.is_a?(Type::Constant) } }
|
|
37
|
+
|
|
38
|
+
collector = Collector.new
|
|
39
|
+
DeclarationWalk.run(root, [collector],
|
|
40
|
+
DeclarationWalk::Context.root(scope: seeded_scope, nesting: EMPTY_NESTING))
|
|
41
|
+
table = marked_cvars(collector.joined_table(seeded_scope), cvars)
|
|
42
|
+
return seeded_scope if table.empty?
|
|
43
|
+
|
|
44
|
+
seeded_scope.with_discovery(seeded_scope.discovery.with(published_constant_cvars: table))
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
# The census as the discovery index holds it: a class's cvar is marked when some write of it in the class's
|
|
48
|
+
# tree is rooted (the joined row is not {NOT_ROOTED}) and the class-cvar census seeds it with a constant.
|
|
49
|
+
def marked_cvars(joined, cvars)
|
|
50
|
+
joined.filter_map do |class_name, entries|
|
|
51
|
+
seeds = cvars[class_name] || {}
|
|
52
|
+
names = entries.filter_map do |name, rooted|
|
|
53
|
+
name if rooted != NOT_ROOTED && seeds[name].is_a?(Type::Constant)
|
|
54
|
+
end
|
|
55
|
+
[class_name, names.to_set.freeze] unless names.empty?
|
|
56
|
+
end.to_h.freeze
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
# A write's row is a type so {CvarHierarchy.join} can union it across a tree as it unions the class-cvar
|
|
60
|
+
# census's: `Constant[true]` for a rooted write, {NOT_ROOTED} for any other. A joined row equal to
|
|
61
|
+
# {NOT_ROOTED} saw no rooted write; a union with `Constant[true]`, or the `Dynamic` an open tree adds, did.
|
|
62
|
+
ROOTED = Type::Combinator.constant_of(true)
|
|
63
|
+
NOT_ROOTED = Type::Combinator.constant_of(false)
|
|
64
|
+
|
|
65
|
+
# The census walk: a `def` body's cvar writes and a `class` / `module` body's own, each under the lexical
|
|
66
|
+
# cref {ClassCvarsCollector} keys the same write by, with the headers {CvarHierarchy} joins along.
|
|
67
|
+
class Collector
|
|
68
|
+
include DeclarationWalk::Collector
|
|
69
|
+
|
|
70
|
+
def initialize
|
|
71
|
+
@table = {}
|
|
72
|
+
@headers = CvarHierarchy.headers
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
def on_declaration(node, context, body)
|
|
76
|
+
PublishedConstantCvars.gather_body(node.body, body.prefix, body.scope, @table)
|
|
77
|
+
CvarHierarchy.record(@headers, node, context, body)
|
|
78
|
+
DeclarationWalk::DESCEND
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
def on_def(node, context)
|
|
82
|
+
PublishedConstantCvars.gather_def(node, context.prefix, context.scope, @table)
|
|
83
|
+
DeclarationWalk::DECLINE
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
# The rows joined along each class's in-file superclass tree.
|
|
87
|
+
def joined_table(scope) = CvarHierarchy.join(@table, @headers, scope)
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
def gather_def(def_node, qualified_prefix, scope, table)
|
|
91
|
+
return if def_node.body.nil? || qualified_prefix.empty?
|
|
92
|
+
|
|
93
|
+
class_name = qualified_prefix.join("::")
|
|
94
|
+
body_scope = CensusScope.census_body_scope(scope, qualified_prefix, Type::Combinator.nominal_of(class_name))
|
|
95
|
+
gather(def_node.body, body_scope, class_name, table)
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
def gather_body(body, qualified_prefix, scope, table)
|
|
99
|
+
return if body.nil? || qualified_prefix.empty?
|
|
100
|
+
|
|
101
|
+
class_name = qualified_prefix.join("::")
|
|
102
|
+
body_scope = CensusScope.census_body_scope(scope, qualified_prefix, Type::Combinator.singleton_of(class_name))
|
|
103
|
+
gather(body, body_scope, class_name, table)
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
# Every cvar write below `node` up to the next `def`, `class` or `module`, which their own events enter.
|
|
107
|
+
def gather(node, scope, class_name, table)
|
|
108
|
+
return unless node.is_a?(Prism::Node)
|
|
109
|
+
|
|
110
|
+
case node
|
|
111
|
+
when Prism::ClassVariableWriteNode, Prism::ClassVariableOrWriteNode,
|
|
112
|
+
Prism::ClassVariableAndWriteNode, Prism::ClassVariableOperatorWriteNode
|
|
113
|
+
record(table, class_name, node.name, node.value, scope)
|
|
114
|
+
when Prism::ClassVariableTargetNode
|
|
115
|
+
record(table, class_name, node.name, nil, scope)
|
|
116
|
+
when Prism::CallNode
|
|
117
|
+
gather_reflective(node, scope, class_name, table)
|
|
118
|
+
end
|
|
119
|
+
return if ClassIvarIndex::IVAR_BARRIER_NODES.any? { |klass| node.is_a?(klass) }
|
|
120
|
+
|
|
121
|
+
node.rigor_each_child { |child| gather(child, scope, class_name, table) }
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
# `class_variable_set(:@@x, v)` on an implicit or `self` receiver, as the class-cvar census reads it.
|
|
125
|
+
def gather_reflective(node, scope, class_name, table)
|
|
126
|
+
return unless node.name == :class_variable_set && (node.receiver.nil? || node.receiver.is_a?(Prism::SelfNode))
|
|
127
|
+
|
|
128
|
+
args = node.arguments&.arguments
|
|
129
|
+
return unless args&.size == 2
|
|
130
|
+
|
|
131
|
+
name_node, value = args
|
|
132
|
+
name = name_node.unescaped if name_node.is_a?(Prism::SymbolNode) || name_node.is_a?(Prism::StringNode)
|
|
133
|
+
record(table, class_name, name.to_sym, value, scope) if name
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
def record(table, class_name, name, value, scope)
|
|
137
|
+
rooted = !value.nil? && Analysis::CheckRules::PublishedConstantGuard.rooted?(value, scope)
|
|
138
|
+
entries = (table[class_name] ||= {})
|
|
139
|
+
entries[name] = rooted || entries[name] == ROOTED ? ROOTED : NOT_ROOTED
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
private_class_method :marked_cvars, :gather, :gather_reflective, :record
|
|
143
|
+
end
|
|
144
|
+
end
|
|
145
|
+
end
|
|
146
|
+
end
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "prism"
|
|
4
|
+
|
|
5
|
+
require_relative "../../analysis/check_rules/published_constant_guard"
|
|
6
|
+
require_relative "../../source/node_children"
|
|
7
|
+
require_relative "../../type"
|
|
8
|
+
require_relative "../declaration_walk/rules"
|
|
9
|
+
require_relative "census_scope"
|
|
10
|
+
|
|
11
|
+
module Rigor
|
|
12
|
+
module Inference
|
|
13
|
+
module ScopeIndexer
|
|
14
|
+
# The #667 census of the instance variables seeded from a published constant, moved out of
|
|
15
|
+
# `scope_indexer.rb` whole (ADR-116 WD9, U3). {.seed_published_constant_ivars} walks one file and puts the
|
|
16
|
+
# table on the discovery index of the scope it is handed; every other function here is an arm or a step of
|
|
17
|
+
# that walk. It asks {DeclarationWalk::Rules} for each declaration context and calls nothing left in
|
|
18
|
+
# `scope_indexer.rb`, which requires this file; this file does not require it back and reads none of the
|
|
19
|
+
# indexer's constants.
|
|
20
|
+
module PublishedConstantIvars
|
|
21
|
+
module_function
|
|
22
|
+
|
|
23
|
+
# Issue #667 — `{class name => Set[ivar name]}` for an ivar whose class-ivar seed is a copy of a
|
|
24
|
+
# foreign published constant (`@mode = AppConfig::MODE` in `initialize`). The cross-method half of the
|
|
25
|
+
# copy provenance: the write and the `@mode == :production` that reads it sit in different method
|
|
26
|
+
# bodies, so no flow edge connects them and the fact has to be censused per class, exactly as the
|
|
27
|
+
# ADR-58 nil seed it rides beside is. Runs only when the project published something.
|
|
28
|
+
def seed_published_constant_ivars(seeded_scope, root)
|
|
29
|
+
return seeded_scope if seeded_scope.published_constant_names.empty?
|
|
30
|
+
|
|
31
|
+
table = {}
|
|
32
|
+
walk_published_constant_ivars(root, [], seeded_scope, table)
|
|
33
|
+
return seeded_scope if table.empty?
|
|
34
|
+
|
|
35
|
+
seeded_scope.with_discovery(
|
|
36
|
+
seeded_scope.discovery.with(published_constant_ivars: table.transform_values(&:freeze).freeze)
|
|
37
|
+
)
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
# `def_owner` names the class a `def` leaf's ivar writes belong to when `self` is
|
|
41
|
+
# rebound — see {ClassIvarIndex.walk_class_ivars}; `[]` marks a self no name covers.
|
|
42
|
+
def walk_published_constant_ivars(node, qualified_prefix, scope, table, def_owner: nil,
|
|
43
|
+
singleton_cref: false)
|
|
44
|
+
return unless node.is_a?(Prism::Node)
|
|
45
|
+
|
|
46
|
+
case node
|
|
47
|
+
when Prism::ClassNode, Prism::ModuleNode
|
|
48
|
+
return if walk_published_ivar_declaration?(node, qualified_prefix, scope, table,
|
|
49
|
+
def_owner, singleton_cref)
|
|
50
|
+
when Prism::SingletonClassNode
|
|
51
|
+
# The expression evaluates in the enclosing cref; the body's cref is unnameable.
|
|
52
|
+
return walk_singleton_published_ivars(node, qualified_prefix, scope, table,
|
|
53
|
+
def_owner, singleton_cref)
|
|
54
|
+
when Prism::ConstantWriteNode, Prism::ConstantPathWriteNode,
|
|
55
|
+
Prism::ConstantOrWriteNode, Prism::ConstantPathOrWriteNode
|
|
56
|
+
return if walk_published_ivar_meta_new?(node, qualified_prefix, scope, table,
|
|
57
|
+
def_owner, singleton_cref)
|
|
58
|
+
when Prism::CallNode
|
|
59
|
+
return if walk_published_ivar_eval_call?(node, qualified_prefix, scope, table,
|
|
60
|
+
def_owner, singleton_cref)
|
|
61
|
+
else
|
|
62
|
+
return if walk_published_ivar_leaf?(node, qualified_prefix, scope, table, def_owner)
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
node.rigor_each_child do |child|
|
|
66
|
+
walk_published_constant_ivars(child, qualified_prefix, scope, table,
|
|
67
|
+
def_owner: def_owner, singleton_cref: singleton_cref)
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
# The remaining leaf arms of {#walk_published_constant_ivars}: a `def self.…` body writes the
|
|
72
|
+
# singleton's ivars, which take no instance seed at all; an ivar write seeds the owner row.
|
|
73
|
+
# Returns true when the node was consumed and its children must not be walked.
|
|
74
|
+
def walk_published_ivar_leaf?(node, qualified_prefix, scope, table, def_owner)
|
|
75
|
+
return !node.receiver.nil? if node.is_a?(Prism::DefNode)
|
|
76
|
+
return false unless node.is_a?(Prism::InstanceVariableWriteNode)
|
|
77
|
+
|
|
78
|
+
record_published_constant_ivar(node, def_owner || qualified_prefix, rvalue_scope(scope, qualified_prefix),
|
|
79
|
+
table)
|
|
80
|
+
true
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
# The `K = Class.new { … }` arm of {#walk_published_constant_ivars}: the block's `def`
|
|
84
|
+
# ivar writes belong to the class the write names; its declarations stay lexical.
|
|
85
|
+
def walk_published_ivar_meta_new?(node, qualified_prefix, scope, table, def_owner,
|
|
86
|
+
singleton_cref)
|
|
87
|
+
split = DeclarationWalk::Rules.meta_new_block_split(node, qualified_prefix, def_owner, singleton_cref)
|
|
88
|
+
return false unless split
|
|
89
|
+
|
|
90
|
+
enclosing, body, body_self = split
|
|
91
|
+
enclosing.each do |part|
|
|
92
|
+
walk_published_constant_ivars(part, qualified_prefix, scope, table,
|
|
93
|
+
def_owner: def_owner, singleton_cref: singleton_cref)
|
|
94
|
+
end
|
|
95
|
+
if body
|
|
96
|
+
walk_published_constant_ivars(body, qualified_prefix, scope, table,
|
|
97
|
+
def_owner: body_self, singleton_cref: singleton_cref)
|
|
98
|
+
end
|
|
99
|
+
true
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
# The eval-family arm of {#walk_published_constant_ivars}: the receiver's `self` anchors
|
|
103
|
+
# `self::` declarations and owns the block's class-body-level `@x` seeds the way the
|
|
104
|
+
# enclosing class owns this body's.
|
|
105
|
+
def walk_published_ivar_eval_call?(node, qualified_prefix, scope, table, def_owner,
|
|
106
|
+
singleton_cref)
|
|
107
|
+
split = DeclarationWalk::Rules.eval_block_split(node, qualified_prefix, def_owner, singleton_cref)
|
|
108
|
+
return false unless split
|
|
109
|
+
|
|
110
|
+
enclosing, body, body_self = split
|
|
111
|
+
enclosing.each do |part|
|
|
112
|
+
walk_published_constant_ivars(part, qualified_prefix, scope, table,
|
|
113
|
+
def_owner: def_owner, singleton_cref: singleton_cref)
|
|
114
|
+
end
|
|
115
|
+
if body
|
|
116
|
+
walk_published_constant_ivars(body, qualified_prefix, scope, table,
|
|
117
|
+
def_owner: body_self, singleton_cref: singleton_cref)
|
|
118
|
+
end
|
|
119
|
+
true
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
# The class/module arm of {#walk_published_constant_ivars}: under an unnameable
|
|
123
|
+
# cref a bare/`self::` header opens `#<singleton>::Name` — ownerless; nameable
|
|
124
|
+
# headers re-anchor at a real cref.
|
|
125
|
+
def walk_published_ivar_declaration?(node, qualified_prefix, scope, table,
|
|
126
|
+
def_owner, singleton_cref)
|
|
127
|
+
ctx = DeclarationWalk::Rules.decl_body_context(node, qualified_prefix, def_owner, singleton_cref)
|
|
128
|
+
return false unless ctx
|
|
129
|
+
|
|
130
|
+
_self_decl, child_prefix, child_cref = ctx
|
|
131
|
+
return true unless node.body
|
|
132
|
+
|
|
133
|
+
walk_published_constant_ivars(node.body, child_cref ? [] : child_prefix, scope, table,
|
|
134
|
+
singleton_cref: child_cref)
|
|
135
|
+
true
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
def walk_singleton_published_ivars(node, qualified_prefix, scope, table, def_owner,
|
|
139
|
+
singleton_cref)
|
|
140
|
+
walk_published_constant_ivars(node.expression, qualified_prefix, scope, table,
|
|
141
|
+
def_owner: def_owner, singleton_cref: singleton_cref)
|
|
142
|
+
return unless node.body
|
|
143
|
+
|
|
144
|
+
# `def` below `class <<` defines singleton methods — their `@x` writes are the
|
|
145
|
+
# class object's own ivars, not instance-ivar seeds — so the body walks ownerless.
|
|
146
|
+
walk_published_constant_ivars(node.body, qualified_prefix, scope, table,
|
|
147
|
+
def_owner: [], singleton_cref: true)
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
# Issue #3437 — the scope the guard is asked under: the write's lexical cref, which is the walk's prefix and
|
|
151
|
+
# not the `def_owner` a rebound `self` credits the ivar to. `Scope#published_constant?` matches a file's own
|
|
152
|
+
# constant by the names a reference resolves to where it is written, so a scope with no `Module.nesting`
|
|
153
|
+
# would read every `@mode = MODE` as the top-level `MODE`. It is {CensusScope.census_body_scope}, the scope
|
|
154
|
+
# {ClassIvarIndex} typed the same rvalue under.
|
|
155
|
+
def rvalue_scope(scope, qualified_prefix)
|
|
156
|
+
return scope if qualified_prefix.empty?
|
|
157
|
+
|
|
158
|
+
CensusScope.census_body_scope(scope, qualified_prefix,
|
|
159
|
+
Type::Combinator.nominal_of(qualified_prefix.join("::")))
|
|
160
|
+
end
|
|
161
|
+
|
|
162
|
+
# The class-ivar accumulator (already seeded when this runs) is the pre-gate: an ivar whose seed is not
|
|
163
|
+
# a `Type::Constant` can never fold a predicate, so there is nothing for the mark to withhold and the
|
|
164
|
+
# guard's one interprocedural hop is not worth paying for it.
|
|
165
|
+
def record_published_constant_ivar(node, qualified_prefix, scope, table)
|
|
166
|
+
return if qualified_prefix.empty?
|
|
167
|
+
|
|
168
|
+
class_name = qualified_prefix.join("::")
|
|
169
|
+
return unless scope.class_ivars_for(class_name)[node.name].is_a?(Type::Constant)
|
|
170
|
+
return unless Analysis::CheckRules::PublishedConstantGuard.rooted?(node.value, scope)
|
|
171
|
+
|
|
172
|
+
(table[class_name] ||= Set.new) << node.name
|
|
173
|
+
end
|
|
174
|
+
|
|
175
|
+
private_class_method :walk_published_constant_ivars, :walk_published_ivar_leaf?, :walk_published_ivar_meta_new?,
|
|
176
|
+
:walk_published_ivar_eval_call?, :walk_published_ivar_declaration?,
|
|
177
|
+
:walk_singleton_published_ivars, :record_published_constant_ivar, :rvalue_scope
|
|
178
|
+
end
|
|
179
|
+
end
|
|
180
|
+
end
|
|
181
|
+
end
|