diff --git a/typed-racket-lib/typed-racket/core.rkt b/typed-racket-lib/typed-racket/core.rkt index 4e3758ad2..bd5ef1496 100644 --- a/typed-racket-lib/typed-racket/core.rkt +++ b/typed-racket-lib/typed-racket/core.rkt @@ -48,10 +48,12 @@ (and (attribute opt?) (syntax-e (attribute opt?))))] [with-refinements? (and (or (attribute refinement-reasoning?) (with-refinements?)) - (when (not (eq? te-mode deep)) + (unless (eq? te-mode deep) (raise-arguments-error - (string->symbol (format "typed/racket/~a" (keyword->string (syntax-e te-attr)))) - "#:with-refinements unsupported")))]) + (string->symbol (format "typed/racket/~a" + (keyword->string + (syntax-e te-attr)))) + "#:with-refinements unsupported")))]) (tc-module/full te-mode stx pmb-form (λ (new-mod pre-before-code pre-after-code) (define ctc-cache (make-hash)) diff --git a/typed-racket-lib/typed-racket/env/global-env.rkt b/typed-racket-lib/typed-racket/env/global-env.rkt index 116c15a03..059469d67 100644 --- a/typed-racket-lib/typed-racket/env/global-env.rkt +++ b/typed-racket-lib/typed-racket/env/global-env.rkt @@ -74,10 +74,8 @@ #:when (attribute type))) (define (maybe-finish-register-type id) - (let ([v (free-id-table-ref the-mapping id)]) - (if (box? v) - (register-type id (unbox v)) - #f))) + (define v (free-id-table-ref the-mapping id)) + (and (box? v) (register-type id (unbox v)))) (define (unregister-type id) (free-id-table-remove! the-mapping id)) @@ -91,13 +89,15 @@ the-mapping (lambda (id e) (when (box? e) - (let ([bnd (identifier-binding id)]) - (tc-error/delayed #:stx id - "Declaration for `~a' provided, but `~a' ~a" - (syntax-e id) (syntax-e id) - (cond [(eq? bnd 'lexical) "is a lexical binding"] ;; should never happen - [(not bnd) "has no definition"] - [else "is defined in another module"]))))))) + (define bnd (identifier-binding id)) + (tc-error/delayed #:stx id + "Declaration for `~a' provided, but `~a' ~a" + (syntax-e id) + (syntax-e id) + (cond + [(eq? bnd 'lexical) "is a lexical binding"] ;; should never happen + [(not bnd) "has no definition"] + [else "is defined in another module"])))))) ;; map over the-mapping, producing a list ;; (id type -> T) -> listof[T] diff --git a/typed-racket-lib/typed-racket/env/init-envs.rkt b/typed-racket-lib/typed-racket/env/init-envs.rkt index c456cbf85..4b0614fe1 100644 --- a/typed-racket-lib/typed-racket/env/init-envs.rkt +++ b/typed-racket-lib/typed-racket/env/init-envs.rkt @@ -331,11 +331,10 @@ [(Instance: ty) `(make-Instance ,(type->sexp ty))] [(Signature: name extends mapping) (define (serialize-mapping m) - (map (lambda (id/ty) - (define id (car id/ty)) - (define ty (force (cdr id/ty))) - `(cons (quote-syntax ,id) ,(type->sexp ty))) - m)) + (for/list ([id/ty (in-list m)]) + (define id (car id/ty)) + (define ty (force (cdr id/ty))) + `(cons (quote-syntax ,id) ,(type->sexp ty)))) (define serialized-extends (and extends `(quote-syntax ,extends))) `(make-Signature (quote-syntax ,name) ,serialized-extends @@ -437,11 +436,10 @@ `(make-PrefabPE (quote ,key) ,idx)])) (define (bound-in-this-module id) - (let ([binding (identifier-binding id)]) - (if (and (list? binding) (module-path-index? (car binding))) - (let-values ([(mp base) (module-path-index-split (car binding))]) - (not mp)) - #f))) + (define binding (identifier-binding id)) + (and (and (list? binding) (module-path-index? (car binding))) + (let-values ([(mp base) (module-path-index-split (car binding))]) + (not mp)))) (define (make-init-code map f) (define (bound-f id v) diff --git a/typed-racket-lib/typed-racket/env/type-alias-env.rkt b/typed-racket-lib/typed-racket/env/type-alias-env.rkt index de5b4c3e9..1996a739d 100644 --- a/typed-racket-lib/typed-racket/env/type-alias-env.rkt +++ b/typed-racket-lib/typed-racket/env/type-alias-env.rkt @@ -80,10 +80,10 @@ (match v [(struct unresolved (stx _ persistent?)) (set-unresolved-in-process! v #t) - (let ([t (parse-type stx)]) - (when persistent? - (mapping-put! id (make-resolved t))) - t)] + (define t (parse-type stx)) + (when persistent? + (mapping-put! id (make-resolved t))) + t] [(struct resolved (t)) t])) diff --git a/typed-racket-lib/typed-racket/rep/core-rep.rkt b/typed-racket-lib/typed-racket/rep/core-rep.rkt index 3e32e576f..c3178cf4d 100644 --- a/typed-racket-lib/typed-racket/rep/core-rep.rkt +++ b/typed-racket-lib/typed-racket/rep/core-rep.rkt @@ -247,7 +247,7 @@ (-> Result? Result?) (match-define (Result: type propset optobject n-existentials) result) (cond - [(> n-existentials 0) + [(positive? n-existentials) (define syms (hash-ref type-var-name-table result (build-list n-existentials (lambda _ (gensym))))) (define vars (map make-F syms)) (make-Result (instantiate-type type vars) (instantiate-propset propset vars) optobject n-existentials)] diff --git a/typed-racket-lib/typed-racket/rep/free-ids.rkt b/typed-racket-lib/typed-racket/rep/free-ids.rkt index f069dd39a..6c8235874 100644 --- a/typed-racket-lib/typed-racket/rep/free-ids.rkt +++ b/typed-racket-lib/typed-racket/rep/free-ids.rkt @@ -69,11 +69,9 @@ (cond [(member x seen free-identifier=?) (cons x seen)] [else - (begin0 - (let ([seen+x (cons x seen)]) - (for/or ([neighbor (in-list (cdr (assoc x deps free-identifier=?)))]) - (and (not (member neighbor visited free-identifier=?)) - (visit neighbor seen+x)))) + (define seen+x (cons x seen)) + (begin0 (for/or ([neighbor (in-list (cdr (assoc x deps free-identifier=?)))]) + (and (not (member neighbor visited free-identifier=?)) (visit neighbor seen+x))) (set! visited (cons x visited)))])) (match (for/or ([entry (in-list deps)]) (visit (car entry) '())) diff --git a/typed-racket-lib/typed-racket/rep/prop-rep.rkt b/typed-racket-lib/typed-racket/rep/prop-rep.rkt index 953332504..069950753 100644 --- a/typed-racket-lib/typed-racket/rep/prop-rep.rkt +++ b/typed-racket-lib/typed-racket/rep/prop-rep.rkt @@ -143,8 +143,7 @@ [#:for-each (f) (for-each f ps)] [#:custom-constructor/contract (-> (listof (or/c TypeProp? NotTypeProp? LeqProp?)) OrProp?) - (let ([ps (sort ps (λ (p q) (unsafe-fx<= (eq-hash-code p) - (eq-hash-code q))))]) + (let ([ps (sort ps unsafe-fx<= #:key eq-hash-code)]) (intern-single-ref! orprop-intern-table ps diff --git a/typed-racket-lib/typed-racket/tc-setup.rkt b/typed-racket-lib/typed-racket/tc-setup.rkt index 197f2ea2d..6f2b123f1 100644 --- a/typed-racket-lib/typed-racket/tc-setup.rkt +++ b/typed-racket-lib/typed-racket/tc-setup.rkt @@ -36,15 +36,15 @@ ;; types are enforced (not no-check etc.), ;; PLT_TR_NO_OPTIMIZE is not set, and the ;; current code inspector has sufficient privileges - (if (and (optimize?) - (memq (current-type-enforcement-mode) (list deep shallow)) - (not (getenv "PLT_TR_NO_OPTIMIZE")) - (authorized-code-inspector?)) - (begin - (do-time "Starting optimizer") - (begin0 (stx-map optimize-top body) - (do-time "Optimized"))) - body)) + (cond + [(and (optimize?) + (memq (current-type-enforcement-mode) (list deep shallow)) + (not (getenv "PLT_TR_NO_OPTIMIZE")) + (authorized-code-inspector?)) + (do-time "Starting optimizer") + (begin0 (stx-map optimize-top body) + (do-time "Optimized"))] + [else body])) (define (maybe-shallow-rewrite body-stx ctc-cache) (case (current-type-enforcement-mode) diff --git a/typed-racket-lib/typed-racket/typed-reader.rkt b/typed-racket-lib/typed-racket/typed-reader.rkt index 7cb6e9340..a9f157bcc 100644 --- a/typed-racket-lib/typed-racket/typed-reader.rkt +++ b/typed-racket-lib/typed-racket/typed-reader.rkt @@ -8,73 +8,82 @@ (define (skip-whitespace port) ;; Skips whitespace characters, sensitive to the current ;; readtable's definition of whitespace - (let ([ch (peek-char port)]) - (unless (eof-object? ch) - ;; Consult current readtable: - (let-values ([(like-ch/sym proc dispatch-proc) - (readtable-mapping (current-readtable) ch)]) - ;; If like-ch/sym is whitespace, then ch is whitespace - (when (and (char? like-ch/sym) - (char-whitespace? like-ch/sym)) - (read-char port) - (skip-whitespace port)))))) + (define ch (peek-char port)) + (unless (eof-object? ch) + ;; Consult current readtable: + (define-values (like-ch/sym proc dispatch-proc) (readtable-mapping (current-readtable) ch)) + ;; If like-ch/sym is whitespace, then ch is whitespace + (when (and (char? like-ch/sym) (char-whitespace? like-ch/sym)) + (read-char port) + (skip-whitespace port)))) (define (skip-comments read-one port src) ;; Recursive read, but skip comments and detect EOF (let loop () - (let ([v (read-one)]) - (cond - [(special-comment? v) (loop)] - [(eof-object? v) - (let-values ([(l c p) (port-next-location port)]) - (raise-read-eof-error "unexpected EOF in type annotation" src l c p 1))] - [else v])))) + (define v (read-one)) + (cond + [(special-comment? v) (loop)] + [(eof-object? v) + (define-values (l c p) (port-next-location port)) + (raise-read-eof-error "unexpected EOF in type annotation" src l c p 1)] + [else v]))) (define (parse port read-one src) (skip-whitespace port) - (let ([name (read-one)]) - (begin0 - (begin (skip-whitespace port) - (let ([next (read-one)]) - (case (syntax-e next) - ;; type annotation - [(:) (skip-whitespace port) - (type-label-property name (syntax->datum (read-one)))] - [(::) (skip-whitespace port) - (datum->syntax name `(ann ,name : ,(read-one)))] - [(@) (let ([elems (let loop ([es '()]) - (skip-whitespace port) - (if (equal? #\} (peek-char port)) - (reverse es) - (loop (cons (read-one) es))))]) - (datum->syntax name `(inst ,name : ,@elems)))] - ;; arbitrary property annotation - [(PROP) (skip-whitespace port) - (let* ([prop-name (syntax-e (read-one))]) - (skip-whitespace port) - (syntax-property name prop-name (read-one)))] - ;; otherwise error - [else - (let-values ([(l c p) (port-next-location port)]) - (raise-read-error (format "typed expression ~a must be followed by :, ::, or @" - (syntax->datum name)) src l c p 1))]))) - (skip-whitespace port) - (let ([c (read-char port)]) - (unless (equal? #\} c) - (let-values ([(l c p) (port-next-location port)]) - (raise-read-error (format "typed expression ~a not properly terminated" (syntax->datum name)) src l c p 1))))))) + (define name (read-one)) + (begin0 (begin + (skip-whitespace port) + (let ([next (read-one)]) + (case (syntax-e next) + ;; type annotation + [(:) + (skip-whitespace port) + (type-label-property name (syntax->datum (read-one)))] + [(::) + (skip-whitespace port) + (datum->syntax name `(ann ,name : ,(read-one)))] + [(@) + (let ([elems (let loop ([es '()]) + (skip-whitespace port) + (if (equal? #\} (peek-char port)) + (reverse es) + (loop (cons (read-one) es))))]) + (datum->syntax name `(inst ,name : ,@elems)))] + ;; arbitrary property annotation + [(PROP) + (skip-whitespace port) + (let* ([prop-name (syntax-e (read-one))]) + (skip-whitespace port) + (syntax-property name prop-name (read-one)))] + ;; otherwise error + [else + (let-values ([(l c p) (port-next-location port)]) + (raise-read-error (format "typed expression ~a must be followed by :, ::, or @" + (syntax->datum name)) + src + l + c + p + 1))]))) + (skip-whitespace port) + (let ([c (read-char port)]) + (unless (equal? #\} c) + (let-values ([(l c p) (port-next-location port)]) + (raise-read-error (format "typed expression ~a not properly terminated" + (syntax->datum name)) + src + l + c + p + 1)))))) (define parse-id-type - (case-lambda - [(ch port src line col pos) - ;; `read-syntax' mode - (datum->syntax - #f - (parse port - (lambda () (read-syntax src port )) - src) - (let-values ([(l c p) (port-next-location port)]) - (list src line col pos (and pos (- p pos)))))])) + (λ (ch port src line col pos) + ;; `read-syntax' mode + (datum->syntax #f + (parse port (lambda () (read-syntax src port)) src) + (let-values ([(l c p) (port-next-location port)]) + (list src line col pos (and pos (- p pos))))))) (define (readtable) ; don't install the reader macro if a dispatch macro on the open brace has already been installed diff --git a/typed-racket-lib/typed-racket/utils/any-wrap.rkt b/typed-racket-lib/typed-racket/utils/any-wrap.rkt index 65f793f26..f8ff873e0 100644 --- a/typed-racket-lib/typed-racket/utils/any-wrap.rkt +++ b/typed-racket-lib/typed-racket/utils/any-wrap.rkt @@ -83,29 +83,28 @@ (define-values (sym init auto ref set! imms par skip?) (parameterize ([current-inspector inspector]) (struct-type-info struct-type))) - (define-values (fun/chap-list _) + (define fun/chap-list (for/fold ([res null] - [imms imms]) - ([n (in-range (+ init auto))]) + [imms imms] + #:result res) + ([n (in-range (+ init auto))]) (if (and (pair? imms) (= (car imms) n)) ;; field is immutable - (values - (list* (make-struct-field-accessor ref n) - (lambda (s v) (with-contract-continuation-mark - blame+neg-party - (any-wrap/traverse v neg-party seen))) - res) - (cdr imms)) + (values (list* (make-struct-field-accessor ref n) + (lambda (s v) + (with-contract-continuation-mark blame+neg-party + (any-wrap/traverse v neg-party seen))) + res) + (cdr imms)) ;; field is mutable - (values - (list* (make-struct-field-accessor ref n) - (lambda (s v) (with-contract-continuation-mark - blame+neg-party - (any-wrap/traverse v neg-party seen))) - (make-struct-field-mutator set! n) - (lambda (s v) (fail neg-party s)) - res) - imms)))) + (values (list* (make-struct-field-accessor ref n) + (lambda (s v) + (with-contract-continuation-mark blame+neg-party + (any-wrap/traverse v neg-party seen))) + (make-struct-field-mutator set! n) + (lambda (s v) (fail neg-party s)) + res) + imms)))) (cond [par (append fun/chap-list (extract-functions par))] [else fun/chap-list])) diff --git a/typed-racket-lib/typed-racket/utils/disarm.rkt b/typed-racket-lib/typed-racket/utils/disarm.rkt index 3d9ffcd20..42c11a05f 100644 --- a/typed-racket-lib/typed-racket/utils/disarm.rkt +++ b/typed-racket-lib/typed-racket/utils/disarm.rkt @@ -9,17 +9,16 @@ (let loop ([v stx]) (cond [(syntax? v) - (let* ([stx (syntax-disarm v orig-insp)] + (let* ([stx v] [r (loop (syntax-e stx))]) (if (eq? r (syntax-e stx)) stx (datum->syntax stx r stx stx)))] - [(pair? v) (let ([a (loop (car v))] - [d (loop (cdr v))]) - (if (and (eq? a (car v)) - (eq? d (cdr v))) - v - (cons a d)))] + [(pair? v) (define a (loop (car v))) + (define d (loop (cdr v))) + (if (and (eq? a (car v)) (eq? d (cdr v))) + v + (cons a d))] [else v]))) (define orig-insp (variable-reference->module-declaration-inspector diff --git a/typed-racket-lib/typed-racket/utils/opaque-object.rkt b/typed-racket-lib/typed-racket/utils/opaque-object.rkt index 5263c1004..7f1f78825 100644 --- a/typed-racket-lib/typed-racket/utils/opaque-object.rkt +++ b/typed-racket-lib/typed-racket/utils/opaque-object.rkt @@ -53,7 +53,7 @@ (define guard/c (dynamic-object/c methods method-ctcs fields field-ctcs)) (define guard/c-proj ((contract-late-neg-projection guard/c) blame)) (λ (obj neg-party) - (when (not (object? obj)) + (unless (object? obj) (raise-blame-error blame #:missing-party neg-party obj "expected an object got ~a" obj)) (define actual-fields (field-names obj)) (define actual-methods diff --git a/typed-racket-lib/typed-racket/utils/plambda-utils.rkt b/typed-racket-lib/typed-racket/utils/plambda-utils.rkt index 3d382d9a0..7271aa3ae 100644 --- a/typed-racket-lib/typed-racket/utils/plambda-utils.rkt +++ b/typed-racket-lib/typed-racket/utils/plambda-utils.rkt @@ -28,22 +28,19 @@ (filter pair? (map rest tvarss))) (define (get-poly-tvarss form) - (let ([plambda-tvars - (let ([p (plambda-prop form)]) - (match (and p (map syntax-e (syntax->list p))) - [#f #f] - [(list var ... dvar '...) - (list (list var dvar))] - [(list id ...) - (list id)]))] - [scoped-tvarss - (for/list ((tvarss (in-list (lookup-scoped-tvar-layer form)))) - (for/list ((tvar (in-list tvarss))) - (match tvar - [(list (list v ...) dotted-v) - (list (map syntax-e v) (syntax-e dotted-v))] - [(list v ...) (map syntax-e v)])))]) - (if plambda-tvars - (cons plambda-tvars scoped-tvarss) - scoped-tvarss))) + (define p (plambda-prop form)) + (define plambda-tvars + (match (and p (map syntax-e (syntax->list p))) + [#f #f] + [(list var ... dvar '...) (list (list var dvar))] + [(list id ...) (list id)])) + (define scoped-tvarss + (for/list ([tvarss (in-list (lookup-scoped-tvar-layer form))]) + (for/list ([tvar (in-list tvarss)]) + (match tvar + [(list (list v ...) dotted-v) (list (map syntax-e v) (syntax-e dotted-v))] + [(list v ...) (map syntax-e v)])))) + (if plambda-tvars + (cons plambda-tvars scoped-tvarss) + scoped-tvarss)) diff --git a/typed-racket-lib/typed-racket/utils/prefab.rkt b/typed-racket-lib/typed-racket/utils/prefab.rkt index 00f356524..7014ef7ac 100644 --- a/typed-racket-lib/typed-racket/utils/prefab.rkt +++ b/typed-racket-lib/typed-racket/utils/prefab.rkt @@ -60,7 +60,7 @@ [(list (? number? n) (? vector? mut)) `(,base-sym ,n (0 #f) ,mut)] [(list (and auto (list auto-n _)) (? vector? mut)) - `(,base-sym ,(- remaining-length auto-n) ,auto ,mut)] + (list base-sym (- remaining-length auto-n) auto mut)] [(list (? number? n)) `(,base-sym ,n (0 #f) #())] [(list (and auto (list auto-n _))) diff --git a/typed-racket-lib/typed-racket/utils/shallow-contract.rkt b/typed-racket-lib/typed-racket/utils/shallow-contract.rkt index 25b486069..d93a7c964 100644 --- a/typed-racket-lib/typed-racket/utils/shallow-contract.rkt +++ b/typed-racket-lib/typed-racket/utils/shallow-contract.rkt @@ -46,23 +46,19 @@ (else ;#(keyword any/c real?)) diff --git a/typed-racket-lib/typed-racket/utils/struct-info.rkt b/typed-racket-lib/typed-racket/utils/struct-info.rkt index ec16b6ad2..ba9ca8fef 100644 --- a/typed-racket-lib/typed-racket/utils/struct-info.rkt +++ b/typed-racket-lib/typed-racket/utils/struct-info.rkt @@ -108,9 +108,7 @@ ;; the function returns the corresponding structure's type name (define/cond-contract (maybe-struct-info-wrapper-type ins) (c:-> c:any/c (c:or/c #f identifier?)) - (if (struct-info-wrapper? ins) - (struct-info-wrapper-type ins) - #f)) + (and (struct-info-wrapper? ins) (struct-info-wrapper-type ins))) ;; create a *-wrapper instance based on sname-is-constr? (define/cond-contract (make-struct-info-wrapper* id info type [sname-is-constr? #t]) diff --git a/typed-racket-lib/typed-racket/utils/tc-utils.rkt b/typed-racket-lib/typed-racket/utils/tc-utils.rkt index cbd84cf51..d6a67c5f3 100644 --- a/typed-racket-lib/typed-racket/utils/tc-utils.rkt +++ b/typed-racket-lib/typed-racket/utils/tc-utils.rkt @@ -77,20 +77,19 @@ don't depend on any other portion of the system (define warn-unreachable? (make-parameter #t)) (define (warn-unreachable e) - (let ([l (current-logger)] - [stx (locate-stx e)]) - (when (and (warn-unreachable?) - (log-level? l 'warning) - (and (syntax-transforming?) - #;(syntax-original? (syntax-local-introduce e))) - #;(and (orig-module-stx) - (eq? (debugf syntax-source-module e) - (debugf syntax-source-module (orig-module-stx)))) - #;(syntax-source-module stx)) - (log-message l 'warning - (format "Typed Racket has detected unreachable code: ~.s" - (locate-stx e)) - e)))) + (define l (current-logger)) + (locate-stx e) + (when (and (warn-unreachable?) + (log-level? l 'warning) + (and (syntax-transforming?) #;(syntax-original? (syntax-local-introduce e))) + #;(and (orig-module-stx) + (eq? (debugf syntax-source-module e) + (debugf syntax-source-module (orig-module-stx)))) + #;(syntax-source-module stx)) + (log-message l + 'warning + (format "Typed Racket has detected unreachable code: ~.s" (locate-stx e)) + e))) (define locate-stx ;; this hash handles using `locate-stx` even when orig/expand change @@ -106,9 +105,9 @@ don't depend on any other portion of the system [else stx])))) (define (raise-typecheck-error msg stxs) - (if (null? (cdr stxs)) - (raise-syntax-error (string->symbol "Type Checker") msg (car stxs)) - (raise-syntax-error (string->symbol "Type Checker") msg #f #f stxs))) + (when (null? (cdr stxs)) + (raise-syntax-error (string->symbol "Type Checker") msg (car stxs))) + (raise-syntax-error (string->symbol "Type Checker") msg #f #f stxs)) (define delayed-errors null) @@ -137,18 +136,17 @@ don't depend on any other portion of the system (reset-errors!) (log-type-error (err-msg f) (err-stx f)) (raise-typecheck-error (err-msg f) (err-stx f))] - [else (let ([stxs - (for/list ([e (in-list l)]) - (with-handlers ([exn:fail:syntax? - (λ (e) ((error-display-handler) (exn-message e) e))]) - (log-type-error (err-msg e) (err-stx e)) - (raise-typecheck-error (err-msg e) (err-stx e))) - (err-stx e))]) - (reset-errors!) - (unless (null? stxs) - (raise-typecheck-error (format "Summary: ~a errors encountered" - (length stxs)) - (apply append stxs))))])) + [else (define stxs + (for/list ([e (in-list l)]) + (with-handlers ([exn:fail:syntax? (λ (e) + ((error-display-handler) (exn-message e) e))]) + (log-type-error (err-msg e) (err-stx e)) + (raise-typecheck-error (err-msg e) (err-stx e))) + (err-stx e))) + (reset-errors!) + (unless (null? stxs) + (raise-typecheck-error (format "Summary: ~a errors encountered" (length stxs)) + (apply append stxs)))])) ;; Returns #t if there's a type error recorded at the same position as ;; the given syntax object. Does not return a useful result if the @@ -197,17 +195,13 @@ don't depend on any other portion of the system (define delay-errors? (make-parameter #f)) (define (tc-error/delayed msg #:stx [stx* (current-orig-stx)] . rest) - (let ([stx (locate-stx stx*)]) - (unless (syntax? stx) - (int-err "erroneous syntax was not a syntax object: ~a\n (error message: ~a)" - stx - msg)) - (current-type-error? #t) - (if (delay-errors?) - (set! delayed-errors (cons (make-err (apply format msg rest) - (list stx)) - delayed-errors)) - (raise-typecheck-error (apply format msg rest) (list stx))))) + (define stx (locate-stx stx*)) + (unless (syntax? stx) + (int-err "erroneous syntax was not a syntax object: ~a\n (error message: ~a)" stx msg)) + (current-type-error? #t) + (if (delay-errors?) + (set! delayed-errors (cons (make-err (apply format msg rest) (list stx)) delayed-errors)) + (raise-typecheck-error (apply format msg rest) (list stx)))) ;; Produce a type error using modern Racket error syntax. ;; Avoid using format directives in the `msg`, `more`, and `field` @@ -246,22 +240,25 @@ don't depend on any other portion of the system ;; produce a type error, using the current syntax (define (tc-error msg . rest) - (let* ([ostx (current-orig-stx)] - [ostxs (if (list? ostx) ostx (list ostx))] - [stxs (map locate-stx ostxs)]) - (current-type-error? #t) - ;; If this isn't original syntax, then we can get some pretty bogus error - ;; messages. Note that this is from a macro expansion, so that introduced - ;; vars and such don't confuse the user. - (cond - [(or (not (orig-module-stx)) - (for/and ([s (in-list ostxs)] #:when s) - (eq? (syntax-source s) (syntax-source (orig-module-stx))))) - (raise-typecheck-error (apply format msg rest) stxs)] - [else (raise-typecheck-error - (apply format (string-append "Error in macro expansion -- " msg) - rest) - stxs)]))) + (define ostx (current-orig-stx)) + (define ostxs + (if (list? ostx) + ostx + (list ostx))) + (define stxs (map locate-stx ostxs)) + (current-type-error? #t) + ;; If this isn't original syntax, then we can get some pretty bogus error + ;; messages. Note that this is from a macro expansion, so that introduced + ;; vars and such don't confuse the user. + (cond + [(or (not (orig-module-stx)) + (for/and ([s (in-list ostxs)] + #:when s) + (eq? (syntax-source s) (syntax-source (orig-module-stx))))) + (raise-typecheck-error (apply format msg rest) stxs)] + [else + (raise-typecheck-error (apply format (string-append "Error in macro expansion -- " msg) rest) + stxs)])) ;; produce a type error, given a particular syntax (define (tc-error/stx stx msg . rest) diff --git a/typed-racket-lib/typed-racket/utils/utils.rkt b/typed-racket-lib/typed-racket/utils/utils.rkt index 6bb2bd48a..4b76d76d2 100644 --- a/typed-racket-lib/typed-racket/utils/utils.rkt +++ b/typed-racket-lib/typed-racket/utils/utils.rkt @@ -180,7 +180,7 @@ at least theoretically. (begin (define (name . args) . body) (provide name)))])) -(define-simple-macro (define/cond-contract/provide (name:id . args) c . body) +(define-syntax-parse-rule (define/cond-contract/provide (name:id . args) c . body) (begin (define (name . args) . body) (provide/cond-contract [name c]))) @@ -377,10 +377,9 @@ at least theoretically. ;; quick in-list/rest and in-list-cycle sanity checks (module+ test - (unless (equal? (for/list ([_ (in-range 0)] - [val (in-list/rest (list 1 2) #f)]) - val) - (list)) + (unless (null? (for/list ([_ (in-range 0)] + [val (in-list/rest (list 1 2) #f)]) + val)) (error 'in-list/rest "broken!")) (unless (equal? (for/list ([_ (in-range 2)] [val (in-list/rest (list 1 2) #f)]) @@ -446,20 +445,20 @@ at least theoretically. (cond [(null? entries) (list (cons key val))] [else - (let ([entry (car entries)]) - (if (equal? (car entry) key) - (cons (cons key val) (cdr entries)) - (cons entry (loop (cdr entries)))))]))) + (define entry (car entries)) + (if (equal? (car entry) key) + (cons (cons key val) (cdr entries)) + (cons entry (loop (cdr entries))))]))) (define (assoc-remove d key) (let loop ([xd d]) (cond [(null? xd) null] [else - (let ([a (car xd)]) - (if (equal? (car a) key) - (cdr xd) - (cons a (loop (cdr xd)))))]))) + (define a (car xd)) + (if (equal? (car a) key) + (cdr xd) + (cons a (loop (cdr xd))))]))) (define (in-assoc-proc l) (in-parallel (map car l) (map cdr l))) diff --git a/typed-racket-test/performance/infer-timing.rkt b/typed-racket-test/performance/infer-timing.rkt index 72e09b02b..c095da01e 100644 --- a/typed-racket-test/performance/infer-timing.rkt +++ b/typed-racket-test/performance/infer-timing.rkt @@ -64,10 +64,8 @@ ;; once we have a set of props that are true/false based on reaching ;; a certain point, this will be more useful (define (fx-from-cases . cases) - (apply from-cases (map (lambda (x) - (add-unconditional-prop-all-args - x -Fixnum)) - (flatten cases)))) + (apply from-cases (for/list ([x (in-list (flatten cases))]) + (add-unconditional-prop-all-args x -Fixnum)))) (define (binop t [r t]) (t t . -> . r)) @@ -407,7 +405,8 @@ (displayln `(big ,n)) (define ty-list (append ts ts)) (collect-garbage) (collect-garbage) (collect-garbage) - (define run (λ () (void (bigcall n ty-list)))) + (define (run) + (void (bigcall n ty-list))) (cond [hsbencher (define-values (vs t r gc) (time-apply run null))