Simplify flat contracts for Value types

Potentially speeds up contracts checks for
types like False or Boolean.
This commit is contained in:
Asumu Takikawa 2016-06-13 00:50:13 -04:00
parent 1ba8e5ba33
commit 295a4b7e39
4 changed files with 8 additions and 4 deletions

View File

@ -626,7 +626,11 @@
[(Syntax: t)
(syntax/sc (t->sc t))]
[(Value: v)
(flat/sc #`(flat-named-contract '#,v (lambda (x) (equal? x '#,v))) v)]
(if (and (c:flat-contract? v)
;; regexps don't match themselves when used as contracts
(not (regexp? v)))
(flat/sc #`(quote #,v))
(flat/sc #`(flat-named-contract '#,v (lambda (x) (equal? x '#,v))) v))]
[(Param: in out)
(parameter/sc (t->sc in) (t->sc out))]
[(Hashtable: k v)

View File

@ -35,7 +35,7 @@
(check-equal? v #f)
(check-equal? ((cast f (Boolean -> Boolean)) #t) #t)
(check-equal? v #t)
(check-exn #rx"expected: \\(or/c #f #t\\)\n *given: \"hello\""
(check-exn #rx"expected: boolean\\?\n *given: \"hello\""
(λ () ((cast f (String -> String)) "hello")))
(check-equal? v #t
"if the previous test hadn't errored, this would be \"hello\" with type Boolean"))

View File

@ -42,7 +42,7 @@
(check-equal? v #f)
(check-equal? ((cast f (Boolean -> Boolean)) #t) #t)
(check-equal? v #t)
(check-exn #rx"expected: \\(or/c #f #t\\)\n *given: \"hello\""
(check-exn #rx"expected: boolean\\?\n *given: \"hello\""
(λ () ((cast f (String -> String)) "hello")))
(check-equal? v #t
"if the previous test hadn't errored, this would be \"hello\" with type Boolean"))

View File

@ -237,7 +237,7 @@
(lambda (f) (f 6))
(lambda (x) 'bad)
#:untyped
#:msg #rx"promised: \\(or/c #f #t\\).*produced: 'bad.*blaming: untyped")
#:msg #rx"promised: boolean\\?.*produced: 'bad.*blaming: untyped")
;; Struct predicates should not have a contract
(t-int ctc
(lambda (foo?)