diff --git a/pkgs/typed-racket-pkgs/typed-racket-lib/typed-racket/optimizer/float-complex.rkt b/pkgs/typed-racket-pkgs/typed-racket-lib/typed-racket/optimizer/float-complex.rkt index 84397118..e7ac86ac 100644 --- a/pkgs/typed-racket-pkgs/typed-racket-lib/typed-racket/optimizer/float-complex.rkt +++ b/pkgs/typed-racket-pkgs/typed-racket-lib/typed-racket/optimizer/float-complex.rkt @@ -463,6 +463,20 @@ #'(unsafe-make-flrectangular real-binding imag-binding)))) +(define-syntax-class possibly-unboxed + #:attributes ([bindings 1] [real-binding 1] [imag-binding 1] [boxed-binding 1]) + (pattern (#t arg:unboxed-float-complex-opt-expr) + #:with (bindings ...) #'(arg.bindings ...) + #:with (real-binding ...) #'(arg.real-binding) + #:with (imag-binding ...) #'(arg.imag-binding) + #:with (boxed-binding ...) #'()) + (pattern (#f arg:opt-expr) + #:with binding-name (generate-temporary 'boxed-binding) + #:with (bindings ...) #'(((binding-name) arg.opt)) + #:with (real-binding ...) #'() + #:with (imag-binding ...) #'() + #:with (boxed-binding ...) #'(binding-name))) + ;; takes as argument a structure describing which arguments will be unboxed ;; and the optimized version of the operator. operators are optimized elsewhere ;; to benefit from local information @@ -472,21 +486,17 @@ ;; call site of a function with unboxed parameters ;; the calling convention is: real parts of unboxed, imag parts, boxed (pattern (#%plain-app op:expr args:expr ...) - #:with ((to-unbox ...) (boxed ...)) unboxed-info + #:with (unboxed-args ...) unboxed-info #:with opt - (let ((args (syntax->list #'(args ...))) - (unboxed (syntax->datum #'(to-unbox ...))) - (boxed (syntax->datum #'(boxed ...)))) - (define (get-arg i) (list-ref args i)) - (syntax-parse (map get-arg unboxed) - [(e:unboxed-float-complex-opt-expr ...) + (syntax-parse #'((unboxed-args args) ...) + [(e:possibly-unboxed ...) (log-unboxing-opt "unboxed call site") #`(let*-values (e.bindings ... ...) (#%plain-app #,opt-operator - e.real-binding ... - e.imag-binding ... - #,@(map (lambda (i) ((optimize) (get-arg i))) - boxed)))])))) ; boxed params + e.real-binding ... ... + e.imag-binding ... ... + e.boxed-binding ... ...))]))) + (define-syntax-class/specialize float-complex-arith-opt-expr (float-complex-arith-expr* #t)) (define-syntax-class/specialize float-complex-arith-expr (float-complex-arith-expr* #f)) diff --git a/pkgs/typed-racket-pkgs/typed-racket-lib/typed-racket/optimizer/unboxed-tables.rkt b/pkgs/typed-racket-pkgs/typed-racket-lib/typed-racket/optimizer/unboxed-tables.rkt index 20e26028..16563791 100644 --- a/pkgs/typed-racket-pkgs/typed-racket-lib/typed-racket/optimizer/unboxed-tables.rkt +++ b/pkgs/typed-racket-pkgs/typed-racket-lib/typed-racket/optimizer/unboxed-tables.rkt @@ -38,15 +38,15 @@ (define unboxed-funs-table (make-free-id-table)) (define (add-unboxed-fun! fun-name unboxed-args) - (define unboxed - (for/list ([i (in-naturals)] [unboxed? unboxed-args] #:when unboxed?) i)) - (define boxed - (for/list ([i (in-naturals)] [unboxed? unboxed-args] #:unless unboxed?) i)) - (dict-set! unboxed-funs-table fun-name (list unboxed boxed))) + (dict-set! unboxed-funs-table fun-name unboxed-args)) (define-syntax-class unboxed-fun - #:attributes ((unboxed 1) (boxed 1) unboxed-info) + #:attributes ((unboxed 1) unboxed-info) (pattern op:id - #:with unboxed-info (dict-ref unboxed-funs-table #'op #f) - #:when (syntax->datum #'unboxed-info) - #:with ((unboxed ...) (boxed ...)) #'unboxed-info)) + #:do [(define unboxed-args (dict-ref unboxed-funs-table #'op #f))] + #:when unboxed-args + #:with ((unboxed ...) (boxed ...)) + (list + (for/list ([i (in-naturals)] [unboxed? unboxed-args] #:when unboxed?) i) + (for/list ([i (in-naturals)] [unboxed? unboxed-args] #:unless unboxed?) i)) + #:with (~and unboxed-info (unboxed-args ...)) unboxed-args)) diff --git a/pkgs/typed-racket-pkgs/typed-racket-test/tests/typed-racket/optimizer/tests/let-loop-effects.rkt b/pkgs/typed-racket-pkgs/typed-racket-test/tests/typed-racket/optimizer/tests/let-loop-effects.rkt new file mode 100644 index 00000000..ef046f2d --- /dev/null +++ b/pkgs/typed-racket-pkgs/typed-racket-test/tests/typed-racket/optimizer/tests/let-loop-effects.rkt @@ -0,0 +1,48 @@ +#;#; +#<