|
1 |
| -{-# LANGUAGE TupleSections #-} |
2 |
| -{-# LANGUAGE RankNTypes #-} |
| 1 | +{-# LANGUAGE CPP #-} |
| 2 | +{-# LANGUAGE RankNTypes #-} |
| 3 | +{-# LANGUAGE TupleSections #-} |
3 | 4 |
|
4 | 5 | module Wingman.Machinery where
|
5 | 6 |
|
@@ -30,11 +31,19 @@ import Refinery.Tactic
|
30 | 31 | import Refinery.Tactic.Internal
|
31 | 32 | import System.Timeout (timeout)
|
32 | 33 | import Wingman.Context (getInstance)
|
33 |
| -import Wingman.GHC (tryUnifyUnivarsButNotSkolems, updateSubst, tacticsGetDataCons, freshTyvars) |
| 34 | +import Wingman.GHC (tryUnifyUnivarsButNotSkolems, updateSubst, tacticsGetDataCons, freshTyvars, tryUnifyUnivarsButNotSkolemsMany) |
34 | 35 | import Wingman.Judgements
|
35 | 36 | import Wingman.Simplify (simplify)
|
36 | 37 | import Wingman.Types
|
37 | 38 |
|
| 39 | +#if __GLASGOW_HASKELL__ < 900 |
| 40 | +import FunDeps (fd_eqs, improveFromInstEnv) |
| 41 | +import Pair (unPair) |
| 42 | +#else |
| 43 | +import GHC.Tc.Instance.FunDeps (fd_eqs, improveFromInstEnv) |
| 44 | +import GHC.Data.Pair (unPair) |
| 45 | +#endif |
| 46 | + |
38 | 47 |
|
39 | 48 | substCTy :: TCvSubst -> CType -> CType
|
40 | 49 | substCTy subst = coerce . substTy subst . coerce
|
@@ -245,6 +254,23 @@ unify goal inst = do
|
245 | 254 | modify $ updateSubst subst
|
246 | 255 | Nothing -> cut
|
247 | 256 |
|
| 257 | +------------------------------------------------------------------------------ |
| 258 | +-- | Get a substition out of a theta's fundeps |
| 259 | +learnFromFundeps |
| 260 | + :: ThetaType |
| 261 | + -> RuleM () |
| 262 | +learnFromFundeps theta = do |
| 263 | + inst_envs <- asks ctxInstEnvs |
| 264 | + skolems <- gets ts_skolems |
| 265 | + subst <- gets ts_unifier |
| 266 | + let theta' = substTheta subst theta |
| 267 | + fundeps = foldMap (foldMap fd_eqs . improveFromInstEnv inst_envs (\_ _ -> ())) theta' |
| 268 | + case tryUnifyUnivarsButNotSkolemsMany skolems $ fmap unPair fundeps of |
| 269 | + Just subst -> |
| 270 | + modify $ updateSubst subst |
| 271 | + Nothing -> cut |
| 272 | + |
| 273 | + |
248 | 274 | cut :: RuleT jdg ext err s m a
|
249 | 275 | cut = RuleT Empty
|
250 | 276 |
|
|
0 commit comments