rigortype 0.1.17 → 0.1.19

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.
Files changed (125) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +159 -222
  3. data/lib/rigor/analysis/check_rules/always_truthy_condition_collector.rb +24 -1
  4. data/lib/rigor/analysis/check_rules/dead_assignment_collector.rb +25 -0
  5. data/lib/rigor/analysis/check_rules/ivar_write_collector.rb +29 -0
  6. data/lib/rigor/analysis/check_rules/main_pass_collector.rb +54 -0
  7. data/lib/rigor/analysis/check_rules/rule_walk.rb +213 -0
  8. data/lib/rigor/analysis/check_rules/unreachable_clause_collector.rb +24 -1
  9. data/lib/rigor/analysis/check_rules.rb +275 -44
  10. data/lib/rigor/analysis/diagnostic.rb +8 -0
  11. data/lib/rigor/analysis/runner/diagnostic_aggregator.rb +581 -0
  12. data/lib/rigor/analysis/runner/pool_coordinator.rb +569 -0
  13. data/lib/rigor/analysis/runner/project_pre_passes.rb +321 -0
  14. data/lib/rigor/analysis/runner/run_snapshots.rb +46 -0
  15. data/lib/rigor/analysis/runner.rb +207 -1200
  16. data/lib/rigor/analysis/worker_session.rb +60 -11
  17. data/lib/rigor/bleeding_edge.rb +123 -0
  18. data/lib/rigor/cache/descriptor.rb +86 -8
  19. data/lib/rigor/cache/incremental_snapshot.rb +10 -4
  20. data/lib/rigor/cache/rbs_cache_producer.rb +5 -1
  21. data/lib/rigor/cache/rbs_descriptor.rb +2 -1
  22. data/lib/rigor/cache/store.rb +46 -13
  23. data/lib/rigor/cli/annotate_command.rb +100 -15
  24. data/lib/rigor/cli/check_command.rb +708 -0
  25. data/lib/rigor/cli/ci_detector.rb +94 -0
  26. data/lib/rigor/cli/diagnostic_formats.rb +345 -0
  27. data/lib/rigor/cli/plugins_command.rb +2 -4
  28. data/lib/rigor/cli/plugins_renderer.rb +0 -2
  29. data/lib/rigor/cli/prism_colorizer.rb +10 -3
  30. data/lib/rigor/cli/show_bleedingedge_command.rb +114 -0
  31. data/lib/rigor/cli/trace_command.rb +143 -0
  32. data/lib/rigor/cli/trace_renderer.rb +310 -0
  33. data/lib/rigor/cli/triage_command.rb +6 -3
  34. data/lib/rigor/cli/triage_renderer.rb +15 -1
  35. data/lib/rigor/cli.rb +21 -612
  36. data/lib/rigor/configuration/severity_profile.rb +13 -1
  37. data/lib/rigor/configuration.rb +66 -7
  38. data/lib/rigor/environment/rbs_loader.rb +78 -68
  39. data/lib/rigor/environment.rb +1 -1
  40. data/lib/rigor/inference/acceptance.rb +10 -0
  41. data/lib/rigor/inference/body_fixpoint.rb +89 -0
  42. data/lib/rigor/inference/budget_trace.rb +29 -2
  43. data/lib/rigor/inference/expression_typer.rb +1080 -105
  44. data/lib/rigor/inference/flow_tracer.rb +180 -0
  45. data/lib/rigor/inference/macro_block_self_type.rb +11 -12
  46. data/lib/rigor/inference/method_dispatcher/array_to_h_folding.rb +60 -0
  47. data/lib/rigor/inference/method_dispatcher/constant_folding.rb +54 -14
  48. data/lib/rigor/inference/method_dispatcher/overload_selector.rb +33 -1
  49. data/lib/rigor/inference/method_dispatcher/reduce_folding.rb +281 -0
  50. data/lib/rigor/inference/method_dispatcher/regexp_folding.rb +71 -0
  51. data/lib/rigor/inference/method_dispatcher/shape_dispatch.rb +148 -10
  52. data/lib/rigor/inference/method_dispatcher.rb +187 -55
  53. data/lib/rigor/inference/method_parameter_binder.rb +56 -2
  54. data/lib/rigor/inference/multi_target_binder.rb +46 -3
  55. data/lib/rigor/inference/mutation_widening.rb +142 -0
  56. data/lib/rigor/inference/narrowing.rb +330 -37
  57. data/lib/rigor/inference/scope_indexer.rb +770 -39
  58. data/lib/rigor/inference/statement_evaluator.rb +998 -68
  59. data/lib/rigor/inference/synthetic_method_scanner.rb +1 -1
  60. data/lib/rigor/plugin/additional_initializer.rb +61 -38
  61. data/lib/rigor/plugin/base.rb +517 -120
  62. data/lib/rigor/plugin/macro/block_as_method.rb +22 -21
  63. data/lib/rigor/plugin/macro/nested_class_template.rb +9 -7
  64. data/lib/rigor/plugin/macro.rb +2 -3
  65. data/lib/rigor/plugin/manifest.rb +4 -24
  66. data/lib/rigor/plugin/node_rule_walk.rb +192 -0
  67. data/lib/rigor/plugin/registry.rb +264 -35
  68. data/lib/rigor/plugin.rb +1 -0
  69. data/lib/rigor/rbs_extended/conformance_checker.rb +86 -1
  70. data/lib/rigor/scope/discovery_index.rb +60 -0
  71. data/lib/rigor/scope.rb +199 -204
  72. data/lib/rigor/sig_gen/generator.rb +8 -0
  73. data/lib/rigor/sig_gen/observation_collector.rb +6 -6
  74. data/lib/rigor/source/literals.rb +14 -0
  75. data/lib/rigor/triage/catalogue.rb +4 -19
  76. data/lib/rigor/triage.rb +69 -1
  77. data/lib/rigor/type/combinator.rb +34 -0
  78. data/lib/rigor/version.rb +1 -1
  79. data/lib/rigor.rb +0 -1
  80. data/plugins/rigor-actioncable/lib/rigor/plugin/actioncable.rb +13 -29
  81. data/plugins/rigor-actionmailer/lib/rigor/plugin/actionmailer.rb +13 -32
  82. data/plugins/rigor-actionpack/lib/rigor/plugin/actionpack/analyzer.rb +1 -2
  83. data/plugins/rigor-actionpack/lib/rigor/plugin/actionpack.rb +27 -90
  84. data/plugins/rigor-activejob/lib/rigor/plugin/activejob.rb +13 -30
  85. data/plugins/rigor-activerecord/lib/rigor/plugin/activerecord/model_discoverer.rb +2 -4
  86. data/plugins/rigor-activerecord/lib/rigor/plugin/activerecord.rb +90 -51
  87. data/plugins/rigor-activestorage/lib/rigor/plugin/activestorage/analyzer.rb +3 -3
  88. data/plugins/rigor-activestorage/lib/rigor/plugin/activestorage.rb +25 -29
  89. data/plugins/rigor-activesupport-core-ext/lib/rigor/plugin/activesupport_core_ext.rb +1 -1
  90. data/plugins/rigor-factorybot/lib/rigor/plugin/factorybot/factory_discoverer.rb +1 -2
  91. data/plugins/rigor-factorybot/lib/rigor/plugin/factorybot.rb +11 -40
  92. data/plugins/rigor-graphql/lib/rigor/plugin/graphql/type_scanner.rb +2 -2
  93. data/plugins/rigor-mangrove/lib/rigor/plugin/mangrove.rb +1 -1
  94. data/plugins/rigor-pundit/lib/rigor/plugin/pundit.rb +10 -21
  95. data/plugins/rigor-rails-i18n/lib/rigor/plugin/rails_i18n.rb +21 -34
  96. data/plugins/rigor-rails-routes/lib/rigor/plugin/rails_routes.rb +11 -18
  97. data/plugins/rigor-rbs-inline/lib/rigor/plugin/rbs_inline.rb +0 -1
  98. data/plugins/rigor-rspec/lib/rigor/plugin/rspec/let_scope_index.rb +12 -2
  99. data/plugins/rigor-rspec/lib/rigor/plugin/rspec/matcher_analyzer.rb +1 -1
  100. data/plugins/rigor-rspec/lib/rigor/plugin/rspec.rb +37 -31
  101. data/plugins/rigor-shoulda-matchers/lib/rigor/plugin/shoulda_matchers.rb +3 -23
  102. data/plugins/rigor-sidekiq/lib/rigor/plugin/sidekiq.rb +8 -21
  103. data/plugins/rigor-sinatra/lib/rigor/plugin/sinatra.rb +1 -1
  104. data/plugins/rigor-sorbet/lib/rigor/plugin/sorbet/absurd_recognizer.rb +8 -29
  105. data/plugins/rigor-sorbet/lib/rigor/plugin/sorbet/catalog.rb +17 -1
  106. data/plugins/rigor-sorbet/lib/rigor/plugin/sorbet/sigil_detector.rb +2 -2
  107. data/plugins/rigor-sorbet/lib/rigor/plugin/sorbet.rb +108 -36
  108. data/sig/rigor/analysis/fact_store.rbs +3 -0
  109. data/sig/rigor/environment.rbs +0 -2
  110. data/sig/rigor/inference/builtins/method_catalog.rbs +1 -1
  111. data/sig/rigor/inference.rbs +5 -0
  112. data/sig/rigor/plugin/base.rbs +6 -4
  113. data/sig/rigor/plugin/manifest.rbs +1 -2
  114. data/sig/rigor/scope.rbs +50 -29
  115. data/sig/rigor/source.rbs +1 -0
  116. data/sig/rigor/type.rbs +1 -0
  117. data/sig/rigor.rbs +1 -1
  118. data/skills/rigor-baseline-reduce/references/01-classify.md +27 -0
  119. data/skills/rigor-ci-setup/SKILL.md +319 -0
  120. data/skills/rigor-plugin-author/SKILL.md +6 -4
  121. data/skills/rigor-plugin-author/references/02-walker-and-types.md +22 -17
  122. data/skills/rigor-project-init/references/03-baseline-and-bugs.md +18 -1
  123. metadata +21 -3
  124. data/lib/rigor/cache/rbs_instance_definitions.rb +0 -66
  125. data/lib/rigor/plugin/macro/external_file.rb +0 -143
