Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add --tallies option to crystal tool unreachable #13969

Merged

Conversation

straight-shoota
Copy link
Member

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 and entry-b.cr. They require some of the same file dependencies, but also different ones. The standard behaviour of unreachable can only tell which defs are unreachable in a and which are unreachable in b. Shared entries are definitely unreachable in both. A def ::foo that is only listed as unreachable in a, not in b can mean it's reachable in b. But it can also mean ::foo is not even in the dependency graph of entry-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 in b 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 a Hash 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.

Co-authored-by: Quinton Miller <nicetas.c@gmail.com>
@straight-shoota straight-shoota added this to the 1.11.0 milestone Dec 21, 2023
@straight-shoota straight-shoota merged commit f362827 into crystal-lang:master Dec 22, 2023
44 checks passed
@straight-shoota straight-shoota deleted the feat/unreachable-tally branch December 22, 2023 14:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants