on master help sign in
Better path generation in termination checker

No need to generate paths after we've already found decreasing arguments. This massively speeds up the checker for larger functions.

commit003b68c4c2d6289adb8e6a9ea0a07964d12d8a2a authorEdwin Brady <ecb10@st-andrews.ac.uk> dateSun 28 Aug 2016, 14:57 (10 years ago) parent9997caf
2 files changed+12−3
libs/base/System/Concurrency/Raw.idr−2 src/Idris/Coverage.hs+12−1
libs/base/System/Concurrency/Raw.idr−2
@@ -1,5 +1,3 @@
1−-- WARNING: No guarantees that this works properly yet!
2−
31module System.Concurrency.Raw
42
53-- Raw (i.e. not type safe) message passing
src/Idris/Coverage.hs+12−1
@@ -779,13 +779,24 @@ mkMultiPaths :: IState -> MultiPath -> [SCGEntry] -> [MultiPath]
779779mkMultiPaths ist path [] = [reverse path]
780780mkMultiPaths ist path cg = concatMap extend cg
781781 where extend (nextf, args)
782− | (nextf, args) `elem` path = [ reverse ((nextf, args) : path) ]
782+ | (nextf, args) `inPath` path = [ reverse ((nextf, args) : path) ]
783783 | [Unchecked] <- lookupTotal nextf (tt_ctxt ist)
784784 = case lookupCtxt nextf (idris_callgraph ist) of
785785 [ncg] -> mkMultiPaths ist ((nextf, args) : path) (scg ncg)
786786 _ -> [ reverse ((nextf, args) : path) ]
787787 | otherwise = [ reverse ((nextf, args) : path) ]
788788
789+ inPath :: SCGEntry -> [SCGEntry] -> Bool
790+ inPath f [] = False
791+ inPath f (g : gs) = smallerEq f g || f == g || inPath f gs
792+
793+ smallerEq :: SCGEntry -> SCGEntry -> Bool
794+ smallerEq (f, args) (g, args')
795+ = f == g && not (null (filter smallers args))
796+ && filter smallers args == filter smallers args'
797+ smallers (Just (_, Smaller)) = True
798+ smallers _ = False
799+
789800-- If any route along the multipath leads to infinite descent, we're fine.
790801-- Try a route beginning with every argument.
791802-- If we reach a point we've been to before, but with a smaller value,