@@ -16,6 +16,7 @@ import Development.IDE.Spans.LocalBindings
16
16
import OccName
17
17
import SrcLoc
18
18
import Type
19
+ import Wingman.GHC (algebraicTyCon )
19
20
import Wingman.Types
20
21
21
22
@@ -149,7 +150,10 @@ findPositionVal :: Judgement' a -> OccName -> Int -> Maybe OccName
149
150
findPositionVal jdg defn pos = listToMaybe $ do
150
151
-- It's important to inspect the entire hypothesis here, as we need to trace
151
152
-- ancstry through potentially disallowed terms in the hypothesis.
152
- (name, hi) <- M. toList $ M. map (overProvenance expandDisallowed) $ hyByName $ jEntireHypothesis jdg
153
+ (name, hi) <- M. toList
154
+ $ M. map (overProvenance expandDisallowed)
155
+ $ hyByName
156
+ $ jEntireHypothesis jdg
153
157
case hi_provenance hi of
154
158
TopLevelArgPrv defn' pos' _
155
159
| defn == defn'
@@ -238,12 +242,13 @@ patternHypothesis scrutinee dc jdg
238
242
= introduceHypothesis $ \ _ pos ->
239
243
PatternMatchPrv $
240
244
PatVal
241
- scrutinee
242
- (maybe mempty
243
- (\ scrut -> S. singleton scrut <> getAncestry jdg scrut)
244
- scrutinee)
245
- (Uniquely dc)
246
- pos
245
+ scrutinee
246
+ (maybe
247
+ mempty
248
+ (\ scrut -> S. singleton scrut <> getAncestry jdg scrut)
249
+ scrutinee)
250
+ (Uniquely dc)
251
+ pos
247
252
248
253
249
254
------------------------------------------------------------------------------
@@ -285,6 +290,21 @@ jLocalHypothesis
285
290
. jHypothesis
286
291
287
292
293
+ ------------------------------------------------------------------------------
294
+ -- | Given a judgment, return the hypotheses that are acceptable to destruct.
295
+ --
296
+ -- We use the ordering of the hypothesis for this purpose. Since new bindings
297
+ -- are always inserted at the beginning, we can impose a canonical ordering on
298
+ -- which order to try destructs by what order they are introduced --- stopping
299
+ -- at the first one we've already destructed.
300
+ jAcceptableDestructTargets :: Judgement' CType -> [HyInfo CType ]
301
+ jAcceptableDestructTargets
302
+ = filter (isJust . algebraicTyCon . unCType . hi_type)
303
+ . takeWhile (not . isAlreadyDestructed . hi_provenance)
304
+ . unHypothesis
305
+ . jEntireHypothesis
306
+
307
+
288
308
------------------------------------------------------------------------------
289
309
-- | If we're in a top hole, the name of the defining function.
290
310
isTopHole :: Context -> Judgement' a -> Maybe OccName
@@ -391,6 +411,12 @@ isDisallowed :: Provenance -> Bool
391
411
isDisallowed DisallowedPrv {} = True
392
412
isDisallowed _ = False
393
413
414
+ ------------------------------------------------------------------------------
415
+ -- | Has this term already been disallowed?
416
+ isAlreadyDestructed :: Provenance -> Bool
417
+ isAlreadyDestructed (DisallowedPrv AlreadyDestructed _) = True
418
+ isAlreadyDestructed _ = False
419
+
394
420
395
421
------------------------------------------------------------------------------
396
422
-- | Eliminates 'DisallowedPrv' provenances.
0 commit comments