-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Rust: Improve StmtList #20512
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
Rust: Improve StmtList #20512
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Improves the StmtList documentation and functionality to clarify that it consists of statements plus an optional tail expression that determines block values.
- Updates documentation to emphasize the statement + optional tail expression structure
- Adds new accessor methods to get statements and expressions together
- Creates comprehensive test coverage for different statement list scenarios
Reviewed Changes
Copilot reviewed 8 out of 18 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| rust/schema/annotations.py | Enhanced documentation and field descriptions for StmtList |
| rust/ql/lib/codeql/rust/elements/internal/StmtListImpl.qll | Added new accessor methods and removed generated file marker |
| rust/ql/lib/codeql/rust/elements/StmtList.qll | Updated documentation to match schema changes |
| rust/ql/test/library-tests/elements/stmtlist/* | New test files for StmtList functionality |
| rust/ql/.gitattributes | Removed generated file marking for StmtListImpl.qll |
| rust/ql/.generated.list | Updated file hashes for modified files |
| AstNode getStmtOrExpr(int index) { | ||
| result = this.getStatement(index) | ||
| or | ||
| index = max(int i | i = -1 or exists(this.getStatement(i))) + 1 and |
Copilot
AI
Sep 24, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] The magic number -1 in the index calculation makes the logic unclear. Consider adding a comment explaining why -1 is used as a base case when no statements exist, or use a more explicit approach like count(this.getStatement(_)) for the index.
| index = max(int i | i = -1 or exists(this.getStatement(i))) + 1 and | |
| index = count(this.getStatement(_)) and |
| or | ||
| index = max(int i | i = -1 or exists(this.getStatement(i))) + 1 and | ||
| result = this.getTailExpr() | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As per the above comment I'm not entirely convinced that we want to expose this predicate. But, if we do, then there is in fact already an implementation here. Given that I think we should:
- Delete
getBlockChildNodeand usegetStmtOrExprin the control flow graph implementation. - Use the
getBlockChildNodeimplementation forgetStmtOrExpras it is a bit simpler. - Remove the tests added in this PR as the CFG tests will then be exercising
getStmtOrExpr.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's interesting, I will make some changes...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done the first two. I could be persuaded to delete the test, but I'm not convinced its redundant - it seems to me that each is testing slightly different areas of code in slightly different ways (there is a lot of overlap).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense! Let's keep the tests.
paldepind
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for addressing my comments. PR looks great to me 👍
Improve
StmtList:elements/stmtlisttest, and moved the existingoperationstest intoelements/operations.