More inlining, fix issues in eval of case

This commit is contained in:
2025-09-23 20:22:50 -07:00
parent cc7d8b4968
commit 3143fa7b0a
5 changed files with 94 additions and 48 deletions

View File

@@ -143,6 +143,8 @@ complexity (Ref _ _) = 1
complexity (Lam _ _ _ _ sc) = 1 + complexity sc
complexity (App _ t u) = complexity t + complexity u
complexity (Bnd _ _) = 1
-- These turn into a projection
complexity (Case _ sc (CaseCons _ _ t :: Nil)) = 1 + complexity sc + complexity t
complexity _ = 100
processDef : List String FC String List (Raw × Raw) M Unit
@@ -168,12 +170,18 @@ processDef ns fc nm clauses = do
-- TODO - make nf that expands all metas and drop zonk
-- Idris2 doesn't expand metas for performance - a lot of these are dropped during erasure.
-- Day1.newt is a test case
-- NOW - might not need this if we do it at compile time
-- This inlines metas and functions flagged Inline.
tm' <- zonk top 0 Nil tm
debug $ \ _ => "NF\n\{render 80 $ pprint Nil tm'}"
debug $ \ _ => "Add def \{nm} \{render 90 $ pprint Nil tm'} : \{render 90 $ pprint Nil ty}"
updateDef (QN ns nm) fc ty (Fn tm')
if complexity tm' < 10
-- putStrLn "complexity \{show (QN ns nm)} \{show $ complexity tm'}"
-- putStrLn $ show tm'
-- TODO we need some protection against inlining a function calling itself.
-- 14 gets us to 6.21s, higher than 11 breaks Zoo4eg.newt with a unification error (probably need to inline at the end instead)
-- But we need better heuristics, maybe fuel and deciding while inlining.
-- bind is explicit here because the complexity has a 100 in it.
if complexity tm' < 11 || show (QN ns nm) == "Prelude.Prelude.Monad Prelude.IO,bind"
then setFlag (QN ns nm) fc Inline
else pure MkUnit