Conversation
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
[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.
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.
That's interesting, I will make some changes...
There was a problem hiding this comment.
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.
Makes sense! Let's keep the tests.
paldepind
left a comment
There was a problem hiding this comment.
Thanks for addressing my comments. PR looks great to me 👍
Improve
StmtList:elements/stmtlisttest, and moved the existingoperationstest intoelements/operations.