From ac81b418d61e150376485a5956421e8e6967a651 Mon Sep 17 00:00:00 2001 From: Liyana Date: Tue, 10 Nov 2020 16:57:33 +0800 Subject: [PATCH 01/10] Added readJSON error messages --- src/compiler/SimpleEditor/JSON.hs | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/compiler/SimpleEditor/JSON.hs b/src/compiler/SimpleEditor/JSON.hs index 8f607dc84..06586c5eb 100644 --- a/src/compiler/SimpleEditor/JSON.hs +++ b/src/compiler/SimpleEditor/JSON.hs @@ -9,14 +9,24 @@ instance JSON Grammar where showJSON (Grammar name extends abstract concretes) = makeObj ["basename".=name, "extends".=extends, "abstract".=abstract, "concretes".=concretes] + readJSON = error "Grammar.readJSON intentionally not defined" instance JSON Abstract where showJSON (Abstract startcat cats funs) = makeObj ["startcat".=startcat, "cats".=cats, "funs".=funs] + readJSON = error "Abstract.readJSON intentionally not defined" -instance JSON Fun where showJSON (Fun name typ) = signature name typ -instance JSON Param where showJSON (Param name rhs) = definition name rhs -instance JSON Oper where showJSON (Oper name rhs) = definition name rhs +instance JSON Fun where + showJSON (Fun name typ) = signature name typ + readJSON = error "Fun.readJSON intentionally not defined" + +instance JSON Param where + showJSON (Param name rhs) = definition name rhs + readJSON = error "Param.readJSON intentionally not defined" + +instance JSON Oper where + showJSON (Oper name rhs) = definition name rhs + readJSON = error "Oper.readJSON intentionally not defined" signature name typ = makeObj ["name".=name,"type".=typ] definition name rhs = makeObj ["name".=name,"rhs".=rhs] @@ -26,12 +36,15 @@ instance JSON Concrete where makeObj ["langcode".=langcode, "opens".=opens, "params".=params, "opers".=opers, "lincats".=lincats, "lins".=lins] + readJSON = error "Concrete.readJSON intentionally not defined" instance JSON Lincat where showJSON (Lincat cat lintype) = makeObj ["cat".=cat, "type".=lintype] + readJSON = error "Lincat.readJSON intentionally not defined" instance JSON Lin where showJSON (Lin fun args lin) = makeObj ["fun".=fun, "args".=args, "lin".=lin] + readJSON = error "Lin.readJSON intentionally not defined" infix 1 .= name .= v = (name,showJSON v) From dc6dd988bc77bc95bc5a5855e1031f4169c1b4b8 Mon Sep 17 00:00:00 2001 From: Liyana Date: Tue, 10 Nov 2020 17:01:47 +0800 Subject: [PATCH 02/10] Replaced inlinePerformIO with accursedUnutterablePerformIO --- src/runtime/haskell/Data/Binary/Builder.hs | 4 ++-- src/runtime/haskell/Data/Binary/Get.hs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/runtime/haskell/Data/Binary/Builder.hs b/src/runtime/haskell/Data/Binary/Builder.hs index b69371f0e..a74428f20 100644 --- a/src/runtime/haskell/Data/Binary/Builder.hs +++ b/src/runtime/haskell/Data/Binary/Builder.hs @@ -68,7 +68,7 @@ import qualified Data.ByteString.Lazy as L import Data.ByteString.Base (inlinePerformIO) import qualified Data.ByteString.Base as S #else -import Data.ByteString.Internal (inlinePerformIO) +import Data.ByteString.Internal (accursedUnutterablePerformIO) import qualified Data.ByteString.Internal as S --import qualified Data.ByteString.Lazy.Internal as L #endif @@ -199,7 +199,7 @@ defaultSize = 32 * k - overhead -- | Sequence an IO operation on the buffer unsafeLiftIO :: (Buffer -> IO Buffer) -> Builder -unsafeLiftIO f = Builder $ \ k buf -> inlinePerformIO $ do +unsafeLiftIO f = Builder $ \ k buf -> accursedUnutterablePerformIO $ do buf' <- f buf return (k buf') {-# INLINE unsafeLiftIO #-} diff --git a/src/runtime/haskell/Data/Binary/Get.hs b/src/runtime/haskell/Data/Binary/Get.hs index 01561d7d9..54f17ae95 100644 --- a/src/runtime/haskell/Data/Binary/Get.hs +++ b/src/runtime/haskell/Data/Binary/Get.hs @@ -423,7 +423,7 @@ readN n f = fmap f $ getBytes n getPtr :: Storable a => Int -> Get a getPtr n = do (fp,o,_) <- readN n B.toForeignPtr - return . B.inlinePerformIO $ withForeignPtr fp $ \p -> peek (castPtr $ p `plusPtr` o) + return . B.accursedUnutterablePerformIO $ withForeignPtr fp $ \p -> peek (castPtr $ p `plusPtr` o) {- INLINE getPtr -} ------------------------------------------------------------------------ From 33aad1b8de0b8387426155870c98adf35e400962 Mon Sep 17 00:00:00 2001 From: Liyana Date: Tue, 10 Nov 2020 17:06:35 +0800 Subject: [PATCH 03/10] Deleted redundant pattern match --- src/compiler/GF/Grammar/Canonical.hs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/compiler/GF/Grammar/Canonical.hs b/src/compiler/GF/Grammar/Canonical.hs index 4adff02f2..0df3236ff 100644 --- a/src/compiler/GF/Grammar/Canonical.hs +++ b/src/compiler/GF/Grammar/Canonical.hs @@ -265,7 +265,6 @@ instance PPA LinPattern where RecordPattern r -> block r TuplePattern ps -> "<"<>punctuate "," ps<>">" WildPattern -> pp "_" - _ -> parens p instance RhsSeparator LinPattern where rhsSep _ = pp "=" From 4364b1d9fb62551fb6361be36cf2563e6d2d93a5 Mon Sep 17 00:00:00 2001 From: Liyana Date: Tue, 10 Nov 2020 17:11:41 +0800 Subject: [PATCH 04/10] Replaced Control.Monad.Error with Control.Monad.Except --- src/runtime/haskell/PGF/TypeCheck.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/runtime/haskell/PGF/TypeCheck.hs b/src/runtime/haskell/PGF/TypeCheck.hs index 5db4ef439..c5cc44b4e 100644 --- a/src/runtime/haskell/PGF/TypeCheck.hs +++ b/src/runtime/haskell/PGF/TypeCheck.hs @@ -41,7 +41,7 @@ import Control.Applicative import Control.Monad --import Control.Monad.Identity import Control.Monad.State -import Control.Monad.Error +import Control.Monad.Except import Text.PrettyPrint ----------------------------------------------------- From 1f7584bf98346c6d044df631a82353fd1c5972af Mon Sep 17 00:00:00 2001 From: Liyana Date: Tue, 10 Nov 2020 17:14:31 +0800 Subject: [PATCH 05/10] Added explicit implementation for 'fromValue' in instance declaration for 'Predef Bool' --- src/compiler/GF/Compile/Compute/Predef.hs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/compiler/GF/Compile/Compute/Predef.hs b/src/compiler/GF/Compile/Compute/Predef.hs index 609a17798..69df3792c 100644 --- a/src/compiler/GF/Compile/Compute/Predef.hs +++ b/src/compiler/GF/Compile/Compute/Predef.hs @@ -27,6 +27,7 @@ instance Predef Int where instance Predef Bool where toValue = boolV + fromValue boolV = return (boolV == boolV) instance Predef String where toValue = string From 8ca4baf470da2fd607d89e7679f7376a56b3f8fb Mon Sep 17 00:00:00 2001 From: Liyana Date: Tue, 10 Nov 2020 17:15:20 +0800 Subject: [PATCH 06/10] Deleted redundant pattern match --- src/compiler/GF/Compile/Compute/ConcreteNew.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/compiler/GF/Compile/Compute/ConcreteNew.hs b/src/compiler/GF/Compile/Compute/ConcreteNew.hs index ea55e77cb..6f00c45e1 100644 --- a/src/compiler/GF/Compile/Compute/ConcreteNew.hs +++ b/src/compiler/GF/Compile/Compute/ConcreteNew.hs @@ -528,7 +528,7 @@ value2term' stop loc xs v0 = -- VGlue v1 v2 -> Glue (v2t v1) (v2t v2) -- VExtR v1 v2 -> ExtR (v2t v1) (v2t v2) VError err -> return (Error err) - _ -> bug ("value2term "++show loc++" : "++show v0) + where v2t = v2txs xs v2txs = value2term' stop loc From 54e5fb6645d4c99900136e7c909ca7905e441912 Mon Sep 17 00:00:00 2001 From: Liyana Date: Tue, 10 Nov 2020 17:19:18 +0800 Subject: [PATCH 07/10] Added explicit implementation for 'readJSON' in the instance declaration for 'JSON PGF.Trie' --- src/server/PGFService.hs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/server/PGFService.hs b/src/server/PGFService.hs index e30ff8652..7edfa9c44 100644 --- a/src/server/PGFService.hs +++ b/src/server/PGFService.hs @@ -1024,6 +1024,7 @@ instance JSON PGF.Trie where showJSON (PGF.Ap f [[]]) = makeObj ["fun".=f] -- leaf -- showJSON (PGF.Ap f [es]) = makeObj ["fun".=f,"children".=es] -- one alternative showJSON (PGF.Ap f alts) = makeObj ["fun".=f,"alts".=alts] + readJSON = error "PGF.Trie.readJSON intentionally not defined" instance JSON PGF.CId where readJSON x = readJSON x >>= maybe (fail "Bad language.") return . PGF.readLanguage From 9b02385e3efcadf39a171f65eaba871b1897360e Mon Sep 17 00:00:00 2001 From: Liyana Date: Tue, 10 Nov 2020 17:26:56 +0800 Subject: [PATCH 08/10] Removed fromValue for boolV --- src/compiler/GF/Compile/Compute/Predef.hs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/compiler/GF/Compile/Compute/Predef.hs b/src/compiler/GF/Compile/Compute/Predef.hs index 69df3792c..609a17798 100644 --- a/src/compiler/GF/Compile/Compute/Predef.hs +++ b/src/compiler/GF/Compile/Compute/Predef.hs @@ -27,7 +27,6 @@ instance Predef Int where instance Predef Bool where toValue = boolV - fromValue boolV = return (boolV == boolV) instance Predef String where toValue = string From 2dc179239f915420a5e9485d87a2fa1adb413e4e Mon Sep 17 00:00:00 2001 From: Liyana Date: Tue, 10 Nov 2020 17:32:43 +0800 Subject: [PATCH 09/10] Replaced Control.Monad.Error with Control.Monad.Except --- src/compiler/GF/Server.hs | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/compiler/GF/Server.hs b/src/compiler/GF/Server.hs index c287e8001..d930d277c 100644 --- a/src/compiler/GF/Server.hs +++ b/src/compiler/GF/Server.hs @@ -6,7 +6,7 @@ import qualified Data.Map as M import Control.Applicative -- for GHC<7.10 import Control.Monad(when) import Control.Monad.State(StateT(..),get,gets,put) -import Control.Monad.Error(ErrorT(..),Error(..)) +import Control.Monad.Except(ExceptT(..),Except(..),runExceptT) import System.Random(randomRIO) --import System.IO(stderr,hPutStrLn) import GF.System.Catch(try) @@ -108,9 +108,9 @@ handle_fcgi execute1 state0 stateM cache = -- * Request handler -- | Handler monad -type HM s a = StateT (Q,s) (ErrorT Response IO) a +type HM s a = StateT (Q,s) (ExceptT Response IO) a run :: HM s Response -> (Q,s) -> IO (s,Response) -run m s = either bad ok =<< runErrorT (runStateT m s) +run m s = either bad ok =<< runExceptT (runStateT m s) where bad resp = return (snd s,resp) ok (resp,(qs,state)) = return (state,resp) @@ -123,12 +123,12 @@ put_qs qs = do state <- get_state; put (qs,state) put_state state = do qs <- get_qs; put (qs,state) err :: Response -> HM s a -err e = StateT $ \ s -> ErrorT $ return $ Left e +err e = StateT $ \ s -> ExceptT $ return $ Left e hmbracket_ :: IO () -> IO () -> HM s a -> HM s a hmbracket_ pre post m = do s <- get - e <- liftIO $ bracket_ pre post $ runErrorT $ runStateT m s + e <- liftIO $ bracket_ pre post $ runExceptT $ runStateT m s case e of Left resp -> err resp Right (a,s) -> do put s;return a @@ -407,9 +407,6 @@ resp404 path = Response 404 [plain,xo] $ "Not found: "++path++"\n" resp500 msg = Response 500 [plain,xo] $ "Internal error: "++msg++"\n" resp501 msg = Response 501 [plain,xo] $ "Not implemented: "++msg++"\n" -instance Error Response where - noMsg = resp500 "no message" - strMsg = resp500 -- * Content types plain = ct "text/plain" "" From 76bec6d71e7c4fdffa2e618ec6578e0858166465 Mon Sep 17 00:00:00 2001 From: Liyana Date: Thu, 12 Nov 2020 09:48:15 +0800 Subject: [PATCH 10/10] Omitted import Except(..) --- src/compiler/GF/Server.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/compiler/GF/Server.hs b/src/compiler/GF/Server.hs index d930d277c..2e8b8b056 100644 --- a/src/compiler/GF/Server.hs +++ b/src/compiler/GF/Server.hs @@ -6,7 +6,7 @@ import qualified Data.Map as M import Control.Applicative -- for GHC<7.10 import Control.Monad(when) import Control.Monad.State(StateT(..),get,gets,put) -import Control.Monad.Except(ExceptT(..),Except(..),runExceptT) +import Control.Monad.Except(ExceptT(..),runExceptT) import System.Random(randomRIO) --import System.IO(stderr,hPutStrLn) import GF.System.Catch(try)