Skip to content

Conversation

@hvitved
Copy link
Contributor

@hvitved hvitved commented Mar 31, 2025

This PR makes Element.toString non-recursive again, and inserts a recursion guard that prevents unintented recursion through ToString (recursion is still possible, but has to go explicitly via ToStringImpl, as is the case in Swift).

@github-actions github-actions bot added the Rust Pull requests that update Rust code label Mar 31, 2025
@hvitved hvitved force-pushed the rust/to-string-non-rec branch from 054e943 to 0cd1f0f Compare March 31, 2025 13:10
@github-actions github-actions bot added the Swift label Mar 31, 2025
@hvitved hvitved force-pushed the rust/to-string-non-rec branch 2 times, most recently from 65daa1a to 0548a96 Compare March 31, 2025 17:55
@hvitved hvitved force-pushed the rust/to-string-non-rec branch from f8d941d to 56f4694 Compare April 1, 2025 06:48
@hvitved hvitved marked this pull request as ready for review April 1, 2025 11:38
Copilot AI review requested due to automatic review settings April 1, 2025 11:38
@hvitved hvitved requested a review from a team as a code owner April 1, 2025 11:38
Copy link
Contributor

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.

Copilot reviewed 2 out of 12 changed files in this pull request and generated no comments.

Files not reviewed (10)
  • misc/codegen/templates/ql_class.mustache: Language not supported
  • rust/ql/.generated.list: Language not supported
  • rust/ql/lib/codeql/rust/elements/internal/ElementImpl.qll: Language not supported
  • rust/ql/lib/codeql/rust/elements/internal/ModuleImpl.qll: Language not supported
  • rust/ql/lib/codeql/rust/elements/internal/UseImpl.qll: Language not supported
  • rust/ql/lib/codeql/rust/elements/internal/UseTreeImpl.qll: Language not supported
  • swift/ql/.generated.list: Language not supported
  • swift/ql/lib/codeql/swift/elements/expr/InitializerLookupExpr.qll: Language not supported
  • swift/ql/lib/codeql/swift/elements/expr/internal/ApplyExprImpl.qll: Language not supported
  • swift/ql/lib/codeql/swift/elements/expr/internal/ExplicitCastExprImpl.qll: Language not supported

Tip: Copilot code review supports C#, Go, Java, JavaScript, Markdown, Python, Ruby and TypeScript, with more languages coming soon. Learn more

@hvitved hvitved added the no-change-note-required This PR does not need a change note label Apr 1, 2025
final string toString() {
result = this.toStringImpl() and
// recursion guard to prevent `toString` from being defined recursively
(exists(any(Element e).toStringImpl()) implies any())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we have a negated term that uses toStringImpl and not one that uses toString?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because that would be non-monotonic recursion :-) So the above prevents cases where toStringImpl calls toString.

Copy link
Contributor

@paldepind paldepind Apr 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Now I get it. We want to prevent toStringImpl from depending on toString and that's why we put toStringImpl there.

@hvitved hvitved merged commit ffb25b7 into github:main Apr 1, 2025
31 of 32 checks passed
@hvitved hvitved deleted the rust/to-string-non-rec branch April 1, 2025 13:31
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 Swift

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants