Skip to content

Commit eca7559

Browse files
committed
WIP
1 parent f858f94 commit eca7559

File tree

6 files changed

+688
-604
lines changed

6 files changed

+688
-604
lines changed

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2250,8 +2250,10 @@ private module Debug {
22502250
Locatable getRelevantLocatable() {
22512251
exists(string filepath, int startline, int startcolumn, int endline, int endcolumn |
22522252
result.getLocation().hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn) and
2253-
filepath.matches("%/main.rs") and
2254-
startline = 52
2253+
// filepath.matches("%/lex.rs") and
2254+
// startline = [156 .. 163]
2255+
filepath.matches("%/algorithm/mod.rs") and
2256+
startline = [300 .. 303]
22552257
)
22562258
}
22572259

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ abstract class Type extends TType {
7575
abstract TypeParameter getPositionalTypeParameter(int i);
7676

7777
/** Gets the default type for the `i`th type parameter, if any. */
78-
TypeMention getTypeParameterDefault(int i) { none() }
78+
TypeRepr getTypeParameterDefault(int i) { none() }
7979

8080
/**
8181
* Gets a type parameter of this type.
@@ -129,7 +129,7 @@ class DataType extends Type, TDataType {
129129
result = TTypeParamTypeParameter(typeItem.getGenericParamList().getTypeParam(i))
130130
}
131131

132-
override TypeMention getTypeParameterDefault(int i) {
132+
override TypeRepr getTypeParameterDefault(int i) {
133133
result = typeItem.getGenericParamList().getTypeParam(i).getDefaultType()
134134
}
135135

@@ -189,7 +189,7 @@ class TraitType extends Type, TTrait {
189189
result.(SelfTypeParameter).getTrait() = trait
190190
}
191191

192-
override TypeMention getTypeParameterDefault(int i) {
192+
override TypeRepr getTypeParameterDefault(int i) {
193193
result = trait.getGenericParamList().getTypeParam(i).getDefaultType()
194194
}
195195

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

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

135135
module TypePath = M1::TypePath;
136136

137-
private module Input2 implements InputSig2 {
137+
private module Input2 implements InputSig2<PreTypeMention> {
138138
private import TypeMention as TM
139139

140-
class TypeMention = TM::TypeMention;
141-
142-
TypeMention getABaseTypeMention(Type t) { none() }
140+
PreTypeMention getABaseTypeMention(Type t) { none() }
143141

144142
Type getATypeParameterConstraint(TypeParameter tp, TypePath path) {
145-
exists(TypeMention tm | result = tm.resolveTypeAt(path) |
143+
exists(TypeMention tm | result = tm.getTypeAt(path) |
146144
tm = tp.(TypeParamTypeParameter).getTypeParam().getATypeBound().getTypeRepr() or
147145
tm = tp.(SelfTypeParameter).getTrait() or
148146
tm =
@@ -162,7 +160,7 @@ private module Input2 implements InputSig2 {
162160
* inference module for more information.
163161
*/
164162
predicate conditionSatisfiesConstraint(
165-
TypeAbstraction abs, TypeMention condition, TypeMention constraint, boolean transitive
163+
TypeAbstraction abs, PreTypeMention condition, PreTypeMention constraint, boolean transitive
166164
) {
167165
// `impl` blocks implementing traits
168166
transitive = false and
@@ -212,7 +210,7 @@ private module Input2 implements InputSig2 {
212210
}
213211
}
214212

215-
private module M2 = Make2<Input2>;
213+
private module M2 = Make2<PreTypeMention, Input2>;
216214

217215
import M2
218216

@@ -236,6 +234,25 @@ module Consistency {
236234
}
237235
}
238236

