Skip to content

Commit 452d307

Browse files
committed
Rust: Make TypeMention directly satisfy HasTypeTree
1 parent 7100ca4 commit 452d307

File tree

8 files changed

+83
-92
lines changed

8 files changed

+83
-92
lines changed

rust/ql/lib/codeql/rust/dataflow/internal/ModelsAsData.qll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ private module Debug {
224224
sc.propagatesFlow(input, _, _, _) and
225225
input.head() = SummaryComponent::argument(pos) and
226226
p = pos.getParameterIn(sc.getParamList()) and
227-
tm.resolveType() instanceof RefType and
227+
tm.getType() instanceof RefType and
228228
not input.tail().head() = SummaryComponent::content(TSingletonContentSet(TReferenceContent()))
229229
|
230230
tm = p.getTypeRepr()
@@ -239,7 +239,7 @@ private module Debug {
239239
exists(TypeMention tm |
240240
relevantManualModel(sc, can) and
241241
sc.propagatesFlow(_, output, _, _) and
242-
tm.resolveType() instanceof RefType and
242+
tm.getType() instanceof RefType and
243243
output.head() = SummaryComponent::return(_) and
244244
not output.tail().head() =
245245
SummaryComponent::content(TSingletonContentSet(TReferenceContent())) and

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ predicate isBlanketLike(ImplItemNode i, TypePath blanketSelfPath, TypeParam blan
4747
exists(TypeMention tm, Type root, TypeParameter tp |
4848
tm = i.(Impl).getSelfTy() and
4949
complexSelfRoot(root, tp) and
50-
tm.resolveType() = root and
51-
tm.resolveTypeAt(blanketSelfPath) = TTypeParamTypeParameter(blanketTypeParam) and
50+
tm.getType() = root and
51+
tm.getTypeAt(blanketSelfPath) = TTypeParamTypeParameter(blanketTypeParam) and
5252
blanketSelfPath = TypePath::singleton(tp) and
5353
hasFirstNonTrivialTraitBound(blanketTypeParam, _)
5454
)

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ class DerefImplItemNode extends ImplItemNode {
2525
*/
2626
pragma[nomagic]
2727
predicate targetHasTypeParameterAt(TypePath path) {
28-
this.getAssocItem("Target").(TypeAlias).getTypeRepr().(TypeMention).resolveTypeAt(path)
29-
instanceof TypeParameter
28+
this.getAssocItem("Target").(TypeAlias).getTypeRepr().(TypeMention).getTypeAt(path) instanceof
29+
TypeParameter
3030
}
3131

3232
/** Gets the first type parameter of the type being implemented, if any. */

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ private import FunctionType
1515

1616
pragma[nomagic]
1717
private Type resolveNonTypeParameterTypeAt(TypeMention tm, TypePath path) {
18-
result = tm.resolveTypeAt(path) and
18+
result = tm.getTypeAt(path) and
1919
not result instanceof TypeParameter
2020
}
2121

@@ -32,7 +32,7 @@ private predicate implSiblingCandidate(
3232
) {
3333
trait = impl.(ImplItemNode).resolveTraitTy() and
3434
selfTy = impl.getSelfTy() and
35-
rootType = selfTy.resolveType()
35+
rootType = selfTy.getType()
3636
}
3737

3838
pragma[nomagic]

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,12 +103,12 @@ Type getAssocFunctionTypeAt(Function f, ImplOrTraitItemNode i, FunctionPosition
103103
// No specialization needed when the function is directly in the trait or
104104
// impl block or the declared type is not a type parameter
105105
(parent = i or not result instanceof TypeParameter) and
106-
result = pos.getTypeMention(f).resolveTypeAt(path)
106+
result = pos.getTypeMention(f).getTypeAt(path)
107107
or
108108
exists(TypePath prefix, TypePath suffix, TypeParameter tp, TypeMention constraint |
109109
BaseTypes::rootTypesSatisfaction(_, TTrait(parent), i, _, constraint) and
110110
path = prefix.append(suffix) and
111-
tp = pos.getTypeMention(f).resolveTypeAt(prefix) and
111+
tp = pos.getTypeMention(f).getTypeAt(prefix) and
112112
if tp = TSelfTypeParameter(_)
113113
then result = resolveImplOrTraitType(i, suffix)
114114
else result = getTraitConstraintTypeAt(i, constraint, tp, suffix)

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

Lines changed: 34 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -134,11 +134,11 @@ class TypePath = M1::TypePath;
134134

135135
module TypePath = M1::TypePath;
136136

137-
private module Input2 implements InputSig2<TypeMentionTypeTree> {
138-
TypeMentionTypeTree getABaseTypeMention(Type t) { none() }
137+
private module Input2 implements InputSig2<TypeMention> {
138+
TypeMention getABaseTypeMention(Type t) { none() }
139139

140140
Type getATypeParameterConstraint(TypeParameter tp, TypePath path) {
141-
exists(TypeMention tm | result = tm.resolveTypeAt(path) |
141+
exists(TypeMention tm | result = tm.getTypeAt(path) |
142142
tm = tp.(TypeParamTypeParameter).getTypeParam().getATypeBound().getTypeRepr() or
143143
tm = tp.(SelfTypeParameter).getTrait() or
144144
tm =
@@ -158,8 +158,7 @@ private module Input2 implements InputSig2<TypeMentionTypeTree> {
158158
* inference module for more information.
159159
*/
160160
predicate conditionSatisfiesConstraint(
161-
TypeAbstraction abs, TypeMentionTypeTree condition, TypeMentionTypeTree constraint,
162-
boolean transitive
161+
TypeAbstraction abs, TypeMention condition, TypeMention constraint, boolean transitive
163162
) {
164163
// `impl` blocks implementing traits
165164
transitive = false and
@@ -209,7 +208,7 @@ private module Input2 implements InputSig2<TypeMentionTypeTree> {
209208
}
210209
}
211210

212-
private module M2 = Make2<TypeMentionTypeTree, Input2>;
211+
private module M2 = Make2<TypeMention, Input2>;
213212

214213
import M2
215214

@@ -228,7 +227,7 @@ module Consistency {
228227
// mention for the self type has multiple types for a path.
229228
not exists(ImplItemNode impl, TypePath selfTypePath |
230229
n = impl.getAnAssocItem().(Function).getSelfParam() and
231-
strictcount(impl.(Impl).getSelfTy().(TypeMention).resolveTypeAt(selfTypePath)) > 1
230+
strictcount(impl.(Impl).getSelfTy().(TypeMention).getTypeAt(selfTypePath)) > 1
232231
)
233232
}
234233
}
@@ -294,7 +293,7 @@ private class FunctionDeclaration extends Function {
294293
result = getAssocFunctionTypeAt(this, i.asSome(), pos, path)
295294
or
296295
i.isNone() and
297-
result = this.getParam(pos.asPosition()).getTypeRepr().(TypeMention).resolveTypeAt(path)
296+
result = this.getParam(pos.asPosition()).getTypeRepr().(TypeMention).getTypeAt(path)
298297
)
299298
}
300299

@@ -305,7 +304,7 @@ private class FunctionDeclaration extends Function {
305304
getAssocFunctionTypeAt(this, i.asSome(), any(FunctionPosition pos | pos.isReturn()), path)
306305
or
307306
i.isNone() and
308-
result = getReturnTypeMention(this).resolveTypeAt(path)
307+
result = getReturnTypeMention(this).getTypeAt(path)
309308
)
310309
}
311310

@@ -349,12 +348,12 @@ private TypeMention getCallExprTypeMentionArgument(CallExpr ce, TypeArgumentPosi
349348

350349
pragma[nomagic]
351350
private Type getCallExprTypeArgument(CallExpr ce, TypeArgumentPosition apos, TypePath path) {
352-
result = getCallExprTypeMentionArgument(ce, apos).resolveTypeAt(path)
351+
result = getCallExprTypeMentionArgument(ce, apos).getTypeAt(path)
353352
or
354353
// Handle constructions that use `Self(...)` syntax
355354
exists(Path p, TypePath path0 |
356355
p = CallExprImpl::getFunctionPath(ce) and
357-
result = p.(TypeMention).resolveTypeAt(path0) and
356+
result = p.(TypeMention).getTypeAt(path0) and
358357
path0.isCons(TTypeParamTypeParameter(apos.asTypeParam()), path)
359358
)
360359
}
@@ -377,16 +376,16 @@ private TypeMention getTypeAnnotation(AstNode n) {
377376
/** Gets the type of `n`, which has an explicit type annotation. */
378377
pragma[nomagic]
379378
private Type inferAnnotatedType(AstNode n, TypePath path) {
380-
result = getTypeAnnotation(n).resolveTypeAt(path)
379+
result = getTypeAnnotation(n).getTypeAt(path)
381380
or
382-
result = n.(ShorthandSelfParameterMention).resolveTypeAt(path)
381+
result = n.(ShorthandSelfParameterMention).getTypeAt(path)
383382
}
384383

385384
pragma[nomagic]
386385
private Type inferFunctionBodyType(AstNode n, TypePath path) {
387386
exists(Function f |
388387
n = f.getFunctionBody() and
389-
result = getReturnTypeMention(f).resolveTypeAt(path) and
388+
result = getReturnTypeMention(f).getTypeAt(path) and
390389
not exists(ImplTraitReturnType i | i.getFunction() = f |
391390
result = i or result = i.getATypeParameter()
392391
)
@@ -430,7 +429,7 @@ module CertainTypeInference {
430429
private TypePath getPathToImplSelfTypeParam(TypeParam tp) {
431430
exists(ImplItemNode impl |
432431
tp = impl.getTypeParam(_) and
433-
TTypeParamTypeParameter(tp) = impl.(Impl).getSelfTy().(TypeMention).resolveTypeAt(result)
432+
TTypeParamTypeParameter(tp) = impl.(Impl).getSelfTy().(TypeMention).getTypeAt(result)
434433
)
435434
}
436435

@@ -446,7 +445,7 @@ module CertainTypeInference {
446445
// and the path `Foo<i64>::bar` we must resolve `A` to `i64`.
447446
exists(TypePath pathToTp |
448447
pathToTp = getPathToImplSelfTypeParam(tp) and
449-
result = p.getQualifier().(TypeMention).resolveTypeAt(pathToTp.appendInverse(suffix))
448+
result = p.getQualifier().(TypeMention).getTypeAt(pathToTp.appendInverse(suffix))
450449
)
451450
or
452451
// For type parameters of the function we must resolve their
@@ -462,11 +461,11 @@ module CertainTypeInference {
462461
}
463462

464463
private Type inferCertainStructExprType(StructExpr se, TypePath path) {
465-
result = se.getPath().(TypeMention).resolveTypeAt(path)
464+
result = se.getPath().(TypeMention).getTypeAt(path)
466465
}
467466

468467
private Type inferCertainStructPatType(StructPat sp, TypePath path) {
469-
result = sp.getPath().(TypeMention).resolveTypeAt(path)
468+
result = sp.getPath().(TypeMention).getTypeAt(path)
470469
}
471470

472471
predicate certainTypeEquality(AstNode n1, TypePath prefix1, AstNode n2, TypePath prefix2) {
@@ -902,7 +901,7 @@ private module StructExprMatchingInput implements MatchingInputSig {
902901
// type of a field
903902
exists(TypeMention tp |
904903
tp = this.getField(dpos.asFieldPos()).getTypeRepr() and
905-
result = tp.resolveTypeAt(path)
904+
result = tp.getTypeAt(path)
906905
)
907906
or
908907
// type parameter of the struct itself
@@ -955,7 +954,7 @@ private module StructExprMatchingInput implements MatchingInputSig {
955954
// Handle constructions that use `Self {...}` syntax
956955
exists(TypeMention tm, TypePath path0 |
957956
tm = this.getStructPath() and
958-
result = tm.resolveTypeAt(path0) and
957+
result = tm.getTypeAt(path0) and
959958
path0.isCons(TTypeParamTypeParameter(apos.asTypeParam()), path)
960959
)
961960
}
@@ -1065,7 +1064,7 @@ pragma[nomagic]
10651064
private Type getCallExprTypeQualifier(CallExpr ce, TypePath path) {
10661065
exists(TypeMention tm |
10671066
tm = getCallExprPathQualifier(ce) and
1068-
result = tm.resolveTypeAt(path) and
1067+
result = tm.getTypeAt(path) and
10691068
not resolvePath(tm) instanceof Trait
10701069
)
10711070
}
@@ -2327,19 +2326,19 @@ private module MethodResolution {
23272326
* instance of the type being implemented.
23282327
*/
23292328
private module TypeQualifierIsInstantiationOfImplSelfInput implements
2330-
IsInstantiationOfInputSig<MethodCallCallExpr, TypeMentionTypeTree>
2329+
IsInstantiationOfInputSig<MethodCallCallExpr, TypeMention>
23312330
{
23322331
pragma[nomagic]
23332332
private predicate potentialInstantiationOf0(
2334-
MethodCallCallExpr ce, ImplItemNode impl, TypeMentionTypeTree constraint
2333+
MethodCallCallExpr ce, ImplItemNode impl, TypeMention constraint
23352334
) {
23362335
ce.hasTypeQualifiedCandidate(impl) and
23372336
constraint = impl.getSelfPath()
23382337
}
23392338

23402339
pragma[nomagic]
23412340
predicate potentialInstantiationOf(
2342-
MethodCallCallExpr ce, TypeAbstraction abs, TypeMentionTypeTree constraint
2341+
MethodCallCallExpr ce, TypeAbstraction abs, TypeMention constraint
23432342
) {
23442343
potentialInstantiationOf0(ce, abs, constraint) and
23452344
if abs.(Impl).hasTrait()
@@ -2350,14 +2349,13 @@ private module MethodResolution {
23502349
else any()
23512350
}
23522351

2353-
predicate relevantConstraint(TypeMentionTypeTree constraint) {
2352+
predicate relevantConstraint(TypeMention constraint) {
23542353
potentialInstantiationOf0(_, _, constraint)
23552354
}
23562355
}
23572356

23582357
private module TypeQualifierIsInstantiationOfImplSelf =
2359-
IsInstantiationOf<MethodCallCallExpr, TypeMentionTypeTree,
2360-
TypeQualifierIsInstantiationOfImplSelfInput>;
2358+
IsInstantiationOf<MethodCallCallExpr, TypeMention, TypeQualifierIsInstantiationOfImplSelfInput>;
23612359

23622360
/**
23632361
* A configuration for anti-matching the type of a receiver against the type of
@@ -2478,7 +2476,7 @@ private module MethodCallMatchingInput implements MatchingWithEnvironmentInputSi
24782476
.getGenericArgList()
24792477
.getTypeArg(apos.asMethodTypeArgumentPosition())
24802478
.(TypeMention)
2481-
.resolveTypeAt(path)
2479+
.getTypeAt(path)
24822480
or
24832481
result = getCallExprTypeArgument(this, apos, path)
24842482
}
@@ -3009,7 +3007,7 @@ abstract private class TupleLikeConstructor extends Addressable {
30093007
}
30103008

30113009
Type getParameterType(FunctionPosition pos, TypePath path) {
3012-
result = this.getTupleField(pos.asPosition()).getTypeRepr().(TypeMention).resolveTypeAt(path)
3010+
result = this.getTupleField(pos.asPosition()).getTypeRepr().(TypeMention).getTypeAt(path)
30133011
}
30143012
}
30153013

@@ -3364,7 +3362,7 @@ private module FieldExprMatchingInput implements MatchingInputSig {
33643362
)
33653363
or
33663364
dpos.isField() and
3367-
result = this.getTypeRepr().(TypeMention).resolveTypeAt(path)
3365+
result = this.getTypeRepr().(TypeMention).getTypeAt(path)
33683366
}
33693367

33703368
override string toString() { result = this.getAstNode().toString() }
@@ -3716,7 +3714,7 @@ private module StructPatMatchingInput implements MatchingInputSig {
37163714
// The struct/enum type is supplied explicitly as a type qualifier, e.g.
37173715
// `let Foo<Bar>::Variant { ... } = ...`.
37183716
apos.isStructPos() and
3719-
result = this.getPath().(TypeMention).resolveTypeAt(path)
3717+
result = this.getPath().(TypeMention).getTypeAt(path)
37203718
}
37213719

37223720
Declaration getTarget() { result = resolvePath(this.getPath()) }
@@ -3766,7 +3764,7 @@ private module TupleStructPatMatchingInput implements MatchingInputSig {
37663764
// The struct/enum type is supplied explicitly as a type qualifier, e.g.
37673765
// `let Option::<Foo>::Some(x) = ...`.
37683766
apos.isSelf() and
3769-
result = this.getPath().(TypeMention).resolveTypeAt(path)
3767+
result = this.getPath().(TypeMention).getTypeAt(path)
37703768
}
37713769

37723770
Declaration getTarget() { result = resolvePath(this.getPath()) }
@@ -3955,13 +3953,13 @@ private Type inferClosureExprType(AstNode n, TypePath path) {
39553953
or
39563954
// Propagate return type annotation to body
39573955
n = ce.getClosureBody() and
3958-
result = ce.getRetType().getTypeRepr().(TypeMention).resolveTypeAt(path)
3956+
result = ce.getRetType().getTypeRepr().(TypeMention).getTypeAt(path)
39593957
)
39603958
}
39613959

39623960
pragma[nomagic]
39633961
private Type inferCastExprType(CastExpr ce, TypePath path) {
3964-
result = ce.getTypeRepr().(TypeMention).resolveTypeAt(path)
3962+
result = ce.getTypeRepr().(TypeMention).getTypeAt(path)
39653963
}
39663964

39673965
cached
@@ -4159,7 +4157,7 @@ private module Debug {
41594157

41604158
predicate debugInferShorthandSelfType(ShorthandSelfParameterMention self, TypePath path, Type t) {
41614159
self = getRelevantLocatable() and
4162-
t = self.resolveTypeAt(path)
4160+
t = self.getTypeAt(path)
41634161
}
41644162

41654163
predicate debugInferMethodCallType(AstNode n, TypePath path, Type t) {
@@ -4174,7 +4172,7 @@ private module Debug {
41744172

41754173
predicate debugTypeMention(TypeMention tm, TypePath path, Type type) {
41764174
tm = getRelevantLocatable() and
4177-
tm.resolveTypeAt(path) = type
4175+
tm.getTypeAt(path) = type
41784176
}
41794177

41804178
Type debugInferAnnotatedType(AstNode n, TypePath path) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ query predicate illFormedTypeMention(TypeMention tm) {
1717
not tm =
1818
any(PathTypeMention ptm |
1919
exists(ptm.resolvePathTypeAt(TypePath::nil())) and
20-
not exists(ptm.resolveType())
20+
not exists(ptm.getType())
2121
or
2222
ptm.(NonAliasPathTypeMention).getResolved() instanceof TypeAlias
2323
) and

0 commit comments

Comments
 (0)