@@ -581,13 +581,6 @@ private BoolExpr getStaticallyKnownNumericEquality(
581581 }
582582 }
583583
584- private BoolExpr mkIsFiniteDouble (Expr <?> z3Expr ) {
585- FPExpr fpVal = typeSystem .getDouble (z3Expr );
586- return ctx .mkAnd (
587- typeSystem .isDouble (z3Expr ),
588- ctx .mkNot (ctx .mkOr (ctx .mkFPIsNaN (fpVal ), ctx .mkFPIsInfinite (fpVal ))));
589- }
590-
591584 private BoolExpr getDynamicNumericEquality (Expr <?> z3Expr0 , Expr <?> z3Expr1 ) {
592585 BoolExpr isIntOrUint0 = ctx .mkOr (typeSystem .isInt (z3Expr0 ), typeSystem .isUint (z3Expr0 ));
593586 BoolExpr isIntOrUint1 = ctx .mkOr (typeSystem .isInt (z3Expr1 ), typeSystem .isUint (z3Expr1 ));
@@ -614,33 +607,27 @@ private BoolExpr getDynamicNumericEquality(Expr<?> z3Expr0, Expr<?> z3Expr1) {
614607 BoolExpr isIntOrUintAndDouble = ctx .mkAnd (isIntOrUint0 , typeSystem .isDouble (z3Expr1 ));
615608 BoolExpr isDoubleAndIntOrUint = ctx .mkAnd (typeSystem .isDouble (z3Expr0 ), isIntOrUint1 );
616609
617- FPExpr fpVal1 = typeSystem .getDouble (z3Expr1 );
618- ArithExpr <?> realVal0 = ctx .mkInt2Real (val0 );
619- BoolExpr intDoubleEq =
620- ctx .mkAnd (
621- mkIsFiniteDouble (z3Expr1 ),
622- ctx .mkLe (realVal0 , ctx .mkFPToReal (fpVal1 )),
623- ctx .mkLe (ctx .mkFPToReal (fpVal1 ), realVal0 ));
624-
625- FPExpr fpVal0 = typeSystem .getDouble (z3Expr0 );
626- ArithExpr <?> realVal1 = ctx .mkInt2Real (val1 );
627- BoolExpr doubleIntEq =
628- ctx .mkAnd (
629- mkIsFiniteDouble (z3Expr0 ),
630- ctx .mkLe (realVal1 , ctx .mkFPToReal (fpVal0 )),
631- ctx .mkLe (ctx .mkFPToReal (fpVal0 ), realVal1 ));
610+ // Likewise fall back to 0.0, which the int/double comparisons never need to define.
611+ FPExpr fpVal0 = guardedDouble (z3Expr0 );
612+ FPExpr fpVal1 = guardedDouble (z3Expr1 );
632613
633614 return (BoolExpr )
634615 CelZ3Exprs .SwitchBuilder .newBuilder (ctx )
635616 .addCase (bothIntOrUint , ctx .mkEq (val0 , val1 ))
636617 .addCase (
637618 bothDouble ,
638619 ctx .mkFPEq (typeSystem .getDouble (z3Expr0 ), typeSystem .getDouble (z3Expr1 )))
639- .addCase (isIntOrUintAndDouble , intDoubleEq )
640- .addCase (isDoubleAndIntOrUint , doubleIntEq )
620+ .addCase (isIntOrUintAndDouble , typeSystem . intEqDouble ( val0 , fpVal1 ) )
621+ .addCase (isDoubleAndIntOrUint , typeSystem . intEqDouble ( val1 , fpVal0 ) )
641622 .build (ctx .mkFalse ());
642623 }
643624
625+ private FPExpr guardedDouble (Expr <?> z3Expr ) {
626+ return (FPExpr )
627+ ctx .mkITE (
628+ typeSystem .isDouble (z3Expr ), typeSystem .getDouble (z3Expr ), typeSystem .mkFpDouble (0.0 ));
629+ }
630+
644631 private boolean hasOptionalElements (TranslatedValue arg ) {
645632 return arg .isLiteral (ExprKind .Kind .LIST )
646633 && !arg .celExpr ().get ().list ().optionalIndices ().isEmpty ();
@@ -672,6 +659,10 @@ private BoolExpr unrollListEquality(
672659 IntExpr idx = ctx .mkInt (i );
673660 Expr <?> elem0 = ctx .mkNth (seq0 , idx );
674661 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 );
675666
676667 if (i >= comprehensionUnrollLimit ) {
677668 constrainListElement (seq0 , idx , elem0 , type0 );
@@ -730,8 +721,8 @@ private TranslatedValue translateEquality(
730721 } else if (isStaticallyKnown (type0 ) && isStaticallyKnown (type1 )) {
731722 equality = typeSystem .getStructuralEquality (z3Arg0 , z3Arg1 );
732723 } else {
733- boolean canBeNumeric0 = type0 . kind () == CelKind . DYN || isNumericType (type0 );
734- boolean canBeNumeric1 = type1 . kind () == CelKind . DYN || isNumericType (type1 );
724+ boolean canBeNumeric0 = ! isStaticallyKnown ( type0 ) || isNumericType (type0 );
725+ boolean canBeNumeric1 = ! isStaticallyKnown ( type1 ) || isNumericType (type1 );
735726
736727 // Check if one side is an explicit LIST that we can unroll
737728 BoolExpr structuralEq = typeSystem .getStructuralEquality (z3Arg0 , z3Arg1 );
@@ -906,23 +897,19 @@ private Expr<?> buildMapIndex(
906897 mapValues );
907898
908899 // Double probes
909- FPExpr dVal =
910- (FPExpr )
911- (Expr ) ctx .mkITE (isDouble , typeSystem .getDouble (rhsTrans ), typeSystem .mkFpDouble (0.0 ));
912- IntExpr dInt = ctx .mkReal2Int (ctx .mkFPToReal (dVal ));
913- BoolExpr doubleIsExact =
914- ctx .mkAnd (
915- isDouble ,
916- ctx .mkNot (ctx .mkOr (ctx .mkFPIsNaN (dVal ), ctx .mkFPIsInfinite (dVal ))),
917- ctx .mkEq (ctx .mkInt2Real (dInt ), ctx .mkFPToReal (dVal )));
900+ FPExpr dVal = guardedDouble (rhsTrans );
901+ IntExpr dInt = typeSystem .truncateDouble (dVal );
902+ BoolExpr doubleIsExact = typeSystem .isIntegral (dVal );
918903 Expr <?> doubleIntKey = typeSystem .wrapInt (dInt );
919904 Expr <?> doubleUintKey = typeSystem .wrapUint (dInt );
905+ // TODO: -2^63 finds an int key here, but the spec doesn't say whether it should.
906+ BoolExpr doubleHasInt = ctx .mkAnd (doubleIsExact , ctx .mkNot (typeSystem .checkIntOverflow (dInt )));
920907 BoolExpr doubleHasUint = ctx .mkAnd (doubleIsExact , ctx .mkGe (dInt , ctx .mkInt (0 )));
921908 ProbeResult doubleProbe =
922909 createProbeResult (
923910 inMapOrig ,
924911 valOrig ,
925- doubleIsExact ,
912+ doubleHasInt ,
926913 doubleIntKey ,
927914 doubleHasUint ,
928915 doubleUintKey ,
0 commit comments