@@ -659,10 +659,16 @@ private BoolExpr unrollListEquality(
659659 IntExpr idx = ctx .mkInt (i );
660660 Expr <?> elem0 = ctx .mkNth (seq0 , idx );
661661 Expr <?> elem1 = ctx .mkNth (seq1 , idx );
662- context .constrainValidValue (
663- ctx .mkAnd (typeSystem .isList (listA .z3Expr ()), ctx .mkLt (idx , ctx .mkLength (seq0 ))), elem0 );
664- context .constrainValidValue (
665- ctx .mkAnd (typeSystem .isList (listB .z3Expr ()), ctx .mkLt (idx , ctx .mkLength (seq1 ))), elem1 );
662+ // A literal's elements, and a concrete declared type's, are already CEL values (performance
663+ // only).
664+ if (!listA .isLiteral (ExprKind .Kind .LIST ) && !hasConcreteElements (type0 )) {
665+ context .constrainValidValue (
666+ ctx .mkAnd (typeSystem .isList (listA .z3Expr ()), ctx .mkLt (idx , ctx .mkLength (seq0 ))), elem0 );
667+ }
668+ if (!listB .isLiteral (ExprKind .Kind .LIST ) && !hasConcreteElements (type1 )) {
669+ context .constrainValidValue (
670+ ctx .mkAnd (typeSystem .isList (listB .z3Expr ()), ctx .mkLt (idx , ctx .mkLength (seq1 ))), elem1 );
671+ }
666672
667673 if (i >= comprehensionUnrollLimit ) {
668674 constrainListElement (seq0 , idx , elem0 , type0 );
@@ -1138,6 +1144,12 @@ static boolean isStaticallyKnown(CelType type) {
11381144 return !kind .isDyn () && !kind .isTypeParam ();
11391145 }
11401146
1147+ /** Whether {@code type} is a list or map whose elements (or keys) have a concrete type. */
1148+ static boolean hasConcreteElements (CelType type ) {
1149+ return (type instanceof ListType || type instanceof MapType )
1150+ && isConcrete (type .parameters ().get (0 ));
1151+ }
1152+
11411153 /** Whether {@code type} and, recursively, its type parameters are statically known. */
11421154 private static boolean isConcrete (CelType type ) {
11431155 return isStaticallyKnown (type )
0 commit comments