Fixed a fixnum typechecking issue.

(cherry picked from commit 4c081c127a)
This commit is contained in:
Vincent St-Amour 2010-11-04 16:03:06 -04:00 committed by Eli Barzilay
parent e36787bdeb
commit b28bdb5bc5
3 changed files with 16 additions and 14 deletions

View File

@ -146,6 +146,12 @@
N]
(tc-e/t (if (let ([y 12]) y) 3 4) -PositiveFixnum)
(tc-e/t 3 -PositiveFixnum)
(tc-e/t 100 -PositiveFixnum)
(tc-e/t -100 -NegativeFixnum)
(tc-e/t 2147483647 -PositiveFixnum)
(tc-e/t -2147483647 -NegativeFixnum)
(tc-e/t 2147483648 -Pos)
(tc-e/t -2147483648 -Integer)
(tc-e/t "foo" -String)
(tc-e (+ 3 4) -Pos)
[tc-e/t (lambda: () 3) (t:-> -PositiveFixnum : -true-lfilter)]

View File

@ -22,15 +22,12 @@
(export tc-expr^)
;; Is the number a fixnum on all the platforms Racket supports?
;; This relies on Racket being compiled only on 32+ bit systems.
;; This check is done at compile time to typecheck literals.
;; Since a zo file compiled on a 64-bit system can be used on 32-bit
;; systems, we can't use the host fixnum? predicate, or large 64-bit
;; fixnums will typecheck as fixnums but not be actual fixnums on the
;; target system. In combination with fixnum typed optimizations, bad
;; things could happen.
(define (portable-fixnum? n)
(and (exact-integer? n)
(< n (expt 2 31))))
(< n (expt 2 31))
(> n (- (expt 2 31)))))
;; return the type of a literal value
;; scheme-value -> type
@ -45,9 +42,9 @@
[i:boolean (-val (syntax-e #'i))]
[i:identifier (-val (syntax-e #'i))]
[0 -Zero]
[(~var i (3d (conjoin number? portable-fixnum? positive?))) -PositiveFixnum]
[(~var i (3d (conjoin number? portable-fixnum? negative?))) -NegativeFixnum]
[(~var i (3d (conjoin number? portable-fixnum?))) -Fixnum]
[(~var i (3d (conjoin portable-fixnum? positive?))) -PositiveFixnum]
[(~var i (3d (conjoin portable-fixnum? negative?))) -NegativeFixnum]
[(~var i (3d (conjoin portable-fixnum?))) -Fixnum]
[(~var i (3d exact-positive-integer?)) -ExactPositiveInteger]
[(~var i (3d exact-nonnegative-integer?)) -ExactNonnegativeInteger]
[(~var i (3d exact-integer?)) -Integer]

View File

@ -174,13 +174,12 @@
(define -ExactPositiveInteger
(make-Base 'Exact-Positive-Integer #'exact-positive-integer?))
;; We can safely use the fixnum? prediate here, unlike in tc-expr-unit.
;; The fixnum? here will be part of the generated contracts, which run
;; on the target system, so we're safe.
;; We're generating a reference to fixnum? rather than calling it, so
;; we're safe from fixnum size issues on different platforms.
(define -PositiveFixnum
(make-Base 'Positive-Fixnum #'(and/c number? fixnum? positive?)))
(make-Base 'Positive-Fixnum #'(and/c fixnum? positive?)))
(define -NegativeFixnum
(make-Base 'Negative-Fixnum #'(and/c number? fixnum? negative?)))
(make-Base 'Negative-Fixnum #'(and/c fixnum? negative?)))
(define -Zero (-val 0))
(define -Real (*Un -InexactReal -ExactRational))