From a6e4dfa639d9f3a554bef59ffaaef199b65542fa Mon Sep 17 00:00:00 2001 From: Matthew Flatt Date: Tue, 29 Aug 2006 07:08:37 +0000 Subject: [PATCH] corrected and improved call-with-values optimization svn: r4182 --- src/mzscheme/src/eval.c | 28 +++++++++++++++++++--------- src/mzscheme/src/syntax.c | 3 +++ 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/src/mzscheme/src/eval.c b/src/mzscheme/src/eval.c index c1b3ac16e8..b207f20209 100644 --- a/src/mzscheme/src/eval.c +++ b/src/mzscheme/src/eval.c @@ -2332,7 +2332,7 @@ Scheme_Object *scheme_optimize_apply_values(Scheme_Object *f, Scheme_Object *e, if (f_is_proc && (e_single_result > 0)) { /* Just make it an application (N M): */ Scheme_App2_Rec *app2; - Scheme_Object *cloned; + Scheme_Object *cloned, *f_cloned; app2 = MALLOC_ONE_TAGGED(Scheme_App2_Rec); app2->iso.so.type = scheme_application2_type; @@ -2343,16 +2343,26 @@ Scheme_Object *scheme_optimize_apply_values(Scheme_Object *f, Scheme_Object *e, If we can shift-clone it, then it will be back in the right coordinates. */ - cloned = NULL; /* scheme_optimize_clone(1, e, info, 0, 0); */ + cloned = scheme_optimize_clone(1, e, info, 0, 0); if (cloned) { - app2->rator = f_is_proc; - app2->rand = cloned; - return optimize_application2((Scheme_Object *)app2, info); - } else { - app2->rator = f; - app2->rand = e; - return (Scheme_Object *)app2; + if (SAME_TYPE(SCHEME_TYPE(f_is_proc), scheme_compiled_unclosed_procedure_type)) + f_cloned = scheme_optimize_clone(1, f_is_proc, info, 0, 0); + else { + /* Otherwise, no clone is needed; in the case of a lexical + variable, we already reversed it. */ + f_cloned = f_is_proc; + } + + if (f_cloned) { + app2->rator = f_cloned; + app2->rand = cloned; + return optimize_application2((Scheme_Object *)app2, info); + } } + + app2->rator = f; + app2->rand = e; + return (Scheme_Object *)app2; } return scheme_make_syntax_compiled(APPVALS_EXPD, cons(f, e)); diff --git a/src/mzscheme/src/syntax.c b/src/mzscheme/src/syntax.c index 77a7c0f760..645f54663a 100644 --- a/src/mzscheme/src/syntax.c +++ b/src/mzscheme/src/syntax.c @@ -2659,6 +2659,9 @@ scheme_optimize_lets(Scheme_Object *form, Optimize_Info *info, int for_inline) Scheme_Type lhs; lhs = SCHEME_TYPE(clv->value); if ((lhs == scheme_compiled_unclosed_procedure_type) + || (lhs == scheme_local_type) + || (lhs == scheme_compiled_toplevel_type) + || (lhs == scheme_compiled_quote_syntax_type) || (lhs > _scheme_compiled_values_types_)) { if (for_inline) { /* Just drop the inline-introduced let */