From ff2f362c8eb6da798fdedc6c1b0a23b0331db435 Mon Sep 17 00:00:00 2001 From: Joe Marshall Date: Wed, 24 Feb 2010 19:00:11 -0800 Subject: [PATCH] Elide conditional canonicalization. --- src/sf/sf.pkg | 1 + src/sf/subst.scm | 32 +++++++++++++++++++++----------- 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/src/sf/sf.pkg b/src/sf/sf.pkg index 87d055580..faee1fea6 100644 --- a/src/sf/sf.pkg +++ b/src/sf/sf.pkg @@ -92,6 +92,7 @@ USA. (parent (scode-optimizer)) (export () sf:display-top-level-procedure-names? + sf:enable-elide-conditional-canonicalization? sf:enable-elide-double-negatives?) (export (scode-optimizer) integrate/top-level diff --git a/src/sf/subst.scm b/src/sf/subst.scm index 65838068d..1ecf124ee 100644 --- a/src/sf/subst.scm +++ b/src/sf/subst.scm @@ -147,19 +147,29 @@ USA. (combination/operands combination))))) ;;;; CONDITIONAL + +;; Expression such as (if (pair? x) #t #f) don't need the conditional. +(define sf:enable-elide-conditional-canonicalization? #t) + (define-method/integrate 'CONDITIONAL (lambda (operations environment expression) - (conditional/make - (conditional/scode expression) - (integrate/expression - operations environment - (conditional/predicate expression)) - (integrate/expression - operations environment - (conditional/consequent expression)) - (integrate/expression - operations environment - (conditional/alternative expression))))) + (let ((ipred (integrate/expression + operations environment + (conditional/predicate expression))) + (icons (integrate/expression + operations environment + (conditional/consequent expression))) + (ialt (integrate/expression + operations environment + (conditional/alternative expression)))) + (cond ((and (expression/constant-eq? icons #t) + (expression/constant-eq? ialt #f) + (expression/boolean? ipred) + (noisy-test sf:enable-elide-conditional-canonicalization? + "elide conditional canonicalization")) + ipred) + (else + (conditional/make (conditional/scode expression) ipred icons ialt)))))) ;;; CONSTANT (define-method/integrate 'CONSTANT -- 2.25.1