@@ -120,6 +120,7 @@ loadIBC reexport fp
120120 ++ "Please clean and rebuild it."
121121 Right archive -> do process reexport archive fp
122122 addImported reexport fp
123+-- dumpTT
123124
124125-- | Load an entire package from its index file
125126loadPkgIndex :: String -> Idris ()
@@ -562,19 +563,28 @@ pDefs reexp ds
562563 updateAlt (DefaultCase t) = do t' <- updateSC t
563564 return (DefaultCase t')
564565
565− update (P t n ty) = do n' <- getSymbol n
566− return $ P t n' ty
567− update (App s f a) = liftM2 (App s) (update f) (update a)
568− update (Bind n b sc) = do b' <- updateB b
569− sc' <- update sc
570− return $ Bind n b' sc'
566+ -- We get a lot of repetition in sub terms and can save a fair chunk
567+ -- of memory if we make sure they're shared. addTT looks for a term
568+ -- and returns it if it exists already, while also keeping stats of
569+ -- how many times a subterm is repeated.
570+ update t = do tm <- addTT t
571+ case tm of
572+ Nothing -> update' t
573+ Just t' -> return t'
574+
575+ update' (P t n ty) = do n' <- getSymbol n
576+ return $ P t n' ty
577+ update' (App s f a) = liftM2 (App s) (update' f) (update' a)
578+ update' (Bind n b sc) = do b' <- updateB b
579+ sc' <- update sc
580+ return $ Bind n b' sc'
571581 where
572− updateB (Let t v) = liftM2 Let (update t) (update v)
573− updateB b = do ty' <- update (binderTy b)
582+ updateB (Let t v) = liftM2 Let (update' t) (update' v)
583+ updateB b = do ty' <- update' (binderTy b)
574584 return (b { binderTy = ty' })
575− update (Proj t i) = do t' <- update t
576− return $ Proj t' i
577− update t = return t
585+ update' (Proj t i) = do t' <- update' t
586+ return $ Proj t' i
587+ update' t = return t
578588
579589pDocs :: [(Name, (Docstring D.DocTerm, [(Name, Docstring D.DocTerm)]))] -> Idris ()
580590pDocs ds = mapM_ (\(n, a) -> addDocStr n (fst a) (snd a)) ds