Skip to content

Commit 3e6f66d

Browse files
committed
wip5
1 parent 1370921 commit 3e6f66d

File tree

1 file changed

+28
-14
lines changed

1 file changed

+28
-14
lines changed

rust/ql/lib/codeql/rust/internal/TypeInference.qll

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1161,18 +1161,32 @@ private module MethodCallResolution {
11611161
)
11621162
}
11631163

1164-
pragma[nomagic]
1165-
private predicate traitMethodInfo(string name, int arity, Trait trait) {
1166-
exists(ImplItemNode i |
1167-
methodInfo(_, name, arity, i, _, _, _) and
1168-
trait = i.resolveTraitTy()
1169-
)
1164+
/**
1165+
* todo
1166+
*
1167+
* Holds if method `f` with the name `name` and the arity `arity` exists in
1168+
* `i`, and the type of the `self` parameter is `selfType`.
1169+
*
1170+
* `rootTypePath` points to the type `rootType` inside `selfType`, which is
1171+
* the (possibly `&`-stripped) root type of `selfType`.
1172+
*/
1173+
pragma[inline]
1174+
predicate methodInfoMatch(
1175+
Function f, string name, int arity, ImplOrTraitItemNode i, FunctionType selfType,
1176+
TypePath rootTypePath, Type rootType
1177+
) {
1178+
methodInfo(f, name, arity, i, selfType, rootTypePath, rootType)
1179+
or
1180+
methodInfo(f, name, arity, i, selfType, rootTypePath, TTypeParamTypeParameter(_))
11701181
}
11711182

11721183
pragma[nomagic]
11731184
private predicate methodCallTraitCandidate(Element mc, Trait trait) {
11741185
exists(string name, int arity | mc.(MethodCall).isMethodCall(name, arity) |
1175-
traitMethodInfo(name, arity, trait)
1186+
exists(ImplItemNode i |
1187+
methodInfo(_, name, arity, i, _, _, _) and
1188+
trait = i.resolveTraitTy()
1189+
)
11761190
or
11771191
methodInfo(_, name, arity, trait, _, _, _)
11781192
)
@@ -1209,7 +1223,7 @@ private module MethodCallResolution {
12091223
) {
12101224
exists(string name, int arity |
12111225
mc.isMethodCall(name, arity) and
1212-
methodInfo(_, name, arity, i, self, rootTypePath, rootType)
1226+
methodInfoMatch(_, name, arity, i, self, rootTypePath, rootType)
12131227
|
12141228
i =
12151229
any(Impl impl |
@@ -1472,7 +1486,7 @@ private module MethodCallResolution {
14721486
this.isMethodCall(_, rootTypePath, rootType, name, arity) and
14731487
isRefStrippedRoot(rootTypePath, rootType) and
14741488
forall(Impl i |
1475-
methodInfo(_, name, arity, i, _, rootTypePath, rootType) and
1489+
methodInfoMatch(_, name, arity, i, _, rootTypePath, rootType) and
14761490
not i.hasTrait()
14771491
|
14781492
this.isNotInherentCandidate(i)
@@ -1883,7 +1897,7 @@ private module FunctionCallResolution {
18831897
exists(TypePath rootTypePath, Type rootType |
18841898
f = call.getPathResolutionResolvedFunctionOrImplementation(resolved) and
18851899
trait = call.(Call).getTrait() and
1886-
MethodCallResolution::methodInfo(f, _, _, i, self, rootTypePath, rootType) and
1900+
MethodCallResolution::methodInfoMatch(f, _, _, i, self, rootTypePath, rootType) and
18871901
call.getTypeAt(rootTypePath) = rootType
18881902
)
18891903
}
@@ -2178,12 +2192,12 @@ private module OperationResolution {
21782192
private module OperationIsInstantiationOfInput implements
21792193
IsInstantiationOfInputSig<Op, FunctionType>
21802194
{
2181-
pragma[nomagic]
2182-
private predicate methodInfo(
2195+
pragma[inline]
2196+
private predicate methodInfoMatch(
21832197
TypeAbstraction abs, FunctionType constraint, Trait trait, string name, int arity,
21842198
TypePath rootTypePath, Type rootType
21852199
) {
2186-
MethodCallResolution::methodInfo(_, name, arity, abs, constraint, rootTypePath, rootType) and
2200+
MethodCallResolution::methodInfoMatch(_, name, arity, abs, constraint, rootTypePath, rootType) and
21872201
(
21882202
trait = abs.(ImplItemNode).resolveTraitTy()
21892203
or
@@ -2195,7 +2209,7 @@ private module OperationResolution {
21952209
predicate potentialInstantiationOf(Op op, TypeAbstraction abs, FunctionType constraint) {
21962210
exists(Trait trait, string name, int arity, TypePath rootTypePath, Type rootType |
21972211
op.isOperation(rootTypePath, rootType, trait, name, arity) and
2198-
methodInfo(abs, constraint, trait, name, arity, rootTypePath, rootType)
2212+
methodInfoMatch(abs, constraint, trait, name, arity, rootTypePath, rootType)
21992213
)
22002214
}
22012215

0 commit comments

Comments
 (0)