Randomly test the TR optimizer.

Compares results of a Racket and a TR sandbox.

original commit: ee0a1d4b89b2dbab9382d37fc4b0139a4ff9b53d
This commit is contained in:
Vincent St-Amour 2012-12-03 21:51:26 -05:00
parent 1501c1db01
commit 50713b7368

View File

@ -130,6 +130,12 @@
(define num-exceptions 0)
(define (mk-eval lang)
(call-with-trusted-sandbox-configuration
(λ () (make-evaluator lang #:requires '(racket/flonum racket/unsafe/ops)))))
(define racket-eval (mk-eval 'racket))
(define tr-eval (mk-eval 'typed/racket))
(define (check-all-reals sexp)
(or (with-handlers
;; something went wrong, almost certainly typechecking failed
@ -139,7 +145,28 @@
#t)])
(get-type sexp)
#f) ; go on and check preservation
(right-type? sexp)))
(and (right-type? sexp)
;; do we get the same result with and without optimization?
(let ()
(define racket-failed? #f)
(define both-failed? #f)
(define racket-result
(with-handlers
;; something went wrong, e.g. division by zero
;; TR must fail too
([exn? (λ (e) (set! racket-failed? #t))])
(racket-eval sexp)))
(define tr-result
(with-handlers
;; did Racket error too?
([exn? (λ (e) (when racket-failed?
(set! both-failed? #t)))])
(tr-eval sexp)))
(or both-failed?
(and (not racket-failed?)
(or (= racket-result tr-result)
;; for NaN, which is not = to itself
(equal? racket-result tr-result))))))))
(define n-attempts 1000)
(command-line