Skip to content

Commit 92adc32

Browse files
author
Alex McKenna
committed
Store RewriteState in MVars
1 parent 1ab240a commit 92adc32

File tree

14 files changed

+492
-351
lines changed

14 files changed

+492
-351
lines changed

clash-ghc/clash-ghc.cabal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ flag use-ghc-paths
6868
executable clash
6969
Main-Is: src-ghc/Batch.hs
7070
Build-Depends: base, clash-ghc
71-
GHC-Options: -Wall -Wcompat -threaded -rtsopts
71+
GHC-Options: -Wall -Wcompat
7272
if flag(dynamic)
7373
GHC-Options: -dynamic
7474
extra-libraries: pthread

clash-lib/src/Clash/Normalize.hs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import Control.Monad (when)
2424
import Control.Monad.State.Strict (State)
2525
import Data.Default (def)
2626
import Data.Either (lefts,partitionEithers)
27-
import qualified Data.IntMap as IntMap
27+
import qualified Data.HashMap.Strict as HashMap
2828
import Data.List
2929
(intersect, mapAccumL)
3030
import qualified Data.Map as Map
@@ -114,7 +114,7 @@ runNormalization
114114
-> NormalizeSession a
115115
-- ^ NormalizeSession to run
116116
-> IO a
117-
runNormalization env supply globals typeTrans peEval eval rcsMap topEntities session = do
117+
runNormalization env supply globals typeTrans peEval eval rcsMap entities session = do
118118
normState <- NormalizeState
119119
<$> MVar.newMVar emptyVarEnv
120120
<*> MVar.newMVar Map.empty
@@ -123,25 +123,24 @@ runNormalization env supply globals typeTrans peEval eval rcsMap topEntities ses
123123
<*> MVar.newMVar Map.empty
124124
<*> MVar.newMVar rcsMap
125125

126-
runRewriteSession rwEnv (rwState normState) session
126+
rwState <- RewriteState
127+
<$> MVar.newMVar mempty
128+
<*> MVar.newMVar globals
129+
<*> MVar.newMVar supply
130+
<*> MVar.newMVar HashMap.empty
131+
<*> MVar.newMVar 0
132+
<*> MVar.newMVar (mempty, 0)
133+
<*> MVar.newMVar emptyVarEnv
134+
<*> pure normState
135+
136+
runRewriteSession rwEnv rwState session
127137
where
128138
rwEnv = RewriteEnv
129139
{ _clashEnv = env
130140
, _typeTranslator = typeTrans
131141
, _peEvaluator = peEval
132142
, _evaluator = eval
133-
, _topEntities = mkVarSet topEntities
134-
}
135-
136-
rwState s = RewriteState
137-
{ _transformCounters = mempty
138-
, _bindings = globals
139-
, _uniqSupply = supply
140-
, _curFun = (error $ $(curLoc) ++ "Report as bug: no curFun", noSrcSpan)
141-
, _nameCounter = 0
142-
, _globalHeap = (IntMap.empty, 0)
143-
, _workFreeBinders = emptyVarEnv
144-
, _extra = s
143+
, _topEntities = mkVarSet entities
145144
}
146145

147146
normalize
@@ -155,7 +154,8 @@ normalize top = do
155154

156155
normalize' :: Id -> NormalizeSession ([Id], (Id, Binding Term))
157156
normalize' nm = do
158-
exprM <- lookupVarEnv nm <$> Lens.use bindings
157+
bndrsV <- Lens.use bindings
158+
exprM <- MVar.withMVar bndrsV (pure . lookupVarEnv nm)
159159
let nmS = showPpr (varName nm)
160160
case exprM of
161161
Just (Binding nm' sp inl pr tm r) -> do

0 commit comments

Comments
 (0)