comparison 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
comparison
equal deleted inserted replaced
1887:2e6795cc992f 1888:5f478ecf65e4
169 decls : (string * int * con * exp) list 169 decls : (string * int * con * exp) list
170 } 170 }
171 171
172 fun kind (_, k, st) = (k, st) 172 fun kind (_, k, st) = (k, st)
173 173
174 val basis = ref 0
175
174 fun exp ((ks, ts), e as old, st : state) = 176 fun exp ((ks, ts), e as old, st : state) =
175 case e of 177 case e of
176 ELet (eds, e, t) => 178 ELet (eds, e, t) =>
177 let 179 let
178 (*val () = Print.prefaces "Letto" [("e", ElabPrint.p_exp E.empty (old, ErrorMsg.dummySpan))]*) 180 (*val () = Print.prefaces "Letto" [("e", ElabPrint.p_exp E.empty (old, ErrorMsg.dummySpan))]*)
183 let 185 let
184 val e = doSubst' (e, subs) 186 val e = doSubst' (e, subs)
185 in 187 in
186 liftExpInExp (~by) (length subs) e 188 liftExpInExp (~by) (length subs) e
187 end 189 end
190
191 fun functionInside (t : con) =
192 case #1 t of
193 TFun _ => true
194 | CApp ((CModProj (basis', [], "transaction"), _), _) => basis' = !basis
195 | _ => false
196
197 val eds = map (fn ed =>
198 case #1 ed of
199 EDVal ((PVar (x, _), _), t, e) =>
200 if functionInside t then
201 (EDValRec [(x, t, E.liftExpInExp 0 e)], #2 ed)
202 else
203 ed
204 | _ => ed) eds
188 205
189 val (eds, (ts, maxName, ds, subs, by)) = 206 val (eds, (ts, maxName, ds, subs, by)) =
190 ListUtil.foldlMapConcat 207 ListUtil.foldlMapConcat
191 (fn (ed, (ts, maxName, ds, subs, by)) => 208 (fn (ed, (ts, maxName, ds, subs, by)) =>
192 case #1 ed of 209 case #1 ed of
420 let 437 let
421 val (str, st) = doStr (str, st) 438 val (str, st) = doStr (str, st)
422 in 439 in
423 ([(DStr (x, n, sgn, str), loc)], st) 440 ([(DStr (x, n, sgn, str), loc)], st)
424 end 441 end
442 | DFfiStr ("Basis", n, _) => (basis := n; default ())
425 | DFfiStr _ => default () 443 | DFfiStr _ => default ()
426 | DConstraint _ => default () 444 | DConstraint _ => default ()
427 | DExport _ => default () 445 | DExport _ => default ()
428 | DTable _ => default () 446 | DTable _ => default ()
429 | DSequence _ => default () 447 | DSequence _ => default ()