@@ -35,6 +35,7 @@ module Unison.PatternMatchCoverage
3535 )
3636where
3737
38+ import Data.List.NonEmpty (nonEmpty )
3839import Data.Set qualified as Set
3940import Debug.Trace
4041import Unison.Debug
@@ -53,34 +54,40 @@ import Unison.Util.Pretty qualified as P
5354checkMatch ::
5455 forall vt v loc m .
5556 (Pmc vt v loc m ) =>
56- -- | the match location
57- loc ->
5857 -- | scrutinee type
5958 Type. Type vt loc ->
6059 -- | match cases
6160 [Term. MatchCase loc (Term. Term' vt v loc )] ->
6261 -- | (redundant locations, inaccessible locations, inhabitants of uncovered refinement type)
6362 m ([loc ], [loc ], [Pattern () ])
64- checkMatch matchLocation scrutineeType cases = do
63+ checkMatch scrutineeType cases = do
6564 ppe <- getPrettyPrintEnv
6665 v0 <- fresh
67- grdtree0 <- desugarMatch matchLocation scrutineeType v0 cases
68- doDebug (P. hang (title " desugared:" ) (prettyGrdTree (prettyPmGrd ppe) (\ _ -> " <loc>" ) grdtree0)) (pure () )
69- (uncovered, grdtree1) <- uncoverAnnotate (Set. singleton (NC. markDirty v0 $ NC. declVar v0 scrutineeType id NC. emptyNormalizedConstraints)) grdtree0
66+ mgrdtree0 <- traverse (desugarMatch scrutineeType v0) (nonEmpty cases)
67+ doDebug (P. hang (title " desugared:" ) (prettyGrdTreeMaybe (prettyPmGrd ppe) (\ _ -> " <loc>" ) mgrdtree0)) (pure () )
68+ let initialUncovered = Set. singleton (NC. markDirty v0 $ NC. declVar v0 scrutineeType id NC. emptyNormalizedConstraints)
69+ (uncovered, grdtree1) <- case mgrdtree0 of
70+ Nothing -> pure (initialUncovered, Nothing )
71+ Just grdtree0 -> fmap Just <$> uncoverAnnotate initialUncovered grdtree0
7072 doDebug
7173 ( P. sep
7274 " \n "
73- [ P. hang (title " annotated:" ) (prettyGrdTree (NC. prettyDnf ppe) (NC. prettyDnf ppe . fst ) grdtree1),
75+ [ P. hang (title " annotated:" ) (prettyGrdTreeMaybe (NC. prettyDnf ppe) (NC. prettyDnf ppe . fst ) grdtree1),
7476 P. hang (title " uncovered:" ) (NC. prettyDnf ppe uncovered)
7577 ]
7678 )
7779 (pure () )
7880 uncoveredExpanded <- concat . fmap Set. toList <$> traverse (expandSolution v0) (Set. toList uncovered)
7981 doDebug (P. hang (title " uncovered expanded:" ) (NC. prettyDnf ppe (Set. fromList uncoveredExpanded))) (pure () )
8082 let sols = map (generateInhabitants v0) uncoveredExpanded
81- let (_accessible, inaccessible, redundant) = classify grdtree1
83+ let (_accessible, inaccessible, redundant) = case grdtree1 of
84+ Nothing -> ([] , [] , [] )
85+ Just x -> classify x
8286 pure (redundant, inaccessible, sols)
8387 where
88+ prettyGrdTreeMaybe prettyNode prettyLeaf = \ case
89+ Nothing -> " <empty>"
90+ Just x -> prettyGrdTree prettyNode prettyLeaf x
8491 title = P. bold
8592 doDebug out = case shouldDebug PatternCoverage of
8693 True -> trace (P. toAnsiUnbroken out)
0 commit comments