From b5fad95e580bf2809e4e1c335c0adadce524813e Mon Sep 17 00:00:00 2001 From: Robby Findler Date: Fri, 6 Aug 2010 13:45:29 -0500 Subject: [PATCH] make the optimizer give up more agressively when it starts out with a completely unknown thing --- collects/racket/contract/private/opt.rkt | 27 ++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/collects/racket/contract/private/opt.rkt b/collects/racket/contract/private/opt.rkt index 7e59f5295f..bc7d95ce82 100644 --- a/collects/racket/contract/private/opt.rkt +++ b/collects/racket/contract/private/opt.rkt @@ -89,7 +89,8 @@ ;; opt/i : id opt/info syntax -> ;; syntax syntax-list syntax-list (union syntax #f) (union syntax #f) (define (opt/i opt/info stx) - (syntax-case stx (if) + ;; the case dispatch here must match what top-level-unknown? is doing + (syntax-case stx () [(ctc arg ...) (and (identifier? #'ctc) (opter #'ctc)) ((opter #'ctc) opt/i opt/info stx)] @@ -112,8 +113,30 @@ [else (opt/unknown opt/i opt/info stx)])) + ;; top-level-unknown? : syntax -> boolean + ;; this must match what the function above is doing + (define (top-level-unknown? stx) + (syntax-case stx () + [(ctc arg ...) + (and (identifier? #'ctc) (opter #'ctc)) + #f] + [argless-ctc + (and (identifier? #'argless-ctc) (opter #'argless-ctc)) + #f] + [(f arg ...) + (and (identifier? #'f) + (syntax-parameter-value #'define/opt-recursive-fn) + (free-identifier=? (syntax-parameter-value #'define/opt-recursive-fn) + #'f)) + #f] + [else + #t])) + (syntax-case stx () - [(_ e) #'(opt/c e ())] + [(_ e) + (if (top-level-unknown? #'e) + #'e + #'(opt/c e ()))] [(_ e (opt-recursive-args ...)) (let*-values ([(info) (make-opt/info #'ctc #'val