@@ -120,6 +120,7 @@ loadIBC reexport fp
120 ++ "Please clean and rebuild it."
120 ++ "Please clean and rebuild it."
121 Right archive -> do process reexport archive fp
121 Right archive -> do process reexport archive fp
122 addImported reexport fp
122 addImported reexport fp
124-- | Load an entire package from its index file
125-- | Load an entire package from its index file
125loadPkgIndex :: String -> Idris ()
126loadPkgIndex :: String -> Idris ()
@@ -562,19 +563,28 @@ pDefs reexp ds
562 updateAlt (DefaultCase t) = do t' <- updateSC t
563 updateAlt (DefaultCase t) = do t' <- updateSC t
563 return (DefaultCase t')
564 return (DefaultCase t')
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
572+ Nothing -> update' t
573+ Just t' -> return t'
565− update (P t n ty) = do n' <- getSymbol n
575+ update' (P t n ty) = do n' <- getSymbol n
566− return $ P t n' ty
576+ return $ P t n' ty
567− update (App s f a) = liftM2 (App s) (update f) (update a)
577+ update' (App s f a) = liftM2 (App s) (update' f) (update' a)
568− update (Bind n b sc) = do b' <- updateB b
578+ update' (Bind n b sc) = do b' <- updateB b
569− sc' <- update sc
579+ sc' <- update sc
570− return $ Bind n b' sc'
580+ return $ Bind n b' sc'
572− updateB (Let t v) = liftM2 Let (update t) (update v)
582+ updateB (Let t v) = liftM2 Let (update' t) (update' v)
573− updateB b = do ty' <- update (binderTy b)
583+ updateB b = do ty' <- update' (binderTy b)
574 return (b { binderTy = ty' })
584 return (b { binderTy = ty' })
575− update (Proj t i) = do t' <- update t
585+ update' (Proj t i) = do t' <- update' t
576− return $ Proj t' i
586+ return $ Proj t' i
577− update t = return t
587+ update' t = return t
579pDocs :: [(Name, (Docstring D.DocTerm, [(Name, Docstring D.DocTerm)]))] -> Idris ()
589pDocs :: [(Name, (Docstring D.DocTerm, [(Name, Docstring D.DocTerm)]))] -> Idris ()
580pDocs ds = mapM_ (\(n, a) -> addDocStr n (fst a) (snd a)) ds
590pDocs ds = mapM_ (\(n, a) -> addDocStr n (fst a) (snd a)) ds