237+
signature predicate relevantTraitSig(AstNode n, Trait t);
238+
239+
module TermSatisfiesTrait<relevantTraitSig/2 relevantTrait> {
240+
private class RelevantTerm extends AstNode {
241+
RelevantTerm() { relevantTrait(this, _) }
242+
243+
Type getTypeAt(TypePath path) { result = inferType(this, path) }
244+
}
245+
246+
private module MethodCallSatisfiesDerefConstraintInput implements
247+
SatisfiesConstraintInputSig<RelevantTerm>
248+
{
249+
pragma[nomagic]
250+
predicate relevantConstraint(RelevantTerm term, Type constraint) {
251+
relevantTrait(term, constraint.(TraitType).getTrait())
252+
}
253+
}
254+
}
255+
239256
/** A function without a `self` parameter. */
240257
private class NonMethodFunction extends Function {
241258
NonMethodFunction() { not this.hasSelfParam() }
@@ -382,7 +399,7 @@ pragma[nomagic]
382399
private Type inferAnnotatedType(AstNode n, TypePath path) {
383400
result = getTypeAnnotation(n).resolveTypeAt(path)
384401
or
385-
result = n.(ShorthandSelfParameterMention).resolveTypeAt(path)
402+
result = n.(SelfParam).(TypeMention).resolveTypeAt(path)
386403
}
387404

388405
pragma[nomagic]
@@ -2330,19 +2347,19 @@ private module MethodResolution {
23302347
* instance of the type being implemented.
23312348
*/
23322349
private module TypeQualifierIsInstantiationOfImplSelfInput implements
2333-
IsInstantiationOfInputSig<MethodCallCallExpr, TypeMentionTypeTree>
2350+
IsInstantiationOfInputSig<MethodCallCallExpr, TypeMention>
23342351
{
23352352
pragma[nomagic]
23362353
private predicate potentialInstantiationOf0(
2337-
MethodCallCallExpr ce, ImplItemNode impl, TypeMentionTypeTree constraint
2354+
MethodCallCallExpr ce, ImplItemNode impl, TypeMention constraint
23382355
) {
23392356
ce.hasTypeQualifiedCandidate(impl) and
23402357
constraint = impl.getSelfPath()
23412358
}
23422359

23432360
pragma[nomagic]
23442361
predicate potentialInstantiationOf(
2345-
MethodCallCallExpr ce, TypeAbstraction abs, TypeMentionTypeTree constraint
2362+
MethodCallCallExpr ce, TypeAbstraction abs, TypeMention constraint
23462363
) {
23472364
potentialInstantiationOf0(ce, abs, constraint) and
23482365
if abs.(Impl).hasTrait()
@@ -2353,14 +2370,13 @@ private module MethodResolution {
23532370
else any()
23542371
}
23552372

2356-
predicate relevantConstraint(TypeMentionTypeTree constraint) {
2373+
predicate relevantConstraint(TypeMention constraint) {
23572374
potentialInstantiationOf0(_, _, constraint)
23582375
}
23592376
}
23602377

23612378
private module TypeQualifierIsInstantiationOfImplSelf =
2362-
IsInstantiationOf<MethodCallCallExpr, TypeMentionTypeTree,
2363-
TypeQualifierIsInstantiationOfImplSelfInput>;
2379+
IsInstantiationOf<MethodCallCallExpr, TypeMention, TypeQualifierIsInstantiationOfImplSelfInput>;
23642380

23652381
/**
23662382
* A configuration for anti-matching the type of a receiver against the type of
@@ -4138,8 +4154,8 @@ private module Debug {
41384154
Locatable getRelevantLocatable() {
41394155
exists(string filepath, int startline, int startcolumn, int endline, int endcolumn |
41404156
result.getLocation().hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn) and
4141-
filepath.matches("%/sqlx.rs") and
4142-
startline = [56 .. 60]
4157+
filepath.matches("%/algorithm/mod.rs") and
4158+
startline = [300 .. 303]
41434159
)
41444160
}
41454161

@@ -4160,9 +4176,9 @@ private module Debug {
41604176
Input2::conditionSatisfiesConstraint(abs, condition, constraint, transitive)
41614177
}
41624178

4163-
predicate debugInferShorthandSelfType(ShorthandSelfParameterMention self, TypePath path, Type t) {
4179+
predicate debugInferShorthandSelfType(SelfParam self, TypePath path, Type t) {
41644180
self = getRelevantLocatable() and
4165-
t = self.resolveTypeAt(path)
4181+
t = self.(TypeMention).resolveTypeAt(path)
41664182
}
41674183

41684184
predicate debugInferMethodCallType(AstNode n, TypePath path, Type t) {

0 commit comments

Comments
 (0)