Skip to content

Commit

Permalink
Merge pull request #705 from AlecsFerra/develop
Browse files Browse the repository at this point in the history
Extensional reasoning on Values
  • Loading branch information
facundominguez authored Oct 9, 2024
2 parents 4233197 + b49e479 commit 3ff2766
Show file tree
Hide file tree
Showing 10 changed files with 306 additions and 113 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
messages in LH
[#2346](https://github.com/ucsd-progsys/liquidhaskell/issues/2346).
- Support extensionality in PLE [#704](https://github.com/ucsd-progsys/liquid-fixpoint/pull/704)
- Add a new flag `--etabeta` to reason with lambdas in PLE [#705](https://github.com/ucsd-progsys/liquid-fixpoint/pull/705)

## 0.9.6.3.1 (2024-08-21)

Expand Down
2 changes: 1 addition & 1 deletion src/Language/Fixpoint/Smt/Serialize.hs
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ smt2VarAs :: SymEnv -> Symbol -> Sort -> Builder
smt2VarAs env x t = parenSeqs ["as", smt2 env x, smt2SortMono x env t]

smt2Lam :: SymEnv -> (Symbol, Sort) -> Expr -> Builder
smt2Lam env (x, xT) (ECst e eT) = parenSeqs [Builder.fromText lambda, x', smt2 env e]
smt2Lam env (x, xT) full@(ECst _ eT) = parenSeqs [Builder.fromText lambda, x', smt2 env full]
where
x' = smtLamArg env x xT
lambda = symbolAtName lambdaName env () (FFunc xT eT)
Expand Down
2 changes: 1 addition & 1 deletion src/Language/Fixpoint/Solver/Common.hs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ askSMT :: Config -> Context -> [(Symbol, Sort)] -> Expr -> IO Bool
askSMT cfg ctx xs e
-- | isContraPred e = return False
| isTautoPred e = return True
| null (kvarsExpr e) = checkValidWithContext ctx [] PTrue e'
| null (kvarsExpr e) = checkValidWithContext ctx xs PTrue e'
| otherwise = return False
where
e' = toSMT "askSMT" cfg ctx xs e
Expand Down
362 changes: 258 additions & 104 deletions src/Language/Fixpoint/Solver/PLE.hs

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions src/Language/Fixpoint/Solver/Rewrite.hs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ ordConstraints (RESTFuel m) _ = bimapConstraints Fuel asFuel $ fuelOC m
asFuel _ = undefined


-- Note: if you change the domain of this function, you need to change
-- also Language.Fixpoint.Solver.PLE.isExprRewritable
convert :: Expr -> RT.RuntimeTerm
convert (EIte i t e) = RT.App "$ite" $ map convert [i,t,e]
convert e@EApp{} | (f, terms) <- splitEAppThroughECst e, EVar fName <- dropECst f
Expand Down
2 changes: 2 additions & 0 deletions src/Language/Fixpoint/Types/Config.hs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ data Config = Config
, noslice :: Bool -- ^ Disable non-concrete KVar slicing
, rewriteAxioms :: Bool -- ^ Allow axiom instantiation via rewriting
, pleWithUndecidedGuards :: Bool -- ^ Unfold invocations with undecided guards in PLE
, etabeta :: Bool -- ^ Eta expand and beta reduce terms to aid PLE
, interpreter :: Bool -- ^ Do not use the interpreter to assist PLE
, oldPLE :: Bool -- ^ Use old version of PLE
, noIncrPle :: Bool -- ^ Use incremental PLE
Expand Down Expand Up @@ -259,6 +260,7 @@ defConfig = Config {
&= name "interpreter"
&= help "Use the interpreter to assist PLE"
, oldPLE = False &= help "Use old version of PLE"
, etabeta = False &= help "Use eta expansion and beta reduction to aid PLE"
, noIncrPle = False &= help "Don't use incremental PLE"
, noEnvironmentReduction =
False
Expand Down
8 changes: 7 additions & 1 deletion src/Language/Fixpoint/Types/Names.hs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ module Language.Fixpoint.Types.Names (

, lambdaName
, lamArgSymbol
, isLamArgSymbol
, isLamArgSymbol, etaExpSymbol

) where

Expand Down Expand Up @@ -611,6 +611,12 @@ lambdaName = "smt_lambda"
lamArgPrefix :: Symbol
lamArgPrefix = "lam_arg"

etaExpPrefix :: Symbol
etaExpPrefix = "eta"

etaExpSymbol :: Int -> Symbol
etaExpSymbol = intSymbol etaExpPrefix

lamArgSymbol :: Int -> Symbol
lamArgSymbol = intSymbol lamArgPrefix

Expand Down
4 changes: 4 additions & 0 deletions src/Language/Fixpoint/Types/Theories.hs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ module Language.Fixpoint.Types.Theories (
, symEnvSort
, symEnvTheory
, insertSymEnv
, deleteSymEnv
, insertsSymEnv
, symbolAtName
, symbolAtSmtName
Expand Down Expand Up @@ -151,6 +152,9 @@ symEnvSort x env = lookupSEnv x (seSort env)
insertSymEnv :: Symbol -> Sort -> SymEnv -> SymEnv
insertSymEnv x t env = env { seSort = insertSEnv x t (seSort env) }

deleteSymEnv :: Symbol -> SymEnv -> SymEnv
deleteSymEnv x env = env { seSort = deleteSEnv x (seSort env) }

insertsSymEnv :: SymEnv -> [(Symbol, Sort)] -> SymEnv
insertsSymEnv = L.foldl' (\env (x, s) -> insertSymEnv x s env)

Expand Down
24 changes: 24 additions & 0 deletions tests/pos/eta_cons.fq
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
fixpoint "--rewrite"
fixpoint "--allowho"
fixpoint "--etabeta"

constant f : (func(0 , [int; int; int]))
define f (x : int, y: int) : int = {(x + y)}

constant g : (func(0 , [int; int; int]))
define g (a : int, b: int) : int = {(b + a)}


data Ty 0 = [
| Cons {mkCons : func(0 , [int; int; int])}
]

constant Cons : (func(0 , [func(0 , [int; int; int]); Ty]))

expand [1 : True; 2 : True]

constraint:
env []
lhs {VV1 : Tuple | true }
rhs {VV2 : Tuple | (Cons f = Cons g) }
id 2 tag []
12 changes: 6 additions & 6 deletions tests/tasty/SimplifyPLE.hs
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ simplify' = PLE.simplify emptyKnowledge emptyICtx
emptyICtx :: PLE.ICtx
emptyICtx =
ICtx
{ icAssms = S.empty, -- S.HashSet Pred
icCands = S.empty, -- :: S.HashSet Expr
icEquals = S.empty, -- :: EvAccum
icSimpl = SM.empty, -- :: !ConstMap
icSubcId = Nothing, -- :: Maybe SubcId
icANFs = [] -- :: [[(Symbol, SortedReft)]]
{ icAssms = S.empty, -- S.HashSet Pred
icCands = S.empty, -- :: S.HashSet Expr
icEquals = S.empty, -- :: EvAccum
icSimpl = SM.empty, -- :: !ConstMap
icSubcId = Nothing, -- :: Maybe SubcId
icANFs = [] -- :: [[(Symbol, SortedReft)]]
}

0 comments on commit 3ff2766

Please sign in to comment.