Skip to content

Commit 125cc91

Browse files
authored
Merge pull request #20358 from hvitved/shared/type-inference-generalize
Shared: Make some generalizations in type inference library
2 parents b34fa7a + e3e1bcd commit 125cc91

File tree

2 files changed

+285
-110
lines changed

2 files changed

+285
-110
lines changed

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

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

1913-
private module IsInstantiationOfInput implements IsInstantiationOfInputSig<MethodCall> {
1913+
private module IsInstantiationOfInput implements
1914+
IsInstantiationOfInputSig<MethodCall, TypeMentionTypeTree>
1915+
{
19141916
/** Holds if `mc` specifies a trait and might target a method in `impl`. */
19151917
pragma[nomagic]
19161918
private predicate methodCallTraitCandidate(MethodCall mc, Impl impl) {
@@ -1939,7 +1941,9 @@ private module IsInstantiationOfInput implements IsInstantiationOfInputSig<Metho
19391941
private TypeRepr getImplSelfTy(Impl impl) { result = impl.getSelfTy() }
19401942

19411943
pragma[nomagic]
1942-
predicate potentialInstantiationOf(MethodCall mc, TypeAbstraction impl, TypeMention constraint) {
1944+
predicate potentialInstantiationOf(
1945+
MethodCall mc, TypeAbstraction impl, TypeMentionTypeTree constraint
1946+
) {
19431947
constraint = getImplSelfTy(impl) and
19441948
(
19451949
methodCallTraitCandidate(mc, impl)
@@ -1958,7 +1962,7 @@ private module IsInstantiationOfInput implements IsInstantiationOfInputSig<Metho
19581962
)
19591963
}
19601964

1961-
predicate relevantTypeMention(TypeMention constraint) {
1965+
predicate relevantTypeMention(TypeMentionTypeTree constraint) {
19621966
exists(Impl impl | methodCandidate(_, _, _, impl) and constraint = impl.getSelfTy())
19631967
}
19641968
}
@@ -2119,14 +2123,16 @@ private predicate methodCallHasNoInherentTarget(MethodCall mc) {
21192123
methodCandidate(rootType, name, arity, impl) and
21202124
not impl.hasTrait()
21212125
|
2122-
IsInstantiationOf<MethodCall, IsInstantiationOfInput>::isNotInstantiationOf(mc, impl, _)
2126+
IsInstantiationOf<MethodCall, TypeMentionTypeTree, IsInstantiationOfInput>::isNotInstantiationOf(mc,
2127+
impl, _)
21232128
)
21242129
)
21252130
}
21262131

21272132
pragma[nomagic]
21282133
private predicate methodCallHasImplCandidate(MethodCall mc, Impl impl) {
2129-
IsInstantiationOf<MethodCall, IsInstantiationOfInput>::isInstantiationOf(mc, impl, _) and
2134+
IsInstantiationOf<MethodCall, TypeMentionTypeTree, IsInstantiationOfInput>::isInstantiationOf(mc,
2135+
impl, _) and
21302136
if impl.hasTrait() and not exists(mc.getTrait())
21312137
then
21322138
// inherent methods take precedence over trait methods, so only allow
@@ -2267,11 +2273,11 @@ private class AmbigousAssocFunctionCallExpr extends MkAmbigousAssocFunctionCallE
22672273
}
22682274

22692275
private module AmbigousAssocFuncIsInstantiationOfInput implements
2270-
IsInstantiationOfInputSig<AmbigousAssocFunctionCallExpr>
2276+
IsInstantiationOfInputSig<AmbigousAssocFunctionCallExpr, TypeMentionTypeTree>
22712277
{
22722278
pragma[nomagic]
22732279
predicate potentialInstantiationOf(
2274-
AmbigousAssocFunctionCallExpr ce, TypeAbstraction impl, TypeMention constraint
2280+
AmbigousAssocFunctionCallExpr ce, TypeAbstraction impl, TypeMentionTypeTree constraint
22752281
) {
22762282
exists(FunctionCallExpr call, Function resolved, Function cand, int pos |
22772283
ce = MkAmbigousAssocFunctionCallExpr(call, resolved, pos) and
@@ -2297,7 +2303,7 @@ private ItemNode resolveUnambigousFunctionCallTarget(FunctionCallExpr call) {
22972303
pragma[nomagic]
22982304
private Function resolveAmbigousFunctionCallTargetFromIndex(FunctionCallExpr call, int index) {
22992305
exists(Impl impl, int pos, Function resolved |
2300-
IsInstantiationOf<AmbigousAssocFunctionCallExpr, AmbigousAssocFuncIsInstantiationOfInput>::isInstantiationOf(MkAmbigousAssocFunctionCallExpr(call,
2306+
IsInstantiationOf<AmbigousAssocFunctionCallExpr, TypeMentionTypeTree, AmbigousAssocFuncIsInstantiationOfInput>::isInstantiationOf(MkAmbigousAssocFunctionCallExpr(call,
23012307
resolved, pos), impl, _) and
23022308
result = call.getAnAmbigousCandidateRanked(impl, pos, resolved, index)
23032309
|

0 commit comments

Comments
 (0)