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

We should have a tool that finds unused diagnostic IDs #67306

Open
beccadax opened this issue Jul 14, 2023 · 7 comments · May be fixed by #68902
Open

We should have a tool that finds unused diagnostic IDs #67306

beccadax opened this issue Jul 14, 2023 · 7 comments · May be fixed by #68902
Assignees
Labels
compiler The Swift compiler itself development tools Area: tools for compiler developers under the 'tools' directory feature A feature request or implementation good first issue Good for newcomers QoI Quality of Implementation utils Area: the build system and other accessory scripts under the "utils" directory

Comments

@beccadax
Copy link
Contributor

While working on #67075, I found several stale diagnostics that are declared in Diagnostics*.def files, but are never used anywhere in the compiler. I deleted most of the ones I found, but I’m sure there are many more.

We should have a tool that scans lib/ and include/ for uses of diagnostic IDs and flags any that are never actually used. This could perhaps be a test that would fail if there are unused diagnostics.

This might be a good first issue for a new contributor who has reasonably strong Python or Swift skills but doesn’t have any experience with compilers yet.

@beccadax beccadax added good first issue Good for newcomers feature A feature request or implementation utils Area: the build system and other accessory scripts under the "utils" directory triage needed This issue needs more specific labels development tools Area: tools for compiler developers under the 'tools' directory QoI Quality of Implementation labels Jul 14, 2023
@ED-1-0
Copy link

ED-1-0 commented Jul 15, 2023

Can I take this issue? This is my first time contributing to open source project.

@AnthonyLatsis AnthonyLatsis added compiler The Swift compiler itself and removed triage needed This issue needs more specific labels labels Jul 16, 2023
@AnthonyLatsis
Copy link
Collaborator

Sure, go ahead.

@ED-1-0
Copy link

ED-1-0 commented Jul 17, 2023

Just to clarify, am I supposed to build diagnostic tools that finds unused diagnostic ID? In addition, Any suggestion on where should I start?

@xedin
Copy link
Contributor

xedin commented Jul 17, 2023

You'd need to load include/swift/AST/DiagnosticsAll.def and for each diagnostic ID in there check whether diag::<diagnostic-id> appears anywhere in lib/ or include/ excluding *.def files.

@XaurDesu
Copy link

This could perhaps be a test that would fail if there are unused diagnostics.

Would https://github.com/apple/swift/tree/main/test/diagnostics be a good location for it? I was thinking we could probably add it as a new file, given how generally files on this folder seem to be designed to just check for a specific problem and i'd imagine this would probably fit under that description more or less. Something along the lines of no-unused-diagnostic-ids.swift.

@mininny
Copy link
Contributor

mininny commented Oct 2, 2023

It seems like there hasn't been much activity in this issue, so I went ahead and created the script. #68902

If you run the script right now, there are about 90 unused diagnostics.
I could go ahead and remove all of the unused diagnostics in the same(or different) PR, but I also think they were created with specific intentions, so maybe we should check if we can find appropriate places for all of the diagnostics.

@tbkka
Copy link
Contributor

tbkka commented Oct 2, 2023

Using git blame, you should be able to find out when/why that diagnostic was added, then trace to see whether it was ever used or whether it was used and then deleted. That might help you identify which ones can safely be deleted now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler The Swift compiler itself development tools Area: tools for compiler developers under the 'tools' directory feature A feature request or implementation good first issue Good for newcomers QoI Quality of Implementation utils Area: the build system and other accessory scripts under the "utils" directory
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants