changeset 1888:5f478ecf65e4

Identify more local definitions as functions that should be lifted to the top level, which has synergistic effects on inlining later
author Adam Chlipala <adam@chlipala.net>
date Tue, 05 Nov 2013 11:58:52 -0500
parents 2e6795cc992f
children c40ed80be943
files src/unnest.sml tests/localfun.ur
diffstat 2 files changed, 209 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/unnest.sml	Mon Nov 04 16:00:48 2013 -0500
+++ b/src/unnest.sml	Tue Nov 05 11:58:52 2013 -0500
@@ -171,6 +171,8 @@
 
 fun kind (_, k, st) = (k, st)
 
+val basis = ref 0
+
 fun exp ((ks, ts), e as old, st : state) =
     case e of
         ELet (eds, e, t) =>
@@ -186,6 +188,21 @@
                     liftExpInExp (~by) (length subs) e
                 end
 
+            fun functionInside (t : con) =
+                case #1 t of
+                    TFun _ => true
+                  | CApp ((CModProj (basis', [], "transaction"), _), _) => basis' = !basis
+                  | _ => false
+
+            val eds = map (fn ed =>
+                              case #1 ed of
+                                  EDVal ((PVar (x, _), _), t, e) =>
+                                  if functionInside t then
+                                      (EDValRec [(x, t, E.liftExpInExp 0 e)], #2 ed)
+                                  else
+                                      ed
+                                | _ => ed) eds
+
             val (eds, (ts, maxName, ds, subs, by)) =
                 ListUtil.foldlMapConcat
                 (fn (ed, (ts, maxName, ds, subs, by)) =>
@@ -422,6 +439,7 @@
                     in
                         ([(DStr (x, n, sgn, str), loc)], st)
                     end
+                  | DFfiStr ("Basis", n, _) => (basis := n; default ())
                   | DFfiStr _ => default ()
                   | DConstraint _ => default ()
                   | DExport _ => default ()
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/localfun.ur	Tue Nov 05 11:58:52 2013 -0500
@@ -0,0 +1,191 @@
+fun boom s =
+    let
+        val bonk =
+            debug s;
+            debug s;
+            debug s;
+            debug s;
+            debug s;
+            debug s;
+            debug s;
+            debug s;
+            debug s;
+            debug s;
+            debug s;
+            debug s;
+            debug s;
+            debug s;
+            debug s;
+            debug s;
+            debug s;
+            debug s;
+            debug s;
+            debug s;
+            debug s;
+            debug s;
+            debug s;
+            debug s;
+            debug s;
+            debug s;
+            debug s;
+            debug s;
+            debug s;
+            debug s;
+            debug s;
+            debug s;
+            debug s;
+            debug s;
+            debug s;
+            debug s;
+            debug s;
+            debug s;
+            debug s;
+            debug s;
+            debug s;
+            debug s;
+            debug s;
+            debug s;
+            debug s;
+            debug s;
+            debug s;
+            debug s;
+            debug s;
+            debug s;
+            debug s;
+            debug s;
+            debug s;
+            debug s;
+            debug s;
+            debug s;
+            debug s;
+            debug s;
+            debug s
+
+        val boonk = fn () =>
+            debug s;
+            debug s;
+            debug s;
+            debug s;
+            debug s;
+            debug s;
+            debug s;
+            debug s;
+            debug s;
+            debug s;
+            debug s;
+            debug s;
+            debug s;
+            debug s;
+            debug s;
+            debug s;
+            debug s;
+            debug s;
+            debug s;
+            debug s;
+            debug s;
+            debug s;
+            debug s;
+            debug s;
+            debug s;
+            debug s;
+            debug s;
+            debug s;
+            debug s;
+            debug s;
+            debug s;
+            debug s;
+            debug s;
+            debug s;
+            debug s;
+            debug s;
+            debug s;
+            debug s;
+            debug s;
+            debug s;
+            debug s;
+            debug s;
+            debug s;
+            debug s;
+            debug s;
+            debug s;
+            debug s;
+            debug s;
+            debug s;
+            debug s;
+            debug s;
+            debug s;
+            debug s;
+            debug s;
+            debug s;
+            debug s;
+            debug s;
+            debug s;
+            debug s
+
+        fun booonk () =
+            debug s;
+            debug s;
+            debug s;
+            debug s;
+            debug s;
+            debug s;
+            debug s;
+            debug s;
+            debug s;
+            debug s;
+            debug s;
+            debug s;
+            debug s;
+            debug s;
+            debug s;
+            debug s;
+            debug s;
+            debug s;
+            debug s;
+            debug s;
+            debug s;
+            debug s;
+            debug s;
+            debug s;
+            debug s;
+            debug s;
+            debug s;
+            debug s;
+            debug s;
+            debug s;
+            debug s;
+            debug s;
+            debug s;
+            debug s;
+            debug s;
+            debug s;
+            debug s;
+            debug s;
+            debug s;
+            debug s;
+            debug s;
+            debug s;
+            debug s;
+            debug s;
+            debug s;
+            debug s;
+            debug s;
+            debug s;
+            debug s;
+            debug s;
+            debug s;
+            debug s;
+            debug s;
+            debug s;
+            debug s;
+            debug s;
+            debug s;
+            debug s;
+            debug s
+    in
+        bonk; bonk; boonk (); boonk (); booonk (); booonk ()
+    end
+
+fun main () : transaction page =
+    boom "test";
+    return <xml/>