Adjust contract-out so it uses the provide transformer machinery properly
closes PR 13946 This is probably not the optimal way to make this change; better would have been to refactor the existing provide/contract implementation so it does not glom the provides all together in the first place (instead of pulling them out afterwards). Do it this way anyways, because I have a big pile of contract-system changes in another branch that also changes around how provide/contract works: this way will be much easier to rebase those changes off of.
This commit is contained in:
parent
3b76628eb1
commit
a8405eb77d
|
@ -1076,6 +1076,21 @@
|
|||
'pos 'neg))))
|
||||
(eval '(require 'contract-struct/c-2b))))
|
||||
|
||||
(test/spec-passed/result
|
||||
'contract-out-rename1
|
||||
'(begin
|
||||
(eval '(module contract-out-rename1-a racket/base
|
||||
(require racket/contract/base)
|
||||
(provide (prefix-out my- (contract-out [f any/c])))
|
||||
(define f 11)))
|
||||
(eval '(module contract-out-rename1-b racket/base
|
||||
(require 'contract-out-rename1-a)
|
||||
(define contract-out-rename1-my-f my-f)
|
||||
(provide contract-out-rename1-my-f)))
|
||||
(eval '(require 'contract-out-rename1-b))
|
||||
(eval 'contract-out-rename1-my-f))
|
||||
11)
|
||||
|
||||
|
||||
|
||||
(contract-eval
|
||||
|
|
|
@ -21,9 +21,38 @@
|
|||
;; check for syntax errors
|
||||
(true-provide/contract stx #t 'contract-out)
|
||||
|
||||
(syntax-case stx ()
|
||||
[(_ . args)
|
||||
(syntax-local-lift-module-end-declaration
|
||||
#`(provide/contract-for-contract-out . args))])
|
||||
|
||||
#`(combine-out))))
|
||||
(with-syntax ([(contracted-vars-info) (generate-temporaries '(contracted-vars-info))])
|
||||
(syntax-local-lift-module-end-declaration
|
||||
#`(handle-contract-out contracted-vars-info #,stx))
|
||||
|
||||
#`(provide-contracted-vars contracted-vars-info)))))
|
||||
|
||||
(define-syntax (handle-contract-out stx)
|
||||
(syntax-case stx ()
|
||||
[(_ contracted-vars-info orig-stx)
|
||||
(let ()
|
||||
(define provide-clauses '())
|
||||
(define without-provide-clauses
|
||||
(let loop ([stx (true-provide/contract #'orig-stx #f 'contract-out)])
|
||||
(syntax-case stx (begin provide)
|
||||
[(begin args ...)
|
||||
#`(begin #,@(map loop (syntax->list #'(args ...))))]
|
||||
[(provide clause ...)
|
||||
(identifier? #'x)
|
||||
(begin (set! provide-clauses (append (syntax->list #'(clause ...))
|
||||
provide-clauses))
|
||||
#'(begin))]
|
||||
[x stx])))
|
||||
#`(begin
|
||||
#,without-provide-clauses
|
||||
(define-syntax contracted-vars-info (quote-syntax #,provide-clauses))))]))
|
||||
|
||||
(define-syntax provide-contracted-vars
|
||||
(make-provide-transformer
|
||||
(λ (stx modes)
|
||||
(define contracted-vars-info
|
||||
(syntax-case stx ()
|
||||
[(_ id) #'id]))
|
||||
(for*/list ([provide-clause (in-list (syntax->list (syntax-local-value contracted-vars-info)))]
|
||||
[export (in-list (expand-export provide-clause modes))])
|
||||
export))))
|
||||
|
|
Loading…
Reference in New Issue
Block a user