Skip to content

Allow hole filling to deal with recursion #472

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

Merged
merged 50 commits into from
Oct 19, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
3527cd2
WIP recursion
isovector Oct 3, 2020
da2d729
Better scoring heuristic
isovector Oct 4, 2020
b805aa9
Don't trace scoring
isovector Oct 4, 2020
1dbec5b
Add fromMaybe test
isovector Oct 4, 2020
803c8d7
wtf; recursion stack frame doesnt seem to work
isovector Oct 4, 2020
fe468f3
Better debugging and smarter apply'
isovector Oct 5, 2020
68cda51
filterT
isovector Oct 5, 2020
a480c19
Fix FilterT
TOTBWF Oct 5, 2020
8fa2a83
derive foldr
isovector Oct 5, 2020
6dee3a2
Merge branch 'recursion-frame-wtf' of github.com:isovector/haskell-la…
isovector Oct 5, 2020
a6e40e1
Test for foldr
isovector Oct 5, 2020
7981a71
Fix JoinCont test
isovector Oct 5, 2020
69d122b
Use generic-lens
isovector Oct 5, 2020
a781803
Positionally-aware recursion
isovector Oct 6, 2020
60ebb74
almost generate fmap for binary tree
isovector Oct 6, 2020
9714f7e
timeout tactic if it's too slow
isovector Oct 6, 2020
3ac43d8
Simpler recursive hypothesis
isovector Oct 6, 2020
89a488a
Remove current position from jdg
isovector Oct 6, 2020
c774fe1
Restrict homomorphic splits to positional args
isovector Oct 6, 2020
4b682a2
Silence a trace
isovector Oct 6, 2020
ab2e592
Better data provenance
isovector Oct 7, 2020
5ddd360
Support multiple positional binding sets
isovector Oct 7, 2020
a3dc935
Prune destructing on pattern vals if they don't introduce new types
isovector Oct 7, 2020
abd365f
Fix pruning to actually run the tactic
isovector Oct 8, 2020
8d53032
Count duplicates
isovector Oct 8, 2020
b8b0d0d
?
isovector Oct 8, 2020
ec13e9f
Don't allow splitting if it doesn't buy you anything
isovector Oct 8, 2020
683c791
Known fmap strategy
isovector Oct 8, 2020
4114d03
Commit to a known solution if one exists
isovector Oct 9, 2020
6ff6504
Compute top level position vals
isovector Oct 9, 2020
29858b0
Add tophole to jdg
isovector Oct 9, 2020
929bcc9
Cleanup ugly hack in intros! \o/
isovector Oct 9, 2020
3272a1e
Fix improperly pruning split of split
isovector Oct 9, 2020
30c9b58
Tracing
isovector Oct 11, 2020
6b8a0b9
unpack introduced bindings
isovector Oct 11, 2020
872cfec
Slightly better format
isovector Oct 11, 2020
8a416d9
compress ppr tree
isovector Oct 11, 2020
621a04d
Merge pull request #26 from isovector/tracing
isovector Oct 13, 2020
8e69004
Fix splitAuto
isovector Oct 13, 2020
a84195c
Cleanup traces
isovector Oct 13, 2020
5f44746
Fix autosplit
isovector Oct 13, 2020
04774c1
Merge branch 'master' into recursion
isovector Oct 16, 2020
4eca10d
Update refinery
isovector Oct 16, 2020
de0cfb9
Attempt GHC compatability
isovector Oct 16, 2020
1b70cee
cpp nightmares
isovector Oct 16, 2020
b700c35
type syn of type syn
isovector Oct 16, 2020
25b9133
wtfff
isovector Oct 16, 2020
baac450
maybe this time
isovector Oct 16, 2020
c6e10fd
omg plzz 810
isovector Oct 16, 2020
c26f9ba
dsgjdsgidgjis
isovector Oct 16, 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
Prev Previous commit
Next Next commit
Known fmap strategy
  • Loading branch information
isovector committed Oct 8, 2020
commit 683c7914e937ba3d9258486e102b92b36fa4be7c
2 changes: 2 additions & 0 deletions haskell-language-server.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,13 @@ executable haskell-language-server
Ide.Plugin.Retrie
Ide.Plugin.StylishHaskell
Ide.Plugin.Tactic
Ide.Plugin.Tactic.Auto
Ide.Plugin.Tactic.CodeGen
Ide.Plugin.Tactic.Context
Ide.Plugin.Tactic.Debug
Ide.Plugin.Tactic.GHC
Ide.Plugin.Tactic.Judgements
Ide.Plugin.Tactic.KnownStrategies
Ide.Plugin.Tactic.Machinery
Ide.Plugin.Tactic.Naming
Ide.Plugin.Tactic.Range
Expand Down
1 change: 1 addition & 0 deletions plugins/tactics/src/Ide/Plugin/Tactic.hs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import qualified FastString
import GHC.Generics (Generic)
import GHC.LanguageExtensions.Type (Extension (LambdaCase))
import Ide.Plugin (mkLspCommand)
import Ide.Plugin.Tactic.Auto
import Ide.Plugin.Tactic.Context
import Ide.Plugin.Tactic.GHC
import Ide.Plugin.Tactic.Judgements
Expand Down
18 changes: 18 additions & 0 deletions plugins/tactics/src/Ide/Plugin/Tactic/Auto.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
module Ide.Plugin.Tactic.Auto where

