-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Rust: Resolve function calls to traits methods #19575
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
051938a
to
e778cbe
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.
Lgtm
// trait bound on the type parameter. | ||
result = getTypeParameterMethod(receiver.getTypeAt(TypePath::nil()), receiver.getField()) | ||
) | ||
Function resolveMethodCallTarget(MethodCall mc) { |
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.
This resolveMethodCallTarget
was previously getStaticTarget
inside MethodCallExpr
. But since we now need for CallExpr
as well, I've moved it in here.
methodCandidateTrait(rootType, mc.getTrait(), name, arity, impl) | ||
or | ||
not exists(mc.getTrait()) and | ||
methodCandidate(rootType, name, arity, impl) |
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.
This new disjunct and methodCandidateTrait
is the crux of the change.
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.
LGTM. Let's wait for DCA before merging.
*/ | ||
pragma[nomagic] | ||
private predicate methodCandidateTrait(Type type, Trait trait, string name, int arity, Impl impl) { | ||
trait = resolvePath(impl.getTrait().(PathTypeRepr).getPath()) and |
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.
Alternatively, trait = resolvePath(impl.(ImplItemNode).getTraitPath())
DCA seems fine to me. "Missing call targets" went down, but I don't think these trait calls where counted as missing before (because there where resolved to the trait itself), so I think the reduction in missing call targets is a secondary effect since some types are now more accurate, and hence some normal method calls can now be resolved. |
This PR adds resolution for function calls to trait methods
ATrait::some_method(obj, ...)
.Key changes:
MethodCall
abstract class that is extended by the different types of expressions that can lead to method calls. Later this class can also be extended by overloaded operators that perform method calls.methodCandidateTrait
predicate, which is similar to the existingmethodCandidate
predicate but which also takes a trait that the method should come from.potentialInstantiationOf
now accounts both for method calls that target a specific trait.