diff --git a/collects/typed-scheme/rep/object-rep.rkt b/collects/typed-scheme/rep/object-rep.rkt index e36c3a5a..3608a0e9 100644 --- a/collects/typed-scheme/rep/object-rep.rkt +++ b/collects/typed-scheme/rep/object-rep.rkt @@ -6,6 +6,7 @@ (dpe CarPE () [#:fold-rhs #:base]) (dpe CdrPE () [#:fold-rhs #:base]) (dpe SyntaxPE () [#:fold-rhs #:base]) +;; t is always a Name (can't put that into the contract b/c of circularity) (dpe StructPE ([t Type?] [idx natural-number/c]) [#:frees (free-vars* t) (free-idxs* t)] [#:fold-rhs (*StructPE (type-rec-id t) idx)]) diff --git a/collects/typed-scheme/typecheck/tc-toplevel.rkt b/collects/typed-scheme/typecheck/tc-toplevel.rkt index e970654b..4fab6fc5 100644 --- a/collects/typed-scheme/typecheck/tc-toplevel.rkt +++ b/collects/typed-scheme/typecheck/tc-toplevel.rkt @@ -11,7 +11,7 @@ ;; to appease syntax-parse "internal-forms.rkt" (rep type-rep) - (types utils convenience) + (types utils convenience type-table) (private parse-type type-annotation type-contract) (env global-env init-envs type-name-env type-alias-env lexical-env) unstable/mutated-vars syntax/id-table @@ -19,7 +19,7 @@ "provide-handling.rkt" "def-binding.rkt" (prefix-in c: racket/contract) - racket/dict + racket/dict (for-template "internal-forms.rkt" unstable/location @@ -306,10 +306,13 @@ [(new-provs ...) (generate-prov def-tbl provide-tbl #'the-variable-reference)]) #`(begin - (define the-variable-reference (quote-module-path)) + #,(if (null? (syntax-e #'(new-provs ...))) + #'(begin) + #'(define the-variable-reference (quote-module-path))) #,(env-init-code syntax-provide? provide-tbl def-tbl) #,(tname-env-init-code) #,(talias-env-init-code) + (begin-for-syntax #,(make-struct-table-code)) (begin new-provs ...))))) ;; typecheck a whole module diff --git a/collects/typed-scheme/types/type-table.rkt b/collects/typed-scheme/types/type-table.rkt index 78cc289c..154ac941 100644 --- a/collects/typed-scheme/types/type-table.rkt +++ b/collects/typed-scheme/types/type-table.rkt @@ -1,7 +1,8 @@ #lang scheme/base (require unstable/debug scheme/contract "../utils/utils.rkt" syntax/id-table racket/dict racket/match - (rep type-rep object-rep) (only-in (types abbrev utils) tc-results?) (utils tc-utils)) + (rep type-rep object-rep) (only-in (types abbrev utils) tc-results?) (utils tc-utils) + (env init-envs) mzlib/pconvert) (define table (make-hasheq)) @@ -25,9 +26,21 @@ [else #f])) (values (mk #f) (mk #t)))) +(define (make-struct-table-code) + (parameterize ([current-print-convert-hook converter] + [show-sharing #f]) + #`(begin #,@(for/list ([(k v) (in-dict struct-fn-table)] + #:when (bound-in-this-module k)) + (match v + [(list pe mut?) + #`(add-struct-fn! (quote-syntax #,k) + #,(print-convert pe) + #,mut?)]))))) + (p/c [add-typeof-expr (syntax? tc-results? . -> . any/c)] [type-of (syntax? . -> . tc-results?)] [reset-type-table (-> any/c)] [add-struct-fn! (identifier? StructPE? boolean? . -> . any/c)] [struct-accessor? (identifier? . -> . (or/c #f StructPE?))] - [struct-mutator? (identifier? . -> . (or/c #f StructPE?))]) \ No newline at end of file + [struct-mutator? (identifier? . -> . (or/c #f StructPE?))] + [make-struct-table-code (-> syntax?)]) \ No newline at end of file