Skip to content

Commit 981f66e

Browse files
committed
wip5
1 parent 1ba70d6 commit 981f66e

2 files changed

Lines changed: 25 additions & 17 deletions

File tree

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -480,18 +480,18 @@ private module Input3 implements InputSig3 {
480480
)
481481
or
482482
exists(CallExprImpl::DynamicCallExpr dce, TupleType tt, int i |
483+
n1 = dce.getSyntacticPositionalArgument(i) and
483484
n2 = dce.getArgList() and
484485
tt.getArity() = dce.getNumberOfSyntacticArguments() and
485-
n1 = dce.getSyntacticPositionalArgument(i) and
486-
path2 = TypePath::singleton(tt.getPositionalTypeParameter(i)) and
487-
path1.isEmpty()
486+
path1.isEmpty() and
487+
path2 = TypePath::singleton(tt.getPositionalTypeParameter(i))
488488
)
489489
or
490490
exists(ClosureExpr ce, int index |
491-
n2 = ce and
492491
n1 = ce.getParam(index).getPat() and
493-
path2 = closureParameterPath(ce.getNumberOfParams(), index) and
494-
path1.isEmpty()
492+
n2 = ce and
493+
path1.isEmpty() and
494+
path2 = closureParameterPath(ce.getNumberOfParams(), index)
495495
)
496496
}
497497

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

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1361,6 +1361,14 @@ module Make1<LocationSig Location, InputSig1<Location> Input1> {
13611361
module MatchingWithEnvironment<MatchingWithEnvironmentInputSig Input> {
13621362
private import Input
13631363

1364+
pragma[nomagic]
1365+
private TypeParameter getDeclTypeParameter(Declaration decl, TypeArgumentPosition tapos) {
1366+
exists(TypeParameterPosition tppos |
1367+
result = decl.getTypeParameter(tppos) and
1368+
typeArgumentParameterPositionMatch(tapos, tppos)
1369+
)
1370+
}
1371+
13641372
/**
13651373
* Gets the type of the type argument at `path` in `a` that corresponds to
13661374
* the type parameter `tp` in `target`, if any.
@@ -1372,10 +1380,9 @@ module Make1<LocationSig Location, InputSig1<Location> Input1> {
13721380
bindingset[a, target]
13731381
pragma[inline_late]
13741382
private Type getTypeArgument(Access a, Declaration target, TypeParameter tp, TypePath path) {
1375-
exists(TypeArgumentPosition tapos, TypeParameterPosition tppos |
1383+
exists(TypeArgumentPosition tapos |
13761384
result = a.getTypeArgument(tapos, path) and
1377-
tp = target.getTypeParameter(tppos) and
1378-
typeArgumentParameterPositionMatch(tapos, tppos) and
1385+
tp = getDeclTypeParameter(target, tapos) and
13791386
not result instanceof UnknownType //and path.isEmpty())
13801387
)
13811388
}
@@ -2403,6 +2410,7 @@ module Make1<LocationSig Location, InputSig1<Location> Input1> {
24032410
private predicate infersCertainTypeAt(AstNode n, TypePath prefix, TypeParameter tp) {
24042411
exists(TypePath path |
24052412
hasInferredCertainType(n, path) and
2413+
not path.isEmpty() and // implied by `isSnoc` below, but improves performance slightly
24062414
path.isSnoc(prefix, tp)
24072415
)
24082416
}
@@ -2521,26 +2529,26 @@ module Make1<LocationSig Location, InputSig1<Location> Input1> {
25212529
not Certain::certainTypeConflict(n, prefix, path, result)
25222530
)
25232531
or
2524-
hasUnknownCertainTypeAt(n, path) and
2525-
result instanceof UnknownType
2526-
or
2527-
infersTypeAt(n, path, result.getATypeParameter())
2528-
}
2529-
2530-
private predicate hasUnknownCertainTypeAt(AstNode n, TypePath path) {
2532+
// If `n` has an explicitly unknown type at `prefix` and at the same time a certain
2533+
// type at `prefix.suffix`, then extend the unknown type information to any path
2534+
// extending `prefix.suffix` where there is no certain type information
25312535
exists(TypePath prefix, TypePath suffix, Type certain, TypeParameter tp |
25322536
inferType0(n, prefix) instanceof UnknownType and
25332537
certain = inferTypeCertain(n, prefix.appendInverse(suffix)) and
25342538
tp = certain.getATypeParameter() and
25352539
path = prefix.append(suffix).append(TypePath::singleton(tp)) and
2536-
not exists(inferTypeCertain(n, path))
2540+
not exists(inferTypeCertain(n, path)) and
2541+
result instanceof UnknownType
25372542
)
2543+
or
2544+
infersTypeAt(n, path, result.getATypeParameter())
25382545
}
25392546

25402547
pragma[nomagic]
25412548
private predicate infersTypeAt(AstNode n, TypePath prefix, TypeParameter tp) {
25422549
exists(TypePath path |
25432550
exists(inferType(n, path)) and
2551+
not path.isEmpty() and // implied by `isSnoc` below, but improves performance slightly
25442552
path.isSnoc(prefix, tp)
25452553
)
25462554
}

0 commit comments

Comments
 (0)