Skip to content

Commit 19e6da5

Browse files
committed
Ruby: Fix bad join-order in resolveConstant
``` [2021-11-09 11:35:47] (99s) Starting to evaluate predicate Module::Cached::resolveConstant#ff#antijoin_rhs/3@f6dcd6 [2021-11-09 11:35:58] (111s) Tuple counts for Module::Cached::resolveConstant#ff#antijoin_rhs/3@f6dcd6 after 11.5s: 165960683 ~0% {4} r1 = JOIN Module::Cached::resolveConstant#ff#shared WITH Module::constantDefinition0#ff_10#join_rhs ON FIRST 1 OUTPUT Rhs.1, Lhs.1 'arg1', Lhs.0 'arg0', Lhs.2 'arg2' 0 ~0% {3} r2 = JOIN r1 WITH Module::ClassDeclaration::getSuperclassExpr_dispred#ff ON FIRST 2 OUTPUT Lhs.2 'arg0', Lhs.1 'arg1', Lhs.3 'arg2' 0 ~0% {3} r3 = JOIN r1 WITH Constant::ConstantAccess::getScopeExpr_dispred#ff ON FIRST 2 OUTPUT Lhs.2 'arg0', Lhs.1 'arg1', Lhs.3 'arg2' 0 ~0% {3} r4 = r2 UNION r3 return r4 ```
1 parent 55ea715 commit 19e6da5

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

ruby/ql/lib/codeql/ruby/ast/internal/Module.qll

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,15 @@ private module Cached {
106106
exists(string qname | qname = resolveConstant(r) and result = TResolved(qname))
107107
}
108108

109+
pragma[nomagic]
110+
private string constantDefinition1(ConstantReadAccess r) {
111+
exists(ConstantWriteAccess w | result = constantDefinition0(w) |
112+
r = w.getScopeExpr()
113+
or
114+
r = w.(ClassDeclaration).getSuperclassExpr()
115+
)
116+
}
117+
109118
/**
110119
* Resolve constant access (class, module or otherwise) to a qualified module name.
111120
* `resolveScopeExpr/1` picks the best (lowest priority number) result of
@@ -121,11 +130,7 @@ private module Cached {
121130
isDefinedConstant(qn) and
122131
qn = resolveScopeExpr(r, p) and
123132
// prevent classes/modules that contain/extend themselves
124-
not exists(ConstantWriteAccess w | qn = constantDefinition0(w) |
125-
r = w.getScopeExpr()
126-
or
127-
r = w.(ClassDeclaration).getSuperclassExpr()
128-
)
133+
not qn = constantDefinition1(r)
129134
|
130135
qn order by p
131136
)

0 commit comments

Comments
 (0)