Home My Page Projects Code Snippets Project Openings SML/NJ
Summary Activity Forums Tracker Lists Tasks Docs Surveys News SCM Files

SCM Repository

[smlnj] Annotation of /sml/trunk/src/compiler/FLINT/opt/fcontract.sml
ViewVC logotype

Annotation of /sml/trunk/src/compiler/FLINT/opt/fcontract.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 213 - (view) (download)

1 : monnier 121 (* copyright 1998 YALE FLINT PROJECT *)
2 : monnier 159 (* monnier@cs.yale.edu *)
3 : monnier 121
4 :     signature FCONTRACT =
5 :     sig
6 :    
7 :     (* needs Collect to be setup properly *)
8 : monnier 213 val contract : FLINT.prog -> FLINT.prog
9 : monnier 121
10 :     end
11 :    
12 :     (* All kinds of beta-reductions. In order to do as much work per pass as
13 :     * possible, the usage counts of each variable (maintained by the Collect
14 :     * module) is kept as much uptodate as possible. For instance as soon as a
15 :     * variable becomes dead, all the variables that were referenced have their
16 :     * usage counts decremented correspondingly. This means that we have to
17 :     * be careful to make sure that a dead variable will indeed not appear
18 :     * in the output lexp since it might else reference other dead variables *)
19 :    
20 : monnier 159 (* things that fcontract does:
21 :     * - several things not mentioned
22 :     * - elimination of Con(Decon x)
23 :     * - update counts when selecting a SWITCH alternative
24 : monnier 162 * - contracting RECORD(R.1,R.2) => R (only if the type is easily available)
25 : monnier 184 * - dropping of dead arguments
26 : monnier 159 *)
27 :    
28 : monnier 121 (* things that lcontract.sml does that fcontract doesn't do (yet):
29 : monnier 159 * - inline across DeBruijn depths (will be solved by named-tvar)
30 : monnier 121 * - elimination of let [dead-vs] = pure in body
31 :     *)
32 :    
33 :     (* things that cpsopt/eta.sml did that fcontract doesn't do:
34 : monnier 159 * - let f vs = select(v,i,g,g vs)
35 : monnier 121 *)
36 :    
37 :     (* things that cpsopt/contract.sml did that fcontract doesn't do:
38 : monnier 159 * - IF-idiom (I still don't know what it is)
39 : monnier 121 * - unifying branches
40 :     * - Handler operations
41 :     * - primops expressions
42 :     * - branch expressions
43 :     *)
44 :    
45 :     (* things that could also be added:
46 : monnier 184 * - elimination of dead vars in let
47 : monnier 191 * - elimination of constant arguments
48 : monnier 121 *)
49 :    
50 :     (* things that would require some type info:
51 :     * - dropping foo in LET vs = RAISE v IN foo
52 :     *)
53 :    
54 :     (* eta-reduction is tricky:
55 :     * - recognition of eta-redexes and introduction of the corresponding
56 :     * substitution in the table has to be done at the very beginning of
57 :     * the processing of the FIX
58 :     * - eta-reduction can turn a known function into an escaping function
59 :     * - fun f (g,v2,v3) = g(g,v2,v3) looks tremendously like an eta-redex
60 :     *)
61 :    
62 :     (* order of contraction is important:
63 :     * - the body of a FIX is contracted before the functions because the
64 :     * functions might end up being inlined in the body in which case they
65 :     * could be contracted twice.
66 :     *)
67 :    
68 :     (* When creating substitution f->g (as happens with eta redexes or with
69 :     * code like `LET [f] = RET[g]'), we need to make sure that the usage cout
70 :     * of f gets properly transfered to g. One way to do that is to make the
71 :     * transfer incremental: each time we apply the substitution, we decrement
72 :     * f's count and increment g's count. But this can be tricky since the
73 :     * elimination of the eta-redex (or the trivial binding) eliminates one of the
74 : monnier 159 * references to g and if this is the only one, we might trigger the killing
75 : monnier 121 * of g even though its count would be later incremented. Similarly, inlining
76 :     * of g would be dangerous as long as some references to f exist.
77 :     * So instead we do the transfer once and for all when we see the eta-redex,
78 :     * which frees us from those two problems but forces us to make sure that
79 :     * every existing reference to f will be substituted with g.
80 :     * Also, the transfer of counts from f to g is not quite straightforward
81 :     * since some of the references to f might be from inside g and without doing
82 :     * the transfer incrementally, we can't easily know which of the usage counts
83 :     * of f should be transfered to the internal counts of g and which to the
84 :     * external counts.
85 :     *)
86 :    
87 : monnier 159 (* Preventing infinite inlining:
88 :     * - inlining a function in its own body amounts to unrolling which has
89 :     * to be controlled (you only want to unroll some number of times).
90 :     * It's currently simply not allowed.
91 :     * - inlining a recursive function outside of tis body amounts to `peeling'
92 :     * one iteration. Here also, since the inlined body will have yet another
93 :     * call, the inlining risks non-termination. It's hence also
94 :     * not allowed.
95 :     * - inlining a mutually recursive function is just a more general form
96 :     * of the problem above although it can be safe and desirable in some cases.
97 :     * To be safe, you simply need that one of the functions forming the
98 :     * mutual-recursion loop cannot be inlined (to break the loop). This cannot
99 :     * be trivially checked. So we (foolishly?) trust the `inline' bit in
100 :     * those cases. This is mostly used to inline wrappers inside the
101 :     * function they wrap.
102 :     * - even if one only allows inlining of funtions showing no sign of
103 :     * recursion, we can be bitten by a program creating its own Y combinator:
104 :     * datatype dt = F of dt -> int -> int
105 :     * let fun f (F g) x = g (F g) x in f (F f) end
106 :     * To solve this problem, `cexp' has an `ifs' parameter containing the set
107 :     * of funtions that we are inlining in order to detect (and break) cycles.
108 :     * - funnily enough, if we allow inlining recursive functions the cycle
109 :     * detection will ensure that the unrolling (or peeling) will only be done
110 :     * once. In the future, maybe.
111 :     *)
112 :    
113 : monnier 184 (* Dropping useless arguments.
114 :     * Arguments whose value is constant (i.e. the function is known and each
115 :     * call site provides the same value for that argument (or the argument
116 :     * itself in the case of recursive calls) can be safely removed and replaced
117 :     * inside the body by a simple let binding. The only problem is that the
118 :     * constant argument might be out of scope at the function definition site.
119 :     * It is obviously always possible to move the function to bring the argument
120 :     * in scope, but since we don't do any code motion here, we're stuck.
121 :     * If it wasn't for this little problem, we could do the cst-arg removal in
122 :     * collect (we don't gain anything from doing it here).
123 :     * The removal of dead arguments (args not used in the body) on the other
124 :     * hand can quite well be done in collect, the only problem being that it
125 :     * is convenient to do it after the cst-arg removal so that we can rely
126 :     * on deadarg to do the actual removal of the cst-arg.
127 :     *)
128 :    
129 : monnier 121 (* Simple inlining (inlining called-once functions, which doesn't require
130 :     * alpha-renaming) seems inoffensive enough but is not always desirable.
131 : monnier 159 * The typical example is wrapper functions introduced by eta-expand: they
132 :     * usually (until inlined) contain the only call to the main function,
133 : monnier 121 * but inlining the main function in the wrapper defeats the purpose of the
134 :     * wrapper.
135 :     * cpsopt dealt with this problem by adding a `NO_INLINE_INTO' hint to the
136 : monnier 159 * wrapper function. In this file, the idea is the following:
137 :     * If you have a function declaration like `let f x = body in exp', first
138 :     * contract `exp' and only contract `body' afterwards. This ensures that
139 :     * the eta-wrapper gets a chance to be inlined before it is (potentially)
140 :     * eta-reduced away. Interesting details:
141 : monnier 121 * - all functions (even the ones that would have a `NO_INLINE_INTO') are
142 :     * contracted, because the "aggressive usage count maintenance" makes any
143 :     * alternative painful (the collect phase has already assumed that dead code
144 :     * will be eliminated, which means that fcontract should at the very least
145 : monnier 159 * do the dead-code elimination, so you can only avoid fcontracting a
146 :     * a function if you can be sure that the body doesn't contain any dead-code,
147 :     * which is generally not known).
148 : monnier 190 * - once a function is fcontracted, its inlinable status is re-examined.
149 :     * More specifically, if no inlining occured during its fcontraction, then
150 :     * we assume that the code has just become smaller and should hence
151 :     * still be considered inlinable. On another hand, if inlining took place,
152 :     * then we have to reset the inline-bit because the new body might
153 :     * be completely different (i.e. much bigger) and inlining it might be
154 :     * undesirable.
155 : monnier 159 * This means that in the case of
156 :     * let fwrap x = body1 and f y = body2 in exp
157 : monnier 190 * if fwrap is fcontracted before f and something gets inlined into it,
158 :     * then fwrap cannot be inlined in f.
159 : monnier 159 * To minimize the impact of this problem, we make sure that we fcontract
160 :     * inlinable functions only after fcontracting other mutually recursive
161 : monnier 190 * functions. One way to solve the problem more thoroughly would be
162 :     * to keep the uncontracted fwrap around until f has been contracted.
163 :     * Such a trick hasn't seemed necessary yet.
164 : monnier 121 * - at the very end of the optimization phase, cpsopt had a special pass
165 :     * that ignored the `NO_INLINE_INTO' hint (since at this stage, inlining
166 :     * into it doesn't have any undesirable side effects any more). The present
167 :     * code doesn't need such a thing. On another hand, the cpsopt approach
168 :     * had the advantage of keeping the `inline' bit from one contract phase to
169 : monnier 159 * the next. If this ends up being important, one could add a global
170 : monnier 121 * "noinline" flag that could be set to true whenever fcontracting an
171 : monnier 159 * inlinable function (this would ensure that fcontracting such an inlinable
172 :     * function can only reduce its size, which would allow keeping the `inline'
173 :     * bit set after fcontracting).
174 : monnier 121 *)
175 :    
176 :     structure FContract :> FCONTRACT =
177 :     struct
178 :     local
179 :     structure F = FLINT
180 :     structure M = IntmapF
181 : monnier 159 structure S = IntSetF
182 : monnier 121 structure C = Collect
183 : monnier 184 structure O = Option
184 : monnier 121 structure DI = DebIndex
185 :     structure PP = PPFlint
186 : monnier 159 structure FU = FlintUtil
187 :     structure LT = LtyExtern
188 : monnier 200 structure LK = LtyKernel
189 : monnier 163 structure OU = OptUtils
190 : monnier 202 structure PO = PrimOp
191 : monnier 159 structure CTRL = Control.FLINT
192 : monnier 121 in
193 :    
194 :     val say = Control.Print.say
195 :     fun bug msg = ErrorMsg.impossible ("FContract: "^msg)
196 :     fun buglexp (msg,le) = (say "\n"; PP.printLexp le; bug msg)
197 :     fun bugval (msg,v) = (say "\n"; PP.printSval v; bug msg)
198 :    
199 :     (* fun sayexn e = app say (map (fn s => s^" <- ") (SMLofNJ.exnHistory e)) *)
200 :    
201 : monnier 159 val cplv = LambdaVar.dupLvar
202 : monnier 200 val mklv = LambdaVar.mkLvar
203 : monnier 121
204 :     datatype sval
205 :     = Val of F.value (* F.value should never be F.VAR lv *)
206 : monnier 202 | Fun of F.lvar * F.lexp * (F.lvar * F.lty) list * F.fkind * sval list list ref
207 : monnier 197 | TFun of F.lvar * F.lexp * (F.tvar * F.tkind) list
208 : monnier 189 | Record of F.lvar * sval list
209 :     | Con of F.lvar * sval * F.dcon * F.tyc list
210 :     | Decon of F.lvar * sval * F.dcon * F.tyc list
211 :     | Select of F.lvar * sval * int
212 : monnier 121 | Var of F.lvar * F.lty option (* cop out case *)
213 :    
214 : monnier 159 fun sval2lty (Var(_,x)) = x
215 :     | sval2lty (Decon(_,_,(_,_,lty),tycs)) =
216 :     SOME(hd(#2 (LT.ltd_arrow (hd(LT.lt_inst(lty, tycs))))))
217 : monnier 199 | sval2lty (Select(_,sv,i)) =
218 :     (case sval2lty sv of SOME lty => SOME(LT.lt_select(lty, i)) | _ => NONE)
219 : monnier 159 | sval2lty _ = NONE
220 : monnier 121
221 : monnier 159 fun tycs_eq ([],[]) = true
222 :     | tycs_eq (tyc1::tycs1,tyc2::tycs2) =
223 :     LT.tc_eqv(tyc1,tyc2) andalso tycs_eq(tycs1,tycs2)
224 :     | tycs_eq _ = false
225 : monnier 121
226 : monnier 200 (* calls `code' to append a lexp to each leaf of `le'.
227 :     * Typically used to transform `let lvs = le in code' so that
228 :     * `code' is now copied at the end of each branch of `le'.
229 :     * `lvs' is a list of lvars that should be used if the result of `le'
230 :     * needs to be bound before calling `code'. *)
231 :     fun append lvs code le =
232 :     let fun l (F.RET vs) = code vs
233 :     | l (le as (F.APP _ | F.TAPP _ | F.RAISE _ | F.HANDLE _)) =
234 :     let val lvs = map (fn lv => let val nlv = cplv lv
235 :     in C.new NONE nlv; nlv end)
236 :     lvs
237 :     in F.LET(lvs, le, code(map F.VAR lvs))
238 :     end
239 :     | l (F.LET (lvs,body,le)) = F.LET(lvs,body, l le)
240 :     | l (F.FIX (fdecs,le)) = F.FIX(fdecs, l le)
241 :     | l (F.TFN (tfdec,le)) = F.TFN(tfdec, l le)
242 :     | l (F.SWITCH (v,ac,arms,def)) =
243 :     let fun larm (con,le) = (con, l le)
244 :     in F.SWITCH(v, ac, map larm arms, O.map l def)
245 :     end
246 :     | l (F.CON (dc,tycs,v,lv,le)) = F.CON(dc, tycs, v, lv, l le)
247 :     | l (F.RECORD (rk,vs,lv,le)) = F.RECORD(rk, vs, lv, l le)
248 :     | l (F.SELECT (v,i,lv,le)) = F.SELECT(v, i, lv, l le)
249 :     | l (F.BRANCH (po,vs,le1,le2)) = F.BRANCH(po, vs, l le1, l le2)
250 :     | l (F.PRIMOP (po,vs,lv,le)) = F.PRIMOP(po, vs, lv, l le)
251 :     in l le
252 :     end
253 :    
254 : monnier 201 (* `extract' extracts the code of a switch arm into a function
255 :     * and replaces it with a call to that function *)
256 :     fun extract (con,le) =
257 :     let val f = mklv()
258 :     val fk = {isrec=NONE,known=true,inline=F.IH_SAFE,
259 :     cconv=F.CC_FUN(LK.FF_FIXED)}
260 :     in case con of
261 :     F.DATAcon(dc as (_,_,lty),tycs,lv) =>
262 :     let val nlv = cplv lv
263 :     val _ = C.new (SOME[lv]) f
264 :     val _ = C.use NONE (C.new NONE nlv)
265 :     val (lty,_) = LT.ltd_parrow(hd(LT.lt_inst(lty, tycs)))
266 :     in ((F.DATAcon(dc, tycs, nlv),
267 :     F.APP(F.VAR f, [F.VAR nlv])),
268 :     (fk, f, [(lv, lty)], le))
269 :     end
270 :     | con =>
271 :     let val _ = C.new (SOME[]) f
272 :     in ((con, F.APP(F.VAR f, [])),
273 :     (fk, f, [], le))
274 :     end
275 :     end
276 :    
277 : monnier 202 fun inScope m lv = (M.lookup m lv; true) handle M.IntmapF => false
278 :    
279 : monnier 213 fun click s c = (if !CTRL.misc = 1 then say s else ();
280 :     c := !c + 1 (* Stats.addCounter c 1 *) )
281 : monnier 185
282 : monnier 213 fun contract (fdec as (_,f,_,_)) = let
283 : monnier 185
284 : monnier 213 val c_dummy = ref 0 (* Stats.newCounter[] *)
285 :     val c_miss = ref 0 (* Stats.newCounter[] *)
286 : monnier 189
287 : monnier 213 val counter = c_dummy
288 : monnier 189
289 :     fun click_deadval () = (click "d" counter)
290 :     fun click_deadlexp () = (click "D" counter)
291 :     fun click_select () = (click "s" counter)
292 :     fun click_record () = (click "r" counter)
293 :     fun click_con () = (click "c" counter)
294 :     fun click_switch () = (click "s" counter)
295 :     fun click_eta () = (click "e" counter)
296 :     fun click_etasplit () = (click "E" counter)
297 :     fun click_branch () = (click "b" counter)
298 :     fun click_dropargs () = (click "a" counter)
299 :    
300 :     fun click_lacktype () = (click "t" c_miss)
301 :    
302 :     (* this counters is actually *used* by fcontract.
303 :     * It's not used just for statistics. *)
304 : monnier 213 val c_inline = ref 0 (* Stats.newCounter[counter] *)
305 : monnier 189 fun click_simpleinline () = (click "i" c_inline)
306 :     fun click_copyinline () = (click "I" c_inline)
307 :     fun click_unroll () = (click "u" c_inline)
308 : monnier 213 fun inline_count () = (* Stats.getCounter *) !c_inline
309 : monnier 189
310 : monnier 186 fun used lv = (C.usenb(C.get lv) > 0)
311 : monnier 199 (* handle x =>
312 : monnier 186 (say("while in FContract.used "^(C.LVarString lv)^"\n");
313 : monnier 199 raise x) *)
314 : monnier 121
315 :     fun eqConV (F.INTcon i1, F.INT i2) = i1 = i2
316 :     | eqConV (F.INT32con i1, F.INT32 i2) = i1 = i2
317 :     | eqConV (F.WORDcon i1, F.WORD i2) = i1 = i2
318 :     | eqConV (F.WORD32con i1, F.WORD32 i2) = i1 = i2
319 :     | eqConV (F.REALcon r1, F.REAL r2) = r1 = r2
320 :     | eqConV (F.STRINGcon s1, F.STRING s2) = s1 = s2
321 :     | eqConV (con,v) = bugval("unexpected comparison with val", v)
322 :    
323 :     fun lookup m lv = (M.lookup m lv)
324 : monnier 202 handle e as M.IntmapF =>
325 : monnier 121 (say "\nlooking up unbound ";
326 :     say (!PP.LVarString lv);
327 : monnier 202 raise e)
328 : monnier 121
329 :     fun sval2val sv =
330 :     case sv
331 : monnier 159 of (Fun{1=lv,...} | TFun{1=lv,...} | Record{1=lv,...} | Decon{1=lv,...}
332 : monnier 121 | Con{1=lv,...} | Select{1=lv,...} | Var{1=lv,...}) => F.VAR lv
333 :     | Val v => v
334 :    
335 : monnier 163 fun val2sval m (F.VAR ov) =
336 : monnier 199 ((lookup m ov) (* handle x =>
337 :     (say("val2sval "^(C.LVarString ov)^"\n"); raise x) *) )
338 : monnier 121 | val2sval m v = Val v
339 :    
340 :     fun bugsv (msg,sv) = bugval(msg, sval2val sv)
341 :    
342 :     fun subst m ov = sval2val (lookup m ov)
343 : monnier 199 fun substval m = sval2val o (val2sval m)
344 :     fun substvar m lv =
345 :     case substval m (F.VAR lv)
346 : monnier 121 of F.VAR lv => lv
347 :     | v => bugval ("unexpected val", v)
348 :    
349 :     (* called when a variable becomes dead.
350 :     * it simply adjusts the use-counts *)
351 :     fun undertake m lv =
352 :     let val undertake = undertake m
353 :     in case lookup m lv
354 : monnier 186 of Var {1=nlv,...} => ()
355 : monnier 121 | Val v => ()
356 : monnier 202 | Fun (lv,le,args,_,_) =>
357 : monnier 187 C.unuselexp undertake
358 :     (F.LET(map #1 args,
359 :     F.RET (map (fn _ => F.INT 0) args),
360 :     le))
361 :     | TFun{1=lv,2=le,...} =>
362 :     C.unuselexp undertake le
363 : monnier 189 | (Select {2=sv,...} | Con {2=sv,...}) => unusesval m sv
364 :     | Record {2=svs,...} => app (unusesval m) svs
365 : monnier 159 (* decon's are implicit so we can't get rid of them *)
366 :     | Decon _ => ()
367 : monnier 121 end
368 :     handle M.IntmapF =>
369 : monnier 186 (say("Unable to undertake "^(C.LVarString lv)^"\n"))
370 : monnier 121 | x =>
371 : monnier 186 (say("while undertaking "^(C.LVarString lv)^"\n"); raise x)
372 : monnier 121
373 : monnier 189 and unusesval m sv = unuseval m (sval2val sv)
374 : monnier 187 and unuseval m (F.VAR lv) =
375 :     if (C.unuse false (C.get lv)) then undertake m lv else ()
376 :     | unuseval f _ = ()
377 :     fun unusecall m lv =
378 :     if (C.unuse true (C.get lv)) then undertake m lv else ()
379 :    
380 :    
381 : monnier 121 fun addbind (m,lv,sv) = M.add(m, lv, sv)
382 :    
383 : monnier 164 (* substitute a value sv for a variable lv and unuse value v. *)
384 : monnier 121 fun substitute (m, lv1, sv, v) =
385 :     (case sval2val sv of F.VAR lv2 => C.transfer(lv1,lv2) | v2 => ();
386 : monnier 187 unuseval m v;
387 : monnier 199 addbind(m, lv1, sv)) (* handle x =>
388 : monnier 186 (say ("while substituting "^
389 : monnier 164 (C.LVarString lv1)^
390 :     " -> ");
391 : monnier 121 PP.printSval (sval2val sv);
392 : monnier 199 raise x) *)
393 : monnier 121
394 :     (* common code for primops *)
395 : monnier 199 fun cpo m (SOME{default,table},po,lty,tycs) =
396 :     (SOME{default=substvar m default,
397 :     table=map (fn (tycs,lv) => (tycs, substvar m lv)) table},
398 : monnier 121 po,lty,tycs)
399 : monnier 199 | cpo _ po = po
400 : monnier 121
401 : monnier 199 fun cdcon m (s,Access.EXN(Access.LVAR lv),lty) =
402 :     (s, Access.EXN(Access.LVAR(substvar m lv)), lty)
403 :     | cdcon _ dc = dc
404 : monnier 121
405 : monnier 201 (* ifs (inlined functions): records which functions we're currently inlining
406 : monnier 199 * in order to detect loops
407 :     * m: is a map lvars to their defining expressions (svals) *)
408 : monnier 201 fun fcexp ifs m le cont = let
409 :     val loop = fcexp ifs
410 : monnier 199 val substval = substval m
411 :     val cdcon = cdcon m
412 :     val cpo = cpo m
413 : monnier 163
414 : monnier 201 fun fcLet (lvs,le,body) =
415 :     loop m le
416 :     (fn (nm,nle) =>
417 :     let fun cbody () =
418 :     let val nm = (foldl (fn (lv,m) =>
419 :     addbind(m, lv, Var(lv, NONE)))
420 :     nm lvs)
421 :     in case loop nm body cont
422 :     of F.RET vs => if vs = (map F.VAR lvs) then nle
423 :     else F.LET(lvs, nle, F.RET vs)
424 :     | nbody => F.LET(lvs, nle, nbody)
425 :     end
426 :     in case nle
427 :     of F.RET vs =>
428 :     let fun simplesubst (lv,v,m) =
429 :     let val sv = val2sval m v
430 :     in substitute(m, lv, sv, sval2val sv)
431 :     end
432 :     val nm = (ListPair.foldl simplesubst nm (lvs, vs))
433 :     in loop nm body cont
434 :     end
435 :     | F.TAPP _ =>
436 :     if List.all (C.dead o C.get) lvs
437 :     then loop nm body cont
438 :     else cbody()
439 :     | (F.BRANCH _ | F.SWITCH _) =>
440 :     (* this is a hack originally meant to cleanup the BRANCH
441 :     * mess introduced in flintnm (where each branch returns
442 :     * just true or false which is generally only used as
443 :     * input to a SWITCH).
444 :     * The present code does more than clean up this case.
445 :     * It has one serious shortcoming: it ends up making
446 :     * three fcontract passes through the same code (plus
447 :     * one cheap traversal). *)
448 :     let fun cassoc (lv,F.SWITCH(F.VAR v,ac,arms,NONE),wrap) =
449 :     if lv <> v orelse C.usenb(C.get lv) > 1
450 :     then cbody() else
451 :     let val (narms,fdecs) =
452 :     ListPair.unzip (map extract arms)
453 :     fun addswitch [v] =
454 :     C.copylexp
455 :     IntmapF.empty
456 :     (F.SWITCH(v,ac,narms,NONE))
457 :     | addswitch _ = bug "prob in addswitch"
458 :     (* replace each leaf `ret' with a copy
459 :     * of the switch *)
460 :     val nle = append [lv] addswitch nle
461 :     (* decorate with the functions extracted
462 :     * from the switch arms *)
463 :     val nle =
464 :     foldl (fn (f,le) => F.FIX([f],le))
465 :     (wrap nle) fdecs
466 :     (* Ugly hack: force one more traversal *)
467 :     val nle = loop nm nle #2
468 :     in click_branch();
469 :     loop nm nle cont
470 :     end
471 :     | cassoc _ = cbody()
472 :     in case (lvs,body)
473 :     of ([lv],le as F.SWITCH _) =>
474 :     cassoc(lv, le, fn x => x)
475 :     | ([lv],F.LET(lvs,le as F.SWITCH _,rest)) =>
476 :     cassoc(lv, le, fn le => F.LET(lvs,le,rest))
477 :     | _ => cbody()
478 :     end
479 :     | _ => cbody()
480 :     end)
481 : monnier 200
482 : monnier 201 fun fcFix (fs,le) =
483 : monnier 202 let (* merge actual arguments to extract the constant subpart *)
484 :     fun merge_actuals ((lv,lty),[],m) = addbind(m, lv, Var(lv, SOME lty))
485 :     | merge_actuals ((lv,lty),a::bs,m) = addbind(m, lv, Var(lv, SOME lty))
486 :     (* FIXME: there's a bug here, but it's not caught by chkflint
487 :     let fun f (b::bs) =
488 :     if sval2val a = sval2val b then f bs
489 :     else addbind(m, lv, Var(lv, SOME lty))
490 :     | f [] =
491 :     (click "C" c_cstarg;
492 :     case sval2val a
493 :     of v as F.VAR lv' =>
494 :     (* FIXME: this inScope check is wrong for non-recursive
495 :     * functions. But it only matters if the function is
496 :     * passed itself as a parameter which cannot happen
497 :     * with the current type system I believe. *)
498 :     if inScope m lv' then
499 :     let val sv =
500 :     case a of Var (v,NONE) => Var(v, SOME lty)
501 :     | _ => a
502 :     in substitute(m, lv, sv, v)
503 :     end
504 :     else (click "O" c_outofscope;
505 :    
506 :     addbind(m, lv, Var(lv, SOME lty)))
507 :     | v => substitute(m, lv, a, v))
508 :     in f bs
509 :     end *)
510 :     (* The actual function contraction *)
511 : monnier 203 fun fcFun ((f,body,args,fk as {inline,cconv,known,isrec},actuals),
512 :     (m,fs)) =
513 : monnier 201 let val fi = C.get f
514 : monnier 203 in if C.dead fi then (m,fs)
515 : monnier 201 else if C.iusenb fi = C.usenb fi then
516 :     (* we need to be careful that undertake not be called
517 :     * recursively *)
518 : monnier 203 (C.use NONE fi; undertake m f; (m,fs))
519 : monnier 201 else
520 : monnier 213 let (* val _ = say ("\nEntering "^(C.LVarString f)) *)
521 : monnier 201 val saved_ic = inline_count()
522 :     (* make up the bindings for args inside the body *)
523 : monnier 202 val actuals = if isSome isrec orelse
524 :     C.escaping fi orelse
525 :     null(!actuals)
526 :     then map (fn _ => []) args
527 :     else OU.transpose(!actuals)
528 :     val nm = ListPair.foldl merge_actuals m (args, actuals)
529 : monnier 201 (* contract the body and create the resulting fundec *)
530 :     val nbody = fcexp (S.add(f, ifs)) nm body #2
531 :     (* if inlining took place, the body might be completely
532 :     * changed (read: bigger), so we have to reset the
533 :     * `inline' bit *)
534 :     val nfk = {isrec=isrec, cconv=cconv,
535 :     known=known orelse not(C.escaping fi),
536 :     inline=if inline_count() = saved_ic
537 :     then inline
538 :     else F.IH_SAFE}
539 :     (* update the binding in the map. This step is
540 :     * not just a mere optimization but is necessary
541 :     * because if we don't do it and the function
542 :     * gets inlined afterwards, the counts will reflect the
543 :     * new contracted code while we'll be working on the
544 :     * the old uncontracted code *)
545 : monnier 203 val nm = addbind(m, f, Fun(f, nbody, args, nfk, ref []))
546 :     in (nm, (nfk, f, args, nbody)::fs)
547 : monnier 213 (* before say ("\nExiting "^(C.LVarString f)) *)
548 : monnier 201 end
549 :     end
550 :    
551 :     (* check for eta redex *)
552 : monnier 202 fun fcEta (fdec as (f,F.APP(F.VAR g,vs),args,_,_),(m,fs,hs)) =
553 : monnier 201 if List.length args = List.length vs andalso
554 :     OU.ListPair_all (fn (v,(lv,t)) =>
555 :     case v of F.VAR v => v = lv andalso lv <> g
556 :     | _ => false)
557 :     (vs, args)
558 :     then
559 :     let val svg = lookup m g
560 :     val g = case sval2val svg
561 :     of F.VAR g => g
562 :     | v => bugval("not a variable", v)
563 :     (* NOTE: we don't want to turn a known function into an
564 :     * escaping one. It's dangerous for optimisations based
565 :     * on known functions (elimination of dead args, f.ex)
566 :     * and could generate cases where call>use in collect *)
567 :     in if (C.escaping(C.get f)) andalso not(C.escaping(C.get g))
568 :     (* the default case could ensure the inline *)
569 :     then (m, fdec::fs, hs)
570 :     else let
571 :     (* if an earlier function h has been eta-reduced
572 :     * to f, we have to be careful to update its
573 :     * binding to not refer to f any more since f
574 :     * will disappear *)
575 :     val nm = foldl (fn (h,m) =>
576 :     if sval2val(lookup m h) = F.VAR f
577 :     then addbind(m, h, svg) else m)
578 :     m hs
579 :     in
580 :     (* I could almost reuse `substitute' but the
581 :     * unuse in substitute assumes the val is escaping *)
582 :     click_eta();
583 :     C.transfer(f, g);
584 :     unusecall m g;
585 :     (addbind(m, f, svg), fs, f::hs)
586 :     end
587 : monnier 189 end
588 : monnier 201 else (m, fdec::fs, hs)
589 :     | fcEta (fdec,(m,fs,hs)) = (m,fdec::fs,hs)
590 :    
591 :     (* add wrapper for various purposes *)
592 :     fun wrap (f as ({inline=F.IH_ALWAYS,...},_,_,_):F.fundec,fs) = f::fs
593 :     | wrap (f as (fk as {isrec,...},g,args,body):F.fundec,fs) =
594 :     let val gi = C.get g
595 :     fun dropargs filter =
596 :     let val (nfk,nfk') = OU.fk_wrap(fk, O.map #1 isrec)
597 :     val args' = filter args
598 :     val ng = cplv g
599 :     val nargs = map (fn (v,t) => (cplv v, t)) args
600 :     val nargs' = map #1 (filter nargs)
601 :     val appargs = (map F.VAR nargs')
602 :     val nf = (nfk, g, nargs, F.APP(F.VAR ng, appargs))
603 :     val nf' = (nfk', ng, args', body)
604 :    
605 :     val ngi = C.new (SOME(map #1 args')) ng
606 :     in
607 :     C.ireset gi;
608 :     app (ignore o (C.new NONE) o #1) nargs;
609 :     C.use (SOME appargs) ngi;
610 :     app (C.use NONE o C.get) nargs';
611 :     nf'::nf::fs
612 : monnier 121 end
613 : monnier 201 in
614 :     (* Don't introduce wrappers for escaping-only functions.
615 :     * This is debatable since although wrappers are useless
616 :     * on escaping-only functions, some of the escaping uses
617 :     * might turn into calls in the course of fcontract, so
618 :     * by not introducing wrappers here, we avoid useless work
619 :     * but we also postpone useful work to later invocations. *)
620 :     if C.dead gi then fs else
621 :     let val used = map (used o #1) args
622 :     in if C.called gi then
623 :     (* if some args are not used, let's drop them *)
624 :     if not (List.all (fn x => x) used) then
625 :     (click_dropargs();
626 : monnier 203 dropargs (fn xs => OU.filter used xs))
627 : monnier 190
628 : monnier 201 (* eta-split: add a wrapper for escaping uses *)
629 :     else if C.escaping gi then
630 :     (* like dropargs but keeping all args *)
631 :     (click_etasplit(); dropargs (fn x => x))
632 :    
633 :     else f::fs
634 :     else f::fs
635 :     end
636 :     end
637 :    
638 :     (* add various wrappers *)
639 :     val fs = foldl wrap [] fs
640 :    
641 :     (* register the new bindings (uncontracted for now) *)
642 : monnier 202 val (nm,fs) = foldl (fn (fdec as (fk,f,args,body),(m,fs)) =>
643 :     let val nf = (f, body, args, fk, ref [])
644 :     in (addbind(m, f, Fun nf), nf::fs) end)
645 :     (m,[]) fs
646 : monnier 201 (* check for eta redexes *)
647 :     val (nm,fs,_) = foldl fcEta (nm,[],[]) fs
648 :    
649 : monnier 204 val (wrappers,funs) =
650 : monnier 202 List.partition (fn (_,_,_,{inline=F.IH_ALWAYS,...},_) => true
651 : monnier 201 | _ => false) fs
652 : monnier 204 val (maybes,funs) =
653 : monnier 203 List.partition (fn (_,_,_,{inline=F.IH_MAYBE _,...},_) => true
654 :     | _ => false) funs
655 : monnier 213
656 : monnier 204 (* First contract the big inlinable functions. This might make them
657 :     * non-inlinable and we'd rather know that before we inline them.
658 :     * Then we inline the body (so that we won't go through the inline-once
659 :     * functions twice), then the normal functions and finally the wrappers
660 :     * (which need to come last to make sure that they get inlined if
661 :     * at all possible) *)
662 :     val fs = []
663 :     val (nm,fs) = foldl fcFun (nm,fs) maybes
664 : monnier 201 val nle = loop nm le cont
665 : monnier 203 val (nm,fs) = foldl fcFun (nm,fs) funs
666 :     val (nm,fs) = foldl fcFun (nm,fs) wrappers
667 : monnier 201 (* junk newly unused funs *)
668 :     val fs = List.filter (used o #2) fs
669 :     in
670 :     case fs
671 :     of [] => nle
672 :     | [f1 as ({isrec=NONE,...},_,_,_),f2] =>
673 :     (* gross hack: `wrap' might have added a second
674 :     * non-recursive function. we need to split them into
675 : monnier 203 * 2 FIXes. This is _very_ ad-hoc. *)
676 : monnier 204 F.FIX([f2], F.FIX([f1], nle))
677 : monnier 201 | _ => F.FIX(fs, nle)
678 :     end
679 : monnier 163
680 : monnier 201 fun fcApp (f,vs) =
681 : monnier 202 let val svs = map (val2sval m) vs
682 : monnier 201 val svf = val2sval m f
683 :     (* F.APP inlining (if any) *)
684 : monnier 202
685 : monnier 201 in case svf
686 : monnier 202 of Fun(g,body,args,{inline,...},actuals) =>
687 :     let val gi = C.get g
688 :     fun noinline () =
689 :     (actuals := svs :: (!actuals);
690 :     cont(m,F.APP(sval2val svf, map sval2val svs)))
691 :     fun simpleinline () =
692 :     (* simple inlining: we should copy the body and then
693 :     * kill the function, but instead we just move the body
694 :     * and kill only the function name.
695 :     * This inlining strategy looks inoffensive enough,
696 :     * but still requires some care: see comments at the
697 :     * begining of this file and in cfun *)
698 : monnier 213 (click_simpleinline();
699 : monnier 202 ignore(C.unuse true gi);
700 :     loop m (F.LET(map #1 args, F.RET vs, body)) cont)
701 :     fun copyinline () =
702 :     (* aggressive inlining. We allow pretty much
703 :     * any inlinling, but we detect and reject inlining
704 :     * recursively which would else lead to infinite loop *)
705 :     (* unrolling is not as straightforward as it seems:
706 :     * if you inline the function you're currently
707 :     * fcontracting, you're asking for trouble: there is a
708 :     * hidden assumption in the counting that the old code
709 :     * will be replaced by the new code (and is hence dead).
710 :     * If the function to be unrolled has the only call to
711 :     * function f, then f might get simpleinlined before
712 :     * unrolling, which means that unrolling will introduce
713 :     * a second occurence of the `only call' but at that point
714 :     * f has already been killed. *)
715 :     let val nle = (F.LET(map #1 args, F.RET vs, body))
716 :     val nle = C.copylexp M.empty nle
717 :     in
718 :     click_copyinline();
719 :     (app (unuseval m) vs);
720 :     unusecall m g;
721 :     fcexp (S.add(g, ifs)) m nle cont
722 :     end
723 :    
724 :     in if C.usenb gi = 1 andalso not(S.member ifs g) then simpleinline()
725 :     else case inline of
726 :     F.IH_SAFE => noinline()
727 :     | F.IH_UNROLL => noinline()
728 :     | F.IH_ALWAYS =>
729 :     if S.member ifs g then noinline() else copyinline()
730 :     | F.IH_MAYBE(min,ws) =>
731 :     if S.member ifs g then noinline() else let
732 :     fun value w _ (Val _ | Con _ | Record _) = w
733 :     | value w v (Fun (f,_,args,_,_)) =
734 :     if C.usenb(C.get v) = 1 then w * 2 else w
735 :     | value w _ _ = 0
736 :     val s = (OU.foldl3 (fn (sv,w,(v,t),s) => value w v sv + s)
737 :     0 (svs,ws,args))
738 :     handle OU.Unbalanced => 0
739 :     in if s > min then copyinline() else noinline()
740 :     end
741 :     end
742 :     | sv => cont(m,F.APP(sval2val svf, map sval2val svs))
743 : monnier 201 end
744 : monnier 184
745 : monnier 201 fun fcTfn ((f,args,body),le) =
746 :     let val fi = C.get f
747 :     in if C.dead fi then (click_deadlexp(); loop m le cont) else
748 :     let val nbody = fcexp ifs m body #2
749 :     val nm = addbind(m, f, TFun(f, nbody, args))
750 : monnier 184 val nle = loop nm le cont
751 : monnier 121 in
752 : monnier 201 if C.dead fi then nle else F.TFN((f, args, nbody), nle)
753 : monnier 121 end
754 : monnier 201 end
755 :    
756 :     fun fcSwitch (v,ac,arms,def) =
757 :     let fun fcsCon (lvc,svc,dc1:F.dcon,tycs1) =
758 :     let fun killle le = C.unuselexp (undertake m) le
759 :     fun kill lv le =
760 :     C.unuselexp (undertake (addbind(m,lv,Var(lv,NONE)))) le
761 :     fun killarm (F.DATAcon(_,_,lv),le) = kill lv le
762 :     | killarm _ = buglexp("bad arm in switch(con)", le)
763 :    
764 :     fun carm ((F.DATAcon(dc2,tycs2,lv),le)::tl) =
765 :     (* sometimes lty1 <> lty2 :-( so this doesn't work:
766 :     * FU.dcon_eq(dc1, dc2) andalso tycs_eq(tycs1,tycs2) *)
767 :     if #2 dc1 = #2 (cdcon dc2) then
768 :     (map killarm tl; (* kill the rest *)
769 :     O.map killle def; (* and the default case *)
770 :     loop (substitute(m, lv, svc, F.VAR lvc))
771 :     le cont)
772 :     else
773 :     (* kill this arm and continue with the rest *)
774 :     (kill lv le; carm tl)
775 :     | carm [] = loop m (O.valOf def) cont
776 :     | carm _ = buglexp("unexpected arm in switch(con,...)", le)
777 :     in click_switch(); carm arms
778 : monnier 186 end
779 : monnier 121
780 : monnier 201 fun fcsVal v =
781 :     let fun kill le = C.unuselexp (undertake m) le
782 :     fun carm ((con,le)::tl) =
783 :     if eqConV(con, v) then
784 :     (map (kill o #2) tl;
785 :     O.map kill def;
786 :     loop m le cont)
787 :     else (kill le; carm tl)
788 :     | carm [] = loop m (O.valOf def) cont
789 :     in click_switch(); carm arms
790 :     end
791 :    
792 :     fun fcsDefault (sv,lvc) =
793 :     case (arms,def)
794 :     of ([(F.DATAcon(dc,tycs,lv),le)],NONE) =>
795 :     (* this is a mere DECON, so we can push the let binding
796 :     * (hidden in cont) inside and maybe even drop the DECON *)
797 :     let val ndc = cdcon dc
798 :     val slv = Decon(lv, sv, ndc, tycs)
799 :     val nm = addbind(m, lv, slv)
800 :     (* see below *)
801 :     (* val nm = addbind(nm, lvc, Con(lvc, slv, ndc, tycs)) *)
802 :     val nle = loop nm le cont
803 :     val nv = sval2val sv
804 :     in
805 :     if used lv then
806 :     F.SWITCH(nv,ac,[(F.DATAcon(ndc,tycs,lv),nle)],NONE)
807 :     else (unuseval m nv; nle)
808 :     end
809 :     | (([(_,le)],NONE) | ([],SOME le)) =>
810 :     (* This should never happen, but we can optimize it away *)
811 :     (unuseval m (sval2val sv); loop m le cont)
812 :     | _ =>
813 :     let fun carm (F.DATAcon(dc,tycs,lv),le) =
814 :     let val ndc = cdcon dc
815 :     val slv = Decon(lv, sv, ndc, tycs)
816 :     val nm = addbind(m, lv, slv)
817 :     (* we can rebind lv to a more precise value
818 :     * !!BEWARE!! This rebinding is misleading:
819 :     * - it gives the impression that `lvc' is built
820 :     * from`lv' although the reverse is true:
821 :     * if `lvc' is undertaken, `lv's count should
822 :     * *not* be updated!
823 :     * Luckily, `lvc' will not become dead while
824 :     * rebound to Con(lv) because it's used by the
825 :     * SWITCH. All in all, it works fine, but it's
826 :     * not as straightforward as it seems.
827 :     * - it seems to be a good idea, but it can hide
828 :     * other opt-opportunities since it hides the
829 :     * previous binding. *)
830 :     (* val nm = addbind(nm, lvc, Con(lvc,slv,ndc,tycs)) *)
831 :     in (F.DATAcon(ndc, tycs, lv), loop nm le #2)
832 :     end
833 :     | carm (con,le) = (con, loop m le #2)
834 :     val narms = map carm arms
835 :     val ndef = Option.map (fn le => loop m le #2) def
836 :     in cont(m, F.SWITCH(sval2val sv, ac, narms, ndef))
837 :     end
838 : monnier 121
839 : monnier 201 in case val2sval m v
840 :     of sv as Con x => fcsCon x
841 :     | sv as Val v => fcsVal v
842 :     | sv as (Var{1=lvc,...} | Select{1=lvc,...} | Decon{1=lvc, ...}
843 :     | (* will probably never happen *) Record{1=lvc,...}) =>
844 :     fcsDefault(sv, lvc)
845 :     | sv as (Fun _ | TFun _) =>
846 :     bugval("unexpected switch arg", sval2val sv)
847 :     end
848 : monnier 159
849 : monnier 201 fun fcCon (dc1,tycs1,v,lv,le) =
850 :     let val lvi = C.get lv
851 :     in if C.dead lvi then (click_deadval(); loop m le cont) else
852 :     let val ndc = cdcon dc1
853 :     fun ccon sv =
854 :     let val nm = addbind(m, lv, Con(lv, sv, ndc, tycs1))
855 :     val nle = loop nm le cont
856 :     in if C.dead lvi then nle
857 :     else F.CON(ndc, tycs1, sval2val sv, lv, nle)
858 :     end
859 :     in case val2sval m v
860 :     of sv as (Decon (lvd,sv',dc2,tycs2)) =>
861 :     if FU.dcon_eq(dc1, dc2) andalso tycs_eq(tycs1,tycs2) then
862 :     (click_con();
863 :     loop (substitute(m, lv, sv', F.VAR lvd)) le cont)
864 :     else ccon sv
865 :     | sv => ccon sv
866 : monnier 189 end
867 : monnier 201 end
868 : monnier 121
869 : monnier 201 fun fcRecord (rk,vs,lv,le) =
870 :     (* g: check whether the record already exists *)
871 :     let val lvi = C.get lv
872 :     in if C.dead lvi then (click_deadval(); loop m le cont) else
873 :     let fun g (Select(_,sv,0)::ss) =
874 :     let fun g' (n,Select(_,sv',i)::ss) =
875 :     if n = i andalso (sval2val sv) = (sval2val sv')
876 :     then g'(n+1,ss) else NONE
877 : monnier 204 | g' (n,[]) =
878 : monnier 201 (case sval2lty sv
879 :     of SOME lty =>
880 : monnier 204 let val ltd =
881 :     case (rk, LT.ltp_tyc lty)
882 :     of (F.RK_STRUCT,false) => LT.ltd_str
883 :     | (F.RK_TUPLE _,true) => LT.ltd_tuple
884 :     (* we might select out of a struct
885 :     * into a tuple or vice-versa *)
886 :     | _ => (fn _ => [])
887 : monnier 201 in if length(ltd lty) = n
888 :     then SOME sv else NONE
889 :     end
890 :     | _ => (click_lacktype(); NONE)) (* sad *)
891 :     | g' _ = NONE
892 :     in g'(1,ss)
893 :     end
894 :     | g _ = NONE
895 :     val svs = map (val2sval m) vs
896 :     in case g svs
897 :     of SOME sv => (click_record();
898 :     loop (substitute(m, lv, sv, F.INT 0)) le cont
899 :     before app (unuseval m) vs)
900 :     | _ =>
901 :     let val nm = addbind(m, lv, Record(lv, svs))
902 :     val nle = loop nm le cont
903 :     in if C.dead lvi then nle
904 :     else F.RECORD(rk, map sval2val svs, lv, nle)
905 :     end
906 : monnier 189 end
907 : monnier 201 end
908 : monnier 121
909 : monnier 201 fun fcSelect (v,i,lv,le) =
910 :     let val lvi = C.get lv
911 :     in if C.dead lvi then (click_deadval(); loop m le cont) else
912 :     (case val2sval m v
913 :     of Record (lvr,svs) =>
914 :     let val sv = List.nth(svs, i)
915 :     in click_select();
916 :     loop (substitute(m, lv, sv, F.VAR lvr)) le cont
917 :     end
918 :     | sv =>
919 :     let val nm = addbind (m, lv, Select(lv, sv, i))
920 :     val nle = loop nm le cont
921 :     in if C.dead lvi then nle
922 :     else F.SELECT(sval2val sv, i, lv, nle)
923 :     end)
924 :     end
925 : monnier 121
926 : monnier 201 fun fcBranch (po,vs,le1,le2) =
927 :     let val nvs = map substval vs
928 :     val npo = cpo po
929 :     val nle1 = loop m le1 #2
930 :     val nle2 = loop m le2 #2
931 :     in cont(m, F.BRANCH(npo, nvs, nle1, nle2))
932 :     end
933 : monnier 121
934 : monnier 201 fun fcPrimop (po,vs,lv,le) =
935 :     let val lvi = C.get lv
936 : monnier 204 val pure = not(PO.effect(#2 po))
937 : monnier 201 in if pure andalso C.dead lvi then (click_deadval();loop m le cont) else
938 : monnier 199 let val nvs = map substval vs
939 : monnier 121 val npo = cpo po
940 : monnier 201 val nm = addbind(m, lv, Var(lv,NONE))
941 :     val nle = loop nm le cont
942 :     in
943 :     if pure andalso C.dead lvi then nle
944 :     else F.PRIMOP(npo, nvs, lv, nle)
945 : monnier 121 end
946 : monnier 201 end
947 : monnier 121
948 : monnier 201 in case le
949 :     of F.RET vs => cont(m, F.RET(map substval vs))
950 :     | F.LET x => fcLet x
951 :     | F.FIX x => fcFix x
952 :     | F.APP x => fcApp x
953 :     | F.TFN x => fcTfn x
954 :     | F.TAPP (f,tycs) => cont(m, F.TAPP(substval f, tycs))
955 :     | F.SWITCH x => fcSwitch x
956 :     | F.CON x => fcCon x
957 :     | F.RECORD x => fcRecord x
958 :     | F.SELECT x => fcSelect x
959 :     | F.RAISE (v,ltys) => cont(m, F.RAISE(substval v, ltys))
960 :     | F.HANDLE (le,v) => cont(m, F.HANDLE(loop m le #2, substval v))
961 :     | F.BRANCH x => fcBranch x
962 :     | F.PRIMOP x => fcPrimop x
963 : monnier 121 end
964 :    
965 : monnier 185 in
966 :     (* C.collect fdec; *)
967 : monnier 201 case fcexp S.empty
968 : monnier 185 M.empty (F.FIX([fdec], F.RET[F.VAR f])) #2
969 :     of F.FIX([fdec], F.RET[F.VAR f]) => fdec
970 :     | fdec => bug "invalid return fundec"
971 :     end
972 : monnier 121
973 :     end
974 :     end

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0