@@ -39,8 +39,8 @@ module Rigor
39
39
  # access by walking every configured `paths:` entry's `.rb`
40
40
  # files plus every `rbi_paths:` entry's `.rbi` files (slice
41
41
  # 4) via the plugin's `IoBoundary`. The catalog is frozen
42
- # after the first build and consulted by
43
- # `#flow_contribution_for` at every call site. RBI files
42
+ # after the first build and consulted by the `dynamic_return`
43
+ # rule at every gated call site. RBI files
44
44
  # share the catalog with project-source sigs — both produce
45
45
  # `MethodSignature` entries keyed by
46
46
  # `(class_name, method_name, kind)`. When a key collides
@@ -101,7 +101,7 @@ module Rigor
101
101
  @enforce_sigil = config.fetch("enforce_sigil")
102
102
  # ADR-11 deferred follow-up — per-call-site assertion
103
103
  # gating. Catalog harvest's `@sigil_by_path` cache is
104
- # consulted at every `flow_contribution_for` call so
104
+ # consulted at every per-call recognition so
105
105
  # `T.let` / `T.cast` / `T.must` / `T.bind` /
106
106
  # `T.assert_type!` only fire in files Sorbet itself
107
107
  # would enforce (`# typed: true` / `:strict` /
@@ -118,7 +118,7 @@ module Rigor
118
118
  @parse_errors_by_path = {}
119
119
  @catalog_built = false
120
120
  # ADR-11 slice 6 — Prism nodes for `T.absurd` calls
121
- # we observed in `flow_contribution_for` to be
121
+ # we observed in the `dynamic_return` rule to be
122
122
  # *reachable* (i.e., their discriminant didn't narrow
