Refactor TR define
to avoid a performance bug
After commit 3d177e454e
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.
This commit is contained in:
parent
6722b7a71e
commit
92b0e86ed1
|
@ -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)))
|
||||
|
|
Loading…
Reference in New Issue
Block a user