@@ -21,8 +21,6 @@ import Libraries.Data.List.LengthMatch
2121import Libraries.Data.List01
2222import Libraries.Data.List01.Quantifiers
2323
24- import Decidable.Equality
25-
2624import Libraries.Text.PrettyPrint.Prettyprinter
2725
2826%default covering
@@ -364,24 +362,14 @@ partition phase (x :: xs) with (partition phase xs)
364362 VarClause => VarClauses [x] NoClauses
365363
366364data ConType : Type where
367- CName : Name -> ( tag : Int) -> ConType
365+ CName : ConTag -> ConType
368366 CDelay : ConType
369367 CConst : Constant -> ConType
370368
371- conTypeEq : (x, y : ConType) -> Maybe (x = y)
372- conTypeEq (CName x tag) (CName x' tag')
373- = do Refl <- nameEq x x'
374- case decEq tag tag' of
375- Yes Refl => Just Refl
376- No contra => Nothing
377- conTypeEq CDelay CDelay = Just Refl
378- conTypeEq (CConst x) (CConst y) = (\ xy => cong CConst xy) <$> constantEq x y
379- conTypeEq _ _ = Nothing
380-
381369data Group : List Name -> -- pattern variables still to process
382370 Scoped where
383371 ConGroup : {newargs : _} ->
384- Name -> ( tag : Int) ->
372+ ConTag ->
385373 List01 True (PatClause (newargs ++ todo) (newargs ++ vars)) ->
386374 Group todo vars
387375 DelayGroup : {tyarg, valarg : _ } ->
@@ -393,14 +381,14 @@ data Group : List Name -> -- pattern variables still to process
393381
394382covering
395383{vars : _ } -> {todo : _} -> Show (Group todo vars) where
396- show (ConGroup c t cs) = " Con " ++ show c ++ " : " ++ show cs
384+ show (ConGroup tag cs) = " Con " ++ show (conName tag) ++ " : " ++ show cs
397385 show (DelayGroup cs) = " Delay: " ++ show cs
398386 show (ConstGroup c cs) = " Const " ++ show c ++ " : " ++ show cs
399387
400388data GroupMatch : ConType -> List Pat -> Group todo vars -> Type where
401- ConMatch : {tag : Int } -> LengthMatch ps newargs ->
402- GroupMatch (CName n tag) ps
403- (ConGroup {newargs} n tag (MkPatClause pvs pats pid rhs :: rest))
389+ ConMatch : {tag : ConTag } -> LengthMatch ps newargs ->
390+ GroupMatch (CName tag) ps
391+ (ConGroup {newargs} tag (MkPatClause pvs pats pid rhs :: rest))
404392 DelayMatch : GroupMatch CDelay []
405393 (DelayGroup {tyarg} {valarg} (MkPatClause pvs pats pid rhs :: rest))
406394 ConstMatch : GroupMatch (CConst c) []
@@ -409,13 +397,13 @@ data GroupMatch : ConType -> List Pat -> Group todo vars -> Type where
409397
410398checkGroupMatch : (c : ConType) -> (ps : List Pat) -> (g : Group todo vars) ->
411399 GroupMatch c ps g
412- checkGroupMatch (CName x tag) ps (ConGroup {newargs} x' tag' (MkPatClause pvs pats pid rhs :: rest))
400+ checkGroupMatch (CName tag) ps (ConGroup {newargs} tag' (MkPatClause pvs pats pid rhs :: rest))
413401 = case checkLengthMatch ps newargs of
414402 Nothing => NoMatch
415- Just prf => case (nameEq x x', decEq tag tag') of
416- ( Just Refl , Yes Refl ) => ConMatch prf
403+ Just prf => case conTagEq tag tag' of
404+ Just Refl => ConMatch prf
417405 _ => NoMatch
418- checkGroupMatch (CName x tag) ps _ = NoMatch
406+ checkGroupMatch (CName tag) ps _ = NoMatch
419407checkGroupMatch CDelay [] (DelayGroup (MkPatClause pvs pats pid rhs :: rest))
420408 = DelayMatch
421409checkGroupMatch (CConst c) [] (ConstGroup c' (MkPatClause pvs pats pid rhs :: rest))
@@ -511,7 +499,7 @@ groupCons fc fn pvars (x :: xs) {isCons = p :: ps}
511499 = foldlC (uncurry . gc) ! (gc [] x p) $ pushIn xs ps
512500 where
513501 addConG : {vars', todo' : _ } ->
514- Name -> ( tag : Int) ->
502+ ConTag ->
515503 List Pat -> NamedPats todo' vars' ->
516504 Int -> (rhs : Term vars') ->
517505 (acc : List01 ne (Group todo' vars')) ->
@@ -520,13 +508,13 @@ groupCons fc fn pvars (x :: xs) {isCons = p :: ps}
520508 -- add new pattern arguments for each of that constructor's arguments.
521509 -- The type of 'ConGroup' ensures that we refer to the arguments by
522510 -- the same name in each of the clauses
523- addConG n tag pargs pats pid rhs []
524- = do cty <- if n == UN ( Basic " ->" )
511+ addConG tag pargs pats pid rhs []
512+ = do cty <- if tag == TConTag ( UN $ Basic " ->" )
525513 then pure $ NBind fc (MN " _" 0 ) (Pi fc top Explicit (MkNFClosure defaultOpts (mkEnv fc vars') (NType fc (MN " top" 0 )))) $
526514 (\ d, a => pure $ NBind fc (MN " _" 1 ) (Pi fc top Explicit (MkNFClosure defaultOpts (mkEnv fc vars') (NErased fc Placeholder )))
527515 (\ d, a => pure $ NType fc (MN " top" 0 )))
528516 else do defs <- get Ctxt
529- Just t <- lookupTyExact n (gamma defs)
517+ Just t <- lookupTyExact (conName tag) (gamma defs)
530518 | Nothing => pure (NErased fc Placeholder )
531519 nf defs (mkEnv fc vars') (embed t)
532520 (patnames ** (l, newargs)) <- nextNames fc " e" pargs (Just cty)
@@ -535,20 +523,20 @@ groupCons fc fn pvars (x :: xs) {isCons = p :: ps}
535523 let pats' = updatePatNames (updateNames (zip patnames pargs))
536524 (weakenNs l pats)
537525 let clause = MkPatClause pvars (newargs ++ pats') pid (weakenNs l rhs)
538- pure [ConGroup n tag [clause]]
539- addConG n tag pargs pats pid rhs (g :: gs) with (checkGroupMatch (CName n tag) pargs g)
540- addConG n tag pargs pats pid rhs
541- (ConGroup n tag (MkPatClause pvars ps tid tm :: rest) :: gs) | ConMatch {newargs} lprf
526+ pure [ConGroup tag [clause]]
527+ addConG tag pargs pats pid rhs (g :: gs) with (checkGroupMatch (CName tag) pargs g)
528+ addConG tag pargs pats pid rhs
529+ (ConGroup tag (MkPatClause pvars ps tid tm :: rest) :: gs) | ConMatch {newargs} lprf
542530 = do let newps = newPats pargs lprf ps
543531 let l = mkSizeOf newargs
544532 let pats' = updatePatNames (updateNames (zip newargs pargs))
545533 (weakenNs l pats)
546534 let newclause = MkPatClause pvars (newps ++ pats') pid (weakenNs l rhs)
547535 -- put the new clause at the end of the group, since we
548536 -- match the clauses top to bottom.
549- pure $ ConGroup n tag (MkPatClause pvars ps tid tm :: rest ++ [newclause]) :: gs
550- addConG n tag pargs pats pid rhs (g :: gs) | NoMatch
551- = (g :: ) <$> addConG n tag pargs pats pid rhs gs
537+ pure $ ConGroup tag (MkPatClause pvars ps tid tm :: rest ++ [newclause]) :: gs
538+ addConG tag pargs pats pid rhs (g :: gs) | NoMatch
539+ = (g :: ) <$> addConG tag pargs pats pid rhs gs
552540
553541 -- This rather ugly special case is to deal with laziness, where Delay
554542 -- is like a constructor, but with a special meaning that it forces
@@ -613,14 +601,14 @@ groupCons fc fn pvars (x :: xs) {isCons = p :: ps}
613601 = addGroup p pprf pats pid (substName n (Local fc (Just True ) idx pprf) rhs) acc
614602 addGroup (PCon cfc n t a pargs) pprf pats pid rhs acc
615603 = if a == length pargs
616- then addConG n t pargs pats pid rhs acc
604+ then addConG ( DConTag n t) pargs pats pid rhs acc
617605 else throw (CaseCompile cfc fn (NotFullyApplied n))
618606 addGroup (PTyCon cfc n a pargs) pprf pats pid rhs acc
619607 = if a == length pargs
620- then addConG n 0 pargs pats pid rhs acc
608+ then addConG ( TConTag n) pargs pats pid rhs acc
621609 else throw (CaseCompile cfc fn (NotFullyApplied n))
622610 addGroup (PArrow _ _ s t) pprf pats pid rhs acc
623- = addConG (UN $ Basic " ->" ) 0 [s, t] pats pid rhs acc
611+ = addConG (TConTag $ UN $ Basic " ->" ) [s, t] pats pid rhs acc
624612 -- Go inside the delay; we'll flag the case as needing to force its
625613 -- scrutinee (need to check in 'caseGroups below)
626614 addGroup (PDelay _ _ pty parg) pprf pats pid rhs acc
@@ -919,10 +907,10 @@ mutual
919907 where
920908 altGroups : forall ne. List01 ne (Group todo vars) -> Core (List (CaseAlt vars))
921909 altGroups [] = pure $ toList $ DefaultCase <$> errorCase
922- altGroups (ConGroup {newargs} cn tag rest :: cs)
910+ altGroups (ConGroup {newargs} tag rest :: cs)
923911 = do crest <- match fc fn phase rest (map (weakenNs (mkSizeOf newargs)) errorCase)
924912 cs' <- altGroups cs
925- pure (ConCase cn tag newargs crest :: cs')
913+ pure (ConCase tag newargs crest :: cs')
926914 altGroups (DelayGroup {tyarg} {valarg} rest :: cs)
927915 = do crest <- match fc fn phase rest (map (weakenNs (mkSizeOf [tyarg, valarg])) errorCase)
928916 cs' <- altGroups cs
@@ -1150,7 +1138,7 @@ simpleCase fc phase fn ty clauses
11501138
11511139mutual
11521140 findReachedAlts : CaseAlt ns' -> List Int
1153- findReachedAlts (ConCase _ _ _ t) = findReached t
1141+ findReachedAlts (ConCase _ _ t) = findReached t
11541142 findReachedAlts (DelayCase _ _ t) = findReached t
11551143 findReachedAlts (ConstCase _ t) = findReached t
11561144 findReachedAlts (DefaultCase t) = findReached t
@@ -1195,7 +1183,7 @@ identifyUnreachableDefaults fc defs nfty cs
11951183
11961184 dropRep : List (CaseAlt vars) -> SortedSet Int -> (List (CaseAlt vars), SortedSet Int)
11971185 dropRep [] extra = ([], extra)
1198- dropRep (c@(ConCase n t args sc) :: rest) extra
1186+ dropRep (c@(ConCase t args sc) :: rest) extra
11991187 -- assumption is that there's no defaultcase in 'rest' because
12001188 -- we've just removed it
12011189 = let (filteredClauses, extraCases) = partition (not . tagIs t) rest
@@ -1225,11 +1213,11 @@ findExtraDefaults fc defs (Case idx el ty altsIn)
12251213 pure (Prelude . toList extraCases ++ extraCases')
12261214 where
12271215 findExtraAlts : CaseAlt vars -> Core (List Int)
1228- findExtraAlts (ConCase x tag args ctree) = findExtraDefaults fc defs ctree
1229- findExtraAlts (DelayCase x arg ctree) = findExtraDefaults fc defs ctree
1230- findExtraAlts (ConstCase x ctree) = findExtraDefaults fc defs ctree
1216+ findExtraAlts (ConCase _ _ ctree) = findExtraDefaults fc defs ctree
1217+ findExtraAlts (DelayCase _ _ ctree) = findExtraDefaults fc defs ctree
1218+ findExtraAlts (ConstCase _ ctree) = findExtraDefaults fc defs ctree
12311219 -- already handled defaults by elaborating them to all possible cons
1232- findExtraAlts (DefaultCase ctree ) = pure []
1220+ findExtraAlts (DefaultCase _ ) = pure []
12331221
12341222findExtraDefaults fc defs ctree = pure []
12351223
0 commit comments