@@ -5,13 +5,11 @@ module Wingman.Machinery where
55
66import Control.Applicative (empty )
77import Control.Lens ((<>~) )
8- import Control.Monad.Error.Class
98import Control.Monad.Reader
109import Control.Monad.State.Class (gets , modify , MonadState )
1110import Control.Monad.State.Strict (StateT (.. ), execStateT )
1211import Control.Monad.Trans.Maybe
1312import Data.Coerce
14- import Data.Either
1513import Data.Foldable
1614import Data.Functor ((<&>) )
1715import Data.Generics (everything , gcount , mkQ )
@@ -96,20 +94,20 @@ runTactic ctx jdg t = do
9694 res <- flip runReaderT ctx
9795 . unExtractM
9896 $ runTacticT t jdg tacticState
99- pure $ case partitionEithers res of
100- (errs, [] ) -> Left $ take 50 errs
101- (_, fmap assoc23 -> solns) -> do
97+ pure $ case res of
98+ (Left errs ) -> Left $ take 50 errs
99+ (Right solns) -> do
102100 let sorted =
103- flip sortBy solns $ comparing $ \ (ext, (_, holes) ) ->
104- Down $ scoreSolution ext jdg holes
101+ flip sortBy solns $ comparing $ \ (Proof ext _ holes) ->
102+ Down $ scoreSolution ext jdg $ fmap snd holes
105103 case sorted of
106- ((syn, (_, subgoals) ) : _) ->
104+ ((Proof syn _ subgoals) : _) ->
107105 Right $
108106 RunTacticResults
109107 { rtr_trace = syn_trace syn
110108 , rtr_extract = simplify $ syn_val syn
111- , rtr_subgoals = subgoals
112- , rtr_other_solns = reverse . fmap fst $ sorted
109+ , rtr_subgoals = fmap snd subgoals
110+ , rtr_other_solns = reverse . fmap pf_extract $ sorted
113111 , rtr_jdg = jdg
114112 , rtr_ctx = ctx
115113 }
@@ -154,7 +152,7 @@ mappingExtract
154152 -> TacticT jdg ext err s m a
155153mappingExtract f (TacticT m)
156154 = TacticT $ StateT $ \ jdg ->
157- mapExtract' f $ runStateT m jdg
155+ mapExtract id f $ runStateT m jdg
158156
159157
160158------------------------------------------------------------------------------
@@ -227,7 +225,10 @@ unify goal inst = do
227225 case tryUnifyUnivarsButNotSkolems skolems goal inst of
228226 Just subst ->
229227 modify $ updateSubst subst
230- Nothing -> throwError (UnificationError inst goal)
228+ Nothing -> cut -- failure (UnificationError inst goal)
229+
230+ cut :: RuleT jdg ext err s m a
231+ cut = RuleT Empty
231232
232233
233234------------------------------------------------------------------------------
@@ -254,26 +255,6 @@ attemptWhen _ t2 False = t2
254255attemptWhen t1 t2 True = commit t1 t2
255256
256257
257- ------------------------------------------------------------------------------
258- -- | Mystical time-traveling combinator for inspecting the extracts produced by
259- -- a tactic. We can use it to guard that extracts match certain predicates, for
260- -- example.
261- --
262- -- Note, that this thing is WEIRD. To illustrate:
263- --
264- -- @@
265- -- peek f
266- -- blah
267- -- @@
268- --
269- -- Here, @f@ can inspect the extract _produced by @blah@,_ which means the
270- -- causality appears to go backwards.
271- --
272- -- 'peek' should be exposed directly by @refinery@ in the next release.
273- peek :: (ext -> TacticT jdg ext err s m () ) -> TacticT jdg ext err s m ()
274- peek k = tactic $ \ j -> Subgoal (() , j) $ \ e -> proofState (k e) j
275-
276-
277258------------------------------------------------------------------------------
278259-- | Run the given tactic iff the current hole contains no univars. Skolems and
279260-- already decided univars are OK though.
@@ -284,7 +265,7 @@ requireConcreteHole m = do
284265 let vars = S. fromList $ tyCoVarsOfTypeWellScoped $ unCType $ jGoal jdg
285266 case S. size $ vars S. \\ skolems of
286267 0 -> m
287- _ -> throwError TooPolymorphic
268+ _ -> failure TooPolymorphic
288269
289270
290271------------------------------------------------------------------------------
@@ -317,7 +298,7 @@ useNameFromHypothesis f name = do
317298 hy <- jHypothesis <$> goal
318299 case M. lookup name $ hyByName hy of
319300 Just hi -> f hi
320- Nothing -> throwError $ NotInScope name
301+ Nothing -> failure $ NotInScope name
321302
322303------------------------------------------------------------------------------
323304-- | Lift a function over 'HyInfo's to one that takes an 'OccName' and tries to
@@ -326,7 +307,7 @@ useNameFromContext :: (HyInfo CType -> TacticsM a) -> OccName -> TacticsM a
326307useNameFromContext f name = do
327308 lookupNameInContext name >>= \ case
328309 Just ty -> f $ createImportedHyInfo name ty
329- Nothing -> throwError $ NotInScope name
310+ Nothing -> failure $ NotInScope name
330311
331312
332313------------------------------------------------------------------------------
@@ -340,12 +321,11 @@ lookupNameInContext name = do
340321
341322
342323getDefiningType
343- :: (MonadError TacticError m , MonadReader Context m )
344- => m CType
324+ :: TacticsM CType
345325getDefiningType = do
346326 calling_fun_name <- fst . head <$> asks ctxDefiningFuncs
347327 maybe
348- (throwError $ NotInScope calling_fun_name)
328+ (failure $ NotInScope calling_fun_name)
349329 pure
350330 =<< lookupNameInContext calling_fun_name
351331
@@ -403,7 +383,7 @@ getOccNameType
403383getOccNameType occ = do
404384 getTyThing occ >>= \ case
405385 Just (AnId v) -> pure $ varType v
406- _ -> throwError $ NotInScope occ
386+ _ -> failure $ NotInScope occ
407387
408388
409389getCurrentDefinitions :: TacticsM [(OccName , CType )]
0 commit comments