-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Rust: Rework type inference for method calls #20282
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
base: main
Are you sure you want to change the base?
Rust: Rework type inference for method calls #20282
Conversation
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.
CodeQL found more than 20 potential problems in the proposed changes. Check the Files changed tab for more details.
e4cfb86
to
4a8c37c
Compare
class State = string; | ||
|
||
// private newtype TAccess = | ||
// TMethodCallAccess(MethodCallDerefChainRef mcd) or |
Check warning
Code scanning / CodeQL
Dead code Warning
// // t0 = getTypeQualifier(this, path0) and | ||
// // apos.getArgumentPosition(false).isSelf() and | ||
// // exists(state) | ||
// // else ( |
Check warning
Code scanning / CodeQL
Dead code Warning
// ) | ||
// } | ||
// bindingset[state] | ||
// pragma[nomagic] |
Check warning
Code scanning / CodeQL
Dead code Warning
// .getParameterType(TArgumentDeclarationPosition(apos.getArgumentPosition()), | ||
// TypePath::nil()) | ||
// | | ||
// if selfParamType = TRefType() |
Check warning
Code scanning / CodeQL
Dead code Warning
|
||
pragma[nomagic] | ||
private Type getACandidateReceiverTypeAtNoMatch(TypePath path, string derefChain) { | ||
this.receiverImplicitlyBorrowed() and |
Check warning
Code scanning / CodeQL
Dead code Warning
private Type getACandidateReceiverTypeAtRef(TypePath path, string derefChain) { | ||
// exists(TypePath path0, Type t0, string derefChain | | ||
// t0 = this.getACandidateReceiverTypeAt(path0, derefChain) | ||
// | |
Check warning
Code scanning / CodeQL
Dead code Warning
|
||
pragma[nomagic] | ||
private Type testgetACandidateReceiverTypeAtRefNoMatch2( | ||
TypePath path, string derefChain, Type rootType, string name, int arity |
Check warning
Code scanning / CodeQL
Dead code Warning
|
||
pragma[nomagic] | ||
private Type testgetACandidateReceiverTypeRefsAt(TypePath path, string derefChain) { | ||
result = this.getACandidateReceiverTypeRefsAt(path, derefChain) and |
Check warning
Code scanning / CodeQL
Singleton set literal Warning
@@ -1087,10 +1094,11 @@ | |||
* For example, if this access is the method call `M(42)`, then the inferred | |||
* type at argument position `0` is `int`. | |||
*/ | |||
Type getInferredType(AccessPosition apos, TypePath path); | |||
bindingset[state] |
Check warning
Code scanning / CodeQL
Missing QLDoc for parameter Warning
4a8c37c
to
e75d79e
Compare
if | ||
apos.isReturn() and | ||
(this instanceof DerefExpr or this instanceof IndexExpr) | ||
then ( |
Check warning
Code scanning / CodeQL
Dead code Warning
} | ||
|
||
pragma[nomagic] | ||
private Type testgetACandidateReceiverTypeAtNoMatch(TypePath path, string derefChain) { |
Check warning
Code scanning / CodeQL
Dead code Warning
// not exists(resolveNonImplMethodCallTarget(rootType, name, arity)) | ||
) | ||
} | ||
|
Check warning
Code scanning / CodeQL
Dead code Warning
) | ||
) | ||
} | ||
|
||
bindingset[trait, name] | ||
pragma[inline_late] | ||
private Function getImplTraitMethod(ImplTraitReturnType trait, string name) { | ||
result = getMethodSuccessor(trait.getImplTraitTypeRepr(), name) | ||
private Function getImplTraitMethod(ImplTraitReturnType trait, string name, int arity) { |
Check warning
Code scanning / CodeQL
Dead code Warning
} | ||
|
||
bindingset[traitObject, name] | ||
pragma[inline_late] | ||
private Function getDynTraitMethod(DynTraitType traitObject, string name) { | ||
result = getMethodSuccessor(traitObject.getTrait(), name) | ||
private Function getDynTraitMethod(DynTraitType traitObject, string name, int arity) { |
Check warning
Code scanning / CodeQL
Dead code Warning
or | ||
bindingset[t, name, arity] | ||
pragma[inline_late] | ||
private Function resolveNonImplMethodCallTarget(Type t, string name, int arity) { |
Check warning
Code scanning / CodeQL
Dead code Warning
|
||
/** | ||
* Holds if `constraint` might occur as the third argument of | ||
* `potentialInstantiationOf`. Defaults to simply projecting the third | ||
* argument of `potentialInstantiationOf`. | ||
*/ | ||
default predicate relevantTypeMention(TypeMention tm) { potentialInstantiationOf(_, _, tm) } | ||
default predicate relevantTypeMention(Constraint tm) { potentialInstantiationOf(_, _, tm) } |
Check warning
Code scanning / CodeQL
Missing QLDoc for parameter Warning
c6385ca
to
1f79831
Compare
9376673
to
063aefe
Compare
61866bf
to
2d1ed65
Compare
bindingset[s] | ||
private predicate isBorrowed(string s) { exists(s.splitAt(";", 1)) } | ||
|
||
private predicate sdf() { isBorrowed(";ref") } |
Check warning
Code scanning / CodeQL
Dead code Warning
tAdj = t | ||
} | ||
pragma[nomagic] | ||
private Type testinferMethodCallExprType( |
Check warning
Code scanning / CodeQL
Dead code Warning
} | ||
|
||
private module CallExprBaseMatching = Matching<CallExprBaseMatchingInput>; | ||
private Type testinferMethodCallExprType0( |
Check warning
Code scanning / CodeQL
Dead code Warning
result = getFieldExprLookupType(fe, name) and | ||
pos = name.toInt() | ||
) | ||
private Type testinferMethodCallExprType(AstNode n, TypePath path) { |
Check warning
Code scanning / CodeQL
Dead code Warning
result = TTupleTypeParameter(arity, i) | ||
private Type inferMethodCallExprType(AstNode n, TypePath path) { | ||
exists( | ||
MethodCallExprMatchingInput::Access a, MethodCallExprMatchingInput::AccessPosition apos, |
Check warning
Code scanning / CodeQL
Omittable 'exists' variable Warning
in this argument
or | ||
exists(int pos, TypePath path, Type type | | ||
functionResolutionDependsOnArgument(impl, name, result, pos + 1, pragma[only_bind_into](path), | ||
type) and |
Check warning
Code scanning / CodeQL
Dead code Warning
or | ||
exists(int pos0 | constraint = cand.getParam(pos0).getTypeRepr() | | ||
if cand.getParamList().hasSelfParam() then pos = pos0 + 1 else pos = pos0 | ||
) |
Check warning
Code scanning / CodeQL
Dead code Warning
2d1ed65
to
3d19a06
Compare
3d19a06
to
153c10b
Compare
153c10b
to
e161d4c
Compare
MethodCallDerefChainRef mc, TypeAbstraction abs, SelfParamType constraint | ||
) { | ||
// mc.getMethodCall() = Debug::getRelevantLocatable() and | ||
exists(Type rootType, string name, int arity, MethodCall mc0 | |
Check warning
Code scanning / CodeQL
Omittable 'exists' variable Warning
in this argument
op = Debug::getRelevantLocatable() | ||
} | ||
|
||
private Function testresolveOperation(Op op, ImplOrTraitItemNode impl, string name) { |
Check warning
Code scanning / CodeQL
Dead code Warning
|
||
/** Gets a method from an `impl` block that matches the method call `mc`. */ | ||
pragma[nomagic] | ||
private Function resolveOperation(Op op) { |
Check warning
Code scanning / CodeQL
Missing QLDoc for parameter Warning
No description provided.