Skip to content

Commit

Permalink
Multiple errors during name resolution
Browse files Browse the repository at this point in the history
  • Loading branch information
paf31 committed Nov 1, 2014
1 parent 33db511 commit 9eb1965
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 18 deletions.
5 changes: 5 additions & 0 deletions examples/failing/MultipleErrors2.purs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module MultipleErrors2 where

foo = itDoesntExist

bar = neitherDoesThis
17 changes: 17 additions & 0 deletions src/Language/PureScript/Errors.hs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@

module Language.PureScript.Errors where

import Data.Either (lefts, rights)
import Data.List (intersperse, intercalate)
import Data.Monoid

import Control.Monad.Error
import Control.Applicative ((<$>))

import Language.PureScript.Declarations
import Language.PureScript.Pretty
Expand Down Expand Up @@ -121,3 +123,18 @@ rethrow f = flip catchError $ \e -> throwError (f e)
--
rethrowWithPosition :: (MonadError ErrorStack m) => SourcePos -> m a -> m a
rethrowWithPosition pos = rethrow (positionError pos <>)

-- |
-- Collect errors in in parallel
--
parU :: (MonadError ErrorStack m, Functor m) => [a] -> (a -> m b) -> m [b]
parU xs f = forM xs (withError . f) >>= collectErrors
where
withError :: (MonadError ErrorStack m, Functor m) => m a -> m (Either ErrorStack a)
withError u = catchError (Right <$> u) (return . Left)

collectErrors :: (MonadError ErrorStack m, Functor m) => [Either ErrorStack a] -> m [a]
collectErrors es = case lefts es of
[err] -> throwError err
[] -> return $ rights es
errs -> throwError $ MultipleErrors errs
2 changes: 1 addition & 1 deletion src/Language/PureScript/Sugar/Names.hs
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ elaborateExports exps (Module mn decls _) = Module mn decls (Just $
--
renameInModule :: ImportEnvironment -> ExportEnvironment -> Module -> Either ErrorStack Module
renameInModule imports exports (Module mn decls exps) =
Module mn <$> mapM go decls <*> pure exps
Module mn <$> parU decls go <*> pure exps
where
(go, _, _, _, _) = everywhereWithContextOnValuesM (Nothing, []) updateDecl updateValue updateBinder updateCase defS

Expand Down
17 changes: 0 additions & 17 deletions src/Language/PureScript/TypeChecker/Monad.hs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import Language.PureScript.Options
import Language.PureScript.Errors

import Data.Maybe
import Data.Either (lefts, rights)

import Control.Applicative
import Control.Monad.State
Expand Down Expand Up @@ -233,19 +232,3 @@ liftUnify unify = do
(a, ust) <- runUnify (defaultUnifyState { unifyNextVar = checkNextVar st }) unify
modify $ \st' -> st' { checkNextVar = unifyNextVar ust }
return (a, unifyCurrentSubstitution ust)

-- |
-- Typecheck in parallel
--
parU :: [a] -> (a -> UnifyT t Check b) -> UnifyT t Check [b]
parU xs f = forM xs (withError . f) >>= collectErrors
where
withError :: UnifyT t Check a -> UnifyT t Check (Either ErrorStack a)
withError u = catchError (Right <$> u) (return . Left)

collectErrors :: [Either ErrorStack a] -> UnifyT t Check [a]
collectErrors es = case lefts es of
[err] -> throwError err
[] -> return $ rights es
errs -> throwError $ MultipleErrors errs

0 comments on commit 9eb1965

Please sign in to comment.