Skip to content

Commit 3717cb3

Browse files
hvitvedhmac
authored andcommitted
Ruby: Fix two join orders
`getExplicitVisibilityModifier` Before [2022-08-17 09:03:16] (186s) Tuple counts for quick_eval#ff/2@2005f7ku after 113ms: 39910 ~0% {2} r1 = SCAN Method#8b49e67f::Method#ff OUTPUT 0, In.0 'this' 39910 ~0% {2} r2 = STREAM DEDUP r1 135 ~2% {2} r3 = JOIN r2 WITH Call#ee92d596::CallImpl::getArgumentImpl#dispred#fbb_120#join_rhs ON FIRST 2 OUTPUT Rhs.2 'result', Lhs.1 'this' 134 ~0% {2} r4 = JOIN r3 WITH Method#8b49e67f::VisibilityModifier#f ON FIRST 1 OUTPUT Lhs.1 'this', Lhs.0 'result' 39910 ~0% {1} r5 = SCAN Method#8b49e67f::Method#ff OUTPUT In.0 'this' 39910 ~0% {1} r6 = STREAM DEDUP r5 39910 ~0% {2} r7 = JOIN r6 WITH Method#8b49e67f::Method::getName#dispred#ff ON FIRST 1 OUTPUT Lhs.0 'this', Rhs.1 39770 ~1% {3} r8 = JOIN r7 WITH AST#a6718388::AstNode::getEnclosingModule#dispred#ff ON FIRST 1 OUTPUT Rhs.1, Lhs.0 'this', Lhs.1 1859722 ~0% {3} r9 = JOIN r8 WITH project#Method#8b49e67f::isDeclaredIn#fff#2_10#join_rhs ON FIRST 1 OUTPUT Rhs.1 'result', Lhs.1 'this', Lhs.2 11757 ~0% {4} r10 = JOIN r9 WITH Method#8b49e67f::VisibilityModifier::getMethodArgument#dispred#bf ON FIRST 1 OUTPUT Lhs.2, Lhs.1 'this', Lhs.0 'result', Rhs.1 24206 ~0% {4} r11 = JOIN r10 WITH Constant#54e8b051::ConstantValue::getStringlikeValue#dispred#ff_10#join_rhs ON FIRST 1 OUTPUT Lhs.3, Rhs.1, Lhs.1 'this', Lhs.2 'result' 292 ~0% {2} r12 = JOIN r11 WITH Expr#6fb2af19::Expr::getConstantValue#dispred#ff ON FIRST 2 OUTPUT Lhs.2 'this', Lhs.3 'result' 426 ~0% {2} r13 = r4 UNION r12 return r13 After [2022-08-17 09:30:31] (0s) Tuple counts for quick_eval#ff/2@e014fd45 after 5ms: 39910 ~0% {1} r1 = SCAN Method#8b49e67f::Method#ff OUTPUT In.0 'this' 39910 ~0% {1} r2 = STREAM DEDUP r1 134 ~1% {2} r3 = JOIN r2 WITH Method#8b49e67f::VisibilityModifier::getMethodArgument#dispred#ff_10#join_rhs ON FIRST 1 OUTPUT Lhs.0 'this', Rhs.1 'result' 37225 ~1% {3} r4 = JOIN r2 WITH project#Method#8b49e67f::methodIsDeclaredIn#ffff ON FIRST 1 OUTPUT Rhs.1, Rhs.2, Lhs.0 'this' 382 ~1% {2} r5 = JOIN r4 WITH Method#8b49e67f::modifiesIn#fff_120#join_rhs ON FIRST 2 OUTPUT Lhs.2 'this', Rhs.2 'result' 516 ~0% {2} r6 = r3 UNION r5 return r6 `getVisibilityModifier()` Before [2022-08-17 09:16:18] (1s) Tuple counts for quick_eval#ff/2@0e9b6ctl after 52ms: 39910 ~0% {1} r1 = SCAN Method#8b49e67f::Method#ff OUTPUT In.0 'this' 39910 ~0% {1} r2 = STREAM DEDUP r1 424 ~0% {2} r3 = JOIN r2 WITH Method#8b49e67f::Method::getExplicitVisibilityModifier#dispred#ff ON FIRST 1 OUTPUT Lhs.0 'this', Rhs.1 'result' 34953 ~0% {3} r4 = JOIN quick_eval#ff#shared WITH Method#8b49e67f::isDeclaredIn#fff ON FIRST 1 OUTPUT Rhs.1, Rhs.2, Lhs.0 'this' 2338 ~0% {2} r5 = JOIN r4 WITH quick_eval#ff#join_rhs ON FIRST 2 OUTPUT Lhs.2 'this', Rhs.2 'result' 3861 ~0% {1} r6 = SCAN Method#8b49e67f::SingletonMethod#ff OUTPUT In.0 'this' 3861 ~0% {1} r7 = STREAM DEDUP r6 3859 ~6% {2} r8 = JOIN r7 WITH AST#a6718388::AstNode::getEnclosingModule#dispred#ff ON FIRST 1 OUTPUT Lhs.0 'this', Rhs.1 3859 ~6% {2} r9 = JOIN r8 WITH Method#8b49e67f::SingletonMethod#ff ON FIRST 1 OUTPUT Lhs.0 'this', Lhs.1 0 ~0% {3} r10 = JOIN r9 WITH Method#8b49e67f::VisibilityModifier::getMethodArgument#dispred#ff_10#join_rhs ON FIRST 1 OUTPUT Rhs.1 'result', Lhs.1, Lhs.0 'this' 3859 ~0% {3} r11 = JOIN r9 WITH Method#8b49e67f::SingletonMethod::getName#dispred#ff ON FIRST 1 OUTPUT Rhs.1, Lhs.0 'this', Lhs.1 7731 ~0% {3} r12 = JOIN r11 WITH Constant#54e8b051::ConstantValue::getStringlikeValue#dispred#ff_10#join_rhs ON FIRST 1 OUTPUT Rhs.1, Lhs.1 'this', Lhs.2 1343055 ~1% {3} r13 = JOIN r12 WITH Expr#6fb2af19::Expr::getConstantValue#dispred#ff_10#join_rhs ON FIRST 1 OUTPUT Rhs.1, Lhs.1 'this', Lhs.2 6546 ~2% {3} r14 = JOIN r13 WITH Method#8b49e67f::VisibilityModifier::getMethodArgument#dispred#ff_10#join_rhs ON FIRST 1 OUTPUT Rhs.1 'result', Lhs.2, Lhs.1 'this' 6546 ~2% {3} r15 = r10 UNION r14 120 ~2% {2} r16 = JOIN r15 WITH AST#a6718388::AstNode::getEnclosingModule#dispred#ff ON FIRST 2 OUTPUT Lhs.2 'this', Lhs.0 'result' 2458 ~0% {2} r17 = r5 UNION r16 2882 ~0% {2} r18 = r3 UNION r17 return r18 After [2022-08-17 09:29:42] (2s) Tuple counts for quick_eval#ff/2@77b18cdg after 5ms: 39910 ~0% {1} r1 = SCAN Method#8b49e67f::Method#ff OUTPUT In.0 'this' 39910 ~0% {1} r2 = STREAM DEDUP r1 516 ~0% {2} r3 = JOIN r2 WITH Method#8b49e67f::Method::getExplicitVisibilityModifier#dispred#ff ON FIRST 1 OUTPUT Lhs.0 'this', Rhs.1 'result' 3861 ~0% {1} r4 = SCAN Method#8b49e67f::SingletonMethod#ff OUTPUT In.0 'this' 3861 ~0% {1} r5 = STREAM DEDUP r4 0 ~0% {2} r6 = JOIN r5 WITH Method#8b49e67f::VisibilityModifier::getMethodArgument#dispred#ff_10#join_rhs ON FIRST 1 OUTPUT Lhs.0 'this', Rhs.1 'result' 516 ~0% {2} r7 = r3 UNION r6 36845 ~0% {3} r8 = JOIN quick_eval#ff#shared WITH Method#8b49e67f::isDeclaredIn#fff ON FIRST 1 OUTPUT Rhs.1, Rhs.2, Lhs.0 'this' 2421 ~0% {2} r9 = JOIN r8 WITH quick_eval#ff#join_rhs ON FIRST 2 OUTPUT Lhs.2 'this', Rhs.2 'result' 2584 ~0% {3} r10 = JOIN r5 WITH project#Method#8b49e67f::methodIsDeclaredIn#ffff ON FIRST 1 OUTPUT Rhs.1, Rhs.2, Lhs.0 'this' 39 ~0% {2} r11 = JOIN r10 WITH Method#8b49e67f::modifiesIn#fff_120#join_rhs ON FIRST 2 OUTPUT Lhs.2 'this', Rhs.2 'result' 2460 ~1% {2} r12 = r9 UNION r11 2976 ~0% {2} r13 = r7 UNION r12 return r13
1 parent 92715ba commit 3717cb3

