Skip to content

Commit 543292c

Browse files
committed
Ruby: use dual graph for common module ancestor check
1 parent 2912dba commit 543292c

1 file changed

Lines changed: 16 additions & 12 deletions

File tree

ruby/ql/lib/codeql/ruby/dataflow/internal/DataFlowPrivate.qll

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
private import codeql.util.Boolean
22
private import codeql.util.Unit
3+
private import codeql.util.DualGraph
34
private import codeql.ruby.AST
45
private import codeql.ruby.ast.internal.Call
56
private import codeql.ruby.ast.internal.Synthesis
@@ -2042,20 +2043,23 @@ private predicate compatibleTypesNonSymRefl(DataFlowType t1, DataFlowType t2) {
20422043
isCollectionClass(t2)
20432044
}
20442045

2045-
pragma[nomagic]
2046-
private predicate compatibleModules(Module m1, Module m2) {
2047-
exists(Module m3 |
2048-
m3.getAnAncestor() = m1 and
2049-
m3.getAnAncestor() = m2
2050-
)
2046+
private module ModuleDualGraphInput implements DualGraphInputSig<Location> {
2047+
class Node = DataFlowType;
2048+
2049+
predicate edge(Node node1, Node node2) {
2050+
exists(Module m1, Module m2 |
2051+
node1 = TModuleDataFlowType(m1) and
2052+
node2 = TModuleDataFlowType(m2) and
2053+
m1.getAnImmediateAncestor() = m2
2054+
)
2055+
}
20512056
}
20522057

2053-
private predicate compatibleModuleTypes(TModuleDataFlowType t1, TModuleDataFlowType t2) {
2054-
exists(Module m1, Module m2 |
2055-
compatibleModules(m1, m2) and
2056-
t1 = TModuleDataFlowType(m1) and
2057-
t2 = TModuleDataFlowType(m2)
2058-
)
2058+
module ModuleDualGraph = MakeDualGraph<Location, ModuleDualGraphInput>;
2059+
2060+
pragma[inline]
2061+
private predicate compatibleModuleTypes(DataFlowType t1, DataFlowType t2) {
2062+
ModuleDualGraph::hasCommonAncestor(t1, t2)
20592063
}
20602064

20612065
/**

0 commit comments

Comments
 (0)