diff --git a/collects/tests/typed-racket/optimizer/tests/pr13468.rkt b/collects/tests/typed-racket/optimizer/tests/pr13468.rkt index c10220fb..1f21f0b0 100644 --- a/collects/tests/typed-racket/optimizer/tests/pr13468.rkt +++ b/collects/tests/typed-racket/optimizer/tests/pr13468.rkt @@ -6,6 +6,7 @@ TR opt: pr13468.rkt 86:5 (- (ann 6.0+2.3i Float-Complex)) -- unboxed unary float TR opt: pr13468.rkt 87:13 6.0+2.3i -- unboxed literal TR opt: pr13468.rkt 87:13 6.0+2.3i -- unboxed literal TR opt: pr13468.rkt 87:5 (/ (ann 6.0+2.3i Float-Complex)) -- unboxed unary float complex +TR missed opt: pr13468.rkt 88:5 (/ (ann 0.0+0.0i Float-Complex) (ann 1 Number)) -- Float-Complex division, potential exact 0s on the rhss -- caused by: 88:42 1 TR missed opt: pr13468.rkt 91:5 (expt (ann -5.0 Flonum) (ann 2.0 Flonum)) -- unexpected complex type TR opt: pr13468.rkt 112:21 0.0 -- float-arg-expr in complex ops TR opt: pr13468.rkt 112:5 (magnitude (ann 0.0 Flonum-Zero)) -- unboxed unary float complex @@ -81,7 +82,6 @@ TR opt: pr13468.rkt 143:5 (real-part (ann 6.0 Flonum)) -- unboxed unary float co - ;; Most bothersome missing cases: (ann (- (ann 6.0+2.3i Float-Complex)) Float-Complex) (ann (/ (ann 6.0+2.3i Float-Complex)) Float-Complex) diff --git a/collects/typed-racket/optimizer/float-complex.rkt b/collects/typed-racket/optimizer/float-complex.rkt index 7058f4ab..3b7f1053 100644 --- a/collects/typed-racket/optimizer/float-complex.rkt +++ b/collects/typed-racket/optimizer/float-complex.rkt @@ -600,11 +600,26 @@ ;; otherwise, optimization is unsound (we'd give a result where we're supposed to throw an error) (pattern (#%plain-app (~literal /) e:expr ...) #:when (subtypeof? this-syntax -FloatComplex) - #:when (for/and ([c (syntax->list #'(e ...))]) - (match (type-of c) - [(tc-result1: t) - (not (subtype -Zero t))] - [_ #f])) + #:when (let ([irritants + (for/list ([c (syntax->list #'(e ...))] + #:when (match (type-of c) + [(tc-result1: t) + (subtype -Zero t)] + [_ #t])) + c)]) + (define safe-to-opt? (null? irritants)) + ;; result is Float-Complex, but unsafe to optimize, missed optimization + (unless safe-to-opt? + (log-missed-optimization + "Float-Complex division, potential exact 0s on the rhss" + (string-append + "This expression has a Float-Complex type, but cannot be safely unboxed. " + "The second (and later) arguments could potentially be exact 0." + (if (null? irritants) + "" + "\nTo fix, change the highlighted expression(s) to have Float (or Float-Complex) type(s).")) + this-syntax irritants)) + safe-to-opt?) #:with exp*:unboxed-float-complex-opt-expr this-syntax #:with real-binding #'exp*.real-binding #:with imag-binding #'exp*.imag-binding