import Control.Applicative
import Ide.Plugin.Tactic.Context
import Ide.Plugin.Tactic.Judgements
import Ide.Plugin.Tactic.KnownStrategies
import Ide.Plugin.Tactic.Tactics
import Ide.Plugin.Tactic.Types


------------------------------------------------------------------------------
-- | Automatically solve a goal.
auto :: TacticsM ()
auto = do
current <- getCurrentDefinitions
knownStrategies
<|> (localTactic (auto' 4) $ disallowing $ fmap fst current)

37 changes: 37 additions & 0 deletions plugins/tactics/src/Ide/Plugin/Tactic/KnownStrategies.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{-# LANGUAGE LambdaCase #-}

module Ide.Plugin.Tactic.KnownStrategies where

import Control.Monad.Error.Class
import Ide.Plugin.Tactic.Context (getCurrentDefinitions)
import Ide.Plugin.Tactic.Tactics
import Ide.Plugin.Tactic.Types
import OccName (mkVarOcc)
import Refinery.Tactic


knownStrategies :: TacticsM ()
knownStrategies = choice
[ deriveFmap
]


known :: String -> TacticsM () -> TacticsM ()
known name t = do
getCurrentDefinitions >>= \case
[(def, _)] | def == mkVarOcc name -> do
traceMX "running known strategy" name
t
_ -> throwError NoApplicableTactic


deriveFmap :: TacticsM ()
deriveFmap = known "fmap" $ do
try intros
overAlgebraicTerms homo
choice
[ overFunctions apply >> auto' 2
, assumption
, recursion
]

34 changes: 11 additions & 23 deletions plugins/tactics/src/Ide/Plugin/Tactic/Tactics.hs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import Data.List
import qualified Data.Map as M
import Data.Maybe
import qualified Data.Set as S
import DataCon
import Development.IDE.GHC.Compat
import GHC.Exts
import GHC.SourceGen.Expr
Expand All @@ -32,12 +33,11 @@ import Ide.Plugin.Tactic.Judgements
import Ide.Plugin.Tactic.Machinery
import Ide.Plugin.Tactic.Naming
import Ide.Plugin.Tactic.Types
import Name (nameOccName)
import Refinery.Tactic
import Refinery.Tactic.Internal
import TcType
import Type hiding (Var)
import Name (nameOccName)
import DataCon


------------------------------------------------------------------------------
Expand Down Expand Up @@ -242,43 +242,31 @@ localTactic t f = do
runStateT (unTacticT t) $ f jdg


------------------------------------------------------------------------------
-- | Automatically solve a goal.
auto :: TacticsM ()
auto = do
current <- getCurrentDefinitions
jdg <- goal
traceM $ mappend "!!!auto current:" $ show current
traceM $ mappend "!!!auto jdg:" $ show jdg
localTactic (auto' 5) $ disallowing $ fmap fst current


auto' :: Int -> TacticsM ()
auto' 0 = throwError NoProgress
auto' n = do
let loop = auto' (n - 1)
try intros
choice
[ attemptOn functionNames $ \fname -> do
[ overFunctions $ \fname -> do
apply fname
loop
, attemptOn algebraicNames $ \aname -> do
, overAlgebraicTerms $ \aname -> do
destructAuto aname
loop
, splitAuto >> loop
, assumption >> loop
, recursion
]

overFunctions :: (OccName -> TacticsM ()) -> TacticsM ()
overFunctions =
attemptOn $ M.keys . M.filter (isFunction . unCType) . jHypothesis

functionNames :: Judgement -> [OccName]
functionNames =
M.keys . M.filter (isFunction . unCType) . jHypothesis


algebraicNames :: Judgement -> [OccName]
algebraicNames =
M.keys . M.filter (isJust . algebraicTyCon . unCType) . jHypothesis
overAlgebraicTerms :: (OccName -> TacticsM ()) -> TacticsM ()
overAlgebraicTerms =
attemptOn $
M.keys . M.filter (isJust . algebraicTyCon . unCType) . jHypothesis


allNames :: Judgement -> [OccName]
Expand Down