Skip to content

Commit 43ac348

Browse files
committed
WIP
1 parent 1412c9c commit 43ac348

File tree

6 files changed

+808
-612
lines changed

6 files changed

+808
-612
lines changed

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1801,6 +1801,10 @@ private ItemNode resolvePathCand0(PathExt path, Namespace ns) {
18011801
)
18021802
}
18031803

1804+
/**
1805+
* Gets an item that `qualifier` may resolve to when `qualifier` is the
1806+
* qualifier of `path` and `name` is the text of `path` following the qualifier.
1807+
*/
18041808
pragma[nomagic]
18051809
private ItemNode resolvePathCandQualifier(PathExt qualifier, PathExt path, string name) {
18061810
qualifier = path.getQualifier() and
@@ -2242,8 +2246,11 @@ private module Debug {
22422246
Locatable getRelevantLocatable() {
22432247
exists(string filepath, int startline, int startcolumn, int endline, int endcolumn |
22442248
result.getLocation().hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn) and
2249+
// filepath.matches("%/associated_types.rs") and
2250+
// startline = [368, 374]
2251+
// startline = 345
22452252
filepath.matches("%/main.rs") and
2246-
startline = 52
2253+
startline = [716 .. 726]
22472254
)
22482255
}
22492256

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

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ 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

140140
class TypeMention = TM::TypeMention;
@@ -162,7 +162,7 @@ private module Input2 implements InputSig2 {
162162
* inference module for more information.
163163
*/
164164
predicate conditionSatisfiesConstraint(
165-
TypeAbstraction abs, TypeMention condition, TypeMention constraint, boolean transitive
165+
TypeAbstraction abs, PreTypeMention condition, PreTypeMention constraint, boolean transitive
166166
) {
167167
// `impl` blocks implementing traits
168168
transitive = false and
@@ -212,7 +212,7 @@ private module Input2 implements InputSig2 {
212212
}
213213
}
214214

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

217217
import M2
218218

@@ -236,6 +236,27 @@ module Consistency {
236236
}
237237
}
238238

239+
signature predicate relevantTraitSig(AstNode n, Trait t);
240+
241+
module TermSatisfiesTrait<relevantTraitSig/2 relevantTrait> {
242+
private class RelevantTerm extends AstNode {
243+
RelevantTerm() { relevantTrait(this, _) }
244+
245+
Type getTypeAt(TypePath path) { result = inferType(this, path) }
246+
}
247+
248+
private module MethodCallSatisfiesDerefConstraintInput implements
249+
SatisfiesConstraintInputSig<RelevantTerm>
250+
{
251+
pragma[nomagic]
252+
predicate relevantConstraint(RelevantTerm term, Type constraint) {
253+
relevantTrait(term, constraint.(TraitType).getTrait())
254+
}
255+
256+
predicate useUniversalConditions() { none() }
257+
}
258+
}
259+
239260
/** A function without a `self` parameter. */
240261
private class NonMethodFunction extends Function {
241262
NonMethodFunction() { not this.hasSelfParam() }
@@ -382,7 +403,7 @@ pragma[nomagic]
382403
private Type inferAnnotatedType(AstNode n, TypePath path) {
383404
result = getTypeAnnotation(n).resolveTypeAt(path)
384405
or
385-
result = n.(ShorthandSelfParameterMention).resolveTypeAt(path)
406+
result = n.(SelfParam).(TypeMention).resolveTypeAt(path)
386407
}
387408

388409
pragma[nomagic]
@@ -3770,12 +3791,12 @@ private module ForIterableSatisfiesConstraintInput implements
37703791

37713792
pragma[nomagic]
37723793
private AssociatedTypeTypeParameter getIteratorItemTypeParameter() {
3773-
result.getTypeAlias() = any(IteratorTrait t).getItemType()
3794+
result = getAssociatedTypeTypeParameter(any(IteratorTrait t).getItemType())
37743795
}
37753796

37763797
pragma[nomagic]
37773798
private AssociatedTypeTypeParameter getIntoIteratorItemTypeParameter() {
3778-
result.getTypeAlias() = any(IntoIteratorTrait t).getItemType()
3799+
result = getAssociatedTypeTypeParameter(any(IntoIteratorTrait t).getItemType())
37793800
}
37803801

37813802
pragma[nomagic]
@@ -4084,12 +4105,14 @@ import Cached
40844105
Type inferType(AstNode n) { result = inferType(n, TypePath::nil()) }
40854106

40864107
/** Provides predicates for debugging the type inference implementation. */
4087-
private module Debug {
4108+
module Debug {
40884109
Locatable getRelevantLocatable() {
40894110
exists(string filepath, int startline, int startcolumn, int endline, int endcolumn |
40904111
result.getLocation().hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn) and
4091-
filepath.matches("%/sqlx.rs") and
4092-
startline = [56 .. 60]
4112+
filepath.matches("%/associated_types.rs") //and
4113+
// startline = [340]
4114+
// startline = 20
4115+
// startline = [120 .. 125]
40934116
)
40944117
}
40954118

@@ -4110,9 +4133,9 @@ private module Debug {
41104133
Input2::conditionSatisfiesConstraint(abs, condition, constraint, transitive)
41114134
}
41124135

4113-
predicate debugInferShorthandSelfType(ShorthandSelfParameterMention self, TypePath path, Type t) {
4136+
predicate debugInferShorthandSelfType(SelfParam self, TypePath path, Type t) {
41144137
self = getRelevantLocatable() and
4115-
t = self.resolveTypeAt(path)
4138+
t = self.(TypeMention).resolveTypeAt(path)
41164139
}
41174140

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

0 commit comments

Comments
 (0)