@@ -397,12 +397,15 @@ elabPE info fc caller r =
397397 [Total _] -> 65536
398398 [Productive] -> 16
399399 _ -> 1
400+ let specnames = mapMaybe (specName (pe_simple specdecl))
401+ (snd specapp)
402+ descs <- mapM getStaticsFrom (map fst specnames)
403+
400404 let opts = [Specialise ((if pe_simple specdecl
401405 then map (\x -> (x, Nothing)) cgns'
402406 else []) ++
403− (n, Just maxred) :
404− mapMaybe (specName (pe_simple specdecl))
405− (snd specapp))]
407+ (n, Just maxred) : specnames ++
408+ concat descs)]
406409 logElab 3 $ "Specialising application: " ++ show specapp
407410 ++ " in " ++ show caller ++
408411 " with " ++ show opts
@@ -443,6 +446,20 @@ elabPE info fc caller r =
443446 | (P Ref n _, _) <- unApply tm = Just (n, Just (if simpl then 1 else 0))
444447 specName simpl _ = Nothing
445448
449+ -- get the descendants of the name 'n' which are marked %static
450+ -- Marking a function %static essentially means it's used to construct
451+ -- programs, so should be evaluated by the partial evaluator
452+ getStaticsFrom :: Name -> Idris [(Name, Maybe Int)]
453+ getStaticsFrom n = do ns <- getAllNames n
454+ i <- getIState
455+ let statics = filter (staticFn i) ns
456+ return (map (\n -> (n, Nothing)) statics)
457+
458+ staticFn :: IState -> Name -> Bool
459+ staticFn i n = case lookupCtxt n (idris_flags i) of
460+ [opts] -> elem StaticFn opts
461+ _ -> False
462+
446463 notStatic ist n = case lookupCtxtExact n (idris_statics ist) of
447464 Just s -> not (or s)
448465 _ -> True