Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
c37f5d5
start work on global potl inference
dcao Aug 9, 2020
d1b2a6e
clean up after myself :^)
dcao Aug 9, 2020
fb10d5e
fix Z3
dcao Aug 9, 2020
3b13b9a
finish basic global potl inference impl
dcao Aug 10, 2020
79939c8
fix bug with nested abstract potentials
dcao Aug 10, 2020
77e414e
updated inference tests
dcao Aug 10, 2020
a59164f
implement initial dependent resource inference
dcao Aug 12, 2020
9cd6d2e
add impl for upperBoundToConstraint
dcao Aug 12, 2020
3bb6708
update inference test suite
dcao Aug 12, 2020
8fbd7d1
add actual dependent optimization
dcao Aug 12, 2020
252f076
provide arguments for inferred potl vars
dcao Aug 13, 2020
d0502dc
add temporary changes
dcao Aug 13, 2020
7ecb6ae
add debug-friendly changes
dcao Aug 17, 2020
fbd205c
switch back to optimizeAssert for correctness
dcao Aug 17, 2020
b9f8a23
fix formula tracked name uniqueness bug
dcao Aug 18, 2020
aa655b3
allow specifying const/dep res inference from cmd line
dcao Aug 18, 2020
a773f14
merge master into dependent-res-infer
dcao Aug 19, 2020
4bf8ad1
pending subs
tjknoth Aug 21, 2020
49a28cd
actually do pending subs
tjknoth Aug 21, 2020
1fdee3a
move List-Replicate test
dcao Aug 23, 2020
fca1d34
add well-formedness constraint for inferred potls
dcao Aug 23, 2020
22cd5dd
add fixes in prep for multiplicity inference
dcao Aug 24, 2020
50c84ff
merge cegis fixes from master
dcao Aug 24, 2020
c463dcd
fix bug which broke cegis inference on constant examples
dcao Aug 25, 2020
22c2638
merge cgen fixes from master
dcao Aug 26, 2020
3d191a1
add merge-sort-quadratic as passing test
dcao Aug 26, 2020
6bf62fa
add list-merge-flatten to passing tests
dcao Aug 26, 2020
09036ee
fix bug with constant optimization preserving state
dcao Aug 30, 2020
47b5208
update tests
dcao Aug 30, 2020
31db3b5
add dependent optimization loop
dcao Sep 5, 2020
4710ede
fix some shit
tjknoth Dec 3, 2020
712043b
merge
tjknoth Dec 3, 2020
499e2b4
range
tjknoth Dec 5, 2020
9b261b4
add separate envs for rvars
dcao Dec 7, 2020
eb1b083
merge
dcao Dec 7, 2020
1efd61a
fixed up
tjknoth Dec 8, 2020
f9c9269
preliminary conditional work
dcao Dec 11, 2020
dba6aea
finish preliminary conditional work
dcao Dec 13, 2020
51f5471
add optimizations to cond res expr synthesis
dcao Jan 8, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 11 additions & 20 deletions bin/Synquid.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import Synquid.Program
import Synquid.Error
import Synquid.Pretty
import Synquid.Parser
import Synquid.Logic (Formula(..), QSpace)
import Synquid.Logic (Formula(..))
import Synquid.Resolver (resolveDecls)
import Synquid.Solver.Monad hiding (name)
import Synquid.Solver.HornClause
Expand All @@ -16,24 +16,20 @@ import Synquid.Synthesis.Util
import Synquid.HtmlOutput
import Synquid.Solver.Types
import Synquid.Solver.CEGIS (initCEGISState)
import Synquid.Z3 (z3LitToInt)

import Control.Applicative ((<|>))
import Control.Monad
import Control.Monad.State hiding (fix)
import System.Exit
import System.Console.CmdArgs
import Data.Time.Calendar
import qualified Data.Map as Map
import Data.Map.Ordered (OMap)
import qualified Data.Map.Ordered as OMap
import Data.Set (Set)
import qualified Data.Set as Set
import Control.Lens ((.~), (^.), (%~), (&), (%=), _last, _Just)
import Data.Maybe (isJust)
import Control.Lens ((.~), (^.), (%~), (%=), _last, _Just)

