Add the remaining diagnosis messages.

This commit is contained in:
Vincent St-Amour 2011-06-27 16:50:36 -04:00
parent 975cb7ad9d
commit 00d23a4535
4 changed files with 16 additions and 18 deletions

View File

@ -378,7 +378,10 @@
#:when (when (and (in-complex-layer? #'e) #:when (when (and (in-complex-layer? #'e)
(for/and ([subexpr (in-list (syntax->list #'(e.args ...)))]) (for/and ([subexpr (in-list (syntax->list #'(e.args ...)))])
(subtypeof? subexpr -Real))) (subtypeof? subexpr -Real)))
(log-missed-optimization "unexpected complex type" this-syntax)) (log-missed-optimization
"unexpected complex type"
"This expression has a Complex type, despite all its arguments being reals. If you do not want or expect complex numbers as results, you may want to restrict the type of the arguments, which may have a beneficial impact on performance."
this-syntax))
;; We don't actually want to match. ;; We don't actually want to match.
#:when #f #:when #f
#:with real-binding #'#f ; required, otherwise syntax/parse is not happy #:with real-binding #'#f ; required, otherwise syntax/parse is not happy

View File

@ -77,12 +77,7 @@
(define (log-float-real-missed-opt stx irritants) (define (log-float-real-missed-opt stx irritants)
(log-missed-optimization (log-missed-optimization
"all args float-arg-expr, result not Float" "all args float-arg-expr, result not Float"
#:msg "This expression has a Real type. It would be better optimized if it had a Float type. To fix this, change the circled expression(s) to have Float type(s)."
(format "This expression has type ~a. It would be better optimized if it had a Float type. To fix this, change the irritant~a to have~a Float type~a."
(print-res (type-of stx))
(if (> (length irritants) 1) "s" "")
(if (> (length irritants) 1) "" " a")
(if (> (length irritants) 1) "s" "")) ; plural
stx irritants)) stx irritants))
(define-syntax-class float-opt-expr (define-syntax-class float-opt-expr
@ -135,7 +130,8 @@
;; which don't perform arithmetic despite returning numbers. ;; which don't perform arithmetic despite returning numbers.
[e:arith-expr [e:arith-expr
(log-missed-optimization (log-missed-optimization
"exact arithmetic subexpression inside a float expression, extra precision discarded" "exact ops inside float expr"
"This expression has a Float type, but the circled subexpression(s) use exact arithmetic. The extra precision of the exact arithmetic will be lost. Using Float types in these subexpression(s) may result in performance gains without significant precision loss."
this-syntax subexpr)] this-syntax subexpr)]
[_ #f]))) [_ #f])))
safe-to-opt?) safe-to-opt?)

View File

@ -90,8 +90,7 @@
;; Attempts to merge the incoming missed optimization with existing ones. ;; Attempts to merge the incoming missed optimization with existing ones.
;; Otherwise, adds the new one to the log. ;; Otherwise, adds the new one to the log.
(define (log-missed-optimization kind stx [irritants '()] (define (log-missed-optimization kind msg stx [irritants '()])
#:msg [msg kind])
;; for convenience, if a single irritant is given, wrap it in a list ;; for convenience, if a single irritant is given, wrap it in a list
;; implicitly ;; implicitly
(let* ([irritants (if (list? irritants) irritants (list irritants))] (let* ([irritants (if (list? irritants) irritants (list irritants))]

View File

@ -33,6 +33,12 @@
[(tc-result1: (MPair: _ _)) #t] [(tc-result1: (MPair: _ _)) #t]
[_ #f])) [_ #f]))
(define (log-pair-missed-opt stx irritant)
(log-missed-optimization
"car/cdr on a potentially empty list"
"According to its type, the circled list could be empty. Access to it cannot be safely optimized. To fix this, restrict the type to non-empty lists, maybe by wrapping this expression in a check for non-emptiness."
stx irritant))
(define-syntax-class pair-opt-expr (define-syntax-class pair-opt-expr
#:commit #:commit
(pattern e:pair-derived-opt-expr (pattern e:pair-derived-opt-expr
@ -44,19 +50,13 @@
;; in this case, we have a potentially empty list, but ;; in this case, we have a potentially empty list, but
;; it has to be a list, otherwise, there would have been ;; it has to be a list, otherwise, there would have been
;; a type error ;; a type error
(begin (begin (log-pair-missed-opt this-syntax #'p) #f))
(log-missed-optimization "car/cdr on a potentially empty list"
this-syntax #'p)
#f))
#:with opt #:with opt
(begin (log-optimization "pair" this-syntax) (begin (log-optimization "pair" this-syntax)
#`(op.unsafe #,((optimize) #'p)))) #`(op.unsafe #,((optimize) #'p))))
(pattern (#%plain-app op:mpair-op p:expr e:expr ...) (pattern (#%plain-app op:mpair-op p:expr e:expr ...)
#:when (or (has-mpair-type? #'p) #:when (or (has-mpair-type? #'p)
(begin (begin (log-pair-missed-opt this-syntax #'p) #f))
(log-missed-optimization "mpair op on a potentially empty mlist"
this-syntax #'p)
#f))
#:with opt #:with opt
(begin (log-optimization "mutable pair" this-syntax) (begin (log-optimization "mutable pair" this-syntax)
#`(op.unsafe #,@(syntax-map (optimize) #'(p e ...)))))) #`(op.unsafe #,@(syntax-map (optimize) #'(p e ...))))))