diff --git a/collects/tests/typed-scheme/unit-tests/typecheck-tests.rkt b/collects/tests/typed-scheme/unit-tests/typecheck-tests.rkt index 5512094393..6c82cc3c2d 100644 --- a/collects/tests/typed-scheme/unit-tests/typecheck-tests.rkt +++ b/collects/tests/typed-scheme/unit-tests/typecheck-tests.rkt @@ -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)] diff --git a/collects/typed-scheme/typecheck/tc-expr-unit.rkt b/collects/typed-scheme/typecheck/tc-expr-unit.rkt index 0fd0402a41..6932cf09f6 100644 --- a/collects/typed-scheme/typecheck/tc-expr-unit.rkt +++ b/collects/typed-scheme/typecheck/tc-expr-unit.rkt @@ -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] diff --git a/collects/typed-scheme/types/abbrev.rkt b/collects/typed-scheme/types/abbrev.rkt index 68bbdbfc4d..fa0711a3ff 100644 --- a/collects/typed-scheme/types/abbrev.rkt +++ b/collects/typed-scheme/types/abbrev.rkt @@ -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))