1
+ {-# LANGUAGE TupleSections #-}
1
2
{-# LANGUAGE DataKinds #-}
2
3
{-# LANGUAGE TypeApplications #-}
3
4
{-# LANGUAGE DeriveGeneric #-}
@@ -17,6 +18,7 @@ import Control.Monad.Except (throwError)
17
18
import Control.Monad.Reader.Class (MonadReader (ask ))
18
19
import Control.Monad.State.Class
19
20
import Control.Monad.State.Strict (StateT (.. ), runStateT )
21
+ import Data.Bool (bool )
20
22
import Data.List
21
23
import qualified Data.Map as M
22
24
import Data.Maybe
@@ -33,12 +35,11 @@ import Ide.Plugin.Tactic.Judgements
33
35
import Ide.Plugin.Tactic.Machinery
34
36
import Ide.Plugin.Tactic.Naming
35
37
import Ide.Plugin.Tactic.Types
36
- import Name (nameOccName )
38
+ import Name (occNameString )
37
39
import Refinery.Tactic
38
40
import Refinery.Tactic.Internal
39
41
import TcType
40
42
import Type hiding (Var )
41
- import Data.Bool (bool )
42
43
43
44
44
45
------------------------------------------------------------------------------
@@ -60,14 +61,14 @@ assume name = rule $ \jdg -> do
60
61
True -> setRecursionFrameData True
61
62
False -> pure ()
62
63
useOccName jdg name
63
- pure $ noLoc $ var' name
64
+ pure $ (tracePrim $ " assume " <> occNameString name, ) $ noLoc $ var' name
64
65
False -> throwError $ GoalMismatch " assume" g
65
66
Nothing -> throwError $ UndefinedHypothesis name
66
67
67
68
68
69
69
70
recursion :: TacticsM ()
70
- recursion = do
71
+ recursion = tracing " recursion " $ do
71
72
defs <- getCurrentDefinitions
72
73
attemptOn (const $ fmap fst defs) $ \ name -> do
73
74
modify $ withRecursionStack (False : )
@@ -90,14 +91,16 @@ intros = rule $ \jdg -> do
90
91
let jdg' = introducing (zip vs $ coerce as)
91
92
$ withNewGoal (CType b) jdg
92
93
modify $ withIntroducedVals $ mappend $ S. fromList vs
93
- sg <- newSubgoal
94
+ (tr, sg)
95
+ <- newSubgoal
94
96
$ bool
95
97
id
96
98
(withPositionMapping
97
99
(extremelyStupid__definingFunction ctx) vs)
98
100
(isTopHole jdg)
99
101
$ jdg'
100
102
pure
103
+ . (rose (" intros {" <> intercalate " , " (fmap show vs) <> " }" ) $ pure tr, )
101
104
. noLoc
102
105
. lambda (fmap bvar' vs)
103
106
$ unLoc sg
@@ -106,7 +109,7 @@ intros = rule $ \jdg -> do
106
109
------------------------------------------------------------------------------
107
110
-- | Case split, and leave holes in the matches.
108
111
destructAuto :: OccName -> TacticsM ()
109
- destructAuto name = do
112
+ destructAuto name = tracing " destruct(auto) " $ do
110
113
jdg <- goal
111
114
case hasDestructed jdg name of
112
115
True -> throwError $ AlreadyDestructed name
@@ -126,7 +129,7 @@ destructAuto name = do
126
129
------------------------------------------------------------------------------
127
130
-- | Case split, and leave holes in the matches.
128
131
destruct :: OccName -> TacticsM ()
129
- destruct name = do
132
+ destruct name = tracing " destruct(user) " $ do
130
133
jdg <- goal
131
134
case hasDestructed jdg name of
132
135
True -> throwError $ AlreadyDestructed name
@@ -136,20 +139,20 @@ destruct name = do
136
139
------------------------------------------------------------------------------
137
140
-- | Case split, using the same data constructor in the matches.
138
141
homo :: OccName -> TacticsM ()
139
- homo = rule . destruct' (\ dc jdg ->
142
+ homo = tracing " homo " . rule . destruct' (\ dc jdg ->
140
143
buildDataCon jdg dc $ snd $ splitAppTys $ unCType $ jGoal jdg)
141
144
142
145
143
146
------------------------------------------------------------------------------
144
147
-- | LambdaCase split, and leave holes in the matches.
145
148
destructLambdaCase :: TacticsM ()
146
- destructLambdaCase = rule $ destructLambdaCase' (const subgoal)
149
+ destructLambdaCase = tracing " destructLambdaCase " $ rule $ destructLambdaCase' (const subgoal)
147
150
148
151
149
152
------------------------------------------------------------------------------
150
153
-- | LambdaCase split, using the same data constructor in the matches.
151
154
homoLambdaCase :: TacticsM ()
152
- homoLambdaCase = rule $ destructLambdaCase' (\ dc jdg ->
155
+ homoLambdaCase = tracing " homoLambdaCase " $ rule $ destructLambdaCase' (\ dc jdg ->
153
156
buildDataCon jdg dc $ snd $ splitAppTys $ unCType $ jGoal jdg)
154
157
155
158
@@ -158,7 +161,7 @@ apply = apply' (const id)
158
161
159
162
160
163
apply' :: (Int -> Judgement -> Judgement ) -> OccName -> TacticsM ()
161
- apply' f func = do
164
+ apply' f func = tracing ( " apply' " <> show func) $ do
162
165
rule $ \ jdg -> do
163
166
let hy = jHypothesis jdg
164
167
g = jGoal jdg
@@ -167,24 +170,28 @@ apply' f func = do
167
170
let (args, ret) = splitFunTys ty
168
171
unify g (CType ret)
169
172
useOccName jdg func
170
- sgs <- traverse ( \ (i, t) ->
173
+ (tr, sgs)
174
+ <- fmap unzipTrace
175
+ $ traverse ( \ (i, t) ->
171
176
newSubgoal
172
177
. f i
173
178
. blacklistingDestruct
174
179
. flip withNewGoal jdg
175
180
$ CType t
176
181
) $ zip [0 .. ] args
177
- pure . noLoc
178
- . foldl' (@@) (var' func)
179
- $ fmap unLoc sgs
182
+ pure
183
+ . (tr, )
184
+ . noLoc
185
+ . foldl' (@@) (var' func)
186
+ $ fmap unLoc sgs
180
187
Nothing -> do
181
188
throwError $ GoalMismatch " apply" g
182
189
183
190
184
191
------------------------------------------------------------------------------
185
192
-- | Choose between each of the goal's data constructors.
186
193
split :: TacticsM ()
187
- split = do
194
+ split = tracing " split(user) " $ do
188
195
jdg <- goal
189
196
let g = jGoal jdg
190
197
case splitTyConApp_maybe $ unCType g of
@@ -196,7 +203,7 @@ split = do
196
203
------------------------------------------------------------------------------
197
204
-- | Choose between each of the goal's data constructors.
198
205
splitAuto :: TacticsM ()
199
- splitAuto = do
206
+ splitAuto = tracing " split(auto) " $ do
200
207
jdg <- goal
201
208
let g = jGoal jdg
202
209
case splitTyConApp_maybe $ unCType g of
@@ -220,7 +227,7 @@ splitAuto = do
220
227
------------------------------------------------------------------------------
221
228
-- | Attempt to instantiate the given data constructor to solve the goal.
222
229
splitDataCon :: DataCon -> TacticsM ()
223
- splitDataCon dc = rule $ \ jdg -> do
230
+ splitDataCon dc = tracing ( " splitDataCon: " <> show dc) $ rule $ \ jdg -> do
224
231
let g = jGoal jdg
225
232
case splitTyConApp_maybe $ unCType g of
226
233
Just (tc, apps) -> do
0 commit comments