-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Rust: Do not dispatch to all implementations when trait target is accurate #20969
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
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3522,12 +3522,27 @@ private module Cached { | |
| any(MethodResolution::MethodCall mc).argumentHasImplicitBorrow(n) | ||
| } | ||
|
|
||
| /** Gets an item (function or tuple struct/variant) that `call` resolves to, if any. */ | ||
| /** | ||
| * Gets an item (function or tuple struct/variant) that `call` resolves to, if | ||
| * any. | ||
| * | ||
| * The parameter `dispatch` is `true` if and only if the resolved target is a | ||
| * trait item because the a precise target could not be determined from the | ||
| * types (for instance in the presence of generics or `dyn` types) | ||
| */ | ||
| cached | ||
| Addressable resolveCallTarget(Expr call) { | ||
| result = call.(MethodResolution::MethodCall).resolveCallTarget(_, _, _) | ||
| Addressable resolveCallTarget(InvocationExpr call, boolean dispatch) { | ||
| dispatch = false and | ||
| result = call.(NonMethodResolution::NonMethodCall).resolveCallTargetViaPathResolution() | ||
| or | ||
| result = call.(NonMethodResolution::NonMethodCall).resolveCallTarget() | ||
| exists(ImplOrTraitItemNode i | | ||
| i instanceof TraitItemNode and dispatch = true | ||
| or | ||
| i instanceof ImplItemNode and dispatch = false | ||
| | | ||
| result = call.(MethodResolution::MethodCall).resolveCallTarget(i, _, _) or | ||
| result = call.(NonMethodResolution::NonMethodCall).resolveCallTargetViaTypeInference(i) | ||
| ) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For method calls, is it always resolved by type inference?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well, "method call" is a bit of an overloaded term now 😅 Syntactic method calls from Semantic methods calls (any expression that ends up calling a method, such as |
||
| } | ||
|
|
||
| /** | ||
|
|
@@ -3668,9 +3683,9 @@ private module Debug { | |
| result = inferType(n, path) | ||
| } | ||
|
|
||
| Addressable debugResolveCallTarget(InvocationExpr c) { | ||
| Addressable debugResolveCallTarget(InvocationExpr c, boolean dispatch) { | ||
| c = getRelevantLocatable() and | ||
| result = resolveCallTarget(c) | ||
| result = resolveCallTarget(c, dispatch) | ||
| } | ||
|
|
||
| predicate debugConditionSatisfiesConstraint( | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.