Skip to content

Commit 7919221

Browse files
committed
wip
1 parent 1c184fd commit 7919221

File tree

1 file changed

+33
-31
lines changed

1 file changed

+33
-31
lines changed

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

Lines changed: 33 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1262,7 +1262,7 @@ private predicate assocFunctionInfo(
12621262
* is the type parameter used in the blanket implementation.
12631263
*/
12641264
pragma[nomagic]
1265-
private predicate functionInfoBlanketLike(
1265+
private predicate assocFunctionInfoBlanketLike(
12661266
Function f, string name, int arity, ImplItemNode impl, Trait trait, FunctionPosition pos,
12671267
AssocFunctionType t, TypePath blanketPath, TypeParam blanketTypeParam
12681268
) {
@@ -1366,85 +1366,86 @@ private class BorrowKind extends TBorrowKind {
13661366
*/
13671367
private module MethodResolution {
13681368
/**
1369-
* Holds if method `m` with the name `name` and the arity `arity` exists in
1369+
* Holds if function `f` with the name `name` and the arity `arity` exists in
13701370
* `i`, and the type of the `self` parameter is `selfType`.
13711371
*
13721372
* `strippedTypePath` points to the type `strippedType` inside `selfType`,
13731373
* which is the (possibly complex-stripped) root type of `selfType`. For example,
1374-
* if `m` has a `&self` parameter, then `strippedTypePath` is `getRefSharedTypeParameter()`
1374+
* if `f` has a `&self` parameter, then `strippedTypePath` is `getRefSharedTypeParameter()`
13751375
* and `strippedType` is the type inside the reference.
13761376
*/
13771377
pragma[nomagic]
1378-
private predicate methodInfo(
1379-
Method m, string name, int arity, FunctionPosition selfPos, ImplOrTraitItemNode i,
1378+
private predicate assocFunctionInfo(
1379+
Function f, string name, int arity, FunctionPosition selfPos, ImplOrTraitItemNode i,
13801380
AssocFunctionType selfType, TypePath strippedTypePath, Type strippedType
13811381
) {
1382-
assocFunctionInfo(m, name, arity, i, selfPos, selfType) and
1382+
assocFunctionInfo(f, name, arity, i, selfPos, selfType) and
13831383
strippedType = selfType.getTypeAt(strippedTypePath) and
13841384
isComplexRootStripped(strippedTypePath, strippedType) and
13851385
selfPos.isSelfOrTypeQualifier()
13861386
}
13871387

13881388
pragma[nomagic]
1389-
private predicate methodInfoTypeParam(
1390-
Method m, string name, int arity, FunctionPosition selfPos, ImplOrTraitItemNode i,
1389+
private predicate assocFunctionInfoTypeParam(
1390+
Function f, string name, int arity, FunctionPosition selfPos, ImplOrTraitItemNode i,
13911391
AssocFunctionType selfType, TypePath strippedTypePath, TypeParam tp
13921392
) {
1393-
methodInfo(m, name, arity, selfPos, i, selfType, strippedTypePath, TTypeParamTypeParameter(tp))
1393+
assocFunctionInfo(f, name, arity, selfPos, i, selfType, strippedTypePath,
1394+
TTypeParamTypeParameter(tp))
13941395
}
13951396

13961397
/**
1397-
* Same as `methodInfo`, but restricted to non-blanket implementations, and
1398-
* allowing for any `strippedType` when the corresponding type inside `m` is
1398+
* Same as `assocFunctionInfo`, but restricted to non-blanket implementations, and
1399+
* allowing for any `strippedType` when the corresponding type inside `f` is
13991400
* a type parameter.
14001401
*/
14011402
pragma[inline]
1402-
private predicate methodInfoNonBlanket(
1403-
Method m, string name, int arity, FunctionPosition selfPos, ImplOrTraitItemNode i,
1403+
private predicate assocFunctionInfoNonBlanket(
1404+
Function f, string name, int arity, FunctionPosition selfPos, ImplOrTraitItemNode i,
14041405
AssocFunctionType selfType, TypePath strippedTypePath, Type strippedType
14051406
) {
14061407
(
1407-
methodInfo(m, name, arity, selfPos, i, selfType, strippedTypePath, strippedType) or
1408-
methodInfoTypeParam(m, name, arity, selfPos, i, selfType, strippedTypePath, _)
1408+
assocFunctionInfo(f, name, arity, selfPos, i, selfType, strippedTypePath, strippedType) or
1409+
assocFunctionInfoTypeParam(f, name, arity, selfPos, i, selfType, strippedTypePath, _)
14091410
) and
14101411
not BlanketImplementation::isBlanketLike(i, _, _)
14111412
}
14121413

14131414
/**
1414-
* Holds if method `m` with the name `name` and the arity `arity` exists in
1415+
* Holds if function `f` with the name `name` and the arity `arity` exists in
14151416
* blanket (like) implementation `impl` of `trait`, and the type of the `self`
14161417
* parameter is `selfType`.
14171418
*
14181419
* `blanketPath` points to the type `blanketTypeParam` inside `selfType`, which
14191420
* is the type parameter used in the blanket implementation.
14201421
*/
14211422
pragma[nomagic]
1422-
private predicate methodInfoBlanketLike(
1423-
Method m, string name, int arity, FunctionPosition selfPos, ImplItemNode impl, Trait trait,
1423+
private predicate assocFunctionSelfInfoBlanketLike(
1424+
Function f, string name, int arity, FunctionPosition selfPos, ImplItemNode impl, Trait trait,
14241425
AssocFunctionType selfType, TypePath blanketPath, TypeParam blanketTypeParam
14251426
) {
1426-
functionInfoBlanketLike(m, name, arity, impl, trait, selfPos, selfType, blanketPath,
1427+
assocFunctionInfoBlanketLike(f, name, arity, impl, trait, selfPos, selfType, blanketPath,
14271428
blanketTypeParam) and
14281429
selfPos.isSelfOrTypeQualifier()
14291430
}
14301431

14311432
pragma[nomagic]
1432-
private predicate methodTraitInfo(string name, int arity, Trait trait) {
1433+
private predicate assocFunctionTraitInfo(string name, int arity, Trait trait) {
14331434
exists(ImplItemNode i |
1434-
methodInfo(_, name, arity, _, i, _, _, _) and
1435+
assocFunctionInfo(_, name, arity, _, i, _, _, _) and
14351436
trait = i.resolveTraitTy()
14361437
)
14371438
or
1438-
methodInfo(_, name, arity, _, trait, _, _, _)
1439+
assocFunctionInfo(_, name, arity, _, trait, _, _, _)
14391440
}
14401441

14411442
pragma[nomagic]
1442-
private predicate methodCallTraitCandidate(Element mc, Trait trait) {
1443+
private predicate assocFunctionCallTraitCandidate(Element mc, Trait trait) {
14431444
mc =
14441445
any(MethodCall mc0 |
14451446
exists(string name, int arity |
14461447
mc0.hasNameAndArity(name, arity) and
1447-
methodTraitInfo(name, arity, trait)
1448+
assocFunctionTraitInfo(name, arity, trait)
14481449
|
14491450
not mc0.hasTrait()
14501451
or
@@ -1453,7 +1454,7 @@ private module MethodResolution {
14531454
)
14541455
}
14551456

1456-
private module MethodTraitIsVisible = TraitIsVisible<methodCallTraitCandidate/2>;
1457+
private module MethodTraitIsVisible = TraitIsVisible<assocFunctionCallTraitCandidate/2>;
14571458

14581459
private predicate methodCallVisibleTraitCandidate = MethodTraitIsVisible::traitIsVisible/2;
14591460

@@ -1482,7 +1483,7 @@ private module MethodResolution {
14821483
) {
14831484
exists(string name, int arity |
14841485
mc.hasNameAndArity(name, arity) and
1485-
methodInfoNonBlanket(m, name, arity, selfPos, i, self, strippedTypePath, strippedType)
1486+
assocFunctionInfoNonBlanket(m, name, arity, selfPos, i, self, strippedTypePath, strippedType)
14861487
|
14871488
i =
14881489
any(Impl impl |
@@ -1516,7 +1517,8 @@ private module MethodResolution {
15161517
) {
15171518
exists(string name, int arity |
15181519
mc.hasNameAndArity(name, arity) and
1519-
methodInfoBlanketLike(m, name, arity, selfPos, impl, _, self, blanketPath, blanketTypeParam)
1520+
assocFunctionSelfInfoBlanketLike(m, name, arity, selfPos, impl, _, self, blanketPath,
1521+
blanketTypeParam)
15201522
|
15211523
methodCallVisibleImplTraitCandidate(mc, impl)
15221524
or
@@ -2170,7 +2172,7 @@ private module MethodResolution {
21702172
exists(TypePath strippedTypePath, Type strippedType, string name, int arity |
21712173
this.hasSignature(_, selfPos, strippedTypePath, strippedType, name, arity) and
21722174
forall(Impl i |
2173-
methodInfoNonBlanket(_, name, arity, selfPos, i, _, strippedTypePath, strippedType) and
2175+
assocFunctionInfoNonBlanket(_, name, arity, selfPos, i, _, strippedTypePath, strippedType) and
21742176
not i.hasTrait()
21752177
|
21762178
this.hasIncompatibleInherentTarget(i)
@@ -2340,7 +2342,7 @@ private module MethodResolution {
23402342
}
23412343

23422344
predicate relevantConstraint(AssocFunctionType constraint) {
2343-
methodInfo(_, _, _, _, _, constraint, _, _) // todo
2345+
assocFunctionInfo(_, _, _, _, _, constraint, _, _) // todo
23442346
}
23452347
}
23462348

@@ -2755,14 +2757,14 @@ private module NonMethodResolution {
27552757
NonMethodFunction f, string name, int arity, ImplItemNode impl, Trait trait,
27562758
FunctionPosition pos, AssocFunctionType t, TypePath blanketPath, TypeParam blanketTypeParam
27572759
) {
2758-
functionInfoBlanketLike(f, name, arity, impl, trait, pos, t, blanketPath, blanketTypeParam) and
2760+
assocFunctionInfoBlanketLike(f, name, arity, impl, trait, pos, t, blanketPath, blanketTypeParam) and
27592761
(
27602762
if pos.isReturn()
27612763
then
27622764
// We only check that the context of the call provides relevant type information
27632765
// when no argument can
27642766
not exists(FunctionPosition pos0 |
2765-
functionInfoBlanketLike(f, name, arity, impl, trait, pos0, _, _, _) and
2767+
assocFunctionInfoBlanketLike(f, name, arity, impl, trait, pos0, _, _, _) and
27662768
not pos0.isReturn()
27672769
)
27682770
else any()

0 commit comments

Comments
 (0)