Skip to content

Commit

Permalink
Fix plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
arybczak committed Sep 10, 2024
1 parent bac27db commit 25e0913
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
12 changes: 10 additions & 2 deletions effectful-plugin/src-legacy/Effectful/Plugin.hs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import GHC.TcPluginM.Extra (lookupModule, lookupName)
#if __GLASGOW_HASKELL__ >= 900
import GHC.Core.Class (Class)
import GHC.Core.InstEnv (InstEnvs, lookupInstEnv)
import GHC.Core.Predicate (isIPClass)
import GHC.Core.Unify (tcUnifyTy)
import GHC.Plugins
( Outputable (ppr), Plugin (pluginRecompile, tcPlugin), PredType
Expand Down Expand Up @@ -46,6 +47,7 @@ import GhcPlugins
, tyConClass_maybe
)
import InstEnv (InstEnvs, lookupInstEnv)
import Predicate (isIPClass)
import TcEnv (tcGetInstEnvs)
import TcPluginM (tcLookupClass, tcPluginIO)
import TcRnTypes
Expand Down Expand Up @@ -145,7 +147,7 @@ solveFakedep (elemCls, visitedRef) allGivens allWanteds = do
-- We store a list of the types of all given constraints, which will be useful later.
allGivenTypes = ctPred <$> allGivens
-- We also store a list of wanted constraints that are /not/ 'Elem e es' for later use.
extraWanteds = ctPred <$> filter irrelevant allWanteds
extraWanteds = ctPred <$> filter (\w -> irrelevant w && not (isIP w)) allWanteds

-- traceM $ "Givens: " <> show (showSDocUnsafe . ppr <$> allGivens)
-- traceM $ "Wanteds: " <> show (showSDocUnsafe . ppr <$> allWanteds)
Expand Down Expand Up @@ -224,9 +226,15 @@ solveFakedep (elemCls, visitedRef) allGivens allWanteds = do
| cls == elemCls = Just $ FakedepWanted (FakedepGiven (fst $ splitAppTys eff) eff es) loc
relevantWanted _ = Nothing

-- Check if a constraint in an implicit parameter.
isIP :: Ct -> Bool
isIP = \case
CDictCan _ cls _ _ -> isIPClass cls
_ -> False

-- Determine whether a constraint is /not/ of form 'Elem e es'.
irrelevant :: Ct -> Bool
irrelevant = isNothing . relevantGiven
irrelevant = isNothing . relevantWanted

-- Given a wanted constraint and a given constraint, unify them and give back a substitution that can be applied
-- to the wanted to make it equal to the given.
Expand Down
17 changes: 16 additions & 1 deletion effectful-plugin/src/Effectful/Plugin.hs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import Data.Traversable

import GHC.Core.Class (Class)
import GHC.Core.InstEnv (InstEnvs, lookupInstEnv)
import GHC.Core.Predicate (isIPClass)
import GHC.Core.TyCo.Rep (PredType, Type)
import GHC.Core.TyCo.Subst
import GHC.Core.TyCon (tyConClass_maybe)
Expand Down Expand Up @@ -167,7 +168,11 @@ solveFakedep (elemCls, visitedRef) _ allGivens allWanteds = do
-- constraints. Therefore, we extract these constraints out of the
-- 'allGivens' and 'allWanted's.
effGivens = mapMaybe maybeEffGiven allGivens
(otherWantedTys, effWanteds) = partitionEithers $ map splitWanteds allWanteds
(otherWantedTys, effWanteds) = partitionEithers
. map splitWanteds
-- Get rid of implicit parameters, they're weird.
. filter (not . isIP)
$ allWanteds

-- We store a list of the types of all given constraints, which will be
-- useful later.
Expand Down Expand Up @@ -241,6 +246,16 @@ solveFakedep (elemCls, visitedRef) _ allGivens allWanteds = do
else Nothing
_ -> Nothing

-- Check if a constraint in an implicit parameter.
isIP :: Ct -> Bool
isIP = \case
#if __GLASGOW_HASKELL__ < 908
CDictCan { cc_class = cls } -> isIPClass cls
#else
CDictCan DictCt { di_cls = cls } -> isIPClass cls
#endif
_ -> False

-- Determine whether a wanted constraint is of form 'e :> es'.
splitWanteds :: Ct -> Either PredType EffWanted
splitWanteds = \case
Expand Down

0 comments on commit 25e0913

Please sign in to comment.