@@ -12,8 +12,6 @@ import qualified Data.Traversable as Traversable
1212import Text.PrettyPrint as P
1313import SourceSyntax.PrettyPrint
1414
15−debug e = {-- liftIO e --} return ()
16−
1715-- Pool
1816-- Holds a bunch of variables
1917-- The rank of each variable is less than or equal to the pool's "maxRank"
@@ -24,7 +22,7 @@ data Pool = Pool {
2422 inhabitants :: [Variable]
2523} deriving Show
2624
27−emptyPool = Pool { maxRank = 0, inhabitants = [] }
25+emptyPool = Pool { maxRank = outermostRank, inhabitants = [] }
2826
2927-- Keeps track of the environment, type variable pool, and a list of errors
3028type SolverState = (Map.Map String Variable, Pool, Int, [IO P.Doc])
@@ -36,7 +34,6 @@ modifyEnv f = modify $ \(env, pool, mark, errors) -> (f env, pool, mark, errors
3634modifyPool f = modify $ \(env, pool, mark, errors) -> (env, f pool, mark, errors)
3735addError message t1 t2 =
3836 modify $ \(env, pool, mark, errors) -> (env, pool, mark, err : errors)
39−
4037 where
4138 wordify = P.fsep . map P.text . words
4239 msg = wordify message
@@ -113,20 +110,16 @@ makeInstance var = do
113110
114111makeCopy :: Int -> Variable -> StateT SolverState IO Variable
115112makeCopy alreadyCopied variable = do
116− debug $ putStr "Copying: "
117113 desc <- liftIO $ UF.descriptor variable
118114 if | mark desc == alreadyCopied ->
119− do debug $ putStrLn "Already Copied"
120115 case copy desc of
121116 Just v -> return v
122117 Nothing -> error "This should be impossible."
123118
124119 | rank desc /= noRank || flex desc == Constant ->
125− do debug $ putStr "did not make a copy: " >> print (mark desc, noRank, flex desc)
126120 return variable
127121
128122 | otherwise -> do
129− debug $ print "no problems!"
130123 pool <- getPool
131124 newVar <- liftIO $ UF.fresh $ Descriptor {
132125 structure = Nothing,
@@ -162,19 +155,13 @@ makeCopy alreadyCopied variable = do
162155
163156restore :: Int -> Variable -> StateT SolverState IO Variable
164157restore alreadyCopied variable = do
165− debug $ putStr "Restoring: "
166158 desc <- liftIO $ UF.descriptor variable
167159 if mark desc /= alreadyCopied
168− then do
169− debug $ putStrLn "not copied, no need to do anything"
170− return variable
160+ then return variable
171161 else do
172− debug $ putStrLn "restoring"
173162 restoredStructure <-
174− case structure desc of
175− Nothing -> return Nothing
176− Just term -> Just <$> traverseTerm (restore alreadyCopied) term
177− debug $ UF.modifyDescriptor variable $ \desc ->
163+ Traversable.traverse (traverseTerm (restore alreadyCopied)) (structure desc)
164+ liftIO $ UF.modifyDescriptor variable $ \desc ->
178165 desc { mark = noMark, rank = noRank, structure = restoredStructure }
179166 return variable
180167