Skip to content

Commit

Permalink
what4: Don't annotate {Nonce,}AppExprs
Browse files Browse the repository at this point in the history
These constructors already carry `Nonce`s, adding another layer can only
hurt performance by adding allocations/indirections, and especially,
disabling important rewrites.
  • Loading branch information
langston-barrett committed Feb 12, 2025
1 parent 13426ed commit 862a865
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
6 changes: 5 additions & 1 deletion what4/src/What4/Expr/Builder.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2044,18 +2044,22 @@ instance IsExprBuilder (ExprBuilder t st fs) where

annotateTerm sym e =
case e of
AppExpr (appExprId -> n) -> return (n, e)
BoundVarExpr (bvarId -> n) -> return (n, e)
NonceAppExpr (nonceExprApp -> Annotation _ n _) -> return (n, e)
_ -> do
NonceAppExpr (nonceExprId -> n) -> return (n, e)
_ -> do -- literals
let tpr = exprType e
n <- sbFreshIndex sym
e' <- sbNonceExpr sym (Annotation tpr n e)
return (n, e')

getAnnotation _sym e =
case e of
AppExpr (appExprId -> n) -> Just n
BoundVarExpr (bvarId -> n) -> Just n
NonceAppExpr (nonceExprApp -> Annotation _ n _) -> Just n
NonceAppExpr (nonceExprId -> n) -> Just n
_ -> Nothing

getUnannotatedTerm _sym e =
Expand Down
2 changes: 1 addition & 1 deletion what4/test/ExprBuilderSMTLib2.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1164,7 +1164,7 @@ testUnsafeSetAbstractValue2 = testCase "test unsafeSetAbstractValue2" $
e2A <- freshConstant sym (userSymbol' "x2A") (BaseBVRepr w)
e2B <- freshConstant sym (userSymbol' "x2B") (BaseBVRepr w)
e2C <- bvAdd sym e2A e2B
(_, e2C') <- annotateTerm sym $ unsafeSetAbstractValue (WUB.BVDArith (WUBA.range w 2 2)) e2C
e2C' <- opacify sym $ unsafeSetAbstractValue (WUB.BVDArith (WUBA.range w 2 2)) e2C
unsignedBVBounds e2C' @?= Just (2, 2)
e2D <- bvAdd sym e2C' =<< bvOne sym w
case asBV e2D of
Expand Down

0 comments on commit 862a865

Please sign in to comment.