import Data.List.Split

import Debug.Pretty.Simple

programName = "resyn"
versionName = "0.1"
releaseDate = fromGregorian 2020 7 15
Expand All @@ -55,8 +51,9 @@ main = do
_constantTime = constTime,
_cegisBound = cegis_max,
_enumerate = ec,
_inferResources = infer,
_inferResources = isJust infer,
_rsolver = res_solver,
_rSolverDomain = maybe Constant id infer,
_sygusLog = logfile,
_cvc4 = cvc4cmd
}
Expand Down Expand Up @@ -146,7 +143,7 @@ data CommandLineArgs
ct :: Bool,
cegis_max :: Int,
eac :: Bool,
infer :: Bool,
infer :: Maybe RDomain,
res_solver :: ResourceSolver,
logfile :: Maybe String,
solve_sygus :: String
Expand Down Expand Up @@ -186,7 +183,7 @@ synt = Synthesis {
ct = False &= help ("Require that all branching expressions consume a constant amount of resources (default: False)"),
cegis_max = 100 &= help ("Maximum number of iterations through the CEGIS loop (default: 100)"),
eac = False &= help ("Enumerate-and-check instead of round-trip resource analysis (default: False)"),
infer = False &= help ("Infer all resource bounds (default: False)"),
infer = Nothing &= help ("Infer all resource bounds (default: False)"),
res_solver = CEGIS &= help (unwords ["Which solver should be used for resource constraints?", show SYGUS, show CEGIS, show Incremental, "(default: ", show CEGIS, ")"]),
logfile = Nothing &= help ("File for logging SYGUS constraints (default: no logging)"),
solve_sygus = "cvc4" &= help ("Command to run SYGUS solver (default: \"cvc4\")")
Expand Down Expand Up @@ -310,7 +307,7 @@ runOnFile synquidParams explorerParams solverParams file libs = do
-- potentials and their values
when ((not (null results)) && infer) $ do
-- We first replace all our Z3 lits where we can to avoid derefencing freed ptrs
let potls = fmap (fmap z3litToInt) $ (finalTState (last results)) ^. persistentState . inferredRVars
let potls = fmap (fmap z3LitToInt) $ (finalTState (last results)) ^. persistentState . inferredRVars

liftIO $ mapM_ (\g -> pdoc ((prettyWithInferred potls g) <+> text "(inferred)"))
$ fmap goal results
Expand Down Expand Up @@ -344,12 +341,9 @@ runOnFile synquidParams explorerParams solverParams file libs = do
-- we collect all res constraints into our state and solve these constraints
-- at the very end.

-- TODO: This is awful for performance. Right now we check all created resource constraints
-- for each function as type-check it. This is good for errors, bad for performance.
-- We should try to not do resource checking until the very end

-- We first modify our persistent typing state to add the inferred potl vars of this goal
_Just . inferredRVars %= \x -> OMap.unionWithL (\_ -> const) x (OMap.fromList [(p, Nothing) | p <- gInferredPotlVars goal])
_Just . inferredRVars %= \x -> OMap.unionWithL (\_ -> const) x (OMap.fromList [(p, Nothing) | (p, _, _) <- gInferredPotlVars goal])
_Just . resourceVars %= (flip Map.union) (Map.fromList $ [(a, b) | (a, b, _) <- gInferredPotlVars goal])

-- We first get our persistent typing state and pass it through
mpts <- get
Expand All @@ -366,9 +360,6 @@ runOnFile synquidParams explorerParams solverParams file libs = do

return result

z3litToInt (Z3Lit _ _ s) = IntLit (read s :: Int)
z3litToInt x = x

assembleResult goal ps = SynthesisResult (fst (head ps)) (snd (head ps)) (tail ps) goal
updateLogLevel goal orig = if gSynthesize goal then orig else 0 -- prevent logging while type checking measures

Expand Down
10 changes: 0 additions & 10 deletions src/Synquid/Logic.hs
Original file line number Diff line number Diff line change
Expand Up @@ -235,16 +235,6 @@ unknownsOf (Cons _ _ es) = Set.unions $ map unknownsOf es
unknownsOf (All _ e) = unknownsOf e
unknownsOf _ = Set.empty

-- collect guards of ITE expressions
-- careful, this should only be used on resource formulas!
itesOf :: Formula -> [Formula]
itesOf (Ite g t f) = [Ite g t f] -- Assumes no nested ITEs!
itesOf (WithSubst _ f) = itesOf f
itesOf (Unary _ f) = itesOf f
itesOf (Binary _ f g) = itesOf f ++ itesOf g
itesOf _ = []



-- | 'posNegUnknowns' @fml@: sets of positive and negative predicate unknowns in @fml@
posNegUnknowns :: Formula -> (Set Id, Set Id)
Expand Down
4 changes: 1 addition & 3 deletions src/Synquid/Pretty.hs
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,7 @@ import Text.PrettyPrint.ANSI.Leijen hiding ((<+>), (<$>), hsep, vsep)
import qualified Text.PrettyPrint.ANSI.Leijen as L
import qualified Data.Set as Set
import qualified Data.Map as Map
import qualified Data.Map.Ordered as OMap
import Data.Map (Map)
import Data.Map.Ordered (OMap)
import Data.Set (Set)
import Data.List
import Data.Maybe (fromMaybe)
Expand Down Expand Up @@ -198,7 +196,7 @@ fmlDocAt n fml = condHlParens (n' <= n) (
SetLit s elems -> hlBrackets $ commaSep $ map fmlDoc elems
Var s name -> if name == valueVarName then special name else text name
Unknown s name -> if Map.null s then text name else hMapDoc pretty pretty s <> text name
WithSubst _ e -> fmlDocAt n' e
WithSubst s e -> if Map.null s then fmlDocAt n' e else hMapDoc pretty pretty s <> fmlDocAt n' e
Unary op e -> pretty op <> fmlDocAt n' e
Binary op e1 e2 -> fmlDocAt n' e1 <+> pretty op <+> fmlDocAt n' e2
Ite e0 e1 e2 -> keyword "if" <+> fmlDoc e0 <+> keyword "then" <+> fmlDoc e1 <+> keyword "else" <+> fmlDoc e2
Expand Down
3 changes: 2 additions & 1 deletion src/Synquid/Program.hs
Original file line number Diff line number Diff line change
Expand Up @@ -658,7 +658,7 @@ data Goal = Goal {
gImpl :: UProgram, -- ^ Implementation template
gDepth :: Int, -- ^ Maximum level of auxiliary goal nesting allowed inside this goal
gSourcePos :: SourcePos, -- ^ Source Position,
gInferredPotlVars :: [Id], -- ^ Set of potential vars to infer for this fn
gInferredPotlVars :: [(Id, [Formula], Environment)], -- ^ Set of potential vars to infer for this fn
gInferSolve :: Bool, -- ^ If gInferredPotlVars isn't empty, indicates if we should actually solve inference constraints or just collect them without solving
gSynthesize :: Bool -- ^ Synthesis flag (false implies typechecking only)
} deriving (Show, Eq, Ord)
Expand Down Expand Up @@ -793,3 +793,4 @@ defaultSetType = DataDecl name typeVars preds cons
insert = ConstructorSig insertSetCtor (FunctionT "x" (ScalarT (TypeVarT Map.empty "a" defMultiplicity) (BoolLit True) defPotential) (FunctionT "xs" (ScalarT (DatatypeT setTypeName [ScalarT (TypeVarT Map.empty "a" defMultiplicity) (BoolLit True) defPotential] []) (BoolLit True) defPotential) (ScalarT (DatatypeT setTypeName [ScalarT (TypeVarT Map.empty "a" defMultiplicity) (BoolLit True) defPotential] []) (BoolLit True) defPotential) defCost) defCost)

setConstructors = [emptySetCtor, singletonCtor, insertSetCtor]

Loading