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 linter rule for missing in intents #26115

Merged
merged 4 commits into from
Oct 22, 2024

Conversation

jabraham17
Copy link
Member

@jabraham17 jabraham17 commented Oct 21, 2024

Adds a chplcheck rule to inform users that formals that initialize a field should have an in intent. Doing this can reduce the number of copies made and improve performance.

This PR takes the following approach to implement this

  1. Identify all field in an aggregate type
  2. For each initializer, identify all formals that have the default intent
  3. If a formal is assigned to a field before init this, warn

Note that this only handles the cases where the left hand side of = can be scope resolved, so something like this.field = myFormal will not trigger the warning yet

Future work: As the resolver comes online and is threaded into chplcheck, this lint rule should make use of the logic in InitResolver to distinguish between initialization and assignment.

[Reviewed by @DanilaFe]

Signed-off-by: Jade Abraham <jade.abraham@hpe.com>
Signed-off-by: Jade Abraham <jade.abraham@hpe.com>
Signed-off-by: Jade Abraham <jade.abraham@hpe.com>
Signed-off-by: Jade Abraham <jade.abraham@hpe.com>
@bradcray
Copy link
Member

I loved your performance-oriented motivation for this rule in today's demo!

@jabraham17 jabraham17 merged commit 863d137 into chapel-lang:main Oct 22, 2024
8 checks passed
@jabraham17 jabraham17 deleted the lint-missing-in branch October 22, 2024 16:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants