From 9170637137c048f6fe2838985388b966af596783 Mon Sep 17 00:00:00 2001 From: Vincent St-Amour Date: Thu, 11 Oct 2012 18:11:10 -0400 Subject: [PATCH] Only recommend dropping exactness in truly inexact contexts. Please merge to release. original commit: 758e4ff112bf83544fdfc833f454930cc0bc5322 --- .../missed-optimizations/precision-loss.rkt | 6 +++--- .../typed-racket/optimizer/tests/case-arrow.rkt | 14 +++++++------- collects/typed-racket/optimizer/float.rkt | 3 ++- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/collects/tests/typed-racket/optimizer/missed-optimizations/precision-loss.rkt b/collects/tests/typed-racket/optimizer/missed-optimizations/precision-loss.rkt index b8ea816f..c39ee302 100644 --- a/collects/tests/typed-racket/optimizer/missed-optimizations/precision-loss.rkt +++ b/collects/tests/typed-racket/optimizer/missed-optimizations/precision-loss.rkt @@ -10,15 +10,12 @@ TR missed opt: precision-loss.rkt 48:8 (* 3/4 2/3) -- all args float-arg-expr, r TR opt: precision-loss.rkt 49:3 (car (list (* 2.0 (ann (* 3/4 2/3) Real)))) -- pair TR missed opt: precision-loss.rkt 49:26 (* 3/4 2/3) -- all args float-arg-expr, result not Float -- caused by: 49:29 3/4, 49:33 2/3 TR missed opt: precision-loss.rkt 49:14 (* 2.0 (ann (* 3/4 2/3) Real)) -- all args float-arg-expr, result not Float -- caused by: 49:26 (* 3/4 2/3) -TR missed opt: precision-loss.rkt 49:14 (* 2.0 (ann (* 3/4 2/3) Real)) -- exact ops inside float expr -- caused by: 49:26 (* 3/4 2/3) TR missed opt: precision-loss.rkt 49:26 (* 3/4 2/3) -- all args float-arg-expr, result not Float -- caused by: 49:29 3/4, 49:33 2/3 TR missed opt: precision-loss.rkt 48:0 (* (ann (* 3/4 2/3) Real) (car (list (* 2.0 (ann (* 3/4 2/3) Real)))) 2.0) -- all args float-arg-expr, result not Float -- caused by: 48:8 (* 3/4 2/3), 49:3 (car (list (* 2.0 (ann (* 3/4 2/3) Real)))) -TR missed opt: precision-loss.rkt 48:0 (* (ann (* 3/4 2/3) Real) (car (list (* 2.0 (ann (* 3/4 2/3) Real)))) 2.0) -- exact ops inside float expr -- caused by: 48:8 (* 3/4 2/3) TR missed opt: precision-loss.rkt 48:8 (* 3/4 2/3) -- all args float-arg-expr, result not Float -- caused by: 48:11 3/4, 48:15 2/3 TR opt: precision-loss.rkt 49:3 (car (list (* 2.0 (ann (* 3/4 2/3) Real)))) -- pair TR missed opt: precision-loss.rkt 49:26 (* 3/4 2/3) -- all args float-arg-expr, result not Float -- caused by: 49:29 3/4, 49:33 2/3 TR missed opt: precision-loss.rkt 49:14 (* 2.0 (ann (* 3/4 2/3) Real)) -- all args float-arg-expr, result not Float -- caused by: 49:26 (* 3/4 2/3) -TR missed opt: precision-loss.rkt 49:14 (* 2.0 (ann (* 3/4 2/3) Real)) -- exact ops inside float expr -- caused by: 49:26 (* 3/4 2/3) TR missed opt: precision-loss.rkt 49:26 (* 3/4 2/3) -- all args float-arg-expr, result not Float -- caused by: 49:29 3/4, 49:33 2/3 2.5 2.75 @@ -28,6 +25,9 @@ TR missed opt: precision-loss.rkt 49:26 (* 3/4 2/3) -- all args float-arg-expr, ) + + + #lang typed/racket ;; warn when the extra precision gained by doing exact computations would diff --git a/collects/tests/typed-racket/optimizer/tests/case-arrow.rkt b/collects/tests/typed-racket/optimizer/tests/case-arrow.rkt index 3d8c3f29..2a8f0dc8 100644 --- a/collects/tests/typed-racket/optimizer/tests/case-arrow.rkt +++ b/collects/tests/typed-racket/optimizer/tests/case-arrow.rkt @@ -2,29 +2,29 @@ ( TR missed opt: case-arrow.rkt 41:15 (- max min) -- all args float-arg-expr, result not Float -- caused by: 41:18 max, 41:22 min TR missed opt: case-arrow.rkt 41:12 (* (- max min) x) -- all args float-arg-expr, result not Float -- caused by: 41:15 (- max min), 41:27 x -TR missed opt: case-arrow.rkt 41:12 (* (- max min) x) -- exact ops inside float expr -- caused by: 41:15 (- max min) TR missed opt: case-arrow.rkt 41:15 (- max min) -- all args float-arg-expr, result not Float -- caused by: 41:18 max, 41:22 min TR missed opt: case-arrow.rkt 41:9 (/ (* (- max min) x) p) -- all args float-arg-expr, result not Float -- caused by: 41:12 (* (- max min) x), 41:30 p -TR missed opt: case-arrow.rkt 41:9 (/ (* (- max min) x) p) -- exact ops inside float expr -- caused by: 41:12 (* (- max min) x) TR missed opt: case-arrow.rkt 41:15 (- max min) -- all args float-arg-expr, result not Float -- caused by: 41:18 max, 41:22 min TR missed opt: case-arrow.rkt 41:12 (* (- max min) x) -- all args float-arg-expr, result not Float -- caused by: 41:15 (- max min), 41:27 x -TR missed opt: case-arrow.rkt 41:12 (* (- max min) x) -- exact ops inside float expr -- caused by: 41:15 (- max min) TR missed opt: case-arrow.rkt 41:15 (- max min) -- all args float-arg-expr, result not Float -- caused by: 41:18 max, 41:22 min TR missed opt: case-arrow.rkt 41:2 (+ min (/ (* (- max min) x) p)) -- all args float-arg-expr, result not Float -- caused by: 41:5 min, 41:9 (/ (* (- max min) x) p) -TR missed opt: case-arrow.rkt 41:2 (+ min (/ (* (- max min) x) p)) -- exact ops inside float expr -- caused by: 41:9 (/ (* (- max min) x) p) TR missed opt: case-arrow.rkt 41:15 (- max min) -- all args float-arg-expr, result not Float -- caused by: 41:18 max, 41:22 min TR missed opt: case-arrow.rkt 41:12 (* (- max min) x) -- all args float-arg-expr, result not Float -- caused by: 41:15 (- max min), 41:27 x -TR missed opt: case-arrow.rkt 41:12 (* (- max min) x) -- exact ops inside float expr -- caused by: 41:15 (- max min) TR missed opt: case-arrow.rkt 41:15 (- max min) -- all args float-arg-expr, result not Float -- caused by: 41:18 max, 41:22 min TR missed opt: case-arrow.rkt 41:9 (/ (* (- max min) x) p) -- all args float-arg-expr, result not Float -- caused by: 41:12 (* (- max min) x), 41:30 p -TR missed opt: case-arrow.rkt 41:9 (/ (* (- max min) x) p) -- exact ops inside float expr -- caused by: 41:12 (* (- max min) x) TR missed opt: case-arrow.rkt 41:15 (- max min) -- all args float-arg-expr, result not Float -- caused by: 41:18 max, 41:22 min TR missed opt: case-arrow.rkt 41:12 (* (- max min) x) -- all args float-arg-expr, result not Float -- caused by: 41:15 (- max min), 41:27 x -TR missed opt: case-arrow.rkt 41:12 (* (- max min) x) -- exact ops inside float expr -- caused by: 41:15 (- max min) TR missed opt: case-arrow.rkt 41:15 (- max min) -- all args float-arg-expr, result not Float -- caused by: 41:18 max, 41:22 min ) #lang typed/racket + + + + + + + ;; Typechecking functions with case-> types causes the body to be typechecked ;; multiple times, which is fine, except that it used to cause the type table ;; to only have information for the last branch (clobbering). This would cause diff --git a/collects/typed-racket/optimizer/float.rkt b/collects/typed-racket/optimizer/float.rkt index 63092e8e..a46b0cc6 100644 --- a/collects/typed-racket/optimizer/float.rkt +++ b/collects/typed-racket/optimizer/float.rkt @@ -147,7 +147,8 @@ (not (in-float-layer? s))) #'e] [_ #f])))) - (when (not (null? extra-precision-subexprs)) + (when (and (not (null? extra-precision-subexprs)) + (subtypeof? this-syntax -InexactReal)) (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."