diff --git a/collects/tests/typed-scheme/optimizer/generic/nested-unboxed-let.rkt b/collects/tests/typed-scheme/optimizer/generic/nested-unboxed-let.rkt new file mode 100644 index 00000000..c16bdebb --- /dev/null +++ b/collects/tests/typed-scheme/optimizer/generic/nested-unboxed-let.rkt @@ -0,0 +1,7 @@ +#lang typed/scheme #:optimize + +(require racket/unsafe/ops) + +(let ((x (+ 1.0+2.0i 2.0+3.0i))) + (let ((x (+ x 2.0+3.0i))) + (+ x 3.0+6.0i))) diff --git a/collects/tests/typed-scheme/optimizer/generic/unboxed-letrec.rkt b/collects/tests/typed-scheme/optimizer/generic/unboxed-letrec.rkt new file mode 100644 index 00000000..aed81a45 --- /dev/null +++ b/collects/tests/typed-scheme/optimizer/generic/unboxed-letrec.rkt @@ -0,0 +1,8 @@ +#lang typed/scheme #:optimize + +(require racket/unsafe/ops) + +(letrec ((#{f : (Any -> Any)} (lambda: ((x : Any)) (f x))) + (#{x : Inexact-Complex} 1.0+2.0i) + (#{y : Inexact-Complex} (+ 2.0+4.0i 3.0+6.0i))) + (+ x y)) diff --git a/collects/typed-scheme/optimizer/unboxed-let.rkt b/collects/typed-scheme/optimizer/unboxed-let.rkt index 1f28db63..ceb1c975 100644 --- a/collects/typed-scheme/optimizer/unboxed-let.rkt +++ b/collects/typed-scheme/optimizer/unboxed-let.rkt @@ -15,7 +15,8 @@ (define-syntax-class unboxed-let-opt-expr #:literal-sets (kernel-literals) - (pattern (~and exp (let-values (clause:expr ...) body:expr ...)) + (pattern (~and exp ((~and op (~or (~literal let-values) (~literal letrec-values))) + (clause:expr ...) body:expr ...)) ;; we look for bindings of complexes that are not mutated and only ;; used in positions where we would unbox them ;; these are candidates for unboxing @@ -40,7 +41,8 @@ (r (in-list (syntax->list #'(opt-candidates.real-binding ...)))) (i (in-list (syntax->list #'(opt-candidates.imag-binding ...))))) (dict-set! unboxed-vars-table v (list r i))) - #`(let* (opt-candidates.bindings ... ... opt-others.res ...) + #`(#,(if (free-identifier=? #'op #'let-values) #'let* #'letrec) + (opt-candidates.bindings ... ... opt-others.res ...) #,@(map (optimize) (syntax->list #'(body ...))))))) ;; if a variable is only used in complex arithmetic operations, it's safe