rigortype 0.4.6 → 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 +50 -3
- data/docs/handbook/appendix-phpstan.md +4 -4
- data/docs/manual/02-cli-reference.md +152 -26
- data/docs/manual/03-configuration.md +36 -3
- data/docs/manual/06-baseline.md +6 -4
- data/docs/manual/09-editor-integration.md +13 -2
- data/docs/manual/10-mcp-server.md +38 -2
- data/docs/manual/12-caching.md +4 -3
- data/docs/manual/plugins/rigor-actionpack.md +19 -11
- data/docs/manual/plugins/rigor-activesupport-core-ext.md +20 -1
- data/lib/rigor/analysis/baseline.rb +24 -27
- 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 +85 -13
- data/lib/rigor/analysis/check_rules/ivar_write_collector.rb +3 -2
- data/lib/rigor/analysis/check_rules/lexical_method_sites.rb +0 -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/rebinding_block_callees.rb +3 -3
- data/lib/rigor/analysis/check_rules/return_in_ensure_collector.rb +1 -2
- 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 +2 -2
- data/lib/rigor/analysis/check_rules/void_value_use_collector.rb +1 -1
- data/lib/rigor/analysis/check_rules.rb +124 -44
- data/lib/rigor/analysis/crash_signature.rb +2 -2
- data/lib/rigor/analysis/dependency_recorder.rb +4 -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 +93 -6
- data/lib/rigor/analysis/fact_store.rb +3 -3
- 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 +27 -16
- data/lib/rigor/analysis/rule_catalog.rb +2 -2
- data/lib/rigor/analysis/run_stats.rb +2 -2
- data/lib/rigor/analysis/runner/buffer_pool_dispatcher.rb +2 -2
- data/lib/rigor/analysis/runner/declaration_position.rb +1 -1
- data/lib/rigor/analysis/runner/diagnostic_aggregator.rb +193 -93
- data/lib/rigor/analysis/runner/effect_envelope_pass.rb +1 -1
- data/lib/rigor/analysis/runner/pool_coordinator.rb +147 -323
- data/lib/rigor/analysis/runner/project_pre_passes.rb +3 -3
- 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/worker_payload.rb +36 -0
- data/lib/rigor/analysis/runner.rb +77 -71
- 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 +24 -31
- 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 +31 -12
- 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 +108 -102
- 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 +25 -20
- 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 +12 -8
- data/lib/rigor/cli/lsp_command.rb +250 -23
- data/lib/rigor/cli/mcp_command.rb +12 -7
- 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 +40 -1
- data/lib/rigor/cli/plugin_command.rb +93 -46
- data/lib/rigor/cli/plugins_command.rb +17 -18
- data/lib/rigor/cli/plugins_renderer.rb +10 -6
- 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 +21 -15
- data/lib/rigor/cli/sig_gen_command.rb +84 -27
- 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 +16 -11
- data/lib/rigor/cli/type_of_project_scope.rb +1 -4
- 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 +1 -1
- data/lib/rigor/configuration/severity_profile.rb +5 -5
- data/lib/rigor/configuration.rb +72 -30
- 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 +480 -67
- data/lib/rigor/environment/reflection.rb +7 -7
- data/lib/rigor/environment/required_features.rb +0 -3
- data/lib/rigor/environment/ruby_library_roots.rb +1 -1
- data/lib/rigor/environment/vendored_signature_plan.rb +153 -0
- data/lib/rigor/environment.rb +41 -10
- 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 +88 -77
- 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 +39 -7
- 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 +46 -4
- data/lib/rigor/inference/definer_resolution.rb +4 -2
- 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/expression_typer.rb +116 -49
- data/lib/rigor/inference/external_ancestor_resolution.rb +3 -4
- data/lib/rigor/inference/global_write_census.rb +76 -2
- 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 +51 -0
- data/lib/rigor/inference/key_presence_guard.rb +2 -1
- data/lib/rigor/inference/loop_value_record.rb +8 -4
- data/lib/rigor/inference/match_rebinding/frame.rb +46 -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 +3 -3
- 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 +1 -1
- 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 +9 -7
- 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 +64 -14
- data/lib/rigor/inference/module_function_state.rb +11 -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 +157 -27
- data/lib/rigor/inference/narrowing.rb +47 -33
- 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_yielder.rb +11 -17
- 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 +0 -1
- data/lib/rigor/inference/scope_indexer/constant_ivar_value.rb +93 -0
- data/lib/rigor/inference/scope_indexer/declared_param_writes.rb +58 -15
- 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.rb +137 -46
- data/lib/rigor/inference/self_call_ivar_writes.rb +84 -12
- 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 +2328 -138
- data/lib/rigor/inference/struct_fold_safety.rb +4 -6
- data/lib/rigor/inference/synthetic_method_scanner.rb +5 -6
- 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 +3 -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 +8 -3
- 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 +39 -1
- 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 +7 -3
- 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 +73 -2
- data/lib/rigor/mcp.rb +1 -1
- data/lib/rigor/plugin/access_denied_error.rb +1 -2
- 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 +9 -13
- data/lib/rigor/plugin/registry.rb +3 -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 +44 -5
- 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 +15 -1
- 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 +365 -31
- 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 +371 -58
- 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 +3 -5
- 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/renderer.rb +15 -9
- data/lib/rigor/sig_gen/skip_reason_catalog.rb +15 -2
- 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 +9 -13
- data/lib/rigor/type/constant.rb +4 -5
- data/lib/rigor/type/hash_shape.rb +21 -40
- 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 +38 -36
- data/plugins/rigor-actionmailer/lib/rigor/plugin/actionmailer/mailer_index.rb +4 -2
- data/plugins/rigor-actionmailer/lib/rigor/plugin/actionmailer.rb +6 -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 +66 -19
- data/plugins/rigor-activejob/lib/rigor/plugin/activejob/effects.rb +1 -1
- data/plugins/rigor-activejob/lib/rigor/plugin/activejob.rb +4 -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-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 +1 -1
- 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 +1 -1
- 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 +3 -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/sig/rigor/analysis/baseline.rbs +0 -3
- 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/registry.rbs +2 -2
- data/sig/rigor/inference.rbs +4 -1
- data/sig/rigor/plugin/additional_initializer.rbs +0 -5
- data/sig/rigor/plugin/base.rbs +1 -0
- data/sig/rigor/plugin/effect_attribution.rbs +3 -3
- data/sig/rigor/plugin/effect_edge.rbs +1 -1
- data/sig/rigor/plugin/effect_entry_points.rbs +3 -3
- data/sig/rigor/plugin/io_boundary.rbs +2 -1
- data/sig/rigor/plugin/manifest.rbs +9 -9
- data/sig/rigor/plugin/protocol_contract.rbs +3 -7
- data/sig/rigor/scope.rbs +23 -3
- 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 +36 -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).
|
|
@@ -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)
|
|
@@ -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
|
|
@@ -95,11 +96,14 @@ module Rigor
|
|
|
95
96
|
# mode used to hard-code `class`, which turned a module into a class the moment it held an emittable method —
|
|
96
97
|
# output that raises `RBS::DuplicatedDeclarationError` on load if the real `module` is declared anywhere else
|
|
97
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).
|
|
98
100
|
def declaration_header(candidate, class_name)
|
|
99
|
-
|
|
101
|
+
params = candidate.class_type_params[class_name]
|
|
102
|
+
return "module #{class_name}#{params}" if candidate.namespace_kinds[class_name] == :module
|
|
100
103
|
|
|
101
104
|
superclass = candidate.class_superclasses[class_name]
|
|
102
|
-
|
|
105
|
+
head = "class #{class_name}#{params}"
|
|
106
|
+
superclass ? "#{head} < #{SuperclassSpelling.absolute(superclass)}" : head
|
|
103
107
|
end
|
|
104
108
|
|
|
105
109
|
def render_diff(candidates)
|
|
@@ -130,19 +134,21 @@ module Rigor
|
|
|
130
134
|
payload = { candidates: candidates.map(&:to_h) }
|
|
131
135
|
payload[:observation] = observation if observation
|
|
132
136
|
payload[:diagnostics] = diagnostics.map(&:to_h) if diagnostics.any?
|
|
133
|
-
@out.puts(JSON.pretty_generate(payload))
|
|
137
|
+
@out.puts(JSON.pretty_generate(CLI::JsonDocument.stamp(payload)))
|
|
134
138
|
end
|
|
135
139
|
|
|
136
140
|
public
|
|
137
141
|
|
|
138
142
|
# The per-source-file outcomes of a `--write` run, and the `--check` verdict, are reported by
|
|
139
143
|
# {WriteReporter}; these delegate so the command keeps one renderer.
|
|
140
|
-
def render_write(results:, format:, refused: [])
|
|
141
|
-
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)
|
|
142
147
|
end
|
|
143
148
|
|
|
144
|
-
def render_check(results:, format:, refused: [])
|
|
145
|
-
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)
|
|
146
152
|
end
|
|
147
153
|
|
|
148
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.",
|
|
@@ -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
|
|
@@ -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
|
|
|
7
9
|
module Rigor
|
|
@@ -18,10 +20,13 @@ module Rigor
|
|
|
18
20
|
# @param refused — methods refused as `sig.skipped.inline-differs`; the JSON payload names them under
|
|
19
21
|
# `refused` (absent when there are none, so an ordinary payload is unchanged), and text mode leaves them
|
|
20
22
|
# to the command's stderr `REFUSED` lines.
|
|
21
|
-
|
|
23
|
+
# @param left_bare — the generic classes whose bare headers the writer held back from the repair (#2605,
|
|
24
|
+
# {Writer#left_bare}); the JSON payload names them under `left_bare` (absent when there are none), and text
|
|
25
|
+
# mode prints one `generic header left bare` line each.
|
|
26
|
+
def render_write(results:, format:, refused: [], left_bare: [])
|
|
22
27
|
case format
|
|
23
|
-
when "json" then render_write_json(results, refused)
|
|
24
|
-
when "text" then
|
|
28
|
+
when "json" then render_write_json(results, refused, left_bare)
|
|
29
|
+
when "text" then render_write_text_with_left_bare(results, left_bare)
|
|
25
30
|
else raise ArgumentError, "unsupported format: #{format}"
|
|
26
31
|
end
|
|
27
32
|
end
|
|
@@ -32,14 +37,19 @@ module Rigor
|
|
|
32
37
|
#
|
|
33
38
|
# @param refused — the methods the generator refused to reconcile (`sig.skipped.inline-differs`):
|
|
34
39
|
# `sig/` is not up to date while one stands, and `--write` cannot fix it.
|
|
35
|
-
|
|
40
|
+
#
|
|
41
|
+
# @param left_bare — as for {#render_write}; reported, but it does not make `sig/` out of date.
|
|
42
|
+
def render_check(results:, format:, refused: [], left_bare: [])
|
|
36
43
|
stale = self.class.out_of_date(results)
|
|
37
44
|
case format
|
|
38
45
|
when "json"
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
46
|
+
payload = { up_to_date: stale.empty? && refused.empty?, results: stale.map { |r| check_entry(r) },
|
|
47
|
+
refused: refused.map(&:to_h) }
|
|
48
|
+
payload[:left_bare] = left_bare unless left_bare.empty?
|
|
49
|
+
@out.puts(JSON.pretty_generate(CLI::JsonDocument.stamp(payload)))
|
|
50
|
+
when "text"
|
|
51
|
+
render_check_text(stale, refused)
|
|
52
|
+
render_left_bare(left_bare)
|
|
43
53
|
else raise ArgumentError, "unsupported format: #{format}"
|
|
44
54
|
end
|
|
45
55
|
end
|
|
@@ -89,6 +99,7 @@ module Rigor
|
|
|
89
99
|
when :created, :updated then render_check_change(result)
|
|
90
100
|
when :skipped_invalid_rbs then render_write_invalid(result)
|
|
91
101
|
when :skipped_invalid_encoding then render_write_invalid_encoding(result)
|
|
102
|
+
when :skipped_unparseable then render_write_unparseable(result)
|
|
92
103
|
end
|
|
93
104
|
end
|
|
94
105
|
end
|
|
@@ -103,12 +114,17 @@ module Rigor
|
|
|
103
114
|
end
|
|
104
115
|
end
|
|
105
116
|
|
|
106
|
-
|
|
117
|
+
# "No changes" only when nothing at all is reported: a header held back is news even when no file changed.
|
|
118
|
+
def render_write_text_with_left_bare(results, left_bare)
|
|
107
119
|
if results.all? { |r| r.action == :noop && r.skipped.empty? }
|
|
108
|
-
@out.puts("No changes")
|
|
109
|
-
|
|
120
|
+
@out.puts("No changes") if left_bare.empty?
|
|
121
|
+
else
|
|
122
|
+
render_write_text(results)
|
|
110
123
|
end
|
|
124
|
+
render_left_bare(left_bare)
|
|
125
|
+
end
|
|
111
126
|
|
|
127
|
+
def render_write_text(results)
|
|
112
128
|
results.each do |result|
|
|
113
129
|
case result.action
|
|
114
130
|
when :created then render_write_created(result)
|
|
@@ -117,6 +133,7 @@ module Rigor
|
|
|
117
133
|
when :skipped_outside_sig_root then render_write_skipped(result)
|
|
118
134
|
when :skipped_invalid_rbs then render_write_invalid(result)
|
|
119
135
|
when :skipped_invalid_encoding then render_write_invalid_encoding(result)
|
|
136
|
+
when :skipped_unparseable then render_write_unparseable(result)
|
|
120
137
|
end
|
|
121
138
|
end
|
|
122
139
|
end
|
|
@@ -125,7 +142,29 @@ module Rigor
|
|
|
125
142
|
# because "added 2" when one of them rewrote a line the project already had would understate the change.
|
|
126
143
|
def applied_counts(result)
|
|
127
144
|
added = "+#{result.applied.size - result.replaced.size}"
|
|
128
|
-
|
|
145
|
+
added = "#{added}, replaced #{result.replaced.size}" unless result.replaced.empty?
|
|
146
|
+
repaired = result.repaired_headers
|
|
147
|
+
repaired.empty? ? added : "#{added}, repaired #{repaired.size} generic header(s): #{repaired.join(', ')}"
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
# #2605 — one line per generic class the writer left with a bare header: every file holding one, and the
|
|
151
|
+
# parameter names the blocking bodies spell. rbs keeps rejecting the class until those names are anchored
|
|
152
|
+
# (`::E`) or the headers are given parameters by hand.
|
|
153
|
+
def render_left_bare(left_bare)
|
|
154
|
+
left_bare.each do |entry|
|
|
155
|
+
reasons = entry.fetch(:blocking).map { |blocking| left_bare_reason(blocking) }
|
|
156
|
+
@out.puts("generic header left bare: #{entry.fetch(:class)} in #{entry.fetch(:targets).join(', ')} " \
|
|
157
|
+
"(#{reasons.join('; ')})")
|
|
158
|
+
end
|
|
159
|
+
end
|
|
160
|
+
|
|
161
|
+
def left_bare_reason(blocking)
|
|
162
|
+
if blocking.fetch(:reason) == "outside_sig_root"
|
|
163
|
+
"an opening outside the sig root at #{blocking.fetch(:target)}, which --write does not rewrite"
|
|
164
|
+
else
|
|
165
|
+
"#{blocking.fetch(:target)} names #{blocking.fetch(:names).join(', ')}, which the type parameter would " \
|
|
166
|
+
"capture"
|
|
167
|
+
end
|
|
129
168
|
end
|
|
130
169
|
|
|
131
170
|
def render_write_created(result)
|
|
@@ -193,10 +232,20 @@ module Rigor
|
|
|
193
232
|
@out.puts(" Re-save the file as UTF-8 and re-run; sig-gen never modifies a file it cannot read faithfully.")
|
|
194
233
|
end
|
|
195
234
|
|
|
196
|
-
|
|
235
|
+
# The EXISTING target file does not parse as RBS, so the writer will not merge into it (#2480). Like the
|
|
236
|
+
# encoding refusal the fix is the user's: the file is quarantined whole by `rigor check` until it parses.
|
|
237
|
+
def render_write_unparseable(result)
|
|
238
|
+
@out.puts("REFUSED #{result.target_path} — the existing file was not updated")
|
|
239
|
+
@out.puts(" #{result.error}")
|
|
240
|
+
@out.puts(" Fix the syntax error and re-run; sig-gen never modifies a file it cannot parse.")
|
|
241
|
+
end
|
|
242
|
+
|
|
243
|
+
def render_write_json(results, refused, left_bare)
|
|
197
244
|
payload = { results: results.map(&:to_h) }
|
|
198
245
|
payload[:refused] = refused.map(&:to_h) unless refused.empty?
|
|
199
|
-
|
|
246
|
+
# Absent when every bare generic header was repaired, so an ordinary payload is unchanged (#2605).
|
|
247
|
+
payload[:left_bare] = left_bare unless left_bare.empty?
|
|
248
|
+
@out.puts(JSON.pretty_generate(CLI::JsonDocument.stamp(payload)))
|
|
200
249
|
end
|
|
201
250
|
end
|
|
202
251
|
end
|