From 3d5f500a4faa3ed668d9ef596c72b9f16c927b66 Mon Sep 17 00:00:00 2001 From: Vincent St-Amour Date: Thu, 9 Feb 2012 16:51:39 -0500 Subject: [PATCH] Emit optimization logs as we optimize, instead of accumulating them. original commit: ddb1982e019183bda437092280b6396fd0bbf2b9 --- collects/typed-racket/optimizer/logging.rkt | 29 ++++++--------------- 1 file changed, 8 insertions(+), 21 deletions(-) diff --git a/collects/typed-racket/optimizer/logging.rkt b/collects/typed-racket/optimizer/logging.rkt index 20f30b17..be26841b 100644 --- a/collects/typed-racket/optimizer/logging.rkt +++ b/collects/typed-racket/optimizer/logging.rkt @@ -16,6 +16,11 @@ (define TR-logging-level 'debug) +(define (emit-log-message l) + (log-message (current-logger) TR-logging-level + (format-log-entry l) + (cons optimization-log-key l))) + ;; producing logs can be expensive, don't do it if no-one's listening ;; to the logs (define (anyone-listening?) (log-level? (current-logger) TR-logging-level)) @@ -26,11 +31,6 @@ ;; since this is used across phases, can't be a gensym (define optimization-log-key 'log-message-coming-from-the-TR-optimizer) -;; we keep track of log entries, to avoid repetitions that would be -;; caused by traversing the same syntax multiple times (which is not -;; a problem per se) -(define log-so-far '()) - ;; msg is for consumption by the DrRacket tool (struct log-entry (kind msg stx located-stx pos) #:prefab) ;; for optimizations only (not missed optimizations, those are below) @@ -39,10 +39,8 @@ (define (log-optimization kind msg stx) (when (anyone-listening?) - (let ([new-entry - (opt-log-entry kind msg - stx (locate-stx stx) (syntax-position stx))]) - (set! log-so-far (cons new-entry log-so-far))))) + (emit-log-message + (opt-log-entry kind msg stx (locate-stx stx) (syntax-position stx))))) ;;-------------------------------------------------------------------- @@ -145,11 +143,6 @@ ;; no related entry, just add the new one (cons new missed-optimizations-log)]))))) -;; When we know all missed opts are known and merging has been done, we -;; can add them to the regular log. -(define (add-missed-opts-to-log) - (set! log-so-far (append log-so-far missed-optimizations-log))) - ;;-------------------------------------------------------------------- @@ -200,15 +193,9 @@ ;; Once the optimizer is done, we sort the log according to source ;; location, then print it. (define (print-log) - (define logger (current-logger)) - (add-missed-opts-to-log) - (for ([x (in-list log-so-far)]) - (log-message logger TR-logging-level - (format-log-entry x) - (cons optimization-log-key x)))) + (for-each emit-log-message missed-optimizations-log)) (define (clear-log) - (set! log-so-far '()) (set! missed-optimizations-log '())) ;;--------------------------------------------------------------------