1- {-# LANGUAGE BlockArguments #-}
21{-# LANGUAGE CPP #-}
2+
3+ {-# LANGUAGE BlockArguments #-}
34{-# LANGUAGE DataKinds #-}
45{-# LANGUAGE NamedFieldPuns #-}
56{-# LANGUAGE PatternSynonyms #-}
@@ -10,10 +11,8 @@ module IfSat.Plugin
1011 where
1112
1213-- base
13- import Control.Monad
14- ( filterM )
1514import Data.Foldable
16- ( for_ )
15+ ( traverse_ )
1716import Data.Maybe
1817 ( catMaybes , mapMaybe )
1918
@@ -35,12 +34,8 @@ import GHC.Tc.Types
3534 ( TcM )
3635import GHC.Tc.Types.Constraint
3736 ( isEmptyWC , CtEvidence (.. ), ctEvEvId )
38- import GHC.Tc.Utils.TcType
39- ( MetaDetails (.. ), metaTyVarRef
40- , tyCoVarsOfTypeList
41- )
4237import GHC.Tc.Utils.TcMType
43- ( isUnfilledMetaTyVar , newTcEvBinds )
38+ ( newTcEvBinds )
4439
4540-- ghc-tcplugin-api
4641import GHC.TcPlugin.API
@@ -49,7 +44,9 @@ import GHC.TcPlugin.API.Internal
4944
5045-- if-instance
5146import IfSat.Plugin.Compat
52- ( wrapTcS , getRestoreTcS )
47+ ( wrapTcS , getRestoreTcS
48+ , unfilledRefsOfType , unfillMutableRef
49+ )
5350
5451--------------------------------------------------------------------------------
5552-- Plugin definition.
@@ -151,9 +148,7 @@ solveWanted defs@( PluginDefs { orClass } ) givens wanted
151148
152149 -- Keep track of the current solver state in order to backtrack
153150 -- in the event that our attempt at solving 'ct_l' fails.
154- ct_l_unfilled_metas <- wrapTcS
155- $ filterM isUnfilledMetaTyVar
156- $ tyCoVarsOfTypeList ct_l_ty
151+ ct_l_unfilled <- wrapTcS $ unfilledRefsOfType ct_l_ty
157152 restoreTcS <- getRestoreTcS
158153
159154 -- Try to solve 'ct_l', using both Givens and top-level instances.
@@ -183,11 +178,8 @@ solveWanted defs@( PluginDefs { orClass } ) givens wanted
183178 -- Reset the solver state to before we attempted to solve 'ct_l',
184179 -- and undo any type variable unifications that happened.
185180 restoreTcS
186- wrapTcS $ for_ ct_l_unfilled_metas \ meta ->
187- writeTcRef ( metaTyVarRef meta ) Flexi
188- ct_r_unfilled_metas <- wrapTcS
189- $ filterM isUnfilledMetaTyVar
190- $ tyCoVarsOfTypeList ct_r_ty
181+ wrapTcS $ traverse_ unfillMutableRef ct_l_unfilled
182+ ct_r_unfilled <- wrapTcS $ unfilledRefsOfType ct_r_ty
191183
192184 -- Try to solve 'ct_r', using both Givens and top-level instances.
193185 residual_ct_r <- solveSimpleWanteds ( unitBag ct_r )
@@ -212,8 +204,7 @@ solveWanted defs@( PluginDefs { orClass } ) givens wanted
212204 -- Reset the solver state to before we attempted to solve 'ct_r',
213205 -- and undo any type variable unifications that happened.
214206 restoreTcS
215- wrapTcS $ for_ ct_r_unfilled_metas \ meta ->
216- writeTcRef ( metaTyVarRef meta ) Flexi
207+ wrapTcS $ traverse_ unfillMutableRef ct_r_unfilled
217208
218209 pure Nothing
219210 pure $ ( , wanted ) <$> mb_wanted_evTerm
@@ -356,8 +347,8 @@ usedGivenCoercions givens ev = mapMaybe dep_cv givens
356347-- selector warnings.
357348wantedEvDest :: HasDebugCallStack => CtEvidence -> TcEvDest
358349wantedEvDest ( CtWanted { ctev_dest = dst } ) = dst
359- wantedEvDest g @ ( CtGiven {} ) =
360- pprPanic " wantedEvDest called on CtGiven " (ppr g )
350+ wantedEvDest non_wtd =
351+ pprPanic " wantedEvDest, but not a Wanted Ct " (ppr non_wtd )
361352
362353--------------------------------------------------------------------------------
363354
@@ -383,9 +374,7 @@ isSatRewriter ( PluginDefs { isSatTyCon } ) givens [ct_ty] = do
383374
384375 -- Keep track of the current solver state in order to undo any
385376 -- side-effects after calling 'solveSimpleWanteds' on 'ct'.
386- ct_unfilled_metas <- wrapTcS
387- $ filterM isUnfilledMetaTyVar
388- $ tyCoVarsOfTypeList ct_ty
377+ ct_unfilled <- wrapTcS $ unfilledRefsOfType ct_ty
389378 restoreTcS <- getRestoreTcS
390379
391380 -- Try to solve 'ct', using both Givens and top-level instances.
@@ -396,8 +385,7 @@ isSatRewriter ( PluginDefs { isSatTyCon } ) givens [ct_ty] = do
396385 -- Reset the solver state to before we attempted to solve 'ct',
397386 -- and undo any type variable unifications that happened.
398387 restoreTcS
399- wrapTcS $ for_ ct_unfilled_metas \ meta ->
400- writeTcRef ( metaTyVarRef meta ) Flexi
388+ wrapTcS $ traverse_ unfillMutableRef ct_unfilled
401389
402390 let
403391 is_sat :: Bool
0 commit comments