Skip to content

Conversation

geoffw0
Copy link
Contributor

@geoffw0 geoffw0 commented Sep 24, 2025

Improve StmtList:

  • document the fact that this consists of a list of statements plus an optional tail expression, and drop a few hints about this in places where people are likely to go wrong.
  • add accessor that gets both together.
  • I've also created an elements/stmtlist test, and moved the existing operations test into elements/operations.

@geoffw0 geoffw0 requested a review from a team as a code owner September 24, 2025 16:32
@geoffw0 geoffw0 added the no-change-note-required This PR does not need a change note label Sep 24, 2025
@geoffw0 geoffw0 removed the request for review from a team September 24, 2025 16:32
@geoffw0 geoffw0 added the Rust Pull requests that update Rust code label Sep 24, 2025
@Copilot Copilot AI review requested due to automatic review settings September 24, 2025 16:32
Copy link
Contributor

@Copilot Copilot AI left a 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
Copy link
Preview

Copilot AI Sep 24, 2025

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.

Suggested change
index = max(int i | i = -1 or exists(this.getStatement(i))) + 1 and
index = count(this.getStatement(_)) and

Copilot uses AI. Check for mistakes.

or
index = max(int i | i = -1 or exists(this.getStatement(i))) + 1 and
result = this.getTailExpr()
}
Copy link
Contributor

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 getBlockChildNode and use getStmtOrExpr in the control flow graph implementation.
  • Use the getBlockChildNode implementation for getStmtOrExpr as it is a bit simpler.
  • Remove the tests added in this PR as the CFG tests will then be exercising getStmtOrExpr.

Copy link
Contributor Author

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...

Copy link
Contributor Author

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).

Copy link
Contributor

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.

Copy link
Contributor

@paldepind paldepind left a 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 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
no-change-note-required This PR does not need a change note Rust Pull requests that update Rust code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants