Skip to content

Commit

Permalink
Have eqTypeM fall back to eqType pre-GHC 9.4
Browse files Browse the repository at this point in the history
  • Loading branch information
sellout committed Dec 14, 2023
1 parent eb734ce commit 5aa593b
Showing 1 changed file with 21 additions and 14 deletions.
35 changes: 21 additions & 14 deletions plugin/src/ConCat/NormaliseType.hs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
{-# LANGUAGE CPP #-}

-- | Utility functions for normalising, comparing types modulo type families.
module ConCat.NormaliseType(runDsM, normaliseTypeM, eqTypeM, runTcForSolver) where
module ConCat.NormaliseType (eqTypeM) where

import GHC.Plugins
#if MIN_VERSION_GLASGOW_HASKELL(9,4,0,0)
import GHC.HsToCore.Monad
import Data.Maybe (maybe)
import GHC.HsToCore.Monad
Expand All @@ -10,6 +13,20 @@ import GHC.Tc.Instance.Family (tcGetFamInstEnvs)
import GHC.Core.FamInstEnv (normaliseType)
import GHC.Core.Reduction (reductionReducedType)
import GHC.Tc.Types (TcM)
#endif

-- | compare two types after first normalising out type families
eqTypeM :: HscEnv -> DynFlags -> ModGuts -> Type -> Type -> IO Bool
#if MIN_VERSION_GLASGOW_HASKELL(9,4,0,0)
eqTypeM env dflags guts ty1 ty2 =
if ty1 `eqType` ty2
then return True
else
runTcForSolver env dflags guts $ do
famInstEnvs <- tcGetFamInstEnvs
let reduction1 = normaliseType famInstEnvs Nominal ty1
let reduction2 = normaliseType famInstEnvs Nominal ty2
return (reductionReducedType reduction1 `eqType` reductionReducedType reduction2)

-- | run a DsM program inside IO
runDsM :: HscEnv -> DynFlags -> ModGuts -> DsM a -> IO a
Expand All @@ -31,16 +48,6 @@ normaliseTypeM env dflags guts ty =
famInstEnvs <- tcGetFamInstEnvs
let reduction = normaliseType famInstEnvs Nominal ty
return (reductionReducedType reduction)

-- | compare two types after first normalising out type families
eqTypeM :: HscEnv -> DynFlags -> ModGuts -> Type -> Type -> IO Bool
eqTypeM env dflags guts ty1 ty2 =
if ty1 `eqType` ty2
then return True
else
runTcForSolver env dflags guts $ do
famInstEnvs <- tcGetFamInstEnvs
let reduction1 = normaliseType famInstEnvs Nominal ty1
let reduction2 = normaliseType famInstEnvs Nominal ty2
return (reductionReducedType reduction1 `eqType` reductionReducedType reduction2)

#else
eqTypeM _ _ _ ty1 ty2 = pure $ ty1 `eqType` ty2
#endif

0 comments on commit 5aa593b

Please sign in to comment.