Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integrate top down #155

Open
wants to merge 37 commits into
base: new_webapp
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 36 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
9895dba
Start integrating our synthesize
EpicOrange Jul 1, 2020
4f37917
Fixed some type errors but stuck at implementing CheckMonad
EpicOrange Jul 2, 2020
be9d10e
got the code compiling to new branch, can't seem to test yet
EpicOrange Jul 2, 2020
1630cb5
cleaned up the code
EpicOrange Jul 2, 2020
317c083
moved files into our own TopDown directory
EpicOrange Jul 2, 2020
b64adcc
turned dfs into one function instead of dfsTop and dfs
EpicOrange Jul 6, 2020
8b29f58
cleaned up code and changed dfsNew to dfs
EpicOrange Jul 6, 2020
030f06f
Add some notes for using check
EpicOrange Jul 6, 2020
2ca1807
Started changing getUnifiedFunctions to use LogicT
EpicOrange Jul 7, 2020
6536214
Got LogicT version of dfs to lazily return the first valid result
EpicOrange Jul 7, 2020
a14c584
Changed it to evaluate solutions lazily
EpicOrange Jul 7, 2020
2d5686f
Starting to rewrite dfs again using type holes
EpicOrange Jul 8, 2020
59801bf
WIP writing the bfs
EpicOrange Jul 8, 2020
7e639ab
Maybe solveTypeConstraint is broken since it doesn't unify Int,Int
EpicOrange Jul 9, 2020
b5b8efe
Merge new_webapp changes
EpicOrange Jul 9, 2020
37de678
Moved code back to dfs and made check work
EpicOrange Jul 9, 2020
f7615ee
adding our timing stuff to synthesize
EpicOrange Jul 9, 2020
3350bff
Add iterative deepening method for dfs
EpicOrange Jul 10, 2020
6506802
right before changing dfs into logicT stuff
EpicOrange Jul 10, 2020
b53b7e6
doesn't compile... need to change dfs to one main function instead of 2
EpicOrange Jul 10, 2020
e60cc17
added comment files and copied things cuz we lazy
EpicOrange Jul 10, 2020
40f1f6a
revereted back to compiling dfs, still have broken unifiedfuncs from …
EpicOrange Jul 13, 2020
c4682be
changed getUnified to return logicT, setting code up for zheng change…
EpicOrange Jul 14, 2020
1c061ea
thought we fixed 'int /= bool' but we didnt
EpicOrange Jul 14, 2020
e54ff28
we think we are done????????????
EpicOrange Jul 14, 2020
fd0bf16
cleaned up code git add src/TopDown/Synthesize.hs git add src/TopDown…
EpicOrange Jul 14, 2020
b80d868
updated scrip stuff - arguments are in wrong order
EpicOrange Jul 15, 2020
8051385
saving code before changing depth to size
EpicOrange Jul 15, 2020
a22e228
got search based on size working. running pretty fastgit add benchmar…
EpicOrange Jul 16, 2020
d92b747
testing depth and size into .tsv files
EpicOrange Jul 16, 2020
6b7efb3
rerun depth tests
EpicOrange Jul 17, 2020
dce7a27
cleaned up code - ready for PR
EpicOrange Jul 17, 2020
fff4045
Added support for higher order functions
EpicOrange Jul 17, 2020
cb5333f
before cleaning... has some HO stuff
EpicOrange Jul 20, 2020
cd4ba26
Clean up top-down code used for tests
EpicOrange Jul 20, 2020
cc4b13a
Update test data
EpicOrange Jul 20, 2020
575105d
attempting HO... getting stuck
EpicOrange Jul 23, 2020
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
126 changes: 126 additions & 0 deletions SynthesizeTheirs.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
module HooglePlus.SynthesizeTheirs(synthesize, envToGoal) where

import Database.Environment
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please revert this file renaming

import Database.Util
import qualified HooglePlus.Abstraction as Abstraction
import PetriNet.PNSolver
import Synquid.Error
import Synquid.Logic
import Synquid.Parser
import Synquid.Pretty
import Synquid.Program
import Synquid.Resolver
import Synquid.Type
import Synquid.Util
import Types.Common
import Types.Environment
import Types.Experiments
import Types.Program
import Types.Solver
import Types.TypeChecker
import Types.Type
import Types.IOFormat
import HooglePlus.Utils
import HooglePlus.IOFormat
import Examples.ExampleChecker

import Control.Applicative ((<$>))
import Control.Concurrent.Chan
import Control.Exception
import Control.Lens
import Control.Monad
import Control.Monad.Except
import Control.Monad.Logic
import Control.Monad.Reader
import Control.Monad.State
import Data.Either
import Data.List
import Data.List.Extra (nubOrdOn)
import qualified Data.Map as Map
import Data.Map (Map)
import Data.Maybe
import qualified Data.Set as Set
import Data.Set (Set)
import Data.Time.Clock
import Data.Time.Format
import System.Exit
import Text.Parsec.Indent
import Text.Parsec.Pos
import Text.Printf (printf)


