diff --git a/collects/tests/typed-scheme/optimizer/missed-optimizations/nested-same-kind.rkt b/collects/tests/typed-scheme/optimizer/missed-optimizations/nested-same-kind.rkt index 6b7a01c5..1ef7320b 100644 --- a/collects/tests/typed-scheme/optimizer/missed-optimizations/nested-same-kind.rkt +++ b/collects/tests/typed-scheme/optimizer/missed-optimizations/nested-same-kind.rkt @@ -1,14 +1,13 @@ #; ( -TR missed opt: nested-same-kind.rkt 25:0 (* 2.0 (* 3.0 (ann 4 Integer))) -- exact ops inside float expr -- caused by: 25:7 (* 3.0 (ann 4 Integer)) -TR missed opt: nested-same-kind.rkt 25:0 (* 2.0 (* 3.0 (ann 4 Integer))) -- all args float-arg-expr, result not Float -- caused by: 25:19 4 (2 times) -TR missed opt: nested-same-kind.rkt 26:0 (* 1.0 (* 2.0 (* 3.0 (ann 4 Integer)))) -- exact ops inside float expr -- caused by: 26:14 (* 3.0 (ann 4 Integer)) (2 times) -TR missed opt: nested-same-kind.rkt 26:0 (* 1.0 (* 2.0 (* 3.0 (ann 4 Integer)))) -- all args float-arg-expr, result not Float -- caused by: 26:26 4 (3 times) -TR missed opt: nested-same-kind.rkt 27:0 (* 2.0 (* 3.0 (ann 4 Integer) (ann 5 Integer))) -- exact ops inside float expr -- caused by: 27:7 (* 3.0 (ann 4 Integer) (ann 5 Integer)) -TR missed opt: nested-same-kind.rkt 27:0 (* 2.0 (* 3.0 (ann 4 Integer) (ann 5 Integer))) -- all args float-arg-expr, result not Float -- caused by: 27:19 4, 27:35 5 (2 times) -TR missed opt: nested-same-kind.rkt 28:0 (* (* 3.0 (ann 4 Integer)) (* 3.0 (ann 4 Integer))) -- exact ops inside float expr -- caused by: 28:27 (* 3.0 (ann 4 Integer)) -TR missed opt: nested-same-kind.rkt 28:0 (* (* 3.0 (ann 4 Integer)) (* 3.0 (ann 4 Integer))) -- exact ops inside float expr -- caused by: 28:3 (* 3.0 (ann 4 Integer)) -TR missed opt: nested-same-kind.rkt 28:0 (* (* 3.0 (ann 4 Integer)) (* 3.0 (ann 4 Integer))) -- all args float-arg-expr, result not Float -- caused by: 28:15 4, 28:39 4 (3 times) +TR missed opt: nested-same-kind.rkt 24:0 (* 2.0 (* 3.0 (ann 4 Integer))) -- exact ops inside float expr -- caused by: 24:7 (* 3.0 (ann 4 Integer)) +TR missed opt: nested-same-kind.rkt 24:0 (* 2.0 (* 3.0 (ann 4 Integer))) -- all args float-arg-expr, result not Float -- caused by: 24:19 4 (2 times) +TR missed opt: nested-same-kind.rkt 25:0 (* 1.0 (* 2.0 (* 3.0 (ann 4 Integer)))) -- exact ops inside float expr -- caused by: 25:14 (* 3.0 (ann 4 Integer)) (2 times) +TR missed opt: nested-same-kind.rkt 25:0 (* 1.0 (* 2.0 (* 3.0 (ann 4 Integer)))) -- all args float-arg-expr, result not Float -- caused by: 25:26 4 (3 times) +TR missed opt: nested-same-kind.rkt 26:0 (* 2.0 (* 3.0 (ann 4 Integer) (ann 5 Integer))) -- exact ops inside float expr -- caused by: 26:7 (* 3.0 (ann 4 Integer) (ann 5 Integer)) +TR missed opt: nested-same-kind.rkt 26:0 (* 2.0 (* 3.0 (ann 4 Integer) (ann 5 Integer))) -- all args float-arg-expr, result not Float -- caused by: 26:19 4, 26:35 5 (2 times) +TR missed opt: nested-same-kind.rkt 27:0 (* (* 3.0 (ann 4 Integer)) (* 3.0 (ann 4 Integer))) -- exact ops inside float expr -- caused by: 27:3 (* 3.0 (ann 4 Integer)), 27:27 (* 3.0 (ann 4 Integer)) +TR missed opt: nested-same-kind.rkt 27:0 (* (* 3.0 (ann 4 Integer)) (* 3.0 (ann 4 Integer))) -- all args float-arg-expr, result not Float -- caused by: 27:15 4, 27:39 4 (3 times) 24.0 24.0 120.0 diff --git a/collects/typed-scheme/optimizer/float.rkt b/collects/typed-scheme/optimizer/float.rkt index 9e5d4b94..8e0a52fc 100644 --- a/collects/typed-scheme/optimizer/float.rkt +++ b/collects/typed-scheme/optimizer/float.rkt @@ -121,21 +121,25 @@ ;; use cases for computing exact intermediate results, then converting them to ;; floats at the end. (when (or safe-to-opt? missed-optimization?) - (for ([subexpr (in-list (syntax->list #'(f1 f2 fs ...)))] - #:when (or (in-real-layer? subexpr) - (in-rational-layer? subexpr))) - (syntax-parse subexpr - ;; Only warn about subexpressions that actually perform exact arithmetic. - ;; There's not much point in warning about literals/variables that will - ;; be coerced anyway, or about things like: - ;; (vector-ref vector-of-rationals x) - ;; which don't perform arithmetic despite returning numbers. - [e:arith-expr - (log-missed-optimization - "exact ops inside float expr" - "This expression has a Float type, but the highlighted 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)] - [_ #f]))) + (define extra-precision-subexprs + (filter + values + (for/list ([subexpr (in-list (syntax->list #'(f1 f2 fs ...)))] + #:when (or (in-real-layer? subexpr) + (in-rational-layer? subexpr))) + (syntax-parse subexpr + ;; Only warn about subexpressions that actually perform exact arithmetic. + ;; There's not much point in warning about literals/variables that will + ;; be coerced anyway, or about things like: + ;; (vector-ref vector-of-rationals x) + ;; which don't perform arithmetic despite returning numbers. + [e:arith-expr #'e] + [_ #f])))) + (when (not (null? extra-precision-subexprs)) + (log-missed-optimization + "exact ops inside float expr" + "This expression has a Float type, but the highlighted 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 extra-precision-subexprs))) safe-to-opt?) #:with opt (begin (log-optimization "binary float" float-opt-msg this-syntax)