[Git][ghc/ghc][wip/js-staging] Fix Outputable instances for JExpr/JVal

Sylvain Henry (@hsyl20) gitlab at gitlab.haskell.org
Wed Aug 10 16:03:00 UTC 2022



Sylvain Henry pushed to branch wip/js-staging at Glasgow Haskell Compiler / GHC


Commits:
5f286bfa by Sylvain Henry at 2022-08-10T18:05:43+02:00
Fix Outputable instances for JExpr/JVal

- Put orphan instances in JS.Ppr
- Also fix some redundant imports

- - - - -


7 changed files:

- compiler/GHC/JS/Make.hs
- compiler/GHC/JS/Ppr.hs
- compiler/GHC/JS/Syntax.hs
- compiler/GHC/JS/Transform.hs
- compiler/GHC/StgToJS/Printer.hs
- compiler/GHC/StgToJS/Regs.hs
- compiler/GHC/StgToJS/Types.hs


Changes:

=====================================
compiler/GHC/JS/Make.hs
=====================================
@@ -142,8 +142,6 @@ import qualified Data.Map as M
 import qualified Data.List as List
 
 import GHC.Utils.Outputable (Outputable (..))
-import qualified GHC.Data.ShortText as ST
-import GHC.Data.ShortText (ShortText)
 import GHC.Data.FastString
 import GHC.Utils.Monad.State.Strict
 import GHC.Utils.Panic


=====================================
compiler/GHC/JS/Ppr.hs
=====================================
@@ -7,6 +7,9 @@
 {-# LANGUAGE GADTs #-}
 {-# LANGUAGE BlockArguments #-}
 
+-- For Outputable instances for JS syntax
+{-# OPTIONS_GHC -Wno-orphans #-}
+
 -- | Pretty-printing JavaScript
 module GHC.JS.Ppr
   ( renderJs
@@ -31,20 +34,23 @@ import GHC.JS.Syntax
 import GHC.JS.Transform
 
 
-import Data.Function
 import Data.Char (isControl, ord)
-import qualified Data.Map as M
-import Data.List
-import Data.Ord
+import Data.List (sortOn)
 
 import Numeric(showHex)
 
+import GHC.Utils.Outputable (Outputable (..), docToSDoc)
 import GHC.Utils.Ppr as PP
-import qualified GHC.Data.ShortText as ST
-import GHC.Data.ShortText (ShortText)
 import GHC.Data.FastString
 import GHC.Types.Unique.Map
 
+instance Outputable JExpr where
+  ppr = docToSDoc . renderJs
+
+instance Outputable JVal where
+  ppr = docToSDoc . renderJs
+
+
 ($$$) :: Doc -> Doc -> Doc
 --x $$$ y = align (nest 2 $ x $+$ y) -- FIXME (Sylvain, 2022/02)
 x $$$ y = nest 2 $ x $+$ y


=====================================
compiler/GHC/JS/Syntax.hs
=====================================
@@ -94,7 +94,6 @@ import GHC.Prelude
 import Control.DeepSeq
 
 import Data.Function
-import qualified Data.Map as M
 import qualified Data.Set as Set
 import Data.Data
 import Data.Word
@@ -102,12 +101,9 @@ import qualified Data.Semigroup as Semigroup
 
 import GHC.Generics
 
-import GHC.Utils.Outputable (Outputable (..))
-import qualified GHC.Utils.Outputable as O
 import GHC.Data.FastString
 import GHC.Utils.Monad.State.Strict
 import GHC.Types.Unique.Map
-import GHC.Utils.Binary
 
 -- FIXME: Jeff (2022,03): This state monad is strict, but uses a lazy list as
 -- the state, since the strict state monad evaluates to WHNF, this state monad
@@ -255,9 +251,6 @@ data JExpr
                                     --   See 'pseudoSaturate'
   deriving (Eq, Typeable, Generic)
 
-instance Outputable JExpr where
-  ppr x = undefined -- O.text (show x)
-
 -- * Useful pattern synonyms to ease programming with the deeply embedded JS
 --   AST. Each pattern wraps @JUOp@ and @JOp@ into a @JExpr at s to save typing and
 --   for convienience. In addition we include a string wrapper for JS string
@@ -362,10 +355,6 @@ data JVal
   | UnsatVal (IdentSupply JVal)         -- ^ An /Unsaturated/ value, see 'pseudoSaturate'
   deriving (Eq, Typeable, Generic)
 
-instance Outputable JVal where
-  ppr x = undefined -- O.text (show x)
-
-
 --------------------------------------------------------------------------------
 --                            Operators
 --------------------------------------------------------------------------------


=====================================
compiler/GHC/JS/Transform.hs
=====================================
@@ -41,12 +41,9 @@ import Data.Functor.Identity
 import Control.Monad
 import Data.Semigroup
 import Data.Bifunctor
-import Data.List
 import Data.Set (Set)
 import qualified Data.Set as Set
 
-import qualified GHC.Data.ShortText as ST
-import GHC.Data.ShortText (ShortText)
 import GHC.Data.FastString
 import GHC.Utils.Monad.State.Strict
 import GHC.Utils.Panic


=====================================
compiler/GHC/StgToJS/Printer.hs
=====================================
@@ -20,24 +20,22 @@ module GHC.StgToJS.Printer
   ( pretty
   , ghcjsRenderJs
   , prettyBlock
-  ) where
+  )
+where
+
+import GHC.Prelude
 
 
 import GHC.JS.Syntax
 import GHC.JS.Ppr
 
-import qualified GHC.Data.ShortText as T
-import           GHC.Utils.Ppr      as PP
-import           GHC.Data.FastString
-import           GHC.Types.Unique.Map
-
-import qualified Data.Map           as M
-import           Data.List
+import GHC.Utils.Ppr      as PP
+import GHC.Data.FastString
+import GHC.Types.Unique.Map
 
+import Data.List (sortOn)
 import Data.Char (isAlpha,isDigit)
 
-import GHC.Prelude
-
 pretty :: JStat -> Doc
 pretty = jsToDocR ghcjsRenderJs
 


=====================================
compiler/GHC/StgToJS/Regs.hs
=====================================
@@ -24,7 +24,6 @@ import GHC.Prelude
 import GHC.JS.Syntax
 import GHC.JS.Make
 
-import qualified GHC.Data.ShortText as ST
 import GHC.Data.FastString
 
 import Data.Array


=====================================
compiler/GHC/StgToJS/Types.hs
=====================================
@@ -9,6 +9,7 @@ import GHC.Prelude
 
 import GHC.JS.Syntax
 import GHC.JS.Make
+import GHC.JS.Ppr
 
 import GHC.Stg.Syntax
 import GHC.Core.TyCon



View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/5f286bfa0818126790ffcb6082402af6e4d7c57c

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/5f286bfa0818126790ffcb6082402af6e4d7c57c
You're receiving this email because of your account on gitlab.haskell.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-commits/attachments/20220810/cd1b42eb/attachment-0001.html>


More information about the ghc-commits mailing list