@@ -348,6 +348,13 @@ elabClauses info' fc opts n_in cs =
348-- | Find 'static' applications in a term and partially evaluate them.
348-- | Find 'static' applications in a term and partially evaluate them.
349-- Return any new transformation rules
349-- Return any new transformation rules
350elabPE :: ElabInfo -> FC -> Name -> Term -> Idris [(Term, Term)]
350elabPE :: 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 []
351elabPE info fc caller r =
358elabPE info fc caller r =
352 do ist <- getIState
359 do ist <- getIState
353 let sa = filter (\ap -> fst ap /= caller) $ getSpecApps ist [] r
360 let sa = filter (\ap -> fst ap /= caller) $ getSpecApps ist [] r
@@ -399,7 +406,7 @@ elabPE info fc caller r =
399 logElab 3 $ "New name: " ++ show newnm
406 logElab 3 $ "New name: " ++ show newnm
400 logElab 3 $ "PE definition type : " ++ (show specTy)
407 logElab 3 $ "PE definition type : " ++ (show specTy)
401 ++ "\n" ++ show opts
408 ++ "\n" ++ show opts
402− logElab 3 $ "PE definition " ++ show newnm ++ ":\n" ++
409+ logElab 5 $ "PE definition " ++ show newnm ++ ":\n" ++
403 showSep "\n"
410 showSep "\n"
404 (map (\ (lhs, rhs) ->
411 (map (\ (lhs, rhs) ->
405 (showTmImpls lhs ++ " = " ++
412 (showTmImpls lhs ++ " = " ++
@@ -414,7 +421,8 @@ elabPE info fc caller r =
414 PClause fc newnm lhs' [] rhs [])
421 PClause fc newnm lhs' [] rhs [])
415 (pe_clauses specdecl)
422 (pe_clauses specdecl)
416 trans <- elabTransform info fc False rhs lhs
423 trans <- elabTransform info fc False rhs lhs
424+ elabClauses (info {pe_depth = pe_depth info + 1}) fc
417− elabClauses info fc (PEGenerated:opts) newnm def
425+ (PEGenerated:opts) newnm def
418 return [trans]
426 return [trans]
419 else return [])
427 else return [])
420 -- if it doesn't work, just don't specialise. Could happen for lots
428 -- if it doesn't work, just don't specialise. Could happen for lots