Skip to content

Commit 642bfbd

Browse files
committed
Shared: Make some generalizations in type inference library
1 parent 7cbaa11 commit 642bfbd

File tree

2 files changed

+279
-109
lines changed

2 files changed

+279
-109
lines changed

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

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1902,7 +1902,9 @@ private predicate isMethodCall(MethodCall mc, Type rootType, string name, int ar
19021902
arity = mc.getNumberOfArguments()
19031903
}
19041904

1905-
private module IsInstantiationOfInput implements IsInstantiationOfInputSig<MethodCall> {
1905+
private module IsInstantiationOfInput implements
1906+
IsInstantiationOfInputSig<MethodCall, TypeMentionTypeTree>
1907+
{
19061908
/** Holds if `mc` specifies a trait and might target a method in `impl`. */
19071909
pragma[nomagic]
19081910
private predicate methodCallTraitCandidate(MethodCall mc, Impl impl) {
@@ -1931,7 +1933,9 @@ private module IsInstantiationOfInput implements IsInstantiationOfInputSig<Metho
19311933
private TypeRepr getImplSelfTy(Impl impl) { result = impl.getSelfTy() }
19321934

19331935
pragma[nomagic]
1934-
predicate potentialInstantiationOf(MethodCall mc, TypeAbstraction impl, TypeMention constraint) {
1936+
predicate potentialInstantiationOf(
1937+
MethodCall mc, TypeAbstraction impl, TypeMentionTypeTree constraint
1938+
) {
19351939
constraint = getImplSelfTy(impl) and
19361940
(
19371941
methodCallTraitCandidate(mc, impl)
@@ -1950,7 +1954,7 @@ private module IsInstantiationOfInput implements IsInstantiationOfInputSig<Metho
19501954
)
19511955
}
19521956

1953-
predicate relevantTypeMention(TypeMention constraint) {
1957+
predicate relevantTypeMention(TypeMentionTypeTree constraint) {
19541958
exists(Impl impl | methodCandidate(_, _, _, impl) and constraint = impl.getSelfTy())
19551959
}
19561960
}
@@ -2111,14 +2115,16 @@ private predicate methodCallHasNoInherentTarget(MethodCall mc) {
21112115
methodCandidate(rootType, name, arity, impl) and
21122116
not impl.hasTrait()
21132117
|
2114-
IsInstantiationOf<MethodCall, IsInstantiationOfInput>::isNotInstantiationOf(mc, impl, _)
2118+
IsInstantiationOf<MethodCall, TypeMentionTypeTree, IsInstantiationOfInput>::isNotInstantiationOf(mc,
2119+
impl, _)
21152120
)
21162121
)
21172122
}
21182123

21192124
pragma[nomagic]
21202125
private predicate methodCallHasImplCandidate(MethodCall mc, Impl impl) {
2121-
IsInstantiationOf<MethodCall, IsInstantiationOfInput>::isInstantiationOf(mc, impl, _) and
2126+
IsInstantiationOf<MethodCall, TypeMentionTypeTree, IsInstantiationOfInput>::isInstantiationOf(mc,
2127+
impl, _) and
21222128
if impl.hasTrait() and not exists(mc.getTrait())
21232129
then
21242130
// inherent methods take precedence over trait methods, so only allow
@@ -2259,11 +2265,11 @@ private class AmbigousAssocFunctionCallExpr extends MkAmbigousAssocFunctionCallE
22592265
}
22602266

22612267
private module AmbigousAssocFuncIsInstantiationOfInput implements
2262-
IsInstantiationOfInputSig<AmbigousAssocFunctionCallExpr>
2268+
IsInstantiationOfInputSig<AmbigousAssocFunctionCallExpr, TypeMentionTypeTree>
22632269
{
22642270
pragma[nomagic]
22652271
predicate potentialInstantiationOf(
2266-
AmbigousAssocFunctionCallExpr ce, TypeAbstraction impl, TypeMention constraint
2272+
AmbigousAssocFunctionCallExpr ce, TypeAbstraction impl, TypeMentionTypeTree constraint
22672273
) {
22682274
exists(FunctionCallExpr call, Function resolved, Function cand, int pos |
22692275
ce = MkAmbigousAssocFunctionCallExpr(call, resolved, pos) and
@@ -2289,7 +2295,7 @@ private ItemNode resolveUnambigousFunctionCallTarget(FunctionCallExpr call) {
22892295
pragma[nomagic]
22902296
private Function resolveAmbigousFunctionCallTargetFromIndex(FunctionCallExpr call, int index) {
22912297
exists(Impl impl, int pos, Function resolved |
2292-
IsInstantiationOf<AmbigousAssocFunctionCallExpr, AmbigousAssocFuncIsInstantiationOfInput>::isInstantiationOf(MkAmbigousAssocFunctionCallExpr(call,
2298+
IsInstantiationOf<AmbigousAssocFunctionCallExpr, TypeMentionTypeTree, AmbigousAssocFuncIsInstantiationOfInput>::isInstantiationOf(MkAmbigousAssocFunctionCallExpr(call,
22932299
resolved, pos), impl, _) and
22942300
result = call.getAnAmbigousCandidateRanked(impl, pos, resolved, index)
22952301
|

0 commit comments

Comments
 (0)