Add --tallies
option to crystal tool unreachable
#13969
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This option changes
crystal tool unreachable
to output all defs and their call counts. The call count of unreachable defs is zero. This additional information enables collecting data across multiple entrypoints with different dependency graphs.Consider two files serving as different entry points,
entry-a.cr
andentry-b.cr
. They require some of the same file dependencies, but also different ones. The standard behaviour ofunreachable
can only tell which defs are unreachable ina
and which are unreachable inb
. Shared entries are definitely unreachable in both. A def::foo
that is only listed as unreachable ina
, not inb
can mean it's reachable inb
. But it can also mean::foo
is not even in the dependency graph ofentry-b.cr
and thus never seen by the compiler.The
--tallies
option printing all defs, reachable and unreachable, resolves this uncertainty by clearly stating whether::foo
is present inb
or not.For this use case, the exact call count wouldn't be necessary. The information whether there's at least one call would suffice. But giving a total number isn't much extra effort and can be useful for further statistical analysis.
The implementation overall is pretty simple, the main change is from
Set
to register presence to aHash
for counting occurences.A demonstration of applying this features on a code base is available at https://gist.github.com/straight-shoota/f7c9120b3bdbc067b4877f88def9c51e
It analyzes the source code of the compiler and standard library using three entry points (compiler, compiler_spec and std_spec) and combines the information into a single database.