Skip to content

Commit

Permalink
Avoid rnf from Control.DeepSeq, it's a massive slowdown.
Browse files Browse the repository at this point in the history
Use primRnf instead.
  • Loading branch information
augustss committed Aug 29, 2024
1 parent 04699be commit c5d0e25
Show file tree
Hide file tree
Showing 8 changed files with 4,438 additions and 4,422 deletions.
8,831 changes: 4,416 additions & 4,415 deletions generated/mhs.c

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions ghc/Compat.hs
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,6 @@ _isWindows = False
rnfNoErr :: forall a . a -> ()
rnfNoErr _ = ()

-- This cannot be implemented with GHC.
rnfErr :: forall a . a -> ()
rnfErr _ = ()
4 changes: 4 additions & 0 deletions lib/Control/DeepSeq.hs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ module Control.DeepSeq (
(<$!!>),
rwhnf,
rnfNoErr,
rnfErr,
) where
import Primitives(primRnfErr, primRnfNoErr)
import Data.Complex
Expand All @@ -17,6 +18,9 @@ import Data.Tuple
rnfNoErr :: forall a . a -> ()
rnfNoErr = primRnfNoErr

rnfErr :: forall a . a -> ()
rnfErr = primRnfErr

infixr 0 $!!

infixr 0 `deepseq`
Expand Down
13 changes: 12 additions & 1 deletion mhs/Compat.hs
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
-- Copyright 2023 Lennart Augustsson
-- See LICENSE file for full license.
module Compat() where
module Compat(rnfNoErr, rnfErr, NFData) where
import Prelude() -- do not import Prelude
import Primitives
-- So we can import Compat, which is full of stuff for GHC.

-- Define these here to avoid dragging in Control.DeepSeq
rnfNoErr :: forall a . a -> ()
rnfNoErr = primRnfNoErr

rnfErr :: forall a . a -> ()
rnfErr = primRnfErr

class NFData a

5 changes: 2 additions & 3 deletions src/MicroHs/Compile.hs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import System.IO.MD5
import System.IO.Serialize
import System.IO.TimeMilli
import System.Process
import Control.DeepSeq
import MicroHs.Abstract
import MicroHs.CompileCache
import MicroHs.Desugar
Expand Down Expand Up @@ -173,12 +172,12 @@ compileModule flags impt mn pathfn file = do
liftIO $ putStrLn $ "type checked:\n" ++ showTModule showEDefs tmdl ++ "-----\n"
let
dmdl = desugar flags tmdl
() <- return $ rnf $ bindingsOf dmdl
() <- return $ rnfErr $ bindingsOf dmdl
t4 <- liftIO getTimeMilli

let
cmdl = setBindings [ (i, compileOpt e) | (i, e) <- bindingsOf dmdl ] dmdl
() <- return $ rnf $ bindingsOf cmdl
() <- return $ rnfErr $ bindingsOf cmdl
t5 <- liftIO getTimeMilli

let tParse = t2 - t1
Expand Down
1 change: 0 additions & 1 deletion src/MicroHs/Exp.hs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import MicroHs.Ident
import MicroHs.Expr(Lit(..), showLit)
import MicroHs.List
import Text.PrettyPrint.HughesPJLite
import Control.DeepSeq
import Debug.Trace

type PrimOp = String
Expand Down
2 changes: 1 addition & 1 deletion src/MicroHs/Instances.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
-- See LICENSE file for full license.
module MicroHs.Instances(compiledWithGHC) where
-- For GHC compatibility
import Control.DeepSeq
import MicroHs.CompileCache
import MicroHs.Ident
import MicroHs.Exp
import MicroHs.Expr
import Compat

compiledWithGHC :: Bool
compiledWithGHC = False
Expand Down
1 change: 0 additions & 1 deletion src/MicroHs/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ module MicroHs.Main(main) where
import Data.Char
import Data.List
import Data.Version
import Control.DeepSeq
import Control.Monad
import Control.Applicative
import Data.Maybe
Expand Down

0 comments on commit c5d0e25

Please sign in to comment.