-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Rust: Handle self
parameters in variables and SSA library
#18088
Conversation
f4ab6a3
to
d06b583
Compare
self
parameters in variables and SSA library
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.
I assume you also meant to add a commit for supporting self
variables, and not just a test?
PR now updated with the actual commit that it was supposed to contain 😅 |
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.
Looks great, some minor comments.
// exclude parameters from function pointer types (e.g. `x` in `fn(x: i32) -> i32`) | ||
not exists(FnPtrType fp | fp.getParamList().getParam(_).getPat() = p) | ||
private predicate variableDecl(AstNode definingNode, AstNode p, string name) { | ||
exists(SelfParam sp | sp = p | |
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.
For patterns like this, I prefer p = any(SelfParam sp |
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.
That is definitely nicer to read!
not exists(Function f | not f.hasBody() and f.getParamList().getSelfParam() = sp) | ||
) | ||
or | ||
exists(IdentPat pat | pat = p | |
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.
Same
/** | ||
* Gets the pattern that declares this variable. | ||
* Gets the pattern that declares this variable, if one exists. |
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.
Nit: The standard phrasing tends to be "if any".
@@ -135,7 +147,9 @@ module Impl { | |||
predicate isCaptured() { this.getAnAccess().isCapture() } | |||
|
|||
/** Gets the parameter that introduces this variable, if any. */ | |||
Param getParameter() { parameterDeclInScope(result, this, _) } | |||
ParamBase getParameter() { | |||
result = this.getSelfParam() or result = getAVariablePatAncestor(this).getParentNode() |
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.
Relying on getParentNode()
is generally not good, as it is basically an untyped interface. So I would prefer if we could revert it back to using parameterDeclInScope
.
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.
I've now removed getParentNode
on the rhs. and added getPat
on the lhs.
DCA looks fine. Thanks for starting the run. |
Changes in this PR:
self
parameters as variables.