From 9ce4dd8770ab66a77367d118767424059fb18087 Mon Sep 17 00:00:00 2001 From: Matthew Flatt Date: Thu, 6 Dec 2018 21:13:12 -0700 Subject: [PATCH] raco exe: fix excessive memory use Avoid retaining namespaces that are created to gather runtime paths. If expansion generates a lot of instances with a lot of type information, for example, this repair can save a lot of space. --- racket/collects/compiler/embed.rkt | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/racket/collects/compiler/embed.rkt b/racket/collects/compiler/embed.rkt index dabc5bb160..0d29f1de3b 100644 --- a/racket/collects/compiler/embed.rkt +++ b/racket/collects/compiler/embed.rkt @@ -546,18 +546,28 @@ (module-compiled-submodules code #f null) #t null)) - (eval no-submodule-code) (let ([module-path (if (path? module-path) (path->complete-path module-path) module-path)]) + (unless (module-declared? module-path) + (parameterize ([current-module-declare-name + (module-path-index-resolve (module-path-index-join + module-path + #f))]) + (eval no-submodule-code))) (define e (expand `(,#'module m racket/kernel (#%require (only ,module-path) racket/runtime-path) (runtime-paths ,module-path)))) (syntax-case e (quote) [(_ m mz (#%mb req (quote (spec ...)))) - (syntax->datum #'(spec ...))] + (for/list ([p (in-list (syntax->datum #'(spec ...)))]) + ;; Strip variable reference from 'module specs, because + ;; we don't need them and they retain the namespace: + (if (and (pair? p) (eq? 'module (car p))) + (list 'module (cadr p)) + p))] [_else (error 'create-empbedding-executable "expansion mismatch when getting external paths: ~e" (syntax->datum e))]))))]