@@ -12,8 +12,6 @@ import qualified Data.Traversable as Traversable
12import Text.PrettyPrint as P
12import Text.PrettyPrint as P
13import SourceSyntax.PrettyPrint
13import SourceSyntax.PrettyPrint
15−debug e = {-- liftIO e --} return ()
18-- Holds a bunch of variables
16-- Holds a bunch of variables
19-- The rank of each variable is less than or equal to the pool's "maxRank"
17-- The rank of each variable is less than or equal to the pool's "maxRank"
@@ -24,7 +22,7 @@ data Pool = Pool {
24 inhabitants :: [Variable]
22 inhabitants :: [Variable]
25} deriving Show
23} deriving Show
27−emptyPool = Pool { maxRank = 0, inhabitants = [] }
25+emptyPool = Pool { maxRank = outermostRank, inhabitants = [] }
29-- Keeps track of the environment, type variable pool, and a list of errors
27-- Keeps track of the environment, type variable pool, and a list of errors
30type SolverState = (Map.Map String Variable, Pool, Int, [IO P.Doc])
28type 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
36modifyPool f = modify $ \(env, pool, mark, errors) -> (env, f pool, mark, errors)
34modifyPool f = modify $ \(env, pool, mark, errors) -> (env, f pool, mark, errors)
37addError message t1 t2 =
35addError message t1 t2 =
38 modify $ \(env, pool, mark, errors) -> (env, pool, mark, err : errors)
36 modify $ \(env, pool, mark, errors) -> (env, pool, mark, err : errors)
41 wordify = P.fsep . map P.text . words
38 wordify = P.fsep . map P.text . words
42 msg = wordify message
39 msg = wordify message
@@ -113,20 +110,16 @@ makeInstance var = do
114makeCopy :: Int -> Variable -> StateT SolverState IO Variable
111makeCopy :: Int -> Variable -> StateT SolverState IO Variable
115makeCopy alreadyCopied variable = do
112makeCopy alreadyCopied variable = do
116− debug $ putStr "Copying: "
117 desc <- liftIO $ UF.descriptor variable
113 desc <- liftIO $ UF.descriptor variable
118 if | mark desc == alreadyCopied ->
114 if | mark desc == alreadyCopied ->
119− do debug $ putStrLn "Already Copied"
120 case copy desc of
115 case copy desc of
121 Just v -> return v
116 Just v -> return v
122 Nothing -> error "This should be impossible."
117 Nothing -> error "This should be impossible."
124 | rank desc /= noRank || flex desc == Constant ->
119 | rank desc /= noRank || flex desc == Constant ->
125− do debug $ putStr "did not make a copy: " >> print (mark desc, noRank, flex desc)
126 return variable
120 return variable
128 | otherwise -> do
122 | otherwise -> do
129− debug $ print "no problems!"
130 pool <- getPool
123 pool <- getPool
131 newVar <- liftIO $ UF.fresh $ Descriptor {
124 newVar <- liftIO $ UF.fresh $ Descriptor {
132 structure = Nothing,
125 structure = Nothing,
@@ -162,19 +155,13 @@ makeCopy alreadyCopied variable = do
163restore :: Int -> Variable -> StateT SolverState IO Variable
156restore :: Int -> Variable -> StateT SolverState IO Variable
164restore alreadyCopied variable = do
157restore alreadyCopied variable = do
165− debug $ putStr "Restoring: "
166 desc <- liftIO $ UF.descriptor variable
158 desc <- liftIO $ UF.descriptor variable
167 if mark desc /= alreadyCopied
159 if mark desc /= alreadyCopied
169− debug $ putStrLn "not copied, no need to do anything"
170− return variable
160+ then return variable
172− debug $ putStrLn "restoring"
173 restoredStructure <-
162 restoredStructure <-
174− case structure desc of
175− Nothing -> return Nothing
176− Just term -> Just <$> traverseTerm (restore alreadyCopied) term
163+ Traversable.traverse (traverseTerm (restore alreadyCopied)) (structure desc)
177− debug $ UF.modifyDescriptor variable $ \desc ->
164+ liftIO $ UF.modifyDescriptor variable $ \desc ->
178 desc { mark = noMark, rank = noRank, structure = restoredStructure }
165 desc { mark = noMark, rank = noRank, structure = restoredStructure }
179 return variable
166 return variable