From 92b0e86ed1cf0270730c004211387b3fdc4b0469 Mon Sep 17 00:00:00 2001 From: Asumu Takikawa Date: Mon, 31 Mar 2014 17:46:39 -0400 Subject: [PATCH] Refactor TR `define` to avoid a performance bug After commit 3d177e454ea3634060a4b9b0814f588bc7c74e49 running the main `math.scrbl` file would show peak memory usage of around 600-700MB when before it was around 400MB. The proximal cause appears to be the expansion of TR definitions, which added an extra `begin` in some cases, combined with redefinitions at the top-level. I don't know the core cause yet. Thanks to Matthew for pointing out the issue and to Vincent for helping with debugging. --- .../typed-racket/base-env/prims.rkt | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/pkgs/typed-racket-pkgs/typed-racket-lib/typed-racket/base-env/prims.rkt b/pkgs/typed-racket-pkgs/typed-racket-lib/typed-racket/base-env/prims.rkt index 09c24c64a2..59d63c60be 100644 --- a/pkgs/typed-racket-pkgs/typed-racket-lib/typed-racket/base-env/prims.rkt +++ b/pkgs/typed-racket-pkgs/typed-racket-lib/typed-racket/base-env/prims.rkt @@ -1218,15 +1218,18 @@ This file defines two sorts of primitives. All of them are provided into any mod (define-syntax (-define stx) (syntax-parse stx #:literals (:) - ;; the first two cases are actually subsumed by the last, + ;; the first three cases are actually subsumed by the last, ;; but manually expanding to using the : annotation form ;; produces better error messages on duplicate annotations + ;; + ;; note, these first two cases can be collapsed into one + ;; but we keep them separate because in some cases it ruins + ;; typechecking performance to merge them. + [(-define nm:id body) + (syntax/loc stx (define nm body))] [(-define nm:id return:return-ann body) - (define/with-syntax maybe-ann - (if (attribute return.type) - #'(: nm return.type) - #'(void))) - (syntax/loc stx (begin maybe-ann (define nm body)))] + (quasisyntax/loc stx + (begin (: nm #,(attribute return.type)) (define nm body)))] [(-define vars:lambda-type-vars nm:id : ty body) (define/with-syntax type (syntax/loc #'ty (All vars.type-vars ty)))