From 59971400af1118b7da5a59589dbc07ddfb3fbb71 Mon Sep 17 00:00:00 2001 From: Sam Tobin-Hochstadt Date: Mon, 3 May 2010 11:33:42 -0400 Subject: [PATCH 01/23] change error message for `define:' (fixes PR 10883) original commit: 55929072bb5b8cb35a113678690418fde048390d --- collects/typed-scheme/private/prims.rkt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/collects/typed-scheme/private/prims.rkt b/collects/typed-scheme/private/prims.rkt index 674dce39..ec2dd433 100644 --- a/collects/typed-scheme/private/prims.rkt +++ b/collects/typed-scheme/private/prims.rkt @@ -199,7 +199,7 @@ This file defines two sorts of primitives. All of them are provided into any mod (syntax/loc stx (define: nm : arrty (lambda: formals body ...))))] - [(define: nm:id ~! (~describe "type annotation" (~seq : ty)) body) + [(define: nm:id ~! (~describe ":" :) (~describe "type" ty) body) (identifier? #'nm) (with-syntax ([new-nm (syntax-property #'nm 'type-label #'ty)]) (syntax/loc stx (define new-nm body)))] From a15708cba848a605e9e7e7e6faaddeb495b2fc93 Mon Sep 17 00:00:00 2001 From: Sam Tobin-Hochstadt Date: Mon, 3 May 2010 13:01:58 -0400 Subject: [PATCH 02/23] run .rkt files original commit: 6b5305afe742cdb399d049c6732fc92ddabbad3d --- collects/tests/typed-scheme/main.rkt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/collects/tests/typed-scheme/main.rkt b/collects/tests/typed-scheme/main.rkt index 63151191..a9c97b8a 100644 --- a/collects/tests/typed-scheme/main.rkt +++ b/collects/tests/typed-scheme/main.rkt @@ -10,7 +10,7 @@ "unit-tests/test-utils.ss") (define (scheme-file? s) - (regexp-match ".*[.](ss|scm)" (path->string s))) + (regexp-match ".*[.](rkt|ss|scm)" (path->string s))) (define-namespace-anchor a) From 55fb37ff164d5757d721eda56cadd7ad9fe99e46 Mon Sep 17 00:00:00 2001 From: Sam Tobin-Hochstadt Date: Mon, 3 May 2010 13:15:19 -0400 Subject: [PATCH 03/23] fix problem reported by Sigrid on plt-scheme original commit: 996405af9c5ba32c49d1051c85b573d1383e244a --- .../tests/typed-scheme/succeed/mutable-struct-pred.ss | 10 ++++++++++ collects/typed-scheme/typecheck/tc-structs.rkt | 4 +++- 2 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 collects/tests/typed-scheme/succeed/mutable-struct-pred.ss diff --git a/collects/tests/typed-scheme/succeed/mutable-struct-pred.ss b/collects/tests/typed-scheme/succeed/mutable-struct-pred.ss new file mode 100644 index 00000000..fbc998e6 --- /dev/null +++ b/collects/tests/typed-scheme/succeed/mutable-struct-pred.ss @@ -0,0 +1,10 @@ +#lang typed/scheme + +(define-struct: x ([y : Any]) #:mutable) + +(define: the-x : Any (make-x 1)) + +(if (x? the-x) + (x-y the-x) + 0) + diff --git a/collects/typed-scheme/typecheck/tc-structs.rkt b/collects/typed-scheme/typecheck/tc-structs.rkt index 510b3422..6717d50b 100644 --- a/collects/typed-scheme/typecheck/tc-structs.rkt +++ b/collects/typed-scheme/typecheck/tc-structs.rkt @@ -111,6 +111,7 @@ #:maker (or maker* maker) #:predicate (or pred* pred) #:struct-info si + #:poly? poly? #:constructor-return cret)))) ;; generate names, and register the approriate types give field types and structure type @@ -123,6 +124,7 @@ #:pred-wrapper [pred-wrapper values] #:maker [maker* #f] #:predicate [pred* #f] + #:poly? [poly? #f] #:constructor-return [cret #f]) ;; create the approriate names that define-struct will bind (define-values (struct-type-id maker pred getters setters) (struct-names nm flds setters?)) @@ -137,7 +139,7 @@ (cons (or maker* maker) (wrapper (->* external-fld-types (if cret cret name)))) (cons (or pred* pred) - (make-pred-ty (if setters? + (make-pred-ty (if (and setters? poly?) (make-StructTop sty) (pred-wrapper name))))) (for/list ([g (in-list getters)] [t (in-list external-fld-types/no-parent)] [i (in-naturals)]) From d4d0b811cd4042bca685866708b5492b8801d376 Mon Sep 17 00:00:00 2001 From: Sam Tobin-Hochstadt Date: Mon, 3 May 2010 13:18:56 -0400 Subject: [PATCH 04/23] rename original commit: 92a3085658a7addbfd8261a8c6573918d2a4235a --- .../succeed/{mutable-struct-pred.ss => mutable-struct-pred.rkt} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename collects/tests/typed-scheme/succeed/{mutable-struct-pred.ss => mutable-struct-pred.rkt} (100%) diff --git a/collects/tests/typed-scheme/succeed/mutable-struct-pred.ss b/collects/tests/typed-scheme/succeed/mutable-struct-pred.rkt similarity index 100% rename from collects/tests/typed-scheme/succeed/mutable-struct-pred.ss rename to collects/tests/typed-scheme/succeed/mutable-struct-pred.rkt From 19c4c523f3e92a7cda28d7f555f46767774b670f Mon Sep 17 00:00:00 2001 From: Sam Tobin-Hochstadt Date: Mon, 3 May 2010 15:13:33 -0400 Subject: [PATCH 05/23] Add test for bug 10868 Add 'unit' command line arg to 'run.rkt' command to just run the unit tests original commit: 34e64b650fd55c99aff3c79279663becd4da4249 --- collects/tests/typed-scheme/main.rkt | 4 ++-- collects/tests/typed-scheme/run.rkt | 2 +- .../tests/typed-scheme/unit-tests/typecheck-tests.rkt | 10 +++++++--- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/collects/tests/typed-scheme/main.rkt b/collects/tests/typed-scheme/main.rkt index a9c97b8a..41edab68 100644 --- a/collects/tests/typed-scheme/main.rkt +++ b/collects/tests/typed-scheme/main.rkt @@ -86,8 +86,8 @@ (test-suite "Typed Scheme Tests" unit-tests int-tests)) -(define (go) (test/gui tests)) -(define (go/text) (run-tests tests 'verbose)) +(define (go [unit? #f]) (test/gui (if unit? unit-tests tests))) +(define (go/text [unit? #f]) (run-tests (if unit? unit-tests tests) 'verbose)) (provide go go/text) diff --git a/collects/tests/typed-scheme/run.rkt b/collects/tests/typed-scheme/run.rkt index d892dd34..993c6d14 100644 --- a/collects/tests/typed-scheme/run.rkt +++ b/collects/tests/typed-scheme/run.rkt @@ -2,5 +2,5 @@ (require "main.ss") (current-namespace (make-base-namespace)) -(unless (= 0 (go/text)) +(unless (= 0 (go/text (member "unit" (vector->list (current-command-line-arguments))))) (error "Typed Scheme Tests did not pass.")) diff --git a/collects/tests/typed-scheme/unit-tests/typecheck-tests.rkt b/collects/tests/typed-scheme/unit-tests/typecheck-tests.rkt index ca865586..82c5b3cb 100644 --- a/collects/tests/typed-scheme/unit-tests/typecheck-tests.rkt +++ b/collects/tests/typed-scheme/unit-tests/typecheck-tests.rkt @@ -799,14 +799,17 @@ (define: foo : (Integer * -> Integer) +) (foo 1 2 3 4 5)) -Integer] + [tc-e (let () + (define: x : Any 7) + (if (box? x) (unbox x) 1)) + Univ] ) (test-suite "check-type tests" (test-exn "Fails correctly" exn:fail:syntax? (lambda () (parameterize ([orig-module-stx #'here]) (check-type #'here N B)))) (test-not-exn "Doesn't fail on subtypes" (lambda () (check-type #'here N Univ))) - (test-not-exn "Doesn't fail on equal types" (lambda () (check-type #'here N N))) - ) + (test-not-exn "Doesn't fail on equal types" (lambda () (check-type #'here N N)))) (test-suite "tc-literal tests" (tc-l 5 -ExactPositiveInteger) @@ -820,7 +823,8 @@ (tc-l #f (-val #f)) (tc-l #"foo" -Bytes) [tc-l () (-val null)] - ) + [tc-l (3 . 4) (-pair -Pos -Pos)] + [tc-l #hash((1 . 2) (3 . 4)) (make-Hashtable -Pos -Pos)]) )) From db9ffaaae82bc4516c899e4fbe82e8b83565694c Mon Sep 17 00:00:00 2001 From: Sam Tobin-Hochstadt Date: Mon, 3 May 2010 18:03:01 -0400 Subject: [PATCH 06/23] use `vector-member' original commit: d5776a12666c507525df54c2f217f819dd407f33 --- collects/tests/typed-scheme/run.rkt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/collects/tests/typed-scheme/run.rkt b/collects/tests/typed-scheme/run.rkt index 993c6d14..f2ff3c10 100644 --- a/collects/tests/typed-scheme/run.rkt +++ b/collects/tests/typed-scheme/run.rkt @@ -1,6 +1,7 @@ -#lang scheme/base +#lang racket/base +(require racket/vector) (require "main.ss") (current-namespace (make-base-namespace)) -(unless (= 0 (go/text (member "unit" (vector->list (current-command-line-arguments))))) +(unless (= 0 (go/text (vector-member "unit" (current-command-line-arguments)))) (error "Typed Scheme Tests did not pass.")) From 419307edd1963b5b560a046faee8bf4a072f444b Mon Sep 17 00:00:00 2001 From: Sam Tobin-Hochstadt Date: Mon, 3 May 2010 18:13:12 -0400 Subject: [PATCH 07/23] add some vector functions original commit: 105a560698dfa979ab592ceb3c443e9425f2c956 --- collects/typed-scheme/private/base-env.rkt | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/collects/typed-scheme/private/base-env.rkt b/collects/typed-scheme/private/base-env.rkt index 84049dbd..164e83b0 100644 --- a/collects/typed-scheme/private/base-env.rkt +++ b/collects/typed-scheme/private/base-env.rkt @@ -367,6 +367,11 @@ [vector-immutable (-poly (a) (->* (list) a (-vec a)))] [vector->immutable-vector (-poly (a) (-> (-vec a) (-vec a)))] [vector-fill! (-poly (a) (-> (-vec a) a -Void))] +[vector-argmax (-poly (a) (-> (-> a -Real) (-vec a) a))] +[vector-argmin (-poly (a) (-> (-> a -Real) (-vec a) a))] +[vector-memq (-poly (a) (-> a (-vec a) (-opt -Nat)))] +[vector-memv (-poly (a) (-> a (-vec a) (-opt -Nat)))] +[vector-member (-poly (a) (a (-vec a) . -> . (-opt -Nat)))] ;; [vector->values no good type here] From 80a48b4a6eb7e97b2b997950f2fde2648ce9d08e Mon Sep 17 00:00:00 2001 From: Jay McCarthy Date: Mon, 3 May 2010 22:30:32 -0600 Subject: [PATCH 08/23] Adding typed/racunit and fixing racunit exports vis a vis documentation original commit: 445a143f5193e874d88bddfa9fc9ef1b52211f26 --- collects/typed/racunit/gui.rkt | 10 ++ collects/typed/racunit/main.rkt | 160 +++++++++++++++++++++++++++++ collects/typed/racunit/text-ui.rkt | 14 +++ 3 files changed, 184 insertions(+) create mode 100644 collects/typed/racunit/gui.rkt create mode 100644 collects/typed/racunit/main.rkt create mode 100644 collects/typed/racunit/text-ui.rkt diff --git a/collects/typed/racunit/gui.rkt b/collects/typed/racunit/gui.rkt new file mode 100644 index 00000000..333ad397 --- /dev/null +++ b/collects/typed/racunit/gui.rkt @@ -0,0 +1,10 @@ +#lang typed/scheme +(require typed/racunit + typed/private/utils) + +(require/typed/provide + racunit/gui + [test/gui + (Test * -> Any)] + [make-gui-runner + (-> (Test * -> Any))]) diff --git a/collects/typed/racunit/main.rkt b/collects/typed/racunit/main.rkt new file mode 100644 index 00000000..5580c8d2 --- /dev/null +++ b/collects/typed/racunit/main.rkt @@ -0,0 +1,160 @@ +#lang typed/scheme +(require typed/private/utils) + +(define-type check-ish-ty + (All (A B) + (case-lambda + (A B -> #t) + (A B String -> #t)))) +(define-type (Predicate A) (A -> Boolean)) +(define-type (Thunk A) (-> A)) + +; 3.2 +(require/typed/provide + racunit + [check (All (A B C) + (case-lambda + ((A B -> C) A B -> C) + ((A B -> C) A B String -> C)))] + [check-eq? check-ish-ty] + [check-not-eq? check-ish-ty] + [check-eqv? check-ish-ty] + [check-not-eqv? check-ish-ty] + [check-equal? check-ish-ty] + [check-not-equal? check-ish-ty] + [check-pred + (All (A B) + (case-lambda + ((A -> B) A -> #t) + ((A -> B) A String -> #t)))] + [check-= + (case-lambda + (Number Number Number -> #t) + (Number Number Number String -> #t))] + [check-true + (case-lambda + (Boolean -> #t) + (Boolean String -> #t))] + [check-false + (case-lambda + (Boolean -> #t) + (Boolean String -> #t))] + [check-not-false + (case-lambda + (Any -> #t) + (Any String -> #t))] + [check-exn + (All (A B) + (case-lambda + ((Predicate A) (Thunk B) -> #t) + ((Predicate A) (Thunk B) String -> #t)))] + [check-not-exn + (All (A) + (case-lambda + ((Thunk A) -> #t) + ((Thunk A) String -> #t)))] + [fail + (case-lambda + (-> #t) + (String -> #t))] + [check-regexp-match + (Regexp String -> #t)]) + +; 3.2.1 +(require-typed-struct check-info + ([name : Symbol] [value : Any]) + racunit) +(define-type CheckInfo check-info) +(provide (struct-out check-info) CheckInfo) +(require/typed/provide + racunit + [make-check-name (String -> CheckInfo)] + [make-check-params ((Listof Any) -> CheckInfo)] + [make-check-location ((List Any (U Number #f) (U Number #f) (U Number #f) (U Number #f)) -> CheckInfo)] + [make-check-expression (Any -> CheckInfo)] + [make-check-message (String -> CheckInfo)] + [make-check-actual (Any -> CheckInfo)] + [make-check-expected (Any -> CheckInfo)] + [with-check-info* (All (A) ((Listof CheckInfo) (Thunk A) -> A))]) +(require (only-in racunit with-check-info)) +(provide with-check-info) + +; 3.2.2 +(require (only-in racunit define-simple-check define-binary-check define-check fail-check)) +(provide define-simple-check define-binary-check define-check fail-check) + +; 3.2.3 +(require/typed/provide + racunit + [current-check-handler + (Parameter (Any -> Any))] + [current-check-around + (Parameter ((Thunk Any) -> Any))]) + +; 3.3 +(require (only-in racunit test-begin test-case)) +(provide test-begin test-case) + +(require/opaque-type TestCase test-case? racunit) +(provide TestCase test-case?) + +(require (only-in racunit test-suite)) +(provide test-suite) +(require/opaque-type TestSuite test-suite? racunit) +(provide TestSuite test-suite?) + +(define-type Test (U TestCase TestSuite)) +(provide Test) + +(require/typed/provide + racunit + [make-test-suite + (case-lambda + (String (Listof Test) -> TestSuite) + ; XXX #:before #:after + )]) + +(require (only-in racunit define-test-suite define/provide-test-suite)) +(provide define-test-suite define/provide-test-suite) + +(require/typed/provide + racunit + [current-test-name (Parameter (Option String))] + [current-test-case-around (Parameter ((Thunk Any) -> Any))] + [test-suite-test-case-around ((Thunk Any) -> Any)] + [test-suite-check-around ((Thunk Any) -> Any)]) + +; 3.4 +(require (only-in racunit before after around delay-test)) +(provide before after around delay-test) + +; 3.5 +; XXX require/expose seems WRONG for typed/scheme + +; 3.7 +(require-typed-struct (exn:test exn) () racunit) +(require-typed-struct (exn:test:check exn:test) ([stack : (Listof CheckInfo)]) racunit) +(require-typed-struct test-result ([test-case-name : (Option String)]) racunit) +(require-typed-struct (test-failure test-result) ([result : Any]) racunit) +(require-typed-struct (test-error test-result) ([result : Any]) racunit) +(require-typed-struct (test-success test-result) ([result : Any]) racunit) +(provide (struct-out exn:test) (struct-out exn:test:check) + (struct-out test-result) + (struct-out test-failure) (struct-out test-error) (struct-out test-success)) + +(define-type (Tree A) + (Rec The-Tree + (Listof (U A The-Tree)))) + +(require/typed/provide + racunit + [run-test-case + ((Option String) (Thunk Any) -> test-result)] + [run-test + (Test -> (Tree test-result))] + ; XXX Requires keywords and weird stuff + #;[fold-test-results + XXX] + ; XXX Requires knowing more about test cases and structs + #;[foldts + XXX]) diff --git a/collects/typed/racunit/text-ui.rkt b/collects/typed/racunit/text-ui.rkt new file mode 100644 index 00000000..16fa4bd1 --- /dev/null +++ b/collects/typed/racunit/text-ui.rkt @@ -0,0 +1,14 @@ +#lang typed/scheme +(require typed/racunit + typed/private/utils) + +(define-type Verbosity + (U 'quiet 'normal 'verbose)) + +(require/typed/provide + racunit/text-ui + [run-tests + (case-lambda + (Test -> Natural) + (Test Verbosity -> Natural))]) +(provide Verbosity) \ No newline at end of file From 5f732f0a0aa2879ca3bd2eea9f184c279c7e8fcf Mon Sep 17 00:00:00 2001 From: Ryan Culpepper Date: Tue, 4 May 2010 11:50:42 -0600 Subject: [PATCH 09/23] syntax/parse: literals, literal-sets, and phases (todo: docs) typed-scheme: added missing import for literal original commit: eff9147ddcf6b8fefb51cb1753ae678c2ac8f0ae --- collects/typed-scheme/private/parse-type.rkt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/collects/typed-scheme/private/parse-type.rkt b/collects/typed-scheme/private/parse-type.rkt index e11a5afc..c74e2956 100644 --- a/collects/typed-scheme/private/parse-type.rkt +++ b/collects/typed-scheme/private/parse-type.rkt @@ -10,7 +10,8 @@ (prefix-in t: (combine-in "base-types-extra.ss" "base-types.ss")) (only-in "colon.ss" :) scheme/match (for-template scheme/base "base-types-extra.ss" "colon.ss") - (for-template (prefix-in t: "base-types-extra.ss"))) + (for-template (prefix-in t: "base-types-extra.ss") + (prefix-in t: (only-in "base-types.ss" Vectorof)))) (define-struct poly (name vars) #:prefab) From 9e9ee0aee4b42e5b2f63fd85b25b58b7d9e043dd Mon Sep 17 00:00:00 2001 From: Sam Tobin-Hochstadt Date: Tue, 4 May 2010 09:42:36 -0400 Subject: [PATCH 10/23] fix some racunit types, add test case original commit: 0a2b16f804502b169e1b1a7ab89fe25f5f6bb0ed --- collects/tests/typed-scheme/succeed/racunit.ss | 18 ++++++++++++++++++ collects/typed/racunit/main.rkt | 11 +++++------ 2 files changed, 23 insertions(+), 6 deletions(-) create mode 100644 collects/tests/typed-scheme/succeed/racunit.ss diff --git a/collects/tests/typed-scheme/succeed/racunit.ss b/collects/tests/typed-scheme/succeed/racunit.ss new file mode 100644 index 00000000..619b0f6b --- /dev/null +++ b/collects/tests/typed-scheme/succeed/racunit.ss @@ -0,0 +1,18 @@ +#lang typed/scheme + +(require typed/racunit) + +(: my-+ : Integer Integer -> Integer) +(define (my-+ a b) + (if (zero? a) + b + (my-+ (sub1 a) (add1 b)))) + +(: my-* : Integer Integer -> Integer) +(define (my-* a b) + (if (zero? a) + b + (my-* (sub1 a) (my-+ b b)))) + +(check-equal? (my-+ 1 1) 2 "Simple addition") +(check-equal? (my-* 1 2) 2 "Simple multiplication") \ No newline at end of file diff --git a/collects/typed/racunit/main.rkt b/collects/typed/racunit/main.rkt index 5580c8d2..619f400a 100644 --- a/collects/typed/racunit/main.rkt +++ b/collects/typed/racunit/main.rkt @@ -2,12 +2,11 @@ (require typed/private/utils) (define-type check-ish-ty - (All (A B) - (case-lambda - (A B -> #t) - (A B String -> #t)))) -(define-type (Predicate A) (A -> Boolean)) -(define-type (Thunk A) (-> A)) + (case-lambda + (Any Any -> Void) + (Any Any String -> Void))) +(define-type (Predicate A) (Any -> Boolean)) +(define-type (Thunk A) (-> Any)) ; 3.2 (require/typed/provide From c1415c98c20073aa4f9ec474f6968f23fb478fda Mon Sep 17 00:00:00 2001 From: Sam Tobin-Hochstadt Date: Tue, 4 May 2010 09:59:12 -0400 Subject: [PATCH 11/23] typed/racunit: - fix more contracts - make test tests not fail original commit: 3ebd04550a14e52ed1ce44abe2c1d9f4b7c3374a --- collects/tests/typed-scheme/succeed/racunit.ss | 2 +- collects/typed/racunit/main.rkt | 18 ++++++++---------- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/collects/tests/typed-scheme/succeed/racunit.ss b/collects/tests/typed-scheme/succeed/racunit.ss index 619b0f6b..568e14d2 100644 --- a/collects/tests/typed-scheme/succeed/racunit.ss +++ b/collects/tests/typed-scheme/succeed/racunit.ss @@ -10,7 +10,7 @@ (: my-* : Integer Integer -> Integer) (define (my-* a b) - (if (zero? a) + (if (= a 1) b (my-* (sub1 a) (my-+ b b)))) diff --git a/collects/typed/racunit/main.rkt b/collects/typed/racunit/main.rkt index 619f400a..93b1752b 100644 --- a/collects/typed/racunit/main.rkt +++ b/collects/typed/racunit/main.rkt @@ -5,8 +5,8 @@ (case-lambda (Any Any -> Void) (Any Any String -> Void))) -(define-type (Predicate A) (Any -> Boolean)) -(define-type (Thunk A) (-> Any)) +(define-type (Predicate A) (A -> Boolean)) +(define-type (Thunk A) (-> A)) ; 3.2 (require/typed/provide @@ -43,15 +43,13 @@ (Any -> #t) (Any String -> #t))] [check-exn - (All (A B) - (case-lambda - ((Predicate A) (Thunk B) -> #t) - ((Predicate A) (Thunk B) String -> #t)))] + (case-lambda + ((Predicate Any) (Thunk Any) -> #t) + ((Predicate Any) (Thunk Any) String -> #t))] [check-not-exn - (All (A) - (case-lambda - ((Thunk A) -> #t) - ((Thunk A) String -> #t)))] + (case-lambda + ((Thunk Any) -> #t) + ((Thunk Any) String -> #t))] [fail (case-lambda (-> #t) From bbf8fe4b549476636c28ce8d2dce90e4e4f14bb1 Mon Sep 17 00:00:00 2001 From: Sam Tobin-Hochstadt Date: Tue, 4 May 2010 16:51:54 -0400 Subject: [PATCH 12/23] use hairy macro rewriting to make more of racunit work original commit: b00b72a73a78f5b24a18fd79d907d987efe61530 --- collects/typed/private/rewriter.rkt | 60 +++++++++++++++++++++++++ collects/typed/racunit/main.rkt | 19 ++++++-- collects/typed/racunit/type-env-ext.rkt | 23 ++++++++++ 3 files changed, 99 insertions(+), 3 deletions(-) create mode 100644 collects/typed/private/rewriter.rkt create mode 100644 collects/typed/racunit/type-env-ext.rkt diff --git a/collects/typed/private/rewriter.rkt b/collects/typed/private/rewriter.rkt new file mode 100644 index 00000000..45c29a5c --- /dev/null +++ b/collects/typed/private/rewriter.rkt @@ -0,0 +1,60 @@ +#lang racket/base +(require (for-syntax syntax/parse racket/base syntax/id-table racket/dict + unstable/debug)) + +(define-for-syntax (rewrite stx tbl from) + (define (rw stx) + (syntax-recertify + (syntax-parse stx #:literal-sets (kernel-literals) + [i:identifier + (dict-ref tbl #'i #'i)] + ;; no expressions here + [((~or (~literal #%top) (~literal quote) (~literal quote-syntax)) . _) stx] + [(#%plain-lambda formals expr ...) + (quasisyntax/loc stx (#%plain-lambda formals #,@(map rw (syntax->list #'(expr ...)))))] + [(case-lambda [formals expr ...] ...) + (with-syntax ([((expr* ...) ...) (for*/list ([exprs (in-list (syntax->list #'((expr ...) ...)))] + [e (in-list (syntax->list exprs))]) + (rw e))]) + (quasisyntax/loc stx (case-lambda [formals expr* ...] ...)))] + [(let-values ([(id ...) rhs] ...) expr ...) + (with-syntax ([(rhs* ...) (map rw (syntax->list #'(rhs ...)))] + [(expr* ...) (map rw (syntax->list #'(expr ...)))]) + (quasisyntax/loc stx (let-values ([(id ...) rhs*] ...) expr* ...)))] + [(letrec-values ([(id ...) rhs] ...) expr ...) + (with-syntax ([(rhs* ...) (map rw (syntax->list #'(rhs ...)))] + [(expr* ...) (map rw (syntax->list #'(expr ...)))]) + (quasisyntax/loc stx (letrec-values ([(id ...) rhs*] ...) expr* ...)))] + [(letrec-syntaxes+values ([(sid ...) srhs] ...) ([(id ...) rhs] ...) expr ...) + (with-syntax ([(srhs* ...) (map rw (syntax->list #'(srhs ...)))] + [(rhs* ...) (map rw (syntax->list #'(rhs ...)))] + [(expr* ...) (map rw (syntax->list #'(expr ...)))]) + (quasisyntax/loc stx (letrec-syntaxes+values ([(sid ...) srhs*] ...) ([(id ...) rhs*] ...) expr* ...)))] + [((~and kw + (~or if begin begin0 set! #%plain-app #%expression + #%variable-reference with-continuation-mark)) + expr ...) + (quasisyntax/loc stx (#,#'kw #,@(map rw (syntax->list #'(expr ...)))))]) + stx + (current-code-inspector) + #f)) + (rw stx)) + +(define-syntax (define-rewriter stx) + (syntax-case stx () + [(_ orig-name new-name [from to] ...) + #'(begin + (define-for-syntax from-list (list #'from ...)) + (define-for-syntax tbl (make-immutable-free-id-table (map cons from-list (list #'to ...)))) + (define-syntax (new-name stx) + (syntax-case stx () + [(_ . args) + (let ([result (local-expand (syntax/loc stx (orig-name . args)) (syntax-local-context) null)]) + (rewrite result tbl from-list))])))])) + +(provide define-rewriter) +#;(define-syntax-rule (m x) (+ x 7)) + +#;(define-rewriter m n [+ -]) + +#;(n 77) diff --git a/collects/typed/racunit/main.rkt b/collects/typed/racunit/main.rkt index 93b1752b..6232b889 100644 --- a/collects/typed/racunit/main.rkt +++ b/collects/typed/racunit/main.rkt @@ -1,5 +1,7 @@ #lang typed/scheme -(require typed/private/utils) +(require typed/private/utils + typed/private/rewriter + "type-env-ext.rkt") (define-type check-ish-ty (case-lambda @@ -67,7 +69,7 @@ racunit [make-check-name (String -> CheckInfo)] [make-check-params ((Listof Any) -> CheckInfo)] - [make-check-location ((List Any (U Number #f) (U Number #f) (U Number #f) (U Number #f)) -> CheckInfo)] + [make-check-location ((List Any (Option Number) (Option Number) (Option Number) (Option Number)) -> CheckInfo)] [make-check-expression (Any -> CheckInfo)] [make-check-message (String -> CheckInfo)] [make-check-actual (Any -> CheckInfo)] @@ -89,7 +91,18 @@ (Parameter ((Thunk Any) -> Any))]) ; 3.3 -(require (only-in racunit test-begin test-case)) +(require (prefix-in t: (except-in racunit struct:check-info struct:exn:test struct:exn:test:check struct:test-result struct:test-failure + struct:test-error struct:test-success))) +(define-rewriter t:test-begin test-begin + [t:current-test-case-around current-test-case-around] + [t:check-around check-around] + [t:current-check-handler current-check-handler] + [t:current-check-around current-check-around]) +(define-rewriter t:test-case test-case + [t:current-test-case-around current-test-case-around] + [t:check-around check-around] + [t:current-check-handler current-check-handler] + [t:current-check-around current-check-around]) (provide test-begin test-case) (require/opaque-type TestCase test-case? racunit) diff --git a/collects/typed/racunit/type-env-ext.rkt b/collects/typed/racunit/type-env-ext.rkt new file mode 100644 index 00000000..02777a75 --- /dev/null +++ b/collects/typed/racunit/type-env-ext.rkt @@ -0,0 +1,23 @@ +#lang scheme/base + +(require typed-scheme/utils/utils + (prefix-in ru: (combine-in racunit racunit/private/test-case racunit/private/check)) + (for-syntax + scheme/base syntax/parse + (utils tc-utils) + (env init-envs) + (except-in (rep filter-rep object-rep type-rep) make-arr) + (types convenience union) + (only-in (types convenience) [make-arr* make-arr]))) + +(define-for-syntax unit-env + (make-env + [ru:check-around + (-poly (a) (-> (-> a) a))] + ;; current-test-case-around + [(syntax-parse (local-expand #'(ru:test-begin 0) 'expression null) + #:context #'ru:test-begin + [(_ _ . _) #'ctca]) + (-poly (a) (-> (-> a) a))])) + +(begin-for-syntax (initialize-type-env unit-env)) \ No newline at end of file From b45d2f1a0c627d525c85ddca503bcb41d2b2721c Mon Sep 17 00:00:00 2001 From: Sam Tobin-Hochstadt Date: Tue, 4 May 2010 16:52:20 -0400 Subject: [PATCH 13/23] handle full generality of extend-parameterization original commit: 4984345657eda9736b458cf73f97996e3da1ce95 --- collects/typed-scheme/typecheck/tc-app.rkt | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/collects/typed-scheme/typecheck/tc-app.rkt b/collects/typed-scheme/typecheck/tc-app.rkt index dcaca4d2..ead820ab 100644 --- a/collects/typed-scheme/typecheck/tc-app.rkt +++ b/collects/typed-scheme/typecheck/tc-app.rkt @@ -20,7 +20,7 @@ (r:infer infer) (for-template (only-in '#%kernel [apply k:apply]) - "internal-forms.ss" scheme/base scheme/bool + "internal-forms.ss" scheme/base scheme/bool '#%paramz (only-in racket/private/class-internal make-object do-make-object))) (import tc-expr^ tc-lambda^ tc-dots^ tc-let^) @@ -425,7 +425,21 @@ (syntax-parse form #:literals (#%plain-app #%plain-lambda letrec-values quote values apply k:apply not list list* call-with-values do-make-object make-object cons - andmap ormap reverse) + andmap ormap reverse extend-parameterization) + [(#%plain-app extend-parameterization pmz args ...) + (let loop ([args (syntax->list #'(args ...))]) + (if (null? args) Univ + (let* ([p (car args)] + [pt (single-value p)] + [v (cadr args)] + [vt (single-value v)]) + (match pt + [(tc-result1: (Param: a b)) + (check-below vt a) + (loop (cddr args))] + [(tc-result1: t) + (tc-error/expr #:ret (or expected (ret Univ)) "expected Parameter, but got ~a" t) + (loop (cddr args))]))))] ;; call-with-values [(#%plain-app call-with-values prod con) (match (tc/funapp #'prod #'() (single-value #'prod) null #f) From 7d53ae96a148e48c54c32ce2db1f11554a8dbda9 Mon Sep 17 00:00:00 2001 From: Sam Tobin-Hochstadt Date: Tue, 4 May 2010 17:26:26 -0400 Subject: [PATCH 14/23] doc fix original commit: 4183a3f32a254897d956f607a8b092767d098885 --- collects/typed-scheme/scribblings/ts-reference.scrbl | 1 + 1 file changed, 1 insertion(+) diff --git a/collects/typed-scheme/scribblings/ts-reference.scrbl b/collects/typed-scheme/scribblings/ts-reference.scrbl index 802a614a..de953b57 100644 --- a/collects/typed-scheme/scribblings/ts-reference.scrbl +++ b/collects/typed-scheme/scribblings/ts-reference.scrbl @@ -21,6 +21,7 @@ @subsubsub*section{Base Types} @deftogether[( @defidform[Number] +@defidform[Complex] @defidform[Real] @defidform[Integer] @defidform[Natural] From 11ae3af9b304b7ad81645cb0c8516e51b9de898d Mon Sep 17 00:00:00 2001 From: Sam Tobin-Hochstadt Date: Tue, 4 May 2010 17:26:33 -0400 Subject: [PATCH 15/23] add type for 2-arg `atan' original commit: 9ab4887e580d17d756e70642168c8c2171b92df1 --- collects/typed-scheme/private/base-env-numeric.rkt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/collects/typed-scheme/private/base-env-numeric.rkt b/collects/typed-scheme/private/base-env-numeric.rkt index 8790a1e8..5d19898f 100644 --- a/collects/typed-scheme/private/base-env-numeric.rkt +++ b/collects/typed-scheme/private/base-env-numeric.rkt @@ -136,7 +136,7 @@ [tan (N . -> . N)] [acos (N . -> . N)] [asin (N . -> . N)] -[atan (N . -> . N)] +[atan (cl->* (N . -> . N) (-Real -Real . -> . N))] [gcd (null -Integer . ->* . -Integer)] [lcm (null -Integer . ->* . -Integer)] From 41634b8e34a9a201ceef33b054279615e7e0040e Mon Sep 17 00:00:00 2001 From: Sam Tobin-Hochstadt Date: Tue, 4 May 2010 17:54:35 -0400 Subject: [PATCH 16/23] use `test-begin' in test original commit: d678e7657deee54921e332157367979b90e36971 --- collects/tests/typed-scheme/succeed/racunit.ss | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/collects/tests/typed-scheme/succeed/racunit.ss b/collects/tests/typed-scheme/succeed/racunit.ss index 568e14d2..9fe72f2c 100644 --- a/collects/tests/typed-scheme/succeed/racunit.ss +++ b/collects/tests/typed-scheme/succeed/racunit.ss @@ -1,7 +1,6 @@ -#lang typed/scheme +#lang typed/scheme/base (require typed/racunit) - (: my-+ : Integer Integer -> Integer) (define (my-+ a b) (if (zero? a) @@ -10,9 +9,10 @@ (: my-* : Integer Integer -> Integer) (define (my-* a b) - (if (= a 1) + (if (= 1 a) b (my-* (sub1 a) (my-+ b b)))) -(check-equal? (my-+ 1 1) 2 "Simple addition") -(check-equal? (my-* 1 2) 2 "Simple multiplication") \ No newline at end of file +(test-begin + (check-equal? (my-+ 1 1) 2 "Simple addition") + (check-equal? (my-* 2 2) 4 "Simple multiplication")) From 9b40abb674999e19b83968227ce52aacd1d51fed Mon Sep 17 00:00:00 2001 From: Sam Tobin-Hochstadt Date: Tue, 4 May 2010 17:55:01 -0400 Subject: [PATCH 17/23] Don't wrap booleans, print typed values original commit: 08ca97bf9e8650f204228ebee4252805db0fcb0f --- collects/typed-scheme/utils/any-wrap.rkt | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/collects/typed-scheme/utils/any-wrap.rkt b/collects/typed-scheme/utils/any-wrap.rkt index 0e7c3116..b1c63e0b 100644 --- a/collects/typed-scheme/utils/any-wrap.rkt +++ b/collects/typed-scheme/utils/any-wrap.rkt @@ -5,14 +5,16 @@ (define-struct any-wrap (val) #:property prop:custom-write (lambda (v p write?) - (fprintf p "#"))) + (fprintf p "#" (any-wrap-val v)))) (define (traverse wrap?) (define (t v) (match v [(? (lambda (e) (and (any-wrap? e) (not wrap?)))) (any-wrap-val v)] [(? (lambda (e) - (or (number? e) (string? e) (char? e) (symbol? e) (keyword? e) (bytes? e) (void? e)))) v] + (or (number? e) (string? e) (char? e) (symbol? e) + (keyword? e) (bytes? e) (boolean? e) (void? e)))) + v] [(cons x y) (cons (t x) (t y))] [(and (? immutable?) (? vector?)) (vector-map t v)] [(and (? immutable?) (box v)) (box (t v))] From 9781bbfbf4c179fee92e2dddb88d2854e2518da8 Mon Sep 17 00:00:00 2001 From: Sam Tobin-Hochstadt Date: Tue, 4 May 2010 17:55:31 -0400 Subject: [PATCH 18/23] Require '#%paramz at the correct phase (thanks ryan) original commit: 087c5129e33458acb20ee4fa9c7d07a4735c719d --- collects/typed-scheme/typecheck/tc-app.rkt | 1 + 1 file changed, 1 insertion(+) diff --git a/collects/typed-scheme/typecheck/tc-app.rkt b/collects/typed-scheme/typecheck/tc-app.rkt index ead820ab..4363171c 100644 --- a/collects/typed-scheme/typecheck/tc-app.rkt +++ b/collects/typed-scheme/typecheck/tc-app.rkt @@ -18,6 +18,7 @@ (except-in (env type-environments) extend) (rep type-rep filter-rep object-rep) (r:infer infer) + '#%paramz (for-template (only-in '#%kernel [apply k:apply]) "internal-forms.ss" scheme/base scheme/bool '#%paramz From e30cd94960a563dd668507779de3bd23c01249eb Mon Sep 17 00:00:00 2001 From: Sam Tobin-Hochstadt Date: Tue, 4 May 2010 17:56:46 -0400 Subject: [PATCH 19/23] checks can sometimes return #t original commit: d7d157b441457e4bbcb07c328c9b8e350f3c92ce --- collects/typed/racunit/main.rkt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/collects/typed/racunit/main.rkt b/collects/typed/racunit/main.rkt index 6232b889..2c4f7a76 100644 --- a/collects/typed/racunit/main.rkt +++ b/collects/typed/racunit/main.rkt @@ -5,8 +5,8 @@ (define-type check-ish-ty (case-lambda - (Any Any -> Void) - (Any Any String -> Void))) + (Any Any -> (U #t Void)) + (Any Any String -> (U #t Void)))) (define-type (Predicate A) (A -> Boolean)) (define-type (Thunk A) (-> A)) From 0c4ea82ca1a7bfc3eb6ef4f25b0e4216c84eb241 Mon Sep 17 00:00:00 2001 From: Sam Tobin-Hochstadt Date: Tue, 4 May 2010 19:45:35 -0400 Subject: [PATCH 20/23] use racunit better to get expected/actual info original commit: a728bae3cb83770c8e293e90acebe4ff1d7491da --- collects/tests/typed-scheme/unit-tests/test-utils.rkt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/collects/tests/typed-scheme/unit-tests/test-utils.rkt b/collects/tests/typed-scheme/unit-tests/test-utils.rkt index d4ad6aed..d3a48721 100644 --- a/collects/tests/typed-scheme/unit-tests/test-utils.rkt +++ b/collects/tests/typed-scheme/unit-tests/test-utils.rkt @@ -47,8 +47,9 @@ (syntax-case stx () [(_ nm a b) (syntax/loc stx (test-check nm type-equal? a b))])) +(define-binary-check (check-tc-result-equal?* tc-result-equal/test? a b)) (define-syntax (check-tc-result-equal? stx) (syntax-case stx () [(_ nm a b) - (syntax/loc stx (test-check nm tc-result-equal/test? a b))])) + (syntax/loc stx (test-case nm (check-tc-result-equal?* a b)))])) From fe3eee50bd17cbfdcc198836f2c224646f3b0755 Mon Sep 17 00:00:00 2001 From: Sam Tobin-Hochstadt Date: Tue, 4 May 2010 19:46:11 -0400 Subject: [PATCH 21/23] avoid error when not transforming original commit: 646bc0ecab63e350d69af5e8517503c2ab6d7fcb --- collects/typed-scheme/utils/tc-utils.rkt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/collects/typed-scheme/utils/tc-utils.rkt b/collects/typed-scheme/utils/tc-utils.rkt index 2ee33523..04fc918a 100644 --- a/collects/typed-scheme/utils/tc-utils.rkt +++ b/collects/typed-scheme/utils/tc-utils.rkt @@ -46,7 +46,7 @@ don't depend on any other portion of the system [stx (locate-stx e)]) (when (and (warn-unreachable?) (log-level? l 'warning) - (syntax-original? (syntax-local-introduce e)) + (and (syntax-transforming?) (syntax-original? (syntax-local-introduce e))) #;(and (orig-module-stx) (eq? (debug syntax-source-module e) (debug syntax-source-module (orig-module-stx)))) #;(syntax-source-module stx)) (log-message l 'warning (format "Typed Scheme has detected unreachable code: ~e" (syntax->datum (locate-stx e))) From 153a5db15b00ba49fd38b4d970c16aace223fd62 Mon Sep 17 00:00:00 2001 From: Sam Tobin-Hochstadt Date: Tue, 4 May 2010 19:46:25 -0400 Subject: [PATCH 22/23] Remove unnecessary requires which caused bizarre errors original commit: ad537cce84c9c0f16183563419512c67ad1d9ccc --- collects/typed-scheme/private/parse-type.rkt | 25 ++++++++++---------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/collects/typed-scheme/private/parse-type.rkt b/collects/typed-scheme/private/parse-type.rkt index c74e2956..9d624317 100644 --- a/collects/typed-scheme/private/parse-type.rkt +++ b/collects/typed-scheme/private/parse-type.rkt @@ -6,12 +6,12 @@ (utils tc-utils stxclass-util) syntax/stx (prefix-in c: scheme/contract) syntax/parse - (env type-environments type-name-env type-alias-env lexical-env) - (prefix-in t: (combine-in "base-types-extra.ss" "base-types.ss")) (only-in "colon.ss" :) + (env type-environments type-name-env type-alias-env lexical-env) scheme/match - (for-template scheme/base "base-types-extra.ss" "colon.ss") - (for-template (prefix-in t: "base-types-extra.ss") - (prefix-in t: (only-in "base-types.ss" Vectorof)))) + (for-template scheme/base "colon.ss") + ;; needed for tests + (combine-in (prefix-in t: "base-types-extra.ss") "colon.ss") + (for-template (prefix-in t: "base-types-extra.ss"))) (define-struct poly (name vars) #:prefab) @@ -87,8 +87,7 @@ (define-splicing-syntax-class latent-filter #:description "latent filter" - (pattern (~seq t:expr @:id pe:path-elem ...) - #:fail-unless (eq? (syntax-e #'@) '@) "expected @" + (pattern (~seq t:expr (~describe "@" (~datum @)) pe:path-elem ...) #:attr type (parse-type #'t) #:attr path (attribute pe.pe)) (pattern t:expr @@ -99,8 +98,8 @@ (parameterize ([current-orig-stx stx]) (syntax-parse stx - #:literals (t:Class t:Refinement t:Instance t:Tuple t:List cons t:pred t:-> : case-lambda - t:Vectorof t:mu t:Rec t:U t:All t:Opaque t:Parameter quote) + #:literals (t:Class t:Refinement t:Instance t:List cons t:pred t:-> : case-lambda + t:Rec t:U t:All t:Opaque t:Parameter quote) [t #:declare t (3d Type?) (attribute t.datum)] @@ -153,7 +152,7 @@ [_ (tc-error/stx ty "Component of case-lambda type was not a function clause")]))))] - [((~and kw t:Vectorof) t) + #;[((~and kw t:Vectorof) t) (add-type-name-reference #'kw) (make-Vector (parse-type #'t))] [((~and kw t:Rec) x:id t) @@ -290,11 +289,11 @@ (tc-error "Opaque: bad syntax")] [(t:U . rest) (tc-error "Union: bad syntax")] - [(t:Vectorof . rest) + #;[(t:Vectorof . rest) (tc-error "Vectorof: bad syntax")] - [((~and (~datum mu) t:mu) . rest) + [((~and (~datum mu) t:Rec) . rest) (tc-error "mu: bad syntax")] - [(t:mu . rest) + [(t:Rec . rest) (tc-error "Rec: bad syntax")] [(t ... t:-> . rest) (tc-error "->: bad syntax")] From 8335533ea29d7a3b818066810d619dff54cabf6b Mon Sep 17 00:00:00 2001 From: Sam Tobin-Hochstadt Date: Tue, 4 May 2010 19:47:00 -0400 Subject: [PATCH 23/23] minor test edits original commit: 90f7f522f8b53d6460fc0da2113605e538969762 --- collects/tests/typed-scheme/unit-tests/all-tests.rkt | 12 ++++++++---- .../typed-scheme/unit-tests/typecheck-tests.rkt | 5 +++-- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/collects/tests/typed-scheme/unit-tests/all-tests.rkt b/collects/tests/typed-scheme/unit-tests/all-tests.rkt index 27fb5069..18774810 100644 --- a/collects/tests/typed-scheme/unit-tests/all-tests.rkt +++ b/collects/tests/typed-scheme/unit-tests/all-tests.rkt @@ -3,16 +3,20 @@ (require "test-utils.ss" "typecheck-tests.ss" ;;fail + "subtype-tests.ss" ;; pass "type-equal-tests.ss" ;; pass "remove-intersect-tests.ss" ;; pass "parse-type-tests.ss" ;; pass - "type-annotation-test.ss" ;; pass - "module-tests.ss" ;; pass "subst-tests.ss" ;; pass "infer-tests.ss" ;; pass + "type-annotation-test.ss" ;; pass + + "module-tests.ss" ;; pass "contract-tests.ss" - (r:infer infer infer-dummy) racunit) + + (r:infer infer infer-dummy) + racunit racunit/text-ui) (provide unit-tests) @@ -22,7 +26,7 @@ (make-test-suite "Unit Tests" (for/list ([f (list - typecheck-tests + typecheck-tests subtype-tests type-equal-tests restrict-tests diff --git a/collects/tests/typed-scheme/unit-tests/typecheck-tests.rkt b/collects/tests/typed-scheme/unit-tests/typecheck-tests.rkt index 82c5b3cb..cfa83732 100644 --- a/collects/tests/typed-scheme/unit-tests/typecheck-tests.rkt +++ b/collects/tests/typed-scheme/unit-tests/typecheck-tests.rkt @@ -6,7 +6,8 @@ (require (private base-env prims type-annotation base-types-extra base-env-numeric - base-env-indexing) + base-env-indexing + parse-type) (typecheck typechecker) (rep type-rep filter-rep object-rep) (rename-in (types utils union convenience abbrev) @@ -17,7 +18,7 @@ (utils tc-utils utils) unstable/mutated-vars (env type-name-env type-environments init-envs) - racunit + racunit racunit/text-ui syntax/parse (for-syntax (utils tc-utils) (typecheck typechecker)