123
123
  # to `bot`). `diagnostics_for_file` walks the per-file
124
124
  # AST and surfaces these as `plugin.sorbet.absurd-reachable`
@@ -128,7 +128,7 @@ module Rigor
128
128
  # plugin hooks.
129
129
  @reachable_absurd_nodes = {}.compare_by_identity
130
130
  # ADR-11 light follow-up — `T.reveal_type` calls
131
- # observed in `flow_contribution_for`, paired with the
131
+ # observed in the `dynamic_return` rule, paired with the
132
132
  # display string for the inferred type at the call site.
133
133
  # Mirrors the absurd-node compare-by-identity hash;
134
134
  # `diagnostics_for_file` surfaces each entry as a
@@ -136,7 +136,7 @@ module Rigor
136
136
  @reveal_type_calls = {}.compare_by_identity
137
137
  # T.bind / T.assert_type! priority slice 1 —
138
138
  # `T.assert_type!` calls observed in
139
- # `flow_contribution_for` whose static subtype check
139
+ # the `dynamic_return` rule whose static subtype check
140
140
  # FAILED, paired with the inferred + asserted type
141
141
  # display strings. Same compare-by-identity discipline.
142
142
  # `diagnostics_for_file` walks the file AST for
@@ -160,9 +160,52 @@ module Rigor
160
160
  diagnostics
161
161
  end
162
162
 
163
- # ADR-11 slice 1 — return-type contribution from the
164
- # parsed `sig { ... }` block. Resolves the receiver in two
165
- # passes:
163
+ # ADR-52 slice 4the per-call return-type path, migrated off
164
+ # the legacy `flow_contribution_for` hook onto the
165
+ # method-name-gated `dynamic_return` DSL. The recognised name
166
+ # set is only known at run time (the catalog's `def` names come
167
+ # from the lazy catalog build), so it is declared as a
168
+ # callable: the engine `instance_exec`s it once per run on
169
+ # first dispatch (always after `#prepare`) and memoises the
170
+ # resolved Symbol Set. The gate is a safe over-approximation —
171
+ # a project method merely *named* `cast` or `find` passes it
172
+ # and is declined by the block's own `T.`-receiver / catalog
173
+ # checks, exactly as the ungated hook used to decline.
174
+ dynamic_return methods: -> { recognised_method_names } do |call_node, scope|
175
+ contribution_return_type(call_node, scope)
176
+ end
177
+
178
+ # ADR-52 slice 4 — `T.bind(self, T)`'s self-narrowing fact,
179
+ # migrated off the legacy hook's `post_return_facts` slot onto
180
+ # the method-gated `type_specifier` DSL (once
181
+ # `flow_contribution_for` is gone, the statement evaluator
182
+ # consults only this path for narrowing facts). The
183
+ # return-type half (`Constant[nil]`) flows through the
184
+ # `dynamic_return` rule above; the block re-checks the `T.`
185
+ # receiver via the recogniser, so an unrelated `bind` call
186
+ # contributes nothing.
187
+ type_specifier methods: [:bind] do |call_node, scope|
188
+ bind_post_return_facts(call_node, scope)
189
+ end
190
+
191
+ private
192
+
193
+ # ADR-52 slice 4 — the run-time method-name gate for the
194
+ # `dynamic_return` rule: the static assertion vocabulary
195
+ # (`T.let` / `T.cast` / …), `T.absurd`, and every method name
196
+ # the catalog carries a sig for.
197
+ def recognised_method_names
198
+ ensure_catalog
199
+ names = AssertionRecognizer::SORBET_ASSERTIONS.dup
200
+ names << :absurd
201
+ names.concat(@catalog.method_names)
202
+ names
203
+ end
204
+
205
+ # The migrated body of the legacy `flow_contribution_for` —
206
+ # same recognition order, but returns the bare `Rigor::Type`
207
+ # the `dynamic_return` contract expects. Resolves the receiver
208
+ # in two passes:
166
209
  #
167
210
  # 1. Constant receiver (`User.find(...)`) → singleton-side
168
211
  # catalog lookup.
@@ -173,18 +216,22 @@ module Rigor
173
216
  # Implicit-self calls (no receiver, current-class method)
174
217
  # are deferred to slice 2 — slice 1 covers the common case
175
218
  # where the sig is on the called method's own class.
176
- def flow_contribution_for(call_node:, scope:)
219
+ def contribution_return_type(call_node, scope)
177
220
  return nil unless call_node.is_a?(Prism::CallNode)
178
221
 
179
222
  # ADR-11 slice 6 — `T.absurd(x)` exhaustiveness. Always
180
- # contributes a `bot` return + raise effect (matches
181
- # Sorbet's runtime behaviour); when the discriminant
182
- # *isn't* narrowed to `bot` at this scope, also records
183
- # the call node so `diagnostics_for_file` can surface a
184
- # `plugin.sorbet.absurd-reachable` warning.
223
+ # contributes a `bot` return (matches Sorbet's runtime
224
+ # behaviour: `T.absurd` raises, so its value type is `bot`
225
+ # and the engine's flow analysis treats code after it as
226
+ # unreachable; the legacy contribution's `exceptional:
227
+ # :raises` slot was never consumed on the dispatcher path —
228
+ # only `return_type` survives the merge). When the
229
+ # discriminant *isn't* narrowed to `bot` at this scope, also
230
+ # records the call node so `diagnostics_for_file` can surface
231
+ # a `plugin.sorbet.absurd-reachable` warning.
185
232
  if AbsurdRecognizer.absurd_call?(call_node)
186
233
  @reachable_absurd_nodes[call_node] = true unless AbsurdRecognizer.exhaustive?(call_node, scope)
187
- return AbsurdRecognizer.contribution(call_node, manifest.id)
234
+ return Rigor::Type::Combinator.bot
188
235
  end
189
236
 
190
237
  # ADR-11 slice 2 — `T.let` / `T.cast` / `T.must` /
@@ -214,31 +261,31 @@ module Rigor
214
261
  if assertion
