diff src/unnest.sml @ 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 bb942416bf1c
children 403f0cc65b9c
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 ()