Skip to content

Commit 2e1b8b8

Browse files
committed
Rust: Fix bad join in unqualifiedPathLookup
Before ``` Pipeline standard for PathResolution::unqualifiedPathLookup/2#6b171b76#reorder_2_0_1@822d53wq was evaluated in 61 iterations totaling 118ms (delta sizes total: 131072). 606491 ~0% {4} r1 = SCAN `PathResolution::getASuccessor/3#febac7bd#prev_delta` OUTPUT In.1, In.2, In.0, In.3 106457 ~1% {3} | JOIN WITH `PathResolution::unqualifiedPathLookup/4#e32cdfce_1230#join_rhs` ON FIRST 3 OUTPUT Lhs.3, Rhs.3, Lhs.1 606491 ~2% {4} r2 = SCAN `PathResolution::getASuccessor/3#febac7bd#prev_delta` OUTPUT In.0, In.2, In.3, In.1 19261 ~0% {4} r3 = JOIN r2 WITH `PathResolution::ModuleLikeNode.isRoot/0#dispred#21662e64` ON FIRST 1 OUTPUT Lhs.3, Lhs.0, Lhs.1, Lhs.2 42776643 ~1% {4} r4 = JOIN r2 WITH `doublyBoundedFastTC@PathResolution::hasChild/2#6b318d51#2@PathResolution::isRoot/1#a01ce5c3#1@PathResolution::hasCratePath/1#73ea688d#1` ON FIRST 1 OUTPUT Lhs.3, Rhs.1, Lhs.1, Lhs.2 42795904 ~1% {4} r5 = r3 UNION r4 24921 ~6% {3} | JOIN WITH `PathResolution::RelevantPath.isCratePath/2#e595e892_120#join_rhs` ON FIRST 2 OUTPUT Lhs.3, Rhs.2, Lhs.2 131378 ~2% {3} r6 = r1 UNION r5 131072 ~2% {3} | AND NOT `PathResolution::unqualifiedPathLookup/2#6b171b76#reorder_2_0_1#prev`(FIRST 3) return r6 ``` After ``` Pipeline standard for PathResolution::unqualifiedPathLookup/2#6b171b76#reorder_2_0_1@0553a4wi was evaluated in 66 iterations totaling 10ms (delta sizes total: 131072). 610251 ~0% {4} r1 = SCAN `PathResolution::getASuccessor/3#febac7bd#prev_delta` OUTPUT In.1, In.2, In.0, In.3 131378 ~0% {3} | JOIN WITH `PathResolution::unqualifiedPathLookup1/4#781de0cd_1230#join_rhs` ON FIRST 3 OUTPUT Lhs.3, Rhs.3, Lhs.1 131072 ~0% {3} | AND NOT `PathResolution::unqualifiedPathLookup/2#6b171b76#reorder_2_0_1#prev`(FIRST 3) return r1 ```
1 parent d8ca8dd commit 2e1b8b8

File tree

1 file changed

+16
-13
lines changed

1 file changed

+16
-13
lines changed

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

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -882,20 +882,24 @@ private predicate hasChild(ItemNode parent, ItemNode child) { child.getImmediate
882882
private predicate rootHasCratePathTc(ItemNode i1, ItemNode i2) =
883883
doublyBoundedFastTC(hasChild/2, isRoot/1, hasCratePath/1)(i1, i2)
884884

885+
pragma[nomagic]
886+
private predicate unqualifiedPathLookup1(RelevantPath p, string name, Namespace ns, ItemNode encl) {
887+
unqualifiedPathLookup(p, name, ns, encl)
888+
or
889+
// For `($)crate`, jump directly to the root module
890+
exists(ItemNode i | p.isCratePath(name, i) |
891+
encl.(ModuleLikeNode).isRoot() and
892+
encl = i
893+
or
894+
rootHasCratePathTc(encl, i)
895+
)
896+
}
897+
885898
pragma[nomagic]
886899
private ItemNode unqualifiedPathLookup(RelevantPath path, Namespace ns) {
887900
exists(ItemNode encl, string name |
888-
result = getASuccessor(encl, pragma[only_bind_into](name), ns)
889-
|
890-
unqualifiedPathLookup(path, name, ns, encl)
891-
or
892-
// For `($)crate`, jump directly to the root module
893-
exists(ItemNode i | path.isCratePath(pragma[only_bind_into](name), i) |
894-
encl.(ModuleLikeNode).isRoot() and
895-
encl = i
896-
or
897-
rootHasCratePathTc(encl, i)
898-
)
901+
result = getASuccessor(encl, name, ns) and
902+
unqualifiedPathLookup1(path, name, ns, encl)
899903
)
900904
}
901905

@@ -916,8 +920,7 @@ private ItemNode resolvePath0(RelevantPath path, Namespace ns) {
916920
or
917921
exists(ItemNode q, string name |
918922
q = resolvePathQualifier(path, name) and
919-
result = q.getASuccessor(name) and
920-
ns = result.getNamespace()
923+
result = getASuccessor(q, name, ns)
921924
)
922925
or
923926
result = resolveUseTreeListItem(_, _, path) and

0 commit comments

Comments
 (0)