Do not optimize-out library exports

This commit is contained in:
Justin Ethier 2015-05-05 18:00:07 -04:00
parent ce2b998a30
commit ef4aa4360a
2 changed files with 4 additions and 4 deletions

View file

@ -83,10 +83,9 @@
;; Optimize-out unused global variables ;; Optimize-out unused global variables
;; For now, do not do this if eval is used. ;; For now, do not do this if eval is used.
;; TODO: do not have to be so aggressive, unless (eval (read)) or such ;; TODO: do not have to be so aggressive, unless (eval (read)) or such
TODO: do not remove globals that are part of the export list!
(if (not (has-global? input-program 'eval)) (if (not (has-global? input-program 'eval))
(set! input-program (set! input-program
(filter-unused-variables input-program))) (filter-unused-variables input-program lib-exports)))
(trace:info "---------------- after processing globals") (trace:info "---------------- after processing globals")
(trace:info input-program) ;pretty-print (trace:info input-program) ;pretty-print

View file

@ -1186,7 +1186,7 @@
;; Many improvements can be made, including: ;; Many improvements can be made, including:
;; ;;
;; TODO: remove unused locals ;; TODO: remove unused locals
(define (filter-unused-variables asts) (define (filter-unused-variables asts lib-exports)
(define (do-filter code) (define (do-filter code)
(let ((all-fv (apply ;; More efficient way to do this? (let ((all-fv (apply ;; More efficient way to do this?
append ;; Could use delete-duplicates append ;; Could use delete-duplicates
@ -1204,7 +1204,8 @@
(filter (filter
(lambda (ast) (lambda (ast)
(or (not (define? ast)) (or (not (define? ast))
(member (define->var ast) all-fv))) (member (define->var ast) all-fv)
(member (define->var ast) lib-exports)))
code))) code)))
;; Keep filtering until no more vars are removed ;; Keep filtering until no more vars are removed
(define (loop code) (define (loop code)