Skip to content

Commit e219281

Browse files
committed
C#: Speed up ForwarderAssertMethod
Avoids the following bad predicate ``` [2023-08-29 10:03:13] (252s) Tuple counts for _Callable#f85cebf6::Callable::getBody#0#dispred#ff_Variable#afb43847::Variable::getAnAccess#0#dispre__#join_rhs/5@43feb6tl after 4m0s: 4416261 ~203% {4} r1 = JOIN _Callable#f85cebf6::Callable::getAParameter#0#dispred#ff_10#join_rhs_Variable#afb43847::Variable::ge__#shared WITH Callable#f85cebf6::Callable::getBody#0#dispred#ff ON FIRST 1 OUTPUT Lhs.1 'arg1', Lhs.2 'arg2', Lhs.0 'arg3', Rhs.1 'arg4' 1189565718 ~152% {5} r2 = JOIN r1 WITH Variable#afb43847::Variable::getAnAccess#0#dispred#ff ON FIRST 1 OUTPUT Rhs.1 'arg0', Lhs.0 'arg1', Lhs.1 'arg2', Lhs.2 'arg3', Lhs.3 'arg4' return r2 ```
1 parent 1ac9d2e commit e219281

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

csharp/ql/lib/semmle/code/csharp/commons/Assertions.qll

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,12 @@ class NUnitAssertNonNullMethod extends NullnessAssertMethod, NUnitAssertMethod {
299299
override int getAnAssertionIndex(boolean b) { result = this.getAnAssertionIndex() and b = false }
300300
}
301301

302+
pragma[nomagic]
303+
private predicate parameterAssertion(Assertion a, int index, Parameter p) {
304+
strictcount(AssignableDefinition def | def.getTarget() = p) = 1 and
305+
a.getExpr(index) = p.getAnAccess()
306+
}
307+
302308
/** A method that forwards to another assertion method. */
303309
class ForwarderAssertMethod extends AssertMethod {
304310
private Assertion a;
@@ -307,10 +313,9 @@ class ForwarderAssertMethod extends AssertMethod {
307313

308314
ForwarderAssertMethod() {
309315
p = this.getAParameter() and
310-
strictcount(AssignableDefinition def | def.getTarget() = p) = 1 and
311316
forex(ControlFlowElement body | body = this.getBody() |
312317
bodyAsserts(this, body, a) and
313-
a.getExpr(forwarderIndex) = p.getAnAccess()
318+
parameterAssertion(a, forwarderIndex, p)
314319
)
315320
}
316321

0 commit comments

Comments
 (0)