Skip to content

Commit

Permalink
ihaskell: Remove partial-fields
Browse files Browse the repository at this point in the history
GHC 8.4 and later have the `-Wpartial-fields` warning flag, so add it and
fix the warnings.
  • Loading branch information
erikd committed Sep 3, 2018
1 parent 8c37c42 commit ba9dade
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 21 deletions.
11 changes: 11 additions & 0 deletions ihaskell.cabal
Expand Up @@ -50,6 +50,10 @@ library
hs-source-dirs: src
default-language: Haskell2010
ghc-options: -Wall

if impl (ghc >= 8.4)
ghc-options: -Wpartial-fields

build-depends:
aeson >=1.0,
base >=4.9,
Expand Down Expand Up @@ -123,6 +127,9 @@ executable ihaskell
Paths_ihaskell
ghc-options: -threaded -rtsopts -Wall

if impl (ghc >= 8.4)
ghc-options: -Wpartial-fields

-- Other library packages from which modules are imported.
default-language: Haskell2010
build-depends:
Expand All @@ -143,6 +150,10 @@ executable ihaskell
Test-Suite hspec
Type: exitcode-stdio-1.0
Ghc-Options: -threaded -Wall

if impl (ghc >= 8.4)
ghc-options: -Wpartial-fields

Main-Is: Hspec.hs
hs-source-dirs: src/tests
other-modules:
Expand Down
18 changes: 11 additions & 7 deletions src/IHaskell/Publish.hs
@@ -1,5 +1,7 @@
{-# language NoImplicitPrelude, DoAndIfThenElse, OverloadedStrings, ExtendedDefaultRules #-}
module IHaskell.Publish (publishResult) where
module IHaskell.Publish
( publishResult
) where

import IHaskellPrelude

Expand Down Expand Up @@ -30,7 +32,7 @@ publishResult send replyHeader displayed updateNeeded poutput upager result = do
case result of
IntermediateResult{} -> False
FinalResult{} -> True
outs = outputs result
outs = evaluationOutputs result

-- If necessary, clear all previous output and redraw.
clear <- readMVar updateNeeded
Expand All @@ -49,11 +51,13 @@ publishResult send replyHeader displayed updateNeeded poutput upager result = do
modifyMVar_ displayed (return . (outs :))

-- If this has some pager output, store it for later.
let pager = pagerOut result
unless (null pager) $
if upager
then modifyMVar_ poutput (return . (++ pager))
else sendOutput $ Display pager
case result of
IntermediateResult _ -> pure ()
FinalResult _ pager _ ->
unless (null pager) $
if upager
then modifyMVar_ poutput (return . (++ pager))
else sendOutput $ Display pager

where
clearOutput = do
Expand Down
29 changes: 16 additions & 13 deletions src/IHaskell/Types.hs
Expand Up @@ -19,6 +19,7 @@ module IHaskell.Types (
MimeType(..),
DisplayData(..),
EvaluationResult(..),
evaluationOutputs,
ExecuteReplyStatus(..),
KernelState(..),
LintStatus(..),
Expand Down Expand Up @@ -248,21 +249,23 @@ instance ToJSON WidgetMethod where
toJSON (CustomContent v) = object ["method" .= ("custom" :: Text), "content" .= v]

-- | Output of evaluation.
data EvaluationResult =
-- | An intermediate result which communicates what has been printed thus
-- far.
IntermediateResult
{ outputs :: Display -- ^ Display outputs.
}
|
FinalResult
{ outputs :: Display -- ^ Display outputs.
, pagerOut :: [DisplayData] -- ^ Mimebundles to display in the IPython
-- pager.
, commMsgs :: [WidgetMsg] -- ^ Comm operations
}
data EvaluationResult
-- | An intermediate result which communicates what has been printed thus far.
= IntermediateResult
!Display -- ^ Display outputs.
| FinalResult
!Display -- ^ Display outputs.
![DisplayData] -- ^ Mimebundles to display in the IPython pager.
![WidgetMsg] -- ^ Comm operations
deriving Show


evaluationOutputs :: EvaluationResult -> Display
evaluationOutputs er =
case er of
IntermediateResult outputs -> outputs
FinalResult outputs _ _ -> outputs

-- | Duplicate a message header, giving it a new UUID and message type.
dupHeader :: MessageHeader -> MessageType -> IO MessageHeader
dupHeader hdr messageType = do
Expand Down
2 changes: 1 addition & 1 deletion stack-8.4.yaml
Expand Up @@ -26,7 +26,7 @@ extra-deps:
ghc-options:
# Eventually we want "$locals": -Wall -Wpartial-fields -Werror
ghc-parser: -Wall -Wpartial-fields -Werror
ihaskell: -Wall -Werror
ihaskell: -Wall -Wpartial-fields -Werror
ihaskell-widgets: -Wall -Wpartial-fields -Werror

nix:
Expand Down

0 comments on commit ba9dade

Please sign in to comment.