packages feed

ghc-tcplugins-extra 0.2.5 → 0.3

raw patch · 3 files changed

+34/−10 lines, 3 filesdep ~ghcPVP ok

version bump matches the API change (PVP)

Dependency ranges changed: ghc

API changes (from Hackage documentation)

- GHC.TcPluginM.Extra: mkSubst :: Ct -> Maybe (TcTyVar, TcType)
+ GHC.TcPluginM.Extra: mkSubst :: Ct -> Maybe ((TcTyVar, TcType), Ct)
- GHC.TcPluginM.Extra: mkSubst' :: [Ct] -> [(TcTyVar, TcType)]
+ GHC.TcPluginM.Extra: mkSubst' :: [Ct] -> [((TcTyVar, TcType), Ct)]

Files

CHANGELOG.md view
@@ -1,3 +1,6 @@+## 0.3 *May 8th 2018*+* Fix bug where results of `flattenGivens` was ambiguous+ ## 0.2.5 *April 15th 2018* * Support for GHC-8.5.20180306 
ghc-tcplugins-extra.cabal view
@@ -1,5 +1,5 @@ name:                ghc-tcplugins-extra-version:             0.2.5+version:             0.3 synopsis:            Utilities for writing GHC type-checker plugins description:         Utilities for writing GHC type-checker plugins, such as                      creating constraints, with a stable API covering multiple
src/GHC/TcPluginM/Extra.hs view
@@ -89,10 +89,13 @@ import Var        (varType) #endif #if __GLASGOW_HASKELL__ >= 804-import Control.Arrow (second)+import Control.Arrow (first, second)+import Data.Function (on)+import Data.List     (groupBy, partition, sortOn) import Data.Maybe    (mapMaybe)-import TcRnTypes     (Ct (..))+import TcRnTypes     (Ct (..), ctLoc, ctEvId, mkNonCanonical) import TcType        (TcTyVar, TcType)+import Type          (mkPrimEqPred) import TyCoRep       (Type (..)) #endif @@ -296,28 +299,46 @@ flattenGivens   :: [Ct]   -> [Ct]-flattenGivens givens = map (substCt subst) givens+flattenGivens givens =+  mapMaybe flatToCt flat ++ map (substCt subst') givens  where   subst = mkSubst' givens+  (flat,subst')+    = second (map fst . concat)+    $ partition ((>= 2) . length)+    $ groupBy ((==) `on` (fst.fst))+    $ sortOn (fst.fst) subst +  flatToCt [((_,lhs),ct),((_,rhs),_)]+    = Just+    $ mkNonCanonical+    $ CtGiven (mkPrimEqPred lhs rhs) (ctEvId ct) (ctLoc ct)++  flatToCt _ = Nothing++ -- | Create flattened substitutions from type equalities, i.e. the substitutions -- have been applied to each others right hand sides. -- -- __NB:__ Only available on GHC 8.4+-mkSubst' :: [Ct] -> [(TcTyVar,TcType)]+mkSubst' :: [Ct] -> [((TcTyVar,TcType),Ct)] mkSubst' = foldr substSubst [] . mapMaybe mkSubst  where-  substSubst (tv,t) s = (tv,substType s t) : map (second (substType [(tv,t)])) s+  substSubst :: ((TcTyVar,TcType),Ct)+             -> [((TcTyVar,TcType),Ct)]+             -> [((TcTyVar,TcType),Ct)]+  substSubst ((tv,t),ct) s = ((tv,substType (map fst s) t),ct)+                           : map (first (second (substType [(tv,t)]))) s  -- | Create simple substitution from type equalities -- -- __NB:__ Only available on GHC 8.4+ mkSubst   :: Ct-  -> Maybe (TcTyVar, TcType)-mkSubst (CTyEqCan {..})  = Just (cc_tyvar,cc_rhs)-mkSubst (CFunEqCan {..}) = Just (cc_fsk,TyConApp cc_fun cc_tyargs)-mkSubst _                = Nothing+  -> Maybe ((TcTyVar, TcType),Ct)+mkSubst ct@(CTyEqCan {..})  = Just ((cc_tyvar,cc_rhs),ct)+mkSubst ct@(CFunEqCan {..}) = Just ((cc_fsk,TyConApp cc_fun cc_tyargs),ct)+mkSubst _                   = Nothing  -- | Apply substitution in the evidence of Cts --