Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

type-contract: add common ctc-cache #917

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions typed-racket-lib/typed-racket/core.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,19 @@
(with-refinements?))])
(tc-module/full stx pmb-form
(λ (new-mod pre-before-code pre-after-code)
(define ctc-cache (make-hash))
(with-syntax*
(;; pmb = #%plain-module-begin
[(pmb . body2) new-mod]
;; perform the provide transformation from [Culpepper 07]
[transformed-body (begin0 (remove-provides #'body2) (do-time "Removed provides"))]
;; add the real definitions of contracts on requires
[transformed-body
(begin0 (change-contract-fixups (syntax->list #'transformed-body))
(begin0 (change-contract-fixups (syntax->list #'transformed-body) ctc-cache)
(do-time "Fixed contract ids"))]
;; add the real definitions of contracts on the before- and after-code
[(before-code ...) (change-provide-fixups (flatten-all-begins pre-before-code))]
[(after-code ...) (begin0 (change-provide-fixups (flatten-all-begins pre-after-code))
[(before-code ...) (change-provide-fixups (flatten-all-begins pre-before-code) ctc-cache)]
[(after-code ...) (begin0 (change-provide-fixups (flatten-all-begins pre-after-code) ctc-cache)
(do-time "Generated contracts"))]
;; potentially optimize the code based on the type information
[(optimized-body ...) (maybe-optimize #'transformed-body)] ;; has own call to do-time
Expand Down
3 changes: 1 addition & 2 deletions typed-racket-lib/typed-racket/private/type-contract.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,7 @@
;; submodule, which always has the above `require`s.
(define include-extra-requires? (box #f))

(define (change-contract-fixups forms)
(define ctc-cache (make-hash))
(define (change-contract-fixups forms [ctc-cache (make-hash)])
(with-new-name-tables
(for/list ((e (in-list forms)))
(if (not (has-contract-def-property? e))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,9 @@
;; doesn't work for looking up types in the optimizer.
(define new-stx
(apply append
(for/list ([form (in-list forms)])
(change-contract-fixups (maybe-optimize (list form))))))
(let ([ctc-cache (make-hash)])
(for/list ([form (in-list forms)])
(change-contract-fixups (maybe-optimize (list form)) ctc-cache)))))
(kont new-stx result)]))])]))

;; Trampoline that continues the typechecking process.
Expand Down