From f8cbf0dccd2e412ea6d7a6f998ad35d37094e180 Mon Sep 17 00:00:00 2001 From: Vincent St-Amour Date: Thu, 6 Jun 2013 13:01:43 -0400 Subject: [PATCH] Fix unsound unary fixnum subtraction optimization. Closes PR13826. original commit: 93d4a5d4266511166de9e8549afec89922a4eb84 --- .../tests/typed-racket/optimizer/tests/unary-fixnum.rkt | 7 ++++++- collects/typed-racket/optimizer/fixnum.rkt | 2 ++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/collects/tests/typed-racket/optimizer/tests/unary-fixnum.rkt b/collects/tests/typed-racket/optimizer/tests/unary-fixnum.rkt index 57f4e809..780fd9bd 100644 --- a/collects/tests/typed-racket/optimizer/tests/unary-fixnum.rkt +++ b/collects/tests/typed-racket/optimizer/tests/unary-fixnum.rkt @@ -1,10 +1,15 @@ #; ( -TR opt: unary-fixnum.rkt 10:0 (bitwise-not 4) -- unary fixnum +TR opt: unary-fixnum.rkt 13:0 (bitwise-not 4) -- unary fixnum +TR opt: unary-fixnum.rkt 14:0 (- (ann 2 Nonnegative-Fixnum)) -- unary fixnum -5 +-2 +2 ) #lang typed/scheme #:optimize (bitwise-not 4) +(- (ann 2 Nonnegative-Fixnum)) +(- (ann -2 Negative-Fixnum)) ; can't optimize negatives diff --git a/collects/typed-racket/optimizer/fixnum.rkt b/collects/typed-racket/optimizer/fixnum.rkt index b136c32f..4d55c5f7 100644 --- a/collects/typed-racket/optimizer/fixnum.rkt +++ b/collects/typed-racket/optimizer/fixnum.rkt @@ -131,6 +131,8 @@ #'(op.unsafe n1.opt n2.opt))) (pattern (#%plain-app (~and op (~literal -)) f:fixnum-expr) + ;; Invalid for `(- )'. + #:when (subtypeof? #'f -NonNegFixnum) #:with opt (begin (log-optimization "unary fixnum" fixnum-opt-msg this-syntax) (add-disappeared-use #'op)