forked from chapel-lang/chapel
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add linter rule for missing in intents (chapel-lang#26115)
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]
- Loading branch information
Showing
6 changed files
with
152 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
module MissingInIntent { | ||
|
||
record myData { | ||
var x: int; | ||
proc init() { | ||
x = 0; | ||
} | ||
proc init(in d: int) { | ||
x = d; | ||
} | ||
} | ||
|
||
|
||
record R { | ||
var x: int; | ||
var y: myData; | ||
proc init(newX: int) { | ||
x = newX; | ||
y = new myData(); | ||
} | ||
proc init(newY: myData) { | ||
x = 0; | ||
y = newY; | ||
} | ||
@chplcheck.ignore("UnusedFormal") | ||
proc init(newY: myData, dummy: int) { | ||
x = newY.x; | ||
y = new myData(); | ||
} | ||
@chplcheck.ignore("UnusedFormal") | ||
proc init(newY: myData, dummy: int, dummy2: int) { | ||
init this; | ||
x = 0; | ||
y = newY; | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
MissingInIntent.chpl:17: node violates rule MissingInIntent | ||
MissingInIntent.chpl:21: node violates rule MissingInIntent | ||
[Success matching fixit for MissingInIntent] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
module MissingInIntent { | ||
|
||
record myData { | ||
var x: int; | ||
proc init() { | ||
x = 0; | ||
} | ||
proc init(in d: int) { | ||
x = d; | ||
} | ||
} | ||
|
||
|
||
record R { | ||
var x: int; | ||
var y: myData; | ||
proc init(in newX: int) { | ||
x = newX; | ||
y = new myData(); | ||
} | ||
proc init(in newY: myData) { | ||
x = 0; | ||
y = newY; | ||
} | ||
@chplcheck.ignore("UnusedFormal") | ||
proc init(newY: myData, dummy: int) { | ||
x = newY.x; | ||
y = new myData(); | ||
} | ||
@chplcheck.ignore("UnusedFormal") | ||
proc init(newY: myData, dummy: int, dummy2: int) { | ||
init this; | ||
x = 0; | ||
y = newY; | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters