From 15aa3d875f2f9ebb5340822ab4cea8af4f0f39fb Mon Sep 17 00:00:00 2001 From: Asumu Takikawa Date: Sat, 31 Oct 2015 02:24:48 -0400 Subject: [PATCH 01/24] Delete top-level hack that's no longer necessary The trampolining implementation of the top-level solves this without the dependency on rep/type-rep.rkt --- .../typed-racket/base-env/prims-contract.rkt | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/typed-racket-lib/typed-racket/base-env/prims-contract.rkt b/typed-racket-lib/typed-racket/base-env/prims-contract.rkt index bb2bae91..69ea6eca 100644 --- a/typed-racket-lib/typed-racket/base-env/prims-contract.rkt +++ b/typed-racket-lib/typed-racket/base-env/prims-contract.rkt @@ -83,11 +83,10 @@ ;; Lazily loaded b/c they're only used sometimes, so we save a lot ;; of loading by not having them when they are unneeded -(lazy-require ["../rep/type-rep.rkt" (make-Opaque Error?)] +(lazy-require ["../rep/type-rep.rkt" (Error?)] ["../types/utils.rkt" (fv)] [syntax/define (normalize-definition)] - [typed-racket/private/parse-type (parse-type)] - [typed-racket/env/type-alias-env (register-resolved-type-alias)]) + [typed-racket/private/parse-type (parse-type)]) (define (with-type* expr ty) (with-type #`(ann #,expr #,ty))) @@ -326,11 +325,6 @@ (pattern #:name-exists)) (syntax-parse stx [(_ ty:id pred:id lib (~optional ne:name-exists-kw) ...) - ;; This line appears redundant with the use of `define-type-alias` below, but - ;; it's actually necessary for top-level uses because this opaque type may appear - ;; in subsequent `require/typed` clauses, which needs to parse the types at - ;; expansion-time, not at typechecking time when aliases are installed. - (register-resolved-type-alias #'ty (make-Opaque #'pred)) (with-syntax ([hidden (generate-temporary #'pred)]) (quasisyntax/loc stx (begin From 0be2156521fdbe71640edb4349da237e8fe71659 Mon Sep 17 00:00:00 2001 From: Asumu Takikawa Date: Sat, 31 Oct 2015 02:27:38 -0400 Subject: [PATCH 02/24] Remove unused lazy-requires --- typed-racket-lib/typed-racket/base-env/prims-contract.rkt | 1 - typed-racket-lib/typed-racket/base-env/prims.rkt | 6 +----- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/typed-racket-lib/typed-racket/base-env/prims-contract.rkt b/typed-racket-lib/typed-racket/base-env/prims-contract.rkt index 69ea6eca..7f96ad89 100644 --- a/typed-racket-lib/typed-racket/base-env/prims-contract.rkt +++ b/typed-racket-lib/typed-racket/base-env/prims-contract.rkt @@ -85,7 +85,6 @@ ;; of loading by not having them when they are unneeded (lazy-require ["../rep/type-rep.rkt" (Error?)] ["../types/utils.rkt" (fv)] - [syntax/define (normalize-definition)] [typed-racket/private/parse-type (parse-type)]) (define (with-type* expr ty) diff --git a/typed-racket-lib/typed-racket/base-env/prims.rkt b/typed-racket-lib/typed-racket/base-env/prims.rkt index 155c0ebb..da4921b3 100644 --- a/typed-racket-lib/typed-racket/base-env/prims.rkt +++ b/typed-racket-lib/typed-racket/base-env/prims.rkt @@ -157,11 +157,7 @@ the typed racket language. ;; Lazily loaded b/c they're only used sometimes, so we save a lot ;; of loading by not having them when they are unneeded (begin-for-syntax - (lazy-require ["../rep/type-rep.rkt" (make-Opaque Error?)] - ["../types/utils.rkt" (fv)] - [syntax/define (normalize-definition)] - [typed-racket/private/parse-type (parse-type)] - [typed-racket/env/type-alias-env (register-resolved-type-alias)])) + (lazy-require [syntax/define (normalize-definition)])) (define-for-syntax (with-type* expr ty) (with-type #`(ann #,expr #,ty))) From 47ba1391f5778033f99c23b1039be3f13ac644b2 Mon Sep 17 00:00:00 2001 From: Asumu Takikawa Date: Sat, 31 Oct 2015 04:14:22 -0400 Subject: [PATCH 03/24] Add `begin-for-cond-contract` --- typed-racket-lib/typed-racket/utils/utils.rkt | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/typed-racket-lib/typed-racket/utils/utils.rkt b/typed-racket-lib/typed-racket/utils/utils.rkt index 1a560dbe..a41a61fa 100644 --- a/typed-racket-lib/typed-racket/utils/utils.rkt +++ b/typed-racket-lib/typed-racket/utils/utils.rkt @@ -100,7 +100,8 @@ at least theoretically. define/cond-contract/provide define-for-cond-contract provide-for-cond-contract - require-for-cond-contract) + require-for-cond-contract + begin-for-cond-contract) (define-require-syntax contract-req (if enable-contracts? @@ -126,6 +127,12 @@ at least theoretically. (syntax-parser [(_ require-spec:expr ...) #'(begin)]))) +(define-syntax begin-for-cond-contract + (if enable-contracts? + (make-rename-transformer #'begin) + (syntax-parser + [(_ e:expr ...) #'(begin)]))) + (define-syntax-rule (define/cond-contract/provide (name . args) c . body) (begin (define/cond-contract name c From ae0741aaa7d4b9530398e9caf930d93e8e606c5f Mon Sep 17 00:00:00 2001 From: Asumu Takikawa Date: Sat, 31 Oct 2015 03:04:35 -0400 Subject: [PATCH 04/24] Use cond-contract forms instead of lazy-require --- .../typed-racket/rep/filter-rep.rkt | 27 ++++++++++--------- 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/typed-racket-lib/typed-racket/rep/filter-rep.rkt b/typed-racket-lib/typed-racket/rep/filter-rep.rkt index cb7235e6..688ef579 100644 --- a/typed-racket-lib/typed-racket/rep/filter-rep.rkt +++ b/typed-racket-lib/typed-racket/rep/filter-rep.rkt @@ -1,20 +1,22 @@ #lang racket/base -;;TODO use contract-req -(require "rep-utils.rkt" "free-variance.rkt" racket/contract/base - racket/lazy-require) +(require "../utils/utils.rkt" "rep-utils.rkt" "free-variance.rkt") -;; TODO use something other than lazy-require. -(lazy-require ["type-rep.rkt" (Type/c Univ? Bottom?)] - ["object-rep.rkt" (Path?)]) +(provide hash-name filter-equal?) -(provide Filter/c FilterSet/c name-ref/c hash-name filter-equal?) +(begin-for-cond-contract + (require racket/contract/base racket/lazy-require) + (lazy-require ["type-rep.rkt" (Type/c Univ? Bottom?)] + ["object-rep.rkt" (Path?)])) -(define (Filter/c-predicate? e) +(provide-for-cond-contract Filter/c FilterSet/c name-ref/c) + +(define-for-cond-contract (Filter/c-predicate? e) (and (Filter? e) (not (NoFilter? e)) (not (FilterSet? e)))) -(define Filter/c (flat-named-contract 'Filter Filter/c-predicate?)) +(define-for-cond-contract Filter/c + (flat-named-contract 'Filter Filter/c-predicate?)) -(define FilterSet/c +(define-for-cond-contract FilterSet/c (flat-named-contract 'FilterSet (λ (e) (or (FilterSet? e) (NoFilter? e))))) @@ -22,10 +24,11 @@ ;; A Name-Ref is any value that represents an object. ;; As an identifier, it represents a free variable in the environment ;; As a list, it represents a De Bruijn indexed bound variable -(define name-ref/c (or/c identifier? (list/c integer? integer?))) +(define-for-cond-contract name-ref/c + (or/c identifier? (list/c integer? integer?))) (define (hash-name v) (if (identifier? v) (hash-id v) (list v))) -(define ((length>=/c len) l) +(define-for-cond-contract ((length>=/c len) l) (and (list? l) (>= (length l) len))) From ea6968f1d9e48d4c13b86a558a333b9482dacbdd Mon Sep 17 00:00:00 2001 From: Vincent St-Amour Date: Mon, 2 Nov 2015 13:26:30 -0600 Subject: [PATCH 05/24] Don't attempt to unfold pair opts when we have no type info. Fixes compilation of the `midi-readwrite` package. --- typed-racket-lib/typed-racket/optimizer/pair.rkt | 1 + 1 file changed, 1 insertion(+) diff --git a/typed-racket-lib/typed-racket/optimizer/pair.rkt b/typed-racket-lib/typed-racket/optimizer/pair.rkt index a5f97a30..54f2b657 100644 --- a/typed-racket-lib/typed-racket/optimizer/pair.rkt +++ b/typed-racket-lib/typed-racket/optimizer/pair.rkt @@ -137,6 +137,7 @@ [(tc-result1: t) t])] [res #'e.arg]) ([accessor (in-list (reverse (syntax->list #'e.alt)))]) + #:break (not t) (cond [(subtype t (-pair Univ Univ)) ; safe to optimize this one layer (syntax-parse accessor From cb35383143e28ca0f743440ba54734a1750760ec Mon Sep 17 00:00:00 2001 From: Sam Tobin-Hochstadt Date: Tue, 27 Oct 2015 17:11:15 -0400 Subject: [PATCH 06/24] Add test case for issue #215. --- typed-racket-test/succeed/match-or.rkt | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 typed-racket-test/succeed/match-or.rkt diff --git a/typed-racket-test/succeed/match-or.rkt b/typed-racket-test/succeed/match-or.rkt new file mode 100644 index 00000000..8fee31d5 --- /dev/null +++ b/typed-racket-test/succeed/match-or.rkt @@ -0,0 +1,7 @@ +#lang typed/racket + +(: f : (Listof Integer) (Listof Integer) → Integer) +(define (f xs ys) + (match* (xs ys) + [((list a b) (or (list a b) (list b a))) (+ a b)] + [(_ _) 42])) \ No newline at end of file From ad0c69ea2965e4bd2cec6fd5b18cc397166dd797 Mon Sep 17 00:00:00 2001 From: Sam Tobin-Hochstadt Date: Mon, 2 Nov 2015 09:20:23 -0500 Subject: [PATCH 07/24] Make these definitions safe again. As of this moment, the performance win on new-metrics.rkt for using the unsafe version is about 1% (avg over 10 runs), which isn't enough to make it worth the segfaults. I believe that changes to the JIT since 2012 (when the unsafe ops were added) have sped up struct access. --- typed-racket-lib/typed-racket/rep/rep-utils.rkt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/typed-racket-lib/typed-racket/rep/rep-utils.rkt b/typed-racket-lib/typed-racket/rep/rep-utils.rkt index b51b2921..b3fb2e46 100644 --- a/typed-racket-lib/typed-racket/rep/rep-utils.rkt +++ b/typed-racket-lib/typed-racket/rep/rep-utils.rkt @@ -362,8 +362,8 @@ [PathElem def-pathelem #:PathElem pathelem-case print-pathelem pathelem-name-ht pathelem-rec-id]) ;; NOTE: change these if the definitions above change, or everything will segfault -(define-syntax-rule (unsafe-Rep-seq v) (unsafe-struct*-ref v 0)) -(define-syntax-rule (unsafe-Type-key v) (unsafe-struct*-ref v 4)) +(define-syntax-rule (unsafe-Rep-seq v) (Rep-seq v)) +(define-syntax-rule (unsafe-Type-key v) (Type-key v)) (provide unsafe-Rep-seq unsafe-Type-key) (define (Rep-values rep) From a3d29d9e03c3e175274a2a313de62cbd68ab695e Mon Sep 17 00:00:00 2001 From: Vincent St-Amour Date: Mon, 2 Nov 2015 15:45:27 -0600 Subject: [PATCH 08/24] Align float-complex/float division with Racket more. Found using random testing. --- .../typed-racket/optimizer/float-complex.rkt | 23 +++++++++++++++---- typed-racket-test/optimizer/known-bugs.rkt | 16 ++++++------- .../optimizer/tests/float-complex-float.rkt | 5 ++++ 3 files changed, 32 insertions(+), 12 deletions(-) diff --git a/typed-racket-lib/typed-racket/optimizer/float-complex.rkt b/typed-racket-lib/typed-racket/optimizer/float-complex.rkt index d3e97d09..6801b284 100644 --- a/typed-racket-lib/typed-racket/optimizer/float-complex.rkt +++ b/typed-racket-lib/typed-racket/optimizer/float-complex.rkt @@ -57,7 +57,11 @@ ;; a+bi / c+di, names for real and imag parts of result -> one let-values binding clause (define (unbox-one-complex-/ a b c d res-real res-imag) - (define both-real? (and (0.0? b) (0.0? d))) + (define first-arg-real? (syntax-property b 'was-real?)) + (define second-arg-real? (syntax-property d 'was-real?)) + ;; if both are real, we can short-circuit a lot + (define both-real? (and first-arg-real? second-arg-real?)) + ;; we have the same cases as the Racket `/' primitive (except for the non-float ones) (define d=0-case #`(values (unsafe-fl+ (unsafe-fl/ #,a #,c) @@ -85,10 +89,17 @@ (unsafe-fl/ (unsafe-fl- (unsafe-fl* b r) a) den))]) (values (unsafe-fl/ (unsafe-fl+ b (unsafe-fl* a r)) den) i))) + (cond [both-real? #`[(#,res-real #,res-imag) (values (unsafe-fl/ #,a #,c) 0.0)]] ; currently not propagated + [second-arg-real? + #`[(#,res-real #,res-imag) + (values (unsafe-fl/ #,a #,c) + (unsafe-fl/ #,b #,c))]] + [first-arg-real? + (unbox-one-float-complex-/ a c d res-real res-imag)] [else #`[(#,res-real #,res-imag) (cond [(unsafe-fl= #,d 0.0) #,d=0-case] @@ -112,7 +123,7 @@ #`(let* ([cm (unsafe-flabs #,c)] [dm (unsafe-flabs #,d)] [swap? (unsafe-fl< cm dm)] - [a #,a] + [a #,a] ; don't swap with `b` (`0`) here, but handle below [c (if swap? #,d #,c)] [d (if swap? #,c #,d)] [r (unsafe-fl/ c d)] @@ -332,10 +343,14 @@ ((real-binding) (unsafe-flreal-part e*)) ((imag-binding) (unsafe-flimag-part e*)))) - ;; The following optimization is incorrect and causes bugs because it turns exact numbers into inexact (pattern e:number-expr #:with e* (generate-temporary) - #:with (real-binding imag-binding) (binding-names) + #:with (real-binding imag-binding*) (binding-names) + #:with imag-binding (if (subtypeof? #'e -Real) + ;; values that were originally reals may need to be + ;; handled specially + (syntax-property #'imag-binding 'was-real? #t) + #'imag-binding) #:do [(log-unboxing-opt (if (subtypeof? #'e -Flonum) "float in complex ops" diff --git a/typed-racket-test/optimizer/known-bugs.rkt b/typed-racket-test/optimizer/known-bugs.rkt index 3601f5d3..dcc0bc2e 100644 --- a/typed-racket-test/optimizer/known-bugs.rkt +++ b/typed-racket-test/optimizer/known-bugs.rkt @@ -58,29 +58,29 @@ ;; Arguments are converted to inexact too early (bad-opt (* (make-rectangular -inf.0 1) (* 1 1))) - (bad-opt (/ -inf.0-inf.0i 8)) + (good-opt (/ -inf.0-inf.0i 8)) (good-opt (- (* -1 1 +nan.0) 1.0+1.0i)) (good-opt (- (* (/ 6 11) (/ 1.2345678f0 123456.7f0)) (make-rectangular 0.0 0.3))) - (bad-opt (/ 1.0 0.0+0.0i)) + (good-opt (/ 1.0 0.0+0.0i)) (good-opt (+ 0.0+0.0i (* 1 1 +inf.0))) (bad-opt (* 1.0f-30 1.0f-30 1.0e60+1.0e60i)) ;; Unary division has bad underflow (good-opt (/ (make-rectangular 1e+100 1e-300))) (good-opt (/ 0.5+1.7e+308i)) - (bad-opt (/ 1 (make-rectangular 1e+100 1e-300))) - (bad-opt (/ 1 0.5+1.7e+308i)) + (good-opt (/ 1 (make-rectangular 1e+100 1e-300))) + (good-opt (/ 1 0.5+1.7e+308i)) ;; Division of complex 0 should only make part of the result nan (good-opt (/ 0.0+0.0i)) - (bad-opt (/ 1 0.0+0.0i)) - (bad-opt (/ 1.5 -3.0+9.8e-324i)) + (good-opt (/ 1 0.0+0.0i)) + (good-opt (/ 1.5 -3.0+9.8e-324i)) ;; Division of complex infinity should only make part of the result nan (good-opt (/ (make-rectangular 1.0 +inf.0))) (good-opt (/ (make-rectangular +inf.0 1.0))) - (bad-opt (/ 1 (make-rectangular 1.0 +inf.0))) - (bad-opt (/ 1 (make-rectangular +inf.0 1.0))) + (good-opt (/ 1 (make-rectangular 1.0 +inf.0))) + (good-opt (/ 1 (make-rectangular +inf.0 1.0))) ;; Exp of large real should have 0 imaginary component (good-opt (+ (exp 1.7976931348623151e+308) 0.0+0.0i)) diff --git a/typed-racket-test/optimizer/tests/float-complex-float.rkt b/typed-racket-test/optimizer/tests/float-complex-float.rkt index e61162a2..7ec33915 100644 --- a/typed-racket-test/optimizer/tests/float-complex-float.rkt +++ b/typed-racket-test/optimizer/tests/float-complex-float.rkt @@ -16,12 +16,16 @@ TR opt: float-complex-float.rkt 5:0 (- 1.0+2.0i 2.0+4.0i 3.0) -- unboxed binary TR opt: float-complex-float.rkt 5:12 2.0+4.0i -- unboxed literal TR opt: float-complex-float.rkt 5:21 3.0 -- float in complex ops TR opt: float-complex-float.rkt 5:3 1.0+2.0i -- unboxed literal +TR opt: float-complex-float.rkt 6:0 (/ 0.0 +inf.0-1.0i) -- unboxed binary float complex +TR opt: float-complex-float.rkt 6:3 0.0 -- float in complex ops +TR opt: float-complex-float.rkt 6:7 +inf.0-1.0i -- unboxed literal END #< Date: Mon, 2 Nov 2015 16:09:32 -0600 Subject: [PATCH 09/24] Fix interaction of sign and underflow in fl/. Found using random testing. --- typed-racket-lib/typed-racket/base-env/base-env-numeric.rkt | 2 +- typed-racket-test/unit-tests/typecheck-tests.rkt | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/typed-racket-lib/typed-racket/base-env/base-env-numeric.rkt b/typed-racket-lib/typed-racket/base-env/base-env-numeric.rkt index 0f17d500..00bf1603 100644 --- a/typed-racket-lib/typed-racket/base-env/base-env-numeric.rkt +++ b/typed-racket-lib/typed-racket/base-env/base-env-numeric.rkt @@ -489,7 +489,7 @@ (fl-type-lambda (from-cases (-FlZero -Fl . -> . -FlZero) ;; we don't have Pos Pos -> Pos, possible underflow - (-NonNegFl -NonNegFl . -> . -NonNegFl) + (-PosFl -PosFl . -> . -NonNegFl) (commutative-binop -PosFl -NegFl -NonPosFl) (-NegFl -NegFl . -> . -NonNegFl) (binop -Fl)))) diff --git a/typed-racket-test/unit-tests/typecheck-tests.rkt b/typed-racket-test/unit-tests/typecheck-tests.rkt index 94a7a928..ffc5532e 100644 --- a/typed-racket-test/unit-tests/typecheck-tests.rkt +++ b/typed-racket-test/unit-tests/typecheck-tests.rkt @@ -450,6 +450,7 @@ (tc-e (min (ann 3 Fixnum) (ann 3 Fixnum)) -Fixnum) (tc-e (min (ann -2 Negative-Fixnum) (ann 3 Fixnum)) -NegFixnum) (tc-e (min (ann 3 Fixnum) (ann -2 Negative-Fixnum)) -NegFixnum) + (tc-e (fl/ 1.7976931348623157e+308 -0.0e0) -Flonum) (tc-e (exact->inexact (ann 3 Number)) (t:Un -InexactReal -InexactComplex)) (tc-e (exact->inexact 3) -PosFlonum) (tc-e (exact->inexact -3) -NegFlonum) From ca9306bb1d4f14f8ffad4aed66297c88717a650a Mon Sep 17 00:00:00 2001 From: Vincent St-Amour Date: Mon, 2 Nov 2015 16:29:58 -0600 Subject: [PATCH 10/24] Use more precise notion of "real argument" for multiplication too. Found using random testing. --- .../typed-racket/optimizer/float-complex.rkt | 52 ++++++++++--------- typed-racket-test/optimizer/known-bugs.rkt | 2 +- .../optimizer/tests/float-complex-float.rkt | 6 +++ 3 files changed, 34 insertions(+), 26 deletions(-) diff --git a/typed-racket-lib/typed-racket/optimizer/float-complex.rkt b/typed-racket-lib/typed-racket/optimizer/float-complex.rkt index 6801b284..e6e00a0c 100644 --- a/typed-racket-lib/typed-racket/optimizer/float-complex.rkt +++ b/typed-racket-lib/typed-racket/optimizer/float-complex.rkt @@ -50,10 +50,6 @@ "The optimizer could optimize it better if it had type Float-Complex.") this-syntax)) -;; If a part is 0.0? -(define (0.0? stx) - (equal? (syntax->datum stx) 0.0)) - ;; a+bi / c+di, names for real and imag parts of result -> one let-values binding clause (define (unbox-one-complex-/ a b c d res-real res-imag) @@ -209,27 +205,33 @@ #'(cs.imag-binding ...)) (list #'imag-binding))] [res '()]) - (if (null? e1) - (reverse res) - (loop (car rs) (car is) (cdr e1) (cdr e2) (cdr rs) (cdr is) - ;; complex multiplication, imag part, then real part (reverse) - ;; we eliminate operations on the imaginary parts of reals - (let ((o-real? (0.0? o2)) - (e-real? (0.0? (car e2)))) - (list* #`((#,(car is)) - #,(cond ((and o-real? e-real?) #'0.0) - (o-real? #`(unsafe-fl* #,o1 #,(car e2))) - (e-real? #`(unsafe-fl* #,o2 #,(car e1))) - (else - #`(unsafe-fl+ (unsafe-fl* #,o2 #,(car e1)) - (unsafe-fl* #,o1 #,(car e2)))))) - #`((#,(car rs)) - #,(cond ((or o-real? e-real?) - #`(unsafe-fl* #,o1 #,(car e1))) - (else - #`(unsafe-fl- (unsafe-fl* #,o1 #,(car e1)) - (unsafe-fl* #,o2 #,(car e2)))))) - res)))))))) + (cond + [(null? e1) + (reverse res)] + [else + (define o-real? (syntax-property o2 'was-real?)) + (define e-real? (syntax-property (car e2) 'was-real?)) + (define both-real? (and o-real? e-real?)) + (define new-imag-id (if both-real? + (syntax-property (car is) 'was-real? #t) + (car is))) + (loop (car rs) new-imag-id (cdr e1) (cdr e2) (cdr rs) (cdr is) + ;; complex multiplication, imag part, then real part (reverse) + ;; we eliminate operations on the imaginary parts of reals + (list* #`((#,new-imag-id) + #,(cond ((and o-real? e-real?) #'0.0) + (o-real? #`(unsafe-fl* #,o1 #,(car e2))) + (e-real? #`(unsafe-fl* #,o2 #,(car e1))) + (else + #`(unsafe-fl+ (unsafe-fl* #,o2 #,(car e1)) + (unsafe-fl* #,o1 #,(car e2)))))) + #`((#,(car rs)) + #,(cond ((or o-real? e-real?) + #`(unsafe-fl* #,o1 #,(car e1))) + (else + #`(unsafe-fl- (unsafe-fl* #,o1 #,(car e1)) + (unsafe-fl* #,o2 #,(car e2)))))) + res))]))))) (pattern (#%plain-app op:*^ :unboxed-float-complex-opt-expr) #:when (subtypeof? this-syntax -FloatComplex) #:do [(log-unboxing-opt "unboxed unary float complex")]) diff --git a/typed-racket-test/optimizer/known-bugs.rkt b/typed-racket-test/optimizer/known-bugs.rkt index dcc0bc2e..72af51c3 100644 --- a/typed-racket-test/optimizer/known-bugs.rkt +++ b/typed-racket-test/optimizer/known-bugs.rkt @@ -57,7 +57,7 @@ (test-suite "Known bugs" ;; Arguments are converted to inexact too early - (bad-opt (* (make-rectangular -inf.0 1) (* 1 1))) + (good-opt (* (make-rectangular -inf.0 1) (* 1 1))) (good-opt (/ -inf.0-inf.0i 8)) (good-opt (- (* -1 1 +nan.0) 1.0+1.0i)) (good-opt (- (* (/ 6 11) (/ 1.2345678f0 123456.7f0)) (make-rectangular 0.0 0.3))) diff --git a/typed-racket-test/optimizer/tests/float-complex-float.rkt b/typed-racket-test/optimizer/tests/float-complex-float.rkt index 7ec33915..e3170021 100644 --- a/typed-racket-test/optimizer/tests/float-complex-float.rkt +++ b/typed-racket-test/optimizer/tests/float-complex-float.rkt @@ -19,6 +19,10 @@ TR opt: float-complex-float.rkt 5:3 1.0+2.0i -- unboxed literal TR opt: float-complex-float.rkt 6:0 (/ 0.0 +inf.0-1.0i) -- unboxed binary float complex TR opt: float-complex-float.rkt 6:3 0.0 -- float in complex ops TR opt: float-complex-float.rkt 6:7 +inf.0-1.0i -- unboxed literal +TR opt: float-complex-float.rkt 7:0 (* -0.9263371220283309 3/2 (make-rectangular +inf.f 0.7692234292042541)) -- unboxed binary float complex +TR opt: float-complex-float.rkt 7:23 3/2 -- non float complex in complex ops +TR opt: float-complex-float.rkt 7:27 (make-rectangular +inf.f 0.7692234292042541) -- make-rectangular elimination +TR opt: float-complex-float.rkt 7:3 -0.9263371220283309 -- float in complex ops END #< Date: Mon, 2 Nov 2015 16:43:37 -0600 Subject: [PATCH 11/24] Fix type of expt when mixing floats and float complexes. Found using random testing. --- .../typed-racket/base-env/base-env-numeric.rkt | 8 ++++++-- typed-racket-test/unit-tests/typecheck-tests.rkt | 1 + 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/typed-racket-lib/typed-racket/base-env/base-env-numeric.rkt b/typed-racket-lib/typed-racket/base-env/base-env-numeric.rkt index 00bf1603..1bf7d85f 100644 --- a/typed-racket-lib/typed-racket/base-env/base-env-numeric.rkt +++ b/typed-racket-lib/typed-racket/base-env/base-env-numeric.rkt @@ -1621,8 +1621,12 @@ (-InexactReal (Un -NegInt -PosInt) . -> . -InexactReal) (-InexactReal -InexactReal . -> . (Un -InexactReal -InexactComplex)) (-Real -Int . -> . -Real) - (-FloatComplex (Un -InexactComplex -InexactReal) . -> . -FloatComplex) - (-SingleFlonumComplex (Un -SingleFlonum -SingleFlonumComplex) . -> . -SingleFlonumComplex) + (-FloatComplex -FloatComplex . -> . -FloatComplex) + (-FloatComplex -Flonum . -> . (Un -FloatComplex -Flonum)) + (-FloatComplex -InexactReal . -> . (Un -FloatComplex -InexactReal)) + (-FloatComplex -InexactComplex . -> . -FloatComplex) + (-SingleFlonumComplex -SingleFlonumComplex . -> . -SingleFlonumComplex) + (-SingleFlonumComplex -SingleFlonum . -> . (Un -SingleFlonumComplex -SingleFlonum)) ((Un -InexactReal -InexactComplex) -InexactComplex . -> . -InexactComplex) (-InexactComplex (Un -InexactReal -InexactComplex) . -> . -InexactComplex) (N N . -> . N))] diff --git a/typed-racket-test/unit-tests/typecheck-tests.rkt b/typed-racket-test/unit-tests/typecheck-tests.rkt index ffc5532e..e42f81ef 100644 --- a/typed-racket-test/unit-tests/typecheck-tests.rkt +++ b/typed-racket-test/unit-tests/typecheck-tests.rkt @@ -451,6 +451,7 @@ (tc-e (min (ann -2 Negative-Fixnum) (ann 3 Fixnum)) -NegFixnum) (tc-e (min (ann 3 Fixnum) (ann -2 Negative-Fixnum)) -NegFixnum) (tc-e (fl/ 1.7976931348623157e+308 -0.0e0) -Flonum) + (tc-e (expt (make-rectangular 3 -1.7976931348623157e+308) (flacos (real->double-flonum 59.316513f0))) (t:Un -Flonum -FloatComplex)) (tc-e (exact->inexact (ann 3 Number)) (t:Un -InexactReal -InexactComplex)) (tc-e (exact->inexact 3) -PosFlonum) (tc-e (exact->inexact -3) -NegFlonum) From f14793c4624c58912ccae0d0db90dff87c46030a Mon Sep 17 00:00:00 2001 From: Vincent St-Amour Date: Tue, 3 Nov 2015 14:11:49 -0600 Subject: [PATCH 12/24] Remove potentially incorrect unsafe operation. --- typed-racket-lib/typed-racket/base-env/prims.rkt | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/typed-racket-lib/typed-racket/base-env/prims.rkt b/typed-racket-lib/typed-racket/base-env/prims.rkt index da4921b3..0ac4028b 100644 --- a/typed-racket-lib/typed-racket/base-env/prims.rkt +++ b/typed-racket-lib/typed-racket/base-env/prims.rkt @@ -808,7 +808,13 @@ the typed racket language. (define i 0) (for (clauses ...) (define v body-expr) - (cond [(unsafe-fx= i 0) (define new-vs (ann (make-vector n v) T)) + ;; can't use `unsafe-fx=` here + ;; if `n` is larger than a fixnum, this is unsafe, and we + ;; don't know whether that's the case until we try creating + ;; the vector + ;; other unsafe ops are after vector allocation, and so are + ;; fine + (cond [(= i 0) (define new-vs (ann (make-vector n v) T)) (set! vs new-vs)] [else (unsafe-vector-set! vs i v)]) (set! i (unsafe-fx+ i 1)) From 59b5cb734680dc337f9e6f12c032e82f36ceb2f6 Mon Sep 17 00:00:00 2001 From: Vincent St-Amour Date: Tue, 3 Nov 2015 14:25:49 -0600 Subject: [PATCH 13/24] Remove unused dependency. --- typed-racket-lib/typed-racket/rep/rep-utils.rkt | 1 - 1 file changed, 1 deletion(-) diff --git a/typed-racket-lib/typed-racket/rep/rep-utils.rkt b/typed-racket-lib/typed-racket/rep/rep-utils.rkt index b3fb2e46..cbe650ac 100644 --- a/typed-racket-lib/typed-racket/rep/rep-utils.rkt +++ b/typed-racket-lib/typed-racket/rep/rep-utils.rkt @@ -7,7 +7,6 @@ "interning.rkt" racket/lazy-require racket/stxparam - racket/unsafe/ops (for-syntax racket/match (except-in syntax/parse id identifier keyword) From 5b57736af6e227edbf87021be3abe026caccd6ea Mon Sep 17 00:00:00 2001 From: Vincent St-Amour Date: Tue, 3 Nov 2015 14:32:23 -0600 Subject: [PATCH 14/24] Guard some unsafe ops. --- typed-racket-lib/typed-racket/types/current-seen.rkt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/typed-racket-lib/typed-racket/types/current-seen.rkt b/typed-racket-lib/typed-racket/types/current-seen.rkt index 33baac42..ed92b27c 100644 --- a/typed-racket-lib/typed-racket/types/current-seen.rkt +++ b/typed-racket-lib/typed-racket/types/current-seen.rkt @@ -24,5 +24,5 @@ A)) (define (seen? ss st cs) (for/or ([i (in-list cs)]) - (and (eq? ss (unsafe-car i)) (eq? st (unsafe-cdr i))))) + (and (pair? i) (eq? ss (unsafe-car i)) (eq? st (unsafe-cdr i))))) From 8f32aad3ee25cf9ee84a1989f4f0308ff1a8556b Mon Sep 17 00:00:00 2001 From: Vincent St-Amour Date: Tue, 3 Nov 2015 14:34:39 -0600 Subject: [PATCH 15/24] Remove not-actually-unsafe unsafe operations. --- typed-racket-lib/typed-racket/rep/rep-utils.rkt | 11 +++-------- typed-racket-lib/typed-racket/types/subtype.rkt | 8 ++++---- 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/typed-racket-lib/typed-racket/rep/rep-utils.rkt b/typed-racket-lib/typed-racket/rep/rep-utils.rkt index cbe650ac..c6d5b6bd 100644 --- a/typed-racket-lib/typed-racket/rep/rep-utils.rkt +++ b/typed-racket-lib/typed-racket/rep/rep-utils.rkt @@ -32,9 +32,9 @@ (define-struct Rep (seq free-vars free-idxs stx) #:transparent #:methods gen:equal+hash [(define (equal-proc x y recur) - (eq? (unsafe-Rep-seq x) (unsafe-Rep-seq y))) - (define (hash-proc x recur) (unsafe-Rep-seq x)) - (define (hash2-proc x recur) (unsafe-Rep-seq x))]) + (eq? (Rep-seq x) (Rep-seq y))) + (define (hash-proc x recur) (Rep-seq x)) + (define (hash2-proc x recur) (Rep-seq x))]) ;; evil tricks for hygienic yet unhygienic-looking reference ;; in say def-type for type-ref-id @@ -360,11 +360,6 @@ [Object def-object #:Object object-case print-object object-name-ht object-rec-id] [PathElem def-pathelem #:PathElem pathelem-case print-pathelem pathelem-name-ht pathelem-rec-id]) -;; NOTE: change these if the definitions above change, or everything will segfault -(define-syntax-rule (unsafe-Rep-seq v) (Rep-seq v)) -(define-syntax-rule (unsafe-Type-key v) (Type-key v)) -(provide unsafe-Rep-seq unsafe-Type-key) - (define (Rep-values rep) (match rep [(? (lambda (e) (or (Filter? e) diff --git a/typed-racket-lib/typed-racket/types/subtype.rkt b/typed-racket-lib/typed-racket/types/subtype.rkt index bb7c8362..1c190a28 100644 --- a/typed-racket-lib/typed-racket/types/subtype.rkt +++ b/typed-racket-lib/typed-racket/types/subtype.rkt @@ -237,8 +237,8 @@ ;; is s a subtype of t, taking into account previously seen pairs A (define/cond-contract (subtype* A s t) (c:-> (c:listof (c:cons/c fixnum? fixnum?)) Type? Type? c:any/c) - (define ss (unsafe-Rep-seq s)) - (define st (unsafe-Rep-seq t)) + (define ss (Rep-seq s)) + (define st (Rep-seq t)) (early-return #:return-when (or (eq? ss st) (seen? ss st A)) A (define cr (let ([inner (hash-ref subtype-cache st #f)]) @@ -246,8 +246,8 @@ (hash-ref inner ss 'missing) 'missing))) #:return-when (boolean? cr) (and cr A) - (define ks (unsafe-Type-key s)) - (define kt (unsafe-Type-key t)) + (define ks (Type-key s)) + (define kt (Type-key t)) #:return-when (and (symbol? ks) (symbol? kt) (not (eq? ks kt))) #f #:return-when (and (symbol? ks) (pair? kt) (not (memq ks kt))) #f #:return-when From 207a12fa2399a70a7cf8bc76b89d9c7c7cb01ded Mon Sep 17 00:00:00 2001 From: Vincent St-Amour Date: Tue, 3 Nov 2015 14:35:32 -0600 Subject: [PATCH 16/24] Fix the fix to compound pair optimimzations. Previous version could drop code on the ground in some cases. --- typed-racket-lib/typed-racket/optimizer/pair.rkt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/typed-racket-lib/typed-racket/optimizer/pair.rkt b/typed-racket-lib/typed-racket/optimizer/pair.rkt index 54f2b657..09fb59bd 100644 --- a/typed-racket-lib/typed-racket/optimizer/pair.rkt +++ b/typed-racket-lib/typed-racket/optimizer/pair.rkt @@ -137,9 +137,8 @@ [(tc-result1: t) t])] [res #'e.arg]) ([accessor (in-list (reverse (syntax->list #'e.alt)))]) - #:break (not t) (cond - [(subtype t (-pair Univ Univ)) ; safe to optimize this one layer + [(and t (subtype t (-pair Univ Univ))) ; safe to optimize this one layer (syntax-parse accessor [op:pair-op (log-pair-opt) From 58e97f83ea01c892a3c7e38b7695bd06a137a831 Mon Sep 17 00:00:00 2001 From: Vincent St-Amour Date: Tue, 3 Nov 2015 15:47:32 -0600 Subject: [PATCH 17/24] Fix sign propagation for division. Found using random testing. --- .../typed-racket/base-env/base-env-numeric.rkt | 8 ++++---- typed-racket-test/unit-tests/typecheck-tests.rkt | 1 + 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/typed-racket-lib/typed-racket/base-env/base-env-numeric.rkt b/typed-racket-lib/typed-racket/base-env/base-env-numeric.rkt index 1bf7d85f..f6b34c60 100644 --- a/typed-racket-lib/typed-racket/base-env/base-env-numeric.rkt +++ b/typed-racket-lib/typed-racket/base-env/base-env-numeric.rkt @@ -1166,10 +1166,10 @@ ;; reals (varop-1+ -NonNegReal -NonNegReal) (-> -NonPosReal -NonPosReal) - (-> -NonPosReal -NonPosReal -NonNegReal) - (-> -NonPosReal -NonNegReal -NonPosReal) - (-> -NonNegReal -NonPosReal -NonPosReal) - (-> -NonPosReal -NonPosReal -NonPosReal -NonPosReal) + (-> -NegReal -NegReal -NonNegReal) ; 0.0 is non-neg, but doesn't preserve sign + (-> -NegReal -PosReal -NonPosReal) ; idem + (-> -PosReal -NegReal -NonPosReal) ; idem + (-> -NegReal -NegReal -NegReal -NonPosReal) ; idem (varop-1+ -Real) ;; complexes (varop-1+ -FloatComplex) diff --git a/typed-racket-test/unit-tests/typecheck-tests.rkt b/typed-racket-test/unit-tests/typecheck-tests.rkt index e42f81ef..c608dbd8 100644 --- a/typed-racket-test/unit-tests/typecheck-tests.rkt +++ b/typed-racket-test/unit-tests/typecheck-tests.rkt @@ -453,6 +453,7 @@ (tc-e (fl/ 1.7976931348623157e+308 -0.0e0) -Flonum) (tc-e (expt (make-rectangular 3 -1.7976931348623157e+308) (flacos (real->double-flonum 59.316513f0))) (t:Un -Flonum -FloatComplex)) (tc-e (exact->inexact (ann 3 Number)) (t:Un -InexactReal -InexactComplex)) + (tc-e (/ (round (exact-round -2.7393196f0)) (real->double-flonum (inexact->exact (real->single-flonum -0.0)))) -Real) (tc-e (exact->inexact 3) -PosFlonum) (tc-e (exact->inexact -3) -NegFlonum) (tc-e (real->double-flonum 0.0) -FlonumPosZero) From 89a06cfae6352f54794f3d589d7421f40e6fc036 Mon Sep 17 00:00:00 2001 From: Vincent St-Amour Date: Tue, 3 Nov 2015 16:02:05 -0600 Subject: [PATCH 18/24] Fix bitwise-and on negative numbers. Found using random testing. --- .../typed-racket/base-env/base-env-numeric.rkt | 12 ++++++------ typed-racket-test/unit-tests/typecheck-tests.rkt | 1 + 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/typed-racket-lib/typed-racket/base-env/base-env-numeric.rkt b/typed-racket-lib/typed-racket/base-env/base-env-numeric.rkt index f6b34c60..26f6326d 100644 --- a/typed-racket-lib/typed-racket/base-env/base-env-numeric.rkt +++ b/typed-racket-lib/typed-racket/base-env/base-env-numeric.rkt @@ -1377,16 +1377,16 @@ (-Int -Int . -> . -Int))] [bitwise-and - (let ([mix-with-int + (let ([mix-with-nat (lambda (t) (list (->* (list t) t t) ; closed - (->* (list -Int t) t t) ; brings result down - (->* (list t -Int) t t)))]) + (->* (list -Nat t) t t) ; brings result down + (->* (list t -Nat) t t)))]) (from-cases (-> -NegFixnum) ; no args -> -1 - (map mix-with-int (list -Zero -Byte -Index -NonNegFixnum)) + (map mix-with-nat (list -Zero -Byte -Index -NonNegFixnum)) ;; closed on negatives, but not closed if we mix with positives - (map varop-1+ (list -NegFixnum -NonPosFixnum)) - (map mix-with-int (list -Fixnum -Nat)) + (map varop-1+ (list -NegFixnum -NonPosFixnum -Fixnum)) + (map mix-with-nat (list -Nat)) (map varop-1+ (list -NegInt -NonPosInt)) (null -Int . ->* . -Int)))] [bitwise-ior diff --git a/typed-racket-test/unit-tests/typecheck-tests.rkt b/typed-racket-test/unit-tests/typecheck-tests.rkt index c608dbd8..55f224a4 100644 --- a/typed-racket-test/unit-tests/typecheck-tests.rkt +++ b/typed-racket-test/unit-tests/typecheck-tests.rkt @@ -454,6 +454,7 @@ (tc-e (expt (make-rectangular 3 -1.7976931348623157e+308) (flacos (real->double-flonum 59.316513f0))) (t:Un -Flonum -FloatComplex)) (tc-e (exact->inexact (ann 3 Number)) (t:Un -InexactReal -InexactComplex)) (tc-e (/ (round (exact-round -2.7393196f0)) (real->double-flonum (inexact->exact (real->single-flonum -0.0)))) -Real) + (tc-e (bitwise-and (exact-round 1.7976931348623157e+308) (exact-round -29)) -Int) (tc-e (exact->inexact 3) -PosFlonum) (tc-e (exact->inexact -3) -NegFlonum) (tc-e (real->double-flonum 0.0) -FlonumPosZero) From e4edf7a9eeac03d00e8a228e36bcdcdad4767e3e Mon Sep 17 00:00:00 2001 From: Vincent St-Amour Date: Tue, 3 Nov 2015 18:04:44 -0600 Subject: [PATCH 19/24] Remove tests made obsolete by safety improvements. --- typed-racket-test/unit-tests/all-tests.rkt | 1 - typed-racket-test/unit-tests/rep-tests.rkt | 23 ---------------------- 2 files changed, 24 deletions(-) delete mode 100644 typed-racket-test/unit-tests/rep-tests.rkt diff --git a/typed-racket-test/unit-tests/all-tests.rkt b/typed-racket-test/unit-tests/all-tests.rkt index 91b0a2ff..1ff12e20 100644 --- a/typed-racket-test/unit-tests/all-tests.rkt +++ b/typed-racket-test/unit-tests/all-tests.rkt @@ -41,7 +41,6 @@ "filter-tests.rkt" "metafunction-tests.rkt" "generalize-tests.rkt" - "rep-tests.rkt" "prims-tests.rkt" "tooltip-tests.rkt" "prefab-tests.rkt" diff --git a/typed-racket-test/unit-tests/rep-tests.rkt b/typed-racket-test/unit-tests/rep-tests.rkt deleted file mode 100644 index 8154c9dc..00000000 --- a/typed-racket-test/unit-tests/rep-tests.rkt +++ /dev/null @@ -1,23 +0,0 @@ -#lang racket/base - -;; Tests for TR representation data structures such as types - -(require "test-utils.rkt" - rackunit - typed-racket/rep/rep-utils - typed-racket/rep/type-rep - typed-racket/types/abbrev) - -(provide tests) -(gen-test-main) - -(define tests - (test-suite - "Tests for TR IR data structures" - - ;; Make sure that unsafe operations return the same results as safe ones - (check-equal? (Rep-seq -String) (unsafe-Rep-seq -String)) - (check-equal? (Rep-seq (-pair -String -String)) (unsafe-Rep-seq (-pair -String -String))) - (check-equal? (Type-key -String) (unsafe-Type-key -String)) - (check-equal? (Type-key (-pair -String -String)) (unsafe-Type-key (-pair -String -String))) - )) From 2881cffdc253be96a7d8f78ff98192db0c57324b Mon Sep 17 00:00:00 2001 From: Vincent St-Amour Date: Tue, 3 Nov 2015 18:27:20 -0600 Subject: [PATCH 20/24] Simplify unsafe op usage. --- typed-racket-lib/typed-racket/types/current-seen.rkt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/typed-racket-lib/typed-racket/types/current-seen.rkt b/typed-racket-lib/typed-racket/types/current-seen.rkt index ed92b27c..0b671243 100644 --- a/typed-racket-lib/typed-racket/types/current-seen.rkt +++ b/typed-racket-lib/typed-racket/types/current-seen.rkt @@ -24,5 +24,5 @@ A)) (define (seen? ss st cs) (for/or ([i (in-list cs)]) - (and (pair? i) (eq? ss (unsafe-car i)) (eq? st (unsafe-cdr i))))) + (and (eq? ss (car i)) (eq? st (unsafe-cdr i))))) From 2e100bcb3385a98b156cbef1c18208a15b6b7321 Mon Sep 17 00:00:00 2001 From: Vincent St-Amour Date: Tue, 3 Nov 2015 20:11:46 -0600 Subject: [PATCH 21/24] Remove unsafety altogether. The bytecode optimizer can do the same transformation. --- typed-racket-lib/typed-racket/types/current-seen.rkt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/typed-racket-lib/typed-racket/types/current-seen.rkt b/typed-racket-lib/typed-racket/types/current-seen.rkt index 0b671243..2c952245 100644 --- a/typed-racket-lib/typed-racket/types/current-seen.rkt +++ b/typed-racket-lib/typed-racket/types/current-seen.rkt @@ -1,5 +1,5 @@ #lang racket/base -(require "../utils/utils.rkt" racket/unsafe/ops) +(require "../utils/utils.rkt") (require (rep type-rep) (contract-req)) (provide (except-out (all-defined-out) current-seen-mark)) @@ -24,5 +24,5 @@ A)) (define (seen? ss st cs) (for/or ([i (in-list cs)]) - (and (eq? ss (car i)) (eq? st (unsafe-cdr i))))) + (and (eq? ss (car i)) (eq? st (cdr i))))) From 390dc3a2b118df6021e016dc575fb9d1e64c13ca Mon Sep 17 00:00:00 2001 From: Alex Knauth Date: Thu, 5 Nov 2015 17:05:30 -0500 Subject: [PATCH 22/24] provide Unit from typed/racket/unit --- typed-racket-lib/typed/racket/unit.rkt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/typed-racket-lib/typed/racket/unit.rkt b/typed-racket-lib/typed/racket/unit.rkt index e36de3c6..ca42413f 100644 --- a/typed-racket-lib/typed/racket/unit.rkt +++ b/typed-racket-lib/typed/racket/unit.rkt @@ -15,9 +15,11 @@ unit-from-context define-unit-from-context) typed-racket/base-env/unit-prims + typed-racket/base-env/base-types-extra typed-racket/base-env/signature-prims) (provide define-signature + Unit unit invoke-unit invoke-unit/infer From 43dc7632d442d659c192df2b828c85b6c2b5b1b3 Mon Sep 17 00:00:00 2001 From: Alex Knauth Date: Thu, 5 Nov 2015 17:10:38 -0500 Subject: [PATCH 23/24] don't provide Unit from typed/racket/base --- typed-racket-lib/typed/racket/base.rkt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/typed-racket-lib/typed/racket/base.rkt b/typed-racket-lib/typed/racket/base.rkt index 4e7316ed..202d91bd 100644 --- a/typed-racket-lib/typed/racket/base.rkt +++ b/typed-racket-lib/typed/racket/base.rkt @@ -19,7 +19,7 @@ require/typed-legacy require-typed-signature) typed-racket/base-env/base-types - (except-in typed-racket/base-env/base-types-extra Distinction)) + (except-in typed-racket/base-env/base-types-extra Distinction Unit)) (provide (rename-out [define-type-alias define-type]) (all-from-out typed-racket/base-env/prims) (all-from-out typed-racket/base-env/base-types) From 37bfd24a0b95a07747d50c229b256f900cc0b89a Mon Sep 17 00:00:00 2001 From: Sam Tobin-Hochstadt Date: Fri, 6 Nov 2015 11:47:11 -0500 Subject: [PATCH 24/24] Add test for or/c problem. --- typed-racket-test/fail/union-or-exclusive.rkt | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 typed-racket-test/fail/union-or-exclusive.rkt diff --git a/typed-racket-test/fail/union-or-exclusive.rkt b/typed-racket-test/fail/union-or-exclusive.rkt new file mode 100644 index 00000000..f3bbf65a --- /dev/null +++ b/typed-racket-test/fail/union-or-exclusive.rkt @@ -0,0 +1,24 @@ +#; +(exn-pred exn:fail:contract? "Real") +#lang typed/racket #:no-optimize + + +(module m1 racket + (define (fix-vector-field-fun f) + (cond [(procedure-arity-includes? f 2 #t) + (λ (x y) (f x y))] + [else + (λ (x y) (f (vector x y)))])) + (provide fix-vector-field-fun)) + +(require/typed + (submod "." m1) + [fix-vector-field-fun (-> (U (-> Real Real Any) + (-> (Vector Real Real) Any)) + (-> Real Real Any))]) + +(: f : (Vector Real Real) -> (Listof Real)) +(define f (λ ([x : (Vector Real Real)] [ignored : Any #f]) + (list (vector-ref x 0) (vector-ref x 1)))) + +((fix-vector-field-fun f) 0.0 0.0)