Skip to content

Commit 96a5210

Browse files
committed
wip2
1 parent 0358736 commit 96a5210

3 files changed

Lines changed: 31 additions & 19 deletions

File tree

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1108,7 +1108,9 @@ private module ContextTyping {
11081108
abstract class ContextTypedCallCand extends Expr {
11091109
abstract Type getTypeArgument(TypeArgumentPosition apos, TypePath path);
11101110

1111-
predicate hasTypeArgument(TypeArgumentPosition apos) { exists(this.getTypeArgument(apos, _)) }
1111+
predicate hasTypeArgument(TypeArgumentPosition apos) {
1112+
this.getTypeArgument(apos, _) != TUnknownType()
1113+
}
11121114

11131115
/**
11141116
* Holds if this call resolves to `target` inside `i`, and the return type
@@ -2962,7 +2964,7 @@ private module ConstructionMatchingInput implements MatchingInputSig {
29622964
not exists(FunctionPosition pos2 | not pos2.isReturn() and tp = d.getDeclaredType(pos2, _)) and
29632965
// check that no explicit type arguments have been supplied for `tp`
29642966
not exists(TypeArgumentPosition tapos |
2965-
exists(this.getTypeArgument(tapos, _)) and
2967+
this.getTypeArgument(tapos, _) != TUnknownType() and
29662968
TTypeParamTypeParameter(tapos.asTypeParam()) = tp
29672969
)
29682970
)

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -695,6 +695,10 @@ private module MkTypeMention<getAdditionalPathTypeAtSig/2 getAdditionalPathTypeA
695695
)
696696
}
697697
}
698+
699+
class InferTypeReprMention extends TypeMentionImpl, InferTypeRepr {
700+
override Type getTypeAt(TypePath path) { result = TUnknownType() and path.isEmpty() }
701+
}
698702
}
699703

700704
private Type preGetAdditionalPathTypeAt(Path p, TypePath typePath) { none() }

shared/typeinference/codeql/typeinference/internal/TypeInference.qll

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1375,7 +1375,8 @@ module Make1<LocationSig Location, InputSig1<Location> Input1> {
13751375
exists(TypeArgumentPosition tapos, TypeParameterPosition tppos |
13761376
result = a.getTypeArgument(tapos, path) and
13771377
tp = target.getTypeParameter(tppos) and
1378-
typeArgumentParameterPositionMatch(tapos, tppos)
1378+
typeArgumentParameterPositionMatch(tapos, tppos) and
1379+
not result instanceof UnknownType //and path.isEmpty())
13791380
)
13801381
}
13811382

@@ -2355,14 +2356,14 @@ module Make1<LocationSig Location, InputSig1<Location> Input1> {
23552356
module Make3<InputSig3 Input3> {
23562357
private import Input3
23572358

2359+
/** Gets the type of `n`, which has an explicit type annotation. */
2360+
pragma[nomagic]
2361+
private Type inferAnnotatedType(AstNode n, TypePath path) {
2362+
result = getTypeAnnotation(n).getTypeAt(path)
2363+
}
2364+
23582365
/** Provides logic for inferring certain type information. */
23592366
private module Certain {
2360-
/** Gets the type of `n`, which has an explicit type annotation. */
2361-
pragma[nomagic]
2362-
Type inferAnnotatedType(AstNode n, TypePath path) {
2363-
result = getTypeAnnotation(n).getTypeAt(path)
2364-
}
2365-
23662367
private predicate stepSymmetricCertain(
23672368
AstNode n1, TypePath path1, AstNode n2, TypePath path2
23682369
) {
@@ -2412,16 +2413,19 @@ module Make1<LocationSig Location, InputSig1<Location> Input1> {
24122413
/** Gets the inferred certain type of `n` at `path`. */
24132414
cached
24142415
Type inferTypeCertain(AstNode n, TypePath path) {
2415-
CachedStage::ref() and
2416-
result = inferAnnotatedType(n, path)
2417-
or
2418-
result = inferTypeFromStepCertain(n, path)
2419-
or
2420-
result = inferTypeCertainSpecific(n, path)
2421-
or
2422-
result = inferLogicalOperationType(n, path)
2423-
or
2424-
infersCertainTypeAt(n, path, result.getATypeParameter())
2416+
(
2417+
CachedStage::ref() and
2418+
result = inferAnnotatedType(n, path)
2419+
or
2420+
result = inferTypeFromStepCertain(n, path)
2421+
or
2422+
result = inferTypeCertainSpecific(n, path)
2423+
or
2424+
result = inferLogicalOperationType(n, path)
2425+
or
2426+
infersCertainTypeAt(n, path, result.getATypeParameter())
2427+
) and
2428+
not result instanceof UnknownType
24252429
}
24262430

24272431
/**
@@ -2556,6 +2560,8 @@ module Make1<LocationSig Location, InputSig1<Location> Input1> {
25562560
not Certain::certainTypeConflict(n, prefix, path, result)
25572561
) and
25582562
(
2563+
result = inferAnnotatedType(n, path)
2564+
or
25592565
result = inferTypeFromStep(n, path)
25602566
or
25612567
result = TopDownTyping<inferTypeFromLubStepTopDown/2>::inferType(n, path)

0 commit comments

Comments
 (0)