File tree

1 file changed

+30
-13
lines changed

1 file changed

+30
-13
lines changed

ruby/ql/lib/codeql/ruby/ast/Method.qll

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ class Method extends MethodBase, TMethod {
173173
result = this.getExplicitVisibilityModifier()
174174
or
175175
not exists(this.getExplicitVisibilityModifier()) and
176-
exists(Namespace n, int methodPos | isDeclaredIn(this, n, methodPos) |
176+
exists(ModuleBase n, int methodPos | isDeclaredIn(this, n, methodPos) |
177177
// The relevant visibility modifier is the closest call that occurs before
178178
// the definition of `m` (typically this means higher up the file).
179179
result =
@@ -204,18 +204,35 @@ class Method extends MethodBase, TMethod {
204204
VisibilityModifier getExplicitVisibilityModifier() {
205205
result.getMethodArgument() = this
206206
or
207-
isDeclaredIn(result, this.getEnclosingModule(), _) and
208-
result.getMethodArgument().getConstantValue().getStringlikeValue() = this.getName()
207+
exists(ModuleBase n, string name |
208+
methodIsDeclaredIn(this, n, name) and
209+
modifiesIn(result, n, name)
210+
)
209211
}
210212
}
211213

214+
pragma[nomagic]
215+
private predicate modifiesIn(VisibilityModifier vm, ModuleBase n, string name) {
216+
n = vm.getEnclosingModule() and
217+
name = vm.getMethodArgument().getConstantValue().getStringlikeValue()
218+
}
219+
212220
/**
213-
* Holds if statement `m` is declared in namespace `n` at position `pos`.
221+
* Holds if statement `s` is declared in namespace `n` at position `pos`.
214222
*/
215-
pragma[noinline]
216-
private predicate isDeclaredIn(Stmt m, Namespace n, int pos) {
217-
n = m.getEnclosingModule() and
218-
n.getStmt(pos) = m
223+
pragma[nomagic]
224+
private predicate isDeclaredIn(Stmt s, ModuleBase n, int pos) {
225+
n = s.getEnclosingModule() and
226+
n.getStmt(pos) = s
227+
}
228+
229+
/**
230+
* Holds if method `m` with name `name` is declared in namespace `n`.
231+
*/
232+
pragma[nomagic]
233+
private predicate methodIsDeclaredIn(MethodBase m, ModuleBase n, string name) {
234+
isDeclaredIn(m, n, _) and
235+
name = m.getName()
219236
}
220237

221238
/** A singleton method. */
@@ -273,11 +290,11 @@ class SingletonMethod extends MethodBase, TSingletonMethod {
273290
override predicate isPrivate() { super.isPrivate() }
274291

275292
override VisibilityModifier getVisibilityModifier() {
276-
result.getEnclosingModule() = this.getEnclosingModule() and
277-
(
278-
result.getMethodArgument() = this
279-
or
280-
result.getMethodArgument().getConstantValue().getStringlikeValue() = this.getName()
293+
result.getMethodArgument() = this
294+
or
295+
exists(ModuleBase n, string name |
296+
methodIsDeclaredIn(this, n, name) and
297+
modifiesIn(result, n, name)
281298
)
282299
}
283300
}

0 commit comments

Comments
 (0)