215
262
  record_reveal_type_call(call_node, assertion.return_type) if call_node.name == :reveal_type
216
263
  record_assert_type_check(call_node, scope) if call_node.name == :assert_type!
217
- return assertion
264
+ return assertion.return_type
218
265
  end
219
266
  end
220
267
 
221
268
  return nil if @catalog.nil? || @catalog.empty?
222
269
 
223
- signature = lookup_signature(call_node, scope)
224
- return nil if signature.nil?
270
+ lookup_signature(call_node, scope)&.return_type
271
+ end
272
+
273
+ # The `type_specifier` body for `T.bind` — same sigil gate as
274
+ # the return-type path, then the recogniser's
275
+ # `post_return_facts` (the `Fact(target_kind: :self)` that
276
+ # narrows `scope.self_type` for the rest of the block).
277
+ def bind_post_return_facts(call_node, scope)
278
+ return nil unless call_node.is_a?(Prism::CallNode)
225
279
 
226
- return_type = signature.return_type
227
- return nil if return_type.nil?
280
+ ensure_catalog
281
+ return nil unless assertion_enforced_here?(scope)
228
282
 
229
- Rigor::FlowContribution.new(
230
- return_type: return_type,
231
- provenance: Rigor::FlowContribution::Provenance.new(
232
- source_family: "plugin.#{manifest.id}",
233
- plugin_id: manifest.id,
234
- node: call_node,
235
- descriptor: nil
236
- )
283
+ contribution = AssertionRecognizer.recognize(
284
+ call_node: call_node, scope: scope, plugin_id: manifest.id
237
285
  )
286
+ contribution&.post_return_facts
238
287
  end
239
288
 
240
- private
241
-
242
289
  # ADR-11 deferred follow-up — per-call-site assertion
243
290
  # gating. With `enforce_sigil: false`, the gate is fully
244
291
  # open (matches the pre-feature behaviour). With
@@ -282,9 +329,34 @@ module Rigor
282
329
  chain_lookup(singleton_target, method_name, anchor_kind: :singleton, mixin_kind: :extend)
283
330
  elsif receiver
284
331
  instance_chain_lookup(receiver, method_name, scope)
332
+ else
333
+ implicit_self_lookup(method_name, scope)
285
334
  end
286
335
  end
287
336
 
337
+ # ADR-11 slice 2 (deferred from slice 1) — implicit-self calls.
338
+ # A receiver-less call inside a method body resolves against the
339
+ # engine's own `scope.self_type`: `Nominal[Foo]` inside an
340
+ # instance method (instance-side lookup), `Singleton[Foo]` inside
341
+ # a `def self.x` body (singleton-side lookup, `extend` mixins).
342
+ # Without this, an enforced sig on a sibling method was invisible
343
+ # to in-class calls — the engine's body-inference tiers then
344
+ # re-typed the sibling's body, overriding an explicit
345
+ # `T.untyped` opt-out (the dispatcher's plugin tier had already
346
+ # run and declined). Anything else (toplevel / Dynamic / DSL
347
+ # self) contributes nothing and the dispatcher continues.
348
+ def implicit_self_lookup(method_name, scope)
349
+ self_type = scope&.self_type
350
+ case self_type
351
+ when Rigor::Type::Singleton
352
+ chain_lookup(self_type.class_name, method_name, anchor_kind: :singleton, mixin_kind: :extend)
353
+ when Rigor::Type::Nominal
354
+ chain_lookup(self_type.class_name, method_name, anchor_kind: :instance, mixin_kind: :include)
355
+ end
356
+ rescue StandardError
357
+ nil
358
+ end
359
+
288
360
  def instance_chain_lookup(receiver_node, method_name, scope)
289
361
  return nil if scope.nil?
290
362
 
@@ -441,7 +513,7 @@ module Rigor
441
513
  # magic comment by skipping the file entirely.
442
514
  level = SigilDetector.detect(contents)
443
515
  # Per-call-site assertion gating consults this map at
444
- # `flow_contribution_for`. Recorded BEFORE the ignored
516
+ # recognition time. Recorded BEFORE the ignored
445
517
  # short-circuit so a `# typed: ignore` file still
446
518
  # reports its level to the gate (the gate then chooses
447
519
  # to suppress assertions there too — `ignore` is
@@ -481,7 +553,7 @@ module Rigor
481
553
  # nodes and emits a `plugin.sorbet.absurd-reachable`
482
554
  # warning for any whose object identity matches
483
555
  # `@reachable_absurd_nodes` (populated during the engine's
484
- # earlier pass through `flow_contribution_for`). Pops
556
+ # earlier pass through the `dynamic_return` rule). Pops
485
557
  # matched entries so a duplicate run doesn't double-emit.
486
558
  def absurd_reachable_diagnostics(path, root)
487
559
  return [] if @reachable_absurd_nodes.empty?
@@ -569,8 +641,8 @@ module Rigor
569
641
  # static subtype check at recogniser time and records the
570
642
  # call only when the inferred type is *provably
571
643
  # incompatible* with the asserted type. Gradual
572
- # consistency rules (`Inference::Acceptance.accepts(...)`
573
- # mode `:gradual`): a `Dynamic[top]` inferred type
644
+ # consistency rules (`Type#accepts` mode `:gradual`): a
645
+ # `Dynamic[top]` inferred type
574
646
  # silences the check; a definite `:no` records for
575
647
  # diagnostic emission; `:maybe` (uncertain) is treated as
576
648
  # "trust the user" and silenced — the runtime check is
@@ -582,7 +654,7 @@ module Rigor
582
654
  inferred, asserted = check
583
655
  return if inferred.nil?
584
656
 
585
- result = Rigor::Inference::Acceptance.accepts(asserted, inferred)
657
+ result = asserted.accepts(inferred)
586
658
  return unless result.no?
587
659
 
588
660
  @assert_type_mismatches[call_node] = [display_for_type(inferred), display_for_type(asserted)]
@@ -2,6 +2,9 @@ module Rigor
2
2
  module Analysis
3
3
  module CheckRules
4
4
  def self?.diagnose: (path: String, root: untyped, scope_index: Hash[untyped, Scope]) -> Array[Diagnostic]
5
+ def self?.build_node_collectors: (String path, untyped scope_index) -> Hash[Symbol, untyped]
6
+ def self?.node_collector_driver: (Hash[Symbol, untyped] collectors) -> untyped
7
+ def self?.shadow_verify_converged_collectors: (String path, untyped root, untyped scope_index, Hash[Symbol, untyped]? collectors) -> void
5
8
  end
6
9
 
7
10
  class FactStore
@@ -58,10 +58,8 @@ module Rigor
58
58
  def rbs_module?: (String | Symbol name) -> bool
59
59
  def instance_definition: (String | Symbol class_name) -> untyped?
60
60
  def instance_method: (class_name: String | Symbol, method_name: String | Symbol) -> untyped?
61
- def uncached_instance_definition: (String | Symbol class_name) -> untyped?
62
61
  def singleton_definition: (String | Symbol class_name) -> untyped?
63
62
  def singleton_method: (class_name: String | Symbol, method_name: String | Symbol) -> untyped?
64
- def uncached_singleton_definition: (String | Symbol class_name) -> untyped?
65
63
  def class_type_param_names: (String | Symbol class_name) -> Array[Symbol]
66
64
  def class_ordering: (String | Symbol lhs, String | Symbol rhs) -> ordering
67
65
  def constant_type: (String name) -> Type::t?
@@ -1,4 +1,4 @@
1
1
  class Rigor::Inference::Builtins::MethodCatalog
2
2
  def initialize: (path: String, ?mutating_selectors: Hash[String, Set[untyped]]) -> void
3
- def reset!: () -> nil
3
+ def reset!: () -> Hash[String, untyped]
4
4
  end
@@ -109,6 +109,9 @@ module Rigor
109
109
  def self?.narrow_not_class: (Type::t type, String class_name, ?exact: bool, ?environment: Environment) -> Type::t
110
110
  def self?.narrow_not_refinement: (Type::t current_type, Type::t refinement_type) -> Type::t
111
111
  def self?.narrow_for_fact: (Type::t current, untyped fact, untyped environment) -> Type::t
112
+ def self?.predicate_certainty: (Type::t? type) -> (:truthy | :falsey | nil)
113
+ def self?.class_pattern_certainty: (Type::t subject_type, String class_name, environment: Environment) -> (:yes | :no | :maybe)
114
+ def self?.value_pattern_certainty: (Type::t subject_type, untyped pattern_value) -> (:yes | :no | :maybe)
112
115
  def self?.predicate_scopes: (untyped node, Scope scope) -> [Scope, Scope]
113
116
  def self?.case_when_scopes: (untyped subject, Array[untyped] conditions, Scope scope) -> [Scope, Scope]
114
117
  def self?.analyse: (untyped node, Scope scope) -> untyped
@@ -117,6 +120,8 @@ module Rigor
117
120
  def self?.trusted_equality_literal?: (untyped literal) -> bool
118
121
  def self?.falsey_value?: (untyped value) -> bool
119
122
  def self?.falsey_nominal?: (Type::Nominal nominal) -> bool
123
+
124
+ VALUE_EQUALITY_CLASSES: Array[Class]
120
125
  end
121
126
 
122
127
  module ClosureEscapeAnalyzer
@@ -14,7 +14,7 @@ class Rigor::Plugin::Base
14
14
  # the no-arg `manifest` reads the cached value back.
15
15
  def self.manifest: (**untyped fields) -> Rigor::Plugin::Manifest
16
16
 
17
- def self.producer: (untyped id, ?serialize: untyped, ?deserialize: untyped) { (untyped params) -> untyped } -> Symbol
17
+ def self.producer: (untyped id, ?watch: untyped, ?serialize: untyped, ?deserialize: untyped) { (untyped params) -> untyped } -> Symbol
18
18
  def self.producers: () -> Hash[Symbol, untyped]
19
19
 
20
20
  def self.node_rule: (untyped node_type) { (*untyped) -> untyped } -> untyped
@@ -23,7 +23,7 @@ class Rigor::Plugin::Base
23
23
  def self.node_file_context: () { (untyped root, untyped scope) -> untyped } -> untyped
24
24
  def self.node_file_context_block: () -> untyped
25
25
 
26
- def self.dynamic_return: (receivers: Array[String]) { (untyped call_node, untyped scope) -> untyped } -> nil
26
+ def self.dynamic_return: (?receivers: (Array[String] | ^() -> Array[String])?, ?methods: (Array[untyped] | ^() -> Array[untyped])?) { (untyped call_node, untyped scope) -> untyped } -> nil
27
27
  def self.dynamic_returns: () -> Array[untyped]
28
28
 
29
29
  def self.type_specifier: (methods: Array[untyped]) { (untyped call_node, untyped scope) -> untyped } -> nil
@@ -41,7 +41,6 @@ class Rigor::Plugin::Base
41
41
  # Overridable lifecycle / extension hooks (default no-ops).
42
42
  def init: (untyped services) -> nil
43
43
  def prepare: (untyped services) -> nil
44
- def flow_contribution_for: (call_node: untyped, scope: untyped) -> untyped
45
44
  def diagnostics_for_file: (path: untyped, scope: untyped, root: untyped) -> Array[untyped]
46
45
 
47
46
  # Engine-executed dispatch over the declared DSLs.
@@ -51,11 +50,14 @@ class Rigor::Plugin::Base
51
50
 
52
51
  # Authoring helpers.
53
52
  def diagnostic: (untyped node, path: untyped, message: untyped, ?severity: untyped, ?rule: untyped, ?location: untyped) -> untyped
53
+ def diagnostics_for: (untyped violations, path: untyped, ?node: untyped) -> Array[untyped]
54
+ def read_fact: (plugin_id: untyped, name: untyped) -> untyped
55
+ def producer_value: (untyped id, ?params: untyped) -> untyped
56
+ def producer_error: (untyped id) -> untyped
54
57
  def manifest: () -> Rigor::Plugin::Manifest
55
58
  def signature_paths: () -> Array[String]
56
59
  def protocol_contracts: () -> untyped
57
60
  def io_boundary: () -> Rigor::Plugin::IoBoundary
58
61
  def cache_for: (untyped producer_id, ?params: untyped, ?descriptor: untyped) -> untyped
59
- def glob_descriptor: (untyped roots, *untyped patterns) -> untyped
60
62
  def plugin_entry: () -> untyped
61
63
  end
@@ -3,7 +3,7 @@ class Rigor::Plugin::Manifest::Consumption
3
3
  end
4
4
 
5
5
  class Rigor::Plugin::Manifest
6
- def initialize: (id: untyped, version: untyped, ?description: untyped, ?config_schema: untyped, ?produces: untyped, ?consumes: untyped, ?owns_receivers: untyped, ?open_receivers: untyped, ?type_node_resolvers: untyped, ?block_as_methods: untyped, ?heredoc_templates: untyped, ?nested_class_templates: untyped, ?trait_registries: untyped, ?external_files: untyped, ?hkt_registrations: untyped, ?hkt_definitions: untyped, ?signature_paths: untyped, ?protocol_contracts: untyped, ?source_rbs_synthesizer: untyped, ?additional_initializers: untyped) -> void
6
+ def initialize: (id: untyped, version: untyped, ?description: untyped, ?config_schema: untyped, ?produces: untyped, ?consumes: untyped, ?owns_receivers: untyped, ?open_receivers: untyped, ?type_node_resolvers: untyped, ?block_as_methods: untyped, ?heredoc_templates: untyped, ?nested_class_templates: untyped, ?trait_registries: untyped, ?hkt_registrations: untyped, ?hkt_definitions: untyped, ?signature_paths: untyped, ?protocol_contracts: untyped, ?source_rbs_synthesizer: untyped, ?additional_initializers: untyped) -> void
7
7
 
8
8
  # Public attribute readers (the full `attr_reader` surface). Plugins
9
9
  # read `manifest.id` / `manifest.protocol_contracts` etc.; declaring
@@ -25,7 +25,6 @@ class Rigor::Plugin::Manifest
25
25
  def heredoc_templates: () -> untyped
26
26
  def nested_class_templates: () -> untyped
27
27
  def trait_registries: () -> untyped
28
- def external_files: () -> untyped
29
28
  def hkt_registrations: () -> untyped
30
29
  def hkt_definitions: () -> untyped
31
30
  def signature_paths: () -> untyped
data/sig/rigor/scope.rbs CHANGED
@@ -4,27 +4,54 @@ module Rigor
4
4
  attr_reader locals: Hash[Symbol, Type::t]
5
5
  attr_reader fact_store: Analysis::FactStore
6
6
  attr_reader self_type: Type::t?
7
- attr_reader declared_types: Hash[untyped, Type::t]
8
7
  attr_reader ivars: Hash[Symbol, Type::t]
9
8
  attr_reader cvars: Hash[Symbol, Type::t]
10
9
  attr_reader globals: Hash[Symbol, Type::t]
11
- attr_reader class_ivars: Hash[String, Hash[Symbol, Type::t]]
12
- attr_reader class_cvars: Hash[String, Hash[Symbol, Type::t]]
13
- attr_reader program_globals: Hash[Symbol, Type::t]
14
- attr_reader discovered_classes: Hash[String, Type::Singleton]
15
- attr_reader in_source_constants: Hash[String, Type::t]
16
- attr_reader discovered_methods: Hash[String, Hash[Symbol, Symbol]]
17
- attr_reader discovered_def_nodes: Hash[String, Hash[Symbol, untyped]]
18
- attr_reader discovered_def_sources: Hash[String, Hash[Symbol, String]]
19
- attr_reader discovered_method_visibilities: Hash[String, Hash[Symbol, Symbol]]
20
- attr_reader discovered_superclasses: Hash[String, String]
21
- attr_reader discovered_includes: Hash[String, Array[String]]
22
- attr_reader discovered_class_sources: Hash[String, Set[String]]
23
- attr_reader data_member_layouts: Hash[String, Array[Symbol]]
10
+ attr_reader discovery: DiscoveryIndex
24
11
  attr_reader indexed_narrowings: Hash[IndexedKey, Type::t]
25
12
  attr_reader method_chain_narrowings: Hash[ChainKey, Type::t]
26
13
  attr_reader source_path: String?
27
14
 
15
+ # ADR-53 Track A — the seed-time discovery tables live on the
16
+ # DiscoveryIndex; Scope keeps per-table readers as delegates.
17
+ def declared_types: () -> Hash[untyped, Type::t]
18
+ def class_ivars: () -> Hash[String, Hash[Symbol, Type::t]]
19
+ def class_cvars: () -> Hash[String, Hash[Symbol, Type::t]]
20
+ def program_globals: () -> Hash[Symbol, Type::t]
21
+ def discovered_classes: () -> Hash[String, Type::Singleton]
22
+ def in_source_constants: () -> Hash[String, Type::t]
23
+ def discovered_methods: () -> Hash[String, Hash[Symbol, Symbol]]
24
+ def discovered_def_nodes: () -> Hash[String, Hash[Symbol, untyped]]
25
+ def discovered_singleton_def_nodes: () -> Hash[String, Hash[Symbol, untyped]]
26
+ def discovered_def_sources: () -> Hash[String, Hash[Symbol, String]]
27
+ def discovered_method_visibilities: () -> Hash[String, Hash[Symbol, Symbol]]
28
+ def discovered_superclasses: () -> Hash[String, String]
29
+ def discovered_includes: () -> Hash[String, Array[String]]
30
+ def discovered_class_sources: () -> Hash[String, Set[String]]
31
+ def data_member_layouts: () -> Hash[String, Array[Symbol]]
32
+
33
+ class DiscoveryIndex
34
+ attr_reader declared_types: Hash[untyped, Type::t]
35
+ attr_reader class_ivars: Hash[String, Hash[Symbol, Type::t]]
36
+ attr_reader class_cvars: Hash[String, Hash[Symbol, Type::t]]
37
+ attr_reader program_globals: Hash[Symbol, Type::t]
38
+ attr_reader discovered_classes: Hash[String, Type::Singleton]
39
+ attr_reader in_source_constants: Hash[String, Type::t]
40
+ attr_reader discovered_methods: Hash[String, Hash[Symbol, Symbol]]
41
+ attr_reader discovered_def_nodes: Hash[String, Hash[Symbol, untyped]]
42
+ attr_reader discovered_singleton_def_nodes: Hash[String, Hash[Symbol, untyped]]
43
+ attr_reader discovered_def_sources: Hash[String, Hash[Symbol, String]]
44
+ attr_reader discovered_method_visibilities: Hash[String, Hash[Symbol, Symbol]]
45
+ attr_reader discovered_superclasses: Hash[String, String]
46
+ attr_reader discovered_includes: Hash[String, Array[String]]
47
+ attr_reader discovered_class_sources: Hash[String, Set[String]]
48
+ attr_reader data_member_layouts: Hash[String, Array[Symbol]]
49
+
50
+ EMPTY: DiscoveryIndex
51
+
52
+ def with: (?declared_types: Hash[untyped, Type::t], ?class_ivars: Hash[String, Hash[Symbol, Type::t]], ?class_cvars: Hash[String, Hash[Symbol, Type::t]], ?program_globals: Hash[Symbol, Type::t], ?discovered_classes: Hash[String, Type::Singleton], ?in_source_constants: Hash[String, Type::t], ?discovered_methods: Hash[String, Hash[Symbol, Symbol]], ?discovered_def_nodes: Hash[String, Hash[Symbol, untyped]], ?discovered_singleton_def_nodes: Hash[String, Hash[Symbol, untyped]], ?discovered_def_sources: Hash[String, Hash[Symbol, String]], ?discovered_method_visibilities: Hash[String, Hash[Symbol, Symbol]], ?discovered_superclasses: Hash[String, String], ?discovered_includes: Hash[String, Array[String]], ?discovered_class_sources: Hash[String, Set[String]], ?data_member_layouts: Hash[String, Array[Symbol]]) -> DiscoveryIndex
53
+ end
54
+
28
55
  class IndexedKey
29
56
  attr_reader receiver_kind: Symbol
30
57
  attr_reader receiver_name: Symbol
@@ -39,8 +66,9 @@ module Rigor
39
66
 
40
67
  def self.empty: (?environment: Environment, ?source_path: String?) -> Scope
41
68
 
42
- def initialize: (environment: Environment, locals: Hash[Symbol, Type::t], ?fact_store: Analysis::FactStore, ?self_type: Type::t?, ?declared_types: Hash[untyped, Type::t], ?ivars: Hash[Symbol, Type::t], ?cvars: Hash[Symbol, Type::t], ?globals: Hash[Symbol, Type::t], ?source_path: String?) -> void
69
+ def initialize: (environment: Environment, locals: Hash[Symbol, Type::t], ?fact_store: Analysis::FactStore, ?self_type: Type::t?, ?ivars: Hash[Symbol, Type::t], ?cvars: Hash[Symbol, Type::t], ?globals: Hash[Symbol, Type::t], ?discovery: DiscoveryIndex, ?source_path: String?) -> void
43
70
  def with_source_path: (String? path) -> Scope
71
+ def with_discovery: (DiscoveryIndex index) -> Scope
44
72
  def local: (String | Symbol name) -> Type::t?
45
73
  def ivar: (String | Symbol name) -> Type::t?
46
74
  def cvar: (String | Symbol name) -> Type::t?
@@ -49,30 +77,24 @@ module Rigor
49
77
  def with_ivar: (String | Symbol name, Type::t type) -> Scope
50
78
  def with_cvar: (String | Symbol name, Type::t type) -> Scope
51
79
  def with_global: (String | Symbol name, Type::t type) -> Scope
80
+ def declaration_sourced: () -> Set[[Symbol, Symbol]]
81
+ def seed_declaration_sourced_ivar: (String | Symbol name, Type::t type) -> Scope
82
+ def with_declaration_sourced_local: (String | Symbol name, Type::t type) -> Scope
83
+ def with_local_declaration_mark: (String | Symbol name) -> Scope
84
+ def declaration_sourced?: (Symbol kind, String | Symbol name) -> bool
85
+ def forget_match_globals: () -> Scope
52
86
  def class_ivars_for: (String | Symbol? class_name) -> Hash[Symbol, Type::t]
53
- def with_class_ivars: (Hash[String, Hash[Symbol, Type::t]] table) -> Scope
54
87
  def class_cvars_for: (String | Symbol? class_name) -> Hash[Symbol, Type::t]
55
- def with_class_cvars: (Hash[String, Hash[Symbol, Type::t]] table) -> Scope
56
- def with_program_globals: (Hash[Symbol, Type::t] table) -> Scope
57
- def with_discovered_classes: (Hash[String, Type::Singleton] table) -> Scope
58
- def with_in_source_constants: (Hash[String, Type::t] table) -> Scope
59
- def with_discovered_methods: (Hash[String, Hash[Symbol, Symbol]] table) -> Scope
60
88
  def discovered_method?: (String | Symbol class_name, String | Symbol method_name, Symbol kind) -> bool
61
- def with_discovered_def_nodes: (Hash[String, Hash[Symbol, untyped]] table) -> Scope
62
- def with_discovered_def_sources: (Hash[String, Hash[Symbol, String]] table) -> Scope
63
89
  def user_def_for: (String | Symbol class_name, String | Symbol method_name) -> untyped?
90
+ def singleton_def_for: (String | Symbol class_name, String | Symbol method_name) -> untyped?
64
91
  def user_def_site_for: (String | Symbol class_name, String | Symbol method_name) -> String?
65
92
  def top_level_def_for: (String | Symbol method_name) -> untyped?
66
93
  def toplevel?: () -> bool
67
- def with_discovered_method_visibilities: (Hash[String, Hash[Symbol, Symbol]] table) -> Scope
68
94
  def discovered_method_visibility: (String | Symbol class_name, String | Symbol method_name) -> Symbol?
69
95
  def superclass_of: (String | Symbol class_name) -> String?
70
- def with_discovered_superclasses: (Hash[String, String] table) -> Scope
71
96
  def data_member_layout: (String | Symbol class_name) -> Array[Symbol]?
72
- def with_data_member_layouts: (Hash[String, Array[Symbol]] table) -> Scope
73
97
  def includes_of: (String | Symbol class_name) -> Array[String]
74
- def with_discovered_includes: (Hash[String, Array[String]] table) -> Scope
75
- def with_discovered_class_sources: (Hash[String, Set[String]] table) -> Scope
76
98
  def indexed_narrowing: (Symbol receiver_kind, String | Symbol receiver_name, untyped key) -> Type::t?
77
99
  def with_indexed_narrowing: (Symbol receiver_kind, String | Symbol receiver_name, untyped key, Type::t type) -> Scope
78
100
  def without_indexed_narrowing: (Symbol receiver_kind, String | Symbol receiver_name, untyped key) -> Scope
@@ -83,7 +105,6 @@ module Rigor
83
105
  def without_method_chain_narrowings_for: (Symbol receiver_kind, String | Symbol receiver_name) -> Scope
84
106
  def with_fact: (Analysis::FactStore::Fact fact) -> Scope
85
107
  def with_self_type: (Type::t? type) -> Scope
86
- def with_declared_types: (Hash[untyped, Type::t] table) -> Scope
87
108
  def facts_for: (?target: Analysis::FactStore::Target?, ?bucket: Symbol?) -> Array[Analysis::FactStore::Fact]
88
109
  def local_facts: (String | Symbol name, ?bucket: Symbol?) -> Array[Analysis::FactStore::Fact]
89
110
  def type_of: (untyped node, ?tracer: Inference::FallbackTracer?) -> Type::t
data/sig/rigor/source.rbs CHANGED
@@ -16,6 +16,7 @@ module Rigor
16
16
  def self?.symbol_or_string_name: (untyped? node) -> String?
17
17
  def self?.symbol: (untyped? node) -> Symbol?
18
18
  def self?.symbol_name: (untyped? node) -> String?
19
+ def self?.symbol_named?: (untyped? node, String name) -> bool
19
20
  def self?.symbol_arguments: (untyped? call_node) -> Array[Symbol]
20
21
  def self?.symbol_arg: (untyped? call_node, Integer index) -> Symbol?
21
22
  end
data/sig/rigor/type.rbs CHANGED
@@ -342,6 +342,7 @@ module Rigor
342
342
  def self?.union: (*Type::t types) -> Type::t
343
343
  def self?.key_of: (Type::t type) -> Type::t
344
344
  def self?.value_of: (Type::t type) -> Type::t
345
+ def self?.widen_value_pinned: (Type::t type) -> Type::t
345
346
  def self?.int_mask: (Array[Integer] flags) -> Type::t?
346
347
  def self?.int_mask_of: (Type::t type) -> Type::t?
347
348
  def self?.indexed_access: (Type::t type, Type::t key) -> Type::t
data/sig/rigor.rbs CHANGED
@@ -11,7 +11,7 @@ module Rigor
11
11
  attr_reader cache_path: String
12
12
  attr_reader baseline_path: String?
13
13
 
14
- def self.load: (?String path) -> Configuration
14
+ def self.load: (?String? path) -> Configuration
15
15
  def self.discover: () -> String?
16
16
  def self.load_with_includes: (String path, ?visited: Set[String]) -> Hash[String, untyped]
17
17
  def initialize: (?Hash[String, untyped] data) -> void
@@ -28,6 +28,33 @@ signal — each hint has an `id`:
28
28
  | `project-monkey-patch` | A DSL / monkey-patch Rigor can't see. | Escalate — a `pre_eval:` entry or a plugin clears the whole cluster. |
29
29
  | `activerecord-relation-misinference` | Likely an engine gap. | Treat sites as candidate false positives (Phase 2). |
30
30
 
31
+ ### `rigor triage --format json` `.selectors` — the by-(class, method) axis
32
+
33
+ Beside `hints`, the triage JSON carries a `selectors` array: one row
34
+ per dispatch target the diagnostics cluster on, built from the
35
+ structured `receiver_type` / `method_name` fields (never message
36
+ parsing). Each row is `{receiver, method, count, files, rules}`. Use
37
+ it to pick *which sites within a rule* to sample first — and to tell a
38
+ systemic cause from a scatter of real bugs — with `jq`, not eyeballing
39
+ the stream:
40
+
41
+ ```sh
42
+ # the dispatch targets responsible for the most diagnostics
43
+ rigor triage --format json | jq -r '.selectors[:15][] | "\(.count)\t\(.files)f\t\(.receiver)#\(.method)"'
44
+ # one method, one receiver, spread across many files → systemic
45
+ # (a plugin / pre_eval clears it) rather than N independent bugs
46
+ rigor triage --format json | jq '.selectors[] | select(.files >= 4)'
47
+ # narrow to a rule you are about to work, ranked by concentration
48
+ rigor triage --format json \
49
+ | jq '[.selectors[] | select(.rules["call.possible-nil-receiver"])] | sort_by(-.count)'
50
+ ```
51
+
52
+ Read it as: **high `count` × high `files` = a systemic selector**
53
+ (escalate as a decision — one fix clears the cluster); **low `count` =
54
+ a candidate genuine bug** to sample directly in Phase 2. The `receiver`
55
+ is a normalised class (`"hi".squish` and `name.squish` both bucket
56
+ under `String#squish`), so a single idiom does not scatter across rows.
57
+
31
58
  ### `rigor baseline dump --format json` — the bucket list
32
59
 
33
60
  ```sh