summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar Adam Chlipala <adamc@hcoop.net>2009-12-31 18:07:53 -0500
committerGravatar Adam Chlipala <adamc@hcoop.net>2009-12-31 18:07:53 -0500
commit76a84dd3fb97b56605292c4f0eab2febe3c6a7ed (patch)
tree0bde2b80fc3e8df14cd6e16f05bdd88e062aca9a /src
parentd57cc15e6b5c1f77ebfbfa222283809a4f594e36 (diff)
Eta-expand bodies of transaction functions in Monoization, to enable later optimization
Diffstat (limited to 'src')
-rw-r--r--src/mono_print.sml32
-rw-r--r--src/mono_reduce.sml33
-rw-r--r--src/monoize.sml23
3 files changed, 59 insertions, 29 deletions
diff --git a/src/mono_print.sml b/src/mono_print.sml
index d190640e..a5e795b2 100644
--- a/src/mono_print.sml
+++ b/src/mono_print.sml
@@ -206,18 +206,26 @@ fun p_exp' par env (e, _) =
string ".",
string x]
- | ECase (e, pes, _) => parenIf true (box [string "case",
- space,
- p_exp env e,
- space,
- string "of",
- space,
- p_list_sep (box [space, string "|", space])
- (fn (p, e) => box [p_pat env p,
- space,
- string "=>",
- space,
- p_exp (E.patBinds env p) e]) pes])
+ | ECase (e, pes, {result, ...}) => parenIf true (box [string "case",
+ space,
+ p_exp env e,
+ space,
+ if !debug then
+ box [string "return",
+ space,
+ p_typ env result,
+ space]
+ else
+ box [],
+ string "of",
+ space,
+ p_list_sep (box [space, string "|", space])
+ (fn (p, e) => box [p_pat env p,
+ space,
+ string "=>",
+ space,
+ p_exp (E.patBinds env p) e])
+ pes])
| EError (e, t) => box [string "(error",
space,
diff --git a/src/mono_reduce.sml b/src/mono_reduce.sml
index aa6b7051..16cfd9f9 100644
--- a/src/mono_reduce.sml
+++ b/src/mono_reduce.sml
@@ -582,23 +582,22 @@ fun reduce file =
fun push () =
case result of
(TFun (dom, result), loc) =>
- if List.all (fn (_, (EAbs _, _)) => true | _ => false) pes then
- let
- val r =
- EAbs ("y", dom, result,
- (ECase (liftExpInExp 0 e',
- map (fn (p, (EAbs (_, _, _, e), _)) =>
- (p, swapExpVarsPat (0, patBinds p) e)
- | _ => raise Fail "MonoReduce ECase") pes,
- {disc = disc, result = result}), loc))
- in
- (*Print.prefaces "Swapped"
- [("e", MonoPrint.p_exp env (e, ErrorMsg.dummySpan)),
- ("r", MonoPrint.p_exp env (r, ErrorMsg.dummySpan))];*)
- r
- end
- else
- e
+ let
+ fun safe (e, _) =
+ case e of
+ EAbs _ => true
+ | _ => false
+ in
+ if List.all (safe o #2) pes then
+ EAbs ("y", dom, result,
+ (ECase (liftExpInExp 0 e',
+ map (fn (p, (EAbs (_, _, _, e), _)) =>
+ (p, swapExpVarsPat (0, patBinds p) e)
+ | _ => raise Fail "MonoReduce ECase") pes,
+ {disc = disc, result = result}), loc))
+ else
+ e
+ end
| _ => e
fun search pes =
diff --git a/src/monoize.sml b/src/monoize.sml
index afe2012f..4d3bfda2 100644
--- a/src/monoize.sml
+++ b/src/monoize.sml
@@ -3440,6 +3440,29 @@ fun monoDecl (env, fm) (all as (d, loc)) =
end
| L.DValRec vis =>
let
+ val vis = map (fn (x, n, t, e, s) =>
+ let
+ fun maybeTransaction (t, e) =
+ case (#1 t, #1 e) of
+ (L.CApp ((L.CFfi ("Basis", "transaction"), _), _), _) =>
+ SOME (L.EAbs ("_",
+ (L.TRecord (L.CRecord ((L.KType, loc), []), loc), loc),
+ t,
+ (L.EApp (CoreEnv.liftExpInExp 0 e,
+ (L.ERecord [], loc)), loc)), loc)
+ | (L.TFun (dom, ran), L.EAbs (x, _, _, e)) =>
+ (case maybeTransaction (ran, e) of
+ NONE => NONE
+ | SOME e => SOME (L.EAbs (x, dom, ran, e), loc))
+ | _ => NONE
+ in
+ (x, n, t,
+ case maybeTransaction (t, e) of
+ NONE => e
+ | SOME e => e,
+ s)
+ end) vis
+
val env = foldl (fn ((x, n, t, e, s), env) => Env.pushENamed env x n t NONE s) env vis
val (vis, fm) = ListUtil.foldlMap