1
1
mirror of https://github.com/github/semantic.git synced 2024-12-20 13:21:59 +03:00

LoadErrors are resumed with the evaluated result, rather than the list of modules to evaluate.

This commit is contained in:
Rob Rix 2018-05-09 12:20:23 -04:00
parent 6330da5bce
commit 662e385b97
4 changed files with 17 additions and 17 deletions

View File

@ -86,14 +86,14 @@ graphingTerms recur term@(In _ syntax) = do
-- | Add vertices to the graph for 'LoadError's.
graphingLoadErrors :: forall location term value effects a
. Members '[ Reader ModuleInfo
, Resumable (LoadError term)
, Resumable (LoadError location value)
, State Graph
] effects
=> SubtermAlgebra (Base term) term (Evaluator location term value effects a)
-> SubtermAlgebra (Base term) term (Evaluator location term value effects a)
graphingLoadErrors recur term = resume @(LoadError term)
graphingLoadErrors recur term = resume @(LoadError location value)
(recur term)
(\ (LoadError name) -> moduleInclusion (Module (BC.pack name)) $> [])
(\ err@(LoadError name) -> moduleInclusion (Module (BC.pack name)) *> throwResumable err)
-- | Add vertices to the graph for evaluated modules and the packages containing them.
graphingModules :: Members '[ Reader ModuleInfo

View File

@ -60,7 +60,7 @@ data Modules location value return where
sendModules :: Member (Modules location value) effects => Modules location value return -> Evaluator location term value effects return
sendModules = send
runModules :: Members '[ Resumable (LoadError term)
runModules :: Members '[ Resumable (LoadError location value)
, State (Environment location value)
, State (Exports location value)
, State (ModuleTable (Maybe (Environment location value, value)))
@ -70,7 +70,7 @@ runModules :: Members '[ Resumable (LoadError term)
-> Evaluator location term value (Modules location value ': effects) a
-> Evaluator location term value (Reader (ModuleTable [Module term]) ': effects) a
runModules evaluateModule = reinterpretEffect (\ m -> case m of
Load name -> askModuleTable >>= maybeM notFound . ModuleTable.lookup name >>= runMerging . foldMap (Merging . evalAndCache)
Load name -> askModuleTable >>= maybe notFound (runMerging . foldMap (Merging . evalAndCache)) . ModuleTable.lookup name
where
notFound = throwResumable (LoadError name)
@ -126,20 +126,20 @@ instance Applicative m => Monoid (Merging m location value) where
-- | An error thrown when loading a module from the list of provided modules. Indicates we weren't able to find a module with the given name.
data LoadError term resume where
LoadError :: ModulePath -> LoadError term [Module term]
data LoadError location value resume where
LoadError :: ModulePath -> LoadError location value (Maybe (Environment location value, value))
deriving instance Eq (LoadError term resume)
deriving instance Show (LoadError term resume)
instance Show1 (LoadError term) where
deriving instance Eq (LoadError location value resume)
deriving instance Show (LoadError location value resume)
instance Show1 (LoadError location value) where
liftShowsPrec _ _ = showsPrec
instance Eq1 (LoadError term) where
instance Eq1 (LoadError location value) where
liftEq _ (LoadError a) (LoadError b) = a == b
runLoadError :: Evaluator location term value (Resumable (LoadError term) ': effects) a -> Evaluator location term value effects (Either (SomeExc (LoadError term)) a)
runLoadError :: Evaluator location term value (Resumable (LoadError location value) ': effects) a -> Evaluator location term value effects (Either (SomeExc (LoadError location value)) a)
runLoadError = raiseHandler runError
runLoadErrorWith :: (forall resume . LoadError term resume -> Evaluator location term value effects resume) -> Evaluator location term value (Resumable (LoadError term) ': effects) a -> Evaluator location term value effects a
runLoadErrorWith :: (forall resume . LoadError location value resume -> Evaluator location term value effects resume) -> Evaluator location term value (Resumable (LoadError location value) ': effects) a -> Evaluator location term value effects a
runLoadErrorWith = runResumableWith

View File

@ -170,7 +170,7 @@ evaluatePackageWith :: ( Evaluatable (Base term)
, EvaluatableConstraints location term value inner
, Members '[ Fail
, Reader (Environment location value)
, Resumable (LoadError term)
, Resumable (LoadError location value)
, State (Environment location value)
, State (Exports location value)
, State (ModuleTable (Maybe (Environment location value, value)))
@ -192,7 +192,7 @@ evaluatePackageBodyWith :: forall location term value inner inner' outer
, EvaluatableConstraints location term value inner
, Members '[ Fail
, Reader (Environment location value)
, Resumable (LoadError term)
, Resumable (LoadError location value)
, State (Environment location value)
, State (Exports location value)
, State (ModuleTable (Maybe (Environment location value, value)))

View File

@ -90,8 +90,8 @@ resumingResolutionError = runResolutionErrorWith (\ err -> traceE ("ResolutionEr
NotFoundError nameToResolve _ _ -> pure nameToResolve
GoImportError pathToResolve -> pure [pathToResolve])
resumingLoadError :: Evaluator location term value (Resumable (LoadError term) ': effects) a -> Evaluator location term value effects a
resumingLoadError = runLoadErrorWith (\ (LoadError _) -> pure [])
resumingLoadError :: Member Trace effects => Evaluator location term value (Resumable (LoadError location value) ': effects) a -> Evaluator location term value effects a
resumingLoadError = runLoadErrorWith (\ (LoadError path) -> traceE ("LoadError: " <> path) $> Nothing)
resumingEvalError :: (AbstractHole value, Member Trace effects, Show value) => Evaluator location term value (Resumable (EvalError value) ': effects) a -> Evaluator location term value effects a
resumingEvalError = runEvalErrorWith (\ err -> traceE ("EvalError" <> show err) *> case err of