rigortype 0.4.5 → 0.4.7
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 +2 -2
- data/data/gem_overlay/activesupport/core_ext.rbs +16 -13
- data/data/vendored_gem_sigs/bundler/bundler.rbs +1 -1
- data/data/vendored_gem_sigs/rubygems/rubygems_extras.rbs +4 -3
- data/docs/handbook/01-getting-started.md +5 -2
- data/docs/handbook/11-sig-gen.md +61 -5
- data/docs/handbook/appendix-phpstan.md +4 -4
- data/docs/manual/02-cli-reference.md +192 -27
- data/docs/manual/03-configuration.md +38 -4
- data/docs/manual/04-diagnostics.md +1 -1
- data/docs/manual/06-baseline.md +6 -4
- data/docs/manual/09-editor-integration.md +13 -2
- data/docs/manual/10-mcp-server.md +47 -3
- data/docs/manual/12-caching.md +9 -1
- data/docs/manual/plugins/rigor-actionmailer.md +30 -0
- data/docs/manual/plugins/rigor-actionpack.md +49 -11
- data/docs/manual/plugins/rigor-activesupport-core-ext.md +20 -1
- data/docs/manual/plugins/rigor-devise.md +15 -0
- data/docs/manual/plugins/rigor-rspec.md +2 -1
- data/lib/rigor/analysis/baseline.rb +24 -27
- data/lib/rigor/analysis/buffer_binding.rb +14 -0
- data/lib/rigor/analysis/check_rules/always_truthy_condition_collector.rb +5 -6
- data/lib/rigor/analysis/check_rules/dead_assignment_collector.rb +2 -2
- data/lib/rigor/analysis/check_rules/declaration_sourced_guard.rb +4 -4
- data/lib/rigor/analysis/check_rules/duplicate_hash_key_collector.rb +2 -2
- data/lib/rigor/analysis/check_rules/inferred_param_guard.rb +105 -12
- data/lib/rigor/analysis/check_rules/ivar_write_collector.rb +143 -15
- data/lib/rigor/analysis/check_rules/lexical_method_sites.rb +4 -1
- data/lib/rigor/analysis/check_rules/main_pass_collector.rb +5 -8
- data/lib/rigor/analysis/check_rules/published_constant_guard.rb +1 -1
- data/lib/rigor/analysis/check_rules/rbs_receiver_surface.rb +66 -3
- data/lib/rigor/analysis/check_rules/rebinding_block_callees/dispatch.rb +112 -0
- data/lib/rigor/analysis/check_rules/rebinding_block_callees.rb +394 -0
- data/lib/rigor/analysis/check_rules/return_in_ensure_collector.rb +1 -2
- data/lib/rigor/analysis/check_rules/ruby_deprecations.rb +7 -0
- data/lib/rigor/analysis/check_rules/rule_ids.rb +1 -1
- data/lib/rigor/analysis/check_rules/rule_walk.rb +9 -7
- data/lib/rigor/analysis/check_rules/shadowed_rescue_collector.rb +3 -4
- data/lib/rigor/analysis/check_rules/special_global_setters.rb +3 -3
- data/lib/rigor/analysis/check_rules/unreachable_clause_collector.rb +53 -2
- data/lib/rigor/analysis/check_rules/void_value_use_collector.rb +1 -1
- data/lib/rigor/analysis/check_rules.rb +217 -52
- data/lib/rigor/analysis/crash_signature.rb +2 -2
- data/lib/rigor/analysis/dependency_recorder.rb +15 -4
- data/lib/rigor/analysis/dependency_source_inference/boundary_cross_reporter.rb +14 -3
- data/lib/rigor/analysis/dependency_source_inference/gem_resolver.rb +1 -1
- data/lib/rigor/analysis/dependency_source_inference/index.rb +6 -8
- data/lib/rigor/analysis/dependency_source_inference/walker.rb +4 -4
- data/lib/rigor/analysis/edit_replay.rb +154 -0
- data/lib/rigor/analysis/fact_store.rb +3 -3
- data/lib/rigor/analysis/incremental.rb +37 -0
- data/lib/rigor/analysis/incremental_run_slot/write_guard.rb +2 -2
- data/lib/rigor/analysis/incremental_run_slot.rb +2 -2
- data/lib/rigor/analysis/incremental_session.rb +202 -43
- data/lib/rigor/analysis/path_expansion.rb +41 -0
- data/lib/rigor/analysis/require_relative_closure.rb +100 -0
- data/lib/rigor/analysis/rule_catalog.rb +7 -3
- data/lib/rigor/analysis/run_disclosure_credit.rb +80 -0
- data/lib/rigor/analysis/run_disclosure_ledger.rb +155 -0
- data/lib/rigor/analysis/run_stats.rb +2 -2
- data/lib/rigor/analysis/runner/buffer_pool_dispatcher.rb +8 -4
- data/lib/rigor/analysis/runner/declaration_position.rb +1 -1
- data/lib/rigor/analysis/runner/diagnostic_aggregator.rb +204 -96
- data/lib/rigor/analysis/runner/effect_envelope_pass.rb +1 -1
- data/lib/rigor/analysis/runner/pool_coordinator.rb +157 -320
- data/lib/rigor/analysis/runner/project_pre_passes.rb +48 -6
- data/lib/rigor/analysis/runner/run_level_facts.rb +304 -0
- data/lib/rigor/analysis/runner/run_snapshots.rb +44 -54
- data/lib/rigor/analysis/runner/scan_environment.rb +51 -0
- data/lib/rigor/analysis/runner/worker_payload.rb +36 -0
- data/lib/rigor/analysis/runner.rb +233 -120
- data/lib/rigor/analysis/self_call_resolution_recorder.rb +1 -1
- data/lib/rigor/analysis/template_unit_positions.rb +2 -3
- data/lib/rigor/analysis/template_units.rb +9 -1
- data/lib/rigor/analysis/worker_session.rb +38 -33
- data/lib/rigor/bleeding_edge.rb +3 -6
- data/lib/rigor/builtins/imported_refinements.rb +6 -8
- data/lib/rigor/builtins/predefined_constant_refinements.rb +1 -1
- data/lib/rigor/builtins/regex_refinement.rb +4 -6
- data/lib/rigor/cache/descriptor.rb +6 -5
- data/lib/rigor/cache/incremental_snapshot.rb +60 -18
- data/lib/rigor/cache/rbs_cache_producer.rb +2 -2
- data/lib/rigor/cache/rbs_class_ancestor_table.rb +1 -1
- data/lib/rigor/cache/rbs_class_type_param_names.rb +2 -2
- data/lib/rigor/cache/rbs_constant_table.rb +1 -1
- data/lib/rigor/cache/rbs_descriptor.rb +54 -3
- data/lib/rigor/cache/rbs_environment.rb +4 -1
- data/lib/rigor/cache/rbs_environment_marshal_patch.rb +2 -2
- data/lib/rigor/cache/rbs_known_class_names.rb +1 -1
- data/lib/rigor/cache/store.rb +11 -10
- data/lib/rigor/ci_detector.rb +1 -1
- data/lib/rigor/cli/annotate_command.rb +24 -19
- data/lib/rigor/cli/baseline_command.rb +145 -55
- data/lib/rigor/cli/catalogue.rb +256 -0
- data/lib/rigor/cli/check_command.rb +188 -93
- data/lib/rigor/cli/check_runner_factory.rb +2 -2
- data/lib/rigor/cli/command.rb +15 -1
- data/lib/rigor/cli/coverage_command.rb +21 -8
- data/lib/rigor/cli/coverage_mutation.rb +5 -7
- data/lib/rigor/cli/coverage_renderer.rb +2 -1
- data/lib/rigor/cli/coverage_scan.rb +3 -5
- data/lib/rigor/cli/diff_command.rb +27 -21
- data/lib/rigor/cli/docs_command.rb +1 -2
- data/lib/rigor/cli/doctor_command.rb +12 -12
- data/lib/rigor/cli/effects_command.rb +50 -40
- data/lib/rigor/cli/effects_diff_renderer.rb +18 -17
- data/lib/rigor/cli/effects_explain_renderer.rb +13 -12
- data/lib/rigor/cli/effects_renderer.rb +2 -1
- data/lib/rigor/cli/effects_snapshot_command.rb +18 -17
- data/lib/rigor/cli/explain_command.rb +18 -8
- data/lib/rigor/cli/fused_protection_renderer.rb +2 -1
- data/lib/rigor/cli/json_document.rb +41 -0
- data/lib/rigor/cli/lens_command.rb +17 -13
- data/lib/rigor/cli/lsp_command.rb +250 -23
- data/lib/rigor/cli/mcp_command.rb +14 -8
- data/lib/rigor/cli/mutation_fork_scan.rb +1 -1
- data/lib/rigor/cli/mutation_protection_renderer.rb +3 -2
- data/lib/rigor/cli/options.rb +60 -4
- data/lib/rigor/cli/plugin_command.rb +93 -46
- data/lib/rigor/cli/plugins_command.rb +22 -18
- data/lib/rigor/cli/plugins_renderer.rb +34 -8
- data/lib/rigor/cli/protection_fork_scan.rb +2 -2
- data/lib/rigor/cli/protection_renderer.rb +2 -1
- data/lib/rigor/cli/show_bleedingedge_command.rb +23 -16
- data/lib/rigor/cli/sig_gen_command.rb +130 -34
- data/lib/rigor/cli/skill_command.rb +32 -3
- data/lib/rigor/cli/skill_deep_probe.rb +1 -1
- data/lib/rigor/cli/skill_describe.rb +1 -1
- data/lib/rigor/cli/trace_command.rb +14 -9
- data/lib/rigor/cli/triage_command.rb +10 -11
- data/lib/rigor/cli/triage_renderer.rb +2 -1
- data/lib/rigor/cli/type_of_command.rb +18 -12
- data/lib/rigor/cli/type_of_project_scope.rb +24 -0
- data/lib/rigor/cli/type_of_renderer.rb +4 -1
- data/lib/rigor/cli/type_scan_command.rb +14 -9
- data/lib/rigor/cli/type_scan_renderer.rb +2 -1
- data/lib/rigor/cli/unused_command.rb +27 -17
- data/lib/rigor/cli/upgrade_command.rb +5 -0
- data/lib/rigor/cli.rb +209 -54
- data/lib/rigor/config_audit.rb +17 -6
- data/lib/rigor/configuration/severity_profile.rb +5 -5
- data/lib/rigor/configuration.rb +86 -34
- data/lib/rigor/effects/definition_context.rb +0 -2
- data/lib/rigor/effects/envelope.rb +1 -1
- data/lib/rigor/effects/framework_units.rb +1 -1
- data/lib/rigor/effects/mutation_classifier.rb +4 -7
- data/lib/rigor/effects/propagator.rb +1 -1
- data/lib/rigor/effects/registry.rb +2 -2
- data/lib/rigor/effects/snapshot.rb +1 -1
- data/lib/rigor/effects/taint_cause.rb +0 -2
- data/lib/rigor/effects/unit_scan.rb +9 -13
- data/lib/rigor/environment/bundle_sig_discovery.rb +5 -9
- data/lib/rigor/environment/class_registry.rb +3 -3
- data/lib/rigor/environment/core_root.rb +77 -0
- data/lib/rigor/environment/default_libraries.rb +1 -1
- data/lib/rigor/environment/deferred_signature_plan.rb +283 -0
- data/lib/rigor/environment/gated_signature_guard.rb +1 -1
- data/lib/rigor/environment/gated_signature_plan.rb +5 -2
- data/lib/rigor/environment/lockfile_resolver.rb +28 -12
- data/lib/rigor/environment/member_consistency/comparator.rb +18 -1
- data/lib/rigor/environment/member_consistency.rb +56 -7
- data/lib/rigor/environment/missing_gem_constant_index.rb +3 -2
- data/lib/rigor/environment/project_path_gems.rb +124 -0
- data/lib/rigor/environment/rbs_hierarchy.rb +6 -15
- data/lib/rigor/environment/rbs_loader.rb +592 -70
- data/lib/rigor/environment/reflection.rb +7 -7
- data/lib/rigor/environment/required_features.rb +136 -32
- data/lib/rigor/environment/ruby_library_roots.rb +122 -0
- data/lib/rigor/environment/vendored_signature_plan.rb +153 -0
- data/lib/rigor/environment.rb +44 -11
- data/lib/rigor/flow_contribution/merger.rb +4 -4
- data/lib/rigor/inference/acceptance.rb +93 -32
- data/lib/rigor/inference/block_parameter_binder.rb +2 -3
- data/lib/rigor/inference/block_run_count.rb +178 -0
- data/lib/rigor/inference/budget_trace.rb +8 -2
- data/lib/rigor/inference/builtins/exception_catalog.rb +2 -2
- data/lib/rigor/inference/builtins/numeric_catalog.rb +2 -5
- data/lib/rigor/inference/builtins/random_catalog.rb +2 -2
- data/lib/rigor/inference/callee_mutation_chain.rb +126 -0
- data/lib/rigor/inference/callee_write_census.rb +815 -0
- data/lib/rigor/inference/construction_escape.rb +217 -0
- data/lib/rigor/inference/declaration_walk/traversal.rb +1 -1
- data/lib/rigor/inference/deep_erasure.rb +170 -0
- data/lib/rigor/inference/def_handle.rb +1 -1
- data/lib/rigor/inference/def_node_resolver.rb +1 -1
- data/lib/rigor/inference/def_return_typer.rb +204 -12
- data/lib/rigor/inference/definer_resolution.rb +21 -5
- data/lib/rigor/inference/definers_index.rb +106 -0
- data/lib/rigor/inference/direct_ivar_writes.rb +300 -0
- data/lib/rigor/inference/element_read_widening.rb +49 -3
- data/lib/rigor/inference/error_info.rb +17 -3
- data/lib/rigor/inference/expression_typer.rb +173 -57
- data/lib/rigor/inference/external_ancestor_resolution.rb +3 -4
- data/lib/rigor/inference/global_write_census.rb +110 -1
- data/lib/rigor/inference/global_writer_reach.rb +260 -0
- data/lib/rigor/inference/hkt_body.rb +1 -2
- data/lib/rigor/inference/hkt_body_parser.rb +3 -5
- data/lib/rigor/inference/hkt_reducer.rb +2 -2
- data/lib/rigor/inference/hkt_registry.rb +3 -5
- data/lib/rigor/inference/indexed_narrowing.rb +4 -7
- data/lib/rigor/inference/intervening_ivar_reset.rb +26 -4
- data/lib/rigor/inference/ivar_writer_census.rb +246 -0
- data/lib/rigor/inference/key_presence_guard.rb +2 -1
- data/lib/rigor/inference/loop_value_record.rb +57 -0
- data/lib/rigor/inference/match_rebinding/frame.rb +65 -0
- data/lib/rigor/inference/match_rebinding/yielding_match.rb +45 -0
- data/lib/rigor/inference/match_rebinding.rb +11 -1
- data/lib/rigor/inference/memo_audit.rb +55 -0
- data/lib/rigor/inference/method_dispatcher/alias_strict_nominals.rb +1 -1
- data/lib/rigor/inference/method_dispatcher/argument_distribution.rb +40 -0
- data/lib/rigor/inference/method_dispatcher/block_folding.rb +1 -1
- data/lib/rigor/inference/method_dispatcher/constant_folding.rb +113 -12
- data/lib/rigor/inference/method_dispatcher/contested_overloads.rb +89 -0
- data/lib/rigor/inference/method_dispatcher/iterator_dispatch.rb +1 -1
- data/lib/rigor/inference/method_dispatcher/kernel_dispatch.rb +7 -3
- data/lib/rigor/inference/method_dispatcher/no_match_fallback.rb +54 -0
- data/lib/rigor/inference/method_dispatcher/overload_selector.rb +39 -27
- data/lib/rigor/inference/method_dispatcher/random_folding.rb +1 -1
- data/lib/rigor/inference/method_dispatcher/rbs_dispatch.rb +203 -17
- data/lib/rigor/inference/method_dispatcher/reduce_folding.rb +1 -1
- data/lib/rigor/inference/method_dispatcher/regexp_folding.rb +2 -2
- data/lib/rigor/inference/method_dispatcher/self_substitute.rb +2 -2
- data/lib/rigor/inference/method_dispatcher/set_folding.rb +59 -24
- data/lib/rigor/inference/method_dispatcher/shape_dispatch.rb +83 -20
- data/lib/rigor/inference/method_dispatcher/singleton_folding.rb +0 -1
- data/lib/rigor/inference/method_dispatcher/singleton_mixin_dispatch.rb +50 -17
- data/lib/rigor/inference/method_dispatcher/struct_folding.rb +5 -5
- data/lib/rigor/inference/method_dispatcher/struct_materialization.rb +4 -6
- data/lib/rigor/inference/method_dispatcher/uri_folding.rb +1 -1
- data/lib/rigor/inference/method_dispatcher.rb +109 -29
- data/lib/rigor/inference/module_function_state/spellings.rb +64 -0
- data/lib/rigor/inference/module_function_state.rb +23 -1
- data/lib/rigor/inference/multi_target_binder.rb +1 -1
- data/lib/rigor/inference/mutation_rejoin.rb +240 -4
- data/lib/rigor/inference/mutation_widening.rb +162 -29
- data/lib/rigor/inference/narrowing.rb +113 -38
- data/lib/rigor/inference/object_mixins.rb +13 -1
- data/lib/rigor/inference/optimistic_origin.rb +1 -1
- data/lib/rigor/inference/out_buffer_mutation.rb +72 -0
- data/lib/rigor/inference/parameter_inference_collector.rb +5 -6
- data/lib/rigor/inference/pre_eval_constants.rb +1 -1
- data/lib/rigor/inference/project_method_ownership.rb +6 -3
- data/lib/rigor/inference/project_seed_tables.rb +2 -1
- data/lib/rigor/inference/project_yielder.rb +122 -0
- data/lib/rigor/inference/receiver_alias.rb +20 -0
- data/lib/rigor/inference/refined_dispatch/constructed_class.rb +3 -1
- data/lib/rigor/inference/refined_dispatch/own_method.rb +2 -1
- data/lib/rigor/inference/remover_holder_scan.rb +233 -0
- data/lib/rigor/inference/remover_narrowing.rb +224 -0
- data/lib/rigor/inference/rewrite_mutation.rb +53 -2
- data/lib/rigor/inference/scope_indexer/certainty.rb +9 -1
- data/lib/rigor/inference/scope_indexer/constant_ivar_value.rb +93 -0
- data/lib/rigor/inference/scope_indexer/declared_ivar_types.rb +64 -0
- data/lib/rigor/inference/scope_indexer/declared_param_writes.rb +205 -0
- data/lib/rigor/inference/scope_indexer/derived_param_value.rb +112 -0
- data/lib/rigor/inference/scope_indexer/empty_seed.rb +99 -0
- data/lib/rigor/inference/scope_indexer/ivar_contributions.rb +135 -0
- data/lib/rigor/inference/scope_indexer/unseen_ivar_writers.rb +133 -0
- data/lib/rigor/inference/scope_indexer.rb +614 -146
- data/lib/rigor/inference/self_call_ivar_writes.rb +101 -17
- data/lib/rigor/inference/set_mutation.rb +189 -0
- data/lib/rigor/inference/singleton_hook_decline.rb +1 -2
- data/lib/rigor/inference/statement_evaluator.rb +3036 -278
- data/lib/rigor/inference/struct_fold_safety.rb +4 -6
- data/lib/rigor/inference/synthetic_method_index.rb +23 -0
- data/lib/rigor/inference/synthetic_method_scanner/project_members.rb +130 -0
- data/lib/rigor/inference/synthetic_method_scanner.rb +73 -14
- data/lib/rigor/inference/toplevel_def_census.rb +59 -0
- data/lib/rigor/inference/unknown_store_widening.rb +103 -4
- data/lib/rigor/inference/unthreaded_rebinds.rb +2 -3
- data/lib/rigor/inference/void_tail_summary.rb +2 -1
- data/lib/rigor/language_server/buffer_table.rb +9 -3
- data/lib/rigor/language_server/completion_provider.rb +26 -20
- data/lib/rigor/language_server/config_warning_announcer.rb +28 -0
- data/lib/rigor/language_server/diagnostic_publisher.rb +28 -9
- data/lib/rigor/language_server/document_symbol_provider.rb +1 -1
- data/lib/rigor/language_server/folding_range_provider.rb +1 -2
- data/lib/rigor/language_server/hover_provider.rb +1 -7
- data/lib/rigor/language_server/hover_renderer.rb +6 -8
- data/lib/rigor/language_server/project_context.rb +98 -4
- data/lib/rigor/language_server/publish_batcher.rb +3 -4
- data/lib/rigor/language_server/selection_range_provider.rb +2 -4
- data/lib/rigor/language_server/server.rb +12 -6
- data/lib/rigor/language_server/signature_help_provider.rb +4 -4
- data/lib/rigor/lens/plugins.rb +1 -1
- data/lib/rigor/mcp/server.rb +82 -3
- data/lib/rigor/mcp.rb +1 -1
- data/lib/rigor/plugin/access_denied_error.rb +1 -2
- data/lib/rigor/plugin/base.rb +26 -11
- data/lib/rigor/plugin/bundled_catalog.rb +1 -12
- data/lib/rigor/plugin/io_boundary.rb +1 -1
- data/lib/rigor/plugin/loader.rb +25 -8
- data/lib/rigor/plugin/macro/heredoc_template.rb +7 -8
- data/lib/rigor/plugin/macro/trait_registry.rb +6 -9
- data/lib/rigor/plugin/manifest.rb +38 -16
- data/lib/rigor/plugin/registry.rb +41 -3
- data/lib/rigor/plugin/services.rb +2 -3
- data/lib/rigor/plugin/source_rbs_synthesis_reporter.rb +11 -0
- data/lib/rigor/plugin/trust_policy.rb +2 -2
- data/lib/rigor/plugin/type_node_resolver.rb +2 -4
- data/lib/rigor/plugin.rb +6 -8
- data/lib/rigor/plugin_gap_advisory.rb +5 -1
- data/lib/rigor/project_environment.rb +16 -2
- data/lib/rigor/protection/analysis_guard.rb +1 -1
- data/lib/rigor/protection/discovery_seed.rb +96 -2
- data/lib/rigor/protection/mutator.rb +1 -1
- data/lib/rigor/rbs_extended/envelope_scanner.rb +4 -6
- data/lib/rigor/rbs_extended/hkt_directives.rb +6 -10
- data/lib/rigor/rbs_extended/reporter.rb +27 -3
- data/lib/rigor/rbs_extended.rb +2 -3
- data/lib/rigor/reflection/constant_ancestors.rb +5 -3
- data/lib/rigor/rooted_glob.rb +25 -2
- data/lib/rigor/run_scoped_slots.rb +38 -0
- data/lib/rigor/runtime/jit.rb +1 -1
- data/lib/rigor/scope/discovery_index.rb +19 -6
- data/lib/rigor/scope/resolution_chain.rb +3 -1
- data/lib/rigor/scope.rb +379 -36
- data/lib/rigor/sig_gen/classification.rb +4 -0
- data/lib/rigor/sig_gen/effect_annotation.rb +3 -3
- data/lib/rigor/sig_gen/generator.rb +668 -84
- data/lib/rigor/sig_gen/generic_header_scan.rb +189 -0
- data/lib/rigor/sig_gen/inline_declarations.rb +2 -2
- data/lib/rigor/sig_gen/layout_index.rb +3 -3
- data/lib/rigor/sig_gen/method_candidate.rb +23 -4
- data/lib/rigor/sig_gen/observation_collector.rb +7 -6
- data/lib/rigor/sig_gen/observed_call.rb +1 -1
- data/lib/rigor/sig_gen/path_mapper.rb +6 -0
- data/lib/rigor/sig_gen/rbs_validity.rb +1 -1
- data/lib/rigor/sig_gen/renderer.rb +21 -12
- data/lib/rigor/sig_gen/skip_reason_catalog.rb +15 -2
- data/lib/rigor/sig_gen/type_elaborator.rb +21 -5
- data/lib/rigor/sig_gen/type_name_qualification.rb +69 -0
- data/lib/rigor/sig_gen/write_reporter.rb +63 -14
- data/lib/rigor/sig_gen/write_result.rb +23 -12
- data/lib/rigor/sig_gen/writer.rb +217 -37
- data/lib/rigor/type/acceptance_router.rb +2 -2
- data/lib/rigor/type/accepts_result.rb +1 -1
- data/lib/rigor/type/app.rb +4 -6
- data/lib/rigor/type/combinator.rb +13 -16
- data/lib/rigor/type/constant.rb +48 -7
- data/lib/rigor/type/hash_shape.rb +26 -40
- data/lib/rigor/type/struct_instance.rb +3 -2
- data/lib/rigor/type/union.rb +1 -1
- data/lib/rigor/type_node/identifier.rb +1 -2
- data/lib/rigor/type_node/resolver_chain.rb +1 -1
- data/lib/rigor/type_node/string_literal.rb +1 -2
- data/lib/rigor/type_node/symbol_literal.rb +1 -2
- data/lib/rigor/type_node/union.rb +3 -6
- data/lib/rigor/value_semantics.rb +1 -10
- data/lib/rigor/version.rb +1 -1
- data/plugins/rigor-actioncable/lib/rigor/plugin/actioncable/channel_discoverer.rb +2 -2
- data/plugins/rigor-actioncable/lib/rigor/plugin/actioncable/channel_index.rb +2 -3
- data/plugins/rigor-actioncable/lib/rigor/plugin/actioncable.rb +1 -1
- data/plugins/rigor-actionmailer/lib/rigor/plugin/actionmailer/mailer_discoverer.rb +89 -70
- data/plugins/rigor-actionmailer/lib/rigor/plugin/actionmailer/mailer_index.rb +4 -2
- data/plugins/rigor-actionmailer/lib/rigor/plugin/actionmailer.rb +25 -4
- data/plugins/rigor-actionpack/lib/rigor/plugin/actionpack/analyzer.rb +1 -1
- data/plugins/rigor-actionpack/lib/rigor/plugin/actionpack/controller_index.rb +1 -5
- data/plugins/rigor-actionpack/lib/rigor/plugin/actionpack/controller_scan.rb +0 -1
- data/plugins/rigor-actionpack/lib/rigor/plugin/actionpack/erb_compiler.rb +2 -1
- data/plugins/rigor-actionpack/lib/rigor/plugin/actionpack/view_assigns.rb +1 -1
- data/plugins/rigor-actionpack/lib/rigor/plugin/actionpack.rb +79 -19
- data/plugins/rigor-activejob/lib/rigor/plugin/activejob/effects.rb +1 -1
- data/plugins/rigor-activejob/lib/rigor/plugin/activejob.rb +6 -3
- data/plugins/rigor-activerecord/lib/rigor/plugin/activerecord/association_roots.rb +3 -2
- data/plugins/rigor-activerecord/lib/rigor/plugin/activerecord/effects.rb +2 -2
- data/plugins/rigor-activerecord/lib/rigor/plugin/activerecord/model_discoverer.rb +21 -31
- data/plugins/rigor-activerecord/lib/rigor/plugin/activerecord/model_index.rb +10 -16
- data/plugins/rigor-activerecord/lib/rigor/plugin/activerecord/schema_parser.rb +2 -3
- data/plugins/rigor-activerecord/lib/rigor/plugin/activerecord/schema_table.rb +0 -1
- data/plugins/rigor-activerecord/lib/rigor/plugin/activerecord.rb +5 -4
- data/plugins/rigor-activestorage/lib/rigor/plugin/activestorage/attachment_discoverer.rb +3 -4
- data/plugins/rigor-activestorage/lib/rigor/plugin/activestorage/attachment_index.rb +1 -1
- data/plugins/rigor-activestorage/lib/rigor/plugin/activestorage.rb +7 -12
- data/plugins/rigor-activestorage/lib/rigor-activestorage.rb +1 -1
- 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/symbolize_keys.rb +102 -0
- data/plugins/rigor-activesupport-core-ext/lib/rigor/plugin/activesupport_core_ext.rb +19 -6
- data/plugins/rigor-activesupport-core-ext/sig/active_support/core_ext.rbs +26 -13
- data/plugins/rigor-alba/lib/rigor/plugin/alba/resource_index.rb +3 -3
- data/plugins/rigor-devise/lib/rigor/plugin/devise.rb +5 -3
- data/plugins/rigor-dry-schema/lib/rigor/plugin/dry_schema/schema_scanner.rb +1 -3
- data/plugins/rigor-dry-struct/lib/rigor/plugin/dry_struct.rb +6 -6
- data/plugins/rigor-dry-types/lib/rigor/plugin/dry_types/alias_scanner.rb +5 -6
- data/plugins/rigor-dry-types/lib/rigor/plugin/dry_types.rb +7 -6
- data/plugins/rigor-dry-validation/lib/rigor/plugin/dry_validation/params_shape.rb +2 -3
- data/plugins/rigor-dry-validation/lib/rigor/plugin/dry_validation.rb +5 -8
- data/plugins/rigor-ethon/lib/rigor/plugin/ethon.rb +0 -1
- data/plugins/rigor-factorybot/lib/rigor/plugin/factorybot/factory_discoverer.rb +1 -1
- data/plugins/rigor-factorybot/lib/rigor/plugin/factorybot.rb +10 -18
- data/plugins/rigor-ffi/lib/rigor/plugin/ffi/analyzer.rb +0 -1
- data/plugins/rigor-ffi/lib/rigor/plugin/ffi/discoverer.rb +0 -2
- data/plugins/rigor-ffi/lib/rigor/plugin/ffi.rb +4 -5
- data/plugins/rigor-grape/lib/rigor/plugin/grape.rb +0 -2
- data/plugins/rigor-graphql/lib/rigor/plugin/graphql/type_scanner.rb +6 -7
- data/plugins/rigor-hanami/lib/rigor/plugin/hanami/action_checker.rb +2 -4
- data/plugins/rigor-hanami/lib/rigor/plugin/hanami.rb +2 -5
- data/plugins/rigor-mangrove/lib/rigor/plugin/mangrove.rb +2 -2
- data/plugins/rigor-minitest/lib/rigor/plugin/minitest/assertion_analyzer.rb +6 -6
- data/plugins/rigor-pundit/lib/rigor/plugin/pundit/policy_discoverer.rb +2 -1
- data/plugins/rigor-rails-i18n/lib/rigor/plugin/rails_i18n/analyzer.rb +3 -8
- data/plugins/rigor-rails-i18n/lib/rigor/plugin/rails_i18n/locale_index.rb +2 -3
- data/plugins/rigor-rails-i18n/lib/rigor/plugin/rails_i18n/locale_loader.rb +5 -8
- data/plugins/rigor-rails-routes/lib/rigor/plugin/rails_routes/analyzer.rb +1 -3
- data/plugins/rigor-rails-routes/lib/rigor/plugin/rails_routes/devise_routes.rb +2 -3
- data/plugins/rigor-rails-routes/lib/rigor/plugin/rails_routes/helper_discoverer.rb +1 -1
- data/plugins/rigor-rails-routes/lib/rigor/plugin/rails_routes/routes_parser.rb +4 -11
- data/plugins/rigor-rails-routes/lib/rigor/plugin/rails_routes.rb +1 -1
- data/plugins/rigor-rbs-inline/lib/rigor/plugin/rbs_inline.rb +2 -1
- data/plugins/rigor-rspec/lib/rigor/plugin/rspec/matcher_analyzer.rb +102 -11
- data/plugins/rigor-rspec/lib/rigor/plugin/rspec.rb +2 -2
- data/plugins/rigor-rspec-rails/lib/rigor/plugin/rspec_rails.rb +3 -4
- data/plugins/rigor-shoulda-matchers/lib/rigor/plugin/shoulda_matchers/analyzer.rb +6 -8
- data/plugins/rigor-sidekiq/lib/rigor/plugin/sidekiq.rb +5 -2
- data/plugins/rigor-sorbet/lib/rigor/plugin/sorbet/absurd_recognizer.rb +4 -5
- data/plugins/rigor-sorbet/lib/rigor/plugin/sorbet/assertion_recognizer.rb +6 -7
- data/plugins/rigor-sorbet/lib/rigor/plugin/sorbet/catalog.rb +1 -1
- data/plugins/rigor-sorbet/lib/rigor/plugin/sorbet/sig_parser.rb +2 -2
- data/plugins/rigor-sorbet/lib/rigor/plugin/sorbet.rb +17 -21
- data/plugins/rigor-statesman/lib/rigor/plugin/statesman.rb +2 -3
- data/plugins/rigor-typelizer/lib/rigor/plugin/typelizer/serializer_discoverer.rb +3 -2
- data/plugins/rigor-typelizer/lib/rigor/plugin/typelizer/serializer_index.rb +4 -4
- data/plugins/rigor-typelizer/lib/rigor/plugin/typelizer.rb +1 -1
- data/sig/rigor/analysis/baseline.rbs +0 -2
- data/sig/rigor/analysis/fact_store.rbs +1 -0
- data/sig/rigor/analysis/reachability/scan_cache.rbs +1 -1
- data/sig/rigor/cli/diff_command.rbs +1 -1
- data/sig/rigor/cli/explain_command.rbs +1 -1
- data/sig/rigor/effects/file_collection.rbs +5 -6
- data/sig/rigor/effects/registry.rbs +8 -6
- data/sig/rigor/effects/summary.rbs +6 -5
- data/sig/rigor/environment.rbs +5 -3
- data/sig/rigor/inference/optimistic_origin.rbs +11 -0
- data/sig/rigor/inference.rbs +10 -1
- data/sig/rigor/plugin/additional_initializer.rbs +0 -5
- data/sig/rigor/plugin/base.rbs +1 -0
- data/sig/rigor/plugin/effect_ancestry.rbs +6 -4
- data/sig/rigor/plugin/effect_attribution.rbs +25 -10
- data/sig/rigor/plugin/effect_edge.rbs +12 -5
- data/sig/rigor/plugin/effect_entry_points.rbs +8 -3
- data/sig/rigor/plugin/io_boundary.rbs +6 -5
- data/sig/rigor/plugin/manifest.rbs +16 -18
- data/sig/rigor/plugin/protocol_contract.rbs +6 -9
- data/sig/rigor/plugin/registry.rbs +1 -1
- data/sig/rigor/scope.rbs +51 -50
- data/sig/rigor/type.rbs +0 -6
- data/skills/rigor-plugin-author/SKILL.md +4 -4
- data/skills/rigor-plugin-author/references/02-walker-and-types.md +5 -5
- data/skills/rigor-plugin-review/SKILL.md +3 -3
- data/skills/rigor-project-init/references/03-baseline-and-bugs.md +12 -1
- metadata +55 -3
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "rbs"
|
|
4
|
+
|
|
5
|
+
require_relative "../environment/rbs_loader"
|
|
6
|
+
require_relative "../rooted_glob"
|
|
7
|
+
|
|
8
|
+
module Rigor
|
|
9
|
+
module SigGen
|
|
10
|
+
# Issues #2603 and #2605 — the run-wide view of the parameterless headers of generic classes (`class Array`, as
|
|
11
|
+
# sig-gen spelled it before #2436) that `sig/` holds, read before the writer changes anything.
|
|
12
|
+
#
|
|
13
|
+
# rbs rejects a class with `GenericParameterMismatchError` while any one of its declarations opens it bare, so
|
|
14
|
+
# the repair is decided per class, across every file the project's RBS env loads from `signature_paths:`: either
|
|
15
|
+
# every bare opening of the class is repaired, or none is. A class is held back ({#left_bare}) when the body of
|
|
16
|
+
# any of its bare openings names one of the parameters as a relative constant ({.shadowing_names}), because the
|
|
17
|
+
# inserted parameter would capture that name, or when one of its bare openings lies outside the sig root, which
|
|
18
|
+
# the writer never rewrites. Every file under the sig root is read, not only those a candidate of the run routes
|
|
19
|
+
# to, so a bare header whose source file is gone is repaired too (#2603); the other signature paths are read
|
|
20
|
+
# and never written.
|
|
21
|
+
#
|
|
22
|
+
# A file that is not valid UTF-8, or does not parse, is not read: rbs never loads it, and the writer refuses it.
|
|
23
|
+
class GenericHeaderScan
|
|
24
|
+
# One bare opening: the file it is in, the class it opens, the parameter names its body spells, and whether
|
|
25
|
+
# the file is under the sig root (the writer may rewrite it).
|
|
26
|
+
Opening = Data.define(:target, :class_name, :names, :writable)
|
|
27
|
+
|
|
28
|
+
# @param sig_root — the directory the writer writes to; the only files it may rewrite.
|
|
29
|
+
# @param signature_dirs — the other directories the RBS env loads (`signature_paths:`), read only. A file
|
|
30
|
+
# under the sig root is read once, as a writable one.
|
|
31
|
+
# @param spelling_for — called with a class name, returns the header spelling to insert
|
|
32
|
+
# (`"[unchecked out E]"`), or nil for a class that is not generic with plain parameters only.
|
|
33
|
+
def self.scan(sig_root:, spelling_for:, signature_dirs: [])
|
|
34
|
+
new(spelling_for).tap do |scan|
|
|
35
|
+
scan.read_tree(sig_root, writable: true)
|
|
36
|
+
signature_dirs.each { |dir| scan.read_tree(dir, writable: false) }
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
# The names in `names` that the declaration's text after its name (superclass, members, nested declarations)
|
|
41
|
+
# spells as a relative constant (`E`, `E::X`, not `::E` or `Foo::E`). A method type that declares a name as
|
|
42
|
+
# its own type parameter (`def m: [E] (E) -> E`) binds every `E` inside it, so its text does not count for
|
|
43
|
+
# that name. The rest is matched as text, so a comment that spells the name counts.
|
|
44
|
+
def self.shadowing_names(source, decl, names)
|
|
45
|
+
start = decl.location[:name].end_pos
|
|
46
|
+
body = source[start...decl.location.end_pos]
|
|
47
|
+
names.select do |name|
|
|
48
|
+
masked = mask_binders(body, binder_ranges(decl, name), start)
|
|
49
|
+
masked.match?(/(?<![\w:])#{Regexp.escape(name)}(?!\w)/)
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
# The source ranges of the method types under `decl` (nested declarations included) that declare `name` as a
|
|
54
|
+
# type parameter of their own.
|
|
55
|
+
def self.binder_ranges(decl, name, ranges = [])
|
|
56
|
+
(decl.respond_to?(:members) ? decl.members : []).each do |member|
|
|
57
|
+
if member.is_a?(RBS::AST::Members::MethodDefinition)
|
|
58
|
+
member.overloads.each do |overload|
|
|
59
|
+
type = overload.method_type
|
|
60
|
+
next unless type.location && type.type_params.any? { |param| param.name.to_s == name }
|
|
61
|
+
|
|
62
|
+
ranges << (type.location.start_pos...type.location.end_pos)
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
binder_ranges(member, name, ranges)
|
|
66
|
+
end
|
|
67
|
+
ranges
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
def self.mask_binders(body, ranges, offset)
|
|
71
|
+
masked = body.dup
|
|
72
|
+
ranges.each do |range|
|
|
73
|
+
from = range.begin - offset
|
|
74
|
+
masked[from, range.size] = " " * range.size if from >= 0 && from + range.size <= masked.size
|
|
75
|
+
end
|
|
76
|
+
masked
|
|
77
|
+
end
|
|
78
|
+
private_class_method :mask_binders
|
|
79
|
+
|
|
80
|
+
# The parameter names `[unchecked out K, unchecked out V]` declares; nil when it does not parse.
|
|
81
|
+
def self.parameter_names(spelling)
|
|
82
|
+
_, _, decls = RBS::Parser.parse_signature("class RigorSigGenProbe#{spelling}\nend\n")
|
|
83
|
+
decls.first&.type_params&.map { |param| param.name.to_s }
|
|
84
|
+
rescue RBS::ParsingError
|
|
85
|
+
nil
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
def initialize(spelling_for)
|
|
89
|
+
@spelling_for = spelling_for
|
|
90
|
+
@openings = []
|
|
91
|
+
@seen = Set.new
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
# Every class to repair, with the spelling to insert: each bare opening of it, in every file read, is clear.
|
|
95
|
+
def repairs
|
|
96
|
+
@repairs ||= by_class.reject { |_, openings| openings.any? { |o| blocking?(o) } }
|
|
97
|
+
.to_h { |name, _| [name, spelling(name)] }
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
# The files that hold a bare opening of a class in {#repairs}, as their `to_s`.
|
|
101
|
+
def repair_targets
|
|
102
|
+
@openings.select { |o| repairs.key?(o.class_name) }.map(&:target).uniq
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
# One entry per class held back: `{ class:, targets:, blocking: [...] }`, where `targets` is every file with a
|
|
106
|
+
# bare opening of it and `blocking` the openings that hold it back, each `{ target:, reason:
|
|
107
|
+
# "outside_sig_root" }` (a file the writer does not rewrite) or `{ target:, reason: "names_parameter", names: }`.
|
|
108
|
+
def left_bare
|
|
109
|
+
by_class.filter_map do |name, openings|
|
|
110
|
+
blocking = openings.select { |o| blocking?(o) }
|
|
111
|
+
next if blocking.empty?
|
|
112
|
+
|
|
113
|
+
{ class: name, targets: openings.map(&:target).uniq, blocking: blocking.map { |o| blocking_entry(o) } }
|
|
114
|
+
end
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
def read_tree(dir, writable:)
|
|
118
|
+
return unless dir.directory?
|
|
119
|
+
|
|
120
|
+
RootedGlob.glob(dir.to_s, "**/*.rbs").sort.each do |path|
|
|
121
|
+
key = realpath(path)
|
|
122
|
+
read_file(Pathname(path), writable) if @seen.add?(key)
|
|
123
|
+
end
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
private
|
|
127
|
+
|
|
128
|
+
def blocking?(opening)
|
|
129
|
+
!opening.writable || !opening.names.empty?
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
def blocking_entry(opening)
|
|
133
|
+
return { target: opening.target, reason: "outside_sig_root" } unless opening.writable
|
|
134
|
+
|
|
135
|
+
{ target: opening.target, reason: "names_parameter", names: opening.names }
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
def realpath(path)
|
|
139
|
+
File.realpath(path)
|
|
140
|
+
rescue SystemCallError
|
|
141
|
+
File.expand_path(path)
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
def by_class
|
|
145
|
+
@by_class ||= @openings.group_by(&:class_name).sort.to_h
|
|
146
|
+
end
|
|
147
|
+
|
|
148
|
+
def spelling(name)
|
|
149
|
+
@spellings ||= {}
|
|
150
|
+
return @spellings[name] if @spellings.key?(name)
|
|
151
|
+
|
|
152
|
+
@spellings[name] = @spelling_for.call(name)
|
|
153
|
+
end
|
|
154
|
+
|
|
155
|
+
def read_file(path, writable)
|
|
156
|
+
source = path.read
|
|
157
|
+
return unless source.valid_encoding?
|
|
158
|
+
|
|
159
|
+
_, _, decls = RBS::Parser.parse_signature(source)
|
|
160
|
+
collect([path.to_s, writable], source, decls, [])
|
|
161
|
+
rescue RBS::ParsingError, SystemCallError
|
|
162
|
+
nil
|
|
163
|
+
end
|
|
164
|
+
|
|
165
|
+
def collect(target, source, decls, prefix)
|
|
166
|
+
decls.each do |decl|
|
|
167
|
+
next unless decl.is_a?(RBS::AST::Declarations::Class) || decl.is_a?(RBS::AST::Declarations::Module)
|
|
168
|
+
|
|
169
|
+
# RBS resolves `module Foo; class ::Set` to the top-level `Set`, and so does this key (#2654).
|
|
170
|
+
path = Environment::RbsLoader.declared_class_path(decl, prefix)
|
|
171
|
+
record(target, source, decl, path.join("::"))
|
|
172
|
+
collect(target, source, decl.members, path)
|
|
173
|
+
end
|
|
174
|
+
end
|
|
175
|
+
|
|
176
|
+
def record(target, source, decl, name)
|
|
177
|
+
return unless decl.type_params.empty? && decl.location&.[](:name)
|
|
178
|
+
|
|
179
|
+
spelled = spelling(name)
|
|
180
|
+
params = spelled && self.class.parameter_names(spelled)
|
|
181
|
+
return if params.nil?
|
|
182
|
+
|
|
183
|
+
file, writable = target
|
|
184
|
+
@openings << Opening.new(target: file, class_name: name, writable: writable,
|
|
185
|
+
names: self.class.shadowing_names(source, decl, params))
|
|
186
|
+
end
|
|
187
|
+
end
|
|
188
|
+
end
|
|
189
|
+
end
|
|
@@ -23,7 +23,7 @@ module Rigor
|
|
|
23
23
|
class InlineDeclarations
|
|
24
24
|
# One inline-declared method.
|
|
25
25
|
#
|
|
26
|
-
# - `method_types` — the declared overloads
|
|
26
|
+
# - `method_types` — the declared overloads, names as written and unresolved.
|
|
27
27
|
# - `annotations` — the annotation strings the author wrote on the member (`deprecated` for
|
|
28
28
|
# `%a{deprecated}`), without the synthesizer's own `rigor:v1:inferred-*` markers.
|
|
29
29
|
# - `return_inferred` — the author declared the parameters and not the return: rbs-inline defaulted it,
|
|
@@ -112,7 +112,7 @@ module Rigor
|
|
|
112
112
|
decls.each do |decl|
|
|
113
113
|
next unless decl.is_a?(::RBS::AST::Declarations::Class) || decl.is_a?(::RBS::AST::Declarations::Module)
|
|
114
114
|
|
|
115
|
-
inner =
|
|
115
|
+
inner = ::Rigor::Environment::RbsLoader.declared_class_path(decl, prefix)
|
|
116
116
|
@generic_classes[inner.join("::")] ||= decl.type_params.map(&:name) unless decl.type_params.empty?
|
|
117
117
|
decl.members.each { |member| block.call(inner.join("::"), member) }
|
|
118
118
|
each_member(decl.members, inner, &block)
|
|
@@ -126,8 +126,8 @@ module Rigor
|
|
|
126
126
|
return unless decl.is_a?(RBS::AST::Declarations::Class) ||
|
|
127
127
|
decl.is_a?(RBS::AST::Declarations::Module)
|
|
128
128
|
|
|
129
|
-
|
|
130
|
-
full =
|
|
129
|
+
path = ::Rigor::Environment::RbsLoader.declared_class_path(decl, prefix)
|
|
130
|
+
full = path.join("::")
|
|
131
131
|
accumulator[full] ||= rbs_path
|
|
132
132
|
decl.members.each do |member|
|
|
133
133
|
# An `overloading?` member (`def f: ... | ...`) adds to a declaration elsewhere; routing a candidate to
|
|
@@ -137,7 +137,7 @@ module Rigor
|
|
|
137
137
|
self.class.member_keys(member).each { |name, kind| @members[[full, name, kind]] ||= rbs_path }
|
|
138
138
|
end
|
|
139
139
|
|
|
140
|
-
record_decls(decl.members,
|
|
140
|
+
record_decls(decl.members, path, rbs_path, accumulator)
|
|
141
141
|
end
|
|
142
142
|
end
|
|
143
143
|
end
|
|
@@ -15,7 +15,7 @@ module Rigor
|
|
|
15
15
|
# ever `skipped` (`sig.skipped.top-level-def`, #1676).
|
|
16
16
|
# - `method_name` — the def's `Symbol` name.
|
|
17
17
|
# - `kind` — `:instance` or `:singleton`.
|
|
18
|
-
# - `inferred_return` —
|
|
18
|
+
# - `inferred_return` — the inferred return type (or `nil` when the inference pass disqualified the def).
|
|
19
19
|
# - `declared_return_rbs` — the existing RBS-declared return spelling, or `nil` when no RBS declares the
|
|
20
20
|
# method.
|
|
21
21
|
# - `declared_rbs` — for an `inline_overwrite`, or a `tighter_return` over the class's own declaration, the
|
|
@@ -33,13 +33,14 @@ module Rigor
|
|
|
33
33
|
class MethodCandidate
|
|
34
34
|
attr_reader :path, :class_name, :method_name, :kind, :classification,
|
|
35
35
|
:inferred_return, :declared_return_rbs, :rbs, :skip_reason,
|
|
36
|
-
:namespace_kinds, :class_shells, :class_superclasses,
|
|
36
|
+
:namespace_kinds, :class_shells, :class_superclasses, :class_type_params,
|
|
37
37
|
:annotations, :effect_reason, :declared_rbs, :declared_annotations
|
|
38
38
|
|
|
39
39
|
def initialize(path:, class_name:, method_name:, kind:, classification:, # rubocop:disable Metrics/ParameterLists
|
|
40
40
|
inferred_return: nil, declared_return_rbs: nil, rbs: nil, skip_reason: nil,
|
|
41
41
|
namespace_kinds: {}, class_shells: [], class_superclasses: {},
|
|
42
|
-
annotations: [], effect_reason: nil, declared_rbs: nil, declared_annotations: []
|
|
42
|
+
annotations: [], effect_reason: nil, declared_rbs: nil, declared_annotations: [],
|
|
43
|
+
class_type_params: {})
|
|
43
44
|
@path = path
|
|
44
45
|
@class_name = class_name
|
|
45
46
|
@method_name = method_name
|
|
@@ -55,6 +56,10 @@ module Rigor
|
|
|
55
56
|
# superclasses appear; computed ones are absent. The Writer emits `class Bar < Base` for the leaf when
|
|
56
57
|
# present.
|
|
57
58
|
@class_superclasses = class_superclasses.freeze
|
|
59
|
+
# Issue #2436 — qualified class name => the type-parameter list a loaded declaration gives it, spelled for
|
|
60
|
+
# a header (`{ "Array" => "[unchecked out E]" }`). A header the writer opens for one of these classes
|
|
61
|
+
# carries the list; a class absent from the map is written without one.
|
|
62
|
+
@class_type_params = class_type_params.freeze
|
|
58
63
|
@annotations = annotations.freeze
|
|
59
64
|
@effect_reason = effect_reason
|
|
60
65
|
@declared_rbs = declared_rbs
|
|
@@ -85,7 +90,21 @@ module Rigor
|
|
|
85
90
|
declared_return_rbs: @declared_return_rbs, rbs: @rbs, skip_reason: @skip_reason,
|
|
86
91
|
namespace_kinds: @namespace_kinds, class_shells: @class_shells,
|
|
87
92
|
class_superclasses: @class_superclasses, annotations: annotations, effect_reason: reason,
|
|
88
|
-
declared_rbs: @declared_rbs, declared_annotations: @declared_annotations
|
|
93
|
+
declared_rbs: @declared_rbs, declared_annotations: @declared_annotations,
|
|
94
|
+
class_type_params: @class_type_params
|
|
95
|
+
)
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
# A copy carrying the run's reopened-class type parameters (#2436).
|
|
99
|
+
def with_class_type_params(class_type_params)
|
|
100
|
+
self.class.new(
|
|
101
|
+
path: @path, class_name: @class_name, method_name: @method_name, kind: @kind,
|
|
102
|
+
classification: @classification, inferred_return: @inferred_return,
|
|
103
|
+
declared_return_rbs: @declared_return_rbs, rbs: @rbs, skip_reason: @skip_reason,
|
|
104
|
+
namespace_kinds: @namespace_kinds, class_shells: @class_shells,
|
|
105
|
+
class_superclasses: @class_superclasses, annotations: @annotations, effect_reason: @effect_reason,
|
|
106
|
+
declared_rbs: @declared_rbs, declared_annotations: @declared_annotations,
|
|
107
|
+
class_type_params: class_type_params
|
|
89
108
|
)
|
|
90
109
|
end
|
|
91
110
|
|
|
@@ -19,9 +19,7 @@ module Rigor
|
|
|
19
19
|
# Walks the `--observe=PATH...` tree (default: the project's test roots), parses every `.rb` file with `Prism`,
|
|
20
20
|
# scope- indexes it the same way the main generator does, and records the per-call-site argument-type tuples
|
|
21
21
|
# for every `Prism::CallNode` whose receiver types as a `Type::Nominal`. The {Generator} consumes the
|
|
22
|
-
# resulting map to render `--params=observed` RBS
|
|
23
|
-
#
|
|
24
|
-
# @return => Array<Array<Rigor::Type>>}]
|
|
22
|
+
# resulting map to render `--params=observed` RBS.
|
|
25
23
|
#
|
|
26
24
|
# ADR-5 clause 2 compliance: the observed union is the MOST PERMISSIVE parameter contract the existing
|
|
27
25
|
# callers prove sufficient — by construction it accepts every type any caller has already passed. The
|
|
@@ -29,8 +27,8 @@ module Rigor
|
|
|
29
27
|
# user opts in.
|
|
30
28
|
#
|
|
31
29
|
# MVP scope:
|
|
32
|
-
# - Explicit-receiver calls only (`foo.bar(args)`). Implicit-self calls inside class bodies
|
|
33
|
-
# `let` / `subject`
|
|
30
|
+
# - Explicit-receiver calls only (`foo.bar(args)`). Implicit-self calls inside class bodies are skipped;
|
|
31
|
+
# RSpec `let` / `subject` receivers are resolved from the spec file (ADR-14 slice 5).
|
|
34
32
|
# - Calls whose receiver does not type as a `Type::Nominal` (e.g. `(some_dynamic).bar(...)`) are skipped —
|
|
35
33
|
# the collector cannot attribute them to a specific class.
|
|
36
34
|
# - A `T | nil` receiver with one `Nominal` / `Singleton` non-nil member counts as that member (#1389).
|
|
@@ -98,7 +96,10 @@ module Rigor
|
|
|
98
96
|
|
|
99
97
|
base_scope = Scope.empty(environment: environment)
|
|
100
98
|
base_scope = base_scope.with_discovery(base_scope.discovery.with(discovered_classes: discovered_classes))
|
|
101
|
-
|
|
99
|
+
# Guard: sig-gen never reads a declared ivar type back (#1406). No spec pins this flag here, because
|
|
100
|
+
# it only matters for an RBS-declared class defined in an observed spec file.
|
|
101
|
+
scope_index = Inference::ScopeIndexer.index(parse_result.value, default_scope: base_scope,
|
|
102
|
+
declared_ivar_types: false)
|
|
102
103
|
bindings = collect_rspec_bindings(parse_result.value, scope_index)
|
|
103
104
|
@before_ivars = collect_before_ivars(parse_result.value, scope_index)
|
|
104
105
|
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
module Rigor
|
|
4
4
|
module SigGen
|
|
5
5
|
# Per-call-site argument observation produced by {ObservationCollector}. ADR-14 follow-up: the earlier MVP
|
|
6
|
-
# shape (
|
|
6
|
+
# shape (positional types only) could not represent keyword arguments — keyword calls like
|
|
7
7
|
# `MethodCatalog.new(path: ..., mutating_selectors: ...)` were silently skipped in that shape. The new shape
|
|
8
8
|
# carries positional and keyword arg types in parallel so the per-position / per-keyword unions can each be
|
|
9
9
|
# reconstructed independently.
|
|
@@ -74,6 +74,12 @@ module Rigor
|
|
|
74
74
|
@sig_root_dir ||= @project_root / sig_root_name
|
|
75
75
|
end
|
|
76
76
|
|
|
77
|
+
# Every directory the project's RBS env loads signatures from (`signature_paths:`), resolved against the
|
|
78
|
+
# project root. The writer reads them to decide a repair (#2605) and writes only under {#sig_root_dir}.
|
|
79
|
+
def signature_dirs
|
|
80
|
+
Array(@configuration.signature_paths).map { |path| @project_root / path }
|
|
81
|
+
end
|
|
82
|
+
|
|
77
83
|
private
|
|
78
84
|
|
|
79
85
|
def source_relative_to_root(source_path)
|
|
@@ -7,7 +7,7 @@ module Rigor
|
|
|
7
7
|
# Parses what sig-gen is about to emit, before it is emitted.
|
|
8
8
|
#
|
|
9
9
|
# Two rendering bugs have shipped RBS that `rbs` itself rejects — a non-identifier record key
|
|
10
|
-
# (`{
|
|
10
|
+
# (`{ "data-contrast": T }`) and a `&block` constructor parameter rendered before the parens
|
|
11
11
|
# (`(**untyped, ?{ (?) -> void })`). Both were found downstream, as a poisoned `sig/` tree: the file is
|
|
12
12
|
# quarantined, its types vanish, and (for a project adopting `reject-unparseable-signatures`) the build
|
|
13
13
|
# fails. A generator that can poison its own consumer's build is worth guarding at the source.
|
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
require "json"
|
|
4
4
|
|
|
5
|
+
require_relative "../cli/json_document"
|
|
6
|
+
|
|
5
7
|
require_relative "classification"
|
|
6
8
|
require_relative "superclass_spelling"
|
|
7
9
|
require_relative "write_reporter"
|
|
@@ -14,8 +16,7 @@ module Rigor
|
|
|
14
16
|
# - `:print` (default) — RBS skeletons grouped by source file and class declaration, ready for the user to
|
|
15
17
|
# paste into `sig/<path>.rbs`.
|
|
16
18
|
# - `:diff` — a unified-style diff comparing the existing RBS spelling (if any) against the inferred
|
|
17
|
-
# spelling
|
|
18
|
-
# slice 2's `--write` merge.
|
|
19
|
+
# spelling, as a minimal "- declared / + inferred" block.
|
|
19
20
|
# - `:json` — machine-readable payload with the same classification table as `:print`, plus every `skipped`
|
|
20
21
|
# row with its `skip_reason` (#778).
|
|
21
22
|
class Renderer
|
|
@@ -29,9 +30,11 @@ module Rigor
|
|
|
29
30
|
# array means "all emittable classifications".
|
|
30
31
|
# @param observation — `{ paths:, missing: }` under `--params=observed`, else `nil`; JSON carries it
|
|
31
32
|
# as the top-level `observation` key (#1398).
|
|
32
|
-
|
|
33
|
+
# @param diagnostics — the path errors `rigor check` would report for the arguments (#1991); JSON carries
|
|
34
|
+
# them as the top-level `diagnostics` key, and only when there are some.
|
|
35
|
+
def render(candidates:, mode:, format:, selection:, observation: nil, diagnostics: [])
|
|
33
36
|
case format
|
|
34
|
-
when "json" then render_json(filter(candidates, selection, with_skipped: true), observation)
|
|
37
|
+
when "json" then render_json(filter(candidates, selection, with_skipped: true), observation, diagnostics)
|
|
35
38
|
when "text"
|
|
36
39
|
filtered = filter(candidates, selection)
|
|
37
40
|
mode == :diff ? render_diff(filtered) : render_print(filtered)
|
|
@@ -93,11 +96,14 @@ module Rigor
|
|
|
93
96
|
# mode used to hard-code `class`, which turned a module into a class the moment it held an emittable method —
|
|
94
97
|
# output that raises `RBS::DuplicatedDeclarationError` on load if the real `module` is declared anywhere else
|
|
95
98
|
# (#227). Defaulting to `class` when the map has no entry keeps the pre-existing spelling for a leaf class.
|
|
99
|
+
# A generic class the run reopens carries its declaration's type parameters, as the written header does (#2436).
|
|
96
100
|
def declaration_header(candidate, class_name)
|
|
97
|
-
|
|
101
|
+
params = candidate.class_type_params[class_name]
|
|
102
|
+
return "module #{class_name}#{params}" if candidate.namespace_kinds[class_name] == :module
|
|
98
103
|
|
|
99
104
|
superclass = candidate.class_superclasses[class_name]
|
|
100
|
-
|
|
105
|
+
head = "class #{class_name}#{params}"
|
|
106
|
+
superclass ? "#{head} < #{SuperclassSpelling.absolute(superclass)}" : head
|
|
101
107
|
end
|
|
102
108
|
|
|
103
109
|
def render_diff(candidates)
|
|
@@ -124,22 +130,25 @@ module Rigor
|
|
|
124
130
|
end
|
|
125
131
|
end
|
|
126
132
|
|
|
127
|
-
def render_json(candidates, observation = nil)
|
|
133
|
+
def render_json(candidates, observation = nil, diagnostics = [])
|
|
128
134
|
payload = { candidates: candidates.map(&:to_h) }
|
|
129
135
|
payload[:observation] = observation if observation
|
|
130
|
-
|
|
136
|
+
payload[:diagnostics] = diagnostics.map(&:to_h) if diagnostics.any?
|
|
137
|
+
@out.puts(JSON.pretty_generate(CLI::JsonDocument.stamp(payload)))
|
|
131
138
|
end
|
|
132
139
|
|
|
133
140
|
public
|
|
134
141
|
|
|
135
142
|
# The per-source-file outcomes of a `--write` run, and the `--check` verdict, are reported by
|
|
136
143
|
# {WriteReporter}; these delegate so the command keeps one renderer.
|
|
137
|
-
def render_write(results:, format:, refused: [])
|
|
138
|
-
WriteReporter.new(out: @out).render_write(results: results, format: format, refused: refused
|
|
144
|
+
def render_write(results:, format:, refused: [], left_bare: [])
|
|
145
|
+
WriteReporter.new(out: @out).render_write(results: results, format: format, refused: refused,
|
|
146
|
+
left_bare: left_bare)
|
|
139
147
|
end
|
|
140
148
|
|
|
141
|
-
def render_check(results:, format:, refused: [])
|
|
142
|
-
WriteReporter.new(out: @out).render_check(results: results, format: format, refused: refused
|
|
149
|
+
def render_check(results:, format:, refused: [], left_bare: [])
|
|
150
|
+
WriteReporter.new(out: @out).render_check(results: results, format: format, refused: refused,
|
|
151
|
+
left_bare: left_bare)
|
|
143
152
|
end
|
|
144
153
|
|
|
145
154
|
def self.refusal_lines(refused)
|
|
@@ -15,8 +15,8 @@ module Rigor
|
|
|
15
15
|
# reason has no severity, no profile mapping and no suppression, and forcing it into {RuleCatalog::Entry}
|
|
16
16
|
# would mean inventing four fields that do not apply.
|
|
17
17
|
#
|
|
18
|
-
# Every id in {Classification::SKIP_DIAGNOSTIC_IDS} MUST have an entry here; the gate is
|
|
19
|
-
# `spec/rigor/
|
|
18
|
+
# Every id in {Classification::SKIP_DIAGNOSTIC_IDS} MUST have an entry here; the gate is the
|
|
19
|
+
# `sig.skipped.*` example in `spec/rigor/cli_spec.rb`.
|
|
20
20
|
module SkipReasonCatalog
|
|
21
21
|
class Entry < Data.define(:id, :summary, :explanation, :next_step)
|
|
22
22
|
# Hash-shaped form for `rigor explain --format=json`. String keys, and `kind` distinguishes a skip
|
|
@@ -110,6 +110,19 @@ module Rigor
|
|
|
110
110
|
next_step: "Declare the class in `sig/` with the same type parameters as the inline declaration " \
|
|
111
111
|
"(`class Box[T]` ... `end`) and re-run; sig-gen then writes the members into it."
|
|
112
112
|
),
|
|
113
|
+
"sig.skipped.generic-reopening" => Entry.new(
|
|
114
|
+
id: "sig.skipped.generic-reopening",
|
|
115
|
+
summary: "The method reopens a generic class whose type parameters sig-gen cannot copy onto a header.",
|
|
116
|
+
explanation: "The class (or one it is nested in) is declared generic by loaded RBS — core, stdlib, a gem " \
|
|
117
|
+
"or `sig/` — and one of its type parameters has an upper bound or a default. sig-gen copies " \
|
|
118
|
+
"a declaration's type parameters onto the header it writes only when every one is plain, " \
|
|
119
|
+
"because a bound or default is a type spelled relative to the declaring file and can name " \
|
|
120
|
+
"a different class under another nesting. A header without the parameters, or with ones " \
|
|
121
|
+
"that differ, is rejected by rbs (`GenericParameterMismatchError`): the class, and every " \
|
|
122
|
+
"class whose signature mentions it, would fail its definition build.",
|
|
123
|
+
next_step: "Declare the class in `sig/` with the declaration's own type parameters (`class Box[T < " \
|
|
124
|
+
"Comparable]` ... `end`) and re-run; sig-gen then writes the members into that declaration."
|
|
125
|
+
),
|
|
113
126
|
"sig.skipped.inline-differs" => Entry.new(
|
|
114
127
|
id: "sig.skipped.inline-differs",
|
|
115
128
|
summary: "The method's inline declaration and its `sig/` declaration disagree; neither was changed.",
|
|
@@ -37,7 +37,17 @@ module Rigor
|
|
|
37
37
|
end
|
|
38
38
|
end
|
|
39
39
|
|
|
40
|
+
# A set is mutable, so the classes the engine reads off its construction (`Set[x]`, `Set.new(xs)`) are not
|
|
41
|
+
# a contract: `x = Set[1]; x << "a"; x` holds a String. A written `Set` therefore keeps `untyped` for its
|
|
42
|
+
# element, as a Set constant does (#2177), however precisely the engine typed it.
|
|
43
|
+
SET_ELEMENT_UNTYPED = "Set"
|
|
44
|
+
private_constant :SET_ELEMENT_UNTYPED
|
|
45
|
+
|
|
40
46
|
def self.elaborate_nominal(type, environment, arity_cache)
|
|
47
|
+
if type.class_name == SET_ELEMENT_UNTYPED && type.type_args.size == 1
|
|
48
|
+
return Type::Combinator.nominal_of(type.class_name, type_args: [Type::Combinator.untyped])
|
|
49
|
+
end
|
|
50
|
+
|
|
41
51
|
elaborated_args = type.type_args.map { |arg| walk(arg, environment, arity_cache) }
|
|
42
52
|
return Type::Combinator.nominal_of(type.class_name, type_args: elaborated_args) if elaborated_args.any?
|
|
43
53
|
|
|
@@ -57,11 +67,17 @@ module Rigor
|
|
|
57
67
|
Type::Tuple.new(elements)
|
|
58
68
|
end
|
|
59
69
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
type
|
|
70
|
+
# A bare generic in a value position (`{ k: Hash.new }`) fails `rbs validate` as a top-level one does
|
|
71
|
+
# (#2177), so the values are elaborated too. Only the pairs change; the key policy is carried over.
|
|
72
|
+
def self.elaborate_hash_shape(type, environment, arity_cache)
|
|
73
|
+
pairs = type.pairs.transform_values { |value| walk(value, environment, arity_cache) }
|
|
74
|
+
return type if pairs == type.pairs
|
|
75
|
+
|
|
76
|
+
Type::HashShape.new(
|
|
77
|
+
pairs,
|
|
78
|
+
required_keys: type.required_keys, optional_keys: type.optional_keys,
|
|
79
|
+
read_only_keys: type.read_only_keys, extra_keys: type.extra_keys
|
|
80
|
+
)
|
|
65
81
|
end
|
|
66
82
|
|
|
67
83
|
def self.generic_arity_for(class_name, environment, cache)
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "rbs"
|
|
4
|
+
|
|
5
|
+
module Rigor
|
|
6
|
+
module SigGen
|
|
7
|
+
# Issue [#2230](https://github.com/rigortype/rigor/issues/2230) — a rendered type names every class by its
|
|
8
|
+
# fully qualified name, but without the leading `::`: `Type::Nominal#erase_to_rbs` writes `Set[untyped]` for
|
|
9
|
+
# `::Set`. RBS resolves a relative name against the declaration it is written in, innermost namespace first,
|
|
10
|
+
# so inside `module Foo` that declares a `Foo::Set` the written `Set[untyped]` names `::Foo::Set`. A generic
|
|
11
|
+
# name then fails validation ("expects parameters [], but given args [untyped]"); a non-generic one types the
|
|
12
|
+
# method as the wrong class without a word.
|
|
13
|
+
#
|
|
14
|
+
# This anchors a name with `::` only where the namespace the member is written in, or one enclosing it,
|
|
15
|
+
# declares a constant with the name's first segment. Where nothing shadows it the spelling is unchanged, so
|
|
16
|
+
# output for the common case does not churn. The check is over every enclosing namespace of the owner, which
|
|
17
|
+
# covers both the nested `module Foo` / `class Bar` layout the writer emits and a compact `class Foo::Bar`
|
|
18
|
+
# header, and it may anchor a name RBS would have resolved correctly anyway: an anchored name is never wrong,
|
|
19
|
+
# while a missed one is.
|
|
20
|
+
module TypeNameQualification
|
|
21
|
+
module_function
|
|
22
|
+
|
|
23
|
+
NAMED_TYPES = [
|
|
24
|
+
RBS::Types::ClassInstance, RBS::Types::ClassSingleton, RBS::Types::Alias, RBS::Types::Interface
|
|
25
|
+
].freeze
|
|
26
|
+
private_constant :NAMED_TYPES
|
|
27
|
+
|
|
28
|
+
# A capitalised word not already preceded by `::` or part of a longer identifier: the first segment of a
|
|
29
|
+
# relative class name. A cheap filter so the common case never reaches the parser.
|
|
30
|
+
RELATIVE_HEAD = /(?<![\w:])[A-Z]\w*/
|
|
31
|
+
private_constant :RELATIVE_HEAD
|
|
32
|
+
|
|
33
|
+
# @param rendered — an erased RBS type whose names each spell the class they mean from the top level.
|
|
34
|
+
# @param owner — the qualified name of the class or module the type is written in; nil at the top level.
|
|
35
|
+
# @param declared — called with a qualified name (`"Foo::Set"`); true when the project or the RBS
|
|
36
|
+
# environment declares a constant there.
|
|
37
|
+
def qualify(rendered, owner, &declared)
|
|
38
|
+
namespaces = enclosing_namespaces(owner)
|
|
39
|
+
return rendered if namespaces.empty?
|
|
40
|
+
return rendered unless rendered.scan(RELATIVE_HEAD).any? { |head| shadowed?(head, namespaces, declared) }
|
|
41
|
+
|
|
42
|
+
positions = []
|
|
43
|
+
collect_positions(RBS::Parser.parse_type(rendered, require_eof: true), namespaces, declared, positions)
|
|
44
|
+
positions.sort.reverse_each.with_object(+rendered) { |position, out| out.insert(position, "::") }
|
|
45
|
+
rescue RBS::ParsingError
|
|
46
|
+
rendered
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
# `"A::B::C"` → `["A::B::C", "A::B", "A"]`: every namespace a relative name written in `A::B::C`'s
|
|
50
|
+
# declaration is looked up in before the top level.
|
|
51
|
+
def enclosing_namespaces(owner)
|
|
52
|
+
segments = owner.to_s.delete_prefix("::").split("::")
|
|
53
|
+
segments.size.downto(1).map { |n| segments.first(n).join("::") }
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def collect_positions(type, namespaces, declared, positions)
|
|
57
|
+
if NAMED_TYPES.any? { |klass| type.is_a?(klass) } && !type.name.absolute?
|
|
58
|
+
head = (type.name.namespace.path.first || type.name.name).to_s
|
|
59
|
+
positions << type.location[:name].start_pos if shadowed?(head, namespaces, declared)
|
|
60
|
+
end
|
|
61
|
+
type.each_type { |child| collect_positions(child, namespaces, declared, positions) }
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
def shadowed?(head, namespaces, declared)
|
|
65
|
+
namespaces.any? { |namespace| declared.call("#{namespace}::#{head}") }
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
end
|