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

Implements aliases support in DCA. #4337

Merged
merged 4 commits into from
Apr 24, 2023
Merged

Conversation

esdrubal
Copy link
Contributor

@esdrubal esdrubal commented Mar 24, 2023

Description

Adds support for aliases in DCA.

Fixes #4328 where a DCA warning was emmited while using struct method defined in an impl self.

Closes #4283
Closes #4328

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.

@esdrubal esdrubal added P: critical Should be looked at before anything else compiler: frontend Everything to do with type checking, control flow analysis, and everything between parsing and IRgen DCA Everything to do with Dead Code Analysis labels Mar 24, 2023
@esdrubal esdrubal self-assigned this Mar 24, 2023
@esdrubal esdrubal marked this pull request as draft March 24, 2023 12:01
@esdrubal esdrubal requested a review from a team March 28, 2023 15:57
@esdrubal esdrubal marked this pull request as ready for review March 28, 2023 15:57
tritao
tritao previously approved these changes Apr 10, 2023
@mohammadfawaz
Copy link
Contributor

I did not understand the purpose of call_path_decl. What does it contain exactly? And why do we only need it in certain situations? (example: only for enums but not structs)

@esdrubal
Copy link
Contributor Author

I did not understand the purpose of call_path_decl. What does it contain exactly? And why do we only need it in certain situations? (example: only for enums but not structs)

call_path_decl is needed for the DCA to be able to retrieve a type alias. For instance in the example below we have EnumScrutinee which contains enum_ref: DeclRefEnum already resolved to an enum, it is impossible to infer if we used a type alias from that. So I added call_path_decl which may be an alias or an enum decl.

EnumScrutinee {
enum_ref: DeclRefEnum,
variant: Box<TyEnumVariant>,
/// Should contain a TyDecl to either an enum or a type alias.
call_path_decl: ty::TyDecl,

Structs should also have it, I probably forgot to add tests cases for structs, I will check that.

Adds support for aliases in DCA.

Fixes #4328 where a DCA warning was emmited while using struct method defined in an impl self.

Closes #4283
Closes #4328
@esdrubal
Copy link
Contributor Author

esdrubal commented Apr 19, 2023

Fixed merging conflicts. And added one more test case and a fix for it.

The reason we have call_path_decl in EnumScrutinee and not in StructScrutinee is because we build an UnsafeDowncast from EnumScrutinee. The DCA uses UnsafeDowncast to connect match statements to the enum variants. In case we use an alias in the enum we need call_path_decl in UnsafeDowncast to contain the type alias decl.

@IGI-111 IGI-111 enabled auto-merge (squash) April 24, 2023 07:37
@IGI-111 IGI-111 merged commit c4368c3 into master Apr 24, 2023
@IGI-111 IGI-111 deleted the esdrubal/4283_DCA_aliases branch April 24, 2023 07:53
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 DCA Everything to do with Dead Code Analysis P: critical Should be looked at before anything else
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Wrong DCA warning while using struct method defined in impl self. Handle DCA for type aliases
5 participants