@@ -348,6 +348,13 @@ elabClauses info' fc opts n_in cs =
348348-- | Find 'static' applications in a term and partially evaluate them.
349349-- Return any new transformation rules
350350elabPE :: ElabInfo -> FC -> Name -> Term -> Idris [(Term, Term)]
351+-- Don't go deeper than 5 nested partially evaluated definitions in one go
352+-- (make this configurable? It's a good limit for most cases, certainly for
353+-- interfaces and polymorphic definitions, but maybe not for DSLs and
354+-- interpreters in complicated cases.
355+-- Possibly only worry about the limit if we've specialised the same function
356+-- a number of times in one go.)
357+elabPE info fc caller r | pe_depth info > 5 = return []
351358elabPE info fc caller r =
352359 do ist <- getIState
353360 let sa = filter (\ap -> fst ap /= caller) $ getSpecApps ist [] r
@@ -399,7 +406,7 @@ elabPE info fc caller r =
399406 logElab 3 $ "New name: " ++ show newnm
400407 logElab 3 $ "PE definition type : " ++ (show specTy)
401408 ++ "\n" ++ show opts
402− logElab 3 $ "PE definition " ++ show newnm ++ ":\n" ++
409+ logElab 5 $ "PE definition " ++ show newnm ++ ":\n" ++
403410 showSep "\n"
404411 (map (\ (lhs, rhs) ->
405412 (showTmImpls lhs ++ " = " ++
@@ -414,7 +421,8 @@ elabPE info fc caller r =
414421 PClause fc newnm lhs' [] rhs [])
415422 (pe_clauses specdecl)
416423 trans <- elabTransform info fc False rhs lhs
417− elabClauses info fc (PEGenerated:opts) newnm def
424+ elabClauses (info {pe_depth = pe_depth info + 1}) fc
425+ (PEGenerated:opts) newnm def
418426 return [trans]
419427 else return [])
420428 -- if it doesn't work, just don't specialise. Could happen for lots