Skip to content

Rust: Remove source vs library deduplication logic #19577

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 12 additions & 38 deletions rust/ql/lib/codeql/rust/internal/PathResolution.qll
Original file line number Diff line number Diff line change
Expand Up @@ -561,17 +561,17 @@ abstract class ImplOrTraitItemNode extends ItemNode {

pragma[nomagic]
private TypeParamItemNode resolveTypeParamPathTypeRepr(PathTypeRepr ptr) {
result = resolvePathFull(ptr.getPath())
result = resolvePath(ptr.getPath())
}

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

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

ItemNode resolveSelfTy() { result = resolvePathFull(this.getSelfPath()) }
ItemNode resolveSelfTy() { result = resolvePath(this.getSelfPath()) }

TraitItemNode resolveTraitTy() { result = resolvePathFull(this.getTraitPath()) }
TraitItemNode resolveTraitTy() { result = resolvePath(this.getTraitPath()) }

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

Expand Down Expand Up @@ -665,7 +665,7 @@ private class ImplTraitTypeReprItemNode extends ItemNode instanceof ImplTraitTyp
}

pragma[nomagic]
ItemNode resolveABound() { result = resolvePathFull(this.getABoundPath()) }
ItemNode resolveABound() { result = resolvePath(this.getABoundPath()) }

override string getName() { result = "(impl trait)" }

Expand Down Expand Up @@ -795,7 +795,7 @@ class TraitItemNode extends ImplOrTraitItemNode, TypeItemNode instanceof Trait {
}

pragma[nomagic]
ItemNode resolveABound() { result = resolvePathFull(this.getABoundPath()) }
ItemNode resolveABound() { result = resolvePath(this.getABoundPath()) }

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

Expand Down Expand Up @@ -847,7 +847,7 @@ class TraitItemNode extends ImplOrTraitItemNode, TypeItemNode instanceof Trait {

class TypeAliasItemNode extends TypeItemNode, AssocItemNode instanceof TypeAlias {
pragma[nomagic]
ItemNode resolveAlias() { result = resolvePathFull(super.getTypeRepr().(PathTypeRepr).getPath()) }
ItemNode resolveAlias() { result = resolvePath(super.getTypeRepr().(PathTypeRepr).getPath()) }

override string getName() { result = TypeAlias.super.getName().getText() }

Expand Down Expand Up @@ -941,7 +941,7 @@ class TypeParamItemNode extends TypeItemNode instanceof TypeParam {
}

pragma[nomagic]
ItemNode resolveABound() { result = resolvePathFull(this.getABoundPath()) }
ItemNode resolveABound() { result = resolvePath(this.getABoundPath()) }

/**
* Holds if this type parameter has a trait bound. Examples:
Expand Down Expand Up @@ -1369,14 +1369,9 @@ private predicate pathUsesNamespace(Path p, Namespace n) {
)
}

/**
* Gets the item that `path` resolves to, if any.
*
* Whenever `path` can resolve to both a function in source code and in library
* code, both are included
*/
pragma[nomagic]
private ItemNode resolvePathFull(RelevantPath path) {
/** Gets the item that `path` resolves to, if any. */
cached
ItemNode resolvePath(RelevantPath path) {
exists(Namespace ns | result = resolvePath0(path, ns) |
pathUsesNamespace(path, ns)
or
Expand All @@ -1385,30 +1380,9 @@ private ItemNode resolvePathFull(RelevantPath path) {
)
}

pragma[nomagic]
private predicate resolvesSourceFunction(RelevantPath path) {
resolvePathFull(path).(Function).fromSource()
}

/** Gets the item that `path` resolves to, if any. */
cached
ItemNode resolvePath(RelevantPath path) {
result = resolvePathFull(path) and
(
// when a function exists in both source code and in library code, it is because
// we also extracted the source code as library code, and hence we only want
// the function from source code
result.fromSource()
or
not result instanceof Function
or
not resolvesSourceFunction(path)
)
}

pragma[nomagic]
private ItemNode resolvePathQualifier(RelevantPath path, string name) {
result = resolvePathFull(path.getQualifier()) and
result = resolvePath(path.getQualifier()) and
name = path.getText()
}

Expand Down Expand Up @@ -1454,7 +1428,7 @@ private ItemNode resolveUseTreeListItemQualifier(
pragma[nomagic]
private ItemNode resolveUseTreeListItem(Use use, UseTree tree) {
tree = use.getUseTree() and
result = resolvePathFull(tree.getPath())
result = resolvePath(tree.getPath())
or
result = resolveUseTreeListItem(use, tree, tree.getPath())
}
Expand Down