rigortype 0.3.5 → 0.3.6
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 +5 -5
- data/data/gem_overlay/activesupport/core_ext.rbs +33 -0
- data/docs/handbook/02-everyday-types.md +1 -1
- data/docs/handbook/04-tuples-and-shapes.md +1 -1
- data/docs/handbook/08-understanding-errors.md +1 -1
- data/docs/handbook/09-plugins.md +2 -2
- data/docs/handbook/10-sorbet.md +1 -1
- data/docs/handbook/README.md +2 -2
- data/docs/handbook/appendix-go.md +1 -1
- data/docs/handbook/appendix-java-csharp.md +2 -2
- data/docs/handbook/appendix-mypy.md +1 -1
- data/docs/handbook/appendix-protocols-and-structural-typing.md +2 -2
- data/docs/handbook/appendix-rust.md +1 -1
- data/docs/handbook/appendix-type-theory.md +2 -2
- data/docs/handbook/appendix-typescript.md +4 -4
- data/docs/manual/02-cli-reference.md +13 -9
- data/docs/manual/03-configuration.md +1 -1
- data/docs/manual/04-diagnostics.md +12 -0
- data/docs/manual/08-skills.md +1 -1
- data/docs/manual/11-ci.md +1 -1
- data/docs/manual/12-caching.md +1 -1
- data/docs/manual/15-type-protection-coverage.md +1 -1
- data/docs/manual/18-removing-dead-code.md +13 -4
- data/docs/manual/19-effect-labels.md +19 -12
- data/docs/manual/README.md +2 -2
- data/docs/manual/plugins/rigor-actionmailer.md +4 -4
- data/docs/manual/plugins/rigor-activejob.md +3 -3
- data/docs/manual/plugins/rigor-activerecord.md +4 -4
- data/docs/manual/plugins/rigor-rails-i18n.md +5 -5
- data/docs/manual/plugins/rigor-rspec.md +6 -2
- data/lib/rigor/analysis/diagnostic.rb +17 -6
- data/lib/rigor/analysis/effects_cache_probe.rb +132 -0
- data/lib/rigor/analysis/reachability/graph.rb +30 -11
- data/lib/rigor/analysis/reachability/plugin_roots.rb +11 -8
- data/lib/rigor/analysis/reachability/scan.rb +20 -4
- data/lib/rigor/analysis/reachability/scan_cache.rb +130 -0
- data/lib/rigor/analysis/run_cache_key.rb +12 -0
- data/lib/rigor/analysis/runner/effect_envelope_pass.rb +14 -8
- data/lib/rigor/analysis/runner.rb +151 -28
- data/lib/rigor/cache/file_digest.rb +20 -2
- data/lib/rigor/cli/check_command.rb +67 -48
- data/lib/rigor/cli/coverage_command.rb +5 -6
- data/lib/rigor/cli/doc_links.rb +100 -0
- data/lib/rigor/cli/docs_command.rb +32 -2
- data/lib/rigor/cli/effects_command.rb +27 -2
- data/lib/rigor/cli/effects_diff_renderer.rb +82 -12
- data/lib/rigor/cli/effects_explain_renderer.rb +6 -3
- data/lib/rigor/cli/effects_snapshot_command.rb +52 -7
- data/lib/rigor/cli/unused_command.rb +65 -16
- data/lib/rigor/cli.rb +21 -8
- data/lib/rigor/effects/definition_lines.rb +100 -0
- data/lib/rigor/effects/envelope_check.rb +18 -1
- data/lib/rigor/effects/liskov_check.rb +17 -8
- data/lib/rigor/effects/signature_sources.rb +13 -2
- data/lib/rigor/effects/snapshot.rb +53 -21
- data/lib/rigor/effects/snapshot_diff.rb +26 -3
- data/lib/rigor/inference/synthetic_method_scanner.rb +7 -0
- data/lib/rigor/rbs_extended/envelope_scanner.rb +9 -0
- data/lib/rigor/version.rb +1 -1
- data/skills/rigor-ci-setup/SKILL.md +2 -2
- data/skills/rigor-editor-setup/SKILL.md +2 -2
- data/skills/rigor-mcp-setup/SKILL.md +2 -2
- data/skills/rigor-monkeypatch-resolve/SKILL.md +1 -1
- data/skills/rigor-plugin-review/SKILL.md +3 -3
- metadata +5 -1
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Rigor
|
|
4
|
+
class CLI
|
|
5
|
+
# Turns the documentation's own relative links into keys `rigor docs` can answer (#430).
|
|
6
|
+
#
|
|
7
|
+
# The manual and handbook link each other and the design corpus the way any prose does —
|
|
8
|
+
# `[ADR-103](../adr/103-effect-labels.md)`. Those links are correct in the repository and correct on
|
|
9
|
+
# GitHub, and they are the coupling between documents: they say which document explains what, and
|
|
10
|
+
# deleting them to leave a bare `ADR-103` would cost that and give nothing back.
|
|
11
|
+
#
|
|
12
|
+
# They are wrong in exactly one place: a reader looking at the file inside an installed gem, where
|
|
13
|
+
# `docs/adr/` was never packaged. Two earlier attempts fixed the file for that reader and made it
|
|
14
|
+
# worse for the others — rewriting every link to a `blob/master` URL hardcoded a host, an
|
|
15
|
+
# organisation and a branch in 297 places and sent a v0.3.5 reader to a document that had moved on;
|
|
16
|
+
# deleting the markup severed the coupling.
|
|
17
|
+
#
|
|
18
|
+
# So the source keeps its links and `rigor docs` rewrites them on the way out:
|
|
19
|
+
#
|
|
20
|
+
# [ADR-103](../adr/103-effect-labels.md) → [ADR-103][adr/103-effect-labels]
|
|
21
|
+
#
|
|
22
|
+
# The key is the repository path minus `docs/` and `.md`, which for a packaged page is exactly the
|
|
23
|
+
# name `rigor docs` already takes, so the reader can run what they are shown. For an unpackaged one
|
|
24
|
+
# the key still resolves — to a routed message naming the path and the repository, from the single
|
|
25
|
+
# constant below rather than from 297 rewritten links.
|
|
26
|
+
module DocLinks
|
|
27
|
+
REPOSITORY = "https://github.com/rigortype/rigor"
|
|
28
|
+
|
|
29
|
+
# `[label](target)` and `[label](target#anchor)`, skipping absolute URLs and bare anchors.
|
|
30
|
+
MARKDOWN_LINK = /\[([^\]]*)\]\((?!https?:|mailto:|#)([^)#\s]+)(#[^)\s]*)?\)/
|
|
31
|
+
private_constant :MARKDOWN_LINK
|
|
32
|
+
|
|
33
|
+
# Where the gem's `docs/` tree sits, so a rendered path can be made repository-relative.
|
|
34
|
+
GEM_ROOT = File.expand_path("../../..", __dir__)
|
|
35
|
+
private_constant :GEM_ROOT
|
|
36
|
+
|
|
37
|
+
module_function
|
|
38
|
+
|
|
39
|
+
# @param body [String] the page as it is stored.
|
|
40
|
+
# @param from [String] its absolute path, so relative targets resolve.
|
|
41
|
+
# @return [String] the page with every relative link turned into a `rigor docs` key.
|
|
42
|
+
def rewrite(body, from:)
|
|
43
|
+
dir = File.dirname(from)
|
|
44
|
+
body.gsub(MARKDOWN_LINK) do
|
|
45
|
+
label = Regexp.last_match(1)
|
|
46
|
+
target = Regexp.last_match(2)
|
|
47
|
+
anchor = Regexp.last_match(3)
|
|
48
|
+
key = key_for(target, dir)
|
|
49
|
+
key.nil? ? "[#{label}](#{target}#{anchor})" : "[#{label}][#{key}#{anchor}]"
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
# Splits a key into its page and its section, for a reader who pasted one back.
|
|
54
|
+
def split_anchor(key)
|
|
55
|
+
page, anchor = key.to_s.split("#", 2)
|
|
56
|
+
[page, anchor]
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
# The key naming `target` as written in `dir`, or nil when it points outside the repository.
|
|
60
|
+
#
|
|
61
|
+
# A `.md` under `docs/` loses both the prefix and the extension, which is exactly the name
|
|
62
|
+
# `rigor docs` already answers — that is what lets a rendered page hand the reader something they
|
|
63
|
+
# can run. Everything else keeps its repository-relative path verbatim: a directory
|
|
64
|
+
# (`examples/rigor-deprecations/`), a source file (`spec/rigor/environment_spec.rb`), a root
|
|
65
|
+
# document (`CHANGELOG.md`). Those are equally routable and equally worth naming; only the
|
|
66
|
+
# round-trip differs, and {.repository_path} reverses both.
|
|
67
|
+
#
|
|
68
|
+
# `target` is taken as written rather than expanded, because `File.expand_path` drops the trailing
|
|
69
|
+
# slash that tells a directory link apart from a page link — prose that writes `[the ADRs](../adr/)`
|
|
70
|
+
# is pointing at a tree, and a key without the slash would claim there is a page there.
|
|
71
|
+
def key_for(target, dir)
|
|
72
|
+
relative = File.expand_path(target, dir).sub("#{GEM_ROOT}/", "")
|
|
73
|
+
return nil if relative.start_with?("/")
|
|
74
|
+
|
|
75
|
+
relative += "/" if target.end_with?("/")
|
|
76
|
+
return relative unless relative.start_with?("docs/") && relative.end_with?(".md")
|
|
77
|
+
|
|
78
|
+
relative.delete_prefix("docs/").delete_suffix(".md")
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
# Repository directories a key may name verbatim. A key that starts with one of these already IS a
|
|
82
|
+
# path — `docs/adr`, `plugins/rigor-sorbet` — because {.key_for} only rewrites `.md` files under
|
|
83
|
+
# `docs/`. Anything else is a documentation key and gets its prefix and extension back.
|
|
84
|
+
#
|
|
85
|
+
# Keying on the ROOT rather than on "has an extension" is what makes a directory work: prose links
|
|
86
|
+
# a tree as often without a trailing slash (`../adr`) as with one, and no string test tells an
|
|
87
|
+
# extensionless file from a directory.
|
|
88
|
+
REPOSITORY_ROOTS = %w[docs examples plugins spec skills data tool bench apps].freeze
|
|
89
|
+
|
|
90
|
+
# The repository path a key names, reversing {.key_for}.
|
|
91
|
+
def repository_path(key)
|
|
92
|
+
return nil if key.nil? || key.empty? || key.include?("..")
|
|
93
|
+
return key if REPOSITORY_ROOTS.include?(key.split("/").first)
|
|
94
|
+
return key if File.extname(key) != ""
|
|
95
|
+
|
|
96
|
+
"docs/#{key}.md"
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
end
|
|
100
|
+
end
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
require_relative "command"
|
|
4
|
+
require_relative "doc_links"
|
|
4
5
|
|
|
5
6
|
module Rigor
|
|
6
7
|
class CLI
|
|
@@ -118,7 +119,7 @@ module Rigor
|
|
|
118
119
|
# a UTF-8 header would set the output buffer to UTF-8 and clash with the body.
|
|
119
120
|
@out.puts("<!-- rigor docs #{doc.fetch(:name)} (rigortype #{Rigor::VERSION}, offline) -->")
|
|
120
121
|
@out.puts
|
|
121
|
-
@out.write(File.read(doc.fetch(:path)))
|
|
122
|
+
@out.write(DocLinks.rewrite(File.read(doc.fetch(:path)), from: doc.fetch(:path)))
|
|
122
123
|
0
|
|
123
124
|
end
|
|
124
125
|
|
|
@@ -138,6 +139,10 @@ module Rigor
|
|
|
138
139
|
# @return [Hash, Integer] the doc entry, or an error exit status
|
|
139
140
|
# after the error has been written to `@err`.
|
|
140
141
|
def resolve_doc(query)
|
|
142
|
+
# A key printed by a rendered page may carry the section it pointed at; resolve the page and say
|
|
143
|
+
# where to look inside it, rather than refusing a key this command handed out.
|
|
144
|
+
query, anchor = DocLinks.split_anchor(query)
|
|
145
|
+
@err.puts("rigor: (section `#{anchor}`)") if anchor && !anchor.empty?
|
|
141
146
|
docs = discover_docs
|
|
142
147
|
|
|
143
148
|
exact = docs.find { |doc| doc.fetch(:exact_aliases).include?(query) }
|
|
@@ -146,11 +151,36 @@ module Rigor
|
|
|
146
151
|
short = docs.select { |doc| doc.fetch(:short_name) == query }
|
|
147
152
|
case short.size
|
|
148
153
|
when 1 then short.first
|
|
149
|
-
when 0 then name_error(query)
|
|
154
|
+
when 0 then unpackaged_doc(query) || name_error(query)
|
|
150
155
|
else ambiguous_error(query, short)
|
|
151
156
|
end
|
|
152
157
|
end
|
|
153
158
|
|
|
159
|
+
# A key the rendered pages hand out for a document the gem does not carry (ADR-74 ships the manual and
|
|
160
|
+
# handbook; the ADR / specification / notes corpus and the repository trees stay out). The key is
|
|
161
|
+
# still answerable — it names a real path — so this routes rather than failing: a reader who followed
|
|
162
|
+
# `[ADR-103][adr/103-effect-labels]` out of `rigor docs` gets told where that document is, which is the
|
|
163
|
+
# whole point of handing them the key instead of a dead relative path or a `master` URL.
|
|
164
|
+
# Categories this command serves itself. A name that fails to resolve inside one of them is a typo,
|
|
165
|
+
# not an unpackaged document, and must reach the did-you-mean listing rather than be routed to a
|
|
166
|
+
# repository path that does not exist — `rigor docs list` and `rigor docs pathh` are the cases
|
|
167
|
+
# that found this.
|
|
168
|
+
PACKAGED_CATEGORIES = %w[manual handbook].freeze
|
|
169
|
+
private_constant :PACKAGED_CATEGORIES
|
|
170
|
+
|
|
171
|
+
def unpackaged_doc(query)
|
|
172
|
+
return nil unless query.include?("/")
|
|
173
|
+
return nil if PACKAGED_CATEGORIES.include?(query.split("/").first)
|
|
174
|
+
|
|
175
|
+
path = DocLinks.repository_path(query)
|
|
176
|
+
return nil if path.nil?
|
|
177
|
+
|
|
178
|
+
@err.puts("rigor: `#{query}` is not packaged with this gem — the manual and handbook are, the " \
|
|
179
|
+
"design records are not.")
|
|
180
|
+
@err.puts("rigor: it is `#{path}` in the Rigor repository (#{DocLinks::REPOSITORY}).")
|
|
181
|
+
1
|
|
182
|
+
end
|
|
183
|
+
|
|
154
184
|
# Every bundled doc, each carrying the aliases `rigor docs <name>` accepts and the category used by `--list`.
|
|
155
185
|
# `install.md` sits at the docs root (category `guide`); the rest are manual / handbook chapters.
|
|
156
186
|
def discover_docs
|
|
@@ -3,7 +3,10 @@
|
|
|
3
3
|
require "optionparser"
|
|
4
4
|
|
|
5
5
|
require_relative "../configuration"
|
|
6
|
-
|
|
6
|
+
# ADR-104 — `analysis/runner` is required lazily (in `#analyze`), not here: a warm report served by
|
|
7
|
+
# {Analysis::EffectsCacheProbe} must reach its answer without `rigor/inference` in `$LOADED_FEATURES`,
|
|
8
|
+
# which is the whole of the boot saving. The probe pulls only the cache and the effects value layer.
|
|
9
|
+
require_relative "../analysis/effects_cache_probe"
|
|
7
10
|
require_relative "../effects/plugin_facts"
|
|
8
11
|
require_relative "../effects/registry"
|
|
9
12
|
require_relative "../plugin/loader"
|
|
@@ -94,7 +97,7 @@ module Rigor
|
|
|
94
97
|
return list_labels(configuration) if options.fetch(:list_labels)
|
|
95
98
|
|
|
96
99
|
scope = @argv.dup
|
|
97
|
-
table, sources =
|
|
100
|
+
table, sources = resolve_table(configuration, scope)
|
|
98
101
|
report = EffectsReport.build(
|
|
99
102
|
table, full: options.fetch(:full), sources: sources, scope: scope,
|
|
100
103
|
label: options.fetch(:label), pure: options.fetch(:pure), limit: options.fetch(:limit)
|
|
@@ -231,6 +234,7 @@ module Rigor
|
|
|
231
234
|
# @return [Array(Rigor::Effects::EffectTable, Hash{String=>Array<String>})] the table, and which
|
|
232
235
|
# file each unit was defined in — the map {EffectsReport} needs to answer a path argument.
|
|
233
236
|
def analyze(configuration, scope)
|
|
237
|
+
require_relative "../analysis/runner"
|
|
234
238
|
runner = Analysis::Runner.new(
|
|
235
239
|
configuration: configuration,
|
|
236
240
|
cache_store: Cache::Store.new(root: configuration.cache_path),
|
|
@@ -240,6 +244,27 @@ module Rigor
|
|
|
240
244
|
runner.run((configuration.paths + scope).uniq)
|
|
241
245
|
[runner.effect_table, runner.effect_sources]
|
|
242
246
|
end
|
|
247
|
+
|
|
248
|
+
# ADR-104 — the report before the engine. A warm run's whole answer is the #482 summary entry, so
|
|
249
|
+
# {Analysis::EffectsCacheProbe} tries to serve it without loading `rigor/inference`; any decline
|
|
250
|
+
# falls through to the full runner, which behaves exactly as it did.
|
|
251
|
+
#
|
|
252
|
+
# The report is a pure function of the table, the sources and the configuration: the envelope
|
|
253
|
+
# diagnostics the analysing path also computes are discarded here (this method reads the table
|
|
254
|
+
# and the sources and nothing else), which is what makes the served answer identical rather than
|
|
255
|
+
# merely similar.
|
|
256
|
+
def resolve_table(configuration, scope)
|
|
257
|
+
served = probe(configuration, scope)
|
|
258
|
+
return [served.table, served.sources] if served
|
|
259
|
+
|
|
260
|
+
analyze(configuration, scope)
|
|
261
|
+
end
|
|
262
|
+
|
|
263
|
+
def probe(configuration, scope)
|
|
264
|
+
Analysis::EffectsCacheProbe.new(
|
|
265
|
+
configuration: configuration, cache_root: configuration.cache_path
|
|
266
|
+
).serve((configuration.paths + scope).uniq)
|
|
267
|
+
end
|
|
243
268
|
end
|
|
244
269
|
end
|
|
245
270
|
end
|
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
require "json"
|
|
4
4
|
|
|
5
|
+
require_relative "../effects/definition_lines"
|
|
6
|
+
require_relative "../effects/snapshot"
|
|
5
7
|
require_relative "../effects/snapshot_diff"
|
|
6
8
|
require_relative "renderable"
|
|
7
9
|
|
|
@@ -16,8 +18,9 @@ module Rigor
|
|
|
16
18
|
# the one line the whole workflow turns on: intent is expressed by regenerating and committing the
|
|
17
19
|
# file, not by annotating the code.
|
|
18
20
|
#
|
|
19
|
-
# It is deliberately not a diagnostic format: no severities
|
|
20
|
-
#
|
|
21
|
+
# It is deliberately not a diagnostic format: no severities and no exit-code weight of its own — the
|
|
22
|
+
# exit code comes from the gate. A row carries a position for a reader to jump to, never one a
|
|
23
|
+
# `# rigor:disable` or a baseline could act on.
|
|
21
24
|
class EffectsDiffRenderer
|
|
22
25
|
include Renderable
|
|
23
26
|
|
|
@@ -41,9 +44,23 @@ module Rigor
|
|
|
41
44
|
CLOSING_LINE = "Run `rigor effects explain` to see what caused this, and `rigor effects update` to " \
|
|
42
45
|
"accept it."
|
|
43
46
|
|
|
44
|
-
|
|
47
|
+
# A regeneration event routes to `update` alone: `explain` answers "what caused this label to
|
|
48
|
+
# appear", and the answer here is "the record was written under different rules", which explain
|
|
49
|
+
# cannot expand and the line above already said.
|
|
50
|
+
REGENERATION_CLOSING_LINE = "Run `rigor effects update` to regenerate the record under the current " \
|
|
51
|
+
"rules."
|
|
52
|
+
|
|
53
|
+
# @param sources [Hash{String=>Array<String>}] `Runner#effect_sources` — where each unit is defined.
|
|
54
|
+
# A drift row names `file:line` so a reviewer does not have to search for the method (#435). The
|
|
55
|
+
# file rides the cached summary entry and is free; the line is resolved by parsing the row's own
|
|
56
|
+
# file ({Effects::DefinitionLines}), which is why a fresh report — no rows — still parses nothing
|
|
57
|
+
# and the whole-project parse ADR-104 removed from this command stays removed.
|
|
58
|
+
# @param lines [Effects::DefinitionLines] seam for the specs; the default parses on demand.
|
|
59
|
+
def initialize(out:, path:, sources: nil, lines: Effects::DefinitionLines.new)
|
|
45
60
|
@out = out
|
|
46
61
|
@path = path
|
|
62
|
+
@sources = sources || {}
|
|
63
|
+
@lines = lines
|
|
47
64
|
end
|
|
48
65
|
|
|
49
66
|
private
|
|
@@ -67,10 +84,7 @@ module Rigor
|
|
|
67
84
|
|
|
68
85
|
@out.puts("")
|
|
69
86
|
@out.puts("#{section_name(table)}:")
|
|
70
|
-
events.each
|
|
71
|
-
suffix = qualified ? " (#{event.table})" : ""
|
|
72
|
-
@out.puts(" #{render_event(event)}#{suffix}")
|
|
73
|
-
end
|
|
87
|
+
events.each { |event| @out.puts(" #{render_event(event, qualified: qualified)}") }
|
|
74
88
|
end
|
|
75
89
|
|
|
76
90
|
def section_name(table)
|
|
@@ -81,9 +95,38 @@ module Rigor
|
|
|
81
95
|
end
|
|
82
96
|
end
|
|
83
97
|
|
|
84
|
-
def render_event(event)
|
|
98
|
+
def render_event(event, qualified: false)
|
|
85
99
|
marker = marker_for(event)
|
|
86
|
-
|
|
100
|
+
return marker if event.symbol.nil?
|
|
101
|
+
|
|
102
|
+
"#{event.symbol} #{marker}#{annotation(event, qualified)}"
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
# One parenthetical, never two: where the unit is defined, and — under `tolerated:`, which pools
|
|
106
|
+
# both tables — which table the event came from. A row with no known source under `tolerated:`
|
|
107
|
+
# renders exactly as it did before this suffix existed.
|
|
108
|
+
#
|
|
109
|
+
# A unit defined by a reopening spans several files and the row names them all rather than picking
|
|
110
|
+
# one; which of them a reviewer wants is exactly what the row cannot know.
|
|
111
|
+
def annotation(event, qualified)
|
|
112
|
+
parts = sources_of(event.symbol).map { |path, line| line ? "#{path}:#{line}" : path }
|
|
113
|
+
parts << event.table if qualified
|
|
114
|
+
parts.empty? ? "" : " (#{parts.join(', ')})"
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
# Where a symbol is defined, as the two renderings share it — one implementation, so the text form
|
|
118
|
+
# and the JSON one cannot disagree about a position (WD3's rule).
|
|
119
|
+
#
|
|
120
|
+
# **A removed symbol has no entry here at all**, and cannot: `sources` is the CURRENT run's, and a
|
|
121
|
+
# method that no longer exists was not defined by it. Such a row renders exactly as it did before
|
|
122
|
+
# this suffix existed.
|
|
123
|
+
#
|
|
124
|
+
# @return [Array<Array(String, Integer)>] `[relative path, line]` per file, the line nil when that
|
|
125
|
+
# file spells the key with no `def` — an accessor, or a definition the nesting cannot name.
|
|
126
|
+
def sources_of(symbol)
|
|
127
|
+
Array(@sources[symbol]).map do |path|
|
|
128
|
+
[Effects::Snapshot.relativize(path, Dir.pwd), @lines.for(key: symbol, path: path)]
|
|
129
|
+
end
|
|
87
130
|
end
|
|
88
131
|
|
|
89
132
|
def marker_for(event)
|
|
@@ -99,21 +142,48 @@ module Rigor
|
|
|
99
142
|
def render_footer(diff)
|
|
100
143
|
footer = diff.footer
|
|
101
144
|
@out.puts("")
|
|
145
|
+
@out.puts(withheld_line(footer)) if diff.regeneration?
|
|
102
146
|
unless footer[:added_symbols].zero? && footer[:removed_symbols].zero?
|
|
103
147
|
@out.puts("symbols: +#{footer[:added_symbols]} / -#{footer[:removed_symbols]} " \
|
|
104
148
|
"(a rename is one of each)")
|
|
105
149
|
end
|
|
106
|
-
@out.puts(CLOSING_LINE)
|
|
150
|
+
@out.puts(diff.regeneration? ? REGENERATION_CLOSING_LINE : CLOSING_LINE)
|
|
151
|
+
end
|
|
152
|
+
|
|
153
|
+
# What a regeneration withheld, said as a count. The counts below it are still printed, so the
|
|
154
|
+
# reader sees the scale of the difference without reading it row by row.
|
|
155
|
+
def withheld_line(footer)
|
|
156
|
+
suppressed = footer[:suppressed]
|
|
157
|
+
return "The two records are not comparable, so no per-method difference is shown." if
|
|
158
|
+
suppressed.zero?
|
|
159
|
+
|
|
160
|
+
noun = suppressed == 1 ? "1 per-method difference is" : "#{suppressed} per-method differences are"
|
|
161
|
+
"The two records were computed under different rules and are not comparable, so #{noun} not shown."
|
|
162
|
+
end
|
|
163
|
+
|
|
164
|
+
# The machine form carries the same position the text one prints (#435): a bot that annotates a pull
|
|
165
|
+
# request is the consumer with the most use for a line and the least ability to find one itself.
|
|
166
|
+
# `sources` is omitted rather than emitted empty when the row names nothing — a removed symbol.
|
|
167
|
+
def event_json(event)
|
|
168
|
+
row = event.to_h
|
|
169
|
+
sources = sources_of(event.symbol)
|
|
170
|
+
return row if sources.empty?
|
|
171
|
+
|
|
172
|
+
row.merge("sources" => sources.map do |path, line|
|
|
173
|
+
line ? { "path" => path, "line" => line } : { "path" => path }
|
|
174
|
+
end)
|
|
107
175
|
end
|
|
108
176
|
|
|
109
177
|
def render_json(diff)
|
|
110
178
|
@out.puts(JSON.pretty_generate(
|
|
111
179
|
"fresh" => diff.fresh?,
|
|
112
|
-
"events" => diff.events.map(
|
|
180
|
+
"events" => diff.events.map { |event| event_json(event) },
|
|
113
181
|
"footer" => {
|
|
114
182
|
"added_symbols" => diff.footer[:added_symbols],
|
|
115
|
-
"removed_symbols" => diff.footer[:removed_symbols]
|
|
183
|
+
"removed_symbols" => diff.footer[:removed_symbols],
|
|
184
|
+
"suppressed" => diff.footer[:suppressed]
|
|
116
185
|
},
|
|
186
|
+
"regeneration" => diff.regeneration?,
|
|
117
187
|
"header" => {
|
|
118
188
|
"snapshot" => @path,
|
|
119
189
|
"gate" => diff.gate.to_s,
|
|
@@ -22,8 +22,9 @@ module Rigor
|
|
|
22
22
|
class EffectsExplainRenderer
|
|
23
23
|
include Renderable
|
|
24
24
|
|
|
25
|
-
# One printed explanation. `path` is empty for a `methods:` row, whose explanation is the origin
|
|
26
|
-
|
|
25
|
+
# One printed explanation. `path` is empty for a `methods:` row, whose explanation is the origin;
|
|
26
|
+
# `causes` is non-empty only for an exhaustiveness row, which has neither (#435).
|
|
27
|
+
Row = Data.define(:table, :symbol, :label, :path, :origin, :causes)
|
|
27
28
|
|
|
28
29
|
def initialize(out:)
|
|
29
30
|
@out = out
|
|
@@ -44,6 +45,7 @@ module Rigor
|
|
|
44
45
|
end
|
|
45
46
|
|
|
46
47
|
def render_row(row)
|
|
48
|
+
return "#{row.symbol} stopped being exhaustive ← #{row.causes.join(', ')}" unless row.causes.empty?
|
|
47
49
|
return "#{row.path.join(' → ')} [#{row.label}]" unless row.path.empty?
|
|
48
50
|
|
|
49
51
|
origin = row.origin ? " ← #{row.origin}" : ""
|
|
@@ -58,7 +60,8 @@ module Rigor
|
|
|
58
60
|
"symbol" => row.symbol,
|
|
59
61
|
"label" => row.label,
|
|
60
62
|
"path" => row.path,
|
|
61
|
-
"origin" => row.origin
|
|
63
|
+
"origin" => row.origin,
|
|
64
|
+
"causes" => row.causes
|
|
62
65
|
}
|
|
63
66
|
end
|
|
64
67
|
))
|
|
@@ -3,7 +3,9 @@
|
|
|
3
3
|
require "did_you_mean"
|
|
4
4
|
require "optionparser"
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
# ADR-104 — `analysis/runner` is required lazily (in `#analyze`): a warm snapshot verb served by the
|
|
7
|
+
# probe must reach its answer without `rigor/inference` in `$LOADED_FEATURES`.
|
|
8
|
+
require_relative "../analysis/effects_cache_probe"
|
|
7
9
|
require_relative "../cache/store"
|
|
8
10
|
require_relative "../configuration"
|
|
9
11
|
require_relative "../effects/discharge"
|
|
@@ -111,7 +113,8 @@ module Rigor
|
|
|
111
113
|
)
|
|
112
114
|
return explain(diff, options) if @verb == "explain"
|
|
113
115
|
|
|
114
|
-
EffectsDiffRenderer.new(out: @out, path: path
|
|
116
|
+
EffectsDiffRenderer.new(out: @out, path: path, sources: @sources)
|
|
117
|
+
.render(diff, format: options.fetch(:format))
|
|
115
118
|
@verb == "check" && diff.drift? ? 1 : 0
|
|
116
119
|
end
|
|
117
120
|
|
|
@@ -163,6 +166,9 @@ module Rigor
|
|
|
163
166
|
# `methods:` change gets the origin in the method's own body.
|
|
164
167
|
def rows_for_changes(diff)
|
|
165
168
|
diff.events.flat_map do |event|
|
|
169
|
+
next exhaustiveness_rows(event) if
|
|
170
|
+
event.category == Effects::SnapshotDiff::EXHAUSTIVE_LOST
|
|
171
|
+
|
|
166
172
|
labels = labels_of(event)
|
|
167
173
|
next [] if labels.empty?
|
|
168
174
|
|
|
@@ -178,13 +184,29 @@ module Rigor
|
|
|
178
184
|
entry ? entry.proven.to_a : []
|
|
179
185
|
end
|
|
180
186
|
|
|
187
|
+
# `exhaustive → not` is the drift row a reader is least equipped to interpret, and it was the one
|
|
188
|
+
# row `explain` could not expand (#435): it carries no label, so {#labels_of} answered with nothing
|
|
189
|
+
# and the event produced no explanation at all. What explains it is the taint causes — the calls
|
|
190
|
+
# the analyzer could not follow — which is the detail the snapshot stopped recording per row
|
|
191
|
+
# (#434). The two halves meet here: the record keeps the stable count, and this names them.
|
|
192
|
+
def exhaustiveness_rows(event)
|
|
193
|
+
entry = @table[event.symbol]
|
|
194
|
+
return [] if entry.nil?
|
|
195
|
+
|
|
196
|
+
causes = Effects::Snapshot.render_causes(entry.causes)
|
|
197
|
+
return [] if causes.empty?
|
|
198
|
+
|
|
199
|
+
[EffectsExplainRenderer::Row.new(table: event.table, symbol: event.symbol, label: nil,
|
|
200
|
+
path: [].freeze, origin: nil, causes: causes)]
|
|
201
|
+
end
|
|
202
|
+
|
|
181
203
|
def reach_rows(symbol, labels)
|
|
182
204
|
labels.filter_map do |label|
|
|
183
205
|
path = Effects::PathFinder.shortest(@table, symbol: symbol, label: label)
|
|
184
206
|
next if path.nil?
|
|
185
207
|
|
|
186
208
|
EffectsExplainRenderer::Row.new(table: "reach", symbol: symbol, label: label,
|
|
187
|
-
path: path.to_a, origin: path.origin)
|
|
209
|
+
path: path.to_a, origin: path.origin, causes: [].freeze)
|
|
188
210
|
end
|
|
189
211
|
end
|
|
190
212
|
|
|
@@ -197,7 +219,7 @@ module Rigor
|
|
|
197
219
|
next if origin.nil?
|
|
198
220
|
|
|
199
221
|
EffectsExplainRenderer::Row.new(table: "methods", symbol: symbol, label: label,
|
|
200
|
-
path: [].freeze, origin: origin.to_s)
|
|
222
|
+
path: [].freeze, origin: origin.to_s, causes: [].freeze)
|
|
201
223
|
end
|
|
202
224
|
end
|
|
203
225
|
|
|
@@ -207,7 +229,20 @@ module Rigor
|
|
|
207
229
|
# the ADR-45 whole-run result cache like `rigor check` — the diagnostics entry plus the #382 effects
|
|
208
230
|
# sidecar keyed beside it, so `rigor effects check` after `rigor check` under a configured `effects:`
|
|
209
231
|
# block is a warm hit plus the fixpoint.
|
|
232
|
+
# ADR-104 — a snapshot is built from the table, the sources and the vocabulary, all three of which
|
|
233
|
+
# the #482 summary entry (plus the plugins' own declarations) carries, so a warm run takes the
|
|
234
|
+
# probe and never loads the engine. A decline is the runner path below, unchanged.
|
|
210
235
|
def build_snapshot(configuration, full:)
|
|
236
|
+
served = Analysis::EffectsCacheProbe.new(
|
|
237
|
+
configuration: configuration, cache_root: configuration.cache_path
|
|
238
|
+
).serve(configuration.paths)
|
|
239
|
+
return snapshot_from(configuration, full, served) if served
|
|
240
|
+
|
|
241
|
+
snapshot_from(configuration, full, analyze(configuration))
|
|
242
|
+
end
|
|
243
|
+
|
|
244
|
+
def analyze(configuration)
|
|
245
|
+
require_relative "../analysis/runner"
|
|
211
246
|
runner = Analysis::Runner.new(
|
|
212
247
|
configuration: configuration,
|
|
213
248
|
cache_store: Cache::Store.new(root: configuration.cache_path),
|
|
@@ -215,14 +250,24 @@ module Rigor
|
|
|
215
250
|
workers: 0
|
|
216
251
|
)
|
|
217
252
|
runner.run(configuration.paths)
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
table: @table, configuration: configuration, sources: runner.effect_sources, full: full,
|
|
253
|
+
Analysis::EffectsCacheProbe::Served.new(
|
|
254
|
+
table: runner.effect_table, sources: runner.effect_sources, plugin_facts: nil,
|
|
221
255
|
registry: Effects::Registry.for_configuration(configuration,
|
|
222
256
|
plugin_facts: runner.effect_plugin_facts)
|
|
223
257
|
)
|
|
224
258
|
end
|
|
225
259
|
|
|
260
|
+
# WD3 — one build, whichever lane produced the inputs, so a served snapshot and an analysed one
|
|
261
|
+
# cannot drift in how they are assembled.
|
|
262
|
+
def snapshot_from(configuration, full, served)
|
|
263
|
+
@table = served.table
|
|
264
|
+
@sources = served.sources
|
|
265
|
+
Effects::Snapshot.build(
|
|
266
|
+
table: @table, configuration: configuration, sources: served.sources, full: full,
|
|
267
|
+
registry: served.registry
|
|
268
|
+
)
|
|
269
|
+
end
|
|
270
|
+
|
|
226
271
|
# ---- options ------------------------------------------------
|
|
227
272
|
|
|
228
273
|
def parse_options
|