Skip to content

Commit 8c95664

Browse files
committed
Rust: Fix bad join in fileImport
Before ``` Evaluated relational algebra for predicate PathResolution::fileImport/2#d9e57816@c790f609 with tuple counts: 241 ~0% {3} r1 = JOIN `_Locatable::Locatable.getFile/0#dispred#f7e24934_PathResolution::isSourceFile/1#803de032#shared` WITH `FileSystem::Folder::Append<PathResolution::shouldAppend>::append/2#beb8f79a_201#join_rhs` ON FIRST 1 OUTPUT Rhs.1, Rhs.2, Lhs.1 291 ~0% {2} | JOIN WITH `PathResolution::pathAttrImport/3#88463ffa_021#join_rhs` ON FIRST 2 OUTPUT Rhs.2, Lhs.2 14978 ~8% {2} r2 = SCAN `PathResolution::modImport0/3#03cccf2a` OUTPUT In.0, In.1 14978 ~8% {2} | STREAM DEDUP 14392 ~9% {2} r3 = r2 AND NOT `PathResolution::modImportNested/3#991244df_0#antijoin_rhs`(FIRST 1) 14392 ~0% {3} | JOIN WITH `PathResolution::modImport0/3#03cccf2a` ON FIRST 2 OUTPUT Lhs.1, Rhs.2, Lhs.0 14355 ~0% {4} | JOIN WITH `PathResolution::fileModule/3#d6c6ceef#fbf_120#join_rhs` ON FIRST 2 OUTPUT Rhs.2, Lhs.0, Lhs.1, Lhs.2 14978 ~0% {2} r4 = JOIN r2 WITH `PathResolution::modImport0/3#03cccf2a` ON FIRST 2 OUTPUT Lhs.1, Lhs.0 329862 ~0% {5} | JOIN WITH `PathResolution::fileModule/3#d6c6ceef#fbf_102#join_rhs` ON FIRST 1 OUTPUT Lhs.1, Lhs.1, Rhs.2, Lhs.0, Rhs.1 577 ~3% {4} | JOIN WITH `PathResolution::modImportNestedLookup/3#6cc4b913#ffb` ON FIRST 3 OUTPUT Lhs.4, Lhs.3, Lhs.2, Lhs.0 14932 ~0% {4} r5 = r3 UNION r4 14932 ~0% {2} | JOIN WITH `PathResolution::fileModule/3#d6c6ceef#fbf` ON FIRST 3 OUTPUT Lhs.0, Lhs.3 14932 ~0% {2} | JOIN WITH `PathResolution::isSourceFile/1#803de032` ON FIRST 1 OUTPUT Lhs.1, Lhs.0 15223 ~0% {2} r6 = r1 UNION r5 return r6 ``` Afer ``` Evaluated relational algebra for predicate PathResolution::fileImport/2#d9e57816@007bd81i with tuple counts: 241 ~0% {3} r1 = JOIN `_Locatable::Locatable.getFile/0#dispred#f7e24934_PathResolution::isSourceFile/1#803de032#shared` WITH `FileSystem::Folder::Append<PathResolution::shouldAppend>::append/2#beb8f79a_201#join_rhs` ON FIRST 1 OUTPUT Rhs.1, Rhs.2, Lhs.1 291 ~0% {2} | JOIN WITH `PathResolution::pathAttrImport/3#88463ffa_021#join_rhs` ON FIRST 2 OUTPUT Rhs.2, Lhs.2 14978 ~8% {2} r2 = SCAN `PathResolution::modImport0/3#03cccf2a` OUTPUT In.0, In.1 14978 ~8% {2} | STREAM DEDUP 14392 ~9% {2} r3 = r2 AND NOT `PathResolution::modImportNested/3#991244df_0#antijoin_rhs`(FIRST 1) 14392 ~0% {3} | JOIN WITH `PathResolution::modImport0/3#03cccf2a` ON FIRST 2 OUTPUT Lhs.1, Rhs.2, Lhs.0 14978 ~9% {3} r4 = JOIN r2 WITH `PathResolution::modImport0/3#03cccf2a` ON FIRST 2 OUTPUT Lhs.0, Lhs.0, Lhs.1 577 ~0% {3} | JOIN WITH `PathResolution::modImportNestedLookup/3#6cc4b913#ffb` ON FIRST 2 OUTPUT Lhs.2, Rhs.2, Lhs.0 14969 ~1% {3} r5 = r3 UNION r4 14932 ~0% {2} | JOIN WITH `PathResolution::fileModule/3#d6c6ceef_120#join_rhs` ON FIRST 2 OUTPUT Rhs.2, Lhs.2 14932 ~0% {2} | JOIN WITH `PathResolution::isSourceFile/1#803de032` ON FIRST 1 OUTPUT Lhs.1, Lhs.0 15223 ~0% {2} r6 = r1 UNION r5 return r6 ```
1 parent 63aac1b commit 8c95664

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -988,6 +988,7 @@ private predicate sourceFileEdge(SourceFile f, string name, ItemNode item) {
988988
}
989989

990990
/** Holds if `f` is available as `mod name;` inside `folder`. */
991+
pragma[nomagic]
991992
private predicate fileModule(SourceFile f, string name, Folder folder) {
992993
exists(File file | file = f.getFile() |
993994
file.getBaseName() = name + ".rs" and
@@ -1002,6 +1003,12 @@ private predicate fileModule(SourceFile f, string name, Folder folder) {
10021003
)
10031004
}
10041005

1006+
bindingset[name, folder]
1007+
pragma[inline_late]
1008+
private predicate fileModuleInlineLate(SourceFile f, string name, Folder folder) {
1009+
fileModule(f, name, folder)
1010+
}
1011+
10051012
/**
10061013
* Gets the `Meta` of the module `m`'s [path attribute][1].
10071014
*
@@ -1084,7 +1091,7 @@ pragma[nomagic]
10841091
predicate fileImport(Module m, SourceFile f) {
10851092
exists(string name, Folder parent |
10861093
modImport0(m, name, _) and
1087-
fileModule(f, name, parent)
1094+
fileModuleInlineLate(f, name, parent)
10881095
|
10891096
// `m` is not inside a nested module
10901097
modImport0(m, name, parent) and

0 commit comments

Comments
 (0)