@@ -779,13 +779,24 @@ mkMultiPaths :: IState -> MultiPath -> [SCGEntry] -> [MultiPath]
779mkMultiPaths ist path [] = [reverse path]
779mkMultiPaths ist path [] = [reverse path]
780mkMultiPaths ist path cg = concatMap extend cg
780mkMultiPaths ist path cg = concatMap extend cg
781 where extend (nextf, args)
781 where extend (nextf, args)
782− | (nextf, args) `elem` path = [ reverse ((nextf, args) : path) ]
782+ | (nextf, args) `inPath` path = [ reverse ((nextf, args) : path) ]
783 | [Unchecked] <- lookupTotal nextf (tt_ctxt ist)
783 | [Unchecked] <- lookupTotal nextf (tt_ctxt ist)
784 = case lookupCtxt nextf (idris_callgraph ist) of
784 = case lookupCtxt nextf (idris_callgraph ist) of
785 [ncg] -> mkMultiPaths ist ((nextf, args) : path) (scg ncg)
785 [ncg] -> mkMultiPaths ist ((nextf, args) : path) (scg ncg)
786 _ -> [ reverse ((nextf, args) : path) ]
786 _ -> [ reverse ((nextf, args) : path) ]
787 | otherwise = [ reverse ((nextf, args) : path) ]
787 | otherwise = [ reverse ((nextf, args) : path) ]
789+ inPath :: SCGEntry -> [SCGEntry] -> Bool
791+ inPath f (g : gs) = smallerEq f g || f == g || inPath f gs
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
789-- If any route along the multipath leads to infinite descent, we're fine.
800-- If any route along the multipath leads to infinite descent, we're fine.
790-- Try a route beginning with every argument.
801-- Try a route beginning with every argument.
791-- If we reach a point we've been to before, but with a smaller value,
802-- If we reach a point we've been to before, but with a smaller value,