Skip to content

Commit 17e53ae

Browse files
committed
Rust: Remove source vs library deduplication logic
1 parent f6231a3 commit 17e53ae

File tree

2 files changed

+13
-49
lines changed

2 files changed

+13
-49
lines changed

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

Lines changed: 10 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -524,17 +524,17 @@ abstract class ImplOrTraitItemNode extends ItemNode {
524524

525525
pragma[nomagic]
526526
private TypeParamItemNode resolveTypeParamPathTypeRepr(PathTypeRepr ptr) {
527-
result = resolvePathFull(ptr.getPath())
527+
result = resolvePath(ptr.getPath())
528528
}
529529

530530
class ImplItemNode extends ImplOrTraitItemNode instanceof Impl {
531531
Path getSelfPath() { result = super.getSelfTy().(PathTypeRepr).getPath() }
532532

533533
Path getTraitPath() { result = super.getTrait().(PathTypeRepr).getPath() }
534534

535-
ItemNode resolveSelfTy() { result = resolvePathFull(this.getSelfPath()) }
535+
ItemNode resolveSelfTy() { result = resolvePath(this.getSelfPath()) }
536536

537-
TraitItemNode resolveTraitTy() { result = resolvePathFull(this.getTraitPath()) }
537+
TraitItemNode resolveTraitTy() { result = resolvePath(this.getTraitPath()) }
538538

539539
override AssocItemNode getAnAssocItem() { result = super.getAssocItemList().getAnAssocItem() }
540540

@@ -733,7 +733,7 @@ class TraitItemNode extends ImplOrTraitItemNode instanceof Trait {
733733
}
734734

735735
pragma[nomagic]
736-
ItemNode resolveABound() { result = resolvePathFull(this.getABoundPath()) }
736+
ItemNode resolveABound() { result = resolvePath(this.getABoundPath()) }
737737

738738
override AssocItemNode getAnAssocItem() { result = super.getAssocItemList().getAnAssocItem() }
739739

@@ -872,7 +872,7 @@ class TypeParamItemNode extends ItemNode instanceof TypeParam {
872872
}
873873

874874
pragma[nomagic]
875-
ItemNode resolveABound() { result = resolvePathFull(this.getABoundPath()) }
875+
ItemNode resolveABound() { result = resolvePath(this.getABoundPath()) }
876876

877877
/**
878878
* Holds if this type parameter has a trait bound. Examples:
@@ -1285,14 +1285,9 @@ private predicate pathUsesNamespace(Path p, Namespace n) {
12851285
)
12861286
}
12871287

1288-
/**
1289-
* Gets the item that `path` resolves to, if any.
1290-
*
1291-
* Whenever `path` can resolve to both a function in source code and in library
1292-
* code, both are included
1293-
*/
1294-
pragma[nomagic]
1295-
private ItemNode resolvePathFull(RelevantPath path) {
1288+
/** Gets the item that `path` resolves to, if any. */
1289+
cached
1290+
ItemNode resolvePath(RelevantPath path) {
12961291
exists(Namespace ns | result = resolvePath0(path, ns) |
12971292
pathUsesNamespace(path, ns)
12981293
or
@@ -1301,30 +1296,9 @@ private ItemNode resolvePathFull(RelevantPath path) {
13011296
)
13021297
}
13031298

1304-
pragma[nomagic]
1305-
private predicate resolvesSourceFunction(RelevantPath path) {
1306-
resolvePathFull(path).(Function).fromSource()
1307-
}
1308-
1309-
/** Gets the item that `path` resolves to, if any. */
1310-
cached
1311-
ItemNode resolvePath(RelevantPath path) {
1312-
result = resolvePathFull(path) and
1313-
(
1314-
// when a function exists in both source code and in library code, it is because
1315-
// we also extracted the source code as library code, and hence we only want
1316-
// the function from source code
1317-
result.fromSource()
1318-
or
1319-
not result instanceof Function
1320-
or
1321-
not resolvesSourceFunction(path)
1322-
)
1323-
}
1324-
13251299
pragma[nomagic]
13261300
private ItemNode resolvePathQualifier(RelevantPath path, string name) {
1327-
result = resolvePathFull(path.getQualifier()) and
1301+
result = resolvePath(path.getQualifier()) and
13281302
name = path.getText()
13291303
}
13301304

@@ -1370,7 +1344,7 @@ private ItemNode resolveUseTreeListItemQualifier(
13701344
pragma[nomagic]
13711345
private ItemNode resolveUseTreeListItem(Use use, UseTree tree) {
13721346
tree = use.getUseTree() and
1373-
result = resolvePathFull(tree.getPath())
1347+
result = resolvePath(tree.getPath())
13741348
or
13751349
result = resolveUseTreeListItem(use, tree, tree.getPath())
13761350
}

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

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1231,9 +1231,10 @@ private module Cached {
12311231
f = any(Impl impl | impl.hasTrait()).(ImplItemNode).getAnAssocItem()
12321232
}
12331233

1234-
private Function resolveMethodCallTargetFrom(MethodCall mc, boolean fromSource) {
1234+
/** Gets a method that the method call `mc` resolves to, if any. */
1235+
cached
1236+
Function resolveMethodCallTarget(MethodCall mc) {
12351237
result = inferMethodCallTarget(mc) and
1236-
(if result.fromSource() then fromSource = true else fromSource = false) and
12371238
(
12381239
// prioritize inherent implementation methods first
12391240
isInherentImplFunction(result)
@@ -1255,17 +1256,6 @@ private module Cached {
12551256
)
12561257
}
12571258

1258-
/** Gets a method that the method call `mc` resolves to, if any. */
1259-
cached
1260-
Function resolveMethodCallTarget(MethodCall mc) {
1261-
// Functions in source code also gets extracted as library code, due to
1262-
// this duplication we prioritize functions from source code.
1263-
result = resolveMethodCallTargetFrom(mc, true)
1264-
or
1265-
not exists(resolveMethodCallTargetFrom(mc, true)) and
1266-
result = resolveMethodCallTargetFrom(mc, false)
1267-
}
1268-
12691259
pragma[inline]
12701260
private Type inferRootTypeDeref(AstNode n) {
12711261
result = inferType(n) and

0 commit comments

Comments
 (0)