envToGoal :: Environment -> String -> IO Goal
envToGoal env queryStr = do
let transformedSig = "goal :: " ++ queryStr ++ "\ngoal = ??"
let parseResult = flip evalState (initialPos "goal") $ runIndentParserT parseProgram () "" transformedSig
case parseResult of
Left parseErr -> let e = toErrorMessage parseErr
in putDoc (pretty e) >> putDoc linebreak >> error (prettyShow e)
Right (funcDecl:decl:_) -> case decl of
Pos _ (SynthesisGoal id uprog) -> do
let Pos _ (FuncDecl _ sch) = funcDecl
let goal = Goal id env sch uprog 3 $ initialPos "goal"
let spec = runExcept $ evalStateT (resolveSchema (gSpec goal)) (initResolverState { _environment = env })
case spec of
Right sp -> do
let (env', monospec) = updateEnvWithBoundTyVars sp env
let (env'', destinationType) = updateEnvWithSpecArgs monospec env'
return $ goal { gEnvironment = env'', gSpec = sp }
Left parseErr -> putDoc (pretty parseErr) >> putDoc linebreak >> error (prettyShow parseErr)
_ -> error "parse a signature for a none goal declaration"

synthesize :: SearchParams -> Goal -> [Example] -> Chan Message -> IO ()
synthesize searchParams goal examples messageChan = catch (do
let rawEnv = gEnvironment goal
let goalType = gSpec goal
let destinationType = lastType (toMonotype goalType)
let useHO = _useHO searchParams
let rawSyms = rawEnv ^. symbols
let hoCands = rawEnv ^. hoCandidates
envWithHo <- if useHO -- add higher order query arguments
then do
let args = rawEnv ^. arguments
let hoArgs = Map.filter (isFunctionType . toMonotype) args
let hoFuns = map (\(k, v) -> (k ++ hoPostfix, withSchema toFunType v)) (Map.toList hoArgs)
return $ rawEnv {
_symbols = rawSyms `Map.union` Map.fromList hoFuns,
_hoCandidates = hoCands ++ map fst hoFuns
}
else do
let syms = Map.filter (not . isHigherOrder . toMonotype) rawSyms
return $ rawEnv {
_symbols = Map.withoutKeys syms $ Set.fromList hoCands,
_hoCandidates = []
}
-- putStrLn $ "Component number: " ++ show (Map.size $ allSymbols env)
let args = Monotype destinationType : Map.elems (envWithHo ^. arguments)
-- start with all the datatypes defined in the components, first level abstraction
let rs = _refineStrategy searchParams
let initCover = case rs of
SypetClone -> Abstraction.firstLvAbs envWithHo (Map.elems (allSymbols envWithHo))
TyGar0 -> emptySolverState ^. (refineState . abstractionCover)
TyGarQ -> Abstraction.specificAbstractionFromTypes envWithHo args
NoGar -> Abstraction.specificAbstractionFromTypes envWithHo args
NoGar0 -> emptySolverState ^. (refineState . abstractionCover)
let is =
emptySolverState
{ _searchParams = searchParams
, _refineState = emptyRefineState { _abstractionCover = initCover }
, _messageChan = messageChan
, _typeChecker = emptyChecker { _checkerChan = messageChan }
}

-- before synthesis, first check that user has provided valid examples
let exWithOutputs = filter ((/=) "??" . output) examples
checkResult <- checkExamples envWithHo goalType exWithOutputs messageChan
-- preseedExamples <- augmentTestSet envWithHo goalType
let augmentedExamples = examples -- nubOrdOn inputs $ examples ++ preseedExamples
case checkResult of
Right errs -> error (unlines ("examples does not type check" : errs))
Left _ -> evalStateT (runPNSolver envWithHo goalType augmentedExamples) is)
(\e ->
writeChan messageChan (MesgLog 0 "error" (show e)) >>
writeChan messageChan (MesgClose (CSError e)) >>
printResult (encodeWithPrefix (QueryOutput [] (show e) [])) >>
error (show e))
-- return ()
3 changes: 2 additions & 1 deletion app/HooglePlus.hs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ import Database.Generate
import Database.Download
import Database.Util
import Synquid.Util (showme)
import HooglePlus.Synthesize
import TopDown.Synthesize
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See TopDown/Synthesize about how to change this

-- import HooglePlus.Synthesize
import HooglePlus.Stats
import Types.Encoder
import HooglePlus.GHCChecker
Expand Down
Loading