Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC

Commits:

5 changed files:

Changes:

  • changelog.d/T28082
    1
    +section: compiler
    
    2
    +issues: #28082
    
    3
    +mrs: !16930
    
    4
    +synopsis:
    
    5
    +  Fix a regression in type inference for injective open type families
    
    6
    +description:
    
    7
    +  Some programs involving an injective open type family with a Given equality
    
    8
    +  involving that same type family are no longer incorrectly rejected by the
    
    9
    +  typechecker.

  • compiler/GHC/Tc/Instance/FunDeps.hs
    ... ... @@ -48,6 +48,8 @@ import GHC.Utils.Panic
    48 48
     
    
    49 49
     import GHC.Data.Pair ( Pair(..) )
    
    50 50
     import Data.List     ( nubBy )
    
    51
    +import Data.List.NonEmpty ( NonEmpty, nonEmpty )
    
    52
    +import qualified Data.List.NonEmpty as NE
    
    51 53
     import Data.Maybe    ( isJust, isNothing )
    
    52 54
     
    
    53 55
     {-
    
    ... ... @@ -123,7 +125,7 @@ Wrinkles:
    123 125
            FDEqns { fd_qtvs = [x2], fd_eqs = [ Maybe x2 ~ ty ] }
    
    124 126
         with two FDEqns, generating two separate unification variables.
    
    125 127
     
    
    126
    -    This is why fd_eqs is a [TypeEqn] not just a TypeEqn
    
    128
    +    This is why fd_eqs is a (NonEmpty TypeEqn) not just a TypeEqn
    
    127 129
     
    
    128 130
     (IMP3) improveFromInstEnv doesn't return any equations that already hold.
    
    129 131
         Reason: just an optimisation; the caller does the same thing, but
    
    ... ... @@ -136,7 +138,7 @@ data FunDepEqns -- Plural becuase fd_eqs has multiple equations
    136 138
                                      --   to fresh unification vars,
    
    137 139
                                      -- See (IMP2) in Note [Improving against instances]
    
    138 140
     
    
    139
    -           , fd_eqs  :: [TypeEqn]  -- Make these pairs of types equal
    
    141
    +           , fd_eqs  :: NonEmpty TypeEqn  -- Make these pairs of types equal
    
    140 142
                             -- Invariant: In each (Pair ty1 ty2), the fd_qtvs may be
    
    141 143
                             -- free in ty1 but not in ty2.  See Wrinkle (1) of
    
    142 144
                             -- Note [Improving against instances]
    
    ... ... @@ -149,7 +151,7 @@ pprEquation :: FunDepEqns -> SDoc
    149 151
     pprEquation (FDEqns { fd_qtvs = qtvs, fd_eqs = pairs })
    
    150 152
       = vcat [text "forall" <+> braces (pprWithCommas ppr qtvs),
    
    151 153
               nest 2 (vcat [ ppr t1 <+> text "~" <+> ppr t2
    
    152
    -                       | Pair t1 t2 <- pairs])]
    
    154
    +                       | Pair t1 t2 <- NE.toList pairs])]
    
    153 155
     
    
    154 156
     {-
    
    155 157
     Given a bunch of predicates that must hold, such as
    
    ... ... @@ -216,8 +218,7 @@ improveFromAnother pred1 pred2
    216 218
         , let (ltys1, rs1) = instFD fd cls_tvs tys1
    
    217 219
               (ltys2, rs2) = instFD fd cls_tvs tys2
    
    218 220
         , eqTypes ltys1 ltys2               -- The LHSs match
    
    219
    -    , let eqs = zipAndComputeFDEqs eqType rs1 rs2
    
    220
    -    , not (null eqs) ]
    
    221
    +    , Just eqs <- [nonEmpty (zipAndComputeFDEqs eqType rs1 rs2)] ]
    
    221 222
     
    
    222 223
     improveFromAnother _ _ = []
    
    223 224
     
    
    ... ... @@ -232,7 +233,7 @@ improveFromInstEnv :: InstEnvs
    232 233
     -- See Note [Improving against instances]
    
    233 234
     -- Post: Equations oriented from the template (matching instance) to the workitem!
    
    234 235
     improveFromInstEnv inst_env cls tys
    
    235
    -  = [ FDEqns { fd_qtvs = meta_tvs, fd_eqs = eqs }
    
    236
    +  = [ fd_eqn
    
    236 237
         | fd <- cls_fds             -- Iterate through the fundeps first,
    
    237 238
                                     -- because there often are none!
    
    238 239
         , let trimmed_tcs = trimRoughMatchTcs cls_tvs fd rough_tcs
    
    ... ... @@ -241,8 +242,8 @@ improveFromInstEnv inst_env cls tys
    241 242
                     -- symmetrically, so it's ok to trim the rough_tcs,
    
    242 243
                     -- rather than trimming each inst_tcs in turn
    
    243 244
         , ispec <- instances
    
    244
    -    , (meta_tvs, eqs) <- improveClsFD cls_tvs fd ispec
    
    245
    -                                      tys trimmed_tcs -- NB: orientation
    
    245
    +    , fd_eqn <- improveClsFD cls_tvs fd ispec
    
    246
    +                             tys trimmed_tcs -- NB: orientation
    
    246 247
         ]
    
    247 248
       where
    
    248 249
         (cls_tvs, cls_fds) = classTvsFds cls
    
    ... ... @@ -252,7 +253,7 @@ improveFromInstEnv inst_env cls tys
    252 253
     improveClsFD :: [TyVar] -> FunDep TyVar    -- One functional dependency from the class
    
    253 254
                  -> ClsInst                    -- An instance template
    
    254 255
                  -> [Type] -> [RoughMatchTc]   -- Arguments of this (C tys) predicate
    
    255
    -             -> [([TyCoVar], [TypeEqn])]   -- Empty or singleton
    
    256
    +             -> [FunDepEqns]               -- Empty or singleton
    
    256 257
     -- See Note [Improving against instances]
    
    257 258
     
    
    258 259
     improveClsFD clas_tvs fd
    
    ... ... @@ -284,10 +285,7 @@ improveClsFD clas_tvs fd
    284 285
                             -- so we would produce no FDs, which is clearly wrong.
    
    285 286
                       -> []
    
    286 287
     
    
    287
    -                  | null fdeqs
    
    288
    -                  -> []
    
    289
    -
    
    290
    -                  | otherwise
    
    288
    +                  | Just fdeqs_ne <- nonEmpty fdeqs
    
    291 289
                       -> -- pprTrace "iproveClsFD" (vcat
    
    292 290
                          --  [ text "is_tvs =" <+> ppr qtvs
    
    293 291
                          --  , text "tys_inst =" <+> ppr tys_inst
    
    ... ... @@ -295,12 +293,15 @@ improveClsFD clas_tvs fd
    295 293
                          --  , text "ltys1 =" <+> ppr ltys1
    
    296 294
                          --  , text "ltys2 =" <+> ppr ltys2
    
    297 295
                          --  , text "subst =" <+> ppr subst ]) $
    
    298
    -                     [(meta_tvs, fdeqs)]
    
    296
    +                     [FDEqns { fd_qtvs = meta_tvs, fd_eqs = fdeqs_ne }]
    
    299 297
                             -- We could avoid this substTy stuff by producing the eqn
    
    300 298
                             -- (qtvs, ls1++rs1, ls2++rs2)
    
    301 299
                             -- which will re-do the ls1/ls2 unification when the equation is
    
    302 300
                             -- executed.  What we're doing instead is recording the partial
    
    303 301
                             -- work of the ls1/ls2 unification leaving a smaller unification problem
    
    302
    +
    
    303
    +                  | otherwise
    
    304
    +                  -> []
    
    304 305
                       where
    
    305 306
                         rtys1' = map (substTy subst) rtys1
    
    306 307
     
    

  • compiler/GHC/Tc/Solver/FunDeps.hs
    ... ... @@ -40,9 +40,10 @@ import GHC.Types.Var.Env( mkInScopeSet )
    40 40
     import GHC.Utils.Outputable
    
    41 41
     import GHC.Utils.Panic
    
    42 42
     
    
    43
    -import Control.Monad( unless )
    
    44 43
     import GHC.Data.Pair
    
    45
    -import Data.Maybe( isJust, mapMaybe )
    
    44
    +import Data.List.NonEmpty( NonEmpty(..), nonEmpty )
    
    45
    +import qualified Data.List.NonEmpty as NE
    
    46
    +import Data.Maybe( isJust, mapMaybe, maybeToList )
    
    46 47
     
    
    47 48
     
    
    48 49
     {- Note [Overview of functional dependencies in type inference]
    
    ... ... @@ -584,10 +585,8 @@ tryFamEqFunDeps mode eqs_for_me fam_tc work_args
    584 585
                   eqns <- mkLocalBuiltinFamEqFDs eqs_for_me fam_tc ops work_args work_rhs
    
    585 586
                 ; tryFDEqns False fam_tc work_args work_item eqns
    
    586 587
     
    
    587
    -            ; unless (hasRelevantGiven eqs_for_me work_args work_item) $
    
    588
    -              -- hasRelevantGiven: See (CF1) in Note [Exploiting closed type families]
    
    589
    -              do { eqns <- mkTopBuiltinFamEqFDs fam_tc ops work_args work_rhs
    
    590
    -                 ; tryFDEqns True fam_tc work_args work_item eqns } }
    
    588
    +            ; eqns <- mkTopBuiltinFamEqFDs eqs_for_me fam_tc ops work_args work_item
    
    589
    +            ; tryFDEqns True fam_tc work_args work_item eqns }
    
    591 590
     
    
    592 591
       | isGiven ev  -- See (INJFAM:Given)
    
    593 592
       , not (tcsmResumable mode)   -- In the pattern-match checker, continue even for
    
    ... ... @@ -598,20 +597,16 @@ tryFamEqFunDeps mode eqs_for_me fam_tc work_args
    598 597
     
    
    599 598
       | otherwise   -- Wanted, user-defined type families
    
    600 599
       = do { -- Note [Do local fundeps before top-level instances]
    
    601
    -         case tyConInjectivityInfo fam_tc of
    
    602
    -           NotInjective  -> nopStage ()
    
    603
    -           Injective inj -> do { eqns <- mkLocalFamEqFDs eqs_for_me fam_tc inj work_args work_rhs
    
    604
    -                               ; tryFDEqns False fam_tc work_args work_item eqns }
    
    600
    +         eqns <- mkLocalFamEqFDs eqs_for_me fam_tc work_args work_rhs
    
    601
    +       ; tryFDEqns False fam_tc work_args work_item eqns
    
    605 602
              -- NB: tryFDEqns bales out on an insoluble fundep
    
    606 603
              -- See (CF4) in Note [Exploiting closed type families]
    
    607 604
     
    
    608
    -       ; unless (hasRelevantGiven eqs_for_me work_args work_item) $
    
    609
    -         -- hasRelevantGiven: See (CF1) in Note [Exploiting closed type families]
    
    610
    -         do { eqns <- mkTopFamEqFDs fam_tc work_args work_item
    
    611
    -            ; tryFDEqns True fam_tc work_args work_item eqns } }
    
    605
    +       ; eqns <- mkTopFamEqFDs eqs_for_me fam_tc work_args work_item
    
    606
    +       ; tryFDEqns True fam_tc work_args work_item eqns }
    
    612 607
     
    
    613
    -mkTopFamEqFDs :: TyCon -> [TcType] -> EqCt -> SolverStage [FunDepEqns]
    
    614
    -mkTopFamEqFDs fam_tc work_args work_item
    
    608
    +mkTopFamEqFDs :: [EqCt] -> TyCon -> [TcType] -> EqCt -> SolverStage [FunDepEqns]
    
    609
    +mkTopFamEqFDs eqs_for_me fam_tc work_args work_item
    
    615 610
       -- NB: work_args exactly saturate fam_tc
    
    616 611
       | isOpenTypeFamilyTyCon fam_tc
    
    617 612
       , Injective inj_flags <- tyConInjectivityInfo fam_tc
    
    ... ... @@ -621,7 +616,11 @@ mkTopFamEqFDs fam_tc work_args work_item
    621 616
       -- Non built-in closed type families
    
    622 617
       -- (Built-in closed type families were dealt with in 'tryFamEqFunDeps'.)
    
    623 618
       | Just ax <- closedFamilyTyConCoAxiom_maybe fam_tc
    
    624
    -  = mkTopClosedFamEqFDs ax work_args work_item
    
    619
    +  = if hasRelevantGiven eqs_for_me work_args work_item
    
    620
    +       -- hasRelevantGiven: See (CF1) in Note [Exploiting closed type families]
    
    621
    +       -- NB: (CF1) applies only to /closed/ type families (#28082)
    
    622
    +    then return []
    
    623
    +    else mkTopClosedFamEqFDs ax work_args work_item
    
    625 624
     
    
    626 625
       | otherwise
    
    627 626
       = -- Anything else: data families, open type families that are not injective,
    
    ... ... @@ -630,6 +629,8 @@ mkTopFamEqFDs fam_tc work_args work_item
    630 629
     
    
    631 630
     tryFDEqns :: Bool -> TyCon -> [TcType] -> EqCt -> [FunDepEqns] -> SolverStage ()
    
    632 631
     tryFDEqns is_top fam_tc work_args work_item@(EqCt { eq_ev = ev, eq_rhs= rhs }) fd_eqns
    
    632
    +  | null fd_eqns = return () -- nothing to do
    
    633
    +  | otherwise
    
    633 634
       = Stage $
    
    634 635
         do { traceTcS "tryFDEqns" (vcat [ text "lhs:" <+> ppr fam_tc <+> ppr work_args
    
    635 636
                                         , text "rhs:" <+> ppr rhs
    
    ... ... @@ -699,7 +700,7 @@ getRelevantBranches :: CoAxiom Branched -> [TcType] -> Xi -> [FunDepEqns]
    699 700
     getRelevantBranches ax work_args work_rhs
    
    700 701
       = go (fromBranches (coAxiomBranches ax))
    
    701 702
       where
    
    702
    -    work_tys = work_rhs : work_args
    
    703
    +    work_tys = work_rhs :| work_args
    
    703 704
     
    
    704 705
         go [] = []
    
    705 706
         go (branch:branches)
    
    ... ... @@ -710,7 +711,7 @@ getRelevantBranches ax work_args work_rhs
    710 711
              is_relevant branch@(CoAxBranch { cab_tvs = qtvs
    
    711 712
                                             , cab_lhs = lhs_tys
    
    712 713
                                             , cab_rhs = rhs_ty })
    
    713
    -            | Just subst <- tcUnifyTysForInjectivity Unifying (rhs_ty:lhs_tys) work_tys
    
    714
    +            | Just subst <- tcUnifyTysForInjectivity Unifying (rhs_ty:lhs_tys) (NE.toList work_tys)
    
    714 715
                                 -- See (RW1)-(RW3) in Note [Relevance]
    
    715 716
                 , let lhs_tys' = map (deepSubstTy subst) lhs_tys
    
    716 717
                       -- deepSubstTy: see (CF8) in Note [Exploiting closed type families]
    
    ... ... @@ -721,15 +722,15 @@ getRelevantBranches ax work_args work_rhs
    721 722
                   then -- `subst` eliminates all qtvs; and no qtvs in range of subst
    
    722 723
                        -- See (CF7)(A) in Note [Exploiting closed type families]
    
    723 724
                        FDEqns { fd_qtvs = []
    
    724
    -                          , fd_eqs  = zipWith Pair (substTy subst rhs_ty : lhs_tys')
    
    725
    -                                                   work_tys }
    
    725
    +                          , fd_eqs  = NE.zipWith Pair (substTy subst rhs_ty :| lhs_tys')
    
    726
    +                                                      work_tys }
    
    726 727
                               -- Do not apply `subst` to `work_tys`;
    
    727 728
                               -- See (CF9) in Note [Exploiting closed type families]
    
    728 729
     
    
    729 730
                   else -- Abandon `subst`; re-create it from (rhs_ty ~ work_rhs)
    
    730 731
                        -- See (CF7)(B) in Note [Exploiting closed type families]
    
    731 732
                        FDEqns { fd_qtvs = qtvs
    
    732
    -                          , fd_eqs  = zipWith Pair (rhs_ty:lhs_tys) work_tys }
    
    733
    +                          , fd_eqs  = NE.zipWith Pair (rhs_ty :| lhs_tys) work_tys }
    
    733 734
     
    
    734 735
                 | otherwise
    
    735 736
                 = Nothing
    
    ... ... @@ -757,32 +758,36 @@ mkTopOpenFamEqFDs fam_tc inj_flags work_args (EqCt { eq_rhs = work_rhs })
    757 758
                 branch_lhs_tys' = substTys subst' branch_lhs_tys
    
    758 759
             -- We must apply the substitution here see
    
    759 760
             -- the Basic Plan in Note [Exploiting open type families]
    
    760
    -      = Just (mkInjectivityFDEqn qtvs' inj_flags branch_lhs_tys' work_args)
    
    761
    +      = mkInjectivityFDEqn qtvs' inj_flags branch_lhs_tys' work_args
    
    761 762
     
    
    762 763
           | otherwise
    
    763 764
           = Nothing
    
    764 765
     
    
    765
    -mkLocalFamEqFDs :: [EqCt] -> TyCon -> [Bool] -> [TcType] -> Xi -> SolverStage [FunDepEqns]
    
    766
    +mkLocalFamEqFDs :: [EqCt] -> TyCon -> [TcType] -> Xi -> SolverStage [FunDepEqns]
    
    766 767
     -- Wanted constraints only
    
    767 768
     -- Both open and closed type families, but only ones with declared injectivity
    
    768 769
     -- See Note [Exploiting local type-family injectivity]
    
    769
    -mkLocalFamEqFDs eqs_for_me fam_tc inj_flags work_args work_rhs
    
    770
    -  = do { let -- eqns_from_inerts: see (INJFAM:Wanted/other)
    
    771
    -             eqns_from_inerts = mapMaybe do_one eqs_for_me
    
    772
    -             -- eqns_from_self: see (INJFAM:Wanted/Self)
    
    773
    -             eqns_from_self = case saturatedFamApp_maybe work_rhs of
    
    774
    -                                Just (tc, rhs_tys) | fam_tc == tc -> [mk_eqn rhs_tys]
    
    775
    -                                _                                 -> []
    
    770
    +mkLocalFamEqFDs eqs_for_me fam_tc work_args work_rhs
    
    771
    +  | Injective inj_flags <- tyConInjectivityInfo fam_tc
    
    772
    +  = let -- eqns_from_inerts: see (INJFAM:Wanted/other)
    
    773
    +        eqns_from_inerts = mapMaybe do_one eqs_for_me
    
    774
    +        -- eqns_from_self: see (INJFAM:Wanted/Self)
    
    775
    +        eqns_from_self = case saturatedFamApp_maybe work_rhs of
    
    776
    +                           Just (tc, rhs_tys) | fam_tc == tc -> maybeToList (mk_eqn rhs_tys)
    
    777
    +                           _                                 -> []
    
    776 778
     
    
    777
    -       ; return (eqns_from_inerts ++ eqns_from_self) }
    
    778
    -  where
    
    779
    -    do_one :: EqCt -> Maybe FunDepEqns
    
    780
    -    do_one (EqCt { eq_lhs = TyFamLHS _ inert_args, eq_rhs = inert_rhs })
    
    781
    -      | work_rhs `tcEqType` inert_rhs = Just (mk_eqn inert_args)
    
    782
    -      | otherwise                     = Nothing
    
    783
    -    do_one _ = pprPanic "interactFunEq 2" (ppr fam_tc)  -- TyVarLHS
    
    779
    +        do_one :: EqCt -> Maybe FunDepEqns
    
    780
    +        do_one (EqCt { eq_lhs = TyFamLHS _ inert_args, eq_rhs = inert_rhs })
    
    781
    +          | work_rhs `tcEqType` inert_rhs = mk_eqn inert_args
    
    782
    +          | otherwise                     = Nothing
    
    783
    +        do_one _ = pprPanic "interactFunEq 2" (ppr fam_tc)  -- TyVarLHS
    
    784 784
     
    
    785
    -    mk_eqn iargs = mkInjectivityFDEqn [] inj_flags work_args iargs
    
    785
    +        mk_eqn iargs = mkInjectivityFDEqn [] inj_flags work_args iargs
    
    786
    +
    
    787
    +    in return (eqns_from_inerts ++ eqns_from_self)
    
    788
    +
    
    789
    +  | otherwise    -- Not injective
    
    790
    +  = return []
    
    786 791
     
    
    787 792
     
    
    788 793
     trimQtvs :: Subst -> [TyVar] -> (Subst, [TyVar])
    
    ... ... @@ -871,28 +876,34 @@ tryGivenBuiltinFamEqFDs eqs_for_me fam_tc ops work_args
    871 876
     
    
    872 877
         do_one _ = return ()
    
    873 878
     
    
    874
    -mkTopBuiltinFamEqFDs :: TyCon -> BuiltinClosedTyFam -> [TcType] -> Xi -> SolverStage [FunDepEqns]
    
    875
    -mkTopBuiltinFamEqFDs fam_tc ops work_args work_rhs
    
    876
    -  = return [FDEqns { fd_qtvs = []
    
    877
    -                   , fd_eqs = map snd $ tryInteractTopFam ops fam_tc work_args work_rhs }]
    
    879
    +mkTopBuiltinFamEqFDs :: [EqCt] -> TyCon -> BuiltinClosedTyFam -> [TcType] -> EqCt
    
    880
    +                     -> SolverStage [FunDepEqns]
    
    881
    +mkTopBuiltinFamEqFDs eqs_for_me fam_tc ops work_args work_item@(EqCt { eq_rhs = work_rhs })
    
    882
    +  | hasRelevantGiven eqs_for_me work_args work_item
    
    883
    +    -- hasRelevantGiven: See (CF1) in Note [Exploiting closed type families]
    
    884
    +    -- A built-in family is very like a closed type family
    
    885
    +  = return []
    
    886
    +  | otherwise
    
    887
    +  = return [ FDEqns { fd_qtvs = [], fd_eqs = eqs }
    
    888
    +           | Just eqs <- [nonEmpty $ map snd $ tryInteractTopFam ops fam_tc work_args work_rhs] ]
    
    878 889
     
    
    879 890
     mkLocalBuiltinFamEqFDs :: [EqCt] -> TyCon -> BuiltinClosedTyFam
    
    880 891
                            -> [TcType] -> Xi -> SolverStage [FunDepEqns]
    
    881 892
     mkLocalBuiltinFamEqFDs eqs_for_me fam_tc ops work_args work_rhs
    
    882 893
       = do { let do_one :: EqCt -> [FunDepEqns]
    
    883 894
                  do_one (EqCt { eq_lhs = TyFamLHS _ inert_args, eq_rhs = inert_rhs })
    
    884
    -               | inert_rhs `tcEqType` work_rhs = [mk_eqn inert_args]
    
    895
    +               | inert_rhs `tcEqType` work_rhs = maybeToList (mk_eqn inert_args)
    
    885 896
                    | otherwise                     = []
    
    886 897
                  do_one _ = pprPanic "interactFunEq 1" (ppr fam_tc) -- TyVarLHS
    
    887 898
     
    
    888
    -             mk_eqn :: [TcType] -> FunDepEqns
    
    889
    -             mk_eqn iargs = FDEqns { fd_qtvs = []
    
    890
    -                                   , fd_eqs = map snd $ tryInteractInertFam ops fam_tc
    
    891
    -                                                                     work_args iargs }
    
    899
    +             mk_eqn :: [TcType] -> Maybe FunDepEqns
    
    900
    +             mk_eqn iargs = do { eqs <- nonEmpty $ map snd $
    
    901
    +                                        tryInteractInertFam ops fam_tc work_args iargs
    
    902
    +                               ; return (FDEqns { fd_qtvs = [], fd_eqs = eqs }) }
    
    892 903
     
    
    893 904
            ; let eqns_from_inerts = concatMap do_one eqs_for_me
    
    894 905
                  eqns_from_self   = case tcSplitTyConApp_maybe work_rhs of
    
    895
    -                                  Just (tc,rhs_tys) | tc==fam_tc -> [mk_eqn rhs_tys]
    
    906
    +                                  Just (tc,rhs_tys) | tc==fam_tc -> maybeToList (mk_eqn rhs_tys)
    
    896 907
                                       _                              -> []
    
    897 908
            ; return (eqns_from_inerts ++ eqns_from_self) }
    
    898 909
     
    
    ... ... @@ -900,7 +911,7 @@ mkLocalBuiltinFamEqFDs eqs_for_me fam_tc ops work_args work_rhs
    900 911
     mkInjectivityFDEqn :: [TcTyVar]             -- Quantify these
    
    901 912
                        -> [Bool]                -- Injectivity flags
    
    902 913
                        -> [TcType] -> [TcType]  -- Make these equal
    
    903
    -                   -> FunDepEqns
    
    914
    +                   -> Maybe FunDepEqns
    
    904 915
     -- When F s1 s2 s3 ~ F t1 t2 t3, and F has injectivity info [True,False,True]
    
    905 916
     --   return the FDEqns { fd_eqs = [Pair s1 t1, Pair s3 t3] }
    
    906 917
     -- The injectivity flags [Bool] will not all be False,
    
    ... ... @@ -912,10 +923,11 @@ mkInjectivityFDEqn qtvs inj_args lhs_args rhs_args
    912 923
                         , text "lhs_args:" <+> ppr lhs_args
    
    913 924
                         , text "rhs_args:" <+> ppr rhs_args ]) $
    
    914 925
         -- Need inj_args lhs_args and rhs_args to be same length for zip3
    
    915
    -    FDEqns { fd_qtvs = qtvs, fd_eqs = eqs }
    
    926
    +    do { eqs <- nonEmpty eqs_list
    
    927
    +       ; return (FDEqns { fd_qtvs = qtvs, fd_eqs = eqs }) }
    
    916 928
       where
    
    917
    -    eqs = [ Pair lhs_arg rhs_arg
    
    918
    -          | (True, lhs_arg, rhs_arg) <- zip3 inj_args lhs_args rhs_args ]
    
    929
    +    eqs_list = [ Pair lhs_arg rhs_arg
    
    930
    +               | (True, lhs_arg, rhs_arg) <- zip3 inj_args lhs_args rhs_args ]
    
    919 931
     
    
    920 932
     getInertFamEqsFor :: TyCon -> [TcType] -> Xi -> TcS [EqCt]
    
    921 933
     -- Look in the InertSet, and return all inert equalities
    
    ... ... @@ -1603,8 +1615,8 @@ instantiateFunDepEqns (FDEqns { fd_qtvs = qtvs, fd_eqs = eqs })
    1603 1615
            ; (_, subst) <- instFlexiXTcM empty_subst qtvs  -- Takes account of kind substitution
    
    1604 1616
            ; return (map (subst_pair subst) rev_eqs) }
    
    1605 1617
       where
    
    1606
    -    rev_eqs = reverse eqs
    
    1607
    -       -- (reverse eqs): See Note [Reverse order of fundep equations]
    
    1618
    +    rev_eqs = reverse $ NE.toList eqs
    
    1619
    +       -- reverse: See Note [Reverse order of fundep equations]
    
    1608 1620
     
    
    1609 1621
         -- The kinds of `qtvs` can have free variables;
    
    1610 1622
         -- in the FDEqns produced by GHC.Tc.Instance.FunDeps.improveFromInstEnv
    

  • testsuite/tests/indexed-types/should_compile/T28082.hs
    1
    +
    
    2
    +{-# LANGUAGE TypeFamilyDependencies #-}
    
    3
    +
    
    4
    +module T28082 where
    
    5
    +
    
    6
    +type family F g = r | r -> g
    
    7
    +
    
    8
    +data P a = P a a
    
    9
    +
    
    10
    +type instance F ( P a ) = P a
    
    11
    +
    
    12
    +idF :: F g -> F g
    
    13
    +idF x = x
    
    14
    +
    
    15
    +f :: F a ~ a => P a -> P a
    
    16
    +f p = idF p 

  • testsuite/tests/indexed-types/should_compile/all.T
    ... ... @@ -319,4 +319,5 @@ test('T25657', normal, compile, [''])
    319 319
     test('T27828', normal, compile, [''])
    
    320 320
     test('T27828a', normal, compile, [''])
    
    321 321
     test('T27828b', normal, compile, [''])
    
    322
    +test('T28082', normal, compile, [''])
    
    322 323
     test('ZapDeps', normal, compile, [''])