rigortype 0.4.0 → 0.4.2
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 +4 -3
- data/data/builtins/ruby_core/io.yml +1 -0
- data/data/builtins/ruby_core/proc.yml +4 -0
- data/data/builtins/ruby_core/random.yml +4 -0
- data/data/builtins/ruby_core/struct.yml +3 -0
- data/data/core_overlay/env.rbs +34 -0
- data/data/core_overlay/gc.rbs +50 -0
- data/data/core_overlay/hash.rbs +45 -0
- data/data/core_overlay/integer.rbs +31 -0
- data/data/core_overlay/io_buffer.rbs +27 -0
- data/data/core_overlay/kernel.rbs +40 -0
- data/data/core_overlay/match_data.rbs +28 -0
- data/data/core_overlay/module.rbs +51 -0
- data/data/core_overlay/object_space.rbs +29 -0
- data/data/core_overlay/proc.rbs +45 -0
- data/data/core_overlay/range.rbs +40 -0
- data/data/core_overlay/source_range.rbs +78 -0
- data/data/core_overlay/string.rbs +86 -0
- data/data/vendored_gem_sigs/prime/integer-extension.rbs +41 -0
- data/data/vendored_gem_sigs/prime/prime.rbs +372 -0
- data/docs/handbook/01-getting-started.md +3 -3
- data/docs/handbook/06-classes.md +3 -1
- data/docs/handbook/08-understanding-errors.md +3 -2
- data/docs/handbook/11-sig-gen.md +6 -0
- data/docs/handbook/appendix-liskov.md +5 -0
- data/docs/install.md +87 -15
- data/docs/manual/02-cli-reference.md +2 -2
- data/docs/manual/03-configuration.md +6 -1
- data/docs/manual/04-diagnostics.md +2 -1
- data/docs/manual/06-baseline.md +2 -0
- data/docs/manual/07-plugins.md +1 -1
- data/docs/manual/08-skills.md +4 -3
- data/docs/manual/12-caching.md +43 -4
- data/docs/manual/14-rails-quickstart.md +19 -11
- data/docs/manual/18-removing-dead-code.md +32 -2
- data/docs/manual/plugins/README.md +6 -1
- data/docs/manual/plugins/rigor-activerecord.md +21 -0
- data/docs/manual/plugins/rigor-alba.md +60 -0
- data/docs/manual/plugins/rigor-minitest.md +22 -4
- data/docs/manual/plugins/rigor-typelizer.md +71 -0
- data/lib/rigor/analysis/check_rules/ivar_write_collector.rb +27 -3
- data/lib/rigor/analysis/check_rules/lexical_method_sites.rb +21 -92
- data/lib/rigor/analysis/check_rules/ruby_deprecations.rb +275 -0
- data/lib/rigor/analysis/check_rules/rule_ids.rb +4 -0
- data/lib/rigor/analysis/check_rules/source_arity.rb +184 -61
- data/lib/rigor/analysis/check_rules.rb +407 -144
- data/lib/rigor/analysis/dependency_recorder.rb +215 -18
- data/lib/rigor/analysis/dependency_source_inference/builder.rb +8 -1
- data/lib/rigor/analysis/dependency_source_inference/gem_resolver.rb +21 -0
- data/lib/rigor/analysis/dependency_source_inference/index.rb +36 -11
- data/lib/rigor/analysis/dependency_source_inference/walker.rb +196 -27
- data/lib/rigor/analysis/erb_template_detector.rb +2 -1
- data/lib/rigor/analysis/incremental.rb +29 -9
- data/lib/rigor/analysis/incremental_run_slot/write_guard.rb +291 -0
- data/lib/rigor/analysis/incremental_run_slot.rb +173 -0
- data/lib/rigor/analysis/incremental_session.rb +287 -50
- data/lib/rigor/analysis/plugin_fact_fingerprint.rb +24 -13
- data/lib/rigor/analysis/reachability/graph.rb +123 -23
- data/lib/rigor/analysis/reachability/scan.rb +290 -36
- data/lib/rigor/analysis/reachability/scan_cache.rb +2 -1
- data/lib/rigor/analysis/rule_catalog.rb +43 -0
- data/lib/rigor/analysis/run_cache_key.rb +43 -9
- data/lib/rigor/analysis/run_stats.rb +2 -2
- data/lib/rigor/analysis/runner/diagnostic_aggregator.rb +88 -6
- data/lib/rigor/analysis/runner/pool_coordinator.rb +52 -13
- data/lib/rigor/analysis/runner/project_pre_passes.rb +21 -13
- data/lib/rigor/analysis/runner/run_snapshots.rb +6 -1
- data/lib/rigor/analysis/runner.rb +371 -49
- data/lib/rigor/analysis/shadow_harness.rb +27 -0
- data/lib/rigor/analysis/source_rbs_gate.rb +157 -0
- data/lib/rigor/analysis/template_unit_paths.rb +6 -4
- data/lib/rigor/analysis/template_units.rb +15 -5
- data/lib/rigor/analysis/worker_session.rb +11 -7
- data/lib/rigor/cache/descriptor.rb +40 -1
- data/lib/rigor/cache/file_digest.rb +28 -0
- data/lib/rigor/cache/incremental_snapshot.rb +92 -8
- data/lib/rigor/cache/store.rb +63 -3
- data/lib/rigor/cache/value_digest.rb +325 -0
- data/lib/rigor/cli/annotate_command.rb +5 -0
- data/lib/rigor/cli/baseline_command.rb +7 -18
- data/lib/rigor/cli/check_command.rb +85 -14
- data/lib/rigor/cli/doctor_command.rb +1 -1
- data/lib/rigor/cli/effects_report.rb +2 -2
- data/lib/rigor/cli/trace_command.rb +5 -0
- data/lib/rigor/cli/type_of_command.rb +5 -3
- data/lib/rigor/cli/unused_command.rb +16 -10
- data/lib/rigor/cli.rb +11 -3
- data/lib/rigor/config_audit.rb +3 -2
- data/lib/rigor/config_path.rb +29 -0
- data/lib/rigor/configuration/severity_profile.rb +11 -0
- data/lib/rigor/configuration.rb +52 -7
- data/lib/rigor/effects/plugin_facts.rb +6 -6
- data/lib/rigor/environment/bundle_sig_discovery.rb +5 -3
- data/lib/rigor/environment/gated_signature_guard.rb +43 -0
- data/lib/rigor/environment/gated_signature_plan.rb +339 -0
- data/lib/rigor/environment/lockfile_resolver.rb +10 -1
- data/lib/rigor/environment/rbs_collection_discovery.rb +10 -1
- data/lib/rigor/environment/rbs_coverage_report.rb +1 -1
- data/lib/rigor/environment/rbs_loader.rb +284 -15
- data/lib/rigor/environment/required_features.rb +206 -0
- data/lib/rigor/environment/source_rbs_synthesis.rb +147 -0
- data/lib/rigor/environment.rb +34 -73
- data/lib/rigor/inference/acceptance.rb +28 -3
- data/lib/rigor/inference/block_parameter_binder.rb +29 -13
- data/lib/rigor/inference/builtins/cruby_definers.rb +61 -0
- data/lib/rigor/inference/builtins/method_catalog.rb +3 -0
- data/lib/rigor/inference/captured_locals.rb +7 -1
- data/lib/rigor/inference/declaration_walk/context.rb +195 -0
- data/lib/rigor/inference/declaration_walk/errors.rb +18 -0
- data/lib/rigor/inference/declaration_walk/shadow.rb +147 -0
- data/lib/rigor/inference/declaration_walk/traversal.rb +441 -0
- data/lib/rigor/inference/declaration_walk.rb +7 -0
- data/lib/rigor/inference/def_node_resolver.rb +26 -3
- data/lib/rigor/inference/definer_resolution.rb +266 -0
- data/lib/rigor/inference/expression_typer.rb +351 -61
- data/lib/rigor/inference/external_ancestor_resolution.rb +13 -16
- data/lib/rigor/inference/global_write_census.rb +7 -4
- data/lib/rigor/inference/guard_rebinding.rb +54 -13
- data/lib/rigor/inference/in_effect_refinements/proc_literals.rb +83 -0
- data/lib/rigor/inference/in_effect_refinements/refine_defs.rb +54 -0
- data/lib/rigor/inference/in_effect_refinements/scope_reads.rb +282 -0
- data/lib/rigor/inference/in_effect_refinements/walk.rb +276 -0
- data/lib/rigor/inference/in_effect_refinements.rb +256 -0
- data/lib/rigor/inference/key_presence_guard/scan.rb +281 -0
- data/lib/rigor/inference/key_presence_guard.rb +303 -0
- data/lib/rigor/inference/macro_block_self_type.rb +73 -14
- data/lib/rigor/inference/method_dispatcher/alias_strict_nominals.rb +36 -0
- data/lib/rigor/inference/method_dispatcher/arithmetic_sequence_elements.rb +73 -0
- data/lib/rigor/inference/method_dispatcher/imprecise_argument.rb +68 -0
- data/lib/rigor/inference/method_dispatcher/integer_step_block_params.rb +81 -0
- data/lib/rigor/inference/method_dispatcher/iterator_dispatch.rb +6 -0
- data/lib/rigor/inference/method_dispatcher/keyword_arguments.rb +267 -0
- data/lib/rigor/inference/method_dispatcher/method_folding.rb +2 -1
- data/lib/rigor/inference/method_dispatcher/overload_selector.rb +122 -105
- data/lib/rigor/inference/method_dispatcher/rbs_dispatch.rb +305 -54
- data/lib/rigor/inference/method_dispatcher/splat_arity.rb +71 -0
- data/lib/rigor/inference/method_dispatcher.rb +44 -11
- data/lib/rigor/inference/module_function_state.rb +214 -0
- data/lib/rigor/inference/multi_target_binder.rb +21 -16
- data/lib/rigor/inference/narrowing.rb +166 -22
- data/lib/rigor/inference/object_mixins.rb +180 -0
- data/lib/rigor/inference/parameter_inference_collector.rb +10 -9
- data/lib/rigor/inference/project_patched_methods.rb +10 -5
- data/lib/rigor/inference/project_patched_scanner.rb +71 -3
- data/lib/rigor/inference/refine_census.rb +239 -0
- data/lib/rigor/inference/refine_self.rb +317 -0
- data/lib/rigor/inference/refined_dispatch/own_method.rb +403 -0
- data/lib/rigor/inference/refined_dispatch.rb +272 -0
- data/lib/rigor/inference/scope_indexer/certainty.rb +176 -0
- data/lib/rigor/inference/scope_indexer/class_cvars_collector.rb +35 -0
- data/lib/rigor/inference/scope_indexer/def_nestings_collector.rb +47 -0
- data/lib/rigor/inference/scope_indexer/layered_def_nestings.rb +36 -0
- data/lib/rigor/inference/scope_indexer/member_layouts_collector.rb +61 -0
- data/lib/rigor/inference/scope_indexer/mixin_accumulator.rb +143 -0
- data/lib/rigor/inference/scope_indexer/superclasses_collector.rb +64 -0
- data/lib/rigor/inference/scope_indexer.rb +2129 -354
- data/lib/rigor/inference/singleton_hook_decline.rb +253 -0
- data/lib/rigor/inference/statement_evaluator.rb +149 -32
- data/lib/rigor/inference/string_mutation.rb +9 -3
- data/lib/rigor/inference/synthetic_method_scanner.rb +2 -1
- data/lib/rigor/inference/version_guard.rb +19 -10
- data/lib/rigor/language_server/project_context.rb +31 -0
- data/lib/rigor/language_server/server.rb +18 -0
- data/lib/rigor/plugin/base.rb +28 -8
- data/lib/rigor/plugin/inflector.rb +1 -1
- data/lib/rigor/plugin/io_boundary.rb +124 -7
- data/lib/rigor/plugin/isolation.rb +1 -1
- data/lib/rigor/plugin/macro/block_as_method.rb +51 -8
- data/lib/rigor/plugin/trust_policy.rb +3 -3
- data/lib/rigor/project_environment.rb +29 -6
- data/lib/rigor/protection/discovery_seed.rb +18 -9
- data/lib/rigor/protection/mutation_cache.rb +4 -4
- data/lib/rigor/protection/mutator.rb +1 -1
- data/lib/rigor/reflection/constant_ancestors.rb +211 -46
- data/lib/rigor/reflection/constant_path.rb +33 -7
- data/lib/rigor/reflection.rb +41 -10
- data/lib/rigor/scope/discovery_index.rb +258 -3
- data/lib/rigor/scope/resolution_chain/relevance.rb +165 -0
- data/lib/rigor/scope/resolution_chain.rb +1032 -0
- data/lib/rigor/scope.rb +480 -328
- data/lib/rigor/sig_gen/alias_index.rb +1 -1
- data/lib/rigor/sig_gen/classification.rb +4 -1
- data/lib/rigor/sig_gen/effect_annotation.rb +2 -2
- data/lib/rigor/sig_gen/generator.rb +77 -21
- data/lib/rigor/sig_gen/method_candidate.rb +2 -2
- data/lib/rigor/sig_gen/skip_reason_catalog.rb +12 -0
- data/lib/rigor/source/alias_names.rb +52 -0
- data/lib/rigor/source/literals.rb +3 -2
- data/lib/rigor/source/symbol_name.rb +20 -0
- data/lib/rigor/type/combinator.rb +59 -3
- data/lib/rigor/type/float_range.rb +4 -1
- data/lib/rigor/type/nominal.rb +6 -1
- data/lib/rigor/version.rb +1 -1
- data/plugins/rigor-ac-library-rb/lib/rigor/plugin/ac_library_rb.rb +28 -0
- data/plugins/rigor-ac-library-rb/lib/rigor-ac-library-rb.rb +3 -0
- data/plugins/rigor-ac-library-rb/sig/ac_library_rb/convolution.rbs +7 -0
- data/plugins/rigor-ac-library-rb/sig/ac_library_rb/data_structures.rbs +160 -0
- data/plugins/rigor-ac-library-rb/sig/ac_library_rb/graph.rbs +94 -0
- data/plugins/rigor-ac-library-rb/sig/ac_library_rb/math.rbs +42 -0
- data/plugins/rigor-ac-library-rb/sig/ac_library_rb/modint.rbs +71 -0
- data/plugins/rigor-ac-library-rb/sig/ac_library_rb/object.rbs +37 -0
- data/plugins/rigor-ac-library-rb/sig/ac_library_rb/segtree.rbs +83 -0
- data/plugins/rigor-actionpack/lib/rigor/plugin/actionpack/analyzer.rb +2 -1
- data/plugins/rigor-activerecord/lib/rigor/plugin/activerecord/association_roots.rb +100 -0
- data/plugins/rigor-activerecord/lib/rigor/plugin/activerecord/model_discoverer.rb +94 -10
- data/plugins/rigor-activerecord/lib/rigor/plugin/activerecord.rb +43 -2
- data/plugins/rigor-activerecord/sig/active_record/relation.rbs +3 -1
- data/plugins/rigor-alba/lib/rigor/plugin/alba/resource_collector.rb +149 -0
- data/plugins/rigor-alba/lib/rigor/plugin/alba/resource_discoverer.rb +74 -0
- data/plugins/rigor-alba/lib/rigor/plugin/alba/resource_index.rb +104 -0
- data/plugins/rigor-alba/lib/rigor/plugin/alba.rb +85 -0
- data/plugins/rigor-alba/lib/rigor-alba.rb +3 -0
- data/plugins/rigor-alba/sig/alba.rbs +4 -0
- data/plugins/rigor-ffi/lib/rigor/plugin/ffi/analyzer.rb +2 -2
- data/plugins/rigor-ffi/lib/rigor/plugin/ffi/target_detector.rb +29 -12
- data/plugins/rigor-ffi/lib/rigor/plugin/ffi.rb +13 -2
- data/plugins/rigor-minitest/lib/rigor/plugin/minitest/assertion_analyzer.rb +130 -21
- data/plugins/rigor-minitest/lib/rigor/plugin/minitest.rb +6 -4
- data/plugins/rigor-pundit/lib/rigor/plugin/pundit/analyzer.rb +4 -4
- data/plugins/rigor-rails-i18n/lib/rigor/plugin/rails_i18n/analyzer.rb +1 -1
- data/plugins/rigor-rails-routes/lib/rigor/plugin/rails_routes/routes_parser.rb +1 -1
- data/plugins/rigor-rbs-inline/lib/rigor/plugin/rbs_inline.rb +31 -0
- data/plugins/rigor-typelizer/lib/rigor/plugin/typelizer/serializer_collector.rb +102 -0
- data/plugins/rigor-typelizer/lib/rigor/plugin/typelizer/serializer_discoverer.rb +87 -0
- data/plugins/rigor-typelizer/lib/rigor/plugin/typelizer/serializer_index.rb +76 -0
- data/plugins/rigor-typelizer/lib/rigor/plugin/typelizer.rb +73 -0
- data/plugins/rigor-typelizer/lib/rigor-typelizer.rb +3 -0
- data/sig/rigor/analysis/dependency_source_inference/index.rbs +1 -1
- data/sig/rigor/environment.rbs +2 -0
- data/sig/rigor/plugin/io_boundary.rbs +4 -0
- data/sig/rigor/scope.rbs +69 -4
- data/sig/rigor/source.rbs +4 -0
- data/sig/rigor.rbs +3 -1
- data/skills/rigor-project-init/SKILL.md +37 -11
- data/skills/rigor-project-init/references/02-configure.md +7 -2
- metadata +90 -1
|
@@ -0,0 +1,339 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "rbs"
|
|
4
|
+
|
|
5
|
+
module Rigor
|
|
6
|
+
class Environment
|
|
7
|
+
# Issue #1713 — loading a {RequiredFeatures}-gated vendored directory minus only what another signature
|
|
8
|
+
# source already declares, instead of standing the whole directory down.
|
|
9
|
+
#
|
|
10
|
+
# `RbsLoader.build_env_for` first tries the directory whole. When that costs the environment something
|
|
11
|
+
# (`RbsLoader.gated_failures`), it builds the environment WITHOUT the directory and plans against it with
|
|
12
|
+
# {.build}: the plan is the directory's parsed declarations, rewritten in memory (the files on disk are never
|
|
13
|
+
# touched), so that
|
|
14
|
+
#
|
|
15
|
+
# - a method, attribute or alias another source declares on the same class is left out (an overload
|
|
16
|
+
# continuation, `def m: ... | ...`, declares nothing of its own and needs the vendored base, so it keeps
|
|
17
|
+
# it); a member declaring two methods loses only the one taken — an `attr_accessor` narrows to its reader
|
|
18
|
+
# or writer, a `def self?.m` to its instance or singleton side;
|
|
19
|
+
# - a type whose header disagrees with another source's — a class one side declares as a module, or a
|
|
20
|
+
# different generic arity — stands down as a whole: its declaration becomes a *shell*, the other source's
|
|
21
|
+
# header with no members and no superclass, which keeps the vendored types nested inside it in their
|
|
22
|
+
# lexical context;
|
|
23
|
+
# - a type in `shelled` (the types the trial build of a previous plan still failed for) is shelled the same
|
|
24
|
+
# way when another source declares it. When none does — the type failed because something it names was
|
|
25
|
+
# displaced, a superclass the project redeclared as a module, say — it keeps its own members and nested
|
|
26
|
+
# types but loses its superclass, and is stamped as a Rigor-synthesized stub type
|
|
27
|
+
# (`RbsLoader::SYNTHETIC_STUB_BUFFER`): its own members still type, and a call it no longer answers reads
|
|
28
|
+
# `Dynamic[top]` rather than drawing `call.undefined-method` for a method it inherits at runtime.
|
|
29
|
+
#
|
|
30
|
+
# The kept declarations load where the directory would have loaded, ahead of the project's signatures, so
|
|
31
|
+
# which declaration is a class's primary one does not move; the shells load after them, so a shell never
|
|
32
|
+
# becomes the primary declaration of a class the project declares. The trial build stays the arbiter:
|
|
33
|
+
# `build_env_for` keeps a plan's environment only when every gated type builds in it.
|
|
34
|
+
#
|
|
35
|
+
# {.standdowns} reads what stood down back off a built environment, the way the other `rbs.coverage.*`
|
|
36
|
+
# notices are derived, so a warm run off the env cache reports what the cold run reported.
|
|
37
|
+
module GatedSignaturePlan
|
|
38
|
+
# Buffer name stamped on the shell declarations. Never a real path, so {.standdowns} tells a shell from the
|
|
39
|
+
# vendored declaration it replaced by it.
|
|
40
|
+
SHELL_BUFFER = "(rigor: vendored stand-down shells)"
|
|
41
|
+
|
|
42
|
+
# The buffer names Rigor synthesizes declarations under. They stand for no source, so neither a plan nor
|
|
43
|
+
# a stand-down report reads them as another source's declaration.
|
|
44
|
+
def self.synthetic_buffers
|
|
45
|
+
[SHELL_BUFFER, RbsLoader::SYNTHETIC_NAMESPACE_BUFFER, RbsLoader::SYNTHETIC_STUB_BUFFER]
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
# A planned load: `leading` and `shells` are `[buffer, directives, decls]` sources, `changed` is false
|
|
49
|
+
# when the plan is the directory as it stands.
|
|
50
|
+
Plan = Data.define(:leading, :shells, :changed)
|
|
51
|
+
|
|
52
|
+
# One plan's walk over the vendored declarations: the environment it plans against, the types to shell
|
|
53
|
+
# whatever their headers, and whether anything was left out.
|
|
54
|
+
class Planner
|
|
55
|
+
attr_reader :changed
|
|
56
|
+
|
|
57
|
+
def initialize(base_env, shelled)
|
|
58
|
+
@base_env = base_env
|
|
59
|
+
@shelled = shelled
|
|
60
|
+
@changed = false
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
# Splits `decls` into what loads ahead of the project's signatures and what loads after them.
|
|
64
|
+
def plan_decls(decls, namespace)
|
|
65
|
+
lead = []
|
|
66
|
+
shell = []
|
|
67
|
+
decls.each do |decl|
|
|
68
|
+
unless GatedSignaturePlan.type_declaration?(decl)
|
|
69
|
+
lead << decl
|
|
70
|
+
next
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
kept, shelled = plan_type(decl, GatedSignaturePlan.qualify(namespace, decl.name))
|
|
74
|
+
lead << kept if kept
|
|
75
|
+
shell << shelled if shelled
|
|
76
|
+
end
|
|
77
|
+
[lead, shell]
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
private
|
|
81
|
+
|
|
82
|
+
def plan_type(decl, name)
|
|
83
|
+
others = GatedSignaturePlan.other_declarations(@base_env, name)
|
|
84
|
+
nested = decl.members.select { |member| GatedSignaturePlan.type_declaration?(member) }
|
|
85
|
+
nested_lead, nested_shell = plan_decls(nested, name)
|
|
86
|
+
if GatedSignaturePlan.header_conflict?(decl, others) || (@shelled.include?(name) && !others.empty?)
|
|
87
|
+
@changed = true
|
|
88
|
+
return [nil, GatedSignaturePlan.header_copy(others.first, decl.name, nested_lead + nested_shell)]
|
|
89
|
+
end
|
|
90
|
+
return [nil, open_type(decl, nested_lead + nested_shell)] if @shelled.include?(name)
|
|
91
|
+
|
|
92
|
+
wrapper = nested_shell.empty? ? nil : GatedSignaturePlan.header_copy(decl, decl.name, nested_shell)
|
|
93
|
+
[keep_type(decl, others, nested_lead), wrapper]
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
# `decl` less the methods `others` declare, with its nested types replaced by their planned kept halves.
|
|
97
|
+
def keep_type(decl, others, nested_lead)
|
|
98
|
+
taken = GatedSignaturePlan.declared_keys(others)
|
|
99
|
+
own = decl.members.reject { |member| GatedSignaturePlan.type_declaration?(member) }
|
|
100
|
+
members = own.filter_map { |member| GatedSignaturePlan.untaken(member, taken) }
|
|
101
|
+
@changed ||= members.size != own.size || members.zip(own).any? { |kept, member| !kept.equal?(member) }
|
|
102
|
+
GatedSignaturePlan.rebuild(decl, members: members + nested_lead)
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
# A type no other source declares that still failed to build: its own members, no superclass, stamped as a
|
|
106
|
+
# synthesized stub type so what it no longer inherits reads untyped.
|
|
107
|
+
def open_type(decl, nested)
|
|
108
|
+
@changed = true
|
|
109
|
+
own = decl.members.reject { |member| GatedSignaturePlan.type_declaration?(member) }
|
|
110
|
+
GatedSignaturePlan.header_copy(decl, decl.name, own + nested, buffer_name: RbsLoader::SYNTHETIC_STUB_BUFFER)
|
|
111
|
+
end
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
module_function
|
|
115
|
+
|
|
116
|
+
# @param roots — the gated directories (Pathnames) to plan, each loaded whole on the first attempt.
|
|
117
|
+
# @param base_env — the environment built without them: every other signature source, resolved.
|
|
118
|
+
# @param shelled — absolute-less type names to shell regardless of their headers.
|
|
119
|
+
def build(roots, base_env, shelled = Set.new)
|
|
120
|
+
planner = Planner.new(base_env, shelled)
|
|
121
|
+
leading = []
|
|
122
|
+
shells = []
|
|
123
|
+
signature_files(roots).each do |file|
|
|
124
|
+
buffer, directives, decls = RbsLoader.parse_signature_file(file)
|
|
125
|
+
next if buffer.nil?
|
|
126
|
+
|
|
127
|
+
lead, shell = planner.plan_decls(decls, nil)
|
|
128
|
+
leading << [buffer, directives, lead]
|
|
129
|
+
shells << [shell_buffer, directives, shell] unless shell.empty?
|
|
130
|
+
end
|
|
131
|
+
Plan.new(leading: leading, shells: shells, changed: planner.changed)
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
def signature_files(roots)
|
|
135
|
+
roots.flat_map { |root| Dir.glob(File.join(root.to_s, "*.rbs")).sort }
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
def shell_buffer
|
|
139
|
+
::RBS::Buffer.new(name: SHELL_BUFFER, content: "")
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
# The declarations of `name` in `env` that some other source made, synthesized stubs left out.
|
|
143
|
+
def other_declarations(env, name)
|
|
144
|
+
entry = env&.class_decls&.[](::RBS::TypeName.parse("::#{name}"))
|
|
145
|
+
return [] if entry.nil?
|
|
146
|
+
|
|
147
|
+
RbsLoader.entry_declarations(entry).reject { |decl| synthetic?(decl) }
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
def synthetic?(decl)
|
|
151
|
+
synthetic_buffers.include?(RbsLoader.declaration_buffer_name(decl))
|
|
152
|
+
end
|
|
153
|
+
|
|
154
|
+
# A class one side declares as a module, or a different number of type parameters. A disagreement the
|
|
155
|
+
# declarations do not show this plainly — a superclass, a variance, a bound — is the trial build's to find.
|
|
156
|
+
def header_conflict?(decl, others)
|
|
157
|
+
first = others.first
|
|
158
|
+
return false if first.nil?
|
|
159
|
+
return true unless first.instance_of?(decl.class)
|
|
160
|
+
|
|
161
|
+
first.type_params.size != decl.type_params.size
|
|
162
|
+
end
|
|
163
|
+
|
|
164
|
+
def declared_keys(others)
|
|
165
|
+
others.each_with_object(Set.new) do |other, keys|
|
|
166
|
+
other.members.each { |member| RbsLoader.member_method_keys(member).each { |key| keys << key } }
|
|
167
|
+
end
|
|
168
|
+
end
|
|
169
|
+
|
|
170
|
+
# `member` less the methods in `taken`: itself when it declares none of them, nil when it declares only
|
|
171
|
+
# them, else narrowed to the one it declares that is not taken.
|
|
172
|
+
def untaken(member, taken)
|
|
173
|
+
keys = RbsLoader.member_method_keys(member)
|
|
174
|
+
left = keys.reject { |key| taken.include?(key) }
|
|
175
|
+
return member if left.size == keys.size
|
|
176
|
+
return nil if left.empty?
|
|
177
|
+
|
|
178
|
+
narrowed(member, left.first)
|
|
179
|
+
end
|
|
180
|
+
|
|
181
|
+
# The two members that declare two methods: an `attr_accessor` (a reader and a writer) and a
|
|
182
|
+
# `def self?.m` (an instance and a singleton method). The instance side of a `self?` method is private
|
|
183
|
+
# (a module function), so narrowing to it keeps that.
|
|
184
|
+
def narrowed(member, key)
|
|
185
|
+
method_name, kind = key
|
|
186
|
+
if member.is_a?(::RBS::AST::Members::MethodDefinition)
|
|
187
|
+
return member.update(kind: kind, visibility: kind == :instance ? :private : member.visibility)
|
|
188
|
+
end
|
|
189
|
+
|
|
190
|
+
attribute = method_name.to_s.end_with?("=") ? ::RBS::AST::Members::AttrWriter : ::RBS::AST::Members::AttrReader
|
|
191
|
+
attribute.new(
|
|
192
|
+
name: member.name, type: member.type, ivar_name: member.ivar_name, kind: member.kind,
|
|
193
|
+
annotations: member.annotations, location: member.location, comment: member.comment,
|
|
194
|
+
visibility: member.visibility
|
|
195
|
+
)
|
|
196
|
+
end
|
|
197
|
+
|
|
198
|
+
# `source`'s kind and type parameters under `name`, carrying only `members` — no superclass, self types,
|
|
199
|
+
# annotations or members of its own, all of which a reopening declaration may omit.
|
|
200
|
+
def header_copy(source, name, members, buffer_name: SHELL_BUFFER)
|
|
201
|
+
location = ::RBS::Location.new(::RBS::Buffer.new(name: buffer_name, content: ""), 0, 0)
|
|
202
|
+
if source.is_a?(::RBS::AST::Declarations::Class)
|
|
203
|
+
::RBS::AST::Declarations::Class.new(
|
|
204
|
+
name: name, type_params: source.type_params, super_class: nil, members: members,
|
|
205
|
+
annotations: [], location: location, comment: nil
|
|
206
|
+
)
|
|
207
|
+
else
|
|
208
|
+
::RBS::AST::Declarations::Module.new(
|
|
209
|
+
name: name, type_params: source.type_params, members: members, self_types: [],
|
|
210
|
+
annotations: [], location: location, comment: nil
|
|
211
|
+
)
|
|
212
|
+
end
|
|
213
|
+
end
|
|
214
|
+
|
|
215
|
+
def rebuild(decl, members:)
|
|
216
|
+
if decl.is_a?(::RBS::AST::Declarations::Class)
|
|
217
|
+
::RBS::AST::Declarations::Class.new(
|
|
218
|
+
name: decl.name, type_params: decl.type_params, super_class: decl.super_class, members: members,
|
|
219
|
+
annotations: decl.annotations, location: decl.location, comment: decl.comment
|
|
220
|
+
)
|
|
221
|
+
else
|
|
222
|
+
::RBS::AST::Declarations::Module.new(
|
|
223
|
+
name: decl.name, type_params: decl.type_params, members: members, self_types: decl.self_types,
|
|
224
|
+
annotations: decl.annotations, location: decl.location, comment: decl.comment
|
|
225
|
+
)
|
|
226
|
+
end
|
|
227
|
+
end
|
|
228
|
+
|
|
229
|
+
def type_declaration?(decl)
|
|
230
|
+
decl.is_a?(::RBS::AST::Declarations::Class) || decl.is_a?(::RBS::AST::Declarations::Module)
|
|
231
|
+
end
|
|
232
|
+
|
|
233
|
+
def qualify(namespace, type_name)
|
|
234
|
+
text = type_name.to_s
|
|
235
|
+
return text.delete_prefix("::") if text.start_with?("::") || namespace.nil?
|
|
236
|
+
|
|
237
|
+
"#{namespace}::#{text}"
|
|
238
|
+
end
|
|
239
|
+
|
|
240
|
+
# What stood down from each of `roots` in `env`, as `[dir, entries, whole]`: `entries` are
|
|
241
|
+
# `[declaration, cause_file, reason]`, `declaration` reading `Integer#prime?`, `Integer.from_prime_division`
|
|
242
|
+
# or `Prime` (a whole type), `cause_file` the buffer name of the other source's declaration, or nil when it
|
|
243
|
+
# cannot be named, and `reason` one of `"member"` (another source declares that method), `"type"` (the
|
|
244
|
+
# type stood down whole, its header contradicted or failing beside another source's declaration) or
|
|
245
|
+
# `"open"` (it failed with no other source declaring it, and was kept without its superclass, unchecked).
|
|
246
|
+
# `whole` is true when the directory stood down entirely; its entries are then only the clashes the
|
|
247
|
+
# environment still shows. A directory nothing stood down from is left out.
|
|
248
|
+
#
|
|
249
|
+
# @param roots — `{dir_basename => Pathname}` of the gated directories the run activated.
|
|
250
|
+
# @param project_files — the project's own signature files: a cause is named from them (or from inline
|
|
251
|
+
# RBS) in preference to another source, and only from them when the type failed rather than clashed.
|
|
252
|
+
def standdowns(env, roots, project_files = Set.new)
|
|
253
|
+
return [] if env.nil?
|
|
254
|
+
|
|
255
|
+
loaded = RbsLoader.loaded_signature_buffers(env)&.to_set { |buffer| buffer.name.to_s } || Set.new
|
|
256
|
+
roots.sort.filter_map do |dir, root|
|
|
257
|
+
files = signature_files([root])
|
|
258
|
+
whole = files.none? { |file| loaded.include?(file) }
|
|
259
|
+
entries = files.flat_map { |file| file_standdowns(env, file, whole, project_files) }.uniq
|
|
260
|
+
[dir, entries, whole] if whole || !entries.empty?
|
|
261
|
+
end
|
|
262
|
+
rescue ::RBS::BaseError
|
|
263
|
+
[]
|
|
264
|
+
end
|
|
265
|
+
|
|
266
|
+
def file_standdowns(env, file, whole, project_files)
|
|
267
|
+
_buffer, _directives, decls = RbsLoader.parse_signature_file(file)
|
|
268
|
+
return [] if decls.nil?
|
|
269
|
+
|
|
270
|
+
entries = []
|
|
271
|
+
each_type(decls, nil) do |decl, name|
|
|
272
|
+
entries.concat(type_standdowns(env, file, [decl, name], whole, project_files))
|
|
273
|
+
end
|
|
274
|
+
entries
|
|
275
|
+
end
|
|
276
|
+
|
|
277
|
+
def each_type(decls, namespace, &block)
|
|
278
|
+
decls.each do |decl|
|
|
279
|
+
next unless type_declaration?(decl)
|
|
280
|
+
|
|
281
|
+
name = qualify(namespace, decl.name)
|
|
282
|
+
block.call(decl, name)
|
|
283
|
+
each_type(decl.members, name, &block)
|
|
284
|
+
end
|
|
285
|
+
end
|
|
286
|
+
|
|
287
|
+
def type_standdowns(env, file, (decl, name), whole, project_files)
|
|
288
|
+
entry = env.class_decls[::RBS::TypeName.parse("::#{name}")]
|
|
289
|
+
declarations = entry.nil? ? [] : RbsLoader.entry_declarations(entry)
|
|
290
|
+
vendored = declarations.select { |other| RbsLoader.declaration_buffer_name(other) == file }
|
|
291
|
+
others = declarations.reject { |other| vendored.include?(other) || synthetic?(other) }
|
|
292
|
+
# A partial load shells a type that stood down, so its vendored declaration is gone; a whole stand-down
|
|
293
|
+
# removed every vendored declaration, and only a header the environment still contradicts names a type.
|
|
294
|
+
conflict = header_conflict?(decl, others)
|
|
295
|
+
type_row = [[name, type_cause(others, conflict, project_files), "type"]]
|
|
296
|
+
return conflict ? type_row : member_standdowns(decl, name, [], others, true) if whole
|
|
297
|
+
return member_standdowns(decl, name, vendored, others, false) unless vendored.empty?
|
|
298
|
+
return [[name, nil, "open"]] if others.empty? && declarations.any? { |other| stub?(other) }
|
|
299
|
+
|
|
300
|
+
type_row
|
|
301
|
+
end
|
|
302
|
+
|
|
303
|
+
# A header clash names the declaration it clashed with, preferring the project's own; a type that only
|
|
304
|
+
# failed beside another source names a project or inline declaration of it, never core or a gem's copy.
|
|
305
|
+
def type_cause(others, conflict, project_files)
|
|
306
|
+
own = others.find do |other|
|
|
307
|
+
name = buffer_of(other).to_s
|
|
308
|
+
project_files.include?(name) || name.start_with?("virtual:")
|
|
309
|
+
end
|
|
310
|
+
buffer_of(own || (conflict ? others.first : nil))
|
|
311
|
+
end
|
|
312
|
+
|
|
313
|
+
def stub?(decl)
|
|
314
|
+
RbsLoader.declaration_buffer_name(decl) == RbsLoader::SYNTHETIC_STUB_BUFFER
|
|
315
|
+
end
|
|
316
|
+
|
|
317
|
+
def member_standdowns(decl, name, vendored, others, whole)
|
|
318
|
+
present = declared_keys(vendored)
|
|
319
|
+
decl.members.flat_map do |member|
|
|
320
|
+
RbsLoader.member_method_keys(member).reject { |key| present.include?(key) }.filter_map do |key|
|
|
321
|
+
cause = others.find { |other| other.members.any? { |m| RbsLoader.member_method_keys(m).include?(key) } }
|
|
322
|
+
next if whole && cause.nil?
|
|
323
|
+
|
|
324
|
+
[member_label(name, key), buffer_of(cause), "member"]
|
|
325
|
+
end
|
|
326
|
+
end
|
|
327
|
+
end
|
|
328
|
+
|
|
329
|
+
def member_label(name, key)
|
|
330
|
+
method_name, kind = key
|
|
331
|
+
"#{name}#{kind == :singleton ? '.' : '#'}#{method_name}"
|
|
332
|
+
end
|
|
333
|
+
|
|
334
|
+
def buffer_of(decl)
|
|
335
|
+
decl && RbsLoader.declaration_buffer_name(decl)
|
|
336
|
+
end
|
|
337
|
+
end
|
|
338
|
+
end
|
|
339
|
+
end
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require_relative "../config_path"
|
|
4
|
+
|
|
3
5
|
module Rigor
|
|
4
6
|
class Environment
|
|
5
7
|
# Gemfile.lock parser for target-project bundler awareness (O4 Layer 3, implemented).
|
|
@@ -109,11 +111,18 @@ module Rigor
|
|
|
109
111
|
end
|
|
110
112
|
private_class_method :do_parse_dependency_names
|
|
111
113
|
|
|
114
|
+
# The absolute path a configured `lockfile:` names, whether or not the file exists. The one place the
|
|
115
|
+
# setting is expanded (a leading `~/` is the home directory), shared by `resolve_lockfile_path` and
|
|
116
|
+
# by `WriteGuard`, which must watch the very path the run reads.
|
|
117
|
+
def self.configured_lockfile_path(lockfile_path, project_root = Dir.pwd)
|
|
118
|
+
Rigor::ConfigPath.absolute(lockfile_path.to_s, project_root)
|
|
119
|
+
end
|
|
120
|
+
|
|
112
121
|
# Returns the resolved lockfile path (`Pathname`) or `nil` when neither explicit nor auto-detect
|
|
113
122
|
# produces one. Public so the stats banner can show what rigor picked up.
|
|
114
123
|
def self.resolve_lockfile_path(lockfile_path:, project_root: Dir.pwd, auto_detect: true)
|
|
115
124
|
if lockfile_path
|
|
116
|
-
path = Pathname.new(
|
|
125
|
+
path = Pathname.new(configured_lockfile_path(lockfile_path, project_root))
|
|
117
126
|
return path if path.file?
|
|
118
127
|
|
|
119
128
|
return nil
|
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
require "yaml"
|
|
4
4
|
|
|
5
|
+
require_relative "../config_path"
|
|
6
|
+
|
|
5
7
|
module Rigor
|
|
6
8
|
class Environment
|
|
7
9
|
# `rbs collection install` awareness (O4 Layer 3 slice 2, implemented).
|
|
@@ -68,11 +70,18 @@ module Rigor
|
|
|
68
70
|
gem_paths_from(collection_root, data, skip_gem_names.to_set)
|
|
69
71
|
end
|
|
70
72
|
|
|
73
|
+
# The absolute path a configured `lockfile:` names, whether or not the file exists. The one place the
|
|
74
|
+
# setting is expanded (a leading `~/` is the home directory), shared by `resolve_lockfile_path` and
|
|
75
|
+
# by `WriteGuard`, which must watch the very path the run reads.
|
|
76
|
+
def self.configured_lockfile_path(lockfile_path, project_root = Dir.pwd)
|
|
77
|
+
Rigor::ConfigPath.absolute(lockfile_path.to_s, project_root)
|
|
78
|
+
end
|
|
79
|
+
|
|
71
80
|
# Returns the resolved lockfile path (`Pathname`) or `nil` when neither explicit nor auto-detect
|
|
72
81
|
# produces one. Public so the stats banner can surface what rigor found.
|
|
73
82
|
def self.resolve_lockfile_path(lockfile_path:, project_root: Dir.pwd, auto_detect: true)
|
|
74
83
|
if lockfile_path
|
|
75
|
-
path = Pathname.new(
|
|
84
|
+
path = Pathname.new(configured_lockfile_path(lockfile_path, project_root))
|
|
76
85
|
return path if path.file?
|
|
77
86
|
|
|
78
87
|
return nil
|
|
@@ -32,7 +32,7 @@ module Rigor
|
|
|
32
32
|
# hard-coding is acceptable; a directory walk at every call would add stat-cost to no benefit.)
|
|
33
33
|
VENDORED_GEM_NAMES = Set[
|
|
34
34
|
"ast", "bcrypt", "bundler", "cgi", "did_you_mean",
|
|
35
|
-
"idn-ruby", "mysql2", "nokogiri", "pg", "prism", "racc", "redis", "rubygems"
|
|
35
|
+
"idn-ruby", "mysql2", "nokogiri", "pg", "prime", "prism", "racc", "redis", "rubygems"
|
|
36
36
|
].freeze
|
|
37
37
|
|
|
38
38
|
# @param locked_gems — The lockfile-resolved gem set. Empty
|