Skip to content

Commit 92f5d5b

Browse files
committed
A5-1-9: Address param confusion
The hash cons value for parameters was incorrectly calculated with parameter uses (e.g accesses to the parameter). The correct approach is to use the variable name and type. This caused performance issues, because the hash cons for a function was made up of all combinations of the accesses to the parameters. For lambdas with many parameters and many accesses, this was problematic.
1 parent e176bb1 commit 92f5d5b

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

cpp/autosar/src/rules/A5-1-9/LambdaEquivalence.qll

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ private module HashCons {
211211

212212
private newtype HC_Params =
213213
HC_NoParams() or
214-
HC_ParamCons(HashConsExpr hc, int i, HC_Params list) { mk_ParamCons(hc, i, list, _) }
214+
HC_ParamCons(Type t, string name, int i, HC_Params list) { mk_ParamCons(t, name, i, list, _) }
215215

216216
/**
217217
* HashConsExpr is the hash-cons of an expression. The relationship between `Expr`
@@ -1275,24 +1275,25 @@ private module HashCons {
12751275
mk_DeclConsInner(_, _, s.getNumDeclarations() - 1, hc, s)
12761276
}
12771277

1278-
private predicate mk_ParamCons(HashConsExpr hc, int i, HC_Params list, Function f) {
1279-
hc = hashConsExpr(f.getParameter(i).getAnAccess()) and
1280-
(
1281-
exists(HashConsExpr head, HC_Params tail |
1282-
mk_ParamConsInner(head, tail, i - 1, list, f) and
1283-
i > 0
1284-
)
1278+
private predicate mk_ParamCons(Type t, string name, int i, HC_Params list, Function f) {
1279+
exists(Parameter p |
1280+
p = f.getParameter(i) and
1281+
t = p.getType() and
1282+
name = p.getName()
1283+
|
1284+
mk_ParamConsInner(_, _, _, i - 1, list, f) and
1285+
i > 0
12851286
or
12861287
i = 0 and
12871288
list = HC_NoParams()
12881289
)
12891290
}
12901291

12911292
private predicate mk_ParamConsInner(
1292-
HashConsExpr head, HC_Params tail, int i, HC_Params list, Function f
1293+
Type t, string name, HC_Params tail, int i, HC_Params list, Function f
12931294
) {
1294-
list = HC_ParamCons(head, i, tail) and
1295-
mk_ParamCons(head, i, tail, f)
1295+
list = HC_ParamCons(t, name, i, tail) and
1296+
mk_ParamCons(t, name, i, tail, f)
12961297
}
12971298

12981299
private predicate mk_FunctionCons(
@@ -1302,7 +1303,7 @@ private module HashCons {
13021303
name = f.getName() and
13031304
body = hashConsStmt(f.getBlock()) and
13041305
if f.getNumberOfParameters() > 0
1305-
then mk_ParamConsInner(_, _, f.getNumberOfParameters() - 1, params, f)
1306+
then mk_ParamConsInner(_, _, _, f.getNumberOfParameters() - 1, params, f)
13061307
else params = HC_NoParams()
13071308
}
13081309

0 commit comments

Comments
 (0)