Add tc-toplevel/full and tc-module/full and use them.
This commit is contained in:
parent
a9e8324a38
commit
feeb6c9163
|
@ -77,8 +77,8 @@
|
|||
(define (:print-type-impl stx)
|
||||
(syntax-parse stx
|
||||
[(_ e)
|
||||
(tc-setup stx #'e 'top-level tc-toplevel-form
|
||||
(lambda (expanded before type)
|
||||
(tc-toplevel/full stx #'e
|
||||
(λ (expanded type)
|
||||
#`(display
|
||||
#,(parameterize ([print-multi-line-case-> #t])
|
||||
(format "~a\n" (match type
|
||||
|
@ -93,13 +93,13 @@
|
|||
(syntax-parse stx
|
||||
[(_ op arg-type ...)
|
||||
(with-syntax ([(dummy-arg ...) (generate-temporaries #'(arg-type ...))])
|
||||
(tc-setup stx
|
||||
(tc-toplevel/full
|
||||
stx
|
||||
;; create a dummy function with the right argument types
|
||||
#`(lambda #,(stx-map type-label-property
|
||||
#'(dummy-arg ...) #'(arg-type ...))
|
||||
(op dummy-arg ...))
|
||||
'top-level tc-toplevel-form
|
||||
(lambda (expanded before type)
|
||||
(λ (expanded type)
|
||||
#`(display
|
||||
#,(format "~a\n"
|
||||
(match type
|
||||
|
@ -112,8 +112,8 @@
|
|||
(syntax-parse stx
|
||||
[(_ op desired-type)
|
||||
(let ([expected (parse-type #'desired-type)])
|
||||
(tc-setup stx #'op 'top-level tc-toplevel-form
|
||||
(lambda (expanded before type)
|
||||
(tc-toplevel/full stx #'op
|
||||
(λ (expanded type)
|
||||
(match type
|
||||
[(tc-result1: (and t (Function: _)) f o)
|
||||
(let ([cleaned (cleanup-type t expected)])
|
||||
|
|
|
@ -24,8 +24,7 @@
|
|||
(let ([pmb-form (syntax/loc stx (#%plain-module-begin forms ...))])
|
||||
(parameterize ([optimize? (or (and (not (attribute opt?)) (optimize?))
|
||||
(and (attribute opt?) (syntax-e (attribute opt?))))])
|
||||
(tc-setup
|
||||
stx pmb-form 'module-begin tc-module
|
||||
(tc-module/full stx pmb-form
|
||||
(λ (new-mod before-code after-code)
|
||||
(with-syntax*
|
||||
(;; pmb = #%plain-module-begin
|
||||
|
@ -61,9 +60,8 @@
|
|||
;; TODO(endobson): Remove the call to do-standard-inits when it is no longer necessary
|
||||
;; Cast at the top-level still needs this for some reason
|
||||
(do-standard-inits)
|
||||
(tc-setup
|
||||
stx #'form 'top-level tc-toplevel-form
|
||||
(λ (body2 before type)
|
||||
(tc-toplevel/full stx #'form
|
||||
(λ (body2 type)
|
||||
(with-syntax*
|
||||
([(optimized-body . _) (maybe-optimize #`(#,body2))])
|
||||
(syntax-parse body2
|
||||
|
|
|
@ -9,8 +9,11 @@
|
|||
(for-syntax racket/base)
|
||||
(for-template racket/base))
|
||||
(lazy-require [typed-racket/optimizer/optimizer (optimize-top)])
|
||||
(lazy-require [typed-racket/typecheck/tc-toplevel (tc-toplevel-form tc-module)])
|
||||
|
||||
(provide tc-setup invis-kw maybe-optimize init-current-type-names)
|
||||
(provide invis-kw maybe-optimize init-current-type-names
|
||||
tc-module/full
|
||||
tc-toplevel/full)
|
||||
|
||||
(define-syntax-class invis-kw
|
||||
#:literals (define-values define-syntaxes #%require
|
||||
|
@ -39,7 +42,7 @@
|
|||
|
||||
(define-logger online-check-syntax)
|
||||
|
||||
(define (tc-setup orig-stx stx expand-ctxt checker f)
|
||||
(define (tc-setup orig-stx stx expand-ctxt checker k)
|
||||
(set-box! typed-context? #t)
|
||||
;(start-timing (syntax-property stx 'enclosing-module-name))
|
||||
(with-handlers
|
||||
|
@ -73,6 +76,13 @@
|
|||
(parameterize ([orig-module-stx (or (orig-module-stx) orig-stx)]
|
||||
[expanded-module-stx fully-expanded-stx])
|
||||
(do-time "Starting `checker'")
|
||||
(define-values (pre-result post-result) (checker fully-expanded-stx))
|
||||
(call-with-values (λ () (checker fully-expanded-stx))
|
||||
(λ results
|
||||
(do-time "Typechecking Done")
|
||||
(f fully-expanded-stx pre-result post-result)))))
|
||||
(apply k fully-expanded-stx results)))))))
|
||||
|
||||
(define (tc-toplevel/full orig-stx stx k)
|
||||
(tc-setup orig-stx stx 'top-level tc-toplevel-form k))
|
||||
|
||||
(define (tc-module/full orig-stx stx k)
|
||||
(tc-setup orig-stx stx 'module-begin tc-module k))
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
|
||||
(provide/cond-contract
|
||||
[tc-module (syntax? . c:-> . (values syntax? syntax?))]
|
||||
[tc-toplevel-form (syntax? . c:-> . (values #f c:any/c))])
|
||||
[tc-toplevel-form (syntax? . c:-> . c:any/c)])
|
||||
|
||||
(define unann-defs (make-free-id-table))
|
||||
|
||||
|
@ -359,17 +359,15 @@
|
|||
|
||||
;; typecheck a top-level form
|
||||
;; used only from #%top-interaction
|
||||
;; syntax -> (values #f (or/c void? tc-results/c))
|
||||
;; syntax -> (or/c void? tc-results/c)
|
||||
(define (tc-toplevel-form form)
|
||||
(syntax-parse form
|
||||
;; Don't open up `begin`s that are supposed to be ignored
|
||||
[(~and ((~literal begin) e ...)
|
||||
(~not (~or _:ignore^ _:ignore-some^)))
|
||||
(define result
|
||||
(begin0
|
||||
(for/last ([form (in-syntax #'(e ...))])
|
||||
(define-values (_ result) (tc-toplevel-form form))
|
||||
result))
|
||||
(begin0 (values #f result)
|
||||
(tc-toplevel-form form))
|
||||
(report-all-errors))]
|
||||
[_
|
||||
;; Handle type aliases
|
||||
|
@ -386,6 +384,6 @@
|
|||
(refine-struct-variance! (list parsed))
|
||||
(register-parsed-struct-bindings! parsed))
|
||||
(tc-toplevel/pass1 form)
|
||||
(begin0 (values #f (tc-toplevel/pass2 form))
|
||||
(begin0 (tc-toplevel/pass2 form)
|
||||
(report-all-errors))]))
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user