Skip to content

Conversation

tritao
Copy link
Contributor

@tritao tritao commented Aug 11, 2025

This adds a new --dump-impls CLI command that can be used to dump all the recognized trait impls for a given type name.

This also extends the compiler diagnostic system to allow the emission of info diagnostics, as previously we could only emit either warnings of errors, which did not fit this use case.

Description

For example, here is the output of cargo run --bin forc -- build --path _test-case --dump-impls=std::string::String:

image

And for enums:

image

Closes #7286.

Checklist

  • I have linked to any relevant issues.
  • I have commented my code, particularly in hard-to-understand areas.
  • I have updated the documentation where relevant (API docs, the reference, and the Sway book).
  • I have added tests that prove my fix is effective or that my feature works.
  • I have added (or requested a maintainer to add) the necessary Breaking* or New Feature labels where relevant.
  • I have done my best to ensure that my PR adheres to the Fuel Labs Code Review Standards.
  • I have requested a review from the relevant team or maintainers.

@tritao tritao self-assigned this Aug 11, 2025
Copy link

codspeed-hq bot commented Aug 14, 2025

CodSpeed Performance Report

Merging #7322 will not alter performance

Comparing tritao:dump-impls (b73f819) with master (13e4df8)

Summary

✅ 25 untouched benchmarks

@tritao tritao added compiler General compiler. Should eventually become more specific as the issue is triaged compiler: frontend Everything to do with type checking, control flow analysis, and everything between parsing and IRgen labels Aug 18, 2025
@tritao tritao marked this pull request as ready for review August 18, 2025 12:40
@tritao tritao requested review from a team as code owners August 18, 2025 12:40
@xunilrj
Copy link
Contributor

xunilrj commented Aug 18, 2025

Would make sense to use the "trait" or the "impl_for" span instead of the whole declaration? That would always show the start of the impl, and would give more uniform results.

struct B {
       _ Match implementations for this type

impl A for B {
     _ help: trait is A

@tritao
Copy link
Contributor Author

tritao commented Aug 19, 2025

Would make sense to use the "trait" or the "impl_for" span instead of the whole declaration? That would always show the start of the impl, and would give more uniform results.

Great suggestion, it indeed looks much better, I have updated the implementation and the screenshots in the PR description.

Also improved the implementation to handle enums as previously only structs were supported.

Copy link
Contributor

@IGI-111 IGI-111 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice, but we need some tests for this.

Snapshots should do well here.

@tritao
Copy link
Contributor Author

tritao commented Aug 20, 2025

Very nice, but we need some tests for this.

Snapshots should do well here.

Added some tests.

Copy link
Contributor

@IGI-111 IGI-111 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good start on the tests, but this is just the happy path, we should also check whether the impls still get captured:

  • when they are in a different file/module
  • when they are in a different package altogether

tritao added 2 commits August 26, 2025 12:31
This adds a new `--dump-impls` CLI command that can be used to dump all
the recognized trait impls for a given type name.

This also extends the compiler diagnostic system to allow the emission
of info diagnostics, as previously we could only emit either warnings of
errors, which did not fit this.

Closes FuelLabs#7286.
@tritao tritao enabled auto-merge (squash) August 26, 2025 11:50
@tritao
Copy link
Contributor Author

tritao commented Aug 26, 2025

That's a good start on the tests, but this is just the happy path, we should also check whether the impls still get captured:

  • when they are in a different file/module
  • when they are in a different package altogether

Updated with these.

@tritao tritao requested review from IGI-111 and a team August 26, 2025 11:51
@IGI-111 IGI-111 requested a review from a team August 26, 2025 17:01
@tritao tritao merged commit 8be2dae into FuelLabs:master Aug 26, 2025
41 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler: frontend Everything to do with type checking, control flow analysis, and everything between parsing and IRgen compiler General compiler. Should eventually become more specific as the issue is triaged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement a command to dump impls for a given type
4 participants