-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Rust: Make Element.toString
non-recursive
#19162
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
Conversation
054e943
to
0cd1f0f
Compare
65daa1a
to
0548a96
Compare
f8d941d
to
56f4694
Compare
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.
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
final string toString() { | ||
result = this.toStringImpl() and | ||
// recursion guard to prevent `toString` from being defined recursively | ||
(exists(any(Element e).toStringImpl()) implies any()) |
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.
Why do we have a negated term that uses toStringImpl
and not one that uses toString
?
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.
Because that would be non-monotonic recursion :-) So the above prevents cases where toStringImpl
calls toString
.
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! Now I get it. We want to prevent toStringImpl
from depending on toString
and that's why we put toStringImpl
there.
This PR makes
Element.toString
non-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).