Skip to content

Commit c043e30

Browse files
committed
Rust: Remove source/library deduplication in path resolution
1 parent 72563ec commit c043e30

File tree

2 files changed

+11
-32
lines changed

2 files changed

+11
-32
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ module Stages {
120120
or
121121
exists(resolvePath(_))
122122
or
123-
exists(any(ItemNode i).getASuccessorFull(_))
123+
exists(any(ItemNode i).getASuccessor(_))
124124
or
125125
exists(any(ItemNode i).getASuccessorRec(_))
126126
or

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

Lines changed: 10 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ abstract class ItemNode extends Locatable {
194194
* both are included
195195
*/
196196
cached
197-
ItemNode getASuccessorFull(string name) {
197+
ItemNode getASuccessor(string name) {
198198
Stages::PathResolutionStage::ref() and
199199
result = this.getASuccessorRec(name)
200200
or
@@ -261,27 +261,6 @@ abstract class ItemNode extends Locatable {
261261
item instanceof TypeParamItemNode
262262
}
263263

264-
pragma[nomagic]
265-
private predicate hasSourceFunction(string name) {
266-
this.getASuccessorFull(name).(Function).fromSource()
267-
}
268-
269-
/** Gets a successor named `name` of this item, if any. */
270-
pragma[nomagic]
271-
ItemNode getASuccessor(string name) {
272-
result = this.getASuccessorFull(name) and
273-
(
274-
// when a function exists in both source code and in library code, it is because
275-
// we also extracted the source code as library code, and hence we only want
276-
// the function from source code
277-
result.fromSource()
278-
or
279-
not result instanceof Function
280-
or
281-
not this.hasSourceFunction(name)
282-
)
283-
}
284-
285264
/** Holds if this item has a canonical path belonging to the crate `c`. */
286265
abstract predicate hasCanonicalPath(Crate c);
287266

@@ -345,7 +324,7 @@ abstract private class ModuleLikeNode extends ItemNode {
345324
private class SourceFileItemNode extends ModuleLikeNode, SourceFile {
346325
pragma[nomagic]
347326
ModuleLikeNode getSuper() {
348-
result = any(ModuleItemNode mod | fileImport(mod, this)).getASuccessorFull("super")
327+
result = any(ModuleItemNode mod | fileImport(mod, this)).getASuccessor("super")
349328
}
350329

351330
override string getName() { result = "(source file)" }
@@ -393,7 +372,7 @@ class CrateItemNode extends ItemNode instanceof Crate {
393372
predicate isPotentialDollarCrateTarget() {
394373
exists(string name, RelevantPath p |
395374
p.isDollarCrateQualifiedPath(name) and
396-
exists(this.getASuccessorFull(name))
375+
exists(this.getASuccessor(name))
397376
)
398377
}
399378

@@ -1245,8 +1224,8 @@ private predicate unqualifiedPathLookup(ItemNode encl, string name, Namespace ns
12451224
}
12461225

12471226
pragma[nomagic]
1248-
private ItemNode getASuccessorFull(ItemNode pred, string name, Namespace ns) {
1249-
result = pred.getASuccessorFull(name) and
1227+
private ItemNode getASuccessor(ItemNode pred, string name, Namespace ns) {
1228+
result = pred.getASuccessor(name) and
12501229
ns = result.getNamespace()
12511230
}
12521231

@@ -1281,7 +1260,7 @@ private predicate keywordLookup(ItemNode encl, string name, RelevantPath p) {
12811260
pragma[nomagic]
12821261
private ItemNode unqualifiedPathLookup(RelevantPath p, Namespace ns) {
12831262
exists(ItemNode encl, string name |
1284-
result = getASuccessorFull(encl, name, ns) and not encl.excludedLocally(name, result)
1263+
result = getASuccessor(encl, name, ns) and not encl.excludedLocally(name, result)
12851264
|
12861265
unqualifiedPathLookup(encl, name, ns, p)
12871266
or
@@ -1306,7 +1285,7 @@ private ItemNode resolvePath0(RelevantPath path, Namespace ns) {
13061285
or
13071286
exists(ItemNode q, string name |
13081287
q = resolvePathQualifier(path, name) and
1309-
result = getASuccessorFull(q, name, ns) and
1288+
result = getASuccessor(q, name, ns) and
13101289
not q.excludedExternally(name, result)
13111290
)
13121291
or
@@ -1383,12 +1362,12 @@ private ItemNode resolveUseTreeListItem(Use use, UseTree tree, RelevantPath path
13831362
mid = resolveUseTreeListItem(use, midTree) and
13841363
tree = midTree.getUseTreeList().getAUseTree() and
13851364
isUseTreeSubPathUnqualified(tree, path, pragma[only_bind_into](name)) and
1386-
result = mid.getASuccessorFull(pragma[only_bind_into](name))
1365+
result = mid.getASuccessor(pragma[only_bind_into](name))
13871366
)
13881367
or
13891368
exists(ItemNode q, string name |
13901369
q = resolveUseTreeListItemQualifier(use, tree, path, name) and
1391-
result = q.getASuccessorFull(name)
1370+
result = q.getASuccessor(name)
13921371
)
13931372
}
13941373

@@ -1418,7 +1397,7 @@ private predicate useImportEdge(Use use, string name, ItemNode item) {
14181397
then
14191398
exists(ItemNode encl, Namespace ns |
14201399
encl.getADescendant() = use and
1421-
item = getASuccessorFull(used, name, ns) and
1400+
item = getASuccessor(used, name, ns) and
14221401
// glob imports can be shadowed
14231402
not declares(encl, ns, name) and
14241403
not name = ["super", "self", "Self", "$crate", "crate"]

0 commit comments

Comments
 (0)