Rust: Make Element.toString non-recursive#19162
Merged
hvitved merged 3 commits intogithub:mainfrom Apr 1, 2025
Merged
Conversation
054e943 to
0cd1f0f
Compare
65daa1a to
0548a96
Compare
f8d941d to
56f4694
Compare
Contributor
There was a problem hiding this comment.
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
paldepind
approved these changes
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()) |
Contributor
There was a problem hiding this comment.
Why do we have a negated term that uses toStringImpl and not one that uses toString?
Contributor
Author
There was a problem hiding this comment.
Because that would be non-monotonic recursion :-) So the above prevents cases where toStringImpl calls toString.
Contributor
There was a problem hiding this comment.
Thanks! Now I get it. We want to prevent toStringImpl from depending on toString and that's why we put toStringImpl there.
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR makes
Element.toStringnon-recursive again, and inserts a recursion guard that prevents unintented recursion throughToString(recursion is still possible, but has to go explicitly viaToStringImpl, as is the case in Swift).