Skip to content

Commit eca3190

Browse files
committed
HashCons: Make some functionality apparent.
The user knows that an expression functionally determines its hashCons value, and that an expression functionally determines its number of children, but this is not provable from the definitions, and so not usable by the optimiser. By storing the result of those known-functional calls in a variable, rather than repeating the call, we enable better join orders.
1 parent 0350286 commit eca3190

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

cpp/ql/src/semmle/code/cpp/valuenumbering/HashCons.qll

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -766,11 +766,13 @@ private predicate mk_ClassAggregateLiteral(Class c, HC_Fields hcf, ClassAggregat
766766
analyzableClassAggregateLiteral(cal) and
767767
c = cal.getUnspecifiedType() and
768768
(
769-
exists(HC_Fields tail, Expr e, Field f |
769+
exists(HC_Fields tail, Expr e, Field f, int numChildren, HashCons eCons |
770770
f.getInitializationOrder() = cal.getNumChild() - 1 and
771771
e = cal.getFieldExpr(f).getFullyConverted() and
772-
hcf = HC_FieldCons(c, cal.getNumChild() - 1, f, hashCons(e), tail) and
773-
mk_FieldCons(c, cal.getNumChild() - 1, f, hashCons(e), tail, cal)
772+
eCons = hashCons(e) and
773+
numChildren = cal.getNumChild() and
774+
hcf = HC_FieldCons(c, numChildren - 1, f, eCons, tail) and
775+
mk_FieldCons(c, numChildren - 1, f, eCons, tail, cal)
774776
)
775777
or
776778
cal.getNumChild() = 0 and
@@ -801,9 +803,10 @@ private predicate mk_ArrayCons(Type t, int i, HashCons hc, HC_Array hca, ArrayAg
801803
private predicate mk_ArrayAggregateLiteral(Type t, HC_Array hca, ArrayAggregateLiteral aal) {
802804
t = aal.getUnspecifiedType() and
803805
(
804-
exists(HashCons head, HC_Array tail |
805-
hca = HC_ArrayCons(t, aal.getNumChild() - 1, head, tail) and
806-
mk_ArrayCons(t, aal.getNumChild() - 1, head, tail, aal)
806+
exists(HashCons head, HC_Array tail, int numElements |
807+
numElements = aal.getNumChild() and
808+
hca = HC_ArrayCons(t, numElements - 1, head, tail) and
809+
mk_ArrayCons(t, numElements - 1, head, tail, aal)
807810
)
808811
or
809812
aal.getNumChild() = 0 and

0 commit comments

Comments
 (0)