on master help sign in
When specialising, reduce more names

Specifically, all names which are called by the function being specialised, by searching the call graph. (Maybe we should also reduce inlinable names)

commitb3bf95671621d6e2b0c41a02387114a3b7bba849 authorEdwin Brady <ecb10@st-andrews.ac.uk> dateTue 26 Nov 2013, 20:20 (13 years ago) parent77b1faf
4 files changed+16−11
src/Core/Evaluate.hs+1−1 src/IRTS/Compiler.hs−8 src/Idris/AbsSyntax.hs+12 src/Idris/ElabDecls.hs+3−2
src/Core/Evaluate.hs+1−1
@@ -151,7 +151,7 @@ usable True n ns
151151 case lookup n ls of
152152 Just 0 -> return (False, ns)
153153 Just i -> return (True, ns)
154− _ -> return (True, ns)
154+ _ -> return (False, ns)
155155usable False n ns
156156 = case lookup n ns of
157157 Just 0 -> return (False, ns)
src/IRTS/Compiler.hs−8
@@ -110,14 +110,6 @@ irMain :: TT Name -> Idris LDecl
110110irMain tm = do i <- ir tm
111111 return $ LFun [] (MN 0 "runMain") [] (LForce i)
112112
113−allNames :: [Name] -> Name -> Idris [Name]
114−allNames ns n | n `elem` ns = return []
115−allNames ns n = do i <- getIState
116− case lookupCtxtExact n (idris_callgraph i) of
117− [ns'] -> do more <- mapM (allNames (n:ns)) (map fst (calls ns'))
118− return (nub (n : concat more))
119− _ -> return [n]
120−
121113mkDecls :: Term -> [Name] -> Idris [(Name, LDecl)]
122114mkDecls t used
123115 = do i <- getIState
src/Idris/AbsSyntax.hs+12
@@ -141,6 +141,18 @@ addToCG n cg
141141 = do i <- getIState
142142 putIState $ i { idris_callgraph = addDef n cg (idris_callgraph i) }
143143
144+-- Trace all the names in a call graph starting at the given name
145+getAllNames :: Name -> Idris [Name]
146+getAllNames n = allNames [] n
147+
148+allNames :: [Name] -> Name -> Idris [Name]
149+allNames ns n | n `elem` ns = return []
150+allNames ns n = do i <- getIState
151+ case lookupCtxtExact n (idris_callgraph i) of
152+ [ns'] -> do more <- mapM (allNames (n:ns)) (map fst (calls ns'))
153+ return (nub (n : concat more))
154+ _ -> return [n]
155+
144156addCoercion :: Name -> Idris ()
145157addCoercion n = do i <- getIState
146158 putIState $ i { idris_coercions = nub $ n : idris_coercions i }
src/Idris/ElabDecls.hs+3−2
@@ -803,8 +803,9 @@ elabPE info fc caller r =
803803 logLvl 5 $ show (newnm, map (concreteArg ist) (snd specapp))
804804 idrisCatch
805805 (when (undef && all (concreteArg ist) (snd specapp)) $ do
806− let opts = [Specialise ((n, Nothing) :
807− (mapMaybe specName (snd specapp)))]
806+ cgns <- getAllNames n
807+ let opts = [Specialise (map (\x -> (x, Nothing)) cgns ++
808+ mapMaybe specName (snd specapp))]
808809 logLvl 3 $ "Specialising application: " ++ show specapp
809810 logLvl 2 $ "New name: " ++ show newnm
810811 iLOG $ "PE definition type : " ++ (show specTy)