add the same fast path to contract? and chaperone-contract? that is already in flat-contract?
This commit is contained in:
parent
36368628af
commit
7c3412957a
|
@ -107,9 +107,25 @@
|
||||||
(print (contract-struct-name stct) port 1)
|
(print (contract-struct-name stct) port 1)
|
||||||
(write-suffix)])]))
|
(write-suffix)])]))
|
||||||
|
|
||||||
(define (contract? x) (and (coerce-contract/f x) #t))
|
(define (contract? x)
|
||||||
|
(or (simple-flat-contract? x)
|
||||||
|
(and (coerce-contract/f x) #t)))
|
||||||
|
|
||||||
(define (flat-contract? x)
|
(define (flat-contract? x)
|
||||||
|
(or (simple-flat-contract? x)
|
||||||
|
(let ([c (coerce-contract/f x)])
|
||||||
|
(and c
|
||||||
|
(flat-contract-struct? c)))))
|
||||||
|
|
||||||
|
(define (chaperone-contract? x)
|
||||||
|
(or (simple-flat-contract? x)
|
||||||
|
(let ([c (coerce-contract/f x)])
|
||||||
|
(and c
|
||||||
|
(or (chaperone-contract-struct? c)
|
||||||
|
(and (prop:opt-chaperone-contract? c)
|
||||||
|
((prop:opt-chaperone-contract-get-test c) c)))))))
|
||||||
|
|
||||||
|
(define (simple-flat-contract? x)
|
||||||
(or (and (procedure? x) (procedure-arity-includes? x 1))
|
(or (and (procedure? x) (procedure-arity-includes? x 1))
|
||||||
(null? x)
|
(null? x)
|
||||||
(boolean? x)
|
(boolean? x)
|
||||||
|
@ -120,17 +136,7 @@
|
||||||
(string? x)
|
(string? x)
|
||||||
(number? x)
|
(number? x)
|
||||||
(regexp? x)
|
(regexp? x)
|
||||||
(byte-regexp? x)
|
(byte-regexp? x)))
|
||||||
(let ([c (coerce-contract/f x)])
|
|
||||||
(and c
|
|
||||||
(flat-contract-struct? c)))))
|
|
||||||
|
|
||||||
(define (chaperone-contract? x)
|
|
||||||
(let ([c (coerce-contract/f x)])
|
|
||||||
(and c
|
|
||||||
(or (chaperone-contract-struct? c)
|
|
||||||
(and (prop:opt-chaperone-contract? c)
|
|
||||||
((prop:opt-chaperone-contract-get-test c) c))))))
|
|
||||||
|
|
||||||
(define (impersonator-contract? x)
|
(define (impersonator-contract? x)
|
||||||
(let ([c (coerce-contract/f x)])
|
(let ([c (coerce-contract/f x)])
|
||||||
|
@ -323,7 +329,19 @@
|
||||||
(set! between/c-s-high b/c-s-h))
|
(set! between/c-s-high b/c-s-h))
|
||||||
|
|
||||||
(define (coerce-contract/f x [name name-default])
|
(define (coerce-contract/f x [name name-default])
|
||||||
(define (coerce-simple-value x)
|
(cond
|
||||||
|
[(coerce-simple-value name x) => values]
|
||||||
|
[(name-default? name) (and (contract-struct? x) x)]
|
||||||
|
[(predicate-contract? x)
|
||||||
|
(struct-copy predicate-contract x [name name])]
|
||||||
|
[(eq-contract? x) (make-eq-contract (eq-contract-val x) name)]
|
||||||
|
[(equal-contract? x) (make-eq-contract (equal-contract-val x) name)]
|
||||||
|
[(=-contract? x) (make-=-contract (=-contract-val x) name)]
|
||||||
|
[(regexp/c? x) (make-regexp/c (regexp/c-reg x) name)]
|
||||||
|
[else #f]))
|
||||||
|
|
||||||
|
|
||||||
|
(define (coerce-simple-value name x)
|
||||||
(cond
|
(cond
|
||||||
[(contract-struct? x) #f] ;; this has to come first, since some of these are procedure?.
|
[(contract-struct? x) #f] ;; this has to come first, since some of these are procedure?.
|
||||||
[(and (procedure? x) (procedure-arity-includes? x 1))
|
[(and (procedure? x) (procedure-arity-includes? x 1))
|
||||||
|
@ -372,16 +390,6 @@
|
||||||
(make-=-contract x (if (name-default? name) x name))]
|
(make-=-contract x (if (name-default? name) x name))]
|
||||||
[(or (regexp? x) (byte-regexp? x)) (make-regexp/c x (if (name-default? name) x name))]
|
[(or (regexp? x) (byte-regexp? x)) (make-regexp/c x (if (name-default? name) x name))]
|
||||||
[else #f]))
|
[else #f]))
|
||||||
(cond
|
|
||||||
[(coerce-simple-value x) => values]
|
|
||||||
[(name-default? name) (and (contract-struct? x) x)]
|
|
||||||
[(predicate-contract? x)
|
|
||||||
(struct-copy predicate-contract x [name name])]
|
|
||||||
[(eq-contract? x) (make-eq-contract (eq-contract-val x) name)]
|
|
||||||
[(equal-contract? x) (make-eq-contract (equal-contract-val x) name)]
|
|
||||||
[(=-contract? x) (make-=-contract (=-contract-val x) name)]
|
|
||||||
[(regexp/c? x) (make-regexp/c (regexp/c-reg x) name)]
|
|
||||||
[else #f]))
|
|
||||||
|
|
||||||
(define the-known-good-contracts
|
(define the-known-good-contracts
|
||||||
(let-syntax ([m (λ (x) #`(list #,@(known-good-contracts)))])
|
(let-syntax ([m (λ (x) #`(list #,@(known-good-contracts)))])
|
||||||
|
|
Loading…
Reference in New